aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-27 15:34:12 +0000
committerChristophe Genevey Metat <genevey.christophe@gmail.com>2016-06-27 15:34:12 +0000
commit3a4870624812ac4286624d3946981cac6aef4e67 (patch)
tree08b05f2d1354b68a466973c177774479484cae1f
parent4450e34453501e9449de830d48e1421590181ef7 (diff)
downloadgnunet-3a4870624812ac4286624d3946981cac6aef4e67.tar.gz
gnunet-3a4870624812ac4286624d3946981cac6aef4e67.zip
add function conv param string
-rw-r--r--src/my/my_query_helper.c34
-rw-r--r--src/regex/gnunet-regex-simulation-profiler.c23
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
@@ -89,6 +89,29 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
89 89
90 90
91/** 91/**
92 * Function called to convert input argument into SQL parameters.
93 *
94 * @param cls closure
95 * @param pq data about the query
96 * @param qbind array of parameters to initialize
97 * @return -1 on error
98 */
99static int
100my_conv_string (void *cls,
101 const struct GNUNET_MY_QueryParam *qp,
102 MYSQL_BIND *qbind)
103{
104 GNUNET_assert (1 == qp->num_params);
105
106 qbind->buffer = (void *) qp->data;
107 qbind->buffer_length = qp->data_len;
108 qbind->buffer_type = MYSQL_TYPE_STRING;
109
110 return 1;
111}
112
113
114/**
92 * Generate query parameter for a string 115 * Generate query parameter for a string
93 * 116 *
94 * @param ptr pointer to the string query parameter to pass 117 * @param ptr pointer to the string query parameter to pass
@@ -96,8 +119,15 @@ GNUNET_MY_query_param_fixed_size (const void *ptr,
96struct GNUNET_MY_QueryParam 119struct GNUNET_MY_QueryParam
97GNUNET_MY_query_param_string (const char *ptr) 120GNUNET_MY_query_param_string (const char *ptr)
98{ 121{
99 return GNUNET_MY_query_param_fixed_size (ptr, 122 struct GNUNET_MY_QueryParam qp = {
100 strlen(ptr)); 123 .conv = &my_conv_string,
124 .cleaner = NULL,
125 .conv_cls = NULL,
126 .num_params = 1,
127 .data = ptr,
128 .data_len = strlen (ptr)
129 };
130 return qp;
101} 131}
102 132
103 133
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)
316 */ 316 */
317static void 317static void
318regex_iterator (void *cls, 318regex_iterator (void *cls,
319 const struct GNUNET_HashCode *key, 319 const struct GNUNET_HashCode *key,
320 const char *proof, 320 const char *proof,
321 int accepting, 321 int accepting,
322 unsigned int num_edges, 322 unsigned int num_edges,
323 const struct REGEX_BLOCK_Edge *edges) 323 const struct REGEX_BLOCK_Edge *edges)
324{ 324{
325 unsigned int i; 325 unsigned int i;
@@ -334,7 +334,7 @@ regex_iterator (void *cls,
334 { 334 {
335 struct GNUNET_MY_QueryParam params_select[] = { 335 struct GNUNET_MY_QueryParam params_select[] = {
336 GNUNET_MY_query_param_auto_from_type (key), 336 GNUNET_MY_query_param_auto_from_type (key),
337 GNUNET_MY_query_param_fixed_size(edges[i].label, strlen (edges[i].label)), 337 GNUNET_MY_query_param_string (edges[i].label),
338 GNUNET_MY_query_param_end 338 GNUNET_MY_query_param_end
339 }; 339 };
340 340
@@ -370,13 +370,14 @@ regex_iterator (void *cls,
370 370
371 if (-1 != total && total > 0) 371 if (-1 != total && total > 0)
372 { 372 {
373 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n", (unsigned long long)total, 373 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Total: %llu (%s, %s)\n",
374 (unsigned long long)total,
374 GNUNET_h2s (key), edges[i].label); 375 GNUNET_h2s (key), edges[i].label);
375 } 376 }
376 377
377 struct GNUNET_MY_QueryParam params_stmt[] = { 378 struct GNUNET_MY_QueryParam params_stmt[] = {
378 GNUNET_MY_query_param_auto_from_type (&key), 379 GNUNET_MY_query_param_auto_from_type (&key),
379 GNUNET_MY_query_param_fixed_size (edges[i].label, strlen (edges[i].label)), 380 GNUNET_MY_query_param_string (edges[i].label),
380 GNUNET_MY_query_param_auto_from_type (&edges[i].destination), 381 GNUNET_MY_query_param_auto_from_type (&edges[i].destination),
381 GNUNET_MY_query_param_uint32 (&iaccepting), 382 GNUNET_MY_query_param_uint32 (&iaccepting),
382 GNUNET_MY_query_param_end 383 GNUNET_MY_query_param_end
@@ -392,8 +393,12 @@ regex_iterator (void *cls,
392 char *key_str = GNUNET_strdup (GNUNET_h2s (key)); 393 char *key_str = GNUNET_strdup (GNUNET_h2s (key));
393 char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination)); 394 char *to_key_str = GNUNET_strdup (GNUNET_h2s (&edges[i].destination));
394 395
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n", key_str, 396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Merged (%s, %s, %s, %i)\n",
396 edges[i].label, to_key_str, accepting); 397 key_str,
398 edges[i].label,
399 to_key_str,
400 accepting);
401
397 GNUNET_free (key_str); 402 GNUNET_free (key_str);
398 GNUNET_free (to_key_str); 403 GNUNET_free (to_key_str);
399 num_merged_transitions++; 404 num_merged_transitions++;
@@ -416,7 +421,7 @@ regex_iterator (void *cls,
416 { 421 {
417 struct GNUNET_MY_QueryParam params_stmt[] = { 422 struct GNUNET_MY_QueryParam params_stmt[] = {
418 GNUNET_MY_query_param_auto_from_type (key), 423 GNUNET_MY_query_param_auto_from_type (key),
419 GNUNET_MY_query_param_fixed_size (NULL, 0), 424 GNUNET_MY_query_param_string (""),
420 GNUNET_MY_query_param_auto_from_type (NULL), 425 GNUNET_MY_query_param_auto_from_type (NULL),
421 GNUNET_MY_query_param_uint32 (&iaccepting), 426 GNUNET_MY_query_param_uint32 (&iaccepting),
422 GNUNET_MY_query_param_end 427 GNUNET_MY_query_param_end