diff options
Diffstat (limited to 'src/datastore/plugin_datastore_mysql.c')
-rw-r--r-- | src/datastore/plugin_datastore_mysql.c | 1007 |
1 files changed, 507 insertions, 500 deletions
diff --git a/src/datastore/plugin_datastore_mysql.c b/src/datastore/plugin_datastore_mysql.c index cc5b558ee..6aec09c54 100644 --- a/src/datastore/plugin_datastore_mysql.c +++ b/src/datastore/plugin_datastore_mysql.c | |||
@@ -129,7 +129,8 @@ | |||
129 | /** | 129 | /** |
130 | * Context for all functions in this plugin. | 130 | * Context for all functions in this plugin. |
131 | */ | 131 | */ |
132 | struct Plugin { | 132 | struct Plugin |
133 | { | ||
133 | /** | 134 | /** |
134 | * Our execution environment. | 135 | * Our execution environment. |
135 | */ | 136 | */ |
@@ -143,7 +144,8 @@ struct Plugin { | |||
143 | /** | 144 | /** |
144 | * Prepared statements. | 145 | * Prepared statements. |
145 | */ | 146 | */ |
146 | #define INSERT_ENTRY "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" | 147 | #define INSERT_ENTRY \ |
148 | "INSERT INTO gn090 (repl,type,prio,anonLevel,expire,rvalue,hash,vhash,value) VALUES (?,?,?,?,?,?,?,?,?)" | ||
147 | struct GNUNET_MYSQL_StatementHandle *insert_entry; | 149 | struct GNUNET_MYSQL_StatementHandle *insert_entry; |
148 | 150 | ||
149 | #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" | 151 | #define DELETE_ENTRY_BY_UID "DELETE FROM gn090 WHERE uid=?" |
@@ -238,29 +240,29 @@ struct Plugin { | |||
238 | * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists, #GNUNET_SYSERR on error | 240 | * @return #GNUNET_OK on success, #GNUNET_NO if no such value exists, #GNUNET_SYSERR on error |
239 | */ | 241 | */ |
240 | static int | 242 | static int |
241 | do_delete_entry(struct Plugin *plugin, | 243 | do_delete_entry (struct Plugin *plugin, |
242 | unsigned long long uid) | 244 | unsigned long long uid) |
243 | { | 245 | { |
244 | int ret; | 246 | int ret; |
245 | uint64_t uid64 = (uint64_t)uid; | 247 | uint64_t uid64 = (uint64_t) uid; |
246 | struct GNUNET_MY_QueryParam params_delete[] = { | 248 | struct GNUNET_MY_QueryParam params_delete[] = { |
247 | GNUNET_MY_query_param_uint64(&uid64), | 249 | GNUNET_MY_query_param_uint64 (&uid64), |
248 | GNUNET_MY_query_param_end | 250 | GNUNET_MY_query_param_end |
249 | }; | 251 | }; |
250 | 252 | ||
251 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
252 | "Deleting value %llu from gn090 table\n", | 254 | "Deleting value %llu from gn090 table\n", |
253 | uid); | 255 | uid); |
254 | ret = GNUNET_MY_exec_prepared(plugin->mc, | 256 | ret = GNUNET_MY_exec_prepared (plugin->mc, |
255 | plugin->delete_entry_by_uid, | 257 | plugin->delete_entry_by_uid, |
256 | params_delete); | 258 | params_delete); |
257 | if (ret >= 0) | 259 | if (ret >= 0) |
258 | { | 260 | { |
259 | return GNUNET_OK; | 261 | return GNUNET_OK; |
260 | } | 262 | } |
261 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
262 | "Deleting value %llu from gn090 table failed\n", | 264 | "Deleting value %llu from gn090 table failed\n", |
263 | (unsigned long long)uid); | 265 | (unsigned long long) uid); |
264 | return ret; | 266 | return ret; |
265 | } | 267 | } |
266 | 268 | ||
@@ -273,8 +275,8 @@ do_delete_entry(struct Plugin *plugin, | |||
273 | * @return number of bytes used on disk | 275 | * @return number of bytes used on disk |
274 | */ | 276 | */ |
275 | static void | 277 | static void |
276 | mysql_plugin_estimate_size(void *cls, | 278 | mysql_plugin_estimate_size (void *cls, |
277 | unsigned long long *estimate) | 279 | unsigned long long *estimate) |
278 | { | 280 | { |
279 | struct Plugin *plugin = cls; | 281 | struct Plugin *plugin = cls; |
280 | uint64_t total; | 282 | uint64_t total; |
@@ -283,29 +285,29 @@ mysql_plugin_estimate_size(void *cls, | |||
283 | GNUNET_MY_query_param_end | 285 | GNUNET_MY_query_param_end |
284 | }; | 286 | }; |
285 | struct GNUNET_MY_ResultSpec results_get[] = { | 287 | struct GNUNET_MY_ResultSpec results_get[] = { |
286 | GNUNET_MY_result_spec_uint64(&total), | 288 | GNUNET_MY_result_spec_uint64 (&total), |
287 | GNUNET_MY_result_spec_end | 289 | GNUNET_MY_result_spec_end |
288 | }; | 290 | }; |
289 | 291 | ||
290 | ret = GNUNET_MY_exec_prepared(plugin->mc, | 292 | ret = GNUNET_MY_exec_prepared (plugin->mc, |
291 | plugin->get_size, | 293 | plugin->get_size, |
292 | params_get); | 294 | params_get); |
293 | *estimate = 0; | 295 | *estimate = 0; |
294 | total = UINT64_MAX; | 296 | total = UINT64_MAX; |
295 | if ((GNUNET_OK == ret) && | 297 | if ((GNUNET_OK == ret) && |
296 | (GNUNET_OK == | 298 | (GNUNET_OK == |
297 | GNUNET_MY_extract_result(plugin->get_size, | 299 | GNUNET_MY_extract_result (plugin->get_size, |
298 | results_get))) | 300 | results_get))) |
299 | { | 301 | { |
300 | *estimate = (unsigned long long)total; | 302 | *estimate = (unsigned long long) total; |
301 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
302 | "Size estimate for MySQL payload is %lld\n", | 304 | "Size estimate for MySQL payload is %lld\n", |
303 | (long long)total); | 305 | (long long) total); |
304 | GNUNET_assert(UINT64_MAX != total); | 306 | GNUNET_assert (UINT64_MAX != total); |
305 | GNUNET_break(GNUNET_NO == | 307 | GNUNET_break (GNUNET_NO == |
306 | GNUNET_MY_extract_result(plugin->get_size, | 308 | GNUNET_MY_extract_result (plugin->get_size, |
307 | NULL)); | 309 | NULL)); |
308 | } | 310 | } |
309 | } | 311 | } |
310 | 312 | ||
311 | 313 | ||
@@ -326,116 +328,116 @@ mysql_plugin_estimate_size(void *cls, | |||
326 | * @param cont_cls closure for @a cont | 328 | * @param cont_cls closure for @a cont |
327 | */ | 329 | */ |
328 | static void | 330 | static void |
329 | mysql_plugin_put(void *cls, | 331 | mysql_plugin_put (void *cls, |
330 | const struct GNUNET_HashCode *key, | 332 | const struct GNUNET_HashCode *key, |
331 | bool absent, | 333 | bool absent, |
332 | uint32_t size, | 334 | uint32_t size, |
333 | const void *data, | 335 | const void *data, |
334 | enum GNUNET_BLOCK_Type type, | 336 | enum GNUNET_BLOCK_Type type, |
335 | uint32_t priority, | 337 | uint32_t priority, |
336 | uint32_t anonymity, | 338 | uint32_t anonymity, |
337 | uint32_t replication, | 339 | uint32_t replication, |
338 | struct GNUNET_TIME_Absolute expiration, | 340 | struct GNUNET_TIME_Absolute expiration, |
339 | PluginPutCont cont, | 341 | PluginPutCont cont, |
340 | void *cont_cls) | 342 | void *cont_cls) |
341 | { | 343 | { |
342 | struct Plugin *plugin = cls; | 344 | struct Plugin *plugin = cls; |
343 | uint64_t lexpiration = expiration.abs_value_us; | 345 | uint64_t lexpiration = expiration.abs_value_us; |
344 | struct GNUNET_HashCode vhash; | 346 | struct GNUNET_HashCode vhash; |
345 | 347 | ||
346 | GNUNET_CRYPTO_hash(data, | 348 | GNUNET_CRYPTO_hash (data, |
347 | size, | 349 | size, |
348 | &vhash); | 350 | &vhash); |
349 | if (!absent) | 351 | if (! absent) |
352 | { | ||
353 | struct GNUNET_MY_QueryParam params_update[] = { | ||
354 | GNUNET_MY_query_param_uint32 (&priority), | ||
355 | GNUNET_MY_query_param_uint32 (&replication), | ||
356 | GNUNET_MY_query_param_uint64 (&lexpiration), | ||
357 | GNUNET_MY_query_param_auto_from_type (key), | ||
358 | GNUNET_MY_query_param_auto_from_type (&vhash), | ||
359 | GNUNET_MY_query_param_end | ||
360 | }; | ||
361 | |||
362 | if (GNUNET_OK != | ||
363 | GNUNET_MY_exec_prepared (plugin->mc, | ||
364 | plugin->update_entry, | ||
365 | params_update)) | ||
350 | { | 366 | { |
351 | struct GNUNET_MY_QueryParam params_update[] = { | 367 | cont (cont_cls, |
352 | GNUNET_MY_query_param_uint32(&priority), | 368 | key, |
353 | GNUNET_MY_query_param_uint32(&replication), | 369 | size, |
354 | GNUNET_MY_query_param_uint64(&lexpiration), | 370 | GNUNET_SYSERR, |
355 | GNUNET_MY_query_param_auto_from_type(key), | 371 | _ ("MySQL statement run failure")); |
356 | GNUNET_MY_query_param_auto_from_type(&vhash), | 372 | return; |
357 | GNUNET_MY_query_param_end | 373 | } |
358 | }; | 374 | |
359 | 375 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt (plugin->update_entry); | |
360 | if (GNUNET_OK != | 376 | my_ulonglong rows = mysql_stmt_affected_rows (stmt); |
361 | GNUNET_MY_exec_prepared(plugin->mc, | 377 | |
362 | plugin->update_entry, | 378 | GNUNET_break (GNUNET_NO == |
363 | params_update)) | 379 | GNUNET_MY_extract_result (plugin->update_entry, |
364 | { | ||
365 | cont(cont_cls, | ||
366 | key, | ||
367 | size, | ||
368 | GNUNET_SYSERR, | ||
369 | _("MySQL statement run failure")); | ||
370 | return; | ||
371 | } | ||
372 | |||
373 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->update_entry); | ||
374 | my_ulonglong rows = mysql_stmt_affected_rows(stmt); | ||
375 | |||
376 | GNUNET_break(GNUNET_NO == | ||
377 | GNUNET_MY_extract_result(plugin->update_entry, | ||
378 | NULL)); | 380 | NULL)); |
379 | if (0 != rows) | 381 | if (0 != rows) |
380 | { | 382 | { |
381 | cont(cont_cls, | 383 | cont (cont_cls, |
382 | key, | 384 | key, |
383 | size, | 385 | size, |
384 | GNUNET_NO, | 386 | GNUNET_NO, |
385 | NULL); | 387 | NULL); |
386 | return; | 388 | return; |
387 | } | ||
388 | } | 389 | } |
390 | } | ||
389 | 391 | ||
390 | uint64_t lrvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 392 | uint64_t lrvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
391 | UINT64_MAX); | 393 | UINT64_MAX); |
392 | struct GNUNET_MY_QueryParam params_insert[] = { | 394 | struct GNUNET_MY_QueryParam params_insert[] = { |
393 | GNUNET_MY_query_param_uint32(&replication), | 395 | GNUNET_MY_query_param_uint32 (&replication), |
394 | GNUNET_MY_query_param_uint32(&type), | 396 | GNUNET_MY_query_param_uint32 (&type), |
395 | GNUNET_MY_query_param_uint32(&priority), | 397 | GNUNET_MY_query_param_uint32 (&priority), |
396 | GNUNET_MY_query_param_uint32(&anonymity), | 398 | GNUNET_MY_query_param_uint32 (&anonymity), |
397 | GNUNET_MY_query_param_uint64(&lexpiration), | 399 | GNUNET_MY_query_param_uint64 (&lexpiration), |
398 | GNUNET_MY_query_param_uint64(&lrvalue), | 400 | GNUNET_MY_query_param_uint64 (&lrvalue), |
399 | GNUNET_MY_query_param_auto_from_type(key), | 401 | GNUNET_MY_query_param_auto_from_type (key), |
400 | GNUNET_MY_query_param_auto_from_type(&vhash), | 402 | GNUNET_MY_query_param_auto_from_type (&vhash), |
401 | GNUNET_MY_query_param_fixed_size(data, size), | 403 | GNUNET_MY_query_param_fixed_size (data, size), |
402 | GNUNET_MY_query_param_end | 404 | GNUNET_MY_query_param_end |
403 | }; | 405 | }; |
404 | 406 | ||
405 | if (size > MAX_DATUM_SIZE) | 407 | if (size > MAX_DATUM_SIZE) |
406 | { | 408 | { |
407 | GNUNET_break(0); | 409 | GNUNET_break (0); |
408 | cont(cont_cls, key, size, GNUNET_SYSERR, _("Data too large")); | 410 | cont (cont_cls, key, size, GNUNET_SYSERR, _ ("Data too large")); |
409 | return; | 411 | return; |
410 | } | 412 | } |
411 | 413 | ||
412 | if (GNUNET_OK != | 414 | if (GNUNET_OK != |
413 | GNUNET_MY_exec_prepared(plugin->mc, | 415 | GNUNET_MY_exec_prepared (plugin->mc, |
414 | plugin->insert_entry, | 416 | plugin->insert_entry, |
415 | params_insert)) | 417 | params_insert)) |
416 | { | 418 | { |
417 | cont(cont_cls, | 419 | cont (cont_cls, |
418 | key, | 420 | key, |
419 | size, | 421 | size, |
420 | GNUNET_SYSERR, | 422 | GNUNET_SYSERR, |
421 | _("MySQL statement run failure")); | 423 | _ ("MySQL statement run failure")); |
422 | return; | 424 | return; |
423 | } | 425 | } |
424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
425 | "Inserted value `%s' with size %u into gn090 table\n", | 427 | "Inserted value `%s' with size %u into gn090 table\n", |
426 | GNUNET_h2s(key), | 428 | GNUNET_h2s (key), |
427 | (unsigned int)size); | 429 | (unsigned int) size); |
428 | if (size > 0) | 430 | if (size > 0) |
429 | plugin->env->duc(plugin->env->cls, | 431 | plugin->env->duc (plugin->env->cls, |
430 | size); | 432 | size); |
431 | GNUNET_break(GNUNET_NO == | 433 | GNUNET_break (GNUNET_NO == |
432 | GNUNET_MY_extract_result(plugin->insert_entry, | 434 | GNUNET_MY_extract_result (plugin->insert_entry, |
433 | NULL)); | 435 | NULL)); |
434 | cont(cont_cls, | 436 | cont (cont_cls, |
435 | key, | 437 | key, |
436 | size, | 438 | size, |
437 | GNUNET_OK, | 439 | GNUNET_OK, |
438 | NULL); | 440 | NULL); |
439 | } | 441 | } |
440 | 442 | ||
441 | 443 | ||
@@ -450,11 +452,11 @@ mysql_plugin_put(void *cls, | |||
450 | * @param params_select arguments to initialize stmt | 452 | * @param params_select arguments to initialize stmt |
451 | */ | 453 | */ |
452 | static void | 454 | static void |
453 | execute_select(struct Plugin *plugin, | 455 | execute_select (struct Plugin *plugin, |
454 | struct GNUNET_MYSQL_StatementHandle *stmt, | 456 | struct GNUNET_MYSQL_StatementHandle *stmt, |
455 | PluginDatumProcessor proc, | 457 | PluginDatumProcessor proc, |
456 | void *proc_cls, | 458 | void *proc_cls, |
457 | struct GNUNET_MY_QueryParam *params_select) | 459 | struct GNUNET_MY_QueryParam *params_select) |
458 | { | 460 | { |
459 | int ret; | 461 | int ret; |
460 | uint32_t replication; | 462 | uint32_t replication; |
@@ -467,65 +469,65 @@ execute_select(struct Plugin *plugin, | |||
467 | struct GNUNET_HashCode key; | 469 | struct GNUNET_HashCode key; |
468 | struct GNUNET_TIME_Absolute expiration; | 470 | struct GNUNET_TIME_Absolute expiration; |
469 | struct GNUNET_MY_ResultSpec results_select[] = { | 471 | struct GNUNET_MY_ResultSpec results_select[] = { |
470 | GNUNET_MY_result_spec_uint32(&replication), | 472 | GNUNET_MY_result_spec_uint32 (&replication), |
471 | GNUNET_MY_result_spec_uint32(&type), | 473 | GNUNET_MY_result_spec_uint32 (&type), |
472 | GNUNET_MY_result_spec_uint32(&priority), | 474 | GNUNET_MY_result_spec_uint32 (&priority), |
473 | GNUNET_MY_result_spec_uint32(&anonymity), | 475 | GNUNET_MY_result_spec_uint32 (&anonymity), |
474 | GNUNET_MY_result_spec_absolute_time(&expiration), | 476 | GNUNET_MY_result_spec_absolute_time (&expiration), |
475 | GNUNET_MY_result_spec_auto_from_type(&key), | 477 | GNUNET_MY_result_spec_auto_from_type (&key), |
476 | GNUNET_MY_result_spec_variable_size(&value, &value_size), | 478 | GNUNET_MY_result_spec_variable_size (&value, &value_size), |
477 | GNUNET_MY_result_spec_uint64(&uid), | 479 | GNUNET_MY_result_spec_uint64 (&uid), |
478 | GNUNET_MY_result_spec_end | 480 | GNUNET_MY_result_spec_end |
479 | }; | 481 | }; |
480 | 482 | ||
481 | ret = GNUNET_MY_exec_prepared(plugin->mc, | 483 | ret = GNUNET_MY_exec_prepared (plugin->mc, |
482 | stmt, | 484 | stmt, |
483 | params_select); | 485 | params_select); |
484 | if (GNUNET_OK != ret) | 486 | if (GNUNET_OK != ret) |
485 | { | 487 | { |
486 | proc(proc_cls, | 488 | proc (proc_cls, |
487 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 489 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
488 | return; | 490 | return; |
489 | } | 491 | } |
490 | 492 | ||
491 | ret = GNUNET_MY_extract_result(stmt, | 493 | ret = GNUNET_MY_extract_result (stmt, |
492 | results_select); | 494 | results_select); |
493 | if (GNUNET_OK != ret) | 495 | if (GNUNET_OK != ret) |
494 | { | 496 | { |
495 | proc(proc_cls, | 497 | proc (proc_cls, |
496 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 498 | NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
497 | return; | 499 | return; |
498 | } | 500 | } |
499 | 501 | ||
500 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
501 | "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", | 503 | "Found %u-byte value under key `%s' with prio %u, anon %u, expire %s selecting from gn090 table\n", |
502 | (unsigned int)value_size, | 504 | (unsigned int) value_size, |
503 | GNUNET_h2s(&key), | 505 | GNUNET_h2s (&key), |
504 | (unsigned int)priority, | 506 | (unsigned int) priority, |
505 | (unsigned int)anonymity, | 507 | (unsigned int) anonymity, |
506 | GNUNET_STRINGS_absolute_time_to_string(expiration)); | 508 | GNUNET_STRINGS_absolute_time_to_string (expiration)); |
507 | GNUNET_assert(value_size < MAX_DATUM_SIZE); | 509 | GNUNET_assert (value_size < MAX_DATUM_SIZE); |
508 | GNUNET_break(GNUNET_NO == | 510 | GNUNET_break (GNUNET_NO == |
509 | GNUNET_MY_extract_result(stmt, | 511 | GNUNET_MY_extract_result (stmt, |
510 | NULL)); | 512 | NULL)); |
511 | ret = proc(proc_cls, | 513 | ret = proc (proc_cls, |
512 | &key, | 514 | &key, |
513 | value_size, | 515 | value_size, |
514 | value, | 516 | value, |
515 | type, | 517 | type, |
516 | priority, | 518 | priority, |
517 | anonymity, | 519 | anonymity, |
518 | replication, | 520 | replication, |
519 | expiration, | 521 | expiration, |
520 | uid); | 522 | uid); |
521 | GNUNET_MY_cleanup_result(results_select); | 523 | GNUNET_MY_cleanup_result (results_select); |
522 | if (GNUNET_NO == ret) | 524 | if (GNUNET_NO == ret) |
523 | { | 525 | { |
524 | do_delete_entry(plugin, uid); | 526 | do_delete_entry (plugin, uid); |
525 | if (0 != value_size) | 527 | if (0 != value_size) |
526 | plugin->env->duc(plugin->env->cls, | 528 | plugin->env->duc (plugin->env->cls, |
527 | -value_size); | 529 | -value_size); |
528 | } | 530 | } |
529 | } | 531 | } |
530 | 532 | ||
531 | 533 | ||
@@ -543,74 +545,74 @@ execute_select(struct Plugin *plugin, | |||
543 | * @param proc_cls closure for @a proc | 545 | * @param proc_cls closure for @a proc |
544 | */ | 546 | */ |
545 | static void | 547 | static void |
546 | mysql_plugin_get_key(void *cls, | 548 | mysql_plugin_get_key (void *cls, |
547 | uint64_t next_uid, | 549 | uint64_t next_uid, |
548 | bool random, | 550 | bool random, |
549 | const struct GNUNET_HashCode *key, | 551 | const struct GNUNET_HashCode *key, |
550 | enum GNUNET_BLOCK_Type type, | 552 | enum GNUNET_BLOCK_Type type, |
551 | PluginDatumProcessor proc, | 553 | PluginDatumProcessor proc, |
552 | void *proc_cls) | 554 | void *proc_cls) |
553 | { | 555 | { |
554 | struct Plugin *plugin = cls; | 556 | struct Plugin *plugin = cls; |
555 | uint64_t rvalue; | 557 | uint64_t rvalue; |
556 | 558 | ||
557 | if (random) | 559 | if (random) |
558 | { | 560 | { |
559 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 561 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
560 | UINT64_MAX); | 562 | UINT64_MAX); |
561 | next_uid = 0; | 563 | next_uid = 0; |
562 | } | 564 | } |
563 | else | 565 | else |
564 | rvalue = 0; | 566 | rvalue = 0; |
565 | 567 | ||
566 | if (NULL == key) | 568 | if (NULL == key) |
567 | { | 569 | { |
568 | struct GNUNET_MY_QueryParam params_select[] = { | 570 | struct GNUNET_MY_QueryParam params_select[] = { |
569 | GNUNET_MY_query_param_uint64(&next_uid), | 571 | GNUNET_MY_query_param_uint64 (&next_uid), |
570 | GNUNET_MY_query_param_uint64(&rvalue), | 572 | GNUNET_MY_query_param_uint64 (&rvalue), |
571 | GNUNET_MY_query_param_uint64(&rvalue), | 573 | GNUNET_MY_query_param_uint64 (&rvalue), |
572 | GNUNET_MY_query_param_end | 574 | GNUNET_MY_query_param_end |
573 | }; | 575 | }; |
574 | 576 | ||
575 | execute_select(plugin, | 577 | execute_select (plugin, |
576 | plugin->select_entry, | 578 | plugin->select_entry, |
577 | proc, | 579 | proc, |
578 | proc_cls, | 580 | proc_cls, |
579 | params_select); | 581 | params_select); |
580 | } | 582 | } |
581 | else if (type != GNUNET_BLOCK_TYPE_ANY) | 583 | else if (type != GNUNET_BLOCK_TYPE_ANY) |
582 | { | 584 | { |
583 | struct GNUNET_MY_QueryParam params_select[] = { | 585 | struct GNUNET_MY_QueryParam params_select[] = { |
584 | GNUNET_MY_query_param_auto_from_type(key), | 586 | GNUNET_MY_query_param_auto_from_type (key), |
585 | GNUNET_MY_query_param_uint32(&type), | 587 | GNUNET_MY_query_param_uint32 (&type), |
586 | GNUNET_MY_query_param_uint64(&next_uid), | 588 | GNUNET_MY_query_param_uint64 (&next_uid), |
587 | GNUNET_MY_query_param_uint64(&rvalue), | 589 | GNUNET_MY_query_param_uint64 (&rvalue), |
588 | GNUNET_MY_query_param_uint64(&rvalue), | 590 | GNUNET_MY_query_param_uint64 (&rvalue), |
589 | GNUNET_MY_query_param_end | 591 | GNUNET_MY_query_param_end |
590 | }; | 592 | }; |
591 | 593 | ||
592 | execute_select(plugin, | 594 | execute_select (plugin, |
593 | plugin->select_entry_by_hash_and_type, | 595 | plugin->select_entry_by_hash_and_type, |
594 | proc, | 596 | proc, |
595 | proc_cls, | 597 | proc_cls, |
596 | params_select); | 598 | params_select); |
597 | } | 599 | } |
598 | else | 600 | else |
599 | { | 601 | { |
600 | struct GNUNET_MY_QueryParam params_select[] = { | 602 | struct GNUNET_MY_QueryParam params_select[] = { |
601 | GNUNET_MY_query_param_auto_from_type(key), | 603 | GNUNET_MY_query_param_auto_from_type (key), |
602 | GNUNET_MY_query_param_uint64(&next_uid), | 604 | GNUNET_MY_query_param_uint64 (&next_uid), |
603 | GNUNET_MY_query_param_uint64(&rvalue), | 605 | GNUNET_MY_query_param_uint64 (&rvalue), |
604 | GNUNET_MY_query_param_uint64(&rvalue), | 606 | GNUNET_MY_query_param_uint64 (&rvalue), |
605 | GNUNET_MY_query_param_end | 607 | GNUNET_MY_query_param_end |
606 | }; | 608 | }; |
607 | 609 | ||
608 | execute_select(plugin, | 610 | execute_select (plugin, |
609 | plugin->select_entry_by_hash, | 611 | plugin->select_entry_by_hash, |
610 | proc, | 612 | proc, |
611 | proc_cls, | 613 | proc_cls, |
612 | params_select); | 614 | params_select); |
613 | } | 615 | } |
614 | } | 616 | } |
615 | 617 | ||
616 | 618 | ||
@@ -626,33 +628,34 @@ mysql_plugin_get_key(void *cls, | |||
626 | * @param proc_cls closure for @a proc | 628 | * @param proc_cls closure for @a proc |
627 | */ | 629 | */ |
628 | static void | 630 | static void |
629 | mysql_plugin_get_zero_anonymity(void *cls, | 631 | mysql_plugin_get_zero_anonymity (void *cls, |
630 | uint64_t next_uid, | 632 | uint64_t next_uid, |
631 | enum GNUNET_BLOCK_Type type, | 633 | enum GNUNET_BLOCK_Type type, |
632 | PluginDatumProcessor proc, | 634 | PluginDatumProcessor proc, |
633 | void *proc_cls) | 635 | void *proc_cls) |
634 | { | 636 | { |
635 | struct Plugin *plugin = cls; | 637 | struct Plugin *plugin = cls; |
636 | uint32_t typei = (uint32_t)type; | 638 | uint32_t typei = (uint32_t) type; |
637 | 639 | ||
638 | struct GNUNET_MY_QueryParam params_zero_iter[] = { | 640 | struct GNUNET_MY_QueryParam params_zero_iter[] = { |
639 | GNUNET_MY_query_param_uint32(&typei), | 641 | GNUNET_MY_query_param_uint32 (&typei), |
640 | GNUNET_MY_query_param_uint64(&next_uid), | 642 | GNUNET_MY_query_param_uint64 (&next_uid), |
641 | GNUNET_MY_query_param_end | 643 | GNUNET_MY_query_param_end |
642 | }; | 644 | }; |
643 | 645 | ||
644 | execute_select(plugin, | 646 | execute_select (plugin, |
645 | plugin->zero_iter, | 647 | plugin->zero_iter, |
646 | proc, | 648 | proc, |
647 | proc_cls, | 649 | proc_cls, |
648 | params_zero_iter); | 650 | params_zero_iter); |
649 | } | 651 | } |
650 | 652 | ||
651 | 653 | ||
652 | /** | 654 | /** |
653 | * Context for #repl_proc() function. | 655 | * Context for #repl_proc() function. |
654 | */ | 656 | */ |
655 | struct ReplCtx { | 657 | struct ReplCtx |
658 | { | ||
656 | /** | 659 | /** |
657 | * Plugin handle. | 660 | * Plugin handle. |
658 | */ | 661 | */ |
@@ -691,49 +694,49 @@ struct ReplCtx { | |||
691 | * #GNUNET_NO to delete the item and continue (if supported) | 694 | * #GNUNET_NO to delete the item and continue (if supported) |
692 | */ | 695 | */ |
693 | static int | 696 | static int |
694 | repl_proc(void *cls, | 697 | repl_proc (void *cls, |
695 | const struct GNUNET_HashCode *key, | 698 | const struct GNUNET_HashCode *key, |
696 | uint32_t size, | 699 | uint32_t size, |
697 | const void *data, | 700 | const void *data, |
698 | enum GNUNET_BLOCK_Type type, | 701 | enum GNUNET_BLOCK_Type type, |
699 | uint32_t priority, | 702 | uint32_t priority, |
700 | uint32_t anonymity, | 703 | uint32_t anonymity, |
701 | uint32_t replication, | 704 | uint32_t replication, |
702 | struct GNUNET_TIME_Absolute expiration, | 705 | struct GNUNET_TIME_Absolute expiration, |
703 | uint64_t uid) | 706 | uint64_t uid) |
704 | { | 707 | { |
705 | struct ReplCtx *rc = cls; | 708 | struct ReplCtx *rc = cls; |
706 | struct Plugin *plugin = rc->plugin; | 709 | struct Plugin *plugin = rc->plugin; |
707 | int ret; | 710 | int ret; |
708 | int iret; | 711 | int iret; |
709 | 712 | ||
710 | ret = rc->proc(rc->proc_cls, | 713 | ret = rc->proc (rc->proc_cls, |
711 | key, | 714 | key, |
712 | size, | 715 | size, |
713 | data, | 716 | data, |
714 | type, | 717 | type, |
715 | priority, | 718 | priority, |
716 | anonymity, | 719 | anonymity, |
717 | replication, | 720 | replication, |
718 | expiration, | 721 | expiration, |
719 | uid); | 722 | uid); |
720 | if (NULL != key) | 723 | if (NULL != key) |
724 | { | ||
725 | struct GNUNET_MY_QueryParam params_proc[] = { | ||
726 | GNUNET_MY_query_param_uint64 (&uid), | ||
727 | GNUNET_MY_query_param_end | ||
728 | }; | ||
729 | |||
730 | iret = GNUNET_MY_exec_prepared (plugin->mc, | ||
731 | plugin->dec_repl, | ||
732 | params_proc); | ||
733 | if (GNUNET_SYSERR == iret) | ||
721 | { | 734 | { |
722 | struct GNUNET_MY_QueryParam params_proc[] = { | 735 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
723 | GNUNET_MY_query_param_uint64(&uid), | 736 | "Failed to reduce replication counter\n"); |
724 | GNUNET_MY_query_param_end | 737 | return GNUNET_SYSERR; |
725 | }; | ||
726 | |||
727 | iret = GNUNET_MY_exec_prepared(plugin->mc, | ||
728 | plugin->dec_repl, | ||
729 | params_proc); | ||
730 | if (GNUNET_SYSERR == iret) | ||
731 | { | ||
732 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
733 | "Failed to reduce replication counter\n"); | ||
734 | return GNUNET_SYSERR; | ||
735 | } | ||
736 | } | 738 | } |
739 | } | ||
737 | return ret; | 740 | return ret; |
738 | } | 741 | } |
739 | 742 | ||
@@ -750,9 +753,9 @@ repl_proc(void *cls, | |||
750 | * @param proc_cls closure for @a proc | 753 | * @param proc_cls closure for @a proc |
751 | */ | 754 | */ |
752 | static void | 755 | static void |
753 | mysql_plugin_get_replication(void *cls, | 756 | mysql_plugin_get_replication (void *cls, |
754 | PluginDatumProcessor proc, | 757 | PluginDatumProcessor proc, |
755 | void *proc_cls) | 758 | void *proc_cls) |
756 | { | 759 | { |
757 | struct Plugin *plugin = cls; | 760 | struct Plugin *plugin = cls; |
758 | uint64_t rvalue; | 761 | uint64_t rvalue; |
@@ -762,14 +765,14 @@ mysql_plugin_get_replication(void *cls, | |||
762 | GNUNET_MY_query_param_end | 765 | GNUNET_MY_query_param_end |
763 | }; | 766 | }; |
764 | struct GNUNET_MY_ResultSpec results_get[] = { | 767 | struct GNUNET_MY_ResultSpec results_get[] = { |
765 | GNUNET_MY_result_spec_uint32(&repl), | 768 | GNUNET_MY_result_spec_uint32 (&repl), |
766 | GNUNET_MY_result_spec_end | 769 | GNUNET_MY_result_spec_end |
767 | }; | 770 | }; |
768 | struct GNUNET_MY_QueryParam params_select[] = { | 771 | struct GNUNET_MY_QueryParam params_select[] = { |
769 | GNUNET_MY_query_param_uint32(&repl), | 772 | GNUNET_MY_query_param_uint32 (&repl), |
770 | GNUNET_MY_query_param_uint64(&rvalue), | 773 | GNUNET_MY_query_param_uint64 (&rvalue), |
771 | GNUNET_MY_query_param_uint32(&repl), | 774 | GNUNET_MY_query_param_uint32 (&repl), |
772 | GNUNET_MY_query_param_uint64(&rvalue), | 775 | GNUNET_MY_query_param_uint64 (&rvalue), |
773 | GNUNET_MY_query_param_end | 776 | GNUNET_MY_query_param_end |
774 | }; | 777 | }; |
775 | 778 | ||
@@ -778,32 +781,32 @@ mysql_plugin_get_replication(void *cls, | |||
778 | rc.proc_cls = proc_cls; | 781 | rc.proc_cls = proc_cls; |
779 | 782 | ||
780 | if (1 != | 783 | if (1 != |
781 | GNUNET_MY_exec_prepared(plugin->mc, | 784 | GNUNET_MY_exec_prepared (plugin->mc, |
782 | plugin->max_repl, | 785 | plugin->max_repl, |
783 | params_get)) | 786 | params_get)) |
784 | { | 787 | { |
785 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 788 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
786 | return; | 789 | return; |
787 | } | 790 | } |
788 | 791 | ||
789 | if (GNUNET_OK != | 792 | if (GNUNET_OK != |
790 | GNUNET_MY_extract_result(plugin->max_repl, | 793 | GNUNET_MY_extract_result (plugin->max_repl, |
791 | results_get)) | 794 | results_get)) |
792 | { | 795 | { |
793 | proc(proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 796 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
794 | return; | 797 | return; |
795 | } | 798 | } |
796 | GNUNET_break(GNUNET_NO == | 799 | GNUNET_break (GNUNET_NO == |
797 | GNUNET_MY_extract_result(plugin->max_repl, | 800 | GNUNET_MY_extract_result (plugin->max_repl, |
798 | NULL)); | 801 | NULL)); |
799 | rvalue = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | 802 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
800 | UINT64_MAX); | 803 | UINT64_MAX); |
801 | 804 | ||
802 | execute_select(plugin, | 805 | execute_select (plugin, |
803 | plugin->select_replication, | 806 | plugin->select_replication, |
804 | &repl_proc, | 807 | &repl_proc, |
805 | &rc, | 808 | &rc, |
806 | params_select); | 809 | params_select); |
807 | } | 810 | } |
808 | 811 | ||
809 | 812 | ||
@@ -815,9 +818,9 @@ mysql_plugin_get_replication(void *cls, | |||
815 | * @param proc_cls closure for @a proc | 818 | * @param proc_cls closure for @a proc |
816 | */ | 819 | */ |
817 | static void | 820 | static void |
818 | mysql_plugin_get_keys(void *cls, | 821 | mysql_plugin_get_keys (void *cls, |
819 | PluginKeyProcessor proc, | 822 | PluginKeyProcessor proc, |
820 | void *proc_cls) | 823 | void *proc_cls) |
821 | { | 824 | { |
822 | struct Plugin *plugin = cls; | 825 | struct Plugin *plugin = cls; |
823 | int ret; | 826 | int ret; |
@@ -829,76 +832,77 @@ mysql_plugin_get_keys(void *cls, | |||
829 | GNUNET_MY_query_param_end | 832 | GNUNET_MY_query_param_end |
830 | }; | 833 | }; |
831 | struct GNUNET_MY_ResultSpec results_select[] = { | 834 | struct GNUNET_MY_ResultSpec results_select[] = { |
832 | GNUNET_MY_result_spec_auto_from_type(&key), | 835 | GNUNET_MY_result_spec_auto_from_type (&key), |
833 | GNUNET_MY_result_spec_end | 836 | GNUNET_MY_result_spec_end |
834 | }; | 837 | }; |
835 | 838 | ||
836 | GNUNET_assert(NULL != proc); | 839 | GNUNET_assert (NULL != proc); |
837 | statement = GNUNET_MYSQL_statement_get_stmt(plugin->get_all_keys); | 840 | statement = GNUNET_MYSQL_statement_get_stmt (plugin->get_all_keys); |
838 | if (GNUNET_OK != | 841 | if (GNUNET_OK != |
839 | GNUNET_MY_exec_prepared(plugin->mc, | 842 | GNUNET_MY_exec_prepared (plugin->mc, |
840 | plugin->get_all_keys, | 843 | plugin->get_all_keys, |
841 | params_select)) | 844 | params_select)) |
842 | { | 845 | { |
843 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 846 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
844 | _("`%s' for `%s' failed at %s:%d with error: %s\n"), | 847 | _ ("`%s' for `%s' failed at %s:%d with error: %s\n"), |
845 | "mysql_stmt_execute", | 848 | "mysql_stmt_execute", |
846 | GET_ALL_KEYS, | 849 | GET_ALL_KEYS, |
847 | __FILE__, | 850 | __FILE__, |
848 | __LINE__, | 851 | __LINE__, |
849 | mysql_stmt_error(statement)); | 852 | mysql_stmt_error (statement)); |
850 | GNUNET_MYSQL_statements_invalidate(plugin->mc); | 853 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
851 | proc(proc_cls, NULL, 0); | 854 | proc (proc_cls, NULL, 0); |
852 | return; | 855 | return; |
853 | } | 856 | } |
854 | memset(&last, 0, sizeof(last)); /* make static analysis happy */ | 857 | memset (&last, 0, sizeof(last)); /* make static analysis happy */ |
855 | ret = GNUNET_YES; | 858 | ret = GNUNET_YES; |
856 | cnt = 0; | 859 | cnt = 0; |
857 | while (ret == GNUNET_YES) | 860 | while (ret == GNUNET_YES) |
861 | { | ||
862 | ret = GNUNET_MY_extract_result (plugin->get_all_keys, | ||
863 | results_select); | ||
864 | if (0 != GNUNET_memcmp (&last, | ||
865 | &key)) | ||
866 | { | ||
867 | if (0 != cnt) | ||
868 | proc (proc_cls, | ||
869 | &last, | ||
870 | cnt); | ||
871 | cnt = 1; | ||
872 | last = key; | ||
873 | } | ||
874 | else | ||
858 | { | 875 | { |
859 | ret = GNUNET_MY_extract_result(plugin->get_all_keys, | 876 | cnt++; |
860 | results_select); | ||
861 | if (0 != GNUNET_memcmp(&last, | ||
862 | &key)) | ||
863 | { | ||
864 | if (0 != cnt) | ||
865 | proc(proc_cls, | ||
866 | &last, | ||
867 | cnt); | ||
868 | cnt = 1; | ||
869 | last = key; | ||
870 | } | ||
871 | else | ||
872 | { | ||
873 | cnt++; | ||
874 | } | ||
875 | } | 877 | } |
878 | } | ||
876 | if (0 != cnt) | 879 | if (0 != cnt) |
877 | proc(proc_cls, | 880 | proc (proc_cls, |
878 | &last, | 881 | &last, |
879 | cnt); | 882 | cnt); |
880 | /* finally, let app know we are done */ | 883 | /* finally, let app know we are done */ |
881 | proc(proc_cls, | 884 | proc (proc_cls, |
882 | NULL, | 885 | NULL, |
883 | 0); | 886 | 0); |
884 | if (GNUNET_SYSERR == ret) | 887 | if (GNUNET_SYSERR == ret) |
885 | { | 888 | { |
886 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 889 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
887 | _("`%s' failed at %s:%d with error: %s\n"), | 890 | _ ("`%s' failed at %s:%d with error: %s\n"), |
888 | "mysql_stmt_fetch", | 891 | "mysql_stmt_fetch", |
889 | __FILE__, | 892 | __FILE__, |
890 | __LINE__, | 893 | __LINE__, |
891 | mysql_stmt_error(statement)); | 894 | mysql_stmt_error (statement)); |
892 | GNUNET_MYSQL_statements_invalidate(plugin->mc); | 895 | GNUNET_MYSQL_statements_invalidate (plugin->mc); |
893 | return; | 896 | return; |
894 | } | 897 | } |
895 | } | 898 | } |
896 | 899 | ||
897 | 900 | ||
898 | /** | 901 | /** |
899 | * Context for #expi_proc() function. | 902 | * Context for #expi_proc() function. |
900 | */ | 903 | */ |
901 | struct ExpiCtx { | 904 | struct ExpiCtx |
905 | { | ||
902 | /** | 906 | /** |
903 | * Plugin handle. | 907 | * Plugin handle. |
904 | */ | 908 | */ |
@@ -938,16 +942,16 @@ struct ExpiCtx { | |||
938 | * #GNUNET_NO to delete the item and continue (if supported) | 942 | * #GNUNET_NO to delete the item and continue (if supported) |
939 | */ | 943 | */ |
940 | static int | 944 | static int |
941 | expi_proc(void *cls, | 945 | expi_proc (void *cls, |
942 | const struct GNUNET_HashCode *key, | 946 | const struct GNUNET_HashCode *key, |
943 | uint32_t size, | 947 | uint32_t size, |
944 | const void *data, | 948 | const void *data, |
945 | enum GNUNET_BLOCK_Type type, | 949 | enum GNUNET_BLOCK_Type type, |
946 | uint32_t priority, | 950 | uint32_t priority, |
947 | uint32_t anonymity, | 951 | uint32_t anonymity, |
948 | uint32_t replication, | 952 | uint32_t replication, |
949 | struct GNUNET_TIME_Absolute expiration, | 953 | struct GNUNET_TIME_Absolute expiration, |
950 | uint64_t uid) | 954 | uint64_t uid) |
951 | { | 955 | { |
952 | struct ExpiCtx *rc = cls; | 956 | struct ExpiCtx *rc = cls; |
953 | struct Plugin *plugin = rc->plugin; | 957 | struct Plugin *plugin = rc->plugin; |
@@ -956,24 +960,24 @@ expi_proc(void *cls, | |||
956 | }; | 960 | }; |
957 | 961 | ||
958 | if (NULL == key) | 962 | if (NULL == key) |
959 | { | 963 | { |
960 | execute_select(plugin, | 964 | execute_select (plugin, |
961 | plugin->select_priority, | 965 | plugin->select_priority, |
962 | rc->proc, | 966 | rc->proc, |
963 | rc->proc_cls, | 967 | rc->proc_cls, |
964 | params_select); | 968 | params_select); |
965 | return GNUNET_SYSERR; | 969 | return GNUNET_SYSERR; |
966 | } | 970 | } |
967 | return rc->proc(rc->proc_cls, | 971 | return rc->proc (rc->proc_cls, |
968 | key, | 972 | key, |
969 | size, | 973 | size, |
970 | data, | 974 | data, |
971 | type, | 975 | type, |
972 | priority, | 976 | priority, |
973 | anonymity, | 977 | anonymity, |
974 | replication, | 978 | replication, |
975 | expiration, | 979 | expiration, |
976 | uid); | 980 | uid); |
977 | } | 981 | } |
978 | 982 | ||
979 | 983 | ||
@@ -986,14 +990,14 @@ expi_proc(void *cls, | |||
986 | * @param proc_cls closure for @a proc | 990 | * @param proc_cls closure for @a proc |
987 | */ | 991 | */ |
988 | static void | 992 | static void |
989 | mysql_plugin_get_expiration(void *cls, | 993 | mysql_plugin_get_expiration (void *cls, |
990 | PluginDatumProcessor proc, | 994 | PluginDatumProcessor proc, |
991 | void *proc_cls) | 995 | void *proc_cls) |
992 | { | 996 | { |
993 | struct Plugin *plugin = cls; | 997 | struct Plugin *plugin = cls; |
994 | struct GNUNET_TIME_Absolute now; | 998 | struct GNUNET_TIME_Absolute now; |
995 | struct GNUNET_MY_QueryParam params_select[] = { | 999 | struct GNUNET_MY_QueryParam params_select[] = { |
996 | GNUNET_MY_query_param_absolute_time(&now), | 1000 | GNUNET_MY_query_param_absolute_time (&now), |
997 | GNUNET_MY_query_param_end | 1001 | GNUNET_MY_query_param_end |
998 | }; | 1002 | }; |
999 | struct ExpiCtx rc; | 1003 | struct ExpiCtx rc; |
@@ -1001,12 +1005,12 @@ mysql_plugin_get_expiration(void *cls, | |||
1001 | rc.plugin = plugin; | 1005 | rc.plugin = plugin; |
1002 | rc.proc = proc; | 1006 | rc.proc = proc; |
1003 | rc.proc_cls = proc_cls; | 1007 | rc.proc_cls = proc_cls; |
1004 | now = GNUNET_TIME_absolute_get(); | 1008 | now = GNUNET_TIME_absolute_get (); |
1005 | execute_select(plugin, | 1009 | execute_select (plugin, |
1006 | plugin->select_expiration, | 1010 | plugin->select_expiration, |
1007 | expi_proc, | 1011 | expi_proc, |
1008 | &rc, | 1012 | &rc, |
1009 | params_select); | 1013 | params_select); |
1010 | } | 1014 | } |
1011 | 1015 | ||
1012 | 1016 | ||
@@ -1016,15 +1020,15 @@ mysql_plugin_get_expiration(void *cls, | |||
1016 | * @param cls the `struct Plugin *` | 1020 | * @param cls the `struct Plugin *` |
1017 | */ | 1021 | */ |
1018 | static void | 1022 | static void |
1019 | mysql_plugin_drop(void *cls) | 1023 | mysql_plugin_drop (void *cls) |
1020 | { | 1024 | { |
1021 | struct Plugin *plugin = cls; | 1025 | struct Plugin *plugin = cls; |
1022 | 1026 | ||
1023 | if (GNUNET_OK != | 1027 | if (GNUNET_OK != |
1024 | GNUNET_MYSQL_statement_run(plugin->mc, | 1028 | GNUNET_MYSQL_statement_run (plugin->mc, |
1025 | "DROP TABLE gn090")) | 1029 | "DROP TABLE gn090")) |
1026 | return; /* error */ | 1030 | return; /* error */ |
1027 | plugin->env->duc(plugin->env->cls, 0); | 1031 | plugin->env->duc (plugin->env->cls, 0); |
1028 | } | 1032 | } |
1029 | 1033 | ||
1030 | 1034 | ||
@@ -1039,55 +1043,56 @@ mysql_plugin_drop(void *cls) | |||
1039 | * @param cont_cls continuation closure for @a cont | 1043 | * @param cont_cls continuation closure for @a cont |
1040 | */ | 1044 | */ |
1041 | static void | 1045 | static void |
1042 | mysql_plugin_remove_key(void *cls, | 1046 | mysql_plugin_remove_key (void *cls, |
1043 | const struct GNUNET_HashCode *key, | 1047 | const struct GNUNET_HashCode *key, |
1044 | uint32_t size, | 1048 | uint32_t size, |
1045 | const void *data, | 1049 | const void *data, |
1046 | PluginRemoveCont cont, | 1050 | PluginRemoveCont cont, |
1047 | void *cont_cls) | 1051 | void *cont_cls) |
1048 | { | 1052 | { |
1049 | struct Plugin *plugin = cls; | 1053 | struct Plugin *plugin = cls; |
1050 | struct GNUNET_MY_QueryParam params_delete[] = { | 1054 | struct GNUNET_MY_QueryParam params_delete[] = { |
1051 | GNUNET_MY_query_param_auto_from_type(key), | 1055 | GNUNET_MY_query_param_auto_from_type (key), |
1052 | GNUNET_MY_query_param_fixed_size(data, size), | 1056 | GNUNET_MY_query_param_fixed_size (data, size), |
1053 | GNUNET_MY_query_param_end | 1057 | GNUNET_MY_query_param_end |
1054 | }; | 1058 | }; |
1055 | 1059 | ||
1056 | if (GNUNET_OK != | 1060 | if (GNUNET_OK != |
1057 | GNUNET_MY_exec_prepared(plugin->mc, | 1061 | GNUNET_MY_exec_prepared (plugin->mc, |
1058 | plugin->delete_entry_by_hash_value, | 1062 | plugin->delete_entry_by_hash_value, |
1059 | params_delete)) | 1063 | params_delete)) |
1060 | { | 1064 | { |
1061 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 1065 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1062 | "Removing key `%s' from gn090 table failed\n", | 1066 | "Removing key `%s' from gn090 table failed\n", |
1063 | GNUNET_h2s(key)); | 1067 | GNUNET_h2s (key)); |
1064 | cont(cont_cls, | 1068 | cont (cont_cls, |
1065 | key, | 1069 | key, |
1066 | size, | 1070 | size, |
1067 | GNUNET_SYSERR, | 1071 | GNUNET_SYSERR, |
1068 | _("MySQL statement run failure")); | 1072 | _ ("MySQL statement run failure")); |
1069 | return; | 1073 | return; |
1070 | } | 1074 | } |
1071 | 1075 | ||
1072 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt(plugin->delete_entry_by_hash_value); | 1076 | MYSQL_STMT *stmt = GNUNET_MYSQL_statement_get_stmt ( |
1073 | my_ulonglong rows = mysql_stmt_affected_rows(stmt); | 1077 | plugin->delete_entry_by_hash_value); |
1078 | my_ulonglong rows = mysql_stmt_affected_rows (stmt); | ||
1074 | 1079 | ||
1075 | if (0 == rows) | 1080 | if (0 == rows) |
1076 | { | 1081 | { |
1077 | cont(cont_cls, | 1082 | cont (cont_cls, |
1078 | key, | 1083 | key, |
1079 | size, | 1084 | size, |
1080 | GNUNET_NO, | 1085 | GNUNET_NO, |
1081 | NULL); | 1086 | NULL); |
1082 | return; | 1087 | return; |
1083 | } | 1088 | } |
1084 | plugin->env->duc(plugin->env->cls, | 1089 | plugin->env->duc (plugin->env->cls, |
1085 | -size); | 1090 | -size); |
1086 | cont(cont_cls, | 1091 | cont (cont_cls, |
1087 | key, | 1092 | key, |
1088 | size, | 1093 | size, |
1089 | GNUNET_OK, | 1094 | GNUNET_OK, |
1090 | NULL); | 1095 | NULL); |
1091 | } | 1096 | } |
1092 | 1097 | ||
1093 | 1098 | ||
@@ -1098,23 +1103,24 @@ mysql_plugin_remove_key(void *cls, | |||
1098 | * @return our `struct Plugin *` | 1103 | * @return our `struct Plugin *` |
1099 | */ | 1104 | */ |
1100 | void * | 1105 | void * |
1101 | libgnunet_plugin_datastore_mysql_init(void *cls) | 1106 | libgnunet_plugin_datastore_mysql_init (void *cls) |
1102 | { | 1107 | { |
1103 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; | 1108 | struct GNUNET_DATASTORE_PluginEnvironment *env = cls; |
1104 | struct GNUNET_DATASTORE_PluginFunctions *api; | 1109 | struct GNUNET_DATASTORE_PluginFunctions *api; |
1105 | struct Plugin *plugin; | 1110 | struct Plugin *plugin; |
1106 | 1111 | ||
1107 | plugin = GNUNET_new(struct Plugin); | 1112 | plugin = GNUNET_new (struct Plugin); |
1108 | plugin->env = env; | 1113 | plugin->env = env; |
1109 | plugin->mc = GNUNET_MYSQL_context_create(env->cfg, | 1114 | plugin->mc = GNUNET_MYSQL_context_create (env->cfg, |
1110 | "datastore-mysql"); | 1115 | "datastore-mysql"); |
1111 | if (NULL == plugin->mc) | 1116 | if (NULL == plugin->mc) |
1112 | { | 1117 | { |
1113 | GNUNET_free(plugin); | 1118 | GNUNET_free (plugin); |
1114 | return NULL; | 1119 | return NULL; |
1115 | } | 1120 | } |
1116 | #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run(plugin->mc, a)) | 1121 | #define MRUNS(a) (GNUNET_OK != GNUNET_MYSQL_statement_run (plugin->mc, a)) |
1117 | #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare(plugin->mc, b))) | 1122 | #define PINIT(a, b) (NULL == (a = GNUNET_MYSQL_statement_prepare (plugin->mc, \ |
1123 | b))) | ||
1118 | if (MRUNS | 1124 | if (MRUNS |
1119 | ("CREATE TABLE IF NOT EXISTS gn090 (" | 1125 | ("CREATE TABLE IF NOT EXISTS gn090 (" |
1120 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," | 1126 | " repl INT(11) UNSIGNED NOT NULL DEFAULT 0," |
@@ -1125,40 +1131,41 @@ libgnunet_plugin_datastore_mysql_init(void *cls) | |||
1125 | " rvalue BIGINT UNSIGNED NOT NULL," | 1131 | " rvalue BIGINT UNSIGNED NOT NULL," |
1126 | " hash BINARY(64) NOT NULL DEFAULT ''," | 1132 | " hash BINARY(64) NOT NULL DEFAULT ''," |
1127 | " vhash BINARY(64) NOT NULL DEFAULT ''," | 1133 | " vhash BINARY(64) NOT NULL DEFAULT ''," |
1128 | " value BLOB NOT NULL DEFAULT ''," " uid BIGINT NOT NULL AUTO_INCREMENT," | 1134 | " value BLOB NOT NULL DEFAULT ''," |
1135 | " uid BIGINT NOT NULL AUTO_INCREMENT," | ||
1129 | " PRIMARY KEY (uid)," | 1136 | " PRIMARY KEY (uid)," |
1130 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," | 1137 | " INDEX idx_hash_type_uid (hash(64),type,rvalue)," |
1131 | " INDEX idx_prio (prio)," | 1138 | " INDEX idx_prio (prio)," |
1132 | " INDEX idx_repl_rvalue (repl,rvalue)," | 1139 | " INDEX idx_repl_rvalue (repl,rvalue)," |
1133 | " INDEX idx_expire (expire)," | 1140 | " INDEX idx_expire (expire)," |
1134 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" | 1141 | " INDEX idx_anonLevel_type_rvalue (anonLevel,type,rvalue)" |
1135 | ") ENGINE=InnoDB") || MRUNS("SET AUTOCOMMIT = 1") || | 1142 | ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1") || |
1136 | PINIT(plugin->insert_entry, INSERT_ENTRY) || | 1143 | PINIT (plugin->insert_entry, INSERT_ENTRY) || |
1137 | PINIT(plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || | 1144 | PINIT (plugin->delete_entry_by_uid, DELETE_ENTRY_BY_UID) || |
1138 | PINIT(plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) || | 1145 | PINIT (plugin->delete_entry_by_hash_value, DELETE_ENTRY_BY_HASH_VALUE) || |
1139 | PINIT(plugin->select_entry, SELECT_ENTRY) || | 1146 | PINIT (plugin->select_entry, SELECT_ENTRY) || |
1140 | PINIT(plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || | 1147 | PINIT (plugin->select_entry_by_hash, SELECT_ENTRY_BY_HASH) || |
1141 | PINIT(plugin->select_entry_by_hash_and_type, | 1148 | PINIT (plugin->select_entry_by_hash_and_type, |
1142 | SELECT_ENTRY_BY_HASH_AND_TYPE) || | 1149 | SELECT_ENTRY_BY_HASH_AND_TYPE) || |
1143 | PINIT(plugin->get_size, SELECT_SIZE) || | 1150 | PINIT (plugin->get_size, SELECT_SIZE) || |
1144 | PINIT(plugin->update_entry, UPDATE_ENTRY) || | 1151 | PINIT (plugin->update_entry, UPDATE_ENTRY) || |
1145 | PINIT(plugin->dec_repl, DEC_REPL) || | 1152 | PINIT (plugin->dec_repl, DEC_REPL) || |
1146 | PINIT(plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) || | 1153 | PINIT (plugin->zero_iter, SELECT_IT_NON_ANONYMOUS) || |
1147 | PINIT(plugin->select_expiration, SELECT_IT_EXPIRATION) || | 1154 | PINIT (plugin->select_expiration, SELECT_IT_EXPIRATION) || |
1148 | PINIT(plugin->select_priority, SELECT_IT_PRIORITY) || | 1155 | PINIT (plugin->select_priority, SELECT_IT_PRIORITY) || |
1149 | PINIT(plugin->max_repl, SELECT_MAX_REPL) || | 1156 | PINIT (plugin->max_repl, SELECT_MAX_REPL) || |
1150 | PINIT(plugin->get_all_keys, GET_ALL_KEYS) || | 1157 | PINIT (plugin->get_all_keys, GET_ALL_KEYS) || |
1151 | PINIT(plugin->select_replication, SELECT_IT_REPLICATION) || | 1158 | PINIT (plugin->select_replication, SELECT_IT_REPLICATION) || |
1152 | false) | 1159 | false) |
1153 | { | 1160 | { |
1154 | GNUNET_MYSQL_context_destroy(plugin->mc); | 1161 | GNUNET_MYSQL_context_destroy (plugin->mc); |
1155 | GNUNET_free(plugin); | 1162 | GNUNET_free (plugin); |
1156 | return NULL; | 1163 | return NULL; |
1157 | } | 1164 | } |
1158 | #undef PINIT | 1165 | #undef PINIT |
1159 | #undef MRUNS | 1166 | #undef MRUNS |
1160 | 1167 | ||
1161 | api = GNUNET_new(struct GNUNET_DATASTORE_PluginFunctions); | 1168 | api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions); |
1162 | api->cls = plugin; | 1169 | api->cls = plugin; |
1163 | api->estimate_size = &mysql_plugin_estimate_size; | 1170 | api->estimate_size = &mysql_plugin_estimate_size; |
1164 | api->put = &mysql_plugin_put; | 1171 | api->put = &mysql_plugin_put; |
@@ -1169,8 +1176,8 @@ libgnunet_plugin_datastore_mysql_init(void *cls) | |||
1169 | api->get_keys = &mysql_plugin_get_keys; | 1176 | api->get_keys = &mysql_plugin_get_keys; |
1170 | api->drop = &mysql_plugin_drop; | 1177 | api->drop = &mysql_plugin_drop; |
1171 | api->remove_key = &mysql_plugin_remove_key; | 1178 | api->remove_key = &mysql_plugin_remove_key; |
1172 | GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "mysql", | 1179 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", |
1173 | _("Mysql database running\n")); | 1180 | _ ("Mysql database running\n")); |
1174 | return api; | 1181 | return api; |
1175 | } | 1182 | } |
1176 | 1183 | ||
@@ -1182,14 +1189,14 @@ libgnunet_plugin_datastore_mysql_init(void *cls) | |||
1182 | * @return always NULL | 1189 | * @return always NULL |
1183 | */ | 1190 | */ |
1184 | void * | 1191 | void * |
1185 | libgnunet_plugin_datastore_mysql_done(void *cls) | 1192 | libgnunet_plugin_datastore_mysql_done (void *cls) |
1186 | { | 1193 | { |
1187 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; | 1194 | struct GNUNET_DATASTORE_PluginFunctions *api = cls; |
1188 | struct Plugin *plugin = api->cls; | 1195 | struct Plugin *plugin = api->cls; |
1189 | 1196 | ||
1190 | GNUNET_MYSQL_context_destroy(plugin->mc); | 1197 | GNUNET_MYSQL_context_destroy (plugin->mc); |
1191 | GNUNET_free(plugin); | 1198 | GNUNET_free (plugin); |
1192 | GNUNET_free(api); | 1199 | GNUNET_free (api); |
1193 | return NULL; | 1200 | return NULL; |
1194 | } | 1201 | } |
1195 | 1202 | ||