diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-02-02 17:15:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-02-02 17:15:37 +0000 |
commit | 779ddb717e6fa5f1fc1a3bb38b014f3cca8af800 (patch) | |
tree | 24947ab76e1bb7a262aecc6bc78733a748de88f0 /src/datastore | |
parent | 74737f023eaabc9a70e748daebc22d5104cee1f1 (diff) | |
download | gnunet-779ddb717e6fa5f1fc1a3bb38b014f3cca8af800.tar.gz gnunet-779ddb717e6fa5f1fc1a3bb38b014f3cca8af800.zip |
-indentation, doxygen
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 129 |
1 files changed, 75 insertions, 54 deletions
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index f2e0454f9..253b69fe7 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -135,7 +135,9 @@ struct Plugin | |||
135 | * @return 0 on success | 135 | * @return 0 on success |
136 | */ | 136 | */ |
137 | static int | 137 | static int |
138 | sq_prepare (sqlite3 * dbh, const char *zSql, sqlite3_stmt ** ppStmt) | 138 | sq_prepare (sqlite3 *dbh, |
139 | const char *zSql, | ||
140 | sqlite3_stmt **ppStmt) | ||
139 | { | 141 | { |
140 | char *dummy; | 142 | char *dummy; |
141 | int result; | 143 | int result; |
@@ -211,7 +213,7 @@ create_indices (sqlite3 * dbh) | |||
211 | * | 213 | * |
212 | * @param cfg our configuration | 214 | * @param cfg our configuration |
213 | * @param plugin the plugin context (state for this module) | 215 | * @param plugin the plugin context (state for this module) |
214 | * @return GNUNET_OK on success | 216 | * @return #GNUNET_OK on success |
215 | */ | 217 | */ |
216 | static int | 218 | static int |
217 | database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 219 | database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -365,6 +367,7 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
365 | /** | 367 | /** |
366 | * Shutdown database connection and associate data | 368 | * Shutdown database connection and associate data |
367 | * structures. | 369 | * structures. |
370 | * | ||
368 | * @param plugin the plugin context (state for this module) | 371 | * @param plugin the plugin context (state for this module) |
369 | */ | 372 | */ |
370 | static void | 373 | static void |
@@ -428,7 +431,8 @@ database_shutdown (struct Plugin *plugin) | |||
428 | * @param rid the ID of the row to delete | 431 | * @param rid the ID of the row to delete |
429 | */ | 432 | */ |
430 | static int | 433 | static int |
431 | delete_by_rowid (struct Plugin *plugin, unsigned long long rid) | 434 | delete_by_rowid (struct Plugin *plugin, |
435 | unsigned long long rid) | ||
432 | { | 436 | { |
433 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) | 437 | if (SQLITE_OK != sqlite3_bind_int64 (plugin->delRow, 1, rid)) |
434 | { | 438 | { |
@@ -462,7 +466,7 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid) | |||
462 | * | 466 | * |
463 | * @param cls closure | 467 | * @param cls closure |
464 | * @param key key for the item | 468 | * @param key key for the item |
465 | * @param size number of bytes in data | 469 | * @param size number of bytes in @a data |
466 | * @param data content stored | 470 | * @param data content stored |
467 | * @param type type of the content | 471 | * @param type type of the content |
468 | * @param priority priority of the content | 472 | * @param priority priority of the content |
@@ -473,10 +477,16 @@ delete_by_rowid (struct Plugin *plugin, unsigned long long rid) | |||
473 | * @return #GNUNET_OK on success | 477 | * @return #GNUNET_OK on success |
474 | */ | 478 | */ |
475 | static int | 479 | static int |
476 | sqlite_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | 480 | sqlite_plugin_put (void *cls, |
477 | const void *data, enum GNUNET_BLOCK_Type type, | 481 | const struct GNUNET_HashCode *key, |
478 | uint32_t priority, uint32_t anonymity, uint32_t replication, | 482 | uint32_t size, |
479 | struct GNUNET_TIME_Absolute expiration, char **msg) | 483 | const void *data, |
484 | enum GNUNET_BLOCK_Type type, | ||
485 | uint32_t priority, | ||
486 | uint32_t anonymity, | ||
487 | uint32_t replication, | ||
488 | struct GNUNET_TIME_Absolute expiration, | ||
489 | char **msg) | ||
480 | { | 490 | { |
481 | struct Plugin *plugin = cls; | 491 | struct Plugin *plugin = cls; |
482 | int n; | 492 | int n; |
@@ -574,11 +584,14 @@ sqlite_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
574 | * MAX of any existing expiration time and | 584 | * MAX of any existing expiration time and |
575 | * this value | 585 | * this value |
576 | * @param msg set to an error message | 586 | * @param msg set to an error message |
577 | * @return GNUNET_OK on success | 587 | * @return #GNUNET_OK on success |
578 | */ | 588 | */ |
579 | static int | 589 | static int |
580 | sqlite_plugin_update (void *cls, uint64_t uid, int delta, | 590 | sqlite_plugin_update (void *cls, |
581 | struct GNUNET_TIME_Absolute expire, char **msg) | 591 | uint64_t uid, |
592 | int delta, | ||
593 | struct GNUNET_TIME_Absolute expire, | ||
594 | char **msg) | ||
582 | { | 595 | { |
583 | struct Plugin *plugin = cls; | 596 | struct Plugin *plugin = cls; |
584 | int n; | 597 | int n; |
@@ -624,11 +637,13 @@ sqlite_plugin_update (void *cls, uint64_t uid, int delta, | |||
624 | * @param plugin the plugin | 637 | * @param plugin the plugin |
625 | * @param stmt the statement | 638 | * @param stmt the statement |
626 | * @param proc processor to call | 639 | * @param proc processor to call |
627 | * @param proc_cls closure for 'proc' | 640 | * @param proc_cls closure for @a proc |
628 | */ | 641 | */ |
629 | static void | 642 | static void |
630 | execute_get (struct Plugin *plugin, sqlite3_stmt * stmt, | 643 | execute_get (struct Plugin *plugin, |
631 | PluginDatumProcessor proc, void *proc_cls) | 644 | sqlite3_stmt *stmt, |
645 | PluginDatumProcessor proc, | ||
646 | void *proc_cls) | ||
632 | { | 647 | { |
633 | int n; | 648 | int n; |
634 | struct GNUNET_TIME_Absolute expiration; | 649 | struct GNUNET_TIME_Absolute expiration; |
@@ -645,8 +660,7 @@ execute_get (struct Plugin *plugin, sqlite3_stmt * stmt, | |||
645 | if (sqlite3_column_bytes (stmt, 4) != sizeof (struct GNUNET_HashCode)) | 660 | if (sqlite3_column_bytes (stmt, 4) != sizeof (struct GNUNET_HashCode)) |
646 | { | 661 | { |
647 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", | 662 | GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", |
648 | _ | 663 | _("Invalid data in database. Trying to fix (by deletion).\n")); |
649 | ("Invalid data in database. Trying to fix (by deletion).\n")); | ||
650 | if (SQLITE_OK != sqlite3_reset (stmt)) | 664 | if (SQLITE_OK != sqlite3_reset (stmt)) |
651 | LOG_SQLITE (plugin, NULL, | 665 | LOG_SQLITE (plugin, NULL, |
652 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 666 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
@@ -703,7 +717,6 @@ execute_get (struct Plugin *plugin, sqlite3_stmt * stmt, | |||
703 | } | 717 | } |
704 | 718 | ||
705 | 719 | ||
706 | |||
707 | /** | 720 | /** |
708 | * Select a subset of the items in the datastore and call | 721 | * Select a subset of the items in the datastore and call |
709 | * the given processor for the item. | 722 | * the given processor for the item. |
@@ -715,7 +728,7 @@ execute_get (struct Plugin *plugin, sqlite3_stmt * stmt, | |||
715 | * Use 0 for any type. | 728 | * Use 0 for any type. |
716 | * @param proc function to call on each matching value; | 729 | * @param proc function to call on each matching value; |
717 | * will be called once with a NULL value at the end | 730 | * will be called once with a NULL value at the end |
718 | * @param proc_cls closure for proc | 731 | * @param proc_cls closure for @a proc |
719 | */ | 732 | */ |
720 | static void | 733 | static void |
721 | sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, | 734 | sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, |
@@ -743,7 +756,6 @@ sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, | |||
743 | } | 756 | } |
744 | 757 | ||
745 | 758 | ||
746 | |||
747 | /** | 759 | /** |
748 | * Get results for a particular key in the datastore. | 760 | * Get results for a particular key in the datastore. |
749 | * | 761 | * |
@@ -759,12 +771,15 @@ sqlite_plugin_get_zero_anonymity (void *cls, uint64_t offset, | |||
759 | * Use 0 for any type. | 771 | * Use 0 for any type. |
760 | * @param proc function to call on each matching value; | 772 | * @param proc function to call on each matching value; |
761 | * will be called once with a NULL value at the end | 773 | * will be called once with a NULL value at the end |
762 | * @param proc_cls closure for proc | 774 | * @param proc_cls closure for @a proc |
763 | */ | 775 | */ |
764 | static void | 776 | static void |
765 | sqlite_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode * key, | 777 | sqlite_plugin_get_key (void *cls, |
766 | const struct GNUNET_HashCode * vhash, | 778 | uint64_t offset, |
767 | enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, | 779 | const struct GNUNET_HashCode *key, |
780 | const struct GNUNET_HashCode *vhash, | ||
781 | enum GNUNET_BLOCK_Type type, | ||
782 | PluginDatumProcessor proc, | ||
768 | void *proc_cls) | 783 | void *proc_cls) |
769 | { | 784 | { |
770 | struct Plugin *plugin = cls; | 785 | struct Plugin *plugin = cls; |
@@ -838,20 +853,21 @@ sqlite_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode | |||
838 | return; | 853 | return; |
839 | } | 854 | } |
840 | sqoff = 1; | 855 | sqoff = 1; |
841 | ret = | 856 | ret = sqlite3_bind_blob (stmt, sqoff++, key, |
842 | sqlite3_bind_blob (stmt, sqoff++, key, sizeof (struct GNUNET_HashCode), | 857 | sizeof (struct GNUNET_HashCode), |
843 | SQLITE_TRANSIENT); | ||
844 | if ((vhash != NULL) && (ret == SQLITE_OK)) | ||
845 | ret = | ||
846 | sqlite3_bind_blob (stmt, sqoff++, vhash, sizeof (struct GNUNET_HashCode), | ||
847 | SQLITE_TRANSIENT); | 858 | SQLITE_TRANSIENT); |
859 | if ((vhash != NULL) && (ret == SQLITE_OK)) | ||
860 | ret = sqlite3_bind_blob (stmt, sqoff++, vhash, | ||
861 | sizeof (struct GNUNET_HashCode), | ||
862 | SQLITE_TRANSIENT); | ||
848 | if ((type != 0) && (ret == SQLITE_OK)) | 863 | if ((type != 0) && (ret == SQLITE_OK)) |
849 | ret = sqlite3_bind_int (stmt, sqoff++, type); | 864 | ret = sqlite3_bind_int (stmt, sqoff++, type); |
850 | if (ret == SQLITE_OK) | 865 | if (ret == SQLITE_OK) |
851 | ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off); | 866 | ret = sqlite3_bind_int64 (stmt, sqoff++, limit_off); |
852 | if (ret != SQLITE_OK) | 867 | if (ret != SQLITE_OK) |
853 | { | 868 | { |
854 | LOG_SQLITE (plugin, NULL, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 869 | LOG_SQLITE (plugin, NULL, |
870 | GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
855 | "sqlite_bind"); | 871 | "sqlite_bind"); |
856 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 872 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
857 | return; | 873 | return; |
@@ -861,9 +877,8 @@ sqlite_plugin_get_key (void *cls, uint64_t offset, const struct GNUNET_HashCode | |||
861 | } | 877 | } |
862 | 878 | ||
863 | 879 | ||
864 | |||
865 | /** | 880 | /** |
866 | * Context for 'repl_proc' function. | 881 | * Context for #repl_proc() function. |
867 | */ | 882 | */ |
868 | struct ReplCtx | 883 | struct ReplCtx |
869 | { | 884 | { |
@@ -874,7 +889,7 @@ struct ReplCtx | |||
874 | PluginDatumProcessor proc; | 889 | PluginDatumProcessor proc; |
875 | 890 | ||
876 | /** | 891 | /** |
877 | * Closure for proc. | 892 | * Closure for @e proc. |
878 | */ | 893 | */ |
879 | void *proc_cls; | 894 | void *proc_cls; |
880 | 895 | ||
@@ -891,13 +906,13 @@ struct ReplCtx | |||
891 | 906 | ||
892 | 907 | ||
893 | /** | 908 | /** |
894 | * Wrapper for the processor for 'sqlite_plugin_replication_get'. | 909 | * Wrapper for the processor for #sqlite_plugin_replication_get(). |
895 | * Decrements the replication counter and calls the original | 910 | * Decrements the replication counter and calls the original |
896 | * processor. | 911 | * processor. |
897 | * | 912 | * |
898 | * @param cls closure | 913 | * @param cls closure |
899 | * @param key key for the content | 914 | * @param key key for the content |
900 | * @param size number of bytes in data | 915 | * @param size number of bytes in @a data |
901 | * @param data content stored | 916 | * @param data content stored |
902 | * @param type type of the content | 917 | * @param type type of the content |
903 | * @param priority priority of the content | 918 | * @param priority priority of the content |
@@ -905,23 +920,31 @@ struct ReplCtx | |||
905 | * @param expiration expiration time for the content | 920 | * @param expiration expiration time for the content |
906 | * @param uid unique identifier for the datum; | 921 | * @param uid unique identifier for the datum; |
907 | * maybe 0 if no unique identifier is available | 922 | * maybe 0 if no unique identifier is available |
908 | * | 923 | * @return #GNUNET_OK for normal return, |
909 | * @return GNUNET_OK for normal return, | 924 | * #GNUNET_NO to delete the item |
910 | * GNUNET_NO to delete the item | ||
911 | */ | 925 | */ |
912 | static int | 926 | static int |
913 | repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | 927 | repl_proc (void *cls, |
914 | const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, | 928 | const struct GNUNET_HashCode *key, |
915 | uint32_t anonymity, struct GNUNET_TIME_Absolute expiration, | 929 | uint32_t size, |
930 | const void *data, | ||
931 | enum GNUNET_BLOCK_Type type, | ||
932 | uint32_t priority, | ||
933 | uint32_t anonymity, | ||
934 | struct GNUNET_TIME_Absolute expiration, | ||
916 | uint64_t uid) | 935 | uint64_t uid) |
917 | { | 936 | { |
918 | struct ReplCtx *rc = cls; | 937 | struct ReplCtx *rc = cls; |
919 | int ret; | 938 | int ret; |
920 | 939 | ||
921 | ret = | 940 | ret = rc->proc (rc->proc_cls, |
922 | rc->proc (rc->proc_cls, key, size, data, type, priority, anonymity, | 941 | key, |
923 | expiration, uid); | 942 | size, data, |
924 | if (key != NULL) | 943 | type, |
944 | priority, | ||
945 | anonymity, | ||
946 | expiration, uid); | ||
947 | if (NULL != key) | ||
925 | { | 948 | { |
926 | rc->uid = uid; | 949 | rc->uid = uid; |
927 | rc->have_uid = GNUNET_YES; | 950 | rc->have_uid = GNUNET_YES; |
@@ -934,11 +957,11 @@ repl_proc (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | |||
934 | * Get a random item for replication. Returns a single random item | 957 | * Get a random item for replication. Returns a single random item |
935 | * from those with the highest replication counters. The item's | 958 | * from those with the highest replication counters. The item's |
936 | * replication counter is decremented by one IF it was positive before. | 959 | * replication counter is decremented by one IF it was positive before. |
937 | * Call 'proc' with all values ZERO or NULL if the datastore is empty. | 960 | * Call @a proc with all values ZERO or NULL if the datastore is empty. |
938 | * | 961 | * |
939 | * @param cls closure | 962 | * @param cls closure |
940 | * @param proc function to call the value (once only). | 963 | * @param proc function to call the value (once only). |
941 | * @param proc_cls closure for proc | 964 | * @param proc_cls closure for @a proc |
942 | */ | 965 | */ |
943 | static void | 966 | static void |
944 | sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc, | 967 | sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc, |
@@ -1020,14 +1043,13 @@ sqlite_plugin_get_replication (void *cls, PluginDatumProcessor proc, | |||
1020 | } | 1043 | } |
1021 | 1044 | ||
1022 | 1045 | ||
1023 | |||
1024 | /** | 1046 | /** |
1025 | * Get a random item that has expired or has low priority. | 1047 | * Get a random item that has expired or has low priority. |
1026 | * Call 'proc' with all values ZERO or NULL if the datastore is empty. | 1048 | * Call @a proc with all values ZERO or NULL if the datastore is empty. |
1027 | * | 1049 | * |
1028 | * @param cls closure | 1050 | * @param cls closure |
1029 | * @param proc function to call the value (once only). | 1051 | * @param proc function to call the value (once only). |
1030 | * @param proc_cls closure for proc | 1052 | * @param proc_cls closure for @a proc |
1031 | */ | 1053 | */ |
1032 | static void | 1054 | static void |
1033 | sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | 1055 | sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, |
@@ -1056,13 +1078,12 @@ sqlite_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
1056 | } | 1078 | } |
1057 | 1079 | ||
1058 | 1080 | ||
1059 | |||
1060 | /** | 1081 | /** |
1061 | * Get all of the keys in the datastore. | 1082 | * Get all of the keys in the datastore. |
1062 | * | 1083 | * |
1063 | * @param cls closure | 1084 | * @param cls closure |
1064 | * @param proc function to call on each key | 1085 | * @param proc function to call on each key |
1065 | * @param proc_cls closure for proc | 1086 | * @param proc_cls closure for @a proc |
1066 | */ | 1087 | */ |
1067 | static void | 1088 | static void |
1068 | sqlite_plugin_get_keys (void *cls, | 1089 | sqlite_plugin_get_keys (void *cls, |
@@ -1113,7 +1134,7 @@ sqlite_plugin_drop (void *cls) | |||
1113 | * Get an estimate of how much space the database is | 1134 | * Get an estimate of how much space the database is |
1114 | * currently using. | 1135 | * currently using. |
1115 | * | 1136 | * |
1116 | * @param cls the 'struct Plugin' | 1137 | * @param cls the `struct Plugin` |
1117 | * @return the size of the database on disk (estimate) | 1138 | * @return the size of the database on disk (estimate) |
1118 | */ | 1139 | */ |
1119 | static unsigned long long | 1140 | static unsigned long long |
@@ -1160,7 +1181,7 @@ sqlite_plugin_estimate_size (void *cls) | |||
1160 | /** | 1181 | /** |
1161 | * Entry point for the plugin. | 1182 | * Entry point for the plugin. |
1162 | * | 1183 | * |
1163 | * @param cls the "struct GNUNET_DATASTORE_PluginEnvironment*" | 1184 | * @param cls the `struct GNUNET_DATASTORE_PluginEnvironment *` |
1164 | * @return NULL on error, othrewise the plugin context | 1185 | * @return NULL on error, othrewise the plugin context |
1165 | */ | 1186 | */ |
1166 | void * | 1187 | void * |