aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore/gnunet-service-psycstore.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-08-29 15:14:17 +0000
committerGabor X Toth <*@tg-x.net>2013-08-29 15:14:17 +0000
commit81eaa5a9d5ebe1e61790069a2777178abd1b6a2c (patch)
tree2b24561b930dca7ede2d27590e1c434fe19ed365 /src/psycstore/gnunet-service-psycstore.c
parentb1ed5b9a472bd56796646a70068eb48da0db3e2f (diff)
downloadgnunet-81eaa5a9d5ebe1e61790069a2777178abd1b6a2c.tar.gz
gnunet-81eaa5a9d5ebe1e61790069a2777178abd1b6a2c.zip
psycstore: sqlite plugin
Diffstat (limited to 'src/psycstore/gnunet-service-psycstore.c')
-rw-r--r--src/psycstore/gnunet-service-psycstore.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c
index 977f77e06..d8f7a2690 100644
--- a/src/psycstore/gnunet-service-psycstore.c
+++ b/src/psycstore/gnunet-service-psycstore.c
@@ -34,6 +34,7 @@
34#include "gnunet_protocols.h" 34#include "gnunet_protocols.h"
35#include "gnunet_statistics_service.h" 35#include "gnunet_statistics_service.h"
36#include "gnunet_psycstore_service.h" 36#include "gnunet_psycstore_service.h"
37#include "gnunet_psycstore_plugin.h"
37#include "psycstore.h" 38#include "psycstore.h"
38 39
39 40
@@ -53,9 +54,14 @@ static struct GNUNET_STATISTICS_Handle *stats;
53static struct GNUNET_SERVER_NotificationContext *nc; 54static struct GNUNET_SERVER_NotificationContext *nc;
54 55
55/** 56/**
56 * Database file. 57 * Database handle
57 */ 58 */
58static char *db_file; 59static struct GNUNET_PSYCSTORE_PluginFunctions *db;
60
61/**
62 * Name of the database plugin
63 */
64static char *db_lib_name;
59 65
60 66
61/** 67/**
@@ -77,8 +83,9 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
77 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 83 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
78 stats = NULL; 84 stats = NULL;
79 } 85 }
80 GNUNET_free (db_file); 86 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
81 db_file = NULL; 87 GNUNET_free (db_lib_name);
88 db_lib_name = NULL;
82} 89}
83 90
84 91
@@ -123,7 +130,7 @@ send_result_code (struct GNUNET_SERVER_Client *client,
123 * @param c configuration to use 130 * @param c configuration to use
124 */ 131 */
125static void 132static void
126run (void *cls, 133run (void *cls,
127 struct GNUNET_SERVER_Handle *server, 134 struct GNUNET_SERVER_Handle *server,
128 const struct GNUNET_CONFIGURATION_Handle *c) 135 const struct GNUNET_CONFIGURATION_Handle *c)
129{ 136{
@@ -132,15 +139,30 @@ run (void *cls,
132 }; 139 };
133 140
134 cfg = c; 141 cfg = c;
142
143 /* Loading database plugin */
144 char *database;
135 if (GNUNET_OK != 145 if (GNUNET_OK !=
136 GNUNET_CONFIGURATION_get_value_filename (cfg, "psycstore", 146 GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
137 "DB_FILE", 147 &database))
138 &db_file)) 148 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
150 }
151 else
139 { 152 {
140 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "psycstore", "DB_FILE"); 153 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_psycstore_%s", database);
141 GNUNET_SCHEDULER_shutdown (); 154 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
155 GNUNET_free (database);
156 }
157 if (NULL == db)
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "Could not load database backend `%s'\n",
161 db_lib_name);
162 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
142 return; 163 return;
143 } 164 }
165
144 stats = GNUNET_STATISTICS_create ("psycstore", cfg); 166 stats = GNUNET_STATISTICS_create ("psycstore", cfg);
145 GNUNET_SERVER_add_handlers (server, handlers); 167 GNUNET_SERVER_add_handlers (server, handlers);
146 nc = GNUNET_SERVER_notification_context_create (server, 1); 168 nc = GNUNET_SERVER_notification_context_create (server, 1);
@@ -160,7 +182,7 @@ int
160main (int argc, char *const *argv) 182main (int argc, char *const *argv)
161{ 183{
162 return (GNUNET_OK == 184 return (GNUNET_OK ==
163 GNUNET_SERVICE_run (argc, argv, "psycstore", 185 GNUNET_SERVICE_run (argc, argv, "psycstore",
164 GNUNET_SERVICE_OPTION_NONE, 186 GNUNET_SERVICE_OPTION_NONE,
165 &run, NULL)) ? 0 : 1; 187 &run, NULL)) ? 0 : 1;
166} 188}