aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r--src/datastore/plugin_datastore_mysql.c1070
1 files changed, 502 insertions, 568 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c
index 3d0da61a0..a9b039981 100644
--- a/src/datastore/plugin_datastore_mysql.c
+++ b/src/datastore/plugin_datastore_mysql.c
@@ -164,7 +164,7 @@ struct GNUNET_MysqlStatementHandle
164/** 164/**
165 * Context for all functions in this plugin. 165 * Context for all functions in this plugin.
166 */ 166 */
167struct Plugin 167struct Plugin
168{ 168{
169 /** 169 /**
170 * Our execution environment. 170 * Our execution environment.
@@ -175,7 +175,7 @@ struct Plugin
175 * Handle to talk to MySQL. 175 * Handle to talk to MySQL.
176 */ 176 */
177 MYSQL *dbf; 177 MYSQL *dbf;
178 178
179 /** 179 /**
180 * We keep all prepared statements in a DLL. This is the head. 180 * We keep all prepared statements in a DLL. This is the head.
181 */ 181 */
@@ -196,13 +196,13 @@ struct Plugin
196 */ 196 */
197#define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" 197#define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)"
198 struct GNUNET_MysqlStatementHandle *insert_entry; 198 struct GNUNET_MysqlStatementHandle *insert_entry;
199 199
200#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" 200#define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?"
201 struct GNUNET_MysqlStatementHandle *delete_entry_by_uid; 201 struct GNUNET_MysqlStatementHandle *delete_entry_by_uid;
202 202
203#define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash) WHERE hash=?" 203#define COUNT_ENTRY_BY_HASH "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash) WHERE hash=?"
204 struct GNUNET_MysqlStatementHandle *count_entry_by_hash; 204 struct GNUNET_MysqlStatementHandle *count_entry_by_hash;
205 205
206#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? ORDER BY uid LIMIT 1 OFFSET ?" 206#define SELECT_ENTRY_BY_HASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash) WHERE hash=? ORDER BY uid LIMIT 1 OFFSET ?"
207 struct GNUNET_MysqlStatementHandle *select_entry_by_hash; 207 struct GNUNET_MysqlStatementHandle *select_entry_by_hash;
208 208
@@ -211,16 +211,16 @@ struct Plugin
211 211
212#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? ORDER BY uid LIMIT 1 OFFSET ?" 212#define SELECT_ENTRY_BY_HASH_AND_VHASH "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? ORDER BY uid LIMIT 1 OFFSET ?"
213 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash; 213 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_vhash;
214 214
215#define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=?" 215#define COUNT_ENTRY_BY_HASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=?"
216 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type; 216 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_and_type;
217 217
218#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=? ORDER BY uid LIMIT 1 OFFSET ?" 218#define SELECT_ENTRY_BY_HASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_type_uid) WHERE hash=? AND type=? ORDER BY uid LIMIT 1 OFFSET ?"
219 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type; 219 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_and_type;
220 220
221#define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=?" 221#define COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT count(*) FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=?"
222 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type; 222 struct GNUNET_MysqlStatementHandle *count_entry_by_hash_vhash_and_type;
223 223
224#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? ORDER BY uid ASC LIMIT 1 OFFSET ?" 224#define SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE "SELECT type,prio,anonLevel,expire,hash,value,uid FROM gn090 FORCE INDEX (idx_hash_vhash) WHERE hash=? AND vhash=? AND type=? ORDER BY uid ASC LIMIT 1 OFFSET ?"
225 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type; 225 struct GNUNET_MysqlStatementHandle *select_entry_by_hash_vhash_and_type;
226 226
@@ -274,6 +274,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
274 char *cnffile; 274 char *cnffile;
275 char *home_dir; 275 char *home_dir;
276 struct stat st; 276 struct stat st;
277
277#ifndef WINDOWS 278#ifndef WINDOWS
278 struct passwd *pw; 279 struct passwd *pw;
279#endif 280#endif
@@ -282,44 +283,47 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
282#ifndef WINDOWS 283#ifndef WINDOWS
283 pw = getpwuid (getuid ()); 284 pw = getpwuid (getuid ());
284 if (!pw) 285 if (!pw)
285 { 286 {
286 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 287 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "getpwuid");
287 "getpwuid"); 288 return NULL;
288 return NULL; 289 }
289 }
290 if (GNUNET_YES == 290 if (GNUNET_YES ==
291 GNUNET_CONFIGURATION_have_value (cfg, 291 GNUNET_CONFIGURATION_have_value (cfg, "datastore-mysql", "CONFIG"))
292 "datastore-mysql", "CONFIG")) 292 {
293 { 293 GNUNET_assert (GNUNET_OK ==
294 GNUNET_assert (GNUNET_OK == 294 GNUNET_CONFIGURATION_get_value_filename (cfg,
295 GNUNET_CONFIGURATION_get_value_filename (cfg, 295 "datastore-mysql",
296 "datastore-mysql", "CONFIG", &cnffile)); 296 "CONFIG",
297 configured = GNUNET_YES; 297 &cnffile));
298 } 298 configured = GNUNET_YES;
299 }
299 else 300 else
300 { 301 {
301 home_dir = GNUNET_strdup (pw->pw_dir); 302 home_dir = GNUNET_strdup (pw->pw_dir);
303 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
304 GNUNET_free (home_dir);
305 configured = GNUNET_NO;
306 }
302#else 307#else
303 home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1); 308 home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1);
304 plibc_conv_to_win_path ("~/", home_dir); 309 plibc_conv_to_win_path ("~/", home_dir);
310 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir);
311 GNUNET_free (home_dir);
312 configured = GNUNET_NO;
305#endif 313#endif
306 GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir); 314
307 GNUNET_free (home_dir);
308 configured = GNUNET_NO;
309 }
310 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
311 _("Trying to use file `%s' for MySQL configuration.\n"), 316 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile);
312 cnffile);
313 if ((0 != STAT (cnffile, &st)) || 317 if ((0 != STAT (cnffile, &st)) ||
314 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) 318 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode)))
315 { 319 {
316 if (configured == GNUNET_YES) 320 if (configured == GNUNET_YES)
317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
318 _("Could not access file `%s': %s\n"), cnffile, 322 _("Could not access file `%s': %s\n"), cnffile,
319 STRERROR (errno)); 323 STRERROR (errno));
320 GNUNET_free (cnffile); 324 GNUNET_free (cnffile);
321 return NULL; 325 return NULL;
322 } 326 }
323 return cnffile; 327 return cnffile;
324} 328}
325 329
@@ -336,18 +340,18 @@ iclose (struct Plugin *plugin)
336 struct GNUNET_MysqlStatementHandle *s; 340 struct GNUNET_MysqlStatementHandle *s;
337 341
338 for (s = plugin->shead; s != NULL; s = s->next) 342 for (s = plugin->shead; s != NULL; s = s->next)
343 {
344 if (s->valid)
339 { 345 {
340 if (s->valid) 346 mysql_stmt_close (s->statement);
341 { 347 s->valid = GNUNET_NO;
342 mysql_stmt_close (s->statement);
343 s->valid = GNUNET_NO;
344 }
345 } 348 }
349 }
346 if (plugin->dbf != NULL) 350 if (plugin->dbf != NULL)
347 { 351 {
348 mysql_close (plugin->dbf); 352 mysql_close (plugin->dbf);
349 plugin->dbf = NULL; 353 plugin->dbf = NULL;
350 } 354 }
351 return GNUNET_OK; 355 return GNUNET_OK;
352} 356}
353 357
@@ -378,75 +382,79 @@ iopen (struct Plugin *plugin)
378 mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client"); 382 mysql_options (plugin->dbf, MYSQL_READ_DEFAULT_GROUP, "client");
379 reconnect = 0; 383 reconnect = 0;
380 mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect); 384 mysql_options (plugin->dbf, MYSQL_OPT_RECONNECT, &reconnect);
381 timeout = 120; /* in seconds */ 385 timeout = 120; /* in seconds */
382 mysql_options (plugin->dbf, 386 mysql_options (plugin->dbf,
383 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout); 387 MYSQL_OPT_CONNECT_TIMEOUT, (const void *) &timeout);
384 mysql_options(plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8"); 388 mysql_options (plugin->dbf, MYSQL_SET_CHARSET_NAME, "UTF8");
385 timeout = 60; /* in seconds */ 389 timeout = 60; /* in seconds */
386 mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 390 mysql_options (plugin->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
387 mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 391 mysql_options (plugin->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
388 mysql_dbname = NULL; 392 mysql_dbname = NULL;
389 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 393 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
390 "datastore-mysql", "DATABASE")) 394 "datastore-mysql",
391 GNUNET_assert (GNUNET_OK == 395 "DATABASE"))
392 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 396 GNUNET_assert (GNUNET_OK ==
393 "datastore-mysql", "DATABASE", 397 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
394 &mysql_dbname)); 398 "datastore-mysql",
399 "DATABASE",
400 &mysql_dbname));
395 else 401 else
396 mysql_dbname = GNUNET_strdup ("gnunet"); 402 mysql_dbname = GNUNET_strdup ("gnunet");
397 mysql_user = NULL; 403 mysql_user = NULL;
398 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 404 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
399 "datastore-mysql", "USER")) 405 "datastore-mysql", "USER"))
400 { 406 {
401 GNUNET_assert (GNUNET_OK == 407 GNUNET_assert (GNUNET_OK ==
402 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 408 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
403 "datastore-mysql", "USER", 409 "datastore-mysql",
404 &mysql_user)); 410 "USER", &mysql_user));
405 } 411 }
406 mysql_password = NULL; 412 mysql_password = NULL;
407 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 413 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
408 "datastore-mysql", "PASSWORD")) 414 "datastore-mysql",
409 { 415 "PASSWORD"))
410 GNUNET_assert (GNUNET_OK == 416 {
411 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 417 GNUNET_assert (GNUNET_OK ==
412 "datastore-mysql", "PASSWORD", 418 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
413 &mysql_password)); 419 "datastore-mysql",
414 } 420 "PASSWORD",
421 &mysql_password));
422 }
415 mysql_server = NULL; 423 mysql_server = NULL;
416 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 424 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
417 "datastore-mysql", "HOST")) 425 "datastore-mysql", "HOST"))
418 { 426 {
419 GNUNET_assert (GNUNET_OK == 427 GNUNET_assert (GNUNET_OK ==
420 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 428 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
421 "datastore-mysql", "HOST", 429 "datastore-mysql",
422 &mysql_server)); 430 "HOST",
423 } 431 &mysql_server));
432 }
424 mysql_port = 0; 433 mysql_port = 0;
425 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg, 434 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (plugin->env->cfg,
426 "datastore-mysql", "PORT")) 435 "datastore-mysql", "PORT"))
427 { 436 {
428 GNUNET_assert (GNUNET_OK == 437 GNUNET_assert (GNUNET_OK ==
429 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, "datastore-mysql", 438 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg,
430 "PORT", &mysql_port)); 439 "datastore-mysql",
431 } 440 "PORT", &mysql_port));
441 }
432 442
433 GNUNET_assert (mysql_dbname != NULL); 443 GNUNET_assert (mysql_dbname != NULL);
434 mysql_real_connect (plugin->dbf, 444 mysql_real_connect (plugin->dbf,
435 mysql_server, 445 mysql_server,
436 mysql_user, mysql_password, 446 mysql_user, mysql_password,
437 mysql_dbname, 447 mysql_dbname,
438 (unsigned int) mysql_port, NULL, 448 (unsigned int) mysql_port, NULL, CLIENT_IGNORE_SIGPIPE);
439 CLIENT_IGNORE_SIGPIPE);
440 GNUNET_free_non_null (mysql_server); 449 GNUNET_free_non_null (mysql_server);
441 GNUNET_free_non_null (mysql_user); 450 GNUNET_free_non_null (mysql_user);
442 GNUNET_free_non_null (mysql_password); 451 GNUNET_free_non_null (mysql_password);
443 GNUNET_free (mysql_dbname); 452 GNUNET_free (mysql_dbname);
444 if (mysql_error (plugin->dbf)[0]) 453 if (mysql_error (plugin->dbf)[0])
445 { 454 {
446 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, 455 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_real_connect", plugin);
447 "mysql_real_connect", plugin); 456 return GNUNET_SYSERR;
448 return GNUNET_SYSERR; 457 }
449 }
450 return GNUNET_OK; 458 return GNUNET_OK;
451} 459}
452 460
@@ -459,19 +467,17 @@ iopen (struct Plugin *plugin)
459 * @return GNUNET_OK on success, GNUNET_SYSERR on error 467 * @return GNUNET_OK on success, GNUNET_SYSERR on error
460 */ 468 */
461static int 469static int
462run_statement (struct Plugin *plugin, 470run_statement (struct Plugin *plugin, const char *statement)
463 const char *statement)
464{ 471{
465 if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin))) 472 if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
466 return GNUNET_SYSERR; 473 return GNUNET_SYSERR;
467 mysql_query (plugin->dbf, statement); 474 mysql_query (plugin->dbf, statement);
468 if (mysql_error (plugin->dbf)[0]) 475 if (mysql_error (plugin->dbf)[0])
469 { 476 {
470 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, 477 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", plugin);
471 "mysql_query", plugin); 478 iclose (plugin);
472 iclose (plugin); 479 return GNUNET_SYSERR;
473 return GNUNET_SYSERR; 480 }
474 }
475 return GNUNET_OK; 481 return GNUNET_OK;
476} 482}
477 483
@@ -484,16 +490,13 @@ run_statement (struct Plugin *plugin,
484 * @return NULL on error 490 * @return NULL on error
485 */ 491 */
486static struct GNUNET_MysqlStatementHandle * 492static struct GNUNET_MysqlStatementHandle *
487prepared_statement_create (struct Plugin *plugin, 493prepared_statement_create (struct Plugin *plugin, const char *statement)
488 const char *statement)
489{ 494{
490 struct GNUNET_MysqlStatementHandle *ret; 495 struct GNUNET_MysqlStatementHandle *ret;
491 496
492 ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle)); 497 ret = GNUNET_malloc (sizeof (struct GNUNET_MysqlStatementHandle));
493 ret->query = GNUNET_strdup (statement); 498 ret->query = GNUNET_strdup (statement);
494 GNUNET_CONTAINER_DLL_insert (plugin->shead, 499 GNUNET_CONTAINER_DLL_insert (plugin->shead, plugin->stail, ret);
495 plugin->stail,
496 ret);
497 return ret; 500 return ret;
498} 501}
499 502
@@ -506,36 +509,30 @@ prepared_statement_create (struct Plugin *plugin,
506 * @return GNUNET_OK on success 509 * @return GNUNET_OK on success
507 */ 510 */
508static int 511static int
509prepare_statement (struct Plugin *plugin, 512prepare_statement (struct Plugin *plugin,
510 struct GNUNET_MysqlStatementHandle *ret) 513 struct GNUNET_MysqlStatementHandle *ret)
511{ 514{
512 if (GNUNET_YES == ret->valid) 515 if (GNUNET_YES == ret->valid)
513 return GNUNET_OK; 516 return GNUNET_OK;
514 if ((NULL == plugin->dbf) && 517 if ((NULL == plugin->dbf) && (GNUNET_OK != iopen (plugin)))
515 (GNUNET_OK != iopen (plugin)))
516 return GNUNET_SYSERR; 518 return GNUNET_SYSERR;
517 ret->statement = mysql_stmt_init (plugin->dbf); 519 ret->statement = mysql_stmt_init (plugin->dbf);
518 if (ret->statement == NULL) 520 if (ret->statement == NULL)
519 { 521 {
520 iclose (plugin); 522 iclose (plugin);
521 return GNUNET_SYSERR; 523 return GNUNET_SYSERR;
522 } 524 }
523 if (mysql_stmt_prepare (ret->statement, 525 if (mysql_stmt_prepare (ret->statement, ret->query, strlen (ret->query)))
524 ret->query, 526 {
525 strlen (ret->query))) 527 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
526 { 528 "mysql",
527 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 529 _("Failed to prepare statement `%s'\n"), ret->query);
528 "mysql", 530 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", plugin);
529 _("Failed to prepare statement `%s'\n"), 531 mysql_stmt_close (ret->statement);
530 ret->query); 532 ret->statement = NULL;
531 LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, 533 iclose (plugin);
532 "mysql_stmt_prepare", 534 return GNUNET_SYSERR;
533 plugin); 535 }
534 mysql_stmt_close (ret->statement);
535 ret->statement = NULL;
536 iclose (plugin);
537 return GNUNET_SYSERR;
538 }
539 ret->valid = GNUNET_YES; 536 ret->valid = GNUNET_YES;
540 return GNUNET_OK; 537 return GNUNET_OK;
541 538
@@ -553,8 +550,7 @@ prepare_statement (struct Plugin *plugin,
553 */ 550 */
554static int 551static int
555init_params (struct Plugin *plugin, 552init_params (struct Plugin *plugin,
556 struct GNUNET_MysqlStatementHandle *s, 553 struct GNUNET_MysqlStatementHandle *s, va_list ap)
557 va_list ap)
558{ 554{
559 MYSQL_BIND qbind[MAX_PARAM]; 555 MYSQL_BIND qbind[MAX_PARAM];
560 unsigned int pc; 556 unsigned int pc;
@@ -563,69 +559,72 @@ init_params (struct Plugin *plugin,
563 559
564 pc = mysql_stmt_param_count (s->statement); 560 pc = mysql_stmt_param_count (s->statement);
565 if (pc > MAX_PARAM) 561 if (pc > MAX_PARAM)
566 { 562 {
567 /* increase internal constant! */ 563 /* increase internal constant! */
568 GNUNET_break (0); 564 GNUNET_break (0);
569 return GNUNET_SYSERR; 565 return GNUNET_SYSERR;
570 } 566 }
571 memset (qbind, 0, sizeof (qbind)); 567 memset (qbind, 0, sizeof (qbind));
572 off = 0; 568 off = 0;
573 ft = 0; 569 ft = 0;
574 while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types)))) 570 while ((pc > 0) && (-1 != (int) (ft = va_arg (ap, enum enum_field_types))))
571 {
572 qbind[off].buffer_type = ft;
573 switch (ft)
575 { 574 {
576 qbind[off].buffer_type = ft; 575 case MYSQL_TYPE_FLOAT:
577 switch (ft) 576 qbind[off].buffer = va_arg (ap, float *);
578 { 577
579 case MYSQL_TYPE_FLOAT: 578 break;
580 qbind[off].buffer = va_arg (ap, float *); 579 case MYSQL_TYPE_LONGLONG:
581 break; 580 qbind[off].buffer = va_arg (ap, unsigned long long *);
582 case MYSQL_TYPE_LONGLONG: 581 qbind[off].is_unsigned = va_arg (ap, int);
583 qbind[off].buffer = va_arg (ap, unsigned long long *); 582
584 qbind[off].is_unsigned = va_arg (ap, int); 583 break;
585 break; 584 case MYSQL_TYPE_LONG:
586 case MYSQL_TYPE_LONG: 585 qbind[off].buffer = va_arg (ap, unsigned int *);
587 qbind[off].buffer = va_arg (ap, unsigned int *); 586 qbind[off].is_unsigned = va_arg (ap, int);
588 qbind[off].is_unsigned = va_arg (ap, int); 587
589 break; 588 break;
590 case MYSQL_TYPE_VAR_STRING: 589 case MYSQL_TYPE_VAR_STRING:
591 case MYSQL_TYPE_STRING: 590 case MYSQL_TYPE_STRING:
592 case MYSQL_TYPE_BLOB: 591 case MYSQL_TYPE_BLOB:
593 qbind[off].buffer = va_arg (ap, void *); 592 qbind[off].buffer = va_arg (ap, void *);
594 qbind[off].buffer_length = va_arg (ap, unsigned long); 593 qbind[off].buffer_length = va_arg (ap, unsigned long);
595 qbind[off].length = va_arg (ap, unsigned long *); 594 qbind[off].length = va_arg (ap, unsigned long *);
596 break; 595
597 default: 596 break;
598 /* unsupported type */ 597 default:
599 GNUNET_break (0); 598 /* unsupported type */
600 return GNUNET_SYSERR; 599 GNUNET_break (0);
601 }
602 pc--;
603 off++;
604 }
605 if (! ( (pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1) ) )
606 {
607 GNUNET_assert (0);
608 return GNUNET_SYSERR; 600 return GNUNET_SYSERR;
609 } 601 }
602 pc--;
603 off++;
604 }
605 if (!((pc == 0) && (-1 != (int) ft) && (va_arg (ap, int) == -1)))
606 {
607 GNUNET_assert (0);
608 return GNUNET_SYSERR;
609 }
610 if (mysql_stmt_bind_param (s->statement, qbind)) 610 if (mysql_stmt_bind_param (s->statement, qbind))
611 { 611 {
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
613 _("`%s' failed at %s:%d with error: %s\n"), 613 _("`%s' failed at %s:%d with error: %s\n"),
614 "mysql_stmt_bind_param", 614 "mysql_stmt_bind_param",
615 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 615 __FILE__, __LINE__, mysql_stmt_error (s->statement));
616 iclose (plugin); 616 iclose (plugin);
617 return GNUNET_SYSERR; 617 return GNUNET_SYSERR;
618 } 618 }
619 if (mysql_stmt_execute (s->statement)) 619 if (mysql_stmt_execute (s->statement))
620 { 620 {
621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
622 _("`%s' for `%s' failed at %s:%d with error: %s\n"), 622 _("`%s' for `%s' failed at %s:%d with error: %s\n"),
623 "mysql_stmt_execute", 623 "mysql_stmt_execute",
624 s->query, 624 s->query, __FILE__, __LINE__, mysql_stmt_error (s->statement));
625 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 625 iclose (plugin);
626 iclose (plugin); 626 return GNUNET_SYSERR;
627 return GNUNET_SYSERR; 627 }
628 }
629 return GNUNET_OK; 628 return GNUNET_OK;
630} 629}
631 630
@@ -645,51 +644,50 @@ init_params (struct Plugin *plugin,
645 */ 644 */
646static int 645static int
647prepared_statement_run_select_va (struct Plugin *plugin, 646prepared_statement_run_select_va (struct Plugin *plugin,
648 struct GNUNET_MysqlStatementHandle *s, 647 struct GNUNET_MysqlStatementHandle *s,
649 unsigned int result_size, 648 unsigned int result_size,
650 MYSQL_BIND *results, 649 MYSQL_BIND * results, va_list ap)
651 va_list ap)
652{ 650{
653 int ret; 651 int ret;
654 unsigned int rsize; 652 unsigned int rsize;
655 653
656 if (GNUNET_OK != prepare_statement (plugin, s)) 654 if (GNUNET_OK != prepare_statement (plugin, s))
657 { 655 {
658 GNUNET_break (0); 656 GNUNET_break (0);
659 return GNUNET_SYSERR; 657 return GNUNET_SYSERR;
660 } 658 }
661 if (GNUNET_OK != init_params (plugin, s, ap)) 659 if (GNUNET_OK != init_params (plugin, s, ap))
662 { 660 {
663 GNUNET_break (0); 661 GNUNET_break (0);
664 return GNUNET_SYSERR; 662 return GNUNET_SYSERR;
665 } 663 }
666 rsize = mysql_stmt_field_count (s->statement); 664 rsize = mysql_stmt_field_count (s->statement);
667 if (rsize > result_size) 665 if (rsize > result_size)
668 { 666 {
669 GNUNET_break (0); 667 GNUNET_break (0);
670 return GNUNET_SYSERR; 668 return GNUNET_SYSERR;
671 } 669 }
672 if (mysql_stmt_bind_result (s->statement, results)) 670 if (mysql_stmt_bind_result (s->statement, results))
673 { 671 {
674 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
675 _("`%s' failed at %s:%d with error: %s\n"), 673 _("`%s' failed at %s:%d with error: %s\n"),
676 "mysql_stmt_bind_result", 674 "mysql_stmt_bind_result",
677 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 675 __FILE__, __LINE__, mysql_stmt_error (s->statement));
678 iclose (plugin); 676 iclose (plugin);
679 return GNUNET_SYSERR; 677 return GNUNET_SYSERR;
680 } 678 }
681 ret = mysql_stmt_fetch (s->statement); 679 ret = mysql_stmt_fetch (s->statement);
682 if (ret == MYSQL_NO_DATA) 680 if (ret == MYSQL_NO_DATA)
683 return GNUNET_NO; 681 return GNUNET_NO;
684 if (ret != 0) 682 if (ret != 0)
685 { 683 {
686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 684 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
687 _("`%s' failed at %s:%d with error: %s\n"), 685 _("`%s' failed at %s:%d with error: %s\n"),
688 "mysql_stmt_fetch", 686 "mysql_stmt_fetch",
689 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 687 __FILE__, __LINE__, mysql_stmt_error (s->statement));
690 iclose (plugin); 688 iclose (plugin);
691 return GNUNET_SYSERR; 689 return GNUNET_SYSERR;
692 } 690 }
693 mysql_stmt_reset (s->statement); 691 mysql_stmt_reset (s->statement);
694 return GNUNET_OK; 692 return GNUNET_OK;
695} 693}
@@ -711,18 +709,15 @@ prepared_statement_run_select_va (struct Plugin *plugin,
711 */ 709 */
712static int 710static int
713prepared_statement_run_select (struct Plugin *plugin, 711prepared_statement_run_select (struct Plugin *plugin,
714 struct GNUNET_MysqlStatementHandle *s, 712 struct GNUNET_MysqlStatementHandle *s,
715 unsigned int result_size, 713 unsigned int result_size,
716 MYSQL_BIND *results, 714 MYSQL_BIND * results, ...)
717 ...)
718{ 715{
719 va_list ap; 716 va_list ap;
720 int ret; 717 int ret;
721 718
722 va_start (ap, results); 719 va_start (ap, results);
723 ret = prepared_statement_run_select_va (plugin, s, 720 ret = prepared_statement_run_select_va (plugin, s, result_size, results, ap);
724 result_size, results,
725 ap);
726 va_end (ap); 721 va_end (ap);
727 return ret; 722 return ret;
728} 723}
@@ -743,8 +738,8 @@ prepared_statement_run_select (struct Plugin *plugin,
743 */ 738 */
744static int 739static int
745prepared_statement_run (struct Plugin *plugin, 740prepared_statement_run (struct Plugin *plugin,
746 struct GNUNET_MysqlStatementHandle *s, 741 struct GNUNET_MysqlStatementHandle *s,
747 unsigned long long *insert_id, ...) 742 unsigned long long *insert_id, ...)
748{ 743{
749 va_list ap; 744 va_list ap;
750 int affected; 745 int affected;
@@ -753,10 +748,10 @@ prepared_statement_run (struct Plugin *plugin,
753 return GNUNET_SYSERR; 748 return GNUNET_SYSERR;
754 va_start (ap, insert_id); 749 va_start (ap, insert_id);
755 if (GNUNET_OK != init_params (plugin, s, ap)) 750 if (GNUNET_OK != init_params (plugin, s, ap))
756 { 751 {
757 va_end (ap); 752 va_end (ap);
758 return GNUNET_SYSERR; 753 return GNUNET_SYSERR;
759 } 754 }
760 va_end (ap); 755 va_end (ap);
761 affected = mysql_stmt_affected_rows (s->statement); 756 affected = mysql_stmt_affected_rows (s->statement);
762 if (NULL != insert_id) 757 if (NULL != insert_id)
@@ -774,26 +769,22 @@ prepared_statement_run (struct Plugin *plugin,
774 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error 769 * @return GNUNET_OK on success, GNUNET_NO if no such value exists, GNUNET_SYSERR on error
775 */ 770 */
776static int 771static int
777do_delete_entry (struct Plugin *plugin, 772do_delete_entry (struct Plugin *plugin, unsigned long long uid)
778 unsigned long long uid)
779{ 773{
780 int ret; 774 int ret;
781 775
782#if DEBUG_MYSQL 776#if DEBUG_MYSQL
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
784 "Deleting value %llu from gn090 table\n", 778 "Deleting value %llu from gn090 table\n", uid);
785 uid);
786#endif 779#endif
787 ret = prepared_statement_run (plugin, 780 ret = prepared_statement_run (plugin,
788 plugin->delete_entry_by_uid, 781 plugin->delete_entry_by_uid,
789 NULL, 782 NULL,
790 MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, 783 MYSQL_TYPE_LONGLONG, &uid, GNUNET_YES, -1);
791 -1);
792 if (ret >= 0) 784 if (ret >= 0)
793 return GNUNET_OK; 785 return GNUNET_OK;
794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 786 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
795 "Deleting value %llu from gn090 table failed\n", 787 "Deleting value %llu from gn090 table failed\n", uid);
796 uid);
797 return ret; 788 return ret;
798} 789}
799 790
@@ -817,11 +808,8 @@ mysql_plugin_estimate_size (void *cls)
817 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG; 808 cbind[0].buffer_type = MYSQL_TYPE_LONGLONG;
818 cbind[0].buffer = &total; 809 cbind[0].buffer = &total;
819 cbind[0].is_unsigned = GNUNET_NO; 810 cbind[0].is_unsigned = GNUNET_NO;
820 if (GNUNET_OK != 811 if (GNUNET_OK !=
821 prepared_statement_run_select (plugin, 812 prepared_statement_run_select (plugin, plugin->get_size, 1, cbind, -1))
822 plugin->get_size,
823 1, cbind,
824 -1))
825 return 0; 813 return 0;
826 return total; 814 return total;
827} 815}
@@ -844,61 +832,58 @@ mysql_plugin_estimate_size (void *cls)
844 */ 832 */
845static int 833static int
846mysql_plugin_put (void *cls, 834mysql_plugin_put (void *cls,
847 const GNUNET_HashCode * key, 835 const GNUNET_HashCode * key,
848 uint32_t size, 836 uint32_t size,
849 const void *data, 837 const void *data,
850 enum GNUNET_BLOCK_Type type, 838 enum GNUNET_BLOCK_Type type,
851 uint32_t priority, 839 uint32_t priority,
852 uint32_t anonymity, 840 uint32_t anonymity,
853 uint32_t replication, 841 uint32_t replication,
854 struct GNUNET_TIME_Absolute expiration, 842 struct GNUNET_TIME_Absolute expiration, char **msg)
855 char **msg)
856{ 843{
857 struct Plugin *plugin = cls; 844 struct Plugin *plugin = cls;
858 unsigned int irepl = replication; 845 unsigned int irepl = replication;
859 unsigned int ipriority = priority; 846 unsigned int ipriority = priority;
860 unsigned int ianonymity = anonymity; 847 unsigned int ianonymity = anonymity;
861 unsigned long long lexpiration = expiration.abs_value; 848 unsigned long long lexpiration = expiration.abs_value;
862 unsigned long long lrvalue = (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 849 unsigned long long lrvalue =
863 UINT64_MAX); 850 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
851 UINT64_MAX);
864 unsigned long hashSize; 852 unsigned long hashSize;
865 unsigned long hashSize2; 853 unsigned long hashSize2;
866 unsigned long lsize; 854 unsigned long lsize;
867 GNUNET_HashCode vhash; 855 GNUNET_HashCode vhash;
868 856
869 if (size > MAX_DATUM_SIZE) 857 if (size > MAX_DATUM_SIZE)
870 { 858 {
871 GNUNET_break (0); 859 GNUNET_break (0);
872 return GNUNET_SYSERR; 860 return GNUNET_SYSERR;
873 } 861 }
874 hashSize = sizeof (GNUNET_HashCode); 862 hashSize = sizeof (GNUNET_HashCode);
875 hashSize2 = sizeof (GNUNET_HashCode); 863 hashSize2 = sizeof (GNUNET_HashCode);
876 lsize = size; 864 lsize = size;
877 GNUNET_CRYPTO_hash (data, size, &vhash); 865 GNUNET_CRYPTO_hash (data, size, &vhash);
878 if (GNUNET_OK != 866 if (GNUNET_OK !=
879 prepared_statement_run (plugin, 867 prepared_statement_run (plugin,
880 plugin->insert_entry, 868 plugin->insert_entry,
881 NULL, 869 NULL,
882 MYSQL_TYPE_LONG, &irepl, GNUNET_YES, 870 MYSQL_TYPE_LONG, &irepl, GNUNET_YES,
883 MYSQL_TYPE_LONG, &type, GNUNET_YES, 871 MYSQL_TYPE_LONG, &type, GNUNET_YES,
884 MYSQL_TYPE_LONG, &ipriority, GNUNET_YES, 872 MYSQL_TYPE_LONG, &ipriority, GNUNET_YES,
885 MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES, 873 MYSQL_TYPE_LONG, &ianonymity, GNUNET_YES,
886 MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES, 874 MYSQL_TYPE_LONGLONG, &lexpiration, GNUNET_YES,
887 MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES, 875 MYSQL_TYPE_LONGLONG, &lrvalue, GNUNET_YES,
888 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 876 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
889 MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2, 877 MYSQL_TYPE_BLOB, &vhash, hashSize2, &hashSize2,
890 MYSQL_TYPE_BLOB, data, lsize, &lsize, 878 MYSQL_TYPE_BLOB, data, lsize, &lsize, -1))
891 -1)) 879 return GNUNET_SYSERR;
892 return GNUNET_SYSERR;
893#if DEBUG_MYSQL 880#if DEBUG_MYSQL
894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 881 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 "Inserted value `%s' with size %u into gn090 table\n", 882 "Inserted value `%s' with size %u into gn090 table\n",
896 GNUNET_h2s (key), 883 GNUNET_h2s (key), (unsigned int) size);
897 (unsigned int) size);
898#endif 884#endif
899 if (size > 0) 885 if (size > 0)
900 plugin->env->duc (plugin->env->cls, 886 plugin->env->duc (plugin->env->cls, size);
901 size);
902 return GNUNET_OK; 887 return GNUNET_OK;
903} 888}
904 889
@@ -928,10 +913,8 @@ mysql_plugin_put (void *cls,
928 */ 913 */
929static int 914static int
930mysql_plugin_update (void *cls, 915mysql_plugin_update (void *cls,
931 uint64_t uid, 916 uint64_t uid,
932 int delta, 917 int delta, struct GNUNET_TIME_Absolute expire, char **msg)
933 struct GNUNET_TIME_Absolute expire,
934 char **msg)
935{ 918{
936 struct Plugin *plugin = cls; 919 struct Plugin *plugin = cls;
937 unsigned long long vkey = uid; 920 unsigned long long vkey = uid;
@@ -940,25 +923,21 @@ mysql_plugin_update (void *cls,
940 923
941#if DEBUG_MYSQL 924#if DEBUG_MYSQL
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "Updating value %llu adding %d to priority and maxing exp at %llu\n", 926 "Updating value %llu adding %d to priority and maxing exp at %llu\n",
944 vkey, 927 vkey, delta, lexpire);
945 delta,
946 lexpire);
947#endif 928#endif
948 ret = prepared_statement_run (plugin, 929 ret = prepared_statement_run (plugin,
949 plugin->update_entry, 930 plugin->update_entry,
950 NULL, 931 NULL,
951 MYSQL_TYPE_LONG, &delta, GNUNET_NO, 932 MYSQL_TYPE_LONG, &delta, GNUNET_NO,
952 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, 933 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
953 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES, 934 MYSQL_TYPE_LONGLONG, &lexpire, GNUNET_YES,
954 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, 935 MYSQL_TYPE_LONGLONG, &vkey, GNUNET_YES, -1);
955 -1);
956 if (ret != GNUNET_OK) 936 if (ret != GNUNET_OK)
957 { 937 {
958 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 938 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
959 "Failed to update value %llu\n", 939 "Failed to update value %llu\n", vkey);
960 vkey); 940 }
961 }
962 return ret; 941 return ret;
963} 942}
964 943
@@ -973,11 +952,10 @@ mysql_plugin_update (void *cls,
973 * @param proc_cls closure for proc 952 * @param proc_cls closure for proc
974 * @param ... arguments to initialize stmt 953 * @param ... arguments to initialize stmt
975 */ 954 */
976static void 955static void
977execute_select (struct Plugin *plugin, 956execute_select (struct Plugin *plugin,
978 struct GNUNET_MysqlStatementHandle *stmt, 957 struct GNUNET_MysqlStatementHandle *stmt,
979 PluginDatumProcessor proc, void *proc_cls, 958 PluginDatumProcessor proc, void *proc_cls, ...)
980 ...)
981{ 959{
982 va_list ap; 960 va_list ap;
983 int ret; 961 int ret;
@@ -1020,51 +998,36 @@ execute_select (struct Plugin *plugin,
1020 rbind[6].is_unsigned = 1; 998 rbind[6].is_unsigned = 1;
1021 999
1022 va_start (ap, proc_cls); 1000 va_start (ap, proc_cls);
1023 ret = prepared_statement_run_select_va (plugin, 1001 ret = prepared_statement_run_select_va (plugin, stmt, 7, rbind, ap);
1024 stmt,
1025 7, rbind,
1026 ap);
1027 va_end (ap); 1002 va_end (ap);
1028 if (ret <= 0) 1003 if (ret <= 0)
1029 { 1004 {
1030 proc (proc_cls, 1005 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1031 NULL, 0, NULL, 0, 0, 0, 1006 return;
1032 GNUNET_TIME_UNIT_ZERO_ABS, 0); 1007 }
1033 return; 1008 GNUNET_assert (size <= sizeof (value));
1034 } 1009 if ((rbind[4].buffer_length != sizeof (GNUNET_HashCode)) ||
1035 GNUNET_assert (size <= sizeof(value)); 1010 (hashSize != sizeof (GNUNET_HashCode)))
1036 if ( (rbind[4].buffer_length != sizeof (GNUNET_HashCode)) || 1011 {
1037 (hashSize != sizeof (GNUNET_HashCode)) ) 1012 GNUNET_break (0);
1038 { 1013 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1039 GNUNET_break (0); 1014 return;
1040 proc (proc_cls, 1015 }
1041 NULL, 0, NULL, 0, 0, 0,
1042 GNUNET_TIME_UNIT_ZERO_ABS, 0);
1043 return;
1044 }
1045#if DEBUG_MYSQL 1016#if DEBUG_MYSQL
1046 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1017 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1047 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %llu selecting from gn090 table\n", 1018 "Found %u-byte value under key `%s' with prio %u, anon %u, expire %llu selecting from gn090 table\n",
1048 (unsigned int) size, 1019 (unsigned int) size, GNUNET_h2s (&key), priority, anonymity, exp);
1049 GNUNET_h2s (&key),
1050 priority,
1051 anonymity,
1052 exp);
1053#endif 1020#endif
1054 GNUNET_assert (size < MAX_DATUM_SIZE); 1021 GNUNET_assert (size < MAX_DATUM_SIZE);
1055 expiration.abs_value = exp; 1022 expiration.abs_value = exp;
1056 ret = proc (proc_cls, 1023 ret = proc (proc_cls,
1057 &key, 1024 &key, size, value, type, priority, anonymity, expiration, uid);
1058 size, value,
1059 type, priority, anonymity, expiration,
1060 uid);
1061 if (ret == GNUNET_NO) 1025 if (ret == GNUNET_NO)
1062 { 1026 {
1063 do_delete_entry (plugin, uid); 1027 do_delete_entry (plugin, uid);
1064 if (size != 0) 1028 if (size != 0)
1065 plugin->env->duc (plugin->env->cls, 1029 plugin->env->duc (plugin->env->cls, -size);
1066 - size); 1030 }
1067 }
1068} 1031}
1069 1032
1070 1033
@@ -1089,11 +1052,11 @@ execute_select (struct Plugin *plugin,
1089 */ 1052 */
1090static void 1053static void
1091mysql_plugin_get_key (void *cls, 1054mysql_plugin_get_key (void *cls,
1092 uint64_t offset, 1055 uint64_t offset,
1093 const GNUNET_HashCode *key, 1056 const GNUNET_HashCode * key,
1094 const GNUNET_HashCode *vhash, 1057 const GNUNET_HashCode * vhash,
1095 enum GNUNET_BLOCK_Type type, 1058 enum GNUNET_BLOCK_Type type,
1096 PluginDatumProcessor proc, void *proc_cls) 1059 PluginDatumProcessor proc, void *proc_cls)
1097{ 1060{
1098 struct Plugin *plugin = cls; 1061 struct Plugin *plugin = cls;
1099 int ret; 1062 int ret;
@@ -1113,115 +1076,107 @@ mysql_plugin_get_key (void *cls,
1113 cbind[0].buffer = &total; 1076 cbind[0].buffer = &total;
1114 cbind[0].is_unsigned = GNUNET_NO; 1077 cbind[0].is_unsigned = GNUNET_NO;
1115 if (type != 0) 1078 if (type != 0)
1079 {
1080 if (vhash != NULL)
1116 { 1081 {
1117 if (vhash != NULL) 1082 ret =
1118 { 1083 prepared_statement_run_select (plugin,
1119 ret = 1084 plugin->
1120 prepared_statement_run_select (plugin, 1085 count_entry_by_hash_vhash_and_type, 1,
1121 plugin->count_entry_by_hash_vhash_and_type, 1086 cbind, MYSQL_TYPE_BLOB, key, hashSize,
1122 1, cbind, 1087 &hashSize, MYSQL_TYPE_BLOB, vhash,
1123 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 1088 hashSize2, &hashSize2, MYSQL_TYPE_LONG,
1124 MYSQL_TYPE_BLOB, vhash, hashSize2, &hashSize2, 1089 &type, GNUNET_YES, -1);
1125 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1126 -1);
1127 }
1128 else
1129 {
1130 ret =
1131 prepared_statement_run_select (plugin,
1132 plugin->count_entry_by_hash_and_type,
1133 1, cbind,
1134 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1135 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1136 -1);
1137 }
1138 } 1090 }
1091 else
1092 {
1093 ret =
1094 prepared_statement_run_select (plugin,
1095 plugin->count_entry_by_hash_and_type,
1096 1, cbind,
1097 MYSQL_TYPE_BLOB, key, hashSize,
1098 &hashSize, MYSQL_TYPE_LONG, &type,
1099 GNUNET_YES, -1);
1100 }
1101 }
1139 else 1102 else
1103 {
1104 if (vhash != NULL)
1140 { 1105 {
1141 if (vhash != NULL) 1106 ret =
1142 { 1107 prepared_statement_run_select (plugin,
1143 ret = 1108 plugin->count_entry_by_hash_and_vhash,
1144 prepared_statement_run_select (plugin, 1109 1, cbind,
1145 plugin->count_entry_by_hash_and_vhash, 1110 MYSQL_TYPE_BLOB, key, hashSize,
1146 1, cbind, 1111 &hashSize, MYSQL_TYPE_BLOB, vhash,
1147 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 1112 hashSize2, &hashSize2, -1);
1148 MYSQL_TYPE_BLOB, vhash, hashSize2, &hashSize2, 1113
1149 -1);
1150
1151 }
1152 else
1153 {
1154 ret =
1155 prepared_statement_run_select (plugin,
1156 plugin->count_entry_by_hash,
1157 1, cbind,
1158 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1159 -1);
1160 }
1161 } 1114 }
1162 if ((ret != GNUNET_OK) || (0 >= total)) 1115 else
1163 { 1116 {
1164 proc (proc_cls, 1117 ret =
1165 NULL, 0, NULL, 0, 0, 0, 1118 prepared_statement_run_select (plugin,
1166 GNUNET_TIME_UNIT_ZERO_ABS, 0); 1119 plugin->count_entry_by_hash,
1167 return; 1120 1, cbind,
1121 MYSQL_TYPE_BLOB, key, hashSize,
1122 &hashSize, -1);
1168 } 1123 }
1124 }
1125 if ((ret != GNUNET_OK) || (0 >= total))
1126 {
1127 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1128 return;
1129 }
1169 offset = offset % total; 1130 offset = offset % total;
1170 off = (unsigned long long) offset; 1131 off = (unsigned long long) offset;
1171#if DEBUG_MYSQL 1132#if DEBUG_MYSQL
1172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1173 "Obtaining %llu/%lld result for GET `%s'\n", 1134 "Obtaining %llu/%lld result for GET `%s'\n",
1174 off, 1135 off, total, GNUNET_h2s (key));
1175 total,
1176 GNUNET_h2s (key));
1177#endif 1136#endif
1178 1137
1179 if (type != GNUNET_BLOCK_TYPE_ANY) 1138 if (type != GNUNET_BLOCK_TYPE_ANY)
1139 {
1140 if (NULL != vhash)
1180 { 1141 {
1181 if (NULL != vhash) 1142 execute_select (plugin,
1182 { 1143 plugin->select_entry_by_hash_vhash_and_type,
1183 execute_select (plugin, 1144 proc, proc_cls,
1184 plugin->select_entry_by_hash_vhash_and_type, 1145 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1185 proc, proc_cls, 1146 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1186 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 1147 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1187 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize, 1148 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1188 MYSQL_TYPE_LONG, &type, GNUNET_YES, 1149 }
1189 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, 1150 else
1190 -1); 1151 {
1191 } 1152 execute_select (plugin,
1192 else 1153 plugin->select_entry_by_hash_and_type,
1193 { 1154 proc, proc_cls,
1194 execute_select (plugin, 1155 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1195 plugin->select_entry_by_hash_and_type, 1156 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1196 proc, proc_cls, 1157 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1197 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1198 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1199 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
1200 -1);
1201 }
1202 } 1158 }
1159 }
1203 else 1160 else
1161 {
1162 if (NULL != vhash)
1204 { 1163 {
1205 if (NULL != vhash) 1164 execute_select (plugin,
1206 { 1165 plugin->select_entry_by_hash_and_vhash,
1207 execute_select (plugin, 1166 proc, proc_cls,
1208 plugin->select_entry_by_hash_and_vhash, 1167 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1209 proc, proc_cls, 1168 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1210 MYSQL_TYPE_BLOB, key, hashSize, &hashSize, 1169 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1211 MYSQL_TYPE_BLOB, vhash, hashSize, &hashSize,
1212 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
1213 -1);
1214 }
1215 else
1216 {
1217 execute_select (plugin,
1218 plugin->select_entry_by_hash,
1219 proc, proc_cls,
1220 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1221 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES,
1222 -1);
1223 }
1224 } 1170 }
1171 else
1172 {
1173 execute_select (plugin,
1174 plugin->select_entry_by_hash,
1175 proc, proc_cls,
1176 MYSQL_TYPE_BLOB, key, hashSize, &hashSize,
1177 MYSQL_TYPE_LONGLONG, &off, GNUNET_YES, -1);
1178 }
1179 }
1225} 1180}
1226 1181
1227 1182
@@ -1237,21 +1192,22 @@ mysql_plugin_get_key (void *cls,
1237 */ 1192 */
1238static void 1193static void
1239mysql_plugin_get_zero_anonymity (void *cls, 1194mysql_plugin_get_zero_anonymity (void *cls,
1240 uint64_t offset, 1195 uint64_t offset,
1241 enum GNUNET_BLOCK_Type type, 1196 enum GNUNET_BLOCK_Type type,
1242 PluginDatumProcessor proc, void *proc_cls) 1197 PluginDatumProcessor proc, void *proc_cls)
1243{ 1198{
1244 struct Plugin *plugin = cls; 1199 struct Plugin *plugin = cls;
1245 unsigned long long rvalue = (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 1200 unsigned long long rvalue =
1246 UINT64_MAX); 1201 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1202 UINT64_MAX);
1203
1247 execute_select (plugin, 1204 execute_select (plugin,
1248 plugin->zero_iter, 1205 plugin->zero_iter,
1249 proc, proc_cls, 1206 proc, proc_cls,
1250 MYSQL_TYPE_LONG, &type, GNUNET_YES, 1207 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1251 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, 1208 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
1252 MYSQL_TYPE_LONG, &type, GNUNET_YES, 1209 MYSQL_TYPE_LONG, &type, GNUNET_YES,
1253 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, 1210 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
1254 -1);
1255} 1211}
1256 1212
1257 1213
@@ -1260,17 +1216,17 @@ mysql_plugin_get_zero_anonymity (void *cls,
1260 */ 1216 */
1261struct ReplCtx 1217struct ReplCtx
1262{ 1218{
1263 1219
1264 /** 1220 /**
1265 * Plugin handle. 1221 * Plugin handle.
1266 */ 1222 */
1267 struct Plugin *plugin; 1223 struct Plugin *plugin;
1268 1224
1269 /** 1225 /**
1270 * Function to call for the result (or the NULL). 1226 * Function to call for the result (or the NULL).
1271 */ 1227 */
1272 PluginDatumProcessor proc; 1228 PluginDatumProcessor proc;
1273 1229
1274 /** 1230 /**
1275 * Closure for proc. 1231 * Closure for proc.
1276 */ 1232 */
@@ -1300,14 +1256,13 @@ struct ReplCtx
1300 */ 1256 */
1301static int 1257static int
1302repl_proc (void *cls, 1258repl_proc (void *cls,
1303 const GNUNET_HashCode *key, 1259 const GNUNET_HashCode * key,
1304 uint32_t size, 1260 uint32_t size,
1305 const void *data, 1261 const void *data,
1306 enum GNUNET_BLOCK_Type type, 1262 enum GNUNET_BLOCK_Type type,
1307 uint32_t priority, 1263 uint32_t priority,
1308 uint32_t anonymity, 1264 uint32_t anonymity,
1309 struct GNUNET_TIME_Absolute expiration, 1265 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1310 uint64_t uid)
1311{ 1266{
1312 struct ReplCtx *rc = cls; 1267 struct ReplCtx *rc = cls;
1313 struct Plugin *plugin = rc->plugin; 1268 struct Plugin *plugin = rc->plugin;
@@ -1316,25 +1271,21 @@ repl_proc (void *cls,
1316 int iret; 1271 int iret;
1317 1272
1318 ret = rc->proc (rc->proc_cls, 1273 ret = rc->proc (rc->proc_cls,
1319 key, 1274 key, size, data, type, priority, anonymity, expiration, uid);
1320 size, data,
1321 type, priority, anonymity, expiration,
1322 uid);
1323 if (NULL != key) 1275 if (NULL != key)
1276 {
1277 oid = (unsigned long long) uid;
1278 iret = prepared_statement_run (plugin,
1279 plugin->dec_repl,
1280 NULL,
1281 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES, -1);
1282 if (iret == GNUNET_SYSERR)
1324 { 1283 {
1325 oid = (unsigned long long) uid; 1284 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1326 iret = prepared_statement_run (plugin, 1285 "Failed to reduce replication counter\n");
1327 plugin->dec_repl, 1286 return GNUNET_SYSERR;
1328 NULL,
1329 MYSQL_TYPE_LONGLONG, &oid, GNUNET_YES,
1330 -1);
1331 if (iret == GNUNET_SYSERR)
1332 {
1333 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1334 "Failed to reduce replication counter\n");
1335 return GNUNET_SYSERR;
1336 }
1337 } 1287 }
1288 }
1338 return ret; 1289 return ret;
1339} 1290}
1340 1291
@@ -1352,14 +1303,14 @@ repl_proc (void *cls,
1352 */ 1303 */
1353static void 1304static void
1354mysql_plugin_get_replication (void *cls, 1305mysql_plugin_get_replication (void *cls,
1355 PluginDatumProcessor proc, void *proc_cls) 1306 PluginDatumProcessor proc, void *proc_cls)
1356{ 1307{
1357 struct Plugin *plugin = cls; 1308 struct Plugin *plugin = cls;
1358 struct ReplCtx rc; 1309 struct ReplCtx rc;
1359 unsigned long long rvalue; 1310 unsigned long long rvalue;
1360 unsigned long repl; 1311 unsigned long repl;
1361 MYSQL_BIND results; 1312 MYSQL_BIND results;
1362 1313
1363 rc.plugin = plugin; 1314 rc.plugin = plugin;
1364 rc.proc = proc; 1315 rc.proc = proc;
1365 rc.proc_cls = proc_cls; 1316 rc.proc_cls = proc_cls;
@@ -1369,28 +1320,19 @@ mysql_plugin_get_replication (void *cls,
1369 results.is_unsigned = GNUNET_YES; 1320 results.is_unsigned = GNUNET_YES;
1370 1321
1371 if (1 != 1322 if (1 !=
1372 prepared_statement_run_select (plugin, 1323 prepared_statement_run_select (plugin, plugin->max_repl, 1, &results, -1))
1373 plugin->max_repl, 1324 {
1374 1, 1325 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
1375 &results, 1326 return;
1376 -1)) 1327 }
1377 { 1328
1378 proc (proc_cls, 1329 rvalue =
1379 NULL, 0, NULL, 0, 0, 0, 1330 (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
1380 GNUNET_TIME_UNIT_ZERO_ABS, 0); 1331 UINT64_MAX);
1381 return; 1332 execute_select (plugin, plugin->select_replication, &repl_proc, &rc,
1382 } 1333 MYSQL_TYPE_LONG, &repl, GNUNET_YES, MYSQL_TYPE_LONGLONG,
1383 1334 &rvalue, GNUNET_YES, MYSQL_TYPE_LONG, &repl, GNUNET_YES,
1384 rvalue = (unsigned long long) GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 1335 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES, -1);
1385 UINT64_MAX);
1386 execute_select (plugin,
1387 plugin->select_replication,
1388 &repl_proc, &rc,
1389 MYSQL_TYPE_LONG, &repl, GNUNET_YES,
1390 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
1391 MYSQL_TYPE_LONG, &repl, GNUNET_YES,
1392 MYSQL_TYPE_LONGLONG, &rvalue, GNUNET_YES,
1393 -1);
1394 1336
1395} 1337}
1396 1338
@@ -1400,17 +1342,17 @@ mysql_plugin_get_replication (void *cls,
1400 */ 1342 */
1401struct ExpiCtx 1343struct ExpiCtx
1402{ 1344{
1403 1345
1404 /** 1346 /**
1405 * Plugin handle. 1347 * Plugin handle.
1406 */ 1348 */
1407 struct Plugin *plugin; 1349 struct Plugin *plugin;
1408 1350
1409 /** 1351 /**
1410 * Function to call for the result (or the NULL). 1352 * Function to call for the result (or the NULL).
1411 */ 1353 */
1412 PluginDatumProcessor proc; 1354 PluginDatumProcessor proc;
1413 1355
1414 /** 1356 /**
1415 * Closure for proc. 1357 * Closure for proc.
1416 */ 1358 */
@@ -1441,31 +1383,25 @@ struct ExpiCtx
1441 */ 1383 */
1442static int 1384static int
1443expi_proc (void *cls, 1385expi_proc (void *cls,
1444 const GNUNET_HashCode *key, 1386 const GNUNET_HashCode * key,
1445 uint32_t size, 1387 uint32_t size,
1446 const void *data, 1388 const void *data,
1447 enum GNUNET_BLOCK_Type type, 1389 enum GNUNET_BLOCK_Type type,
1448 uint32_t priority, 1390 uint32_t priority,
1449 uint32_t anonymity, 1391 uint32_t anonymity,
1450 struct GNUNET_TIME_Absolute expiration, 1392 struct GNUNET_TIME_Absolute expiration, uint64_t uid)
1451 uint64_t uid)
1452{ 1393{
1453 struct ExpiCtx *rc = cls; 1394 struct ExpiCtx *rc = cls;
1454 struct Plugin *plugin = rc->plugin; 1395 struct Plugin *plugin = rc->plugin;
1455 1396
1456 if (NULL == key) 1397 if (NULL == key)
1457 { 1398 {
1458 execute_select (plugin, 1399 execute_select (plugin,
1459 plugin->select_priority, 1400 plugin->select_priority, rc->proc, rc->proc_cls, -1);
1460 rc->proc, rc->proc_cls, 1401 return GNUNET_SYSERR;
1461 -1); 1402 }
1462 return GNUNET_SYSERR;
1463 }
1464 return rc->proc (rc->proc_cls, 1403 return rc->proc (rc->proc_cls,
1465 key, 1404 key, size, data, type, priority, anonymity, expiration, uid);
1466 size, data,
1467 type, priority, anonymity, expiration,
1468 uid);
1469} 1405}
1470 1406
1471 1407
@@ -1479,21 +1415,19 @@ expi_proc (void *cls,
1479 */ 1415 */
1480static void 1416static void
1481mysql_plugin_get_expiration (void *cls, 1417mysql_plugin_get_expiration (void *cls,
1482 PluginDatumProcessor proc, void *proc_cls) 1418 PluginDatumProcessor proc, void *proc_cls)
1483{ 1419{
1484 struct Plugin *plugin = cls; 1420 struct Plugin *plugin = cls;
1485 long long nt; 1421 long long nt;
1486 struct ExpiCtx rc; 1422 struct ExpiCtx rc;
1487 1423
1488 rc.plugin = plugin; 1424 rc.plugin = plugin;
1489 rc.proc = proc; 1425 rc.proc = proc;
1490 rc.proc_cls = proc_cls; 1426 rc.proc_cls = proc_cls;
1491 nt = (long long) GNUNET_TIME_absolute_get().abs_value; 1427 nt = (long long) GNUNET_TIME_absolute_get ().abs_value;
1492 execute_select (plugin, 1428 execute_select (plugin,
1493 plugin->select_expiration, 1429 plugin->select_expiration,
1494 expi_proc, &rc, 1430 expi_proc, &rc, MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES, -1);
1495 MYSQL_TYPE_LONGLONG, &nt, GNUNET_YES,
1496 -1);
1497 1431
1498} 1432}
1499 1433
@@ -1503,14 +1437,13 @@ mysql_plugin_get_expiration (void *cls,
1503 * 1437 *
1504 * @param cls the "struct Plugin*" 1438 * @param cls the "struct Plugin*"
1505 */ 1439 */
1506static void 1440static void
1507mysql_plugin_drop (void *cls) 1441mysql_plugin_drop (void *cls)
1508{ 1442{
1509 struct Plugin *plugin = cls; 1443 struct Plugin *plugin = cls;
1510 1444
1511 if (GNUNET_OK != run_statement (plugin, 1445 if (GNUNET_OK != run_statement (plugin, "DROP TABLE gn090"))
1512 "DROP TABLE gn090")) 1446 return; /* error */
1513 return; /* error */
1514 plugin->env->duc (plugin->env->cls, 0); 1447 plugin->env->duc (plugin->env->cls, 0);
1515} 1448}
1516 1449
@@ -1532,12 +1465,12 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1532 plugin->env = env; 1465 plugin->env = env;
1533 plugin->cnffile = get_my_cnf_path (env->cfg); 1466 plugin->cnffile = get_my_cnf_path (env->cfg);
1534 if (GNUNET_OK != iopen (plugin)) 1467 if (GNUNET_OK != iopen (plugin))
1535 { 1468 {
1536 iclose (plugin); 1469 iclose (plugin);
1537 GNUNET_free_non_null (plugin->cnffile); 1470 GNUNET_free_non_null (plugin->cnffile);
1538 GNUNET_free (plugin); 1471 GNUNET_free (plugin);
1539 return NULL; 1472 return NULL;
1540 } 1473 }
1541#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) 1474#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
1542#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) 1475#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
1543 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 (" 1476 if (MRUNS ("CREATE TABLE IF NOT EXISTS gn090 ("
@@ -1565,29 +1498,32 @@ libgnunet_plugin_datastore_mysql_init (void *cls)
1565 PINIT (plugin->insert_entry, INSERT_ENTRY) || 1498 PINIT (plugin->insert_entry, INSERT_ENTRY) ||
1566 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || 1499 PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) ||
1567 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || 1500 PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) ||
1568 PINIT (plugin->select_entry_by_hash_and_vhash, SELECT_ENTRY_BY_HASH_AND_VHASH) 1501 PINIT (plugin->select_entry_by_hash_and_vhash,
1569 || PINIT (plugin->select_entry_by_hash_and_type, SELECT_ENTRY_BY_HASH_AND_TYPE) 1502 SELECT_ENTRY_BY_HASH_AND_VHASH) ||
1570 || PINIT (plugin->select_entry_by_hash_vhash_and_type, 1503 PINIT (plugin->select_entry_by_hash_and_type,
1571 SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE) 1504 SELECT_ENTRY_BY_HASH_AND_TYPE) ||
1572 || PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH) 1505 PINIT (plugin->select_entry_by_hash_vhash_and_type,
1573 || PINIT (plugin->get_size, SELECT_SIZE) 1506 SELECT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
1574 || PINIT (plugin->count_entry_by_hash_and_vhash, COUNT_ENTRY_BY_HASH_AND_VHASH) 1507 PINIT (plugin->count_entry_by_hash, COUNT_ENTRY_BY_HASH) ||
1575 || PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE) 1508 PINIT (plugin->get_size, SELECT_SIZE) ||
1509 PINIT (plugin->count_entry_by_hash_and_vhash,
1510 COUNT_ENTRY_BY_HASH_AND_VHASH) ||
1511 PINIT (plugin->count_entry_by_hash_and_type, COUNT_ENTRY_BY_HASH_AND_TYPE)
1576 || PINIT (plugin->count_entry_by_hash_vhash_and_type, 1512 || PINIT (plugin->count_entry_by_hash_vhash_and_type,
1577 COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE) 1513 COUNT_ENTRY_BY_HASH_VHASH_AND_TYPE) ||
1578 || PINIT (plugin->update_entry, UPDATE_ENTRY) 1514 PINIT (plugin->update_entry, UPDATE_ENTRY) ||
1579 || PINIT (plugin->dec_repl, DEC_REPL) 1515 PINIT (plugin->dec_repl, DEC_REPL) ||
1580 || PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) 1516 PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) ||
1581 || PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) 1517 PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) ||
1582 || PINIT (plugin->select_priority, SELECT_IT_PRIORITY) 1518 PINIT (plugin->select_priority, SELECT_IT_PRIORITY) ||
1583 || PINIT (plugin->max_repl, SELECT_MAX_REPL) 1519 PINIT (plugin->max_repl, SELECT_MAX_REPL) ||
1584 || PINIT (plugin->select_replication, SELECT_IT_REPLICATION) ) 1520 PINIT (plugin->select_replication, SELECT_IT_REPLICATION))
1585 { 1521 {
1586 iclose (plugin); 1522 iclose (plugin);
1587 GNUNET_free_non_null (plugin->cnffile); 1523 GNUNET_free_non_null (plugin->cnffile);
1588 GNUNET_free (plugin); 1524 GNUNET_free (plugin);
1589 return NULL; 1525 return NULL;
1590 } 1526 }
1591#undef PINIT 1527#undef PINIT
1592#undef MRUNS 1528#undef MRUNS
1593 1529
@@ -1621,13 +1557,11 @@ libgnunet_plugin_datastore_mysql_done (void *cls)
1621 1557
1622 iclose (plugin); 1558 iclose (plugin);
1623 while (NULL != (s = plugin->shead)) 1559 while (NULL != (s = plugin->shead))
1624 { 1560 {
1625 GNUNET_CONTAINER_DLL_remove (plugin->shead, 1561 GNUNET_CONTAINER_DLL_remove (plugin->shead, plugin->stail, s);
1626 plugin->stail, 1562 GNUNET_free (s->query);
1627 s); 1563 GNUNET_free (s);
1628 GNUNET_free (s->query); 1564 }
1629 GNUNET_free (s);
1630 }
1631 GNUNET_free_non_null (plugin->cnffile); 1565 GNUNET_free_non_null (plugin->cnffile);
1632 GNUNET_free (plugin); 1566 GNUNET_free (plugin);
1633 GNUNET_free (api); 1567 GNUNET_free (api);