diff options
Diffstat (limited to 'src/peerstore/plugin_peerstore_sqlite.c')
-rw-r--r-- | src/peerstore/plugin_peerstore_sqlite.c | 61 |
1 files changed, 2 insertions, 59 deletions
diff --git a/src/peerstore/plugin_peerstore_sqlite.c b/src/peerstore/plugin_peerstore_sqlite.c index ead2aade6..8d35466de 100644 --- a/src/peerstore/plugin_peerstore_sqlite.c +++ b/src/peerstore/plugin_peerstore_sqlite.c | |||
@@ -51,6 +51,8 @@ | |||
51 | 51 | ||
52 | #define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__) | 52 | #define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__) |
53 | 53 | ||
54 | //FIXME: Indexes | ||
55 | |||
54 | /** | 56 | /** |
55 | * Context for all functions in this plugin. | 57 | * Context for all functions in this plugin. |
56 | */ | 58 | */ |
@@ -98,11 +100,6 @@ struct Plugin | |||
98 | sqlite3_stmt *select_peerstoredata_by_all; | 100 | sqlite3_stmt *select_peerstoredata_by_all; |
99 | 101 | ||
100 | /** | 102 | /** |
101 | * Precompiled SQL for selecting from peerstoredata | ||
102 | */ | ||
103 | sqlite3_stmt *select_peerstoredata_by_all_and_value; | ||
104 | |||
105 | /** | ||
106 | * Precompiled SQL for deleting expired records from peerstoredata | 103 | * Precompiled SQL for deleting expired records from peerstoredata |
107 | */ | 104 | */ |
108 | sqlite3_stmt *expire_peerstoredata; | 105 | sqlite3_stmt *expire_peerstoredata; |
@@ -237,42 +234,6 @@ peerstore_sqlite_iterate_records (void *cls, | |||
237 | } | 234 | } |
238 | 235 | ||
239 | /** | 236 | /** |
240 | * Checks if a record with the given information | ||
241 | * already exists | ||
242 | * | ||
243 | * @return #GNUNET_YES / #GNUNET_NO | ||
244 | * | ||
245 | static int | ||
246 | check_existing(void *cls, | ||
247 | const char *sub_system, | ||
248 | const struct GNUNET_PeerIdentity *peer, | ||
249 | const char *key, | ||
250 | const void *value, | ||
251 | size_t size) | ||
252 | { | ||
253 | struct Plugin *plugin = cls; | ||
254 | sqlite3_stmt *stmt = plugin->select_peerstoredata_by_all_and_value; | ||
255 | int sret; | ||
256 | |||
257 | if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC) | ||
258 | || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC) | ||
259 | || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC) | ||
260 | || SQLITE_OK != sqlite3_bind_blob(stmt, 4, value, size, SQLITE_STATIC)) | ||
261 | { | ||
262 | LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
263 | "sqlite3_bind"); | ||
264 | sqlite3_reset(stmt); | ||
265 | return GNUNET_NO; | ||
266 | } | ||
267 | sret = sqlite3_step (stmt); | ||
268 | sqlite3_reset(stmt); | ||
269 | if(SQLITE_ROW == sret) | ||
270 | return GNUNET_YES; | ||
271 | return GNUNET_NO; | ||
272 | |||
273 | }*/ | ||
274 | |||
275 | /** | ||
276 | * Store a record in the peerstore. | 237 | * Store a record in the peerstore. |
277 | * Key is the combination of sub system and peer identity. | 238 | * Key is the combination of sub system and peer identity. |
278 | * One key can store multiple values. | 239 | * One key can store multiple values. |
@@ -296,17 +257,6 @@ peerstore_sqlite_store_record(void *cls, | |||
296 | struct Plugin *plugin = cls; | 257 | struct Plugin *plugin = cls; |
297 | sqlite3_stmt *stmt = plugin->insert_peerstoredata; | 258 | sqlite3_stmt *stmt = plugin->insert_peerstoredata; |
298 | 259 | ||
299 | //FIXME: check if value exists with the same key first | ||
300 | /*if(GNUNET_YES == check_existing(cls, | ||
301 | sub_system, | ||
302 | peer, | ||
303 | key, | ||
304 | value, | ||
305 | size)) | ||
306 | { | ||
307 | |||
308 | }*/ | ||
309 | |||
310 | if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC) | 260 | if(SQLITE_OK != sqlite3_bind_text(stmt, 1, sub_system, strlen(sub_system) + 1, SQLITE_STATIC) |
311 | || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC) | 261 | || SQLITE_OK != sqlite3_bind_blob(stmt, 2, peer, sizeof(struct GNUNET_PeerIdentity), SQLITE_STATIC) |
312 | || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC) | 262 | || SQLITE_OK != sqlite3_bind_text(stmt, 3, key, strlen(key) + 1, SQLITE_STATIC) |
@@ -466,13 +416,6 @@ database_setup (struct Plugin *plugin) | |||
466 | " AND key = ?", | 416 | " AND key = ?", |
467 | &plugin->select_peerstoredata_by_all); | 417 | &plugin->select_peerstoredata_by_all); |
468 | sql_prepare(plugin->dbh, | 418 | sql_prepare(plugin->dbh, |
469 | "SELECT * FROM peerstoredata" | ||
470 | " WHERE sub_system = ?" | ||
471 | " AND peer_id = ?" | ||
472 | " AND key = ?" | ||
473 | " AND value = ?", | ||
474 | &plugin->select_peerstoredata_by_all_and_value); | ||
475 | sql_prepare(plugin->dbh, | ||
476 | "DELETE FROM peerstoredata" | 419 | "DELETE FROM peerstoredata" |
477 | " WHERE expiry < ?", | 420 | " WHERE expiry < ?", |
478 | &plugin->expire_peerstoredata); | 421 | &plugin->expire_peerstoredata); |