*/
#define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst)))
+
/**
* FIXME.
*
*/
+
+ /**
+ * Variable-size result expected
+ *
+ * @param[out] dst where to store the result, allocated
+ * @param[out] sptr where to store the size of @a dst
+ * @return array entru for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_variable_size (void **dst,
+ size_t *ptr_size);
+/**
+ * RSA public key expected
+ *
+ * @param name name of the field in the table
+ * @param[out] rsa where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa);
+
+/**
+ * RSA signature expected.
+ *
+ * @param[out] sig where to store the result;
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig);
+
+/**
+ * 0- terminated string exprected.
+ *
+ * @param[out] dst where to store the result, allocated
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_string (char **dst);
+
+/**
+ * Absolute time expected
+ *
+ * @param name name of the field in the table
+ * @param[out] at where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at);
+
+/**
+ * Absolute time in network byte order expected
+ *
+ * @param[out] at where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at);
+
+/**
+ * uint16_t expected
+ *
+ * @param[out] u16 where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint16 (uint16_t *u16);
+
+/**
+ * uint32_t expected
+ *
+ * @param[out] u32 where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint32 (uint32_t *u32);
+
+/**
+ * uint64_t expected.
+ *
+ * @param[out] u64 where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint64 (uint64_t *u64);
+
int
GNUNET_MY_extract_result (MYSQL_BIND * result,
struct GNUNET_MY_QueryParam *qp,
#include "platform.h"
#include "gnunet_util_lib.h"
-#include "gnunet_pq_lib.h"
-
-/**
- * Function called to clean up memory allocated
- * by a #GNUNET_MY_ResultConverter.
- *
- * @param cls closure
- * @param rd result data to clean up
- */
-static void
-clean_varsize_blob (void *cls,
- void *rs)
-{
- void **dst = rd;
-
- if (NULL != *dst)
- {
- GNUNET_free (*dst);
- *dst = NULL;
- }
-}
-
+#include "gnunet_my_lib.h"
/**
* extract data from a Mysql database @a result at row @a row
void *idst;
size_t len;
- MYSQL_ROW * rows;
- MYSQL_FIELD * field;
+ MYSQL_ROW rows;
+ MYSQL_FIELD *field;
rows = mysql_fetch_row (result);
field = mysql_fetch_field (result);
//If it's the correct field
- if (field != fname)
+ if (field->name != fname)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field '%s' does not exist in result",
(void *)(dst),
0,
ptr_size
- }
+ };
return res;
}
*
*/
static int
-extracted_fixed_blob (void *cls,
+extract_fixed_blob (void *cls,
MYSQL_RES * result,
int row,
const char * fname,
size_t len;
const char *res;
- MYSQL_ROW * rows;
+ MYSQL_ROW rows;
MYSQL_FIELD * field;
rows = mysql_fetch_row (result);
field = mysql_fetch_field (result);
//If it's the correct field
- if (field != fname)
+ if (field->name != fname)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field '%s' does not exist in result",
static int
extract_rsa_public_key (void *cls,
MYSQL_RES *result,
- int rown,
+ int row,
const char *fname,
size_t *dst_size,
void *dst)
size_t len;
const char *res;
- MYSQL_ROW * rows;
+ MYSQL_ROW rows;
MYSQL_FIELD * field;
*pk = NULL;
field = mysql_fetch_field (result);
//If it's the correct field
- if (field != fname)
+ if (field->name != fname)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field '%s' does not exist in result",
return GNUNET_OK;
}
-/**
- * Function called to clean up memory allocated
- * by a #GNUNET_MY_ResultConverter
- *
- * @param cls closure
- * @param rd result data to clean up
- */
-static void
-clean_rsa_public_key (void *cls,
- void *rd)
-{
- struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
- if (NULL != *pk)
- {
- GNUNET_CRYPTO_rsa_public_key_free (*pk);
- *pk = NULL;
- }
-}
-
-
/**
* RSA public key expected
*
const char *res;
- MYSQL_ROW * rows;
+ MYSQL_ROW rows;
MYSQL_FIELD * field;
*sig = NULL;
field = mysql_fetch_field (result);
//If it's the correct field
- if (field == fname)
+ if (field->name == fname)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field '%s' does not exist in result",
size_t len;
const char *res;
- MYSQL_ROW * rows;
+ MYSQL_ROW rows;
MYSQL_FIELD * field;
*str = NULL;
void *dst)
{
//TO COMPLETE
+ uint16_t *udst = dst;
+ const uint16_t *res;
+
+ MYSQL_ROW rows;
+ MYSQL_FIELD * field;
+
+ rows = mysql_fetch_row (result);
+
+ field = mysql_fetch_field (result);
+
+ //If it's the correct field
+ if (field->name == fname)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Field '%s' does not exist in result",
+ fname);
+ return GNUNET_SYSERR;
+ }
+
+
+ if (rows[row] == NULL)
+ {
+ return GNUNET_SYSERR;
+ }
+
+ GNUNET_assert (NULL != dst);
+
+ if (sizeof (uint16_t) != *dst_size)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+
+ res = (uint16_t) rows[row];
+ *udst = ntohs (*res);
+
+ return GNUNET_OK;
}
/**
}
/**
+ * Extrac data from a MYSQL database @a result at row @a row
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in, out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_OK if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static int
+extract_uint32 (void *cls,
+ MYSQL_RES * result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ uint32_t *udst = dst;
+ const uint32_t *res;
+
+ MYSQL_ROW rows;
+ MYSQL_FIELD * field;
+
+ rows = mysql_fetch_row (result);
+
+ field = mysql_fetch_field (result);
+
+ //If it's the correct field
+ if (field->name == fname)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Field '%s' does not exist in result",
+ fname);
+ return GNUNET_SYSERR;
+ }
+
+
+ if (rows[row] == NULL)
+ {
+ return GNUNET_SYSERR;
+ }
+
+ GNUNET_assert (NULL != dst);
+
+ if (sizeof (uint32_t) != *dst_size)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+
+ res = (uint32_t) rows[row];
+
+ *udst = ntohl (*res);
+ return GNUNET_OK;
+}
+
+/**
+ * uint32_t expected
+ *
+ * @param[out] u32 where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint32 (uint32_t *u32)
+{
+ struct GNUNET_MY_ResultSpec res = {
+ &extract_uint32,
+ NULL,
+ (void *) u32,
+ sizeof (*u32),
+ NULL
+ };
+ return res;
+}
+
+/**
+ * Extract data from a MYSQL database @a result at row @a row
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in, out] dst_size where to store size of result, may be null
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_OK if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static int
+extract_uint64 (void *cls,
+ MYSQL_RES * result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ uint64_t *udst = dst;
+ const uint64_t *res;
+
+ MYSQL_ROW rows;
+ MYSQL_FIELD * field;
+
+ rows = mysql_fetch_row (result);
+
+ field = mysql_fetch_field (result);
+
+ //If it's the correct field
+ if (field->name == fname)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Field '%s' does not exist in result",
+ fname);
+ return GNUNET_SYSERR;
+ }
+
+
+ if (rows[row] == NULL)
+ {
+ return GNUNET_SYSERR;
+ }
+
+ GNUNET_assert (NULL != dst);
+ if (sizeof (uint64_t) != *dst_size)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+
+ res = (uint64_t) rows[row];
+ *udst = GNUNET_ntohll (*res);
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * uint64_t expected.
+ *
+ * @param[out] u64 where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_MY_ResultSpec
+GNUNET_MY_result_spec_uint64 (uint64_t *u64)
+{
+ struct GNUNET_MY_ResultSpec res = {
+ &extract_uint64,
+ NULL,
+ (void *) u64,
+ sizeof (*u64),
+ NULL
+ };
+ return res;
+}
+
/* end of pq_result_helper.c */
\ No newline at end of file