diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-13 19:50:12 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-13 19:50:12 +0100 |
commit | 8691934f57063bfa5032f4e34836ecbcb3d761e9 (patch) | |
tree | 0dfdc331e0db4a179402359f7be9945ce769a503 /src/namestore/plugin_namestore_sqlite.c | |
parent | e7739331e20a0ec26febd6d4268323d3b0638341 (diff) | |
download | gnunet-8691934f57063bfa5032f4e34836ecbcb3d761e9.tar.gz gnunet-8691934f57063bfa5032f4e34836ecbcb3d761e9.zip |
convert sqlite plugin to use libgnunetsq
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 394 |
1 files changed, 215 insertions, 179 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index d64ce10a8..5c3533506 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * This file is part of GNUnet | 2 | * This file is part of GNUnet |
3 | * Copyright (C) 2009-2013 GNUnet e.V. | 3 | * Copyright (C) 2009-2017 GNUnet e.V. |
4 | * | 4 | * |
5 | * GNUnet is free software; you can redistribute it and/or modify | 5 | * GNUnet is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published | 6 | * it under the terms of the GNU General Public License as published |
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_namestore_plugin.h" | 28 | #include "gnunet_namestore_plugin.h" |
29 | #include "gnunet_namestore_service.h" | 29 | #include "gnunet_namestore_service.h" |
30 | #include "gnunet_gnsrecord_lib.h" | 30 | #include "gnunet_gnsrecord_lib.h" |
31 | #include "gnunet_sq_lib.h" | ||
31 | #include "namestore.h" | 32 | #include "namestore.h" |
32 | #include <sqlite3.h> | 33 | #include <sqlite3.h> |
33 | 34 | ||
@@ -113,16 +114,24 @@ struct Plugin | |||
113 | * @return 0 on success | 114 | * @return 0 on success |
114 | */ | 115 | */ |
115 | static int | 116 | static int |
116 | sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt) | 117 | sq_prepare (sqlite3 *dbh, |
118 | const char *zSql, | ||
119 | sqlite3_stmt **ppStmt) | ||
117 | { | 120 | { |
118 | char *dummy; | 121 | char *dummy; |
119 | int result; | 122 | int result; |
120 | 123 | ||
121 | result = | 124 | result = |
122 | sqlite3_prepare_v2 (dbh, zSql, strlen (zSql), ppStmt, | 125 | sqlite3_prepare_v2 (dbh, |
126 | zSql, | ||
127 | strlen (zSql), | ||
128 | ppStmt, | ||
123 | (const char **) &dummy); | 129 | (const char **) &dummy); |
124 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 130 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
125 | "Prepared `%s' / %p: %d\n", zSql, *ppStmt, result); | 131 | "Prepared `%s' / %p: %d\n", |
132 | zSql, | ||
133 | *ppStmt, | ||
134 | result); | ||
126 | return result; | 135 | return result; |
127 | } | 136 | } |
128 | 137 | ||
@@ -275,38 +284,41 @@ database_setup (struct Plugin *plugin) | |||
275 | 284 | ||
276 | create_indices (plugin->dbh); | 285 | create_indices (plugin->dbh); |
277 | 286 | ||
278 | if ((sq_prepare | 287 | if ( (SQLITE_OK != |
279 | (plugin->dbh, | 288 | sq_prepare (plugin->dbh, |
280 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label)" | 289 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label)" |
281 | " VALUES (?, ?, ?, ?, ?, ?)", | 290 | " VALUES (?, ?, ?, ?, ?, ?)", |
282 | &plugin->store_records) != SQLITE_OK) || | 291 | &plugin->store_records)) || |
283 | (sq_prepare | 292 | (SQLITE_OK != |
284 | (plugin->dbh, | 293 | sq_prepare (plugin->dbh, |
285 | "DELETE FROM ns097records WHERE zone_private_key=? AND label=?", | 294 | "DELETE FROM ns097records WHERE zone_private_key=? AND label=?", |
286 | &plugin->delete_records) != SQLITE_OK) || | 295 | &plugin->delete_records)) || |
287 | (sq_prepare | 296 | (SQLITE_OK != |
288 | (plugin->dbh, | 297 | sq_prepare (plugin->dbh, |
289 | "SELECT record_count,record_data,label" | 298 | "SELECT record_count,record_data,label" |
290 | " FROM ns097records WHERE zone_private_key=? AND pkey=?", | 299 | " FROM ns097records WHERE zone_private_key=? AND pkey=?", |
291 | &plugin->zone_to_name) != SQLITE_OK) || | 300 | &plugin->zone_to_name)) || |
292 | (sq_prepare | 301 | (SQLITE_OK != |
293 | (plugin->dbh, | 302 | sq_prepare (plugin->dbh, |
294 | "SELECT record_count,record_data,label" | 303 | "SELECT record_count,record_data,label" |
295 | " FROM ns097records WHERE zone_private_key=? ORDER BY rvalue LIMIT 1 OFFSET ?", | 304 | " FROM ns097records WHERE zone_private_key=?" |
296 | &plugin->iterate_zone) != SQLITE_OK) || | 305 | " ORDER BY rvalue LIMIT 1 OFFSET ?", |
297 | (sq_prepare | 306 | &plugin->iterate_zone)) || |
298 | (plugin->dbh, | 307 | (SQLITE_OK != |
299 | "SELECT record_count,record_data,label,zone_private_key" | 308 | sq_prepare (plugin->dbh, |
300 | " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?", | 309 | "SELECT record_count,record_data,label,zone_private_key" |
301 | &plugin->iterate_all_zones) != SQLITE_OK) || | 310 | " FROM ns097records ORDER BY rvalue LIMIT 1 OFFSET ?", |
302 | (sq_prepare | 311 | &plugin->iterate_all_zones)) || |
303 | (plugin->dbh, | 312 | (SQLITE_OK != |
304 | "SELECT record_count,record_data,label,zone_private_key" | 313 | sq_prepare (plugin->dbh, |
305 | " FROM ns097records WHERE zone_private_key=? AND label=?", | 314 | "SELECT record_count,record_data,label,zone_private_key" |
306 | &plugin->lookup_label) != SQLITE_OK) | 315 | " FROM ns097records WHERE zone_private_key=? AND label=?", |
307 | ) | 316 | &plugin->lookup_label)) |
317 | ) | ||
308 | { | 318 | { |
309 | LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling"); | 319 | LOG_SQLITE (plugin, |
320 | GNUNET_ERROR_TYPE_ERROR, | ||
321 | "precompiling"); | ||
310 | return GNUNET_SYSERR; | 322 | return GNUNET_SYSERR; |
311 | } | 323 | } |
312 | return GNUNET_OK; | 324 | return GNUNET_OK; |
@@ -341,21 +353,30 @@ database_shutdown (struct Plugin *plugin) | |||
341 | { | 353 | { |
342 | LOG (GNUNET_ERROR_TYPE_WARNING, | 354 | LOG (GNUNET_ERROR_TYPE_WARNING, |
343 | _("Tried to close sqlite without finalizing all prepared statements.\n")); | 355 | _("Tried to close sqlite without finalizing all prepared statements.\n")); |
344 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 356 | stmt = sqlite3_next_stmt (plugin->dbh, |
345 | while (stmt != NULL) | 357 | NULL); |
358 | while (NULL != stmt) | ||
346 | { | 359 | { |
347 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", | 360 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
348 | "Closing statement %p\n", stmt); | 361 | "sqlite", |
362 | "Closing statement %p\n", | ||
363 | stmt); | ||
349 | result = sqlite3_finalize (stmt); | 364 | result = sqlite3_finalize (stmt); |
350 | if (result != SQLITE_OK) | 365 | if (result != SQLITE_OK) |
351 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", | 366 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, |
352 | "Failed to close statement %p: %d\n", stmt, result); | 367 | "sqlite", |
353 | stmt = sqlite3_next_stmt (plugin->dbh, NULL); | 368 | "Failed to close statement %p: %d\n", |
369 | stmt, | ||
370 | result); | ||
371 | stmt = sqlite3_next_stmt (plugin->dbh, | ||
372 | NULL); | ||
354 | } | 373 | } |
355 | result = sqlite3_close (plugin->dbh); | 374 | result = sqlite3_close (plugin->dbh); |
356 | } | 375 | } |
357 | if (SQLITE_OK != result) | 376 | if (SQLITE_OK != result) |
358 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_close"); | 377 | LOG_SQLITE (plugin, |
378 | GNUNET_ERROR_TYPE_ERROR, | ||
379 | "sqlite3_close"); | ||
359 | 380 | ||
360 | GNUNET_free_non_null (plugin->fn); | 381 | GNUNET_free_non_null (plugin->fn); |
361 | } | 382 | } |
@@ -407,7 +428,13 @@ namestore_sqlite_store_records (void *cls, | |||
407 | return GNUNET_SYSERR; | 428 | return GNUNET_SYSERR; |
408 | } | 429 | } |
409 | { | 430 | { |
431 | /* First delete 'old' records */ | ||
410 | char data[data_size]; | 432 | char data[data_size]; |
433 | struct GNUNET_SQ_QueryParam dparams[] = { | ||
434 | GNUNET_SQ_query_param_auto_from_type (zone_key), | ||
435 | GNUNET_SQ_query_param_string (label), | ||
436 | GNUNET_SQ_query_param_end | ||
437 | }; | ||
411 | 438 | ||
412 | if (data_size != | 439 | if (data_size != |
413 | GNUNET_GNSRECORD_records_serialize (rd_count, | 440 | GNUNET_GNSRECORD_records_serialize (rd_count, |
@@ -418,92 +445,71 @@ namestore_sqlite_store_records (void *cls, | |||
418 | GNUNET_break (0); | 445 | GNUNET_break (0); |
419 | return GNUNET_SYSERR; | 446 | return GNUNET_SYSERR; |
420 | } | 447 | } |
421 | 448 | if (GNUNET_OK != | |
422 | /* First delete 'old' records */ | 449 | GNUNET_SQ_bind (plugin->delete_records, |
423 | if ((SQLITE_OK != | 450 | dparams)) |
424 | sqlite3_bind_blob (plugin->delete_records, | ||
425 | 1, | ||
426 | zone_key, | ||
427 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | ||
428 | SQLITE_STATIC)) || | ||
429 | (SQLITE_OK != | ||
430 | sqlite3_bind_text (plugin->delete_records, | ||
431 | 2, | ||
432 | label, | ||
433 | -1, | ||
434 | SQLITE_STATIC))) | ||
435 | { | 451 | { |
436 | LOG_SQLITE (plugin, | 452 | LOG_SQLITE (plugin, |
437 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 453 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
438 | "sqlite3_bind_XXXX"); | 454 | "sqlite3_bind_XXXX"); |
439 | if (SQLITE_OK != sqlite3_reset (plugin->delete_records)) | 455 | GNUNET_SQ_reset (plugin->dbh, |
440 | LOG_SQLITE (plugin, | 456 | plugin->delete_records); |
441 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
442 | "sqlite3_reset"); | ||
443 | return GNUNET_SYSERR; | 457 | return GNUNET_SYSERR; |
444 | 458 | ||
445 | } | 459 | } |
446 | n = sqlite3_step (plugin->delete_records); | 460 | n = sqlite3_step (plugin->delete_records); |
447 | if (SQLITE_OK != sqlite3_reset (plugin->delete_records)) | 461 | GNUNET_SQ_reset (plugin->dbh, |
448 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 462 | plugin->delete_records); |
449 | "sqlite3_reset"); | ||
450 | 463 | ||
451 | if (0 != rd_count) | 464 | if (0 != rd_count) |
452 | { | 465 | { |
453 | if ((SQLITE_OK != | 466 | uint32_t rd_count32 = (uint32_t) rd_count; |
454 | sqlite3_bind_blob (plugin->store_records, | 467 | struct GNUNET_SQ_QueryParam sparams[] = { |
455 | 1, | 468 | GNUNET_SQ_query_param_auto_from_type (zone_key), |
456 | zone_key, | 469 | GNUNET_SQ_query_param_auto_from_type (&rvalue), |
457 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 470 | GNUNET_SQ_query_param_uint64 (&rvalue), |
458 | SQLITE_STATIC)) || | 471 | GNUNET_SQ_query_param_uint32 (&rd_count32), |
459 | (SQLITE_OK != | 472 | GNUNET_SQ_query_param_fixed_size (data, data_size), |
460 | sqlite3_bind_blob (plugin->store_records, | 473 | GNUNET_SQ_query_param_string (label), |
461 | 2, | 474 | GNUNET_SQ_query_param_end |
462 | &pkey, | 475 | }; |
463 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | 476 | |
464 | SQLITE_STATIC)) || | 477 | if (GNUNET_OK != |
465 | (SQLITE_OK != | 478 | GNUNET_SQ_bind (plugin->store_records, |
466 | sqlite3_bind_int64 (plugin->store_records, 3, rvalue)) || | 479 | sparams)) |
467 | (SQLITE_OK != | ||
468 | sqlite3_bind_int (plugin->store_records, 4, rd_count)) || | ||
469 | (SQLITE_OK != | ||
470 | sqlite3_bind_blob (plugin->store_records, 5, | ||
471 | data, data_size, | ||
472 | SQLITE_STATIC)) || | ||
473 | (SQLITE_OK != | ||
474 | sqlite3_bind_text (plugin->store_records, 6, | ||
475 | label, -1, | ||
476 | SQLITE_STATIC))) | ||
477 | { | 480 | { |
478 | LOG_SQLITE (plugin, | 481 | LOG_SQLITE (plugin, |
479 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 482 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
480 | "sqlite3_bind_XXXX"); | 483 | "sqlite3_bind_XXXX"); |
481 | if (SQLITE_OK != sqlite3_reset (plugin->store_records)) | 484 | GNUNET_SQ_reset (plugin->dbh, |
482 | LOG_SQLITE (plugin, | 485 | plugin->store_records); |
483 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
484 | "sqlite3_reset"); | ||
485 | return GNUNET_SYSERR; | 486 | return GNUNET_SYSERR; |
486 | } | 487 | } |
487 | n = sqlite3_step (plugin->store_records); | 488 | n = sqlite3_step (plugin->store_records); |
488 | if (SQLITE_OK != sqlite3_reset (plugin->store_records)) | 489 | GNUNET_SQ_reset (plugin->dbh, |
489 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 490 | plugin->store_records); |
490 | "sqlite3_reset"); | ||
491 | } | 491 | } |
492 | } | 492 | } |
493 | switch (n) | 493 | switch (n) |
494 | { | 494 | { |
495 | case SQLITE_DONE: | 495 | case SQLITE_DONE: |
496 | if (0 != rd_count) | 496 | if (0 != rd_count) |
497 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record stored\n"); | 497 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
498 | "sqlite", | ||
499 | "Record stored\n"); | ||
498 | else | 500 | else |
499 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Record deleted\n"); | 501 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
502 | "sqlite", | ||
503 | "Record deleted\n"); | ||
500 | return GNUNET_OK; | 504 | return GNUNET_OK; |
501 | case SQLITE_BUSY: | 505 | case SQLITE_BUSY: |
502 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 506 | LOG_SQLITE (plugin, |
507 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | ||
503 | "sqlite3_step"); | 508 | "sqlite3_step"); |
504 | return GNUNET_NO; | 509 | return GNUNET_NO; |
505 | default: | 510 | default: |
506 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 511 | LOG_SQLITE (plugin, |
512 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
507 | "sqlite3_step"); | 513 | "sqlite3_step"); |
508 | return GNUNET_SYSERR; | 514 | return GNUNET_SYSERR; |
509 | } | 515 | } |
@@ -526,37 +532,47 @@ static int | |||
526 | get_record_and_call_iterator (struct Plugin *plugin, | 532 | get_record_and_call_iterator (struct Plugin *plugin, |
527 | sqlite3_stmt *stmt, | 533 | sqlite3_stmt *stmt, |
528 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 534 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
529 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 535 | GNUNET_NAMESTORE_RecordIterator iter, |
536 | void *iter_cls) | ||
530 | { | 537 | { |
531 | unsigned int record_count; | 538 | uint32_t record_count; |
532 | size_t data_size; | 539 | size_t data_size; |
533 | const char *data; | 540 | void *data; |
534 | const char *label; | 541 | char *label; |
542 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | ||
535 | int ret; | 543 | int ret; |
536 | int sret; | 544 | int sret; |
537 | 545 | ||
538 | ret = GNUNET_NO; | 546 | ret = GNUNET_NO; |
539 | if (SQLITE_ROW == (sret = sqlite3_step (stmt))) | 547 | if (SQLITE_ROW == (sret = sqlite3_step (stmt))) |
540 | { | 548 | { |
541 | record_count = sqlite3_column_int (stmt, 0); | 549 | struct GNUNET_SQ_ResultSpec rs[] = { |
542 | data_size = sqlite3_column_bytes (stmt, 1); | 550 | GNUNET_SQ_result_spec_uint32 (&record_count), |
543 | data = sqlite3_column_blob (stmt, 1); | 551 | GNUNET_SQ_result_spec_variable_size (&data, &data_size), |
544 | label = (const char*) sqlite3_column_text (stmt, 2); | 552 | GNUNET_SQ_result_spec_string (&label), |
553 | GNUNET_SQ_result_spec_end | ||
554 | }; | ||
555 | struct GNUNET_SQ_ResultSpec rsx[] = { | ||
556 | GNUNET_SQ_result_spec_uint32 (&record_count), | ||
557 | GNUNET_SQ_result_spec_variable_size (&data, &data_size), | ||
558 | GNUNET_SQ_result_spec_string (&label), | ||
559 | GNUNET_SQ_result_spec_auto_from_type (&zk), | ||
560 | GNUNET_SQ_result_spec_end | ||
561 | }; | ||
562 | |||
545 | if (NULL == zone_key) | 563 | if (NULL == zone_key) |
546 | { | 564 | { |
547 | /* must be "iterate_all_zones", got one extra return value */ | 565 | zone_key = &zk; |
548 | if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != | 566 | ret = GNUNET_SQ_extract_result (stmt, |
549 | sqlite3_column_bytes (stmt, 3)) | 567 | rsx); |
550 | { | 568 | } |
551 | GNUNET_break (0); | 569 | else |
552 | ret = GNUNET_SYSERR; | 570 | { |
553 | } | 571 | ret = GNUNET_SQ_extract_result (stmt, |
554 | else | 572 | rs); |
555 | { | ||
556 | zone_key = sqlite3_column_blob (stmt, 3); | ||
557 | } | ||
558 | } | 573 | } |
559 | if (record_count > 64 * 1024) | 574 | if ( (GNUNET_OK != ret) || |
575 | (record_count > 64 * 1024) ) | ||
560 | { | 576 | { |
561 | /* sanity check, don't stack allocate far too much just | 577 | /* sanity check, don't stack allocate far too much just |
562 | because database might contain a large value here */ | 578 | because database might contain a large value here */ |
@@ -568,32 +584,40 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
568 | struct GNUNET_GNSRECORD_Data rd[record_count]; | 584 | struct GNUNET_GNSRECORD_Data rd[record_count]; |
569 | 585 | ||
570 | if (GNUNET_OK != | 586 | if (GNUNET_OK != |
571 | GNUNET_GNSRECORD_records_deserialize (data_size, data, | 587 | GNUNET_GNSRECORD_records_deserialize (data_size, |
572 | record_count, rd)) | 588 | data, |
589 | record_count, | ||
590 | rd)) | ||
573 | { | 591 | { |
574 | GNUNET_break (0); | 592 | GNUNET_break (0); |
575 | ret = GNUNET_SYSERR; | 593 | ret = GNUNET_SYSERR; |
576 | } | 594 | } |
577 | else if (NULL != zone_key) | 595 | else |
578 | { | 596 | { |
579 | if (NULL != iter) | 597 | if (NULL != iter) |
580 | iter (iter_cls, zone_key, label, record_count, rd); | 598 | iter (iter_cls, |
599 | zone_key, | ||
600 | label, | ||
601 | record_count, | ||
602 | rd); | ||
581 | ret = GNUNET_YES; | 603 | ret = GNUNET_YES; |
582 | } | 604 | } |
583 | } | 605 | } |
606 | GNUNET_SQ_cleanup_result (rs); | ||
584 | } | 607 | } |
585 | else | 608 | else |
586 | { | 609 | { |
587 | if (SQLITE_DONE != sret) | 610 | if (SQLITE_DONE != sret) |
588 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite_step"); | 611 | LOG_SQLITE (plugin, |
612 | GNUNET_ERROR_TYPE_ERROR, | ||
613 | "sqlite_step"); | ||
589 | } | 614 | } |
590 | if (SQLITE_OK != sqlite3_reset (stmt)) | 615 | GNUNET_SQ_reset (plugin->dbh, |
591 | LOG_SQLITE (plugin, | 616 | stmt); |
592 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
593 | "sqlite3_reset"); | ||
594 | return ret; | 617 | return ret; |
595 | } | 618 | } |
596 | 619 | ||
620 | |||
597 | /** | 621 | /** |
598 | * Lookup records in the datastore for which we are the authority. | 622 | * Lookup records in the datastore for which we are the authority. |
599 | * | 623 | * |
@@ -606,37 +630,35 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
606 | */ | 630 | */ |
607 | static int | 631 | static int |
608 | namestore_sqlite_lookup_records (void *cls, | 632 | namestore_sqlite_lookup_records (void *cls, |
609 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, | 633 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
610 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 634 | const char *label, |
635 | GNUNET_NAMESTORE_RecordIterator iter, | ||
636 | void *iter_cls) | ||
611 | { | 637 | { |
612 | struct Plugin *plugin = cls; | 638 | struct Plugin *plugin = cls; |
613 | sqlite3_stmt *stmt; | 639 | struct GNUNET_SQ_QueryParam params[] = { |
614 | int err; | 640 | GNUNET_SQ_query_param_auto_from_type (zone), |
641 | GNUNET_SQ_query_param_string (label), | ||
642 | GNUNET_SQ_query_param_end | ||
643 | }; | ||
615 | 644 | ||
616 | if (NULL == zone) | 645 | if (NULL == zone) |
617 | { | ||
618 | return GNUNET_SYSERR; | 646 | return GNUNET_SYSERR; |
619 | } | 647 | if (GNUNET_OK != |
620 | else | 648 | GNUNET_SQ_bind (plugin->lookup_label, |
621 | { | 649 | params)) |
622 | stmt = plugin->lookup_label; | ||
623 | err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, | ||
624 | zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | ||
625 | SQLITE_STATIC)) || | ||
626 | (SQLITE_OK != sqlite3_bind_text (stmt, 2, | ||
627 | label, -1, SQLITE_STATIC)) ); | ||
628 | } | ||
629 | if (err) | ||
630 | { | 650 | { |
631 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 651 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
632 | "sqlite3_bind_XXXX"); | 652 | "sqlite3_bind_XXXX"); |
633 | if (SQLITE_OK != sqlite3_reset (stmt)) | 653 | GNUNET_SQ_reset (plugin->dbh, |
634 | LOG_SQLITE (plugin, | 654 | plugin->lookup_label); |
635 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
636 | "sqlite3_reset"); | ||
637 | return GNUNET_SYSERR; | 655 | return GNUNET_SYSERR; |
638 | } | 656 | } |
639 | return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); | 657 | return get_record_and_call_iterator (plugin, |
658 | plugin->lookup_label, | ||
659 | zone, | ||
660 | iter, | ||
661 | iter_cls); | ||
640 | } | 662 | } |
641 | 663 | ||
642 | 664 | ||
@@ -655,7 +677,8 @@ static int | |||
655 | namestore_sqlite_iterate_records (void *cls, | 677 | namestore_sqlite_iterate_records (void *cls, |
656 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 678 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
657 | uint64_t offset, | 679 | uint64_t offset, |
658 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 680 | GNUNET_NAMESTORE_RecordIterator iter, |
681 | void *iter_cls) | ||
659 | { | 682 | { |
660 | struct Plugin *plugin = cls; | 683 | struct Plugin *plugin = cls; |
661 | sqlite3_stmt *stmt; | 684 | sqlite3_stmt *stmt; |
@@ -663,30 +686,41 @@ namestore_sqlite_iterate_records (void *cls, | |||
663 | 686 | ||
664 | if (NULL == zone) | 687 | if (NULL == zone) |
665 | { | 688 | { |
689 | struct GNUNET_SQ_QueryParam params[] = { | ||
690 | GNUNET_SQ_query_param_uint64 (&offset), | ||
691 | GNUNET_SQ_query_param_end | ||
692 | }; | ||
693 | |||
666 | stmt = plugin->iterate_all_zones; | 694 | stmt = plugin->iterate_all_zones; |
667 | err = (SQLITE_OK != sqlite3_bind_int64 (stmt, 1, | 695 | err = GNUNET_SQ_bind (stmt, |
668 | offset)); | 696 | params); |
669 | } | 697 | } |
670 | else | 698 | else |
671 | { | 699 | { |
700 | struct GNUNET_SQ_QueryParam params[] = { | ||
701 | GNUNET_SQ_query_param_auto_from_type (zone), | ||
702 | GNUNET_SQ_query_param_uint64 (&offset), | ||
703 | GNUNET_SQ_query_param_end | ||
704 | }; | ||
705 | |||
672 | stmt = plugin->iterate_zone; | 706 | stmt = plugin->iterate_zone; |
673 | err = ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, | 707 | err = GNUNET_SQ_bind (stmt, |
674 | zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 708 | params); |
675 | SQLITE_STATIC)) || | ||
676 | (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, | ||
677 | offset)) ); | ||
678 | } | 709 | } |
679 | if (err) | 710 | if (GNUNET_OK != err) |
680 | { | 711 | { |
681 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 712 | LOG_SQLITE (plugin, |
713 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
682 | "sqlite3_bind_XXXX"); | 714 | "sqlite3_bind_XXXX"); |
683 | if (SQLITE_OK != sqlite3_reset (stmt)) | 715 | GNUNET_SQ_reset (plugin->dbh, |
684 | LOG_SQLITE (plugin, | 716 | stmt); |
685 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
686 | "sqlite3_reset"); | ||
687 | return GNUNET_SYSERR; | 717 | return GNUNET_SYSERR; |
688 | } | 718 | } |
689 | return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); | 719 | return get_record_and_call_iterator (plugin, |
720 | stmt, | ||
721 | zone, | ||
722 | iter, | ||
723 | iter_cls); | ||
690 | } | 724 | } |
691 | 725 | ||
692 | 726 | ||
@@ -708,29 +742,31 @@ namestore_sqlite_zone_to_name (void *cls, | |||
708 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 742 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
709 | { | 743 | { |
710 | struct Plugin *plugin = cls; | 744 | struct Plugin *plugin = cls; |
711 | sqlite3_stmt *stmt; | 745 | struct GNUNET_SQ_QueryParam params[] = { |
746 | GNUNET_SQ_query_param_auto_from_type (zone), | ||
747 | GNUNET_SQ_query_param_auto_from_type (value_zone), | ||
748 | GNUNET_SQ_query_param_end | ||
749 | }; | ||
712 | 750 | ||
713 | stmt = plugin->zone_to_name; | 751 | if (GNUNET_OK != |
714 | if ( (SQLITE_OK != sqlite3_bind_blob (stmt, 1, | 752 | GNUNET_SQ_bind (plugin->zone_to_name, |
715 | zone, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 753 | params)) |
716 | SQLITE_STATIC)) || | ||
717 | (SQLITE_OK != sqlite3_bind_blob (stmt, 2, | ||
718 | value_zone, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), | ||
719 | SQLITE_STATIC)) ) | ||
720 | { | 754 | { |
721 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 755 | LOG_SQLITE (plugin, |
756 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
722 | "sqlite3_bind_XXXX"); | 757 | "sqlite3_bind_XXXX"); |
723 | if (SQLITE_OK != sqlite3_reset (stmt)) | 758 | GNUNET_SQ_reset (plugin->dbh, |
724 | LOG_SQLITE (plugin, | 759 | plugin->zone_to_name); |
725 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
726 | "sqlite3_reset"); | ||
727 | return GNUNET_SYSERR; | 760 | return GNUNET_SYSERR; |
728 | } | 761 | } |
729 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 762 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
730 | "Performing reverse lookup for `%s'\n", | 763 | "Performing reverse lookup for `%s'\n", |
731 | GNUNET_GNSRECORD_z2s (value_zone)); | 764 | GNUNET_GNSRECORD_z2s (value_zone)); |
732 | 765 | return get_record_and_call_iterator (plugin, | |
733 | return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); | 766 | plugin->zone_to_name, |
767 | zone, | ||
768 | iter, | ||
769 | iter_cls); | ||
734 | } | 770 | } |
735 | 771 | ||
736 | 772 | ||