diff options
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 81 |
1 files changed, 73 insertions, 8 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index bdbaf96b3..3b1b7ac21 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -553,6 +553,68 @@ namestore_postgres_zone_to_name (void *cls, | |||
553 | return GNUNET_OK; | 553 | return GNUNET_OK; |
554 | } | 554 | } |
555 | 555 | ||
556 | /** | ||
557 | * Begin a transaction for a client. | ||
558 | * | ||
559 | * @param cls closure (internal context for the plugin) | ||
560 | * @param emsg error message set of return code is #GNUNET_SYSERR | ||
561 | * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started. | ||
562 | */ | ||
563 | static enum GNUNET_GenericReturnValue | ||
564 | namestore_postgres_transaction_begin (void *cls, | ||
565 | char **emsg) | ||
566 | { | ||
567 | struct Plugin *plugin = cls; | ||
568 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
569 | GNUNET_PQ_make_execute ("BEGIN;"), | ||
570 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
571 | }; | ||
572 | |||
573 | return GNUNET_PQ_exec_statements (plugin->dbh, es); | ||
574 | } | ||
575 | |||
576 | /** | ||
577 | * Commit a transaction for a client. | ||
578 | * This releases the lock on the database. | ||
579 | * | ||
580 | * @param cls closure (internal context for the plugin) | ||
581 | * @param emsg error message set of return code is #GNUNET_SYSERR | ||
582 | * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started. | ||
583 | */ | ||
584 | static enum GNUNET_GenericReturnValue | ||
585 | namestore_postgres_transaction_rollback (void *cls, | ||
586 | char **emsg) | ||
587 | { | ||
588 | struct Plugin *plugin = cls; | ||
589 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
590 | GNUNET_PQ_make_execute ("ROLLBACK;"), | ||
591 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
592 | }; | ||
593 | |||
594 | return GNUNET_PQ_exec_statements (plugin->dbh, es); | ||
595 | } | ||
596 | |||
597 | /** | ||
598 | * Roll back a transaction for a client. | ||
599 | * This releases the lock on the database. | ||
600 | * | ||
601 | * @param cls closure (internal context for the plugin) | ||
602 | * @param emsg error message set of return code is #GNUNET_SYSERR | ||
603 | * @return #GNUNET_YES on success, #GNUNET_SYSERR if transaction cannot be started. | ||
604 | */ | ||
605 | static enum GNUNET_GenericReturnValue | ||
606 | namestore_postgres_transaction_commit (void *cls, | ||
607 | char **emsg) | ||
608 | { | ||
609 | struct Plugin *plugin = cls; | ||
610 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
611 | GNUNET_PQ_make_execute ("COMMIT;"), | ||
612 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
613 | }; | ||
614 | |||
615 | return GNUNET_PQ_exec_statements (plugin->dbh, es); | ||
616 | } | ||
617 | |||
556 | 618 | ||
557 | /** | 619 | /** |
558 | * Shutdown database connection and associate data | 620 | * Shutdown database connection and associate data |
@@ -577,25 +639,27 @@ database_shutdown (struct Plugin *plugin) | |||
577 | void * | 639 | void * |
578 | libgnunet_plugin_namestore_postgres_init (void *cls) | 640 | libgnunet_plugin_namestore_postgres_init (void *cls) |
579 | { | 641 | { |
580 | static struct Plugin plugin; | 642 | struct Plugin *plugin; |
581 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 643 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
582 | struct GNUNET_NAMESTORE_PluginFunctions *api; | 644 | struct GNUNET_NAMESTORE_PluginFunctions *api; |
583 | 645 | ||
584 | if (NULL != plugin.cfg) | 646 | plugin = GNUNET_new (struct Plugin); |
585 | return NULL; /* can only initialize once! */ | 647 | plugin->cfg = cfg; |
586 | memset (&plugin, 0, sizeof(struct Plugin)); | 648 | if (GNUNET_OK != database_setup (plugin)) |
587 | plugin.cfg = cfg; | ||
588 | if (GNUNET_OK != database_setup (&plugin)) | ||
589 | { | 649 | { |
590 | database_shutdown (&plugin); | 650 | database_shutdown (plugin); |
651 | GNUNET_free (plugin); | ||
591 | return NULL; | 652 | return NULL; |
592 | } | 653 | } |
593 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); | 654 | api = GNUNET_new (struct GNUNET_NAMESTORE_PluginFunctions); |
594 | api->cls = &plugin; | 655 | api->cls = plugin; |
595 | api->store_records = &namestore_postgres_store_records; | 656 | api->store_records = &namestore_postgres_store_records; |
596 | api->iterate_records = &namestore_postgres_iterate_records; | 657 | api->iterate_records = &namestore_postgres_iterate_records; |
597 | api->zone_to_name = &namestore_postgres_zone_to_name; | 658 | api->zone_to_name = &namestore_postgres_zone_to_name; |
598 | api->lookup_records = &namestore_postgres_lookup_records; | 659 | api->lookup_records = &namestore_postgres_lookup_records; |
660 | api->transaction_begin = &namestore_postgres_transaction_begin; | ||
661 | api->transaction_commit = &namestore_postgres_transaction_commit; | ||
662 | api->transaction_rollback = &namestore_postgres_transaction_rollback; | ||
599 | LOG (GNUNET_ERROR_TYPE_INFO, | 663 | LOG (GNUNET_ERROR_TYPE_INFO, |
600 | "Postgres namestore plugin running\n"); | 664 | "Postgres namestore plugin running\n"); |
601 | return api; | 665 | return api; |
@@ -616,6 +680,7 @@ libgnunet_plugin_namestore_postgres_done (void *cls) | |||
616 | 680 | ||
617 | database_shutdown (plugin); | 681 | database_shutdown (plugin); |
618 | plugin->cfg = NULL; | 682 | plugin->cfg = NULL; |
683 | GNUNET_free (plugin); | ||
619 | GNUNET_free (api); | 684 | GNUNET_free (api); |
620 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 685 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
621 | "Postgres namestore plugin is finished\n"); | 686 | "Postgres namestore plugin is finished\n"); |