From 3a4870624812ac4286624d3946981cac6aef4e67 Mon Sep 17 00:00:00 2001 From: Christophe Genevey Metat Date: Mon, 27 Jun 2016 15:34:12 +0000 Subject: [PATCH] add function conv param string --- src/my/my_query_helper.c | 34 ++++++++++++++++++-- src/regex/gnunet-regex-simulation-profiler.c | 23 +++++++------ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index 436860691..17ade5a92 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c @@ -88,6 +88,29 @@ GNUNET_MY_query_param_fixed_size (const void *ptr, } +/** + * Function called to convert input argument into SQL parameters. + * + * @param cls closure + * @param pq data about the query + * @param qbind array of parameters to initialize + * @return -1 on error + */ +static int +my_conv_string (void *cls, + const struct GNUNET_MY_QueryParam *qp, + MYSQL_BIND *qbind) +{ + GNUNET_assert (1 == qp->num_params); + + qbind->buffer = (void *) qp->data; + qbind->buffer_length = qp->data_len; + qbind->buffer_type = MYSQL_TYPE_STRING; + + return 1; +} + + /** * Generate query parameter for a string * @@ -96,8 +119,15 @@ GNUNET_MY_query_param_fixed_size (const void *ptr, struct GNUNET_MY_QueryParam GNUNET_MY_query_param_string (const char *ptr) { - return GNUNET_MY_query_param_fixed_size (ptr, - strlen(ptr)); + struct GNUNET_MY_QueryParam qp = { + .conv = &my_conv_string, + .cleaner = NULL, + .conv_cls = NULL, + .num_params = 1, + .data = ptr, + .data_len = strlen (ptr) + }; + return qp; } diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c index e88a00749..62c768a55 100644 --- a/src/regex/gnunet-regex-simulation-profiler.c +++ b/src/regex/gnunet-regex-simulation-profiler.c @@ -316,10 +316,10 @@ do_abort (void *cls) */ static void regex_iterator (void *cls, - const struct GNUNET_HashCode *key, - const char *proof, + const struct GNUNET_HashCode *key, + const char *proof, int accepting, - unsigned int num_edges, + unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges) { unsigned int i; @@ -334,7 +334,7 @@ regex_iterator (void *cls, { struct GNUNET_MY_QueryParam params_select[] = { GNUNET_MY_query_param_auto_from_type (key), - GNUNET_MY_query_param_fixed_size(edges[i].label, strlen (edges[i].label)), + GNUNET_MY_query_param_string (edges[i].label), GNUNET_MY_query_param_end }; @@ -370,13 +370,14 @@ regex_iterator (void *cls, if (-1 != total && total > 0) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", (unsigned long long)total, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", + (unsigned long long)total, GNUNET_h2s (key), edges[i].label); } struct GNUNET_MY_QueryParam params_stmt[] = { GNUNET_MY_query_param_auto_from_type (&key), - GNUNET_MY_query_param_fixed_size (edges[i].label, strlen (edges[i].label)), + GNUNET_MY_query_param_string (edges[i].label), GNUNET_MY_query_param_auto_from_type (&edges[i].destination), GNUNET_MY_query_param_uint32 (&iaccepting), GNUNET_MY_query_param_end @@ -392,8 +393,12 @@ regex_iterator (void *cls, char *key_str = GNUNET_strdup (GNUNET_h2s (key)); char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n", key_str, - edges[i].label, to_key_str, accepting); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n", + key_str, + edges[i].label, + to_key_str, + accepting); + GNUNET_free (key_str); GNUNET_free (to_key_str); num_merged_transitions++; @@ -416,7 +421,7 @@ regex_iterator (void *cls, { struct GNUNET_MY_QueryParam params_stmt[] = { GNUNET_MY_query_param_auto_from_type (key), - GNUNET_MY_query_param_fixed_size (NULL, 0), + GNUNET_MY_query_param_string (""), GNUNET_MY_query_param_auto_from_type (NULL), GNUNET_MY_query_param_uint32 (&iaccepting), GNUNET_MY_query_param_end -- 2.25.1