diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-22 08:27:07 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-22 08:27:07 +0000 |
commit | 8cfdd55547ca1163f168af6d0254a17e5e0328c0 (patch) | |
tree | 5e8cdd23b0ce888105a4da1d38e29a8c3024081f /src/namestore/plugin_namestore_postgres.c | |
parent | c490ebb5586ac03989e5da563626b1578702cf29 (diff) | |
download | gnunet-8cfdd55547ca1163f168af6d0254a17e5e0328c0.tar.gz gnunet-8cfdd55547ca1163f168af6d0254a17e5e0328c0.zip |
ported postgres plugin to new API to get it to compile
functionality was not adapted
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 119 |
1 files changed, 101 insertions, 18 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index b62c306f3..546653d90 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -211,6 +211,9 @@ database_setup (struct Plugin *plugin) | |||
211 | return GNUNET_OK; | 211 | return GNUNET_OK; |
212 | } | 212 | } |
213 | 213 | ||
214 | #if 0 | ||
215 | |||
216 | TODO: removed | ||
214 | 217 | ||
215 | /** | 218 | /** |
216 | * Removes any existing record in the given zone with the same name. | 219 | * Removes any existing record in the given zone with the same name. |
@@ -252,6 +255,7 @@ namestore_postgres_remove_records (void *cls, | |||
252 | } | 255 | } |
253 | 256 | ||
254 | 257 | ||
258 | |||
255 | /** | 259 | /** |
256 | * Store a record in the datastore. Removes any existing record in the | 260 | * Store a record in the datastore. Removes any existing record in the |
257 | * same zone with the same name. | 261 | * same zone with the same name. |
@@ -356,6 +360,7 @@ namestore_postgres_put_records (void *cls, | |||
356 | } | 360 | } |
357 | return GNUNET_OK; | 361 | return GNUNET_OK; |
358 | } | 362 | } |
363 | #endif | ||
359 | 364 | ||
360 | 365 | ||
361 | /** | 366 | /** |
@@ -378,9 +383,10 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
378 | { | 383 | { |
379 | unsigned int record_count; | 384 | unsigned int record_count; |
380 | size_t data_size; | 385 | size_t data_size; |
381 | const struct GNUNET_CRYPTO_EccPublicKey *zone_key; | 386 | /* const struct GNUNET_CRYPTO_EccPublicKey *zone_key; */ |
382 | const struct GNUNET_CRYPTO_EccSignature *sig; | 387 | const struct GNUNET_CRYPTO_EccPrivateKey *zone_key; |
383 | struct GNUNET_TIME_Absolute expiration; | 388 | /* const struct GNUNET_CRYPTO_EccSignature *sig; */ |
389 | /* struct GNUNET_TIME_Absolute expiration; */ | ||
384 | const char *data; | 390 | const char *data; |
385 | const char *name; | 391 | const char *name; |
386 | unsigned int cnt; | 392 | unsigned int cnt; |
@@ -401,7 +407,8 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 407 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
402 | "Ending iteration (no more results)\n"); | 408 | "Ending iteration (no more results)\n"); |
403 | PQclear (res); | 409 | PQclear (res); |
404 | iter (iter_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); | 410 | |
411 | iter (iter_cls, NULL, NULL, 0, NULL); | ||
405 | return GNUNET_NO; | 412 | return GNUNET_NO; |
406 | } | 413 | } |
407 | GNUNET_assert (1 == cnt); | 414 | GNUNET_assert (1 == cnt); |
@@ -415,15 +422,17 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
415 | PQclear (res); | 422 | PQclear (res); |
416 | return GNUNET_SYSERR; | 423 | return GNUNET_SYSERR; |
417 | } | 424 | } |
418 | zone_key = (const struct GNUNET_CRYPTO_EccPublicKey *) PQgetvalue (res, 0, 0); | 425 | zone_key = (const struct GNUNET_CRYPTO_EccPrivateKey *) PQgetvalue (res, 0, 0); |
426 | /* zone_key = (const struct GNUNET_CRYPTO_EccPublicKey *) PQgetvalue (res, 0, 0); */ | ||
419 | name = PQgetvalue (res, 0, 1); | 427 | name = PQgetvalue (res, 0, 1); |
420 | name_len = PQgetlength (res, 0, 1); | 428 | name_len = PQgetlength (res, 0, 1); |
421 | record_count = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2)); | 429 | record_count = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2)); |
422 | data_size = PQgetlength (res, 0, 3); | 430 | data_size = PQgetlength (res, 0, 3); |
423 | data = PQgetvalue (res, 0, 3); | 431 | data = PQgetvalue (res, 0, 3); |
432 | /* | ||
424 | expiration.abs_value_us = | 433 | expiration.abs_value_us = |
425 | GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 4)); | 434 | GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 4)); |
426 | sig = (const struct GNUNET_CRYPTO_EccSignature*) PQgetvalue (res, 0, 5); | 435 | sig = (const struct GNUNET_CRYPTO_EccSignature*) PQgetvalue (res, 0, 5); */ |
427 | if (record_count > 64 * 1024) | 436 | if (record_count > 64 * 1024) |
428 | { | 437 | { |
429 | /* sanity check, don't stack allocate far too much just | 438 | /* sanity check, don't stack allocate far too much just |
@@ -446,8 +455,7 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
446 | PQclear (res); | 455 | PQclear (res); |
447 | return GNUNET_SYSERR; | 456 | return GNUNET_SYSERR; |
448 | } | 457 | } |
449 | iter (iter_cls, zone_key, expiration, buf, | 458 | iter (iter_cls, zone_key, buf, record_count, rd); |
450 | record_count, rd, sig); | ||
451 | } | 459 | } |
452 | PQclear (res); | 460 | PQclear (res); |
453 | return GNUNET_OK; | 461 | return GNUNET_OK; |
@@ -460,7 +468,6 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
460 | * | 468 | * |
461 | * @param cls closure (internal context for the plugin) | 469 | * @param cls closure (internal context for the plugin) |
462 | * @param zone hash of public key of the zone, NULL to iterate over all zones | 470 | * @param zone hash of public key of the zone, NULL to iterate over all zones |
463 | * @param name name as string, NULL to iterate over all records of the zone | ||
464 | * @param offset offset in the list of all matching records | 471 | * @param offset offset in the list of all matching records |
465 | * @param iter function to call with the result | 472 | * @param iter function to call with the result |
466 | * @param iter_cls closure for iter | 473 | * @param iter_cls closure for iter |
@@ -469,11 +476,11 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
469 | */ | 476 | */ |
470 | static int | 477 | static int |
471 | namestore_postgres_iterate_records (void *cls, | 478 | namestore_postgres_iterate_records (void *cls, |
472 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 479 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, |
473 | const char *name, | ||
474 | uint64_t offset, | 480 | uint64_t offset, |
475 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 481 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
476 | { | 482 | { |
483 | #if 0 | ||
477 | struct Plugin *plugin = cls; | 484 | struct Plugin *plugin = cls; |
478 | const char *stmt_name; | 485 | const char *stmt_name; |
479 | struct GNUNET_CRYPTO_ShortHashCode name_hase; | 486 | struct GNUNET_CRYPTO_ShortHashCode name_hase; |
@@ -506,7 +513,9 @@ namestore_postgres_iterate_records (void *cls, | |||
506 | } | 513 | } |
507 | else | 514 | else |
508 | { | 515 | { |
509 | GNUNET_CRYPTO_short_hash (name, strlen(name), &name_hase); | 516 | /* TODO Adapt to new API |
517 | * GNUNET_CRYPTO_short_hash (name, strlen(name), &name_hase); | ||
518 | */ | ||
510 | stmt_name = "iterate_by_name"; | 519 | stmt_name = "iterate_by_name"; |
511 | num_params = 2; | 520 | num_params = 2; |
512 | first_param = 1; | 521 | first_param = 1; |
@@ -520,7 +529,9 @@ namestore_postgres_iterate_records (void *cls, | |||
520 | } | 529 | } |
521 | else | 530 | else |
522 | { | 531 | { |
523 | GNUNET_CRYPTO_short_hash (name, strlen(name), &name_hase); | 532 | /* TODO Adapt to new API |
533 | * GNUNET_CRYPTO_short_hash (name, strlen(name), &name_hase); | ||
534 | */ | ||
524 | stmt_name = "iterate_records"; | 535 | stmt_name = "iterate_records"; |
525 | num_params = 3; | 536 | num_params = 3; |
526 | first_param = 0; | 537 | first_param = 0; |
@@ -531,6 +542,9 @@ namestore_postgres_iterate_records (void *cls, | |||
531 | ¶mLengths[first_param], | 542 | ¶mLengths[first_param], |
532 | ¶mFormats[first_param], 1); | 543 | ¶mFormats[first_param], 1); |
533 | return get_record_and_call_iterator (plugin, stmt_name, res, iter, iter_cls); | 544 | return get_record_and_call_iterator (plugin, stmt_name, res, iter, iter_cls); |
545 | #endif | ||
546 | GNUNET_break (0); | ||
547 | return GNUNET_SYSERR; | ||
534 | } | 548 | } |
535 | 549 | ||
536 | 550 | ||
@@ -548,10 +562,11 @@ namestore_postgres_iterate_records (void *cls, | |||
548 | */ | 562 | */ |
549 | static int | 563 | static int |
550 | namestore_postgres_zone_to_name (void *cls, | 564 | namestore_postgres_zone_to_name (void *cls, |
551 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 565 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, |
552 | const struct GNUNET_CRYPTO_ShortHashCode *value_zone, | 566 | const struct GNUNET_CRYPTO_EccPublicKey *value_zone, |
553 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 567 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
554 | { | 568 | { |
569 | #if 0 | ||
555 | struct Plugin *plugin = cls; | 570 | struct Plugin *plugin = cls; |
556 | const char *paramValues[] = { | 571 | const char *paramValues[] = { |
557 | (const char *) zone, | 572 | (const char *) zone, |
@@ -568,6 +583,9 @@ namestore_postgres_zone_to_name (void *cls, | |||
568 | PQexecPrepared (plugin->dbh, "zone_to_name", 2, | 583 | PQexecPrepared (plugin->dbh, "zone_to_name", 2, |
569 | paramValues, paramLengths, paramFormats, 1); | 584 | paramValues, paramLengths, paramFormats, 1); |
570 | return get_record_and_call_iterator (plugin, "zone_to_name", res, iter, iter_cls); | 585 | return get_record_and_call_iterator (plugin, "zone_to_name", res, iter, iter_cls); |
586 | #endif | ||
587 | GNUNET_break (0); | ||
588 | return GNUNET_SYSERR; | ||
571 | } | 589 | } |
572 | 590 | ||
573 | 591 | ||
@@ -604,6 +622,68 @@ namestore_postgres_delete_zone (void *cls, | |||
604 | PQclear (ret); | 622 | PQclear (ret); |
605 | } | 623 | } |
606 | 624 | ||
625 | /** | ||
626 | * Cache a block in the datastore. | ||
627 | * | ||
628 | * @param cls closure (internal context for the plugin) | ||
629 | * @param block block to cache | ||
630 | * @return GNUNET_OK on success, else GNUNET_SYSERR | ||
631 | */ | ||
632 | static int | ||
633 | namestore_postgres_cache_block (void *cls, | ||
634 | const struct GNUNET_NAMESTORE_Block *block) | ||
635 | { | ||
636 | // struct Plugin *plugin = cls; | ||
637 | GNUNET_break (0); | ||
638 | /* To be implemented */ | ||
639 | return GNUNET_OK; | ||
640 | } | ||
641 | |||
642 | /** | ||
643 | * Get the block for a particular zone and label in the | ||
644 | * datastore. Will return at most one result to the iterator. | ||
645 | * | ||
646 | * @param cls closure (internal context for the plugin) | ||
647 | * @param query hash of public key derived from the zone and the label | ||
648 | * @param iter function to call with the result | ||
649 | * @param iter_cls closure for iter | ||
650 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
651 | */ | ||
652 | static int | ||
653 | namestore_postgres_lookup_block (void *cls, | ||
654 | const struct GNUNET_HashCode *query, | ||
655 | GNUNET_NAMESTORE_BlockCallback iter, void *iter_cls) | ||
656 | { | ||
657 | // struct Plugin *plugin = cls; | ||
658 | GNUNET_break (0); | ||
659 | /* To be implemented */ | ||
660 | return GNUNET_OK; | ||
661 | } | ||
662 | |||
663 | /** | ||
664 | * Store a record in the datastore. Removes any existing record in the | ||
665 | * same zone with the same name. | ||
666 | * | ||
667 | * @param cls closure (internal context for the plugin) | ||
668 | * @param zone_key private key of the zone | ||
669 | * @param label name that is being mapped (at most 255 characters long) | ||
670 | * @param rd_count number of entries in 'rd' array | ||
671 | * @param rd array of records with data to store | ||
672 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
673 | */ | ||
674 | static int | ||
675 | namestore_postgres_store_records (void *cls, | ||
676 | const struct GNUNET_CRYPTO_EccPrivateKey *zone_key, | ||
677 | const char *label, | ||
678 | unsigned int rd_count, | ||
679 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
680 | { | ||
681 | // struct Plugin *plugin = cls; | ||
682 | GNUNET_break (0); | ||
683 | /* To be implemented */ | ||
684 | return GNUNET_OK; | ||
685 | } | ||
686 | |||
607 | 687 | ||
608 | /** | 688 | /** |
609 | * Shutdown database connection and associate data | 689 | * Shutdown database connection and associate data |
@@ -643,11 +723,14 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
643 | } | 723 | } |
644 | api = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_PluginFunctions)); | 724 | api = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_PluginFunctions)); |
645 | api->cls = &plugin; | 725 | api->cls = &plugin; |
646 | api->put_records = &namestore_postgres_put_records; | 726 | /* api->put_records = &namestore_postgres_put_records; */ |
647 | api->remove_records = &namestore_postgres_remove_records; | 727 | /* api->remove_records = &namestore_postgres_remove_records; */ |
728 | api->cache_block = &namestore_postgres_cache_block; | ||
729 | api->lookup_block = &namestore_postgres_lookup_block; | ||
730 | api->store_records = &namestore_postgres_store_records; | ||
648 | api->iterate_records = &namestore_postgres_iterate_records; | 731 | api->iterate_records = &namestore_postgres_iterate_records; |
649 | api->zone_to_name = &namestore_postgres_zone_to_name; | 732 | api->zone_to_name = &namestore_postgres_zone_to_name; |
650 | api->delete_zone = &namestore_postgres_delete_zone; | 733 | /* api->delete_zone = &namestore_postgres_delete_zone; */ |
651 | LOG (GNUNET_ERROR_TYPE_INFO, | 734 | LOG (GNUNET_ERROR_TYPE_INFO, |
652 | _("Postgres database running\n")); | 735 | _("Postgres database running\n")); |
653 | return api; | 736 | return api; |