diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-10 12:32:40 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-10 12:32:40 +0000 |
commit | f06baa8a2c99545167142049f19f4a7bedfe1764 (patch) | |
tree | 185d0bba4ddd80c6c186183bc1cdf8d85815023c /src/my | |
parent | 2f1634060e7d4aab5ff046ca50f1e21bae7471fb (diff) | |
download | gnunet-f06baa8a2c99545167142049f19f4a7bedfe1764.tar.gz gnunet-f06baa8a2c99545167142049f19f4a7bedfe1764.zip |
finish to fix memory leak
Diffstat (limited to 'src/my')
-rw-r--r-- | src/my/my.c | 13 | ||||
-rw-r--r-- | src/my/my_query_helper.c | 20 | ||||
-rw-r--r-- | src/my/my_result_helper.c | 148 | ||||
-rw-r--r-- | src/my/test_my.c | 97 |
4 files changed, 139 insertions, 139 deletions
diff --git a/src/my/my.c b/src/my/my.c index 0328477be..54b1b8e64 100644 --- a/src/my/my.c +++ b/src/my/my.c | |||
@@ -107,6 +107,7 @@ GNUNET_MY_exec_prepared (struct GNUNET_MYSQL_Context *mc, | |||
107 | * #GNUNET_MY_exect_prepared(). | 107 | * #GNUNET_MY_exect_prepared(). |
108 | * | 108 | * |
109 | * @param qp query specification to clean up | 109 | * @param qp query specification to clean up |
110 | * @param qbind array of parameter to clean up | ||
110 | */ | 111 | */ |
111 | void | 112 | void |
112 | GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, | 113 | GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, |
@@ -115,9 +116,9 @@ GNUNET_MY_cleanup_query (struct GNUNET_MY_QueryParam *qp, | |||
115 | unsigned int i; | 116 | unsigned int i; |
116 | 117 | ||
117 | for (i=0; NULL != qp[i].conv ;i++) | 118 | for (i=0; NULL != qp[i].conv ;i++) |
118 | if(NULL != qp[i].cleaner) | 119 | if(NULL != qp[i].cleaner) |
119 | qp[i].cleaner (qp[i].conv_cls, | 120 | qp[i].cleaner (qp[i].conv_cls, |
120 | &qbind[i]); | 121 | &qbind[i]); |
121 | } | 122 | } |
122 | 123 | ||
123 | 124 | ||
@@ -142,7 +143,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
142 | int ret; | 143 | int ret; |
143 | MYSQL_STMT *stmt; | 144 | MYSQL_STMT *stmt; |
144 | 145 | ||
145 | stmt = GNUNET_MYSQL_statement_get_stmt (NULL /* FIXME */, sh); | 146 | stmt = GNUNET_MYSQL_statement_get_stmt (NULL, sh); |
146 | if (NULL == stmt) | 147 | if (NULL == stmt) |
147 | { | 148 | { |
148 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", | 149 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", |
@@ -183,7 +184,6 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
184 | "Pre-conversion for MySQL result failed at offset %u\n", | 185 | "Pre-conversion for MySQL result failed at offset %u\n", |
185 | i); | 186 | i); |
186 | GNUNET_MY_cleanup_result (rs); | ||
187 | return GNUNET_SYSERR; | 187 | return GNUNET_SYSERR; |
188 | } | 188 | } |
189 | field_off += rp->num_fields; | 189 | field_off += rp->num_fields; |
@@ -209,6 +209,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
209 | _("mysql_stmt_fetch failed at %s:%d with error: %s\n"), | 209 | _("mysql_stmt_fetch failed at %s:%d with error: %s\n"), |
210 | __FILE__, __LINE__, | 210 | __FILE__, __LINE__, |
211 | mysql_stmt_error (stmt)); | 211 | mysql_stmt_error (stmt)); |
212 | GNUNET_MY_cleanup_result (rs); | ||
212 | return GNUNET_SYSERR; | 213 | return GNUNET_SYSERR; |
213 | } | 214 | } |
214 | field_off = 0; | 215 | field_off = 0; |
@@ -241,7 +242,7 @@ GNUNET_MY_extract_result (struct GNUNET_MYSQL_StatementHandle *sh, | |||
241 | * Free all memory that was allocated in @a rs during | 242 | * Free all memory that was allocated in @a rs during |
242 | * #GNUNET_MY_extract_result(). | 243 | * #GNUNET_MY_extract_result(). |
243 | * | 244 | * |
244 | * @param rs reult specification to clean up | 245 | * @param rs result specification to clean up |
245 | */ | 246 | */ |
246 | void | 247 | void |
247 | GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs) | 248 | GNUNET_MY_cleanup_result (struct GNUNET_MY_ResultSpec *rs) |
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index c09422160..8ecfc2b64 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -21,6 +21,7 @@ | |||
21 | * @file my/my_query_helper.c | 21 | * @file my/my_query_helper.c |
22 | * @brief library to help with access to a MySQL database | 22 | * @brief library to help with access to a MySQL database |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Christophe Genevey | ||
24 | */ | 25 | */ |
25 | #include "platform.h" | 26 | #include "platform.h" |
26 | #include <mysql/mysql.h> | 27 | #include <mysql/mysql.h> |
@@ -32,7 +33,7 @@ | |||
32 | * by a #GNUNET_MY_QueryConverter. | 33 | * by a #GNUNET_MY_QueryConverter. |
33 | * | 34 | * |
34 | * @param cls closure | 35 | * @param cls closure |
35 | * @param rd result data to clean up | 36 | * @param qbind array of parameter to clean up |
36 | */ | 37 | */ |
37 | static void | 38 | static void |
38 | my_clean_query (void *cls, | 39 | my_clean_query (void *cls, |
@@ -119,7 +120,6 @@ my_conv_uint16 (void *cls, | |||
119 | 120 | ||
120 | GNUNET_assert (1 == qp->num_params); | 121 | GNUNET_assert (1 == qp->num_params); |
121 | 122 | ||
122 | |||
123 | u_nbo = GNUNET_new (uint16_t); | 123 | u_nbo = GNUNET_new (uint16_t); |
124 | if (NULL == u_nbo) | 124 | if (NULL == u_nbo) |
125 | return -1; | 125 | return -1; |
@@ -143,13 +143,13 @@ struct GNUNET_MY_QueryParam | |||
143 | GNUNET_MY_query_param_uint16 (const uint16_t *x) | 143 | GNUNET_MY_query_param_uint16 (const uint16_t *x) |
144 | { | 144 | { |
145 | struct GNUNET_MY_QueryParam res = { | 145 | struct GNUNET_MY_QueryParam res = { |
146 | .conv = &my_conv_uint16, | 146 | .conv = &my_conv_uint16, |
147 | .cleaner = &my_clean_query, | 147 | .cleaner = &my_clean_query, |
148 | .conv_cls = NULL, | 148 | .conv_cls = NULL, |
149 | .num_params = 1, | 149 | .num_params = 1, |
150 | .data = x, | 150 | .data = x, |
151 | .data_len = sizeof (*x) | 151 | .data_len = sizeof (*x) |
152 | }; | 152 | }; |
153 | 153 | ||
154 | return res; | 154 | return res; |
155 | } | 155 | } |
@@ -275,7 +275,7 @@ my_conv_rsa_public_key (void *cls, | |||
275 | size_t buf_size; | 275 | size_t buf_size; |
276 | 276 | ||
277 | GNUNET_assert(1 == qp->num_params); | 277 | GNUNET_assert(1 == qp->num_params); |
278 | // FIXME: this leaks memory right now... | 278 | |
279 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf); | 279 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, &buf); |
280 | 280 | ||
281 | qbind->buffer = (void *) buf; | 281 | qbind->buffer = (void *) buf; |
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index 9c04b9bed..963e3f618 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_result_helper.c | |||
@@ -23,12 +23,15 @@ | |||
23 | #include "gnunet_util_lib.h" | 23 | #include "gnunet_util_lib.h" |
24 | #include "gnunet_my_lib.h" | 24 | #include "gnunet_my_lib.h" |
25 | 25 | ||
26 | |||
26 | /** | 27 | /** |
27 | * extract data from a Mysql database @a result at row @a row | 28 | * extract data from a Mysql database @a result at row @a row |
28 | * | 29 | * |
29 | * @param cls closure | 30 | * @param cls closure |
30 | * @param qp data about the query | 31 | * @param[in,out] rs |
31 | * @param result mysql result | 32 | * @param stmt the mysql statement that is being run |
33 | * @param column the column that is being processed | ||
34 | * @param[out] result mysql result | ||
32 | * @return | 35 | * @return |
33 | * #GNUNET_OK if all results could be extracted | 36 | * #GNUNET_OK if all results could be extracted |
34 | * #GNUNET_SYSERR if a result was invalid | 37 | * #GNUNET_SYSERR if a result was invalid |
@@ -117,11 +120,12 @@ cleanup_varsize_blob (void *cls, | |||
117 | } | 120 | } |
118 | } | 121 | } |
119 | 122 | ||
123 | |||
120 | /** | 124 | /** |
121 | * Variable-size result expected | 125 | * Variable-size result expected |
122 | * | 126 | * |
123 | * @param[out] dst where to store the result, allocated | 127 | * @param[out] dst where to store the result, allocated |
124 | * @param[out] sptr where to store the size of @a dst | 128 | * @param[out] ptr_size where to store the size of @a dst |
125 | * @return array entru for the result specification to use | 129 | * @return array entru for the result specification to use |
126 | */ | 130 | */ |
127 | struct GNUNET_MY_ResultSpec | 131 | struct GNUNET_MY_ResultSpec |
@@ -146,11 +150,10 @@ GNUNET_MY_result_spec_variable_size (void **dst, | |||
146 | * Extract data from a Mysql database @a result at row @a row | 150 | * Extract data from a Mysql database @a result at row @a row |
147 | * | 151 | * |
148 | * @param cls closure | 152 | * @param cls closure |
149 | * @param result where to extract data from | 153 | * @param[in,out] rs |
150 | * @param int row to extract data from | 154 | * @param stmt the mysql statement that is being run |
151 | * @param fname name (or prefix) of the fields to extract from | 155 | * @param column the column that is being processed |
152 | * @param[in] dst_size desired size, never NULL | 156 | * @param[out] results |
153 | * @param[out] dst where to store the result | ||
154 | * @return | 157 | * @return |
155 | * #GNUNET_OK if all results could be extracted | 158 | * #GNUNET_OK if all results could be extracted |
156 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) | 159 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) |
@@ -176,11 +179,10 @@ pre_extract_fixed_blob (void *cls, | |||
176 | * result at row @a row | 179 | * result at row @a row |
177 | * | 180 | * |
178 | * @param cls closure | 181 | * @param cls closure |
179 | * @param result where to extract data from | 182 | * @param[in,out] rs |
180 | * @param int row to extract data from | 183 | * @param stmt the mysql statement that is being run |
181 | * @param fname name (or prefix) of the fields to extract from | 184 | * @param column the column that is being processed |
182 | * @param[in] dst_size desired size, never NULL | 185 | * @param[out] results |
183 | * @param[out] dst where to store the result | ||
184 | * @return | 186 | * @return |
185 | * #GNUNET_OK if all results could be extracted | 187 | * #GNUNET_OK if all results could be extracted |
186 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) | 188 | * #GNUNET_SYSERR if a result was invalid(non-existing field or NULL) |
@@ -203,7 +205,7 @@ post_extract_fixed_blob (void *cls, | |||
203 | * | 205 | * |
204 | * @param name name of the field in the table | 206 | * @param name name of the field in the table |
205 | * @param[out] dst where to store the result | 207 | * @param[out] dst where to store the result |
206 | * @param dst_size number of bytes in @a dst | 208 | * @param ptr_size number of bytes in @a dst |
207 | * @return array entry for the result specification to use | 209 | * @return array entry for the result specification to use |
208 | */ | 210 | */ |
209 | struct GNUNET_MY_ResultSpec | 211 | struct GNUNET_MY_ResultSpec |
@@ -228,11 +230,10 @@ GNUNET_MY_result_spec_fixed_size (void *ptr, | |||
228 | * Extract data from a Mysql database @a result at row @a row | 230 | * Extract data from a Mysql database @a result at row @a row |
229 | * | 231 | * |
230 | * @param cls closure | 232 | * @param cls closure |
231 | * @param result where to extract data from | 233 | * @param[in,out] rs |
232 | * @param int row to extract data from | 234 | * @param stmt the mysql statement that is being run |
233 | * @param fname name (or prefix) of the fields to extract from | 235 | * @param column the column that is being processed |
234 | * @param[in, out] dst_size where to store size of result, may be NULL | 236 | * @param[out] results |
235 | * @param[out] dst where to store the result | ||
236 | * @return | 237 | * @return |
237 | * #GNUNET_OK if all results could be extracted | 238 | * #GNUNET_OK if all results could be extracted |
238 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 239 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -258,11 +259,10 @@ pre_extract_rsa_public_key (void *cls, | |||
258 | * result at row @a row | 259 | * result at row @a row |
259 | * | 260 | * |
260 | * @param cls closure | 261 | * @param cls closure |
261 | * @param result where to extract data from | 262 | * @param[in,out] rs |
262 | * @param int row to extract data from | 263 | * @param stmt the mysql statement that is being run |
263 | * @param fname name (or prefix) of the fields to extract from | 264 | * @param column the column that is being processed |
264 | * @param[in, out] dst_size where to store size of result, may be NULL | 265 | * @param[out] results |
265 | * @param[out] dst where to store the result | ||
266 | * @return | 266 | * @return |
267 | * #GNUNET_OK if all results could be extracted | 267 | * #GNUNET_OK if all results could be extracted |
268 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 268 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -297,6 +297,7 @@ post_extract_rsa_public_key (void *cls, | |||
297 | GNUNET_free (buf); | 297 | GNUNET_free (buf); |
298 | return GNUNET_SYSERR; | 298 | return GNUNET_SYSERR; |
299 | } | 299 | } |
300 | |||
300 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, | 301 | *pk = GNUNET_CRYPTO_rsa_public_key_decode (buf, |
301 | size); | 302 | size); |
302 | GNUNET_free (buf); | 303 | GNUNET_free (buf); |
@@ -316,7 +317,7 @@ post_extract_rsa_public_key (void *cls, | |||
316 | * by a #GNUNET_MY_ResultConverter. | 317 | * by a #GNUNET_MY_ResultConverter. |
317 | * | 318 | * |
318 | * @param cls closure | 319 | * @param cls closure |
319 | * @param rd result data to clean up | 320 | * @param rs result data to clean up |
320 | */ | 321 | */ |
321 | static void | 322 | static void |
322 | clean_rsa_public_key (void *cls, | 323 | clean_rsa_public_key (void *cls, |
@@ -354,15 +355,15 @@ GNUNET_MY_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa) | |||
354 | return res; | 355 | return res; |
355 | } | 356 | } |
356 | 357 | ||
358 | |||
357 | /** | 359 | /** |
358 | * Extract data from a Mysql database @a result at row @a row. | 360 | * Extract data from a Mysql database @a result at row @a row. |
359 | * | 361 | * |
360 | * @param cls closure | 362 | * @param cls closure |
361 | * @param result where to extract data from | 363 | * @param[in,out] rs |
362 | * @param int row to extract data from | 364 | * @param stmt the mysql statement that is being run |
363 | * @param fname name (or prefix) of the fields to extract from | 365 | * @param column the column that is being processed |
364 | * @param[in,out] dst_size where to store size of result, may be NULL | 366 | * @param[out] results |
365 | * @param[out] dst where to store the result | ||
366 | * @return | 367 | * @return |
367 | * #GNUNET_OK if all results could be extracted | 368 | * #GNUNET_OK if all results could be extracted |
368 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 369 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -387,11 +388,10 @@ pre_extract_rsa_signature (void *cls, | |||
387 | * Extract data from a Mysql database @a result at row @a row. | 388 | * Extract data from a Mysql database @a result at row @a row. |
388 | * | 389 | * |
389 | * @param cls closure | 390 | * @param cls closure |
390 | * @param result where to extract data from | 391 | * @param[in,out] rs |
391 | * @param int row to extract data from | 392 | * @param stmt the mysql statement that is being run |
392 | * @param fname name (or prefix) of the fields to extract from | 393 | * @param column the column that is being processed |
393 | * @param[in,out] dst_size where to store size of result, may be NULL | 394 | * @param[out] results |
394 | * @param[out] dst where to store the result | ||
395 | * @return | 395 | * @return |
396 | * #GNUNET_OK if all results could be extracted | 396 | * #GNUNET_OK if all results could be extracted |
397 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 397 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -481,15 +481,15 @@ GNUNET_MY_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig) | |||
481 | return res; | 481 | return res; |
482 | } | 482 | } |
483 | 483 | ||
484 | |||
484 | /** | 485 | /** |
485 | * Extract data from a Mysql database @a result at row @a row | 486 | * Extract data from a Mysql database @a result at row @a row |
486 | * | 487 | * |
487 | * @param cls closure | 488 | * @param cls closure |
488 | * @param result where to extract data from | 489 | * @param[in,out] rs |
489 | * @param int row to extract data from | 490 | * @param stmt the mysql statement that is being run |
490 | * @param fname name (or prefix) of the fields to extract from | 491 | * @param column the column that is being processed |
491 | * @param[in, out] dst_size where to store size of result, may be NULL | 492 | * @param[out] results |
492 | * @param[out] dst where to store the result | ||
493 | * @return | 493 | * @return |
494 | * #GNUNET_OK if all results could be extracted | 494 | * #GNUNET_OK if all results could be extracted |
495 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) | 495 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) |
@@ -513,11 +513,10 @@ pre_extract_string (void * cls, | |||
513 | * Check size of extracted fixed size data from a Mysql database @a | 513 | * Check size of extracted fixed size data from a Mysql database @a |
514 | * | 514 | * |
515 | * @param cls closure | 515 | * @param cls closure |
516 | * @param result where to extract data from | 516 | * @param[in,out] rs |
517 | * @param int row to extract data from | 517 | * @param stmt the mysql statement that is being run |
518 | * @param fname name (or prefix) of the fields to extract from | 518 | * @param column the column that is being processed |
519 | * @param[in, out] dst_size where to store size of result, may be NULL | 519 | * @param[out] results |
520 | * @param[out] dst where to store the result | ||
521 | * @return | 520 | * @return |
522 | * #GNUNET_OK if all results could be extracted | 521 | * #GNUNET_OK if all results could be extracted |
523 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) | 522 | * #GNUNET_SYSERR if a result was invalid (non existing field or NULL) |
@@ -589,11 +588,10 @@ GNUNET_MY_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at) | |||
589 | * Extract data from a Postgres database @a result at row @a row. | 588 | * Extract data from a Postgres database @a result at row @a row. |
590 | * | 589 | * |
591 | * @param cls closure | 590 | * @param cls closure |
592 | * @param result where to extract data from | 591 | * @param[in,out] rs |
593 | * @param int row to extract data from | 592 | * @param stmt the mysql statement that is being run |
594 | * @param fname name (or prefix) of the fields to extract from | 593 | * @param column the column that is being processed |
595 | * @param[in,out] dst_size where to store size of result, may be NULL | 594 | * @param[out] results |
596 | * @param[out] dst where to store the result | ||
597 | * @return | 595 | * @return |
598 | * #GNUNET_YES if all results could be extracted | 596 | * #GNUNET_YES if all results could be extracted |
599 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 597 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -618,11 +616,10 @@ pre_extract_uint16 (void *cls, | |||
618 | * Check size of extracted fixed size data from a Mysql datbase. | 616 | * Check size of extracted fixed size data from a Mysql datbase. |
619 | * | 617 | * |
620 | * @param cls closure | 618 | * @param cls closure |
621 | * @param result where to extract data from | 619 | * @param[in,out] rs |
622 | * @param int row to extract data from | 620 | * @param stmt the mysql statement that is being run |
623 | * @param fname name (or prefix) of the fields to extract from | 621 | * @param column the column that is being processed |
624 | * @param[in,out] dst_size where to store size of result, may be NULL | 622 | * @param[out] results |
625 | * @param[out] dst where to store the result | ||
626 | * @return | 623 | * @return |
627 | * #GNUNET_YES if all results could be extracted | 624 | * #GNUNET_YES if all results could be extracted |
628 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 625 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -660,15 +657,16 @@ GNUNET_MY_result_spec_uint16 (uint16_t *u16) | |||
660 | return res; | 657 | return res; |
661 | } | 658 | } |
662 | 659 | ||
660 | |||
663 | /** | 661 | /** |
664 | * Extrac data from a MYSQL database @a result at row @a row | 662 | * Extrac data from a MYSQL database @a result at row @a row |
665 | * | 663 | * |
666 | * @param cls closure | 664 | * @param cls closure |
667 | * @param result where to extract data from | 665 | * @param cls closure |
668 | * @param int row to extract data from | 666 | * @param[in,out] rs |
669 | * @param fname name (or prefix) of the fields to extract from | 667 | * @param stmt the mysql statement that is being run |
670 | * @param[in, out] dst_size where to store size of result, may be NULL | 668 | * @param column the column that is being processed |
671 | * @param[out] dst where to store the result | 669 | * @param[out] results |
672 | * @return | 670 | * @return |
673 | * #GNUNET_OK if all results could be extracted | 671 | * #GNUNET_OK if all results could be extracted |
674 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 672 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -693,11 +691,11 @@ pre_extract_uint32 (void *cls, | |||
693 | * Extrac data from a MYSQL database @a result at row @a row | 691 | * Extrac data from a MYSQL database @a result at row @a row |
694 | * | 692 | * |
695 | * @param cls closure | 693 | * @param cls closure |
696 | * @param result where to extract data from | 694 | * @param cls closure |
697 | * @param int row to extract data from | 695 | * @param[in,out] rs |
698 | * @param fname name (or prefix) of the fields to extract from | 696 | * @param stmt the mysql statement that is being run |
699 | * @param[in, out] dst_size where to store size of result, may be NULL | 697 | * @param column the column that is being processed |
700 | * @param[out] dst where to store the result | 698 | * @param[out] results |
701 | * @return | 699 | * @return |
702 | * #GNUNET_OK if all results could be extracted | 700 | * #GNUNET_OK if all results could be extracted |
703 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 701 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -740,11 +738,10 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32) | |||
740 | * Extract data from a MYSQL database @a result at row @a row | 738 | * Extract data from a MYSQL database @a result at row @a row |
741 | * | 739 | * |
742 | * @param cls closure | 740 | * @param cls closure |
743 | * @param result where to extract data from | 741 | * @param[in,out] rs |
744 | * @param int row to extract data from | 742 | * @param stmt the mysql statement that is being run |
745 | * @param fname name (or prefix) of the fields to extract from | 743 | * @param column the column that is being processed |
746 | * @param[in, out] dst_size where to store size of result, may be null | 744 | * @param[out] results |
747 | * @param[out] dst where to store the result | ||
748 | * @return | 745 | * @return |
749 | * #GNUNET_OK if all results could be extracted | 746 | * #GNUNET_OK if all results could be extracted |
750 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 747 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -765,16 +762,14 @@ pre_extract_uint64 (void *cls, | |||
765 | } | 762 | } |
766 | 763 | ||
767 | 764 | ||
768 | |||
769 | /** | 765 | /** |
770 | * Check size of extracted fixe size data from a Mysql database | 766 | * Check size of extracted fixe size data from a Mysql database |
771 | * | 767 | * |
772 | * @param cls closure | 768 | * @param cls closure |
773 | * @param result where to extract data from | 769 | * @param[in,out] rs |
774 | * @param int row to extract data from | 770 | * @param stmt the mysql statement that is being run |
775 | * @param fname name (or prefix) of the fields to extract from | 771 | * @param column the column that is being processed |
776 | * @param[in, out] dst_size where to store size of result, may be null | 772 | * @param[out] results |
777 | * @param[out] dst where to store the result | ||
778 | * @return | 773 | * @return |
779 | * #GNUNET_OK if all results could be extracted | 774 | * #GNUNET_OK if all results could be extracted |
780 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) | 775 | * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL) |
@@ -812,4 +807,5 @@ GNUNET_MY_result_spec_uint64 (uint64_t *u64) | |||
812 | return res; | 807 | return res; |
813 | } | 808 | } |
814 | 809 | ||
810 | |||
815 | /* end of pq_result_helper.c */ | 811 | /* end of pq_result_helper.c */ |
diff --git a/src/my/test_my.c b/src/my/test_my.c index a375a76fa..5f778ad46 100644 --- a/src/my/test_my.c +++ b/src/my/test_my.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_mysql_lib.h" | 28 | #include "gnunet_mysql_lib.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | 30 | ||
31 | |||
31 | /** | 32 | /** |
32 | * Run actual test queries. | 33 | * Run actual test queries. |
33 | * | 34 | * |
@@ -77,7 +78,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
77 | 78 | ||
78 | memset (&hc, 0, sizeof(hc)); | 79 | memset (&hc, 0, sizeof(hc)); |
79 | memset (&hc2, 0, sizeof(hc2)); | 80 | memset (&hc2, 0, sizeof(hc2)); |
80 | 81 | ||
81 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, | 82 | statements_handle_insert = GNUNET_MYSQL_statement_prepare (context, |
82 | "INSERT INTO test_my2 (" | 83 | "INSERT INTO test_my2 (" |
83 | " pub" | 84 | " pub" |
@@ -139,28 +140,28 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
139 | } | 140 | } |
140 | 141 | ||
141 | struct GNUNET_MY_QueryParam params_select[] = { | 142 | struct GNUNET_MY_QueryParam params_select[] = { |
142 | GNUNET_MY_query_param_end | 143 | GNUNET_MY_query_param_end |
143 | }; | 144 | }; |
144 | 145 | ||
145 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, | 146 | if (GNUNET_OK != GNUNET_MY_exec_prepared (context, |
146 | statements_handle_select, | 147 | statements_handle_select, |
147 | params_select)) | 148 | params_select)) |
148 | { | 149 | { |
149 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); | 150 | fprintf (stderr, "Failed to execute prepared statement SELECT\n"); |
150 | return 1; | 151 | return 1; |
151 | } | 152 | } |
152 | 153 | ||
153 | struct GNUNET_MY_ResultSpec results_select[] = { | 154 | struct GNUNET_MY_ResultSpec results_select[] = { |
154 | GNUNET_MY_result_spec_rsa_public_key (&pub2), | 155 | GNUNET_MY_result_spec_rsa_public_key (&pub2), |
155 | GNUNET_MY_result_spec_rsa_signature (&sig2), | 156 | GNUNET_MY_result_spec_rsa_signature (&sig2), |
156 | GNUNET_MY_result_spec_absolute_time (&abs_time2), | 157 | GNUNET_MY_result_spec_absolute_time (&abs_time2), |
157 | GNUNET_MY_result_spec_absolute_time (&forever2), | 158 | GNUNET_MY_result_spec_absolute_time (&forever2), |
158 | GNUNET_MY_result_spec_auto_from_type (&hc2), | 159 | GNUNET_MY_result_spec_auto_from_type (&hc2), |
159 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), | 160 | GNUNET_MY_result_spec_variable_size (&msg2, &msg2_len), |
160 | GNUNET_MY_result_spec_uint16 (&u162), | 161 | GNUNET_MY_result_spec_uint16 (&u162), |
161 | GNUNET_MY_result_spec_uint32 (&u322), | 162 | GNUNET_MY_result_spec_uint32 (&u322), |
162 | GNUNET_MY_result_spec_uint64 (&u642), | 163 | GNUNET_MY_result_spec_uint64 (&u642), |
163 | GNUNET_MY_result_spec_end | 164 | GNUNET_MY_result_spec_end |
164 | }; | 165 | }; |
165 | 166 | ||
166 | ret = GNUNET_MY_extract_result (statements_handle_select, | 167 | ret = GNUNET_MY_extract_result (statements_handle_select, |
@@ -177,17 +178,18 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
177 | GNUNET_assert (NULL != sig2); | 178 | GNUNET_assert (NULL != sig2); |
178 | GNUNET_assert (NULL != pub2); | 179 | GNUNET_assert (NULL != pub2); |
179 | GNUNET_break (0 == | 180 | GNUNET_break (0 == |
180 | GNUNET_CRYPTO_rsa_signature_cmp (sig, | 181 | GNUNET_CRYPTO_rsa_signature_cmp (sig, |
181 | sig2)); | 182 | sig2)); |
182 | GNUNET_break (0 == | 183 | GNUNET_break (0 == |
183 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, | 184 | GNUNET_CRYPTO_rsa_public_key_cmp (pub, |
184 | pub2)); | 185 | pub2)); |
185 | 186 | ||
186 | GNUNET_break (strlen (msg) == msg2_len); | 187 | GNUNET_break (strlen (msg) == msg2_len); |
187 | GNUNET_break (0 == | 188 | GNUNET_break (0 == |
188 | strncmp (msg, | 189 | strncmp (msg, |
189 | msg2, | 190 | msg2, |
190 | msg2_len)); | 191 | msg2_len)); |
192 | |||
191 | GNUNET_break (16 == u162); | 193 | GNUNET_break (16 == u162); |
192 | GNUNET_break (32 == u322); | 194 | GNUNET_break (32 == u322); |
193 | GNUNET_break (64 == u642); | 195 | GNUNET_break (64 == u642); |
@@ -199,7 +201,7 @@ run_queries (struct GNUNET_MYSQL_Context *context) | |||
199 | GNUNET_CRYPTO_rsa_public_key_free (pub); | 201 | GNUNET_CRYPTO_rsa_public_key_free (pub); |
200 | 202 | ||
201 | if (GNUNET_OK != ret) | 203 | if (GNUNET_OK != ret) |
202 | return 1; | 204 | return 1; |
203 | 205 | ||
204 | return 0; | 206 | return 0; |
205 | } | 207 | } |
@@ -212,46 +214,47 @@ main (int argc, const char * const argv[]) | |||
212 | struct GNUNET_MYSQL_Context *context = NULL; | 214 | struct GNUNET_MYSQL_Context *context = NULL; |
213 | int ret; | 215 | int ret; |
214 | 216 | ||
215 | GNUNET_log_setup ( "test-my", | 217 | GNUNET_log_setup ("test-my", |
216 | "WARNING", | 218 | "WARNING", |
217 | NULL); | 219 | NULL); |
218 | 220 | ||
219 | config = GNUNET_CONFIGURATION_create (); | 221 | config = GNUNET_CONFIGURATION_create (); |
220 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (config, "test_my.conf")) | 222 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (config, "test_my.conf")) |
221 | { | 223 | { |
222 | fprintf (stderr, "Failed to parse configuaration\n"); | 224 | fprintf (stderr, "Failed to parse configuaration\n"); |
223 | return 1; | 225 | return 1; |
224 | } | 226 | } |
225 | 227 | ||
226 | context = GNUNET_MYSQL_context_create (config, | 228 | context = GNUNET_MYSQL_context_create (config, |
227 | "datastore-mysql"); | 229 | "datastore-mysql"); |
228 | if (NULL == context) | 230 | if (NULL == context) |
229 | { | 231 | { |
230 | fprintf(stderr, "Failed to connect to database\n"); | 232 | fprintf(stderr, "Failed to connect to database\n"); |
231 | return 77; | 233 | return 77; |
232 | } | 234 | } |
233 | 235 | ||
234 | (void) GNUNET_MYSQL_statement_run (context, | 236 | (void) GNUNET_MYSQL_statement_run (context, |
235 | "DROP TABLE test_my2;"); | 237 | "DROP TABLE test_my2;"); |
238 | |||
236 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, | 239 | if (GNUNET_OK != GNUNET_MYSQL_statement_run (context, |
237 | "CREATE TABLE IF NOT EXISTS test_my2(" | 240 | "CREATE TABLE IF NOT EXISTS test_my2(" |
238 | " pub BLOB NOT NULL" | 241 | " pub BLOB NOT NULL" |
239 | ",sig BLOB NOT NULL" | 242 | ",sig BLOB NOT NULL" |
240 | ",abs_time BIGINT NOT NULL" | 243 | ",abs_time BIGINT NOT NULL" |
241 | ",forever BIGINT NOT NULL" | 244 | ",forever BIGINT NOT NULL" |
242 | ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" | 245 | ",hash BLOB NOT NULL CHECK(LENGTH(hash)=64)" |
243 | ",vsize BLOB NOT NULL" | 246 | ",vsize BLOB NOT NULL" |
244 | ",u16 SMALLINT NOT NULL" | 247 | ",u16 SMALLINT NOT NULL" |
245 | ",u32 INT NOT NULL" | 248 | ",u32 INT NOT NULL" |
246 | ",u64 BIGINT NOT NULL" | 249 | ",u64 BIGINT NOT NULL" |
247 | ")")) | 250 | ")")) |
248 | { | 251 | { |
249 | fprintf (stderr, | 252 | fprintf (stderr, |
250 | "Failed to create table \n"); | 253 | "Failed to create table \n"); |
251 | GNUNET_MYSQL_statements_invalidate (context); | 254 | GNUNET_MYSQL_statements_invalidate (context); |
252 | GNUNET_MYSQL_context_destroy (context); | 255 | GNUNET_MYSQL_context_destroy (context); |
253 | 256 | ||
254 | return 1; | 257 | return 1; |
255 | } | 258 | } |
256 | 259 | ||
257 | ret = run_queries (context); | 260 | ret = run_queries (context); |