From f1f8aa05f4c44042a4d59300b44955481bb3c2b0 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 19 May 2016 13:30:48 +0000 Subject: extending MY api to cover result extraction --- src/include/gnunet_my_lib.h | 104 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 7 deletions(-) (limited to 'src/include') diff --git a/src/include/gnunet_my_lib.h b/src/include/gnunet_my_lib.h index 50826a700..b63ee9218 100644 --- a/src/include/gnunet_my_lib.h +++ b/src/include/gnunet_my_lib.h @@ -64,11 +64,6 @@ typedef int const struct GNUNET_MY_QueryParam *qp, MYSQL_BIND *qbind); -/****** CREATE A NEW STRUCTURE ? *****/ -struct GNUNET_MY_Result -{ - -}; /** * Information we pass to #GNUNET_MY_exec_prepared() to @@ -106,7 +101,7 @@ struct GNUNET_MY_QueryParam /** - * End of result parameter specification. + * End of query parameter specification. * * @return array last entry for the result specification to use */ @@ -140,7 +135,102 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, const struct GNUNET_MY_QueryParam *params); -static int extract_result(MYSQL * result, int row) ; +/** + * Information we pass to #GNUNET_MY_extract_result() to + * initialize the arguments of the prepared statement. + */ +struct GNUNET_MY_ResultParam; + + +/** + * Function called to convert input argument into SQL parameters. + * + * @param cls closure + * @param pq data about the query + * @return -1 on error + */ +typedef int +(*GNUNET_MY_ResultConverter)(void *cls, + struct GNUNET_MY_QueryParam *qp, + MYSQL_BIND *results); + + +/** + * Information we pass to #GNUNET_MY_extract_result() to + * initialize the arguments of the prepared statement. + */ +struct GNUNET_MY_ResultSpec +{ + + /** + * Function to call for the type conversion. + */ + GNUNET_MY_ResultConverter conv; + + /** + * Closure for @e conv. + */ + void *conv_cls; + + /** + * Destination for the data. + */ + void *dst; + + /** + * Allowed size for the data, 0 for variable-size + * (in this case, the type of @e dst is a `void **` + * and we need to allocate a buffer of the right size). + */ + size_t dst_size; + + /** + * Where to store actual size of the result. + */ + size_t *result_size; + +}; + + +/** + * End of result speceter specification. + * + * @return array last entry for the result specification to use + */ +#define GNUNET_MY_result_spec_end { NULL, NULL, NULL, 0, NULL } + + + +/** + * Obtain fixed size result of @a ptr_size bytes from + * MySQL, store in already allocated buffer at @a ptr. + * + * @spec ptr where to write the result + * @oaran ptr_size number of bytes available at @a ptr + */ +struct GNUNET_MY_ResultSpec +GNUNET_MY_result_spec_fixed_size (void *ptr, + size_t ptr_size); + + +/** + * We expect a fixed-size result, with size determined by the type of `* dst` + * + * @spec name name of the field in the table + * @spec dst point to where to store the result, type fits expected result size + * @return array entry for the result specification to use + */ +#define GNUNET_MY_result_spec_auto_from_type(dst) GNUNET_MY_result_spec_fixed_size ((dst), sizeof (*(dst))) + + +/** + * FIXME. + */ +int +GNUNET_MY_extract_result (struct GNUNET_MYSQL_Context *mc, + struct GNUNET_MYSQL_StatementHandle *stmt, + int row, + struct GNUNET_MY_ResultSpec *specs); #if 0 /* keep Emacsens' auto-indent happy */ { -- cgit v1.2.3