aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/plugin_peerstore_sqlite.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-04-27 18:40:04 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-04-27 18:40:04 +0000
commita8504a84ee0161e36180811b1d44fd1dc3ab9b17 (patch)
treeee2fe1ae4fddd83759d906deeaae8d70eae98fd7 /src/peerstore/plugin_peerstore_sqlite.c
parent4637bb9965f3b945426d888f353e566da75ee32a (diff)
downloadgnunet-a8504a84ee0161e36180811b1d44fd1dc3ab9b17.tar.gz
gnunet-a8504a84ee0161e36180811b1d44fd1dc3ab9b17.zip
PEERSTORE sqlite plugin store function
Diffstat (limited to 'src/peerstore/plugin_peerstore_sqlite.c')
-rw-r--r--src/peerstore/plugin_peerstore_sqlite.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c
index ff6ae9f67..41b6044b3 100644
--- a/src/peerstore/plugin_peerstore_sqlite.c
+++ b/src/peerstore/plugin_peerstore_sqlite.c
@@ -80,6 +80,51 @@ struct Plugin
80}; 80};
81 81
82/** 82/**
83 * Store a record in the peerstore.
84 * Key is the combination of sub system and peer identity.
85 * One key can store multiple values.
86 *
87 * @param cls closure (internal context for the plugin)
88 * @param sub_system name of the GNUnet sub system responsible
89 * @param peer peer identity
90 * @param value value to be stored
91 * @param size size of value to be stored
92 * @return #GNUNET_OK on success, else #GNUNET_SYSERR
93 */
94static int
95peerstore_sqlite_store_record (void *cls,
96 const char *sub_system,
97 const struct GNUNET_PeerIdentity *peer,
98 const void *value,
99 size_t size)
100{
101 struct Plugin *plugin = cls;
102 sqlite3_stmt *stmt = plugin->insert_peerstoredata;
103
104 //FIXME: check if value exists with the same key first
105
106 if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, sizeof(sub_system), SQLITE_STATIC)
107 || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC)
108 || SQLITE_OK != sqlite3_bind_blob(stmt, 3, value, size, SQLITE_STATIC))
109 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
110 "sqlite3_bind");
111 else if (SQLITE_DONE != sqlite3_step (stmt))
112 {
113 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
114 "sqlite3_step");
115 }
116 if (SQLITE_OK != sqlite3_reset (stmt))
117 {
118 LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
119 "sqlite3_reset");
120 return GNUNET_SYSERR;
121 }
122
123 return GNUNET_OK;
124}
125
126
127/**
83 * @brief Prepare a SQL statement 128 * @brief Prepare a SQL statement
84 * 129 *
85 * @param dbh handle to the database 130 * @param dbh handle to the database
@@ -243,7 +288,8 @@ libgnunet_plugin_peerstore_sqlite_init (void *cls)
243 } 288 }
244 api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions); 289 api = GNUNET_new (struct GNUNET_PEERSTORE_PluginFunctions);
245 api->cls = &plugin; 290 api->cls = &plugin;
246 LOG(GNUNET_ERROR_TYPE_INFO, "Sqlite plugin is running\n"); 291 api->store_record = &peerstore_sqlite_store_record;
292 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is running\n");
247 return api; 293 return api;
248} 294}
249 295
@@ -262,7 +308,7 @@ libgnunet_plugin_peerstore_sqlite_done (void *cls)
262 database_shutdown (plugin); 308 database_shutdown (plugin);
263 plugin->cfg = NULL; 309 plugin->cfg = NULL;
264 GNUNET_free (api); 310 GNUNET_free (api);
265 LOG (GNUNET_ERROR_TYPE_INFO, "Sqlite plugin is finished\n"); 311 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sqlite plugin is finished\n");
266 return NULL; 312 return NULL;
267 313
268} 314}