aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-03-14 22:40:04 +0000
committerChristian Grothoff <christian@grothoff.org>2016-03-14 22:40:04 +0000
commit4c1791f13283df27338cd877e2087d519aaab05e (patch)
treeb852de95aa307225befc78c54624811f3a79e344 /src/datastore/plugin_datastore_postgres.c
parent165f050555ce4f06380cc26c1dc09235c7b135e6 (diff)
downloadgnunet-4c1791f13283df27338cd877e2087d519aaab05e.tar.gz
gnunet-4c1791f13283df27338cd877e2087d519aaab05e.zip
-bugfix, adding comments, fixing indent
Diffstat (limited to 'src/datastore/plugin_datastore_postgres.c')
-rw-r--r--src/datastore/plugin_datastore_postgres.c204
1 files changed, 102 insertions, 102 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 0c51e8b7d..faf988517 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -78,7 +78,7 @@ init_connection (struct Plugin *plugin)
78 78
79 ret = 79 ret =
80 PQexec (plugin->dbh, 80 PQexec (plugin->dbh,
81 "CREATE TABLE gn090 (" 81 "CREATE TABLE gn090 ("
82 " repl INTEGER NOT NULL DEFAULT 0," 82 " repl INTEGER NOT NULL DEFAULT 0,"
83 " type INTEGER NOT NULL DEFAULT 0," 83 " type INTEGER NOT NULL DEFAULT 0,"
84 " prio INTEGER NOT NULL DEFAULT 0," 84 " prio INTEGER NOT NULL DEFAULT 0,"
@@ -87,7 +87,7 @@ init_connection (struct Plugin *plugin)
87 " rvalue BIGINT NOT NULL DEFAULT 0," 87 " rvalue BIGINT NOT NULL DEFAULT 0,"
88 " hash BYTEA NOT NULL DEFAULT ''," 88 " hash BYTEA NOT NULL DEFAULT '',"
89 " vhash BYTEA NOT NULL DEFAULT ''," 89 " vhash BYTEA NOT NULL DEFAULT '',"
90 " value BYTEA NOT NULL DEFAULT '')" 90 " value BYTEA NOT NULL DEFAULT '')"
91 "WITH OIDS"); 91 "WITH OIDS");
92 if ( (NULL == ret) || 92 if ( (NULL == ret) ||
93 ((PQresultStatus (ret) != PGRES_COMMAND_OK) && 93 ((PQresultStatus (ret) != PGRES_COMMAND_OK) &&
@@ -257,10 +257,10 @@ postgres_plugin_estimate_size (void *cls, unsigned long long *estimate)
257 "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0, 257 "SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0,
258 NULL, NULL, NULL, NULL, 1); 258 NULL, NULL, NULL, NULL, 1);
259 if (GNUNET_OK != 259 if (GNUNET_OK !=
260 GNUNET_POSTGRES_check_result (plugin->dbh, 260 GNUNET_POSTGRES_check_result (plugin->dbh,
261 ret, 261 ret,
262 PGRES_TUPLES_OK, 262 PGRES_TUPLES_OK,
263 "PQexecParams", 263 "PQexecParams",
264 "get_size")) 264 "get_size"))
265 { 265 {
266 *estimate = 0; 266 *estimate = 0;
@@ -302,15 +302,15 @@ postgres_plugin_estimate_size (void *cls, unsigned long long *estimate)
302 * @param cont_cls continuation closure 302 * @param cont_cls continuation closure
303 */ 303 */
304static void 304static void
305postgres_plugin_put (void *cls, 305postgres_plugin_put (void *cls,
306 const struct GNUNET_HashCode *key, 306 const struct GNUNET_HashCode *key,
307 uint32_t size, 307 uint32_t size,
308 const void *data, 308 const void *data,
309 enum GNUNET_BLOCK_Type type, 309 enum GNUNET_BLOCK_Type type,
310 uint32_t priority, 310 uint32_t priority,
311 uint32_t anonymity, 311 uint32_t anonymity,
312 uint32_t replication, 312 uint32_t replication,
313 struct GNUNET_TIME_Absolute expiration, 313 struct GNUNET_TIME_Absolute expiration,
314 PluginPutCont cont, 314 PluginPutCont cont,
315 void *cont_cls) 315 void *cont_cls)
316{ 316{
@@ -335,22 +335,22 @@ postgres_plugin_put (void *cls,
335 "put", 335 "put",
336 params); 336 params);
337 if (GNUNET_OK != 337 if (GNUNET_OK !=
338 GNUNET_POSTGRES_check_result (plugin->dbh, 338 GNUNET_POSTGRES_check_result (plugin->dbh,
339 ret, 339 ret,
340 PGRES_COMMAND_OK, 340 PGRES_COMMAND_OK,
341 "PQexecPrepared", "put")) 341 "PQexecPrepared", "put"))
342 { 342 {
343 cont (cont_cls, key, size, 343 cont (cont_cls, key, size,
344 GNUNET_SYSERR, 344 GNUNET_SYSERR,
345 _("Postgress exec failure")); 345 _("Postgress exec failure"));
346 return; 346 return;
347 } 347 }
348 PQclear (ret); 348 PQclear (ret);
349 plugin->env->duc (plugin->env->cls, 349 plugin->env->duc (plugin->env->cls,
350 size + GNUNET_DATASTORE_ENTRY_OVERHEAD); 350 size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
351 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
352 "datastore-postgres", 352 "datastore-postgres",
353 "Stored %u bytes in database\n", 353 "Stored %u bytes in database\n",
354 (unsigned int) size); 354 (unsigned int) size);
355 cont (cont_cls, key, size, GNUNET_OK, NULL); 355 cont (cont_cls, key, size, GNUNET_OK, NULL);
356} 356}
@@ -367,7 +367,7 @@ postgres_plugin_put (void *cls,
367 * @param line line number for error messages 367 * @param line line number for error messages
368 */ 368 */
369static void 369static void
370process_result (struct Plugin *plugin, 370process_result (struct Plugin *plugin,
371 PluginDatumProcessor proc, 371 PluginDatumProcessor proc,
372 void *proc_cls, 372 void *proc_cls,
373 PGresult * res, 373 PGresult * res,
@@ -394,9 +394,9 @@ process_result (struct Plugin *plugin,
394 }; 394 };
395 395
396 if (GNUNET_OK != 396 if (GNUNET_OK !=
397 GNUNET_POSTGRES_check_result_ (plugin->dbh, 397 GNUNET_POSTGRES_check_result_ (plugin->dbh,
398 res, 398 res,
399 PGRES_TUPLES_OK, 399 PGRES_TUPLES_OK,
400 "PQexecPrepared", 400 "PQexecPrepared",
401 "select", 401 "select",
402 filename, line)) 402 filename, line))
@@ -404,7 +404,7 @@ process_result (struct Plugin *plugin,
404 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
405 "datastore-postgres", 405 "datastore-postgres",
406 "Ending iteration (postgres error)\n"); 406 "Ending iteration (postgres error)\n");
407 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 407 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
408 GNUNET_TIME_UNIT_ZERO_ABS, 0); 408 GNUNET_TIME_UNIT_ZERO_ABS, 0);
409 return; 409 return;
410 } 410 }
@@ -412,15 +412,15 @@ process_result (struct Plugin *plugin,
412 if (0 == PQntuples (res)) 412 if (0 == PQntuples (res))
413 { 413 {
414 /* no result */ 414 /* no result */
415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
416 "datastore-postgres", 416 "datastore-postgres",
417 "Ending iteration (no more results)\n"); 417 "Ending iteration (no more results)\n");
418 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 418 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
419 GNUNET_TIME_UNIT_ZERO_ABS, 0); 419 GNUNET_TIME_UNIT_ZERO_ABS, 0);
420 PQclear (res); 420 PQclear (res);
421 return; 421 return;
422 } 422 }
423 if (1 != PQntuples (res)) 423 if (1 != PQntuples (res))
424 { 424 {
425 GNUNET_break (0); 425 GNUNET_break (0);
426 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 426 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
@@ -436,23 +436,23 @@ process_result (struct Plugin *plugin,
436 GNUNET_break (0); 436 GNUNET_break (0);
437 PQclear (res); 437 PQclear (res);
438 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh, 438 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
439 "delrow", 439 "delrow",
440 rowid); 440 rowid);
441 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 441 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
442 GNUNET_TIME_UNIT_ZERO_ABS, 0); 442 GNUNET_TIME_UNIT_ZERO_ABS, 0);
443 return; 443 return;
444 } 444 }
445 445
446 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 446 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
447 "datastore-postgres", 447 "datastore-postgres",
448 "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",
449 (unsigned int) size, 449 (unsigned int) size,
450 (unsigned int) utype); 450 (unsigned int) utype);
451 iret = proc (proc_cls, 451 iret = proc (proc_cls,
452 &key, 452 &key,
453 size, 453 size,
454 data, 454 data,
455 (enum GNUNET_BLOCK_Type) utype, 455 (enum GNUNET_BLOCK_Type) utype,
456 priority, 456 priority,
457 anonymity, 457 anonymity,
458 expiration_time, 458 expiration_time,
@@ -461,20 +461,20 @@ process_result (struct Plugin *plugin,
461 if (iret == GNUNET_NO) 461 if (iret == GNUNET_NO)
462 { 462 {
463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
464 "Processor asked for item %u to be removed.\n", 464 "Processor asked for item %u to be removed.\n",
465 (unsigned int) rowid); 465 (unsigned int) rowid);
466 if (GNUNET_OK == 466 if (GNUNET_OK ==
467 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh, 467 GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
468 "delrow", 468 "delrow",
469 rowid)) 469 rowid))
470 { 470 {
471 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
472 "datastore-postgres", 472 "datastore-postgres",
473 "Deleting %u bytes from database\n", 473 "Deleting %u bytes from database\n",
474 (unsigned int) size); 474 (unsigned int) size);
475 plugin->env->duc (plugin->env->cls, 475 plugin->env->duc (plugin->env->cls,
476 - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD)); 476 - (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 477 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
478 "datastore-postgres", 478 "datastore-postgres",
479 "Deleted %u bytes from database\n", 479 "Deleted %u bytes from database\n",
480 (unsigned int) size); 480 (unsigned int) size);
@@ -503,7 +503,7 @@ process_result (struct Plugin *plugin,
503 * @param proc_cls closure for iter 503 * @param proc_cls closure for iter
504 */ 504 */
505static void 505static void
506postgres_plugin_get_key (void *cls, 506postgres_plugin_get_key (void *cls,
507 uint64_t offset, 507 uint64_t offset,
508 const struct GNUNET_HashCode *key, 508 const struct GNUNET_HashCode *key,
509 const struct GNUNET_HashCode *vhash, 509 const struct GNUNET_HashCode *vhash,
@@ -521,7 +521,7 @@ postgres_plugin_get_key (void *cls,
521 { 521 {
522 if (NULL != vhash) 522 if (NULL != vhash)
523 { 523 {
524 struct GNUNET_PQ_QueryParam params[] = { 524 struct GNUNET_PQ_QueryParam params[] = {
525 GNUNET_PQ_query_param_auto_from_type (key), 525 GNUNET_PQ_query_param_auto_from_type (key),
526 GNUNET_PQ_query_param_auto_from_type (vhash), 526 GNUNET_PQ_query_param_auto_from_type (vhash),
527 GNUNET_PQ_query_param_uint32 (&utype), 527 GNUNET_PQ_query_param_uint32 (&utype),
@@ -533,7 +533,7 @@ postgres_plugin_get_key (void *cls,
533 } 533 }
534 else 534 else
535 { 535 {
536 struct GNUNET_PQ_QueryParam params[] = { 536 struct GNUNET_PQ_QueryParam params[] = {
537 GNUNET_PQ_query_param_auto_from_type (key), 537 GNUNET_PQ_query_param_auto_from_type (key),
538 GNUNET_PQ_query_param_uint32 (&utype), 538 GNUNET_PQ_query_param_uint32 (&utype),
539 GNUNET_PQ_query_param_end 539 GNUNET_PQ_query_param_end
@@ -547,7 +547,7 @@ postgres_plugin_get_key (void *cls,
547 { 547 {
548 if (NULL != vhash) 548 if (NULL != vhash)
549 { 549 {
550 struct GNUNET_PQ_QueryParam params[] = { 550 struct GNUNET_PQ_QueryParam params[] = {
551 GNUNET_PQ_query_param_auto_from_type (key), 551 GNUNET_PQ_query_param_auto_from_type (key),
552 GNUNET_PQ_query_param_auto_from_type (vhash), 552 GNUNET_PQ_query_param_auto_from_type (vhash),
553 GNUNET_PQ_query_param_end 553 GNUNET_PQ_query_param_end
@@ -558,7 +558,7 @@ postgres_plugin_get_key (void *cls,
558 } 558 }
559 else 559 else
560 { 560 {
561 struct GNUNET_PQ_QueryParam params[] = { 561 struct GNUNET_PQ_QueryParam params[] = {
562 GNUNET_PQ_query_param_auto_from_type (key), 562 GNUNET_PQ_query_param_auto_from_type (key),
563 GNUNET_PQ_query_param_end 563 GNUNET_PQ_query_param_end
564 }; 564 };
@@ -569,23 +569,23 @@ postgres_plugin_get_key (void *cls,
569 } 569 }
570 570
571 if (GNUNET_OK != 571 if (GNUNET_OK !=
572 GNUNET_POSTGRES_check_result (plugin->dbh, 572 GNUNET_POSTGRES_check_result (plugin->dbh,
573 ret, 573 ret,
574 PGRES_TUPLES_OK, 574 PGRES_TUPLES_OK,
575 "PQexecParams", 575 "PQexecParams",
576 "count")) 576 "count"))
577 { 577 {
578 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 578 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
579 GNUNET_TIME_UNIT_ZERO_ABS, 0); 579 GNUNET_TIME_UNIT_ZERO_ABS, 0);
580 return; 580 return;
581 } 581 }
582 if ( (PQntuples (ret) != 1) || 582 if ( (PQntuples (ret) != 1) ||
583 (PQnfields (ret) != 1) || 583 (PQnfields (ret) != 1) ||
584 (PQgetlength (ret, 0, 0) != sizeof (uint64_t))) 584 (PQgetlength (ret, 0, 0) != sizeof (uint64_t)))
585 { 585 {
586 GNUNET_break (0); 586 GNUNET_break (0);
587 PQclear (ret); 587 PQclear (ret);
588 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 588 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
589 GNUNET_TIME_UNIT_ZERO_ABS, 0); 589 GNUNET_TIME_UNIT_ZERO_ABS, 0);
590 return; 590 return;
591 } 591 }
@@ -593,7 +593,7 @@ postgres_plugin_get_key (void *cls,
593 PQclear (ret); 593 PQclear (ret);
594 if (0 == total) 594 if (0 == total)
595 { 595 {
596 proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 596 proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
597 GNUNET_TIME_UNIT_ZERO_ABS, 0); 597 GNUNET_TIME_UNIT_ZERO_ABS, 0);
598 return; 598 return;
599 } 599 }
@@ -603,9 +603,9 @@ postgres_plugin_get_key (void *cls,
603 { 603 {
604 if (NULL != vhash) 604 if (NULL != vhash)
605 { 605 {
606 struct GNUNET_PQ_QueryParam params[] = { 606 struct GNUNET_PQ_QueryParam params[] = {
607 GNUNET_PQ_query_param_auto_from_type (key), 607 GNUNET_PQ_query_param_auto_from_type (key),
608 GNUNET_PQ_query_param_auto_from_type (&vhash), 608 GNUNET_PQ_query_param_auto_from_type (vhash),
609 GNUNET_PQ_query_param_uint32 (&utype), 609 GNUNET_PQ_query_param_uint32 (&utype),
610 GNUNET_PQ_query_param_uint64 (&limit_off), 610 GNUNET_PQ_query_param_uint64 (&limit_off),
611 GNUNET_PQ_query_param_end 611 GNUNET_PQ_query_param_end
@@ -616,7 +616,7 @@ postgres_plugin_get_key (void *cls,
616 } 616 }
617 else 617 else
618 { 618 {
619 struct GNUNET_PQ_QueryParam params[] = { 619 struct GNUNET_PQ_QueryParam params[] = {
620 GNUNET_PQ_query_param_auto_from_type (key), 620 GNUNET_PQ_query_param_auto_from_type (key),
621 GNUNET_PQ_query_param_uint32 (&utype), 621 GNUNET_PQ_query_param_uint32 (&utype),
622 GNUNET_PQ_query_param_uint64 (&limit_off), 622 GNUNET_PQ_query_param_uint64 (&limit_off),
@@ -631,9 +631,9 @@ postgres_plugin_get_key (void *cls,
631 { 631 {
632 if (NULL != vhash) 632 if (NULL != vhash)
633 { 633 {
634 struct GNUNET_PQ_QueryParam params[] = { 634 struct GNUNET_PQ_QueryParam params[] = {
635 GNUNET_PQ_query_param_auto_from_type (key), 635 GNUNET_PQ_query_param_auto_from_type (key),
636 GNUNET_PQ_query_param_auto_from_type (&vhash), 636 GNUNET_PQ_query_param_auto_from_type (vhash),
637 GNUNET_PQ_query_param_uint64 (&limit_off), 637 GNUNET_PQ_query_param_uint64 (&limit_off),
638 GNUNET_PQ_query_param_end 638 GNUNET_PQ_query_param_end
639 }; 639 };
@@ -643,7 +643,7 @@ postgres_plugin_get_key (void *cls,
643 } 643 }
644 else 644 else
645 { 645 {
646 struct GNUNET_PQ_QueryParam params[] = { 646 struct GNUNET_PQ_QueryParam params[] = {
647 GNUNET_PQ_query_param_auto_from_type (key), 647 GNUNET_PQ_query_param_auto_from_type (key),
648 GNUNET_PQ_query_param_uint64 (&limit_off), 648 GNUNET_PQ_query_param_uint64 (&limit_off),
649 GNUNET_PQ_query_param_end 649 GNUNET_PQ_query_param_end
@@ -655,8 +655,8 @@ postgres_plugin_get_key (void *cls,
655 } 655 }
656 process_result (plugin, 656 process_result (plugin,
657 proc, 657 proc,
658 proc_cls, 658 proc_cls,
659 ret, 659 ret,
660 __FILE__, __LINE__); 660 __FILE__, __LINE__);
661} 661}
662 662
@@ -675,15 +675,15 @@ postgres_plugin_get_key (void *cls,
675 * @param proc_cls closure for @a proc 675 * @param proc_cls closure for @a proc
676 */ 676 */
677static void 677static void
678postgres_plugin_get_zero_anonymity (void *cls, 678postgres_plugin_get_zero_anonymity (void *cls,
679 uint64_t offset, 679 uint64_t offset,
680 enum GNUNET_BLOCK_Type type, 680 enum GNUNET_BLOCK_Type type,
681 PluginDatumProcessor proc, 681 PluginDatumProcessor proc,
682 void *proc_cls) 682 void *proc_cls)
683{ 683{
684 struct Plugin *plugin = cls; 684 struct Plugin *plugin = cls;
685 uint32_t utype = type; 685 uint32_t utype = type;
686 struct GNUNET_PQ_QueryParam params[] = { 686 struct GNUNET_PQ_QueryParam params[] = {
687 GNUNET_PQ_query_param_uint32 (&utype), 687 GNUNET_PQ_query_param_uint32 (&utype),
688 GNUNET_PQ_query_param_uint64 (&offset), 688 GNUNET_PQ_query_param_uint64 (&offset),
689 GNUNET_PQ_query_param_end 689 GNUNET_PQ_query_param_end
@@ -694,7 +694,7 @@ postgres_plugin_get_zero_anonymity (void *cls,
694 "select_non_anonymous", 694 "select_non_anonymous",
695 params); 695 params);
696 696
697 process_result (plugin, 697 process_result (plugin,
698 proc, proc_cls, 698 proc, proc_cls,
699 ret, 699 ret,
700 __FILE__, __LINE__); 700 __FILE__, __LINE__);
@@ -739,7 +739,7 @@ struct ReplCtx
739 * @param expiration expiration time for the content 739 * @param expiration expiration time for the content
740 * @param uid unique identifier for the datum; 740 * @param uid unique identifier for the datum;
741 * maybe 0 if no unique identifier is available 741 * maybe 0 if no unique identifier is available
742 * @return #GNUNET_SYSERR to abort the iteration, 742 * @return #GNUNET_SYSERR to abort the iteration,
743 * #GNUNET_OK to continue 743 * #GNUNET_OK to continue
744 * (continue on call to "next", of course), 744 * (continue on call to "next", of course),
745 * #GNUNET_NO to delete the item and continue (if supported) 745 * #GNUNET_NO to delete the item and continue (if supported)
@@ -749,9 +749,9 @@ repl_proc (void *cls,
749 const struct GNUNET_HashCode *key, 749 const struct GNUNET_HashCode *key,
750 uint32_t size, 750 uint32_t size,
751 const void *data, 751 const void *data,
752 enum GNUNET_BLOCK_Type type, 752 enum GNUNET_BLOCK_Type type,
753 uint32_t priority, 753 uint32_t priority,
754 uint32_t anonymity, 754 uint32_t anonymity,
755 struct GNUNET_TIME_Absolute expiration, 755 struct GNUNET_TIME_Absolute expiration,
756 uint64_t uid) 756 uint64_t uid)
757{ 757{
@@ -759,17 +759,17 @@ repl_proc (void *cls,
759 struct Plugin *plugin = rc->plugin; 759 struct Plugin *plugin = rc->plugin;
760 int ret; 760 int ret;
761 uint32_t oid = (uint32_t) uid; 761 uint32_t oid = (uint32_t) uid;
762 struct GNUNET_PQ_QueryParam params[] = { 762 struct GNUNET_PQ_QueryParam params[] = {
763 GNUNET_PQ_query_param_uint32 (&oid), 763 GNUNET_PQ_query_param_uint32 (&oid),
764 GNUNET_PQ_query_param_end 764 GNUNET_PQ_query_param_end
765 }; 765 };
766 PGresult *qret; 766 PGresult *qret;
767 767
768 ret = rc->proc (rc->proc_cls, 768 ret = rc->proc (rc->proc_cls,
769 key, 769 key,
770 size, data, 770 size, data,
771 type, 771 type,
772 priority, 772 priority,
773 anonymity, 773 anonymity,
774 expiration, uid); 774 expiration, uid);
775 if (NULL == key) 775 if (NULL == key)
@@ -778,9 +778,9 @@ repl_proc (void *cls,
778 "decrepl", 778 "decrepl",
779 params); 779 params);
780 if (GNUNET_OK != 780 if (GNUNET_OK !=
781 GNUNET_POSTGRES_check_result (plugin->dbh, 781 GNUNET_POSTGRES_check_result (plugin->dbh,
782 qret, 782 qret,
783 PGRES_COMMAND_OK, 783 PGRES_COMMAND_OK,
784 "PQexecPrepared", 784 "PQexecPrepared",
785 "decrepl")) 785 "decrepl"))
786 return GNUNET_SYSERR; 786 return GNUNET_SYSERR;
@@ -801,7 +801,7 @@ repl_proc (void *cls,
801 * @param proc_cls closure for @a proc 801 * @param proc_cls closure for @a proc
802 */ 802 */
803static void 803static void
804postgres_plugin_get_replication (void *cls, 804postgres_plugin_get_replication (void *cls,
805 PluginDatumProcessor proc, 805 PluginDatumProcessor proc,
806 void *proc_cls) 806 void *proc_cls)
807{ 807{
@@ -812,13 +812,13 @@ postgres_plugin_get_replication (void *cls,
812 rc.plugin = plugin; 812 rc.plugin = plugin;
813 rc.proc = proc; 813 rc.proc = proc;
814 rc.proc_cls = proc_cls; 814 rc.proc_cls = proc_cls;
815 ret = PQexecPrepared (plugin->dbh, 815 ret = PQexecPrepared (plugin->dbh,
816 "select_replication_order", 0, NULL, NULL, 816 "select_replication_order", 0, NULL, NULL,
817 NULL, 1); 817 NULL, 1);
818 process_result (plugin, 818 process_result (plugin,
819 &repl_proc, 819 &repl_proc,
820 &rc, 820 &rc,
821 ret, 821 ret,
822 __FILE__, __LINE__); 822 __FILE__, __LINE__);
823} 823}
824 824
@@ -832,13 +832,13 @@ postgres_plugin_get_replication (void *cls,
832 * @param proc_cls closure for @a proc 832 * @param proc_cls closure for @a proc
833 */ 833 */
834static void 834static void
835postgres_plugin_get_expiration (void *cls, 835postgres_plugin_get_expiration (void *cls,
836 PluginDatumProcessor proc, 836 PluginDatumProcessor proc,
837 void *proc_cls) 837 void *proc_cls)
838{ 838{
839 struct Plugin *plugin = cls; 839 struct Plugin *plugin = cls;
840 struct GNUNET_TIME_Absolute now; 840 struct GNUNET_TIME_Absolute now;
841 struct GNUNET_PQ_QueryParam params[] = { 841 struct GNUNET_PQ_QueryParam params[] = {
842 GNUNET_PQ_query_param_absolute_time (&now), 842 GNUNET_PQ_query_param_absolute_time (&now),
843 GNUNET_PQ_query_param_end 843 GNUNET_PQ_query_param_end
844 }; 844 };
@@ -879,8 +879,8 @@ postgres_plugin_get_expiration (void *cls,
879 * @param cons_cls continuation closure 879 * @param cons_cls continuation closure
880 */ 880 */
881static void 881static void
882postgres_plugin_update (void *cls, 882postgres_plugin_update (void *cls,
883 uint64_t uid, 883 uint64_t uid,
884 int delta, 884 int delta,
885 struct GNUNET_TIME_Absolute expire, 885 struct GNUNET_TIME_Absolute expire,
886 PluginUpdateCont cont, 886 PluginUpdateCont cont,
@@ -889,7 +889,7 @@ postgres_plugin_update (void *cls,
889 struct Plugin *plugin = cls; 889 struct Plugin *plugin = cls;
890 uint32_t idelta = delta; 890 uint32_t idelta = delta;
891 uint32_t oid = (uint32_t) uid; 891 uint32_t oid = (uint32_t) uid;
892 struct GNUNET_PQ_QueryParam params[] = { 892 struct GNUNET_PQ_QueryParam params[] = {
893 GNUNET_PQ_query_param_uint32 (&idelta), 893 GNUNET_PQ_query_param_uint32 (&idelta),
894 GNUNET_PQ_query_param_absolute_time (&expire), 894 GNUNET_PQ_query_param_absolute_time (&expire),
895 GNUNET_PQ_query_param_uint32 (&oid), 895 GNUNET_PQ_query_param_uint32 (&oid),
@@ -902,24 +902,23 @@ postgres_plugin_update (void *cls,
902 params); 902 params);
903 if (GNUNET_OK != 903 if (GNUNET_OK !=
904 GNUNET_POSTGRES_check_result (plugin->dbh, 904 GNUNET_POSTGRES_check_result (plugin->dbh,
905 ret, 905 ret,
906 PGRES_COMMAND_OK, 906 PGRES_COMMAND_OK,
907 "PQexecPrepared", 907 "PQexecPrepared",
908 "update")) 908 "update"))
909 { 909 {
910 cont (cont_cls, 910 cont (cont_cls,
911 GNUNET_SYSERR, 911 GNUNET_SYSERR,
912 NULL); 912 NULL);
913 return; 913 return;
914 } 914 }
915 PQclear (ret); 915 PQclear (ret);
916 cont (cont_cls, 916 cont (cont_cls,
917 GNUNET_OK, 917 GNUNET_OK,
918 NULL); 918 NULL);
919} 919}
920 920
921 921
922
923/** 922/**
924 * Get all of the keys in the datastore. 923 * Get all of the keys in the datastore.
925 * 924 *
@@ -938,17 +937,17 @@ postgres_plugin_get_keys (void *cls,
938 struct GNUNET_HashCode key; 937 struct GNUNET_HashCode key;
939 PGresult * res; 938 PGresult * res;
940 939
941 res = PQexecPrepared (plugin->dbh, 940 res = PQexecPrepared (plugin->dbh,
942 "get_keys", 941 "get_keys",
943 0, NULL, NULL, NULL, 1); 942 0, NULL, NULL, NULL, 1);
944 ret = PQntuples (res); 943 ret = PQntuples (res);
945 for (i=0;i<ret;i++) 944 for (i=0;i<ret;i++)
946 { 945 {
947 if (sizeof (struct GNUNET_HashCode) != 946 if (sizeof (struct GNUNET_HashCode) !=
948 PQgetlength (res, i, 0)) 947 PQgetlength (res, i, 0))
949 { 948 {
950 memcpy (&key, 949 memcpy (&key,
951 PQgetvalue (res, i, 0), 950 PQgetvalue (res, i, 0),
952 sizeof (struct GNUNET_HashCode)); 951 sizeof (struct GNUNET_HashCode));
953 proc (proc_cls, &key, 1); 952 proc (proc_cls, &key, 1);
954 } 953 }
@@ -958,7 +957,6 @@ postgres_plugin_get_keys (void *cls,
958} 957}
959 958
960 959
961
962/** 960/**
963 * Drop database. 961 * Drop database.
964 * 962 *
@@ -969,10 +967,11 @@ postgres_plugin_drop (void *cls)
969{ 967{
970 struct Plugin *plugin = cls; 968 struct Plugin *plugin = cls;
971 969
972 if (GNUNET_OK != 970 if (GNUNET_OK !=
973 GNUNET_POSTGRES_exec (plugin->dbh, "DROP TABLE gn090")) 971 GNUNET_POSTGRES_exec (plugin->dbh,
974 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, 972 "DROP TABLE gn090"))
975 "postgres", 973 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
974 "postgres",
976 _("Failed to drop table from database.\n")); 975 _("Failed to drop table from database.\n"));
977} 976}
978 977
@@ -1008,7 +1007,8 @@ libgnunet_plugin_datastore_postgres_init (void *cls)
1008 api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity; 1007 api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
1009 api->get_keys = &postgres_plugin_get_keys; 1008 api->get_keys = &postgres_plugin_get_keys;
1010 api->drop = &postgres_plugin_drop; 1009 api->drop = &postgres_plugin_drop;
1011 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres", 1010 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
1011 "datastore-postgres",
1012 _("Postgres database running\n")); 1012 _("Postgres database running\n"));
1013 return api; 1013 return api;
1014} 1014}