aboutsummaryrefslogtreecommitdiff
path: root/src/datacache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/datacache
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/datacache')
-rw-r--r--src/datacache/datacache.c37
-rw-r--r--src/datacache/perf_datacache.c47
-rw-r--r--src/datacache/plugin_datacache_mysql.c247
-rw-r--r--src/datacache/plugin_datacache_postgres.c170
-rw-r--r--src/datacache/plugin_datacache_sqlite.c161
-rw-r--r--src/datacache/plugin_datacache_template.c14
-rw-r--r--src/datacache/test_datacache.c39
-rw-r--r--src/datacache/test_datacache_quota.c15
8 files changed, 292 insertions, 438 deletions
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index a17eb9628..9d12fbc3e 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -105,8 +105,8 @@ env_delete_notify (void *cls, const GNUNET_HashCode * key, size_t size)
105 GNUNET_assert (h->utilization >= size); 105 GNUNET_assert (h->utilization >= size);
106 h->utilization -= size; 106 h->utilization -= size;
107 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key); 107 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
108 GNUNET_STATISTICS_update (h->stats, 108 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), -size,
109 gettext_noop ("# bytes stored"), -size, GNUNET_NO); 109 GNUNET_NO);
110} 110}
111 111
112 112
@@ -131,16 +131,16 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
131 GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", &quota)) 131 GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", &quota))
132 { 132 {
133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
134 _("No `%s' specified for `%s' in configuration!\n"), 134 _("No `%s' specified for `%s' in configuration!\n"), "QUOTA",
135 "QUOTA", section); 135 section);
136 return NULL; 136 return NULL;
137 } 137 }
138 if (GNUNET_OK != 138 if (GNUNET_OK !=
139 GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name)) 139 GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name))
140 { 140 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 _("No `%s' specified for `%s' in configuration!\n"), 142 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
143 "DATABASE", section); 143 section);
144 return NULL; 144 return NULL;
145 } 145 }
146 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ 146 bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */
@@ -164,8 +164,8 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
164 ret->env.cls = ret; 164 ret->env.cls = ret;
165 ret->env.delete_notify = &env_delete_notify; 165 ret->env.delete_notify = &env_delete_notify;
166 ret->env.quota = quota; 166 ret->env.quota = quota;
167 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 167 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datacache plugin\n"),
168 _("Loading `%s' datacache plugin\n"), name); 168 name);
169 GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name); 169 GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name);
170 ret->short_name = name; 170 ret->short_name = name;
171 ret->lib_name = libname; 171 ret->lib_name = libname;
@@ -199,8 +199,8 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
199 if (h->bloom_name != NULL) 199 if (h->bloom_name != NULL)
200 { 200 {
201 if (0 != UNLINK (h->bloom_name)) 201 if (0 != UNLINK (h->bloom_name))
202 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 202 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink",
203 "unlink", h->bloom_name); 203 h->bloom_name);
204 GNUNET_free (h->bloom_name); 204 GNUNET_free (h->bloom_name);
205 } 205 }
206 GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO); 206 GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO);
@@ -221,10 +221,8 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
221 */ 221 */
222int 222int
223GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, 223GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
224 const GNUNET_HashCode * key, 224 const GNUNET_HashCode * key, size_t size,
225 size_t size, 225 const char *data, enum GNUNET_BLOCK_Type type,
226 const char *data,
227 enum GNUNET_BLOCK_Type type,
228 struct GNUNET_TIME_Absolute discard_time) 226 struct GNUNET_TIME_Absolute discard_time)
229{ 227{
230 uint32_t used; 228 uint32_t used;
@@ -235,8 +233,8 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
235 GNUNET_break (0); 233 GNUNET_break (0);
236 return GNUNET_SYSERR; 234 return GNUNET_SYSERR;
237 } 235 }
238 GNUNET_STATISTICS_update (h->stats, 236 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size,
239 gettext_noop ("# bytes stored"), size, GNUNET_NO); 237 GNUNET_NO);
240 GNUNET_CONTAINER_bloomfilter_add (h->filter, key); 238 GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
241 while (h->utilization + used > h->env.quota) 239 while (h->utilization + used > h->env.quota)
242 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls)); 240 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
@@ -258,12 +256,11 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
258 */ 256 */
259unsigned int 257unsigned int
260GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, 258GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
261 const GNUNET_HashCode * key, 259 const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type,
262 enum GNUNET_BLOCK_Type type,
263 GNUNET_DATACACHE_Iterator iter, void *iter_cls) 260 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
264{ 261{
265 GNUNET_STATISTICS_update (h->stats, 262 GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1,
266 gettext_noop ("# requests received"), 1, GNUNET_NO); 263 GNUNET_NO);
267 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) 264 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key))
268 { 265 {
269 GNUNET_STATISTICS_update (h->stats, 266 GNUNET_STATISTICS_update (h->stats,
diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c
index 3af76dbb6..a5dc02362 100644
--- a/src/datacache/perf_datacache.c
+++ b/src/datacache/perf_datacache.c
@@ -44,10 +44,9 @@ static const char *plugin_name;
44 44
45 45
46static int 46static int
47checkIt (void *cls, 47checkIt (void *cls, struct GNUNET_TIME_Absolute exp,
48 struct GNUNET_TIME_Absolute exp, 48 const GNUNET_HashCode * key, size_t size, const char *data,
49 const GNUNET_HashCode * key, 49 enum GNUNET_BLOCK_Type type)
50 size_t size, const char *data, enum GNUNET_BLOCK_Type type)
51{ 50{
52 if ((size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size))) 51 if ((size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size)))
53 found++; 52 found++;
@@ -56,9 +55,8 @@ checkIt (void *cls,
56 55
57 56
58static void 57static void
59run (void *cls, 58run (void *cls, char *const *args, const char *cfgfile,
60 char *const *args, 59 const struct GNUNET_CONFIGURATION_Handle *cfg)
61 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
62{ 60{
63 struct GNUNET_DATACACHE_Handle *h; 61 struct GNUNET_DATACACHE_Handle *h;
64 GNUNET_HashCode k; 62 GNUNET_HashCode k;
@@ -86,21 +84,17 @@ run (void *cls,
86 if (0 == i % (ITERATIONS / 80)) 84 if (0 == i % (ITERATIONS / 80))
87 fprintf (stderr, "."); 85 fprintf (stderr, ".");
88 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); 86 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
89 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, 87 ASSERT (GNUNET_OK ==
90 &k, 88 GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode),
91 sizeof (GNUNET_HashCode), 89 (const char *) &n, 1 + i % 16, exp));
92 (const char *) &n,
93 1 + i % 16, exp));
94 k = n; 90 k = n;
95 } 91 }
96 fprintf (stderr, "\n"); 92 fprintf (stderr, "\n");
97 fprintf (stdout, "Stored %u items in %llums\n", 93 fprintf (stdout, "Stored %u items in %llums\n", ITERATIONS,
98 ITERATIONS, 94 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
99 (unsigned long long) 95 rel_value);
100 GNUNET_TIME_absolute_get_duration (start).rel_value);
101 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name); 96 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name);
102 GAUGER (gstr, 97 GAUGER (gstr, "Time to PUT item in datacache",
103 "Time to PUT item in datacache",
104 GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS, 98 GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS,
105 "ms/item"); 99 "ms/item");
106 start = GNUNET_TIME_absolute_get (); 100 start = GNUNET_TIME_absolute_get ();
@@ -117,12 +111,10 @@ run (void *cls,
117 fprintf (stdout, 111 fprintf (stdout,
118 "Found %u/%u items in %llums (%u were deleted during storage processing)\n", 112 "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
119 found, ITERATIONS, 113 found, ITERATIONS,
120 (unsigned long long) 114 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
121 GNUNET_TIME_absolute_get_duration (start).rel_value, 115 rel_value, ITERATIONS - found);
122 ITERATIONS - found);
123 if (found > 0) 116 if (found > 0)
124 GAUGER (gstr, 117 GAUGER (gstr, "Time to GET item from datacache",
125 "Time to GET item from datacache",
126 GNUNET_TIME_absolute_get_duration (start).rel_value / found, 118 GNUNET_TIME_absolute_get_duration (start).rel_value / found,
127 "ms/item"); 119 "ms/item");
128 GNUNET_DATACACHE_destroy (h); 120 GNUNET_DATACACHE_destroy (h);
@@ -170,13 +162,12 @@ main (int argc, char *argv[])
170 else 162 else
171 pos = (char *) plugin_name; 163 pos = (char *) plugin_name;
172 164
173 GNUNET_snprintf (cfg_name, 165 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "perf_datacache_data_%s.conf",
174 sizeof (cfg_name), 166 plugin_name);
175 "perf_datacache_data_%s.conf", plugin_name);
176 if (pos != plugin_name) 167 if (pos != plugin_name)
177 pos[0] = '.'; 168 pos[0] = '.';
178 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 169 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
179 xargv, "perf-datacache", "nohelp", options, &run, NULL); 170 "perf-datacache", "nohelp", options, &run, NULL);
180 if (ok != 0) 171 if (ok != 0)
181 fprintf (stderr, "Missed some perfcases: %d\n", ok); 172 fprintf (stderr, "Missed some perfcases: %d\n", ok);
182 return ok; 173 return ok;
diff --git a/src/datacache/plugin_datacache_mysql.c b/src/datacache/plugin_datacache_mysql.c
index f4530ccef..62787eea6 100644
--- a/src/datacache/plugin_datacache_mysql.c
+++ b/src/datacache/plugin_datacache_mysql.c
@@ -222,8 +222,8 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg)
222#endif 222#endif
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 223 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
224 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); 224 _("Trying to use file `%s' for MySQL configuration.\n"), cnffile);
225 if ((0 != STAT (cnffile, &st)) || 225 if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) ||
226 (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) 226 (!S_ISREG (st.st_mode)))
227 { 227 {
228 if (configured == GNUNET_YES) 228 if (configured == GNUNET_YES)
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -303,9 +303,9 @@ iopen (struct Plugin *ret)
303 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); 303 mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout);
304 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); 304 mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout);
305 mysql_dbname = NULL; 305 mysql_dbname = NULL;
306 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 306 if (GNUNET_YES ==
307 "datacache-mysql", 307 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
308 "DATABASE")) 308 "DATABASE"))
309 GNUNET_assert (GNUNET_OK == 309 GNUNET_assert (GNUNET_OK ==
310 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 310 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
311 "datacache-mysql", 311 "datacache-mysql",
@@ -314,8 +314,9 @@ iopen (struct Plugin *ret)
314 else 314 else
315 mysql_dbname = GNUNET_strdup ("gnunet"); 315 mysql_dbname = GNUNET_strdup ("gnunet");
316 mysql_user = NULL; 316 mysql_user = NULL;
317 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 317 if (GNUNET_YES ==
318 "datacache-mysql", "USER")) 318 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
319 "USER"))
319 { 320 {
320 GNUNET_assert (GNUNET_OK == 321 GNUNET_assert (GNUNET_OK ==
321 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 322 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
@@ -323,9 +324,9 @@ iopen (struct Plugin *ret)
323 "USER", &mysql_user)); 324 "USER", &mysql_user));
324 } 325 }
325 mysql_password = NULL; 326 mysql_password = NULL;
326 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 327 if (GNUNET_YES ==
327 "datacache-mysql", 328 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
328 "PASSWORD")) 329 "PASSWORD"))
329 { 330 {
330 GNUNET_assert (GNUNET_OK == 331 GNUNET_assert (GNUNET_OK ==
331 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 332 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
@@ -334,8 +335,9 @@ iopen (struct Plugin *ret)
334 &mysql_password)); 335 &mysql_password));
335 } 336 }
336 mysql_server = NULL; 337 mysql_server = NULL;
337 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 338 if (GNUNET_YES ==
338 "datacache-mysql", "HOST")) 339 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
340 "HOST"))
339 { 341 {
340 GNUNET_assert (GNUNET_OK == 342 GNUNET_assert (GNUNET_OK ==
341 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, 343 GNUNET_CONFIGURATION_get_value_string (ret->env->cfg,
@@ -344,8 +346,9 @@ iopen (struct Plugin *ret)
344 &mysql_server)); 346 &mysql_server));
345 } 347 }
346 mysql_port = 0; 348 mysql_port = 0;
347 if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, 349 if (GNUNET_YES ==
348 "datacache-mysql", "PORT")) 350 GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql",
351 "PORT"))
349 { 352 {
350 GNUNET_assert (GNUNET_OK == 353 GNUNET_assert (GNUNET_OK ==
351 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg, 354 GNUNET_CONFIGURATION_get_value_number (ret->env->cfg,
@@ -450,8 +453,8 @@ prepare_statement (struct Plugin *plugin,
450 * @return GNUNET_SYSERR on error, GNUNET_OK on success 453 * @return GNUNET_SYSERR on error, GNUNET_OK on success
451 */ 454 */
452static int 455static int
453init_params (struct Plugin *plugin, 456init_params (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *s,
454 struct GNUNET_MysqlStatementHandle *s, va_list ap) 457 va_list ap)
455{ 458{
456 MYSQL_BIND qbind[MAX_PARAM]; 459 MYSQL_BIND qbind[MAX_PARAM];
457 unsigned int pc; 460 unsigned int pc;
@@ -512,8 +515,8 @@ init_params (struct Plugin *plugin,
512 { 515 {
513 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
514 _("`%s' failed at %s:%d with error: %s\n"), 517 _("`%s' failed at %s:%d with error: %s\n"),
515 "mysql_stmt_bind_param", 518 "mysql_stmt_bind_param", __FILE__, __LINE__,
516 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 519 mysql_stmt_error (s->statement));
517 iclose (plugin); 520 iclose (plugin);
518 return GNUNET_SYSERR; 521 return GNUNET_SYSERR;
519 } 522 }
@@ -521,8 +524,8 @@ init_params (struct Plugin *plugin,
521 { 524 {
522 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
523 _("`%s' failed at %s:%d with error: %s\n"), 526 _("`%s' failed at %s:%d with error: %s\n"),
524 "mysql_stmt_execute", 527 "mysql_stmt_execute", __FILE__, __LINE__,
525 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 528 mysql_stmt_error (s->statement));
526 iclose (plugin); 529 iclose (plugin);
527 return GNUNET_SYSERR; 530 return GNUNET_SYSERR;
528 } 531 }
@@ -538,8 +541,7 @@ init_params (struct Plugin *plugin,
538 * @param values values returned by MySQL 541 * @param values values returned by MySQL
539 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort 542 * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort
540 */ 543 */
541typedef int (*GNUNET_MysqlDataProcessor) (void *cls, 544typedef int (*GNUNET_MysqlDataProcessor) (void *cls, unsigned int num_values,
542 unsigned int num_values,
543 MYSQL_BIND * values); 545 MYSQL_BIND * values);
544 546
545 547
@@ -561,12 +563,10 @@ typedef int (*GNUNET_MysqlDataProcessor) (void *cls,
561 */ 563 */
562static int 564static int
563prepared_statement_run_select (struct Plugin *plugin, 565prepared_statement_run_select (struct Plugin *plugin,
564 struct GNUNET_MysqlStatementHandle 566 struct GNUNET_MysqlStatementHandle *s,
565 *s, 567 unsigned int result_size, MYSQL_BIND * results,
566 unsigned int result_size, 568 GNUNET_MysqlDataProcessor processor,
567 MYSQL_BIND * results, 569 void *processor_cls, ...)
568 GNUNET_MysqlDataProcessor
569 processor, void *processor_cls, ...)
570{ 570{
571 va_list ap; 571 va_list ap;
572 int ret; 572 int ret;
@@ -596,8 +596,8 @@ prepared_statement_run_select (struct Plugin *plugin,
596 { 596 {
597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
598 _("`%s' failed at %s:%d with error: %s\n"), 598 _("`%s' failed at %s:%d with error: %s\n"),
599 "mysql_stmt_bind_result", 599 "mysql_stmt_bind_result", __FILE__, __LINE__,
600 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 600 mysql_stmt_error (s->statement));
601 iclose (plugin); 601 iclose (plugin);
602 return GNUNET_SYSERR; 602 return GNUNET_SYSERR;
603 } 603 }
@@ -612,8 +612,8 @@ prepared_statement_run_select (struct Plugin *plugin,
612 { 612 {
613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
614 _("`%s' failed at %s:%d with error: %s\n"), 614 _("`%s' failed at %s:%d with error: %s\n"),
615 "mysql_stmt_fetch", 615 "mysql_stmt_fetch", __FILE__, __LINE__,
616 __FILE__, __LINE__, mysql_stmt_error (s->statement)); 616 mysql_stmt_error (s->statement));
617 iclose (plugin); 617 iclose (plugin);
618 return GNUNET_SYSERR; 618 return GNUNET_SYSERR;
619 } 619 }
@@ -676,17 +676,17 @@ static int
676itable (struct Plugin *plugin) 676itable (struct Plugin *plugin)
677{ 677{
678#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) 678#define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) )
679 if (MRUNS ("CREATE TEMPORARY TABLE gn080dstore (" 679 if (MRUNS
680 " type INT(11) UNSIGNED NOT NULL DEFAULT 0," 680 ("CREATE TEMPORARY TABLE gn080dstore ("
681 " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0," 681 " type INT(11) UNSIGNED NOT NULL DEFAULT 0,"
682 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," 682 " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0,"
683 " hash BINARY(64) NOT NULL DEFAULT ''," 683 " expire BIGINT UNSIGNED NOT NULL DEFAULT 0,"
684 " vhash BINARY(64) NOT NULL DEFAULT ''," 684 " hash BINARY(64) NOT NULL DEFAULT '',"
685 " value BLOB NOT NULL DEFAULT ''," 685 " vhash BINARY(64) NOT NULL DEFAULT '',"
686 " INDEX hashidx (hash(64),type,expire)," 686 " value BLOB NOT NULL DEFAULT '',"
687 " INDEX allidx (hash(64),vhash(64),type)," 687 " INDEX hashidx (hash(64),type,expire),"
688 " INDEX expireidx (puttime)" ") ENGINE=InnoDB") || 688 " INDEX allidx (hash(64),vhash(64),type)," " INDEX expireidx (puttime)"
689 MRUNS ("SET AUTOCOMMIT = 1")) 689 ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1"))
690 return GNUNET_SYSERR; 690 return GNUNET_SYSERR;
691#undef MRUNS 691#undef MRUNS
692#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) 692#define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b)))
@@ -714,11 +714,8 @@ itable (struct Plugin *plugin)
714 * @return 0 on error, number of bytes used otherwise 714 * @return 0 on error, number of bytes used otherwise
715 */ 715 */
716static size_t 716static size_t
717mysql_plugin_put (void *cls, 717mysql_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
718 const GNUNET_HashCode * key, 718 const char *data, enum GNUNET_BLOCK_Type type,
719 size_t size,
720 const char *data,
721 enum GNUNET_BLOCK_Type type,
722 struct GNUNET_TIME_Absolute discard_time) 719 struct GNUNET_TIME_Absolute discard_time)
723{ 720{
724 struct Plugin *plugin = cls; 721 struct Plugin *plugin = cls;
@@ -745,23 +742,12 @@ mysql_plugin_put (void *cls,
745 v_now = (unsigned long long) now.abs_value; 742 v_now = (unsigned long long) now.abs_value;
746 v_discard_time = (unsigned long long) discard_time.abs_value; 743 v_discard_time = (unsigned long long) discard_time.abs_value;
747 if (GNUNET_OK == 744 if (GNUNET_OK ==
748 prepared_statement_run (plugin, 745 prepared_statement_run (plugin, plugin->update_value, NULL,
749 plugin->update_value, 746 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
750 NULL, 747 MYSQL_TYPE_LONGLONG, &v_discard_time, GNUNET_YES,
751 MYSQL_TYPE_LONGLONG, 748 MYSQL_TYPE_BLOB, key, sizeof (GNUNET_HashCode),
752 &v_now, 749 &k_length, MYSQL_TYPE_BLOB, &vhash,
753 GNUNET_YES, 750 sizeof (GNUNET_HashCode), &h_length,
754 MYSQL_TYPE_LONGLONG,
755 &v_discard_time,
756 GNUNET_YES,
757 MYSQL_TYPE_BLOB,
758 key,
759 sizeof (GNUNET_HashCode),
760 &k_length,
761 MYSQL_TYPE_BLOB,
762 &vhash,
763 sizeof (GNUNET_HashCode),
764 &h_length,
765 MYSQL_TYPE_LONG, &v_type, GNUNET_YES, -1)) 751 MYSQL_TYPE_LONG, &v_type, GNUNET_YES, -1))
766 return GNUNET_OK; 752 return GNUNET_OK;
767 753
@@ -770,29 +756,16 @@ mysql_plugin_put (void *cls,
770 k_length = sizeof (GNUNET_HashCode); 756 k_length = sizeof (GNUNET_HashCode);
771 v_length = size; 757 v_length = size;
772 if (GNUNET_OK != 758 if (GNUNET_OK !=
773 (ret = prepared_statement_run (plugin, 759 (ret =
774 plugin->insert_value, 760 prepared_statement_run (plugin, plugin->insert_value, NULL,
775 NULL, 761 MYSQL_TYPE_LONG, &type, GNUNET_YES,
776 MYSQL_TYPE_LONG, 762 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
777 &type, 763 MYSQL_TYPE_LONGLONG, &v_discard_time, GNUNET_YES,
778 GNUNET_YES, 764 MYSQL_TYPE_BLOB, key, sizeof (GNUNET_HashCode),
779 MYSQL_TYPE_LONGLONG, 765 &k_length, MYSQL_TYPE_BLOB, &vhash,
780 &v_now, 766 sizeof (GNUNET_HashCode), &h_length,
781 GNUNET_YES, 767 MYSQL_TYPE_BLOB, data, (unsigned long) size,
782 MYSQL_TYPE_LONGLONG, 768 &v_length, -1)))
783 &v_discard_time,
784 GNUNET_YES,
785 MYSQL_TYPE_BLOB,
786 key,
787 sizeof (GNUNET_HashCode),
788 &k_length,
789 MYSQL_TYPE_BLOB,
790 &vhash,
791 sizeof (GNUNET_HashCode),
792 &h_length,
793 MYSQL_TYPE_BLOB,
794 data,
795 (unsigned long) size, &v_length, -1)))
796 { 769 {
797 if (ret == GNUNET_SYSERR) 770 if (ret == GNUNET_SYSERR)
798 itable (plugin); 771 itable (plugin);
@@ -821,10 +794,9 @@ return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
821 * @return the number of results found 794 * @return the number of results found
822 */ 795 */
823static unsigned int 796static unsigned int
824mysql_plugin_get (void *cls, 797mysql_plugin_get (void *cls, const GNUNET_HashCode * key,
825 const GNUNET_HashCode * key, 798 enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter,
826 enum GNUNET_BLOCK_Type type, 799 void *iter_cls)
827 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
828{ 800{
829 struct Plugin *plugin = cls; 801 struct Plugin *plugin = cls;
830 MYSQL_BIND rbind[3]; 802 MYSQL_BIND rbind[3];
@@ -852,22 +824,13 @@ mysql_plugin_get (void *cls,
852 v_type = type; 824 v_type = type;
853 v_now = (unsigned long long) now.abs_value; 825 v_now = (unsigned long long) now.abs_value;
854 if ((GNUNET_OK != 826 if ((GNUNET_OK !=
855 (ret = prepared_statement_run_select (plugin, 827 (ret =
856 plugin->count_value, 828 prepared_statement_run_select (plugin, plugin->count_value, 1, rbind,
857 1, 829 return_ok, NULL, MYSQL_TYPE_BLOB, key,
858 rbind, 830 sizeof (GNUNET_HashCode), &h_length,
859 return_ok, 831 MYSQL_TYPE_LONG, &v_type, GNUNET_YES,
860 NULL, 832 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
861 MYSQL_TYPE_BLOB, 833 -1))) || (-1 == total))
862 key,
863 sizeof
864 (GNUNET_HashCode),
865 &h_length,
866 MYSQL_TYPE_LONG,
867 &v_type, GNUNET_YES,
868 MYSQL_TYPE_LONGLONG,
869 &v_now, GNUNET_YES,
870 -1))) || (-1 == total))
871 { 834 {
872 if (ret == GNUNET_SYSERR) 835 if (ret == GNUNET_SYSERR)
873 itable (plugin); 836 itable (plugin);
@@ -890,25 +853,13 @@ mysql_plugin_get (void *cls,
890 rbind[1].buffer = &v_expire; 853 rbind[1].buffer = &v_expire;
891 off = (off + 1) % total; 854 off = (off + 1) % total;
892 if (GNUNET_OK != 855 if (GNUNET_OK !=
893 (ret = prepared_statement_run_select (plugin, 856 (ret =
894 plugin->select_value, 857 prepared_statement_run_select (plugin, plugin->select_value, 2, rbind,
895 2, 858 return_ok, NULL, MYSQL_TYPE_BLOB, key,
896 rbind, 859 sizeof (GNUNET_HashCode), &h_length,
897 return_ok, 860 MYSQL_TYPE_LONG, &v_type, GNUNET_YES,
898 NULL, 861 MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES,
899 MYSQL_TYPE_BLOB, 862 MYSQL_TYPE_LONG, &off, GNUNET_YES, -1)))
900 key,
901 sizeof
902 (GNUNET_HashCode),
903 &h_length,
904 MYSQL_TYPE_LONG,
905 &v_type,
906 GNUNET_YES,
907 MYSQL_TYPE_LONGLONG,
908 &v_now,
909 GNUNET_YES,
910 MYSQL_TYPE_LONG,
911 &off, GNUNET_YES, -1)))
912 { 863 {
913 if (ret == GNUNET_SYSERR) 864 if (ret == GNUNET_SYSERR)
914 itable (plugin); 865 itable (plugin);
@@ -965,32 +916,20 @@ mysql_plugin_del (void *cls)
965 rbind[3].length = &v_length; 916 rbind[3].length = &v_length;
966 rbind[3].buffer = buffer; 917 rbind[3].buffer = buffer;
967 if ((GNUNET_OK != 918 if ((GNUNET_OK !=
968 (ret = prepared_statement_run_select (plugin, 919 (ret =
969 plugin->select_old_value, 920 prepared_statement_run_select (plugin, plugin->select_old_value, 4,
970 4, 921 rbind, return_ok, NULL, -1))) ||
971 rbind,
972 return_ok,
973 NULL,
974 -1))) ||
975 (GNUNET_OK != 922 (GNUNET_OK !=
976 (ret = prepared_statement_run (plugin, 923 (ret =
977 plugin->delete_value, 924 prepared_statement_run (plugin, plugin->delete_value, NULL,
978 NULL, 925 MYSQL_TYPE_BLOB, &v_key,
979 MYSQL_TYPE_BLOB, 926 sizeof (GNUNET_HashCode), &k_length,
980 &v_key, 927 MYSQL_TYPE_BLOB, &vhash,
981 sizeof (GNUNET_HashCode), 928 sizeof (GNUNET_HashCode), &h_length,
982 &k_length, 929 MYSQL_TYPE_LONG, &v_type, GNUNET_YES,
983 MYSQL_TYPE_BLOB, 930 MYSQL_TYPE_BLOB, buffer,
984 &vhash, 931 (unsigned long) sizeof (buffer), &v_length,
985 sizeof (GNUNET_HashCode), 932 -1))))
986 &h_length,
987 MYSQL_TYPE_LONG,
988 &v_type,
989 GNUNET_YES,
990 MYSQL_TYPE_BLOB,
991 buffer,
992 (unsigned long)
993 sizeof (buffer), &v_length, -1))))
994 { 933 {
995 if (ret == GNUNET_SYSERR) 934 if (ret == GNUNET_SYSERR)
996 itable (plugin); 935 itable (plugin);
@@ -1036,8 +975,8 @@ libgnunet_plugin_datacache_mysql_init (void *cls)
1036 api->get = &mysql_plugin_get; 975 api->get = &mysql_plugin_get;
1037 api->put = &mysql_plugin_put; 976 api->put = &mysql_plugin_put;
1038 api->del = &mysql_plugin_del; 977 api->del = &mysql_plugin_del;
1039 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 978 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql",
1040 "mysql", _("MySQL datacache running\n")); 979 _("MySQL datacache running\n"));
1041 return api; 980 return api;
1042} 981}
1043 982
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c
index fdc377b8f..c5730078a 100644
--- a/src/datacache/plugin_datacache_postgres.c
+++ b/src/datacache/plugin_datacache_postgres.c
@@ -61,9 +61,7 @@ struct Plugin
61 * @return GNUNET_OK if the result is acceptable 61 * @return GNUNET_OK if the result is acceptable
62 */ 62 */
63static int 63static int
64check_result (struct Plugin *plugin, 64check_result (struct Plugin *plugin, PGresult * ret, int expected_status,
65 PGresult * ret,
66 int expected_status,
67 const char *command, const char *args, int line) 65 const char *command, const char *args, int line)
68{ 66{
69 if (ret == NULL) 67 if (ret == NULL)
@@ -78,9 +76,8 @@ check_result (struct Plugin *plugin,
78 { 76 {
79 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 77 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
80 "datastore-postgres", 78 "datastore-postgres",
81 _("`%s:%s' failed at %s:%d with error: %s"), 79 _("`%s:%s' failed at %s:%d with error: %s"), command, args,
82 command, args, __FILE__, line, 80 __FILE__, line, PQerrorMessage (plugin->dbh));
83 PQerrorMessage (plugin->dbh));
84 PQclear (ret); 81 PQclear (ret);
85 return GNUNET_SYSERR; 82 return GNUNET_SYSERR;
86 } 83 }
@@ -97,8 +94,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line)
97 PGresult *ret; 94 PGresult *ret;
98 95
99 ret = PQexec (plugin->dbh, sql); 96 ret = PQexec (plugin->dbh, sql);
100 if (GNUNET_OK != check_result (plugin, 97 if (GNUNET_OK !=
101 ret, PGRES_COMMAND_OK, "PQexec", sql, line)) 98 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexec", sql, line))
102 return GNUNET_SYSERR; 99 return GNUNET_SYSERR;
103 PQclear (ret); 100 PQclear (ret);
104 return GNUNET_OK; 101 return GNUNET_OK;
@@ -109,8 +106,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line)
109 * Prepare SQL statement. 106 * Prepare SQL statement.
110 */ 107 */
111static int 108static int
112pq_prepare (struct Plugin *plugin, 109pq_prepare (struct Plugin *plugin, const char *name, const char *sql,
113 const char *name, const char *sql, int nparms, int line) 110 int nparms, int line)
114{ 111{
115 PGresult *ret; 112 PGresult *ret;
116 113
@@ -136,8 +133,8 @@ init_connection (struct Plugin *plugin)
136 /* Open database and precompile statements */ 133 /* Open database and precompile statements */
137 if (GNUNET_OK != 134 if (GNUNET_OK !=
138 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 135 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
139 "datacache-postgres", 136 "datacache-postgres", "CONFIG",
140 "CONFIG", &conninfo)) 137 &conninfo))
141 conninfo = NULL; 138 conninfo = NULL;
142 plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); 139 plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo);
143 GNUNET_free_non_null (conninfo); 140 GNUNET_free_non_null (conninfo);
@@ -148,28 +145,27 @@ init_connection (struct Plugin *plugin)
148 } 145 }
149 if (PQstatus (plugin->dbh) != CONNECTION_OK) 146 if (PQstatus (plugin->dbh) != CONNECTION_OK)
150 { 147 {
151 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 148 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "datacache-postgres",
152 "datacache-postgres",
153 _("Unable to initialize Postgres: %s"), 149 _("Unable to initialize Postgres: %s"),
154 PQerrorMessage (plugin->dbh)); 150 PQerrorMessage (plugin->dbh));
155 PQfinish (plugin->dbh); 151 PQfinish (plugin->dbh);
156 plugin->dbh = NULL; 152 plugin->dbh = NULL;
157 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
158 } 154 }
159 ret = PQexec (plugin->dbh, 155 ret =
160 "CREATE TEMPORARY TABLE gn090dc (" 156 PQexec (plugin->dbh,
161 " type INTEGER NOT NULL DEFAULT 0," 157 "CREATE TEMPORARY TABLE gn090dc ("
162 " discard_time BIGINT NOT NULL DEFAULT 0," 158 " type INTEGER NOT NULL DEFAULT 0,"
163 " key BYTEA NOT NULL DEFAULT ''," 159 " discard_time BIGINT NOT NULL DEFAULT 0,"
164 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); 160 " key BYTEA NOT NULL DEFAULT '',"
161 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
165 if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */ 162 if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */
166 PQresultErrorField 163 PQresultErrorField
167 (ret, 164 (ret,
168 PG_DIAG_SQLSTATE))))) 165 PG_DIAG_SQLSTATE)))))
169 { 166 {
170 (void) check_result (plugin, 167 (void) check_result (plugin, ret, PGRES_COMMAND_OK, "CREATE TABLE",
171 ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090dc", 168 "gn090dc", __LINE__);
172 __LINE__);
173 PQfinish (plugin->dbh); 169 PQfinish (plugin->dbh);
174 plugin->dbh = NULL; 170 plugin->dbh = NULL;
175 return GNUNET_SYSERR; 171 return GNUNET_SYSERR;
@@ -190,11 +186,12 @@ init_connection (struct Plugin *plugin)
190 } 186 }
191 PQclear (ret); 187 PQclear (ret);
192#if 1 188#if 1
193 ret = PQexec (plugin->dbh, 189 ret =
194 "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL"); 190 PQexec (plugin->dbh,
191 "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL");
195 if (GNUNET_OK != 192 if (GNUNET_OK !=
196 check_result (plugin, 193 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc",
197 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__)) 194 __LINE__))
198 { 195 {
199 PQfinish (plugin->dbh); 196 PQfinish (plugin->dbh);
200 plugin->dbh = NULL; 197 plugin->dbh = NULL;
@@ -203,8 +200,8 @@ init_connection (struct Plugin *plugin)
203 PQclear (ret); 200 PQclear (ret);
204 ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN"); 201 ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN");
205 if (GNUNET_OK != 202 if (GNUNET_OK !=
206 check_result (plugin, 203 check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc",
207 ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__)) 204 __LINE__))
208 { 205 {
209 PQfinish (plugin->dbh); 206 PQfinish (plugin->dbh);
210 plugin->dbh = NULL; 207 plugin->dbh = NULL;
@@ -213,35 +210,22 @@ init_connection (struct Plugin *plugin)
213 PQclear (ret); 210 PQclear (ret);
214#endif 211#endif
215 if ((GNUNET_OK != 212 if ((GNUNET_OK !=
216 pq_prepare (plugin, 213 pq_prepare (plugin, "getkt",
217 "getkt",
218 "SELECT discard_time,type,value FROM gn090dc " 214 "SELECT discard_time,type,value FROM gn090dc "
219 "WHERE key=$1 AND type=$2 ", 215 "WHERE key=$1 AND type=$2 ", 2, __LINE__)) ||
220 2,
221 __LINE__)) ||
222 (GNUNET_OK != 216 (GNUNET_OK !=
223 pq_prepare (plugin, 217 pq_prepare (plugin, "getk",
224 "getk",
225 "SELECT discard_time,type,value FROM gn090dc " 218 "SELECT discard_time,type,value FROM gn090dc "
226 "WHERE key=$1", 219 "WHERE key=$1", 1, __LINE__)) ||
227 1,
228 __LINE__)) ||
229 (GNUNET_OK != 220 (GNUNET_OK !=
230 pq_prepare (plugin, 221 pq_prepare (plugin, "getm",
231 "getm",
232 "SELECT length(value),oid,key FROM gn090dc " 222 "SELECT length(value),oid,key FROM gn090dc "
233 "ORDER BY discard_time ASC LIMIT 1", 223 "ORDER BY discard_time ASC LIMIT 1", 0, __LINE__)) ||
234 0,
235 __LINE__)) ||
236 (GNUNET_OK != 224 (GNUNET_OK !=
237 pq_prepare (plugin, 225 pq_prepare (plugin, "delrow", "DELETE FROM gn090dc WHERE oid=$1", 1,
238 "delrow",
239 "DELETE FROM gn090dc WHERE oid=$1",
240 1,
241 __LINE__)) || 226 __LINE__)) ||
242 (GNUNET_OK != 227 (GNUNET_OK !=
243 pq_prepare (plugin, 228 pq_prepare (plugin, "put",
244 "put",
245 "INSERT INTO gn090dc (type, discard_time, key, value) " 229 "INSERT INTO gn090dc (type, discard_time, key, value) "
246 "VALUES ($1, $2, $3, $4)", 4, __LINE__))) 230 "VALUES ($1, $2, $3, $4)", 4, __LINE__)))
247 { 231 {
@@ -268,12 +252,11 @@ delete_by_rowid (struct Plugin *plugin, uint32_t rowid)
268 const int paramFormats[] = { 1 }; 252 const int paramFormats[] = { 1 };
269 PGresult *ret; 253 PGresult *ret;
270 254
271 ret = PQexecPrepared (plugin->dbh, 255 ret =
272 "delrow", 256 PQexecPrepared (plugin->dbh, "delrow", 1, paramValues, paramLengths,
273 1, paramValues, paramLengths, paramFormats, 1); 257 paramFormats, 1);
274 if (GNUNET_OK != 258 if (GNUNET_OK !=
275 check_result (plugin, 259 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
276 ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow",
277 __LINE__)) 260 __LINE__))
278 { 261 {
279 return GNUNET_SYSERR; 262 return GNUNET_SYSERR;
@@ -295,11 +278,8 @@ delete_by_rowid (struct Plugin *plugin, uint32_t rowid)
295 * @return 0 on error, number of bytes used otherwise 278 * @return 0 on error, number of bytes used otherwise
296 */ 279 */
297static size_t 280static size_t
298postgres_plugin_put (void *cls, 281postgres_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
299 const GNUNET_HashCode * key, 282 const char *data, enum GNUNET_BLOCK_Type type,
300 size_t size,
301 const char *data,
302 enum GNUNET_BLOCK_Type type,
303 struct GNUNET_TIME_Absolute discard_time) 283 struct GNUNET_TIME_Absolute discard_time)
304{ 284{
305 struct Plugin *plugin = cls; 285 struct Plugin *plugin = cls;
@@ -321,11 +301,12 @@ postgres_plugin_put (void *cls,
321 }; 301 };
322 const int paramFormats[] = { 1, 1, 1, 1 }; 302 const int paramFormats[] = { 1, 1, 1, 1 };
323 303
324 ret = PQexecPrepared (plugin->dbh, 304 ret =
325 "put", 4, paramValues, paramLengths, paramFormats, 1); 305 PQexecPrepared (plugin->dbh, "put", 4, paramValues, paramLengths,
326 if (GNUNET_OK != check_result (plugin, ret, 306 paramFormats, 1);
327 PGRES_COMMAND_OK, 307 if (GNUNET_OK !=
328 "PQexecPrepared", "put", __LINE__)) 308 check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put",
309 __LINE__))
329 return GNUNET_SYSERR; 310 return GNUNET_SYSERR;
330 PQclear (ret); 311 PQclear (ret);
331 return size + OVERHEAD; 312 return size + OVERHEAD;
@@ -344,8 +325,7 @@ postgres_plugin_put (void *cls,
344 * @return the number of results found 325 * @return the number of results found
345 */ 326 */
346static unsigned int 327static unsigned int
347postgres_plugin_get (void *cls, 328postgres_plugin_get (void *cls, const GNUNET_HashCode * key,
348 const GNUNET_HashCode * key,
349 enum GNUNET_BLOCK_Type type, 329 enum GNUNET_BLOCK_Type type,
350 GNUNET_DATACACHE_Iterator iter, void *iter_cls) 330 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
351{ 331{
@@ -368,19 +348,16 @@ postgres_plugin_get (void *cls,
368 PGresult *res; 348 PGresult *res;
369 349
370 cnt = 0; 350 cnt = 0;
371 res = PQexecPrepared (plugin->dbh, 351 res =
372 (type == 0) ? "getk" : "getkt", 352 PQexecPrepared (plugin->dbh, (type == 0) ? "getk" : "getkt",
373 (type == 0) ? 1 : 2, 353 (type == 0) ? 1 : 2, paramValues, paramLengths,
374 paramValues, paramLengths, paramFormats, 1); 354 paramFormats, 1);
375 if (GNUNET_OK != check_result (plugin, 355 if (GNUNET_OK !=
376 res, 356 check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared",
377 PGRES_TUPLES_OK, 357 (type == 0) ? "getk" : "getkt", __LINE__))
378 "PQexecPrepared",
379 (type == 0) ? "getk" : "getkt", __LINE__))
380 { 358 {
381#if DEBUG_POSTGRES 359#if DEBUG_POSTGRES
382 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 360 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
383 "datacache-postgres",
384 "Ending iteration (postgres error)\n"); 361 "Ending iteration (postgres error)\n");
385#endif 362#endif
386 return 0; 363 return 0;
@@ -390,8 +367,7 @@ postgres_plugin_get (void *cls,
390 { 367 {
391 /* no result */ 368 /* no result */
392#if DEBUG_POSTGRES 369#if DEBUG_POSTGRES
393 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 370 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
394 "datacache-postgres",
395 "Ending iteration (no more results)\n"); 371 "Ending iteration (no more results)\n");
396#endif 372#endif
397 PQclear (res); 373 PQclear (res);
@@ -402,8 +378,7 @@ postgres_plugin_get (void *cls,
402 PQclear (res); 378 PQclear (res);
403 return cnt; 379 return cnt;
404 } 380 }
405 if ((3 != PQnfields (res)) || 381 if ((3 != PQnfields (res)) || (sizeof (uint64_t) != PQfsize (res, 0)) ||
406 (sizeof (uint64_t) != PQfsize (res, 0)) ||
407 (sizeof (uint32_t) != PQfsize (res, 1))) 382 (sizeof (uint32_t) != PQfsize (res, 1)))
408 { 383 {
409 GNUNET_break (0); 384 GNUNET_break (0);
@@ -417,19 +392,16 @@ postgres_plugin_get (void *cls,
417 type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1)); 392 type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1));
418 size = PQgetlength (res, i, 2); 393 size = PQgetlength (res, i, 2);
419#if DEBUG_POSTGRES 394#if DEBUG_POSTGRES
420 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 395 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
421 "datacache-postgres",
422 "Found result of size %u bytes and type %u in database\n", 396 "Found result of size %u bytes and type %u in database\n",
423 (unsigned int) size, (unsigned int) type); 397 (unsigned int) size, (unsigned int) type);
424#endif 398#endif
425 if (GNUNET_SYSERR == 399 if (GNUNET_SYSERR ==
426 iter (iter_cls, 400 iter (iter_cls, expiration_time, key, size, PQgetvalue (res, i, 2),
427 expiration_time, 401 (enum GNUNET_BLOCK_Type) type))
428 key, size, PQgetvalue (res, i, 2), (enum GNUNET_BLOCK_Type) type))
429 { 402 {
430#if DEBUG_POSTGRES 403#if DEBUG_POSTGRES
431 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
432 "datacache-postgres",
433 "Ending iteration (client error)\n"); 405 "Ending iteration (client error)\n");
434#endif 406#endif
435 PQclear (res); 407 PQclear (res);
@@ -458,14 +430,12 @@ postgres_plugin_del (void *cls)
458 PGresult *res; 430 PGresult *res;
459 431
460 res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1); 432 res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1);
461 if (GNUNET_OK != check_result (plugin, 433 if (GNUNET_OK !=
462 res, 434 check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared", "getm",
463 PGRES_TUPLES_OK, 435 __LINE__))
464 "PQexecPrepared", "getm", __LINE__))
465 { 436 {
466#if DEBUG_POSTGRES 437#if DEBUG_POSTGRES
467 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 438 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
468 "datacache-postgres",
469 "Ending iteration (postgres error)\n"); 439 "Ending iteration (postgres error)\n");
470#endif 440#endif
471 return 0; 441 return 0;
@@ -474,15 +444,13 @@ postgres_plugin_del (void *cls)
474 { 444 {
475 /* no result */ 445 /* no result */
476#if DEBUG_POSTGRES 446#if DEBUG_POSTGRES
477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 447 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres",
478 "datacache-postgres",
479 "Ending iteration (no more results)\n"); 448 "Ending iteration (no more results)\n");
480#endif 449#endif
481 PQclear (res); 450 PQclear (res);
482 return GNUNET_SYSERR; 451 return GNUNET_SYSERR;
483 } 452 }
484 if ((3 != PQnfields (res)) || 453 if ((3 != PQnfields (res)) || (sizeof (size) != PQfsize (res, 0)) ||
485 (sizeof (size) != PQfsize (res, 0)) ||
486 (sizeof (oid) != PQfsize (res, 1)) || 454 (sizeof (oid) != PQfsize (res, 1)) ||
487 (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2))) 455 (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2)))
488 { 456 {
@@ -528,8 +496,8 @@ libgnunet_plugin_datacache_postgres_init (void *cls)
528 api->get = &postgres_plugin_get; 496 api->get = &postgres_plugin_get;
529 api->put = &postgres_plugin_put; 497 api->put = &postgres_plugin_put;
530 api->del = &postgres_plugin_del; 498 api->del = &postgres_plugin_del;
531 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 499 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datacache-postgres",
532 "datacache-postgres", _("Postgres datacache running\n")); 500 _("Postgres datacache running\n"));
533 return api; 501 return api;
534} 502}
535 503
diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c
index 5f534227f..3d67ffc22 100644
--- a/src/datacache/plugin_datacache_sqlite.c
+++ b/src/datacache/plugin_datacache_sqlite.c
@@ -78,8 +78,8 @@ sq_prepare (sqlite3 * dbh, const char *zSql, /* SQL statement, UTF-8 encoded
78{ /* OUT: Statement handle */ 78{ /* OUT: Statement handle */
79 char *dummy; 79 char *dummy;
80 80
81 return sqlite3_prepare (dbh, 81 return sqlite3_prepare (dbh, zSql, strlen (zSql), ppStmt,
82 zSql, strlen (zSql), ppStmt, (const char **) &dummy); 82 (const char **) &dummy);
83} 83}
84 84
85 85
@@ -95,11 +95,8 @@ sq_prepare (sqlite3 * dbh, const char *zSql, /* SQL statement, UTF-8 encoded
95 * @return 0 on error, number of bytes used otherwise 95 * @return 0 on error, number of bytes used otherwise
96 */ 96 */
97static size_t 97static size_t
98sqlite_plugin_put (void *cls, 98sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
99 const GNUNET_HashCode * key, 99 const char *data, enum GNUNET_BLOCK_Type type,
100 size_t size,
101 const char *data,
102 enum GNUNET_BLOCK_Type type,
103 struct GNUNET_TIME_Absolute discard_time) 100 struct GNUNET_TIME_Absolute discard_time)
104{ 101{
105 struct Plugin *plugin = cls; 102 struct Plugin *plugin = cls;
@@ -109,48 +106,44 @@ sqlite_plugin_put (void *cls,
109#if DEBUG_DATACACHE_SQLITE 106#if DEBUG_DATACACHE_SQLITE
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
111 "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n", 108 "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n",
112 "PUT", 109 "PUT", (unsigned int) size, GNUNET_h2s (key),
113 (unsigned int) size,
114 GNUNET_h2s (key),
115 (unsigned long long) 110 (unsigned long long)
116 GNUNET_TIME_absolute_get_remaining (discard_time).rel_value); 111 GNUNET_TIME_absolute_get_remaining (discard_time).rel_value);
117#endif 112#endif
118 dval = (int64_t) discard_time.abs_value; 113 dval = (int64_t) discard_time.abs_value;
119 if (dval < 0) 114 if (dval < 0)
120 dval = INT64_MAX; 115 dval = INT64_MAX;
121 if (sq_prepare (plugin->dbh, 116 if (sq_prepare
122 "INSERT INTO ds090 " 117 (plugin->dbh,
123 "(type, expire, key, value) " 118 "INSERT INTO ds090 " "(type, expire, key, value) " "VALUES (?, ?, ?, ?)",
124 "VALUES (?, ?, ?, ?)", &stmt) != SQLITE_OK) 119 &stmt) != SQLITE_OK)
125 { 120 {
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
127 _("`%s' failed at %s:%d with error: %s\n"), 122 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
128 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 123 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
129 return 0; 124 return 0;
130 } 125 }
131 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || 126 if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) ||
132 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) || 127 (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) ||
133 (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode), 128 (SQLITE_OK !=
134 SQLITE_TRANSIENT)) || 129 sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode),
130 SQLITE_TRANSIENT)) ||
135 (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT))) 131 (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT)))
136 { 132 {
137 LOG_SQLITE (plugin->dbh, 133 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
138 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
139 "sqlite3_bind_xxx"); 134 "sqlite3_bind_xxx");
140 sqlite3_finalize (stmt); 135 sqlite3_finalize (stmt);
141 return 0; 136 return 0;
142 } 137 }
143 if (SQLITE_DONE != sqlite3_step (stmt)) 138 if (SQLITE_DONE != sqlite3_step (stmt))
144 { 139 {
145 LOG_SQLITE (plugin->dbh, 140 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
146 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
147 "sqlite3_step"); 141 "sqlite3_step");
148 sqlite3_finalize (stmt); 142 sqlite3_finalize (stmt);
149 return 0; 143 return 0;
150 } 144 }
151 if (SQLITE_OK != sqlite3_finalize (stmt)) 145 if (SQLITE_OK != sqlite3_finalize (stmt))
152 LOG_SQLITE (plugin->dbh, 146 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
153 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
154 "sqlite3_finalize"); 147 "sqlite3_finalize");
155 return size + OVERHEAD; 148 return size + OVERHEAD;
156} 149}
@@ -168,10 +161,9 @@ sqlite_plugin_put (void *cls,
168 * @return the number of results found 161 * @return the number of results found
169 */ 162 */
170static unsigned int 163static unsigned int
171sqlite_plugin_get (void *cls, 164sqlite_plugin_get (void *cls, const GNUNET_HashCode * key,
172 const GNUNET_HashCode * key, 165 enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter,
173 enum GNUNET_BLOCK_Type type, 166 void *iter_cls)
174 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
175{ 167{
176 struct Plugin *plugin = cls; 168 struct Plugin *plugin = cls;
177 sqlite3_stmt *stmt; 169 sqlite3_stmt *stmt;
@@ -187,16 +179,17 @@ sqlite_plugin_get (void *cls,
187 179
188 now = GNUNET_TIME_absolute_get (); 180 now = GNUNET_TIME_absolute_get ();
189#if DEBUG_DATACACHE_SQLITE 181#if DEBUG_DATACACHE_SQLITE
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' for key `%4s'\n", "GET",
191 "Processing `%s' for key `%4s'\n", "GET", GNUNET_h2s (key)); 183 GNUNET_h2s (key));
192#endif 184#endif
193 if (sq_prepare (plugin->dbh, 185 if (sq_prepare
194 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", 186 (plugin->dbh,
195 &stmt) != SQLITE_OK) 187 "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?",
188 &stmt) != SQLITE_OK)
196 { 189 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
198 _("`%s' failed at %s:%d with error: %s\n"), 191 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
199 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 192 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
200 return 0; 193 return 0;
201 } 194 }
202 ntime = (int64_t) now.abs_value; 195 ntime = (int64_t) now.abs_value;
@@ -204,12 +197,10 @@ sqlite_plugin_get (void *cls,
204 if ((SQLITE_OK != 197 if ((SQLITE_OK !=
205 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), 198 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
206 SQLITE_TRANSIENT)) || 199 SQLITE_TRANSIENT)) ||
207 (SQLITE_OK != 200 (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
208 sqlite3_bind_int (stmt, 2, type)) ||
209 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value))) 201 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value)))
210 { 202 {
211 LOG_SQLITE (plugin->dbh, 203 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
212 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
213 "sqlite3_bind_xxx"); 204 "sqlite3_bind_xxx");
214 sqlite3_finalize (stmt); 205 sqlite3_finalize (stmt);
215 return 0; 206 return 0;
@@ -217,8 +208,7 @@ sqlite_plugin_get (void *cls,
217 208
218 if (SQLITE_ROW != sqlite3_step (stmt)) 209 if (SQLITE_ROW != sqlite3_step (stmt))
219 { 210 {
220 LOG_SQLITE (plugin->dbh, 211 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
221 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
222 "sqlite_step"); 212 "sqlite_step");
223 sqlite3_finalize (stmt); 213 sqlite3_finalize (stmt);
224 return 0; 214 return 0;
@@ -233,27 +223,23 @@ sqlite_plugin_get (void *cls,
233 while (cnt < total) 223 while (cnt < total)
234 { 224 {
235 off = (off + 1) % total; 225 off = (off + 1) % total;
236 GNUNET_snprintf (scratch, 226 GNUNET_snprintf (scratch, sizeof (scratch),
237 sizeof (scratch),
238 "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u", 227 "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u",
239 off); 228 off);
240 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) 229 if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK)
241 { 230 {
242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
243 _("`%s' failed at %s:%d with error: %s\n"), 232 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
244 "sq_prepare", __FILE__, __LINE__, 233 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
245 sqlite3_errmsg (plugin->dbh));
246 return cnt; 234 return cnt;
247 } 235 }
248 if ((SQLITE_OK != 236 if ((SQLITE_OK !=
249 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), 237 sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode),
250 SQLITE_TRANSIENT)) || 238 SQLITE_TRANSIENT)) ||
251 (SQLITE_OK != 239 (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) ||
252 sqlite3_bind_int (stmt, 2, type)) ||
253 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value))) 240 (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value)))
254 { 241 {
255 LOG_SQLITE (plugin->dbh, 242 LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
256 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
257 "sqlite3_bind_xxx"); 243 "sqlite3_bind_xxx");
258 sqlite3_finalize (stmt); 244 sqlite3_finalize (stmt);
259 return cnt; 245 return cnt;
@@ -301,13 +287,14 @@ sqlite_plugin_del (void *cls)
301#endif 287#endif
302 stmt = NULL; 288 stmt = NULL;
303 dstmt = NULL; 289 dstmt = NULL;
304 if (sq_prepare (plugin->dbh, 290 if (sq_prepare
305 "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", 291 (plugin->dbh,
306 &stmt) != SQLITE_OK) 292 "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1",
293 &stmt) != SQLITE_OK)
307 { 294 {
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
309 _("`%s' failed at %s:%d with error: %s\n"), 296 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
310 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 297 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
311 if (stmt != NULL) 298 if (stmt != NULL)
312 (void) sqlite3_finalize (stmt); 299 (void) sqlite3_finalize (stmt);
313 return GNUNET_SYSERR; 300 return GNUNET_SYSERR;
@@ -315,9 +302,8 @@ sqlite_plugin_del (void *cls)
315 if (SQLITE_ROW != sqlite3_step (stmt)) 302 if (SQLITE_ROW != sqlite3_step (stmt))
316 { 303 {
317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
318 _("`%s' failed at %s:%d with error: %s\n"), 305 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
319 "sqlite3_step", __FILE__, __LINE__, 306 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
320 sqlite3_errmsg (plugin->dbh));
321 (void) sqlite3_finalize (stmt); 307 (void) sqlite3_finalize (stmt);
322 return GNUNET_SYSERR; 308 return GNUNET_SYSERR;
323 } 309 }
@@ -329,54 +315,44 @@ sqlite_plugin_del (void *cls)
329 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); 315 memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
330 if (SQLITE_OK != sqlite3_finalize (stmt)) 316 if (SQLITE_OK != sqlite3_finalize (stmt))
331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
332 _("`%s' failed at %s:%d with error: %s\n"), 318 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
333 "sqlite3_step", __FILE__, __LINE__, 319 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
334 sqlite3_errmsg (plugin->dbh)); 320 if (sq_prepare
335 if (sq_prepare (plugin->dbh, 321 (plugin->dbh, "DELETE FROM ds090 " "WHERE key=? AND value=? AND type=?",
336 "DELETE FROM ds090 " 322 &dstmt) != SQLITE_OK)
337 "WHERE key=? AND value=? AND type=?", &dstmt) != SQLITE_OK)
338 { 323 {
339 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
340 _("`%s' failed at %s:%d with error: %s\n"), 325 _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare",
341 "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); 326 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
342 if (stmt != NULL) 327 if (stmt != NULL)
343 (void) sqlite3_finalize (stmt); 328 (void) sqlite3_finalize (stmt);
344 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
345 } 330 }
346 if ((SQLITE_OK != 331 if ((SQLITE_OK !=
347 sqlite3_bind_blob (dstmt, 332 sqlite3_bind_blob (dstmt, 1, &hc, sizeof (GNUNET_HashCode),
348 1, &hc,
349 sizeof (GNUNET_HashCode),
350 SQLITE_TRANSIENT)) ||
351 (SQLITE_OK !=
352 sqlite3_bind_blob (dstmt,
353 2, blob,
354 dsize,
355 SQLITE_TRANSIENT)) || 333 SQLITE_TRANSIENT)) ||
356 (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype))) 334 (SQLITE_OK != sqlite3_bind_blob (dstmt, 2, blob, dsize, SQLITE_TRANSIENT))
335 || (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype)))
357 { 336 {
358 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
359 _("`%s' failed at %s:%d with error: %s\n"), 338 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind",
360 "sqlite3_bind", __FILE__, __LINE__, 339 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
361 sqlite3_errmsg (plugin->dbh));
362 (void) sqlite3_finalize (dstmt); 340 (void) sqlite3_finalize (dstmt);
363 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
364 } 342 }
365 if (sqlite3_step (dstmt) != SQLITE_DONE) 343 if (sqlite3_step (dstmt) != SQLITE_DONE)
366 { 344 {
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
368 _("`%s' failed at %s:%d with error: %s\n"), 346 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
369 "sqlite3_step", __FILE__, __LINE__, 347 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
370 sqlite3_errmsg (plugin->dbh));
371 (void) sqlite3_finalize (dstmt); 348 (void) sqlite3_finalize (dstmt);
372 return GNUNET_SYSERR; 349 return GNUNET_SYSERR;
373 } 350 }
374 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); 351 plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD);
375 if (SQLITE_OK != sqlite3_finalize (dstmt)) 352 if (SQLITE_OK != sqlite3_finalize (dstmt))
376 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 353 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
377 _("`%s' failed at %s:%d with error: %s\n"), 354 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_finalize",
378 "sqlite3_finalize", __FILE__, __LINE__, 355 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
379 sqlite3_errmsg (plugin->dbh));
380 return GNUNET_OK; 356 return GNUNET_OK;
381} 357}
382 358
@@ -425,8 +401,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
425 SQLITE3_EXEC (dbh, "PRAGMA count_changes=OFF"); 401 SQLITE3_EXEC (dbh, "PRAGMA count_changes=OFF");
426 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092"); 402 SQLITE3_EXEC (dbh, "PRAGMA page_size=4092");
427 SQLITE3_EXEC (dbh, 403 SQLITE3_EXEC (dbh,
428 "CREATE TABLE ds090 (" 404 "CREATE TABLE ds090 (" " type INTEGER NOT NULL DEFAULT 0,"
429 " type INTEGER NOT NULL DEFAULT 0,"
430 " expire INTEGER NOT NULL DEFAULT 0," 405 " expire INTEGER NOT NULL DEFAULT 0,"
431 " key BLOB NOT NULL DEFAULT ''," 406 " key BLOB NOT NULL DEFAULT '',"
432 " value BLOB NOT NULL DEFAULT '')"); 407 " value BLOB NOT NULL DEFAULT '')");
@@ -440,8 +415,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls)
440 api->get = &sqlite_plugin_get; 415 api->get = &sqlite_plugin_get;
441 api->put = &sqlite_plugin_put; 416 api->put = &sqlite_plugin_put;
442 api->del = &sqlite_plugin_del; 417 api->del = &sqlite_plugin_del;
443 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 418 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite",
444 "sqlite", _("Sqlite datacache running\n")); 419 _("Sqlite datacache running\n"));
445 return api; 420 return api;
446} 421}
447 422
@@ -474,22 +449,20 @@ libgnunet_plugin_datacache_sqlite_done (void *cls)
474#if SQLITE_VERSION_NUMBER >= 3007000 449#if SQLITE_VERSION_NUMBER >= 3007000
475 if (result == SQLITE_BUSY) 450 if (result == SQLITE_BUSY)
476 { 451 {
477 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 452 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite",
478 "sqlite",
479 _ 453 _
480 ("Tried to close sqlite without finalizing all prepared statements.\n")); 454 ("Tried to close sqlite without finalizing all prepared statements.\n"));
481 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 455 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
482 while (stmt != NULL) 456 while (stmt != NULL)
483 { 457 {
484#if DEBUG_SQLITE 458#if DEBUG_SQLITE
485 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
486 "sqlite", "Closing statement %p\n", stmt); 460 "Closing statement %p\n", stmt);
487#endif 461#endif
488 result = sqlite3_finalize (stmt); 462 result = sqlite3_finalize (stmt);
489#if DEBUG_SQLITE 463#if DEBUG_SQLITE
490 if (result != SQLITE_OK) 464 if (result != SQLITE_OK)
491 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 465 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite",
492 "sqlite",
493 "Failed to close statement %p: %d\n", stmt, result); 466 "Failed to close statement %p: %d\n", stmt, result);
494#endif 467#endif
495 stmt = sqlite3_next_stmt (plugin->dbh, NULL); 468 stmt = sqlite3_next_stmt (plugin->dbh, NULL);
diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c
index 865f431d7..046c603ad 100644
--- a/src/datacache/plugin_datacache_template.c
+++ b/src/datacache/plugin_datacache_template.c
@@ -52,11 +52,8 @@ struct Plugin
52 * @return 0 on error, number of bytes used otherwise 52 * @return 0 on error, number of bytes used otherwise
53 */ 53 */
54static size_t 54static size_t
55template_plugin_put (void *cls, 55template_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size,
56 const GNUNET_HashCode * key, 56 const char *data, enum GNUNET_BLOCK_Type type,
57 size_t size,
58 const char *data,
59 enum GNUNET_BLOCK_Type type,
60 struct GNUNET_TIME_Absolute discard_time) 57 struct GNUNET_TIME_Absolute discard_time)
61{ 58{
62 GNUNET_break (0); 59 GNUNET_break (0);
@@ -76,8 +73,7 @@ template_plugin_put (void *cls,
76 * @return the number of results found 73 * @return the number of results found
77 */ 74 */
78static unsigned int 75static unsigned int
79template_plugin_get (void *cls, 76template_plugin_get (void *cls, const GNUNET_HashCode * key,
80 const GNUNET_HashCode * key,
81 enum GNUNET_BLOCK_Type type, 77 enum GNUNET_BLOCK_Type type,
82 GNUNET_DATACACHE_Iterator iter, void *iter_cls) 78 GNUNET_DATACACHE_Iterator iter, void *iter_cls)
83{ 79{
@@ -121,8 +117,8 @@ libgnunet_plugin_datacache_template_init (void *cls)
121 api->get = &template_plugin_get; 117 api->get = &template_plugin_get;
122 api->put = &template_plugin_put; 118 api->put = &template_plugin_put;
123 api->del = &template_plugin_del; 119 api->del = &template_plugin_del;
124 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 120 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template",
125 "template", _("Template datacache running\n")); 121 _("Template datacache running\n"));
126 return api; 122 return api;
127} 123}
128 124
diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c
index c04facc15..abf0209d8 100644
--- a/src/datacache/test_datacache.c
+++ b/src/datacache/test_datacache.c
@@ -39,10 +39,9 @@ static const char *plugin_name;
39 39
40 40
41static int 41static int
42checkIt (void *cls, 42checkIt (void *cls, struct GNUNET_TIME_Absolute exp,
43 struct GNUNET_TIME_Absolute exp, 43 const GNUNET_HashCode * key, size_t size, const char *data,
44 const GNUNET_HashCode * key, 44 enum GNUNET_BLOCK_Type type)
45 size_t size, const char *data, enum GNUNET_BLOCK_Type type)
46{ 45{
47 if (size != sizeof (GNUNET_HashCode)) 46 if (size != sizeof (GNUNET_HashCode))
48 { 47 {
@@ -59,9 +58,8 @@ checkIt (void *cls,
59 58
60 59
61static void 60static void
62run (void *cls, 61run (void *cls, char *const *args, const char *cfgfile,
63 char *const *args, 62 const struct GNUNET_CONFIGURATION_Handle *cfg)
64 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
65{ 63{
66 struct GNUNET_DATACACHE_Handle *h; 64 struct GNUNET_DATACACHE_Handle *h;
67 GNUNET_HashCode k; 65 GNUNET_HashCode k;
@@ -83,11 +81,9 @@ run (void *cls,
83 for (i = 0; i < 100; i++) 81 for (i = 0; i < 100; i++)
84 { 82 {
85 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); 83 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
86 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, 84 ASSERT (GNUNET_OK ==
87 &k, 85 GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode),
88 sizeof (GNUNET_HashCode), 86 (const char *) &n, 1 + i % 16, exp));
89 (const char *) &n,
90 1 + i % 16, exp));
91 k = n; 87 k = n;
92 } 88 }
93 memset (&k, 0, sizeof (GNUNET_HashCode)); 89 memset (&k, 0, sizeof (GNUNET_HashCode));
@@ -100,12 +96,10 @@ run (void *cls,
100 96
101 memset (&k, 42, sizeof (GNUNET_HashCode)); 97 memset (&k, 42, sizeof (GNUNET_HashCode));
102 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); 98 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
103 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, 99 ASSERT (GNUNET_OK ==
104 &k, 100 GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode),
105 sizeof (GNUNET_HashCode), 101 (const char *) &n, 792,
106 (const char *) &n, 102 GNUNET_TIME_UNIT_FOREVER_ABS));
107 792,
108 GNUNET_TIME_UNIT_FOREVER_ABS));
109 ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); 103 ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n));
110 104
111 GNUNET_DATACACHE_destroy (h); 105 GNUNET_DATACACHE_destroy (h);
@@ -153,13 +147,12 @@ main (int argc, char *argv[])
153 else 147 else
154 pos = (char *) plugin_name; 148 pos = (char *) plugin_name;
155 149
156 GNUNET_snprintf (cfg_name, 150 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf",
157 sizeof (cfg_name), 151 plugin_name);
158 "test_datacache_data_%s.conf", plugin_name);
159 if (pos != plugin_name) 152 if (pos != plugin_name)
160 pos[0] = '.'; 153 pos[0] = '.';
161 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 154 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
162 xargv, "test-datacache", "nohelp", options, &run, NULL); 155 "test-datacache", "nohelp", options, &run, NULL);
163 if (ok != 0) 156 if (ok != 0)
164 fprintf (stderr, "Missed some testcases: %d\n", ok); 157 fprintf (stderr, "Missed some testcases: %d\n", ok);
165 return ok; 158 return ok;
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c
index f943844a4..ad8681cec 100644
--- a/src/datacache/test_datacache_quota.c
+++ b/src/datacache/test_datacache_quota.c
@@ -44,9 +44,8 @@ static const char *plugin_name;
44 * some of the data from the last iteration is still there. 44 * some of the data from the last iteration is still there.
45 */ 45 */
46static void 46static void
47run (void *cls, 47run (void *cls, char *const *args, const char *cfgfile,
48 char *const *args, 48 const struct GNUNET_CONFIGURATION_Handle *cfg)
49 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
50{ 49{
51 struct GNUNET_DATACACHE_Handle *h; 50 struct GNUNET_DATACACHE_Handle *h;
52 GNUNET_HashCode k; 51 GNUNET_HashCode k;
@@ -140,14 +139,12 @@ main (int argc, char *argv[])
140 else 139 else
141 pos = (char *) plugin_name; 140 pos = (char *) plugin_name;
142 141
143 GNUNET_snprintf (cfg_name, 142 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf",
144 sizeof (cfg_name), 143 plugin_name);
145 "test_datacache_data_%s.conf", plugin_name);
146 if (pos != plugin_name) 144 if (pos != plugin_name)
147 pos[0] = '.'; 145 pos[0] = '.';
148 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, 146 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
149 xargv, "test-datacache-quota", "nohelp", 147 "test-datacache-quota", "nohelp", options, &run, NULL);
150 options, &run, NULL);
151 if (ok != 0) 148 if (ok != 0)
152 fprintf (stderr, "Missed some testcases: %d\n", ok); 149 fprintf (stderr, "Missed some testcases: %d\n", ok);
153 return ok; 150 return ok;