aboutsummaryrefslogtreecommitdiff
path: root/src/datastore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-02-06 17:33:40 +0000
committerChristian Grothoff <christian@grothoff.org>2016-02-06 17:33:40 +0000
commit85cc361c21c0e1e45d1f2c0fd2ce7c3ee1e2528c (patch)
tree26e0c875d6db9f2fa792c9703fcea532589e521f /src/datastore
parentb7f29be97540eca5c2d5d2c7802849aec87e70c0 (diff)
downloadgnunet-85cc361c21c0e1e45d1f2c0fd2ce7c3ee1e2528c.tar.gz
gnunet-85cc361c21c0e1e45d1f2c0fd2ce7c3ee1e2528c.zip
make some more use of libgnunetpq
Diffstat (limited to 'src/datastore')
-rw-r--r--src/datastore/Makefile.am1
-rw-r--r--src/datastore/plugin_datastore_postgres.c663
2 files changed, 398 insertions, 266 deletions
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index 4ad0ae028..9d08c8ac9 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -147,6 +147,7 @@ libgnunet_plugin_datastore_postgres_la_SOURCES = \
147libgnunet_plugin_datastore_postgres_la_LIBADD = \ 147libgnunet_plugin_datastore_postgres_la_LIBADD = \
148 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 148 $(top_builddir)/src/statistics/libgnunetstatistics.la \
149 $(top_builddir)/src/postgres/libgnunetpostgres.la \ 149 $(top_builddir)/src/postgres/libgnunetpostgres.la \
150 $(top_builddir)/src/pq/libgnunetpq.la \
150 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq 151 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq
151libgnunet_plugin_datastore_postgres_la_LDFLAGS = \ 152libgnunet_plugin_datastore_postgres_la_LDFLAGS = \
152 $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS) 153 $(GN_PLUGIN_LDFLAGS) $(POSTGRESQL_LDFLAGS)
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 653ef2944..0c51e8b7d 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2009-2013 GNUnet e.V. 3 Copyright (C) 2009-2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_datastore_plugin.h" 28#include "gnunet_datastore_plugin.h"
29#include "gnunet_postgres_lib.h" 29#include "gnunet_postgres_lib.h"
30#include "gnunet_pq_lib.h"
30 31
31 32
32/** 33/**
@@ -77,7 +78,8 @@ init_connection (struct Plugin *plugin)
77 78
78 ret = 79 ret =
79 PQexec (plugin->dbh, 80 PQexec (plugin->dbh,
80 "CREATE TABLE gn090 (" " repl INTEGER NOT NULL DEFAULT 0," 81 "CREATE TABLE gn090 ("
82 " repl INTEGER NOT NULL DEFAULT 0,"
81 " type INTEGER NOT NULL DEFAULT 0," 83 " type INTEGER NOT NULL DEFAULT 0,"
82 " prio INTEGER NOT NULL DEFAULT 0," 84 " prio INTEGER NOT NULL DEFAULT 0,"
83 " anonLevel INTEGER NOT NULL DEFAULT 0," 85 " anonLevel INTEGER NOT NULL DEFAULT 0,"
@@ -85,7 +87,8 @@ init_connection (struct Plugin *plugin)
85 " rvalue BIGINT NOT NULL DEFAULT 0," 87 " rvalue BIGINT NOT NULL DEFAULT 0,"
86 " hash BYTEA NOT NULL DEFAULT ''," 88 " hash BYTEA NOT NULL DEFAULT '',"
87 " vhash BYTEA NOT NULL DEFAULT ''," 89 " vhash BYTEA NOT NULL DEFAULT '',"
88 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); 90 " value BYTEA NOT NULL DEFAULT '')"
91 "WITH OIDS");
89 if ( (NULL == ret) || 92 if ( (NULL == ret) ||
90 ((PQresultStatus (ret) != PGRES_COMMAND_OK) && 93 ((PQresultStatus (ret) != PGRES_COMMAND_OK) &&
91 (0 != strcmp ("42P07", /* duplicate table */ 94 (0 != strcmp ("42P07", /* duplicate table */
@@ -115,10 +118,10 @@ init_connection (struct Plugin *plugin)
115 GNUNET_POSTGRES_exec (plugin->dbh, "CREATE INDEX idx_expire ON gn090 (expire)")) || 118 GNUNET_POSTGRES_exec (plugin->dbh, "CREATE INDEX idx_expire ON gn090 (expire)")) ||
116 (GNUNET_OK != 119 (GNUNET_OK !=
117 GNUNET_POSTGRES_exec (plugin->dbh, 120 GNUNET_POSTGRES_exec (plugin->dbh,
118 "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)")) || 121 "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)")) ||
119 (GNUNET_OK != 122 (GNUNET_OK !=
120 GNUNET_POSTGRES_exec (plugin->dbh, 123 GNUNET_POSTGRES_exec (plugin->dbh,
121 "CREATE INDEX idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)")) || 124 "CREATE INDEX idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)")) ||
122 (GNUNET_OK != 125 (GNUNET_OK !=
123 GNUNET_POSTGRES_exec (plugin->dbh, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)")) || 126 GNUNET_POSTGRES_exec (plugin->dbh, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)")) ||
124 (GNUNET_OK != 127 (GNUNET_OK !=
@@ -181,6 +184,18 @@ init_connection (struct Plugin *plugin)
181 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 " 184 "SELECT type, prio, anonLevel, expire, hash, value, oid FROM gn090 "
182 "WHERE hash=$1 " "ORDER BY oid ASC LIMIT 1 OFFSET $2", 2)) || 185 "WHERE hash=$1 " "ORDER BY oid ASC LIMIT 1 OFFSET $2", 2)) ||
183 (GNUNET_OK != 186 (GNUNET_OK !=
187 GNUNET_POSTGRES_prepare (plugin->dbh, "count_getvt",
188 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3", 3)) ||
189 (GNUNET_OK !=
190 GNUNET_POSTGRES_prepare (plugin->dbh, "count_gett",
191 "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2", 2)) ||
192 (GNUNET_OK !=
193 GNUNET_POSTGRES_prepare (plugin->dbh, "count_getv",
194 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2", 2)) ||
195 (GNUNET_OK !=
196 GNUNET_POSTGRES_prepare (plugin->dbh, "count_get",
197 "SELECT count(*) FROM gn090 WHERE hash=$1", 1)) ||
198 (GNUNET_OK !=
184 GNUNET_POSTGRES_prepare (plugin->dbh, "put", 199 GNUNET_POSTGRES_prepare (plugin->dbh, "put",
185 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) " 200 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
186 "VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)", 9)) || 201 "VALUES ($1, $2, $3, $4, $5, RANDOM(), $6, $7, $8)", 9)) ||
@@ -242,7 +257,11 @@ postgres_plugin_estimate_size (void *cls, unsigned long long *estimate)
242 "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0, 257 "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0,
243 NULL, NULL, NULL, NULL, 1); 258 NULL, NULL, NULL, NULL, 1);
244 if (GNUNET_OK != 259 if (GNUNET_OK !=
245 GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_TUPLES_OK, "PQexecParams", "get_size")) 260 GNUNET_POSTGRES_check_result (plugin->dbh,
261 ret,
262 PGRES_TUPLES_OK,
263 "PQexecParams",
264 "get_size"))
246 { 265 {
247 *estimate = 0; 266 *estimate = 0;
248 return; 267 return;
@@ -283,65 +302,62 @@ postgres_plugin_estimate_size (void *cls, unsigned long long *estimate)
283 * @param cont_cls continuation closure 302 * @param cont_cls continuation closure
284 */ 303 */
285static void 304static void
286postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, 305postgres_plugin_put (void *cls,
287 const void *data, enum GNUNET_BLOCK_Type type, 306 const struct GNUNET_HashCode *key,
288 uint32_t priority, uint32_t anonymity, 307 uint32_t size,
308 const void *data,
309 enum GNUNET_BLOCK_Type type,
310 uint32_t priority,
311 uint32_t anonymity,
289 uint32_t replication, 312 uint32_t replication,
290 struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, 313 struct GNUNET_TIME_Absolute expiration,
314 PluginPutCont cont,
291 void *cont_cls) 315 void *cont_cls)
292{ 316{
293 struct Plugin *plugin = cls; 317 struct Plugin *plugin = cls;
318 uint32_t utype = type;
294 struct GNUNET_HashCode vhash; 319 struct GNUNET_HashCode vhash;
295 PGresult *ret; 320 PGresult *ret;
296 uint32_t btype = htonl (type); 321 struct GNUNET_PQ_QueryParam params[] = {
297 uint32_t bprio = htonl (priority); 322 GNUNET_PQ_query_param_uint32 (&replication),
298 uint32_t banon = htonl (anonymity); 323 GNUNET_PQ_query_param_uint32 (&utype),
299 uint32_t brepl = htonl (replication); 324 GNUNET_PQ_query_param_uint32 (&priority),
300 uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value_us__; 325 GNUNET_PQ_query_param_uint32 (&anonymity),
301 326 GNUNET_PQ_query_param_absolute_time (&expiration),
302 const char *paramValues[] = { 327 GNUNET_PQ_query_param_auto_from_type (key),
303 (const char *) &brepl, 328 GNUNET_PQ_query_param_auto_from_type (&vhash),
304 (const char *) &btype, 329 GNUNET_PQ_query_param_fixed_size (data, size),
305 (const char *) &bprio, 330 GNUNET_PQ_query_param_end
306 (const char *) &banon,
307 (const char *) &bexpi,
308 (const char *) key,
309 (const char *) &vhash,
310 (const char *) data
311 }; 331 };
312 int paramLengths[] = {
313 sizeof (brepl),
314 sizeof (btype),
315 sizeof (bprio),
316 sizeof (banon),
317 sizeof (bexpi),
318 sizeof (struct GNUNET_HashCode),
319 sizeof (struct GNUNET_HashCode),
320 size
321 };
322 const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 };
323 332
324 GNUNET_CRYPTO_hash (data, size, &vhash); 333 GNUNET_CRYPTO_hash (data, size, &vhash);
325 ret = 334 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
326 PQexecPrepared (plugin->dbh, "put", 8, paramValues, paramLengths, 335 "put",
327 paramFormats, 1); 336 params);
328 if (GNUNET_OK != 337 if (GNUNET_OK !=
329 GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put")) 338 GNUNET_POSTGRES_check_result (plugin->dbh,
339 ret,
340 PGRES_COMMAND_OK,
341 "PQexecPrepared", "put"))
330 { 342 {
331 cont (cont_cls, key, size, GNUNET_SYSERR, _("Postgress exec failure")); 343 cont (cont_cls, key, size,
344 GNUNET_SYSERR,
345 _("Postgress exec failure"));
332 return; 346 return;
333 } 347 }
334 PQclear (ret); 348 PQclear (ret);
335 plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 349 plugin->env->duc (plugin->env->cls,
336 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", 350 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
337 "Stored %u bytes in database\n", (unsigned int) size); 351 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
352 "datastore-postgres",
353 "Stored %u bytes in database\n",
354 (unsigned int) size);
338 cont (cont_cls, key, size, GNUNET_OK, NULL); 355 cont (cont_cls, key, size, GNUNET_OK, NULL);
339} 356}
340 357
341 358
342/** 359/**
343 * Function invoked to process the result and call 360 * Function invoked to process the result and call the processor.
344 * the processor.
345 * 361 *
346 * @param plugin global plugin data 362 * @param plugin global plugin data
347 * @param proc function to call the value (once only). 363 * @param proc function to call the value (once only).
@@ -351,89 +367,117 @@ postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t siz
351 * @param line line number for error messages 367 * @param line line number for error messages
352 */ 368 */
353static void 369static void
354process_result (struct Plugin *plugin, PluginDatumProcessor proc, 370process_result (struct Plugin *plugin,
355 void *proc_cls, PGresult * res, 371 PluginDatumProcessor proc,
372 void *proc_cls,
373 PGresult * res,
356 const char *filename, int line) 374 const char *filename, int line)
357{ 375{
358 int iret; 376 int iret;
359 enum GNUNET_BLOCK_Type type; 377 uint32_t rowid;
378 uint32_t utype;
360 uint32_t anonymity; 379 uint32_t anonymity;
361 uint32_t priority; 380 uint32_t priority;
362 uint32_t size; 381 size_t size;
363 unsigned int rowid; 382 void *data;
364 struct GNUNET_TIME_Absolute expiration_time; 383 struct GNUNET_TIME_Absolute expiration_time;
365 struct GNUNET_HashCode key; 384 struct GNUNET_HashCode key;
385 struct GNUNET_PQ_ResultSpec rs[] = {
386 GNUNET_PQ_result_spec_uint32 ("type", &utype),
387 GNUNET_PQ_result_spec_uint32 ("prio", &priority),
388 GNUNET_PQ_result_spec_uint32 ("anonLevel", &anonymity),
389 GNUNET_PQ_result_spec_uint32 ("oid", &rowid),
390 GNUNET_PQ_result_spec_absolute_time ("expire", &expiration_time),
391 GNUNET_PQ_result_spec_auto_from_type ("hash", &key),
392 GNUNET_PQ_result_spec_variable_size ("value", &data, &size),
393 GNUNET_PQ_result_spec_end
394 };
366 395
367 if (GNUNET_OK != 396 if (GNUNET_OK !=
368 GNUNET_POSTGRES_check_result_ (plugin->dbh, res, PGRES_TUPLES_OK, "PQexecPrepared", "select", 397 GNUNET_POSTGRES_check_result_ (plugin->dbh,
398 res,
399 PGRES_TUPLES_OK,
400 "PQexecPrepared",
401 "select",
369 filename, line)) 402 filename, line))
370 { 403 {
371 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", 404 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
405 "datastore-postgres",
372 "Ending iteration (postgres error)\n"); 406 "Ending iteration (postgres error)\n");
373 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 407 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
408 GNUNET_TIME_UNIT_ZERO_ABS, 0);
374 return; 409 return;
375 } 410 }
376 411
377 if (0 == PQntuples (res)) 412 if (0 == PQntuples (res))
378 { 413 {
379 /* no result */ 414 /* no result */
380 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", 415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
416 "datastore-postgres",
381 "Ending iteration (no more results)\n"); 417 "Ending iteration (no more results)\n");
382 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 418 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
419 GNUNET_TIME_UNIT_ZERO_ABS, 0);
383 PQclear (res); 420 PQclear (res);
384 return; 421 return;
385 } 422 }
386 if ((1 != PQntuples (res)) || (7 != PQnfields (res)) || 423 if (1 != PQntuples (res))
387 (sizeof (uint32_t) != PQfsize (res, 0)) ||
388 (sizeof (uint32_t) != PQfsize (res, 6)))
389 { 424 {
390 GNUNET_break (0); 425 GNUNET_break (0);
391 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 426 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
427 GNUNET_TIME_UNIT_ZERO_ABS, 0);
392 PQclear (res); 428 PQclear (res);
393 return; 429 return;
394 } 430 }
395 rowid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 6)); 431 if (GNUNET_OK !=
396 if ((sizeof (uint32_t) != PQfsize (res, 0)) || 432 GNUNET_PQ_extract_result (res,
397 (sizeof (uint32_t) != PQfsize (res, 1)) || 433 rs,
398 (sizeof (uint32_t) != PQfsize (res, 2)) || 434 0))
399 (sizeof (uint64_t) != PQfsize (res, 3)) ||
400 (sizeof (struct GNUNET_HashCode) != PQgetlength (res, 0, 4)))
401 { 435 {
402 GNUNET_break (0); 436 GNUNET_break (0);
403 PQclear (res); 437 PQclear (res);
404 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh, "delrow", rowid); 438 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
405 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 439 "delrow",
440 rowid);
441 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
442 GNUNET_TIME_UNIT_ZERO_ABS, 0);
406 return; 443 return;
407 } 444 }
408 445
409 type = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0)); 446 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
410 priority = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1)); 447 "datastore-postgres",
411 anonymity = ntohl (*(uint32_t *) PQgetvalue (res, 0, 2));
412 expiration_time.abs_value_us =
413 GNUNET_ntohll (*(uint64_t *) PQgetvalue (res, 0, 3));
414 memcpy (&key, PQgetvalue (res, 0, 4), sizeof (struct GNUNET_HashCode));
415 size = PQgetlength (res, 0, 5);
416 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
417 "Found result of size %u bytes and type %u in database\n", 448 "Found result of size %u bytes and type %u in database\n",
418 (unsigned int) size, (unsigned int) type); 449 (unsigned int) size,
419 iret = 450 (unsigned int) utype);
420 proc (proc_cls, &key, size, PQgetvalue (res, 0, 5), 451 iret = proc (proc_cls,
421 (enum GNUNET_BLOCK_Type) type, priority, anonymity, expiration_time, 452 &key,
422 rowid); 453 size,
454 data,
455 (enum GNUNET_BLOCK_Type) utype,
456 priority,
457 anonymity,
458 expiration_time,
459 rowid);
423 PQclear (res); 460 PQclear (res);
424 if (iret == GNUNET_NO) 461 if (iret == GNUNET_NO)
425 { 462 {
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "Processor asked for item %u to be removed.\n", rowid); 464 "Processor asked for item %u to be removed.\n",
428 if (GNUNET_OK == GNUNET_POSTGRES_delete_by_rowid (plugin->dbh, "delrow", rowid)) 465 (unsigned int) rowid);
466 if (GNUNET_OK ==
467 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
468 "delrow",
469 rowid))
429 { 470 {
430 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", 471 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
472 "datastore-postgres",
431 "Deleting %u bytes from database\n", 473 "Deleting %u bytes from database\n",
432 (unsigned int) size); 474 (unsigned int) size);
433 plugin->env->duc (plugin->env->cls, 475 plugin->env->duc (plugin->env->cls,
434 -(size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 476 - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
435 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", 477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
436 "Deleted %u bytes from database\n", (unsigned int) size); 478 "datastore-postgres",
479 "Deleted %u bytes from database\n",
480 (unsigned int) size);
437 } 481 }
438 } 482 }
439} 483}
@@ -459,110 +503,161 @@ process_result (struct Plugin *plugin, PluginDatumProcessor proc,
459 * @param proc_cls closure for iter 503 * @param proc_cls closure for iter
460 */ 504 */
461static void 505static void
462postgres_plugin_get_key (void *cls, uint64_t offset, 506postgres_plugin_get_key (void *cls,
463 const struct GNUNET_HashCode * key, 507 uint64_t offset,
464 const struct GNUNET_HashCode * vhash, 508 const struct GNUNET_HashCode *key,
465 enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, 509 const struct GNUNET_HashCode *vhash,
510 enum GNUNET_BLOCK_Type type,
511 PluginDatumProcessor proc,
466 void *proc_cls) 512 void *proc_cls)
467{ 513{
468 struct Plugin *plugin = cls; 514 struct Plugin *plugin = cls;
469 const int paramFormats[] = { 1, 1, 1, 1, 1 }; 515 uint32_t utype = type;
470 int paramLengths[4];
471 const char *paramValues[4];
472 int nparams;
473 const char *pname;
474 PGresult *ret; 516 PGresult *ret;
475 uint64_t total; 517 uint64_t total;
476 uint64_t blimit_off; 518 uint64_t limit_off;
477 uint32_t btype; 519
478 520 if (0 != type)
479 GNUNET_assert (key != NULL);
480 paramValues[0] = (const char *) key;
481 paramLengths[0] = sizeof (struct GNUNET_HashCode);
482 btype = htonl (type);
483 if (type != 0)
484 { 521 {
485 if (vhash != NULL) 522 if (NULL != vhash)
486 { 523 {
487 paramValues[1] = (const char *) vhash; 524 struct GNUNET_PQ_QueryParam params[] = {
488 paramLengths[1] = sizeof (struct GNUNET_HashCode); 525 GNUNET_PQ_query_param_auto_from_type (key),
489 paramValues[2] = (const char *) &btype; 526 GNUNET_PQ_query_param_auto_from_type (vhash),
490 paramLengths[2] = sizeof (btype); 527 GNUNET_PQ_query_param_uint32 (&utype),
491 paramValues[3] = (const char *) &blimit_off; 528 GNUNET_PQ_query_param_end
492 paramLengths[3] = sizeof (blimit_off); 529 };
493 nparams = 4; 530 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
494 pname = "getvt"; 531 "count_getvt",
495 ret = 532 params);
496 PQexecParams (plugin->dbh,
497 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2 AND type=$3",
498 3, NULL, paramValues, paramLengths, paramFormats, 1);
499 } 533 }
500 else 534 else
501 { 535 {
502 paramValues[1] = (const char *) &btype; 536 struct GNUNET_PQ_QueryParam params[] = {
503 paramLengths[1] = sizeof (btype); 537 GNUNET_PQ_query_param_auto_from_type (key),
504 paramValues[2] = (const char *) &blimit_off; 538 GNUNET_PQ_query_param_uint32 (&utype),
505 paramLengths[2] = sizeof (blimit_off); 539 GNUNET_PQ_query_param_end
506 nparams = 3; 540 };
507 pname = "gett"; 541 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
508 ret = 542 "count_gett",
509 PQexecParams (plugin->dbh, 543 params);
510 "SELECT count(*) FROM gn090 WHERE hash=$1 AND type=$2",
511 2, NULL, paramValues, paramLengths, paramFormats, 1);
512 } 544 }
513 } 545 }
514 else 546 else
515 { 547 {
516 if (vhash != NULL) 548 if (NULL != vhash)
517 { 549 {
518 paramValues[1] = (const char *) vhash; 550 struct GNUNET_PQ_QueryParam params[] = {
519 paramLengths[1] = sizeof (struct GNUNET_HashCode); 551 GNUNET_PQ_query_param_auto_from_type (key),
520 paramValues[2] = (const char *) &blimit_off; 552 GNUNET_PQ_query_param_auto_from_type (vhash),
521 paramLengths[2] = sizeof (blimit_off); 553 GNUNET_PQ_query_param_end
522 nparams = 3; 554 };
523 pname = "getv"; 555 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
524 ret = 556 "count_getv",
525 PQexecParams (plugin->dbh, 557 params);
526 "SELECT count(*) FROM gn090 WHERE hash=$1 AND vhash=$2",
527 2, NULL, paramValues, paramLengths, paramFormats, 1);
528 } 558 }
529 else 559 else
530 { 560 {
531 paramValues[1] = (const char *) &blimit_off; 561 struct GNUNET_PQ_QueryParam params[] = {
532 paramLengths[1] = sizeof (blimit_off); 562 GNUNET_PQ_query_param_auto_from_type (key),
533 nparams = 2; 563 GNUNET_PQ_query_param_end
534 pname = "get"; 564 };
535 ret = 565 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
536 PQexecParams (plugin->dbh, "SELECT count(*) FROM gn090 WHERE hash=$1", 566 "count_get",
537 1, NULL, paramValues, paramLengths, paramFormats, 1); 567 params);
538 } 568 }
539 } 569 }
570
540 if (GNUNET_OK != 571 if (GNUNET_OK !=
541 GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_TUPLES_OK, "PQexecParams", pname)) 572 GNUNET_POSTGRES_check_result (plugin->dbh,
573 ret,
574 PGRES_TUPLES_OK,
575 "PQexecParams",
576 "count"))
542 { 577 {
543 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 578 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
579 GNUNET_TIME_UNIT_ZERO_ABS, 0);
544 return; 580 return;
545 } 581 }
546 if ((PQntuples (ret) != 1) || (PQnfields (ret) != 1) || 582 if ( (PQntuples (ret) != 1) ||
547 (PQgetlength (ret, 0, 0) != sizeof (unsigned long long))) 583 (PQnfields (ret) != 1) ||
584 (PQgetlength (ret, 0, 0) != sizeof (uint64_t)))
548 { 585 {
549 GNUNET_break (0); 586 GNUNET_break (0);
550 PQclear (ret); 587 PQclear (ret);
551 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 588 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
589 GNUNET_TIME_UNIT_ZERO_ABS, 0);
552 return; 590 return;
553 } 591 }
554 total = GNUNET_ntohll (*(const unsigned long long *) PQgetvalue (ret, 0, 0)); 592 total = GNUNET_ntohll (*(const uint64_t *) PQgetvalue (ret, 0, 0));
555 PQclear (ret); 593 PQclear (ret);
556 if (total == 0) 594 if (0 == total)
557 { 595 {
558 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); 596 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
597 GNUNET_TIME_UNIT_ZERO_ABS, 0);
559 return; 598 return;
560 } 599 }
561 blimit_off = GNUNET_htonll (offset % total); 600 limit_off = offset % total;
562 ret = 601
563 PQexecPrepared (plugin->dbh, pname, nparams, paramValues, paramLengths, 602 if (0 != type)
564 paramFormats, 1); 603 {
565 process_result (plugin, proc, proc_cls, ret, __FILE__, __LINE__); 604 if (NULL != vhash)
605 {
606 struct GNUNET_PQ_QueryParam params[] = {
607 GNUNET_PQ_query_param_auto_from_type (key),
608 GNUNET_PQ_query_param_auto_from_type (&vhash),
609 GNUNET_PQ_query_param_uint32 (&utype),
610 GNUNET_PQ_query_param_uint64 (&limit_off),
611 GNUNET_PQ_query_param_end
612 };
613 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
614 "getvt",
615 params);
616 }
617 else
618 {
619 struct GNUNET_PQ_QueryParam params[] = {
620 GNUNET_PQ_query_param_auto_from_type (key),
621 GNUNET_PQ_query_param_uint32 (&utype),
622 GNUNET_PQ_query_param_uint64 (&limit_off),
623 GNUNET_PQ_query_param_end
624 };
625 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
626 "gett",
627 params);
628 }
629 }
630 else
631 {
632 if (NULL != vhash)
633 {
634 struct GNUNET_PQ_QueryParam params[] = {
635 GNUNET_PQ_query_param_auto_from_type (key),
636 GNUNET_PQ_query_param_auto_from_type (&vhash),
637 GNUNET_PQ_query_param_uint64 (&limit_off),
638 GNUNET_PQ_query_param_end
639 };
640 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
641 "getv",
642 params);
643 }
644 else
645 {
646 struct GNUNET_PQ_QueryParam params[] = {
647 GNUNET_PQ_query_param_auto_from_type (key),
648 GNUNET_PQ_query_param_uint64 (&limit_off),
649 GNUNET_PQ_query_param_end
650 };
651 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
652 "get",
653 params);
654 }
655 }
656 process_result (plugin,
657 proc,
658 proc_cls,
659 ret,
660 __FILE__, __LINE__);
566} 661}
567 662
568 663
@@ -570,39 +665,44 @@ postgres_plugin_get_key (void *cls, uint64_t offset,
570 * Select a subset of the items in the datastore and call 665 * Select a subset of the items in the datastore and call
571 * the given iterator for each of them. 666 * the given iterator for each of them.
572 * 667 *
573 * @param cls our "struct Plugin*" 668 * @param cls our `struct Plugin *`
574 * @param offset offset of the result (modulo num-results); 669 * @param offset offset of the result (modulo num-results);
575 * specific ordering does not matter for the offset 670 * specific ordering does not matter for the offset
576 * @param type entries of which type should be considered? 671 * @param type entries of which type should be considered?
577 * Use 0 for any type. 672 * Use 0 for any type.
578 * @param proc function to call on the matching value; 673 * @param proc function to call on the matching value;
579 * will be called with a NULL if no value matches 674 * will be called with a NULL if no value matches
580 * @param proc_cls closure for proc 675 * @param proc_cls closure for @a proc
581 */ 676 */
582static void 677static void
583postgres_plugin_get_zero_anonymity (void *cls, uint64_t offset, 678postgres_plugin_get_zero_anonymity (void *cls,
679 uint64_t offset,
584 enum GNUNET_BLOCK_Type type, 680 enum GNUNET_BLOCK_Type type,
585 PluginDatumProcessor proc, void *proc_cls) 681 PluginDatumProcessor proc,
682 void *proc_cls)
586{ 683{
587 struct Plugin *plugin = cls; 684 struct Plugin *plugin = cls;
588 uint32_t btype; 685 uint32_t utype = type;
589 uint64_t boff; 686 struct GNUNET_PQ_QueryParam params[] = {
590 const int paramFormats[] = { 1, 1 }; 687 GNUNET_PQ_query_param_uint32 (&utype),
591 int paramLengths[] = { sizeof (btype), sizeof (boff) }; 688 GNUNET_PQ_query_param_uint64 (&offset),
592 const char *paramValues[] = { (const char *) &btype, (const char *) &boff }; 689 GNUNET_PQ_query_param_end
690 };
593 PGresult *ret; 691 PGresult *ret;
594 692
595 btype = htonl ((uint32_t) type); 693 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
596 boff = GNUNET_htonll (offset); 694 "select_non_anonymous",
597 ret = 695 params);
598 PQexecPrepared (plugin->dbh, "select_non_anonymous", 2, paramValues, 696
599 paramLengths, paramFormats, 1); 697 process_result (plugin,
600 process_result (plugin, proc, proc_cls, ret, __FILE__, __LINE__); 698 proc, proc_cls,
699 ret,
700 __FILE__, __LINE__);
601} 701}
602 702
603 703
604/** 704/**
605 * Context for 'repl_iter' function. 705 * Context for #repl_iter() function.
606 */ 706 */
607struct ReplCtx 707struct ReplCtx
608{ 708{
@@ -618,7 +718,7 @@ struct ReplCtx
618 PluginDatumProcessor proc; 718 PluginDatumProcessor proc;
619 719
620 /** 720 /**
621 * Closure for proc. 721 * Closure for @e proc.
622 */ 722 */
623 void *proc_cls; 723 void *proc_cls;
624}; 724};
@@ -629,9 +729,9 @@ struct ReplCtx
629 * Decrements the replication counter and calls the original 729 * Decrements the replication counter and calls the original
630 * iterator. 730 * iterator.
631 * 731 *
632 * @param cls closure with the 'struct ReplCtx*' 732 * @param cls closure with the `struct ReplCtx *`
633 * @param key key for the content 733 * @param key key for the content
634 * @param size number of bytes in data 734 * @param size number of bytes in @a data
635 * @param data content stored 735 * @param data content stored
636 * @param type type of the content 736 * @param type type of the content
637 * @param priority priority of the content 737 * @param priority priority of the content
@@ -639,61 +739,70 @@ struct ReplCtx
639 * @param expiration expiration time for the content 739 * @param expiration expiration time for the content
640 * @param uid unique identifier for the datum; 740 * @param uid unique identifier for the datum;
641 * maybe 0 if no unique identifier is available 741 * maybe 0 if no unique identifier is available
642 * 742 * @return #GNUNET_SYSERR to abort the iteration,
643 * @return GNUNET_SYSERR to abort the iteration, GNUNET_OK to continue 743 * #GNUNET_OK to continue
644 * (continue on call to "next", of course), 744 * (continue on call to "next", of course),
645 * GNUNET_NO to delete the item and continue (if supported) 745 * #GNUNET_NO to delete the item and continue (if supported)
646 */ 746 */
647static int 747static int
648repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, 748repl_proc (void *cls,
649 const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, 749 const struct GNUNET_HashCode *key,
650 uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, 750 uint32_t size,
751 const void *data,
752 enum GNUNET_BLOCK_Type type,
753 uint32_t priority,
754 uint32_t anonymity,
755 struct GNUNET_TIME_Absolute expiration,
651 uint64_t uid) 756 uint64_t uid)
652{ 757{
653 struct ReplCtx *rc = cls; 758 struct ReplCtx *rc = cls;
654 struct Plugin *plugin = rc->plugin; 759 struct Plugin *plugin = rc->plugin;
655 int ret; 760 int ret;
761 uint32_t oid = (uint32_t) uid;
762 struct GNUNET_PQ_QueryParam params[] = {
763 GNUNET_PQ_query_param_uint32 (&oid),
764 GNUNET_PQ_query_param_end
765 };
656 PGresult *qret; 766 PGresult *qret;
657 uint32_t boid;
658 767
659 ret = 768 ret = rc->proc (rc->proc_cls,
660 rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, 769 key,
661 expiration, uid); 770 size, data,
662 if (NULL != key) 771 type,
663 { 772 priority,
664 boid = htonl ((uint32_t) uid); 773 anonymity,
665 const char *paramValues[] = { 774 expiration, uid);
666 (const char *) &boid, 775 if (NULL == key)
667 }; 776 return ret;
668 int paramLengths[] = { 777 qret = GNUNET_PQ_exec_prepared (plugin->dbh,
669 sizeof (boid), 778 "decrepl",
670 }; 779 params);
671 const int paramFormats[] = { 1 }; 780 if (GNUNET_OK !=
672 qret = 781 GNUNET_POSTGRES_check_result (plugin->dbh,
673 PQexecPrepared (plugin->dbh, "decrepl", 1, paramValues, paramLengths, 782 qret,
674 paramFormats, 1); 783 PGRES_COMMAND_OK,
675 if (GNUNET_OK != 784 "PQexecPrepared",
676 GNUNET_POSTGRES_check_result (plugin->dbh, qret, PGRES_COMMAND_OK, "PQexecPrepared", 785 "decrepl"))
677 "decrepl")) 786 return GNUNET_SYSERR;
678 return GNUNET_SYSERR; 787 PQclear (qret);
679 PQclear (qret);
680 }
681 return ret; 788 return ret;
682} 789}
683 790
684 791
685/** 792/**
686 * Get a random item for replication. Returns a single, not expired, random item 793 * Get a random item for replication. Returns a single, not expired,
687 * from those with the highest replication counters. The item's 794 * random item from those with the highest replication counters. The
688 * replication counter is decremented by one IF it was positive before. 795 * item's replication counter is decremented by one IF it was positive
689 * Call 'proc' with all values ZERO or NULL if the datastore is empty. 796 * before. Call @a proc with all values ZERO or NULL if the datastore
797 * is empty.
690 * 798 *
691 * @param cls closure with the 'struct Plugin' 799 * @param cls closure with the `struct Plugin`
692 * @param proc function to call the value (once only). 800 * @param proc function to call the value (once only).
693 * @param proc_cls closure for proc 801 * @param proc_cls closure for @a proc
694 */ 802 */
695static void 803static void
696postgres_plugin_get_replication (void *cls, PluginDatumProcessor proc, 804postgres_plugin_get_replication (void *cls,
805 PluginDatumProcessor proc,
697 void *proc_cls) 806 void *proc_cls)
698{ 807{
699 struct Plugin *plugin = cls; 808 struct Plugin *plugin = cls;
@@ -703,37 +812,46 @@ postgres_plugin_get_replication (void *cls, PluginDatumProcessor proc,
703 rc.plugin = plugin; 812 rc.plugin = plugin;
704 rc.proc = proc; 813 rc.proc = proc;
705 rc.proc_cls = proc_cls; 814 rc.proc_cls = proc_cls;
706 ret = 815 ret = PQexecPrepared (plugin->dbh,
707 PQexecPrepared (plugin->dbh, "select_replication_order", 0, NULL, NULL, 816 "select_replication_order", 0, NULL, NULL,
708 NULL, 1); 817 NULL, 1);
709 process_result (plugin, &repl_proc, &rc, ret, __FILE__, __LINE__); 818 process_result (plugin,
819 &repl_proc,
820 &rc,
821 ret,
822 __FILE__, __LINE__);
710} 823}
711 824
712 825
713/** 826/**
714 * Get a random item for expiration. 827 * Get a random item for expiration. Call @a proc with all values
715 * Call 'proc' with all values ZERO or NULL if the datastore is empty. 828 * ZERO or NULL if the datastore is empty.
716 * 829 *
717 * @param cls closure with the 'struct Plugin' 830 * @param cls closure with the `struct Plugin`
718 * @param proc function to call the value (once only). 831 * @param proc function to call the value (once only).
719 * @param proc_cls closure for proc 832 * @param proc_cls closure for @a proc
720 */ 833 */
721static void 834static void
722postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc, 835postgres_plugin_get_expiration (void *cls,
836 PluginDatumProcessor proc,
723 void *proc_cls) 837 void *proc_cls)
724{ 838{
725 struct Plugin *plugin = cls; 839 struct Plugin *plugin = cls;
726 uint64_t btime; 840 struct GNUNET_TIME_Absolute now;
727 const int paramFormats[] = { 1 }; 841 struct GNUNET_PQ_QueryParam params[] = {
728 int paramLengths[] = { sizeof (btime) }; 842 GNUNET_PQ_query_param_absolute_time (&now),
729 const char *paramValues[] = { (const char *) &btime }; 843 GNUNET_PQ_query_param_end
844 };
730 PGresult *ret; 845 PGresult *ret;
731 846
732 btime = GNUNET_htonll (GNUNET_TIME_absolute_get ().abs_value_us); 847 now = GNUNET_TIME_absolute_get ();
733 ret = 848 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
734 PQexecPrepared (plugin->dbh, "select_expiration_order", 1, paramValues, 849 "select_expiration_order",
735 paramLengths, paramFormats, 1); 850 params);
736 process_result (plugin, proc, proc_cls, ret, __FILE__, __LINE__); 851 process_result (plugin,
852 proc, proc_cls,
853 ret,
854 __FILE__, __LINE__);
737} 855}
738 856
739 857
@@ -748,7 +866,7 @@ postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
748 * Note that it is possible for multiple values to match this put. 866 * Note that it is possible for multiple values to match this put.
749 * In that case, all of the respective values are updated. 867 * In that case, all of the respective values are updated.
750 * 868 *
751 * @param cls our "struct Plugin*" 869 * @param cls our `struct Plugin *`
752 * @param uid unique identifier of the datum 870 * @param uid unique identifier of the datum
753 * @param delta by how much should the priority 871 * @param delta by how much should the priority
754 * change? If priority + delta < 0 the 872 * change? If priority + delta < 0 the
@@ -761,39 +879,43 @@ postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
761 * @param cons_cls continuation closure 879 * @param cons_cls continuation closure
762 */ 880 */
763static void 881static void
764postgres_plugin_update (void *cls, uint64_t uid, int delta, 882postgres_plugin_update (void *cls,
883 uint64_t uid,
884 int delta,
765 struct GNUNET_TIME_Absolute expire, 885 struct GNUNET_TIME_Absolute expire,
766 PluginUpdateCont cont, void *cont_cls) 886 PluginUpdateCont cont,
887 void *cont_cls)
767{ 888{
768 struct Plugin *plugin = cls; 889 struct Plugin *plugin = cls;
769 PGresult *ret; 890 uint32_t idelta = delta;
770 int32_t bdelta = (int32_t) htonl ((uint32_t) delta); 891 uint32_t oid = (uint32_t) uid;
771 uint32_t boid = htonl ((uint32_t) uid); 892 struct GNUNET_PQ_QueryParam params[] = {
772 uint64_t bexpire = GNUNET_TIME_absolute_hton (expire).abs_value_us__; 893 GNUNET_PQ_query_param_uint32 (&idelta),
773 894 GNUNET_PQ_query_param_absolute_time (&expire),
774 const char *paramValues[] = { 895 GNUNET_PQ_query_param_uint32 (&oid),
775 (const char *) &bdelta, 896 GNUNET_PQ_query_param_end
776 (const char *) &bexpire,
777 (const char *) &boid,
778 };
779 int paramLengths[] = {
780 sizeof (bdelta),
781 sizeof (bexpire),
782 sizeof (boid),
783 }; 897 };
784 const int paramFormats[] = { 1, 1, 1 }; 898 PGresult *ret;
785 899
786 ret = 900 ret = GNUNET_PQ_exec_prepared (plugin->dbh,
787 PQexecPrepared (plugin->dbh, "update", 3, paramValues, paramLengths, 901 "update",
788 paramFormats, 1); 902 params);
789 if (GNUNET_OK != 903 if (GNUNET_OK !=
790 GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "update")) 904 GNUNET_POSTGRES_check_result (plugin->dbh,
905 ret,
906 PGRES_COMMAND_OK,
907 "PQexecPrepared",
908 "update"))
791 { 909 {
792 cont (cont_cls, GNUNET_SYSERR, NULL); 910 cont (cont_cls,
911 GNUNET_SYSERR,
912 NULL);
793 return; 913 return;
794 } 914 }
795 PQclear (ret); 915 PQclear (ret);
796 cont (cont_cls, GNUNET_OK, NULL); 916 cont (cont_cls,
917 GNUNET_OK,
918 NULL);
797} 919}
798 920
799 921
@@ -801,9 +923,9 @@ postgres_plugin_update (void *cls, uint64_t uid, int delta,
801/** 923/**
802 * Get all of the keys in the datastore. 924 * Get all of the keys in the datastore.
803 * 925 *
804 * @param cls closure with the 'struct Plugin' 926 * @param cls closure with the `struct Plugin *`
805 * @param proc function to call on each key 927 * @param proc function to call on each key
806 * @param proc_cls closure for proc 928 * @param proc_cls closure for @a proc
807 */ 929 */
808static void 930static void
809postgres_plugin_get_keys (void *cls, 931postgres_plugin_get_keys (void *cls,
@@ -816,13 +938,18 @@ postgres_plugin_get_keys (void *cls,
816 struct GNUNET_HashCode key; 938 struct GNUNET_HashCode key;
817 PGresult * res; 939 PGresult * res;
818 940
819 res = PQexecPrepared (plugin->dbh, "get_keys", 0, NULL, NULL, NULL, 1); 941 res = PQexecPrepared (plugin->dbh,
942 "get_keys",
943 0, NULL, NULL, NULL, 1);
820 ret = PQntuples (res); 944 ret = PQntuples (res);
821 for (i=0;i<ret;i++) 945 for (i=0;i<ret;i++)
822 { 946 {
823 if (sizeof (struct GNUNET_HashCode) != PQgetlength (res, i, 0)) 947 if (sizeof (struct GNUNET_HashCode) !=
948 PQgetlength (res, i, 0))
824 { 949 {
825 memcpy (&key, PQgetvalue (res, i, 0), sizeof (struct GNUNET_HashCode)); 950 memcpy (&key,
951 PQgetvalue (res, i, 0),
952 sizeof (struct GNUNET_HashCode));
826 proc (proc_cls, &key, 1); 953 proc (proc_cls, &key, 1);
827 } 954 }
828 } 955 }
@@ -835,23 +962,26 @@ postgres_plugin_get_keys (void *cls,
835/** 962/**
836 * Drop database. 963 * Drop database.
837 * 964 *
838 * @param cls closure with the 'struct Plugin' 965 * @param cls closure with the `struct Plugin *`
839 */ 966 */
840static void 967static void
841postgres_plugin_drop (void *cls) 968postgres_plugin_drop (void *cls)
842{ 969{
843 struct Plugin *plugin = cls; 970 struct Plugin *plugin = cls;
844 971
845 if (GNUNET_OK != GNUNET_POSTGRES_exec (plugin->dbh, "DROP TABLE gn090")) 972 if (GNUNET_OK !=
846 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "postgres", _("Failed to drop table from database.\n")); 973 GNUNET_POSTGRES_exec (plugin->dbh, "DROP TABLE gn090"))
974 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
975 "postgres",
976 _("Failed to drop table from database.\n"));
847} 977}
848 978
849 979
850/** 980/**
851 * Entry point for the plugin. 981 * Entry point for the plugin.
852 * 982 *
853 * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*" 983 * @param cls the `struct GNUNET_DATASTORE_PluginEnvironment*`
854 * @return our "struct Plugin*" 984 * @return our `struct Plugin *`
855 */ 985 */
856void * 986void *
857libgnunet_plugin_datastore_postgres_init (void *cls) 987libgnunet_plugin_datastore_postgres_init (void *cls)
@@ -886,7 +1016,8 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
886 1016
887/** 1017/**
888 * Exit point from the plugin. 1018 * Exit point from the plugin.
889 * @param cls our "struct Plugin*" 1019 *
1020 * @param cls our `struct Plugin *`
890 * @return always NULL 1021 * @return always NULL
891 */ 1022 */
892void * 1023void *