diff options
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index b3a8f59ea..92e3a8d8a 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -91,7 +91,7 @@ create_indices (PGconn * dbh) | |||
91 | GNUNET_POSTGRES_exec (dbh, "CREATE INDEX ir_name_rv ON ns091records (record_name_hash,rvalue)")) || | 91 | GNUNET_POSTGRES_exec (dbh, "CREATE INDEX ir_name_rv ON ns091records (record_name_hash,rvalue)")) || |
92 | (GNUNET_OK != | 92 | (GNUNET_OK != |
93 | GNUNET_POSTGRES_exec (dbh, "CREATE INDEX ir_rv ON ns091records (rvalue)")) ) | 93 | GNUNET_POSTGRES_exec (dbh, "CREATE INDEX ir_rv ON ns091records (rvalue)")) ) |
94 | LOG (GNUNET_ERROR_TYPE_ERROR, | 94 | LOG (GNUNET_ERROR_TYPE_ERROR, |
95 | _("Failed to create indices\n")); | 95 | _("Failed to create indices\n")); |
96 | } | 96 | } |
97 | 97 | ||
@@ -113,7 +113,7 @@ database_setup (struct Plugin *plugin) | |||
113 | "namestore-postgres"); | 113 | "namestore-postgres"); |
114 | if (NULL == plugin->dbh) | 114 | if (NULL == plugin->dbh) |
115 | return GNUNET_SYSERR; | 115 | return GNUNET_SYSERR; |
116 | if (GNUNET_YES == | 116 | if (GNUNET_YES == |
117 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | 117 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, |
118 | "namestore-postgres", | 118 | "namestore-postgres", |
119 | "TEMPORARY_TABLE")) | 119 | "TEMPORARY_TABLE")) |
@@ -121,15 +121,15 @@ database_setup (struct Plugin *plugin) | |||
121 | res = | 121 | res = |
122 | PQexec (plugin->dbh, | 122 | PQexec (plugin->dbh, |
123 | "CREATE TEMPORARY TABLE ns091records (" | 123 | "CREATE TEMPORARY TABLE ns091records (" |
124 | " zone_key BYTEA NOT NULL DEFAULT ''," | 124 | " zone_key BYTEA NOT NULL DEFAULT ''," |
125 | " zone_delegation BYTEA NOT NULL DEFAULT ''," | 125 | " zone_delegation BYTEA NOT NULL DEFAULT ''," |
126 | " zone_hash BYTEA NOT NULL DEFAULT ''," | 126 | " zone_hash BYTEA NOT NULL DEFAULT ''," |
127 | " record_count INTEGER NOT NULL DEFAULT 0," | 127 | " record_count INTEGER NOT NULL DEFAULT 0," |
128 | " record_data BYTEA NOT NULL DEFAULT ''," | 128 | " record_data BYTEA NOT NULL DEFAULT ''," |
129 | " block_expiration_time BIGINT NOT NULL DEFAULT 0," | 129 | " block_expiration_time BIGINT NOT NULL DEFAULT 0," |
130 | " signature BYTEA NOT NULL DEFAULT ''," | 130 | " signature BYTEA NOT NULL DEFAULT ''," |
131 | " record_name TEXT NOT NULL DEFAULT ''," | 131 | " record_name TEXT NOT NULL DEFAULT ''," |
132 | " record_name_hash BYTEA NOT NULL DEFAULT ''," | 132 | " record_name_hash BYTEA NOT NULL DEFAULT ''," |
133 | " rvalue BIGINT NOT NULL DEFAULT 0" | 133 | " rvalue BIGINT NOT NULL DEFAULT 0" |
134 | ")" "WITH OIDS"); | 134 | ")" "WITH OIDS"); |
135 | } | 135 | } |
@@ -137,15 +137,15 @@ database_setup (struct Plugin *plugin) | |||
137 | res = | 137 | res = |
138 | PQexec (plugin->dbh, | 138 | PQexec (plugin->dbh, |
139 | "CREATE TABLE ns091records (" | 139 | "CREATE TABLE ns091records (" |
140 | " zone_key BYTEA NOT NULL DEFAULT ''," | 140 | " zone_key BYTEA NOT NULL DEFAULT ''," |
141 | " zone_delegation BYTEA NOT NULL DEFAULT ''," | 141 | " zone_delegation BYTEA NOT NULL DEFAULT ''," |
142 | " zone_hash BYTEA NOT NULL DEFAULT ''," | 142 | " zone_hash BYTEA NOT NULL DEFAULT ''," |
143 | " record_count INTEGER NOT NULL DEFAULT 0," | 143 | " record_count INTEGER NOT NULL DEFAULT 0," |
144 | " record_data BYTEA NOT NULL DEFAULT ''," | 144 | " record_data BYTEA NOT NULL DEFAULT ''," |
145 | " block_expiration_time BIGINT NOT NULL DEFAULT 0," | 145 | " block_expiration_time BIGINT NOT NULL DEFAULT 0," |
146 | " signature BYTEA NOT NULL DEFAULT ''," | 146 | " signature BYTEA NOT NULL DEFAULT ''," |
147 | " record_name TEXT NOT NULL DEFAULT ''," | 147 | " record_name TEXT NOT NULL DEFAULT ''," |
148 | " record_name_hash BYTEA NOT NULL DEFAULT ''," | 148 | " record_name_hash BYTEA NOT NULL DEFAULT ''," |
149 | " rvalue BIGINT NOT NULL DEFAULT 0" | 149 | " rvalue BIGINT NOT NULL DEFAULT 0" |
150 | ")" "WITH OIDS"); | 150 | ")" "WITH OIDS"); |
151 | 151 | ||
@@ -167,7 +167,7 @@ database_setup (struct Plugin *plugin) | |||
167 | if ((GNUNET_OK != | 167 | if ((GNUNET_OK != |
168 | GNUNET_POSTGRES_prepare (plugin->dbh, | 168 | GNUNET_POSTGRES_prepare (plugin->dbh, |
169 | "put_records", | 169 | "put_records", |
170 | "INSERT INTO ns091records (zone_key, record_name, record_count, record_data, block_expiration_time, signature" | 170 | "INSERT INTO ns091records (zone_key, record_name, record_count, record_data, block_expiration_time, signature" |
171 | ", zone_delegation, zone_hash, record_name_hash, rvalue) VALUES " | 171 | ", zone_delegation, zone_hash, record_name_hash, rvalue) VALUES " |
172 | "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", 10)) || | 172 | "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", 10)) || |
173 | (GNUNET_OK != | 173 | (GNUNET_OK != |
@@ -177,22 +177,22 @@ database_setup (struct Plugin *plugin) | |||
177 | (GNUNET_OK != | 177 | (GNUNET_OK != |
178 | GNUNET_POSTGRES_prepare (plugin->dbh, | 178 | GNUNET_POSTGRES_prepare (plugin->dbh, |
179 | "iterate_records", | 179 | "iterate_records", |
180 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" | 180 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" |
181 | " FROM ns091records WHERE zone_hash=$1 AND record_name_hash=$2 ORDER BY rvalue LIMIT 1 OFFSET $3", 3)) || | 181 | " FROM ns091records WHERE zone_hash=$1 AND record_name_hash=$2 ORDER BY rvalue LIMIT 1 OFFSET $3", 3)) || |
182 | (GNUNET_OK != | 182 | (GNUNET_OK != |
183 | GNUNET_POSTGRES_prepare (plugin->dbh, | 183 | GNUNET_POSTGRES_prepare (plugin->dbh, |
184 | "iterate_by_zone", | 184 | "iterate_by_zone", |
185 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" | 185 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" |
186 | " FROM ns091records WHERE zone_hash=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2)) || | 186 | " FROM ns091records WHERE zone_hash=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2)) || |
187 | (GNUNET_OK != | 187 | (GNUNET_OK != |
188 | GNUNET_POSTGRES_prepare (plugin->dbh, | 188 | GNUNET_POSTGRES_prepare (plugin->dbh, |
189 | "iterate_by_name", | 189 | "iterate_by_name", |
190 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" | 190 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" |
191 | " FROM ns091records WHERE record_name_hash=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2)) || | 191 | " FROM ns091records WHERE record_name_hash=$1 ORDER BY rvalue LIMIT 1 OFFSET $2", 2)) || |
192 | (GNUNET_OK != | 192 | (GNUNET_OK != |
193 | GNUNET_POSTGRES_prepare (plugin->dbh, | 193 | GNUNET_POSTGRES_prepare (plugin->dbh, |
194 | "iterate_all", | 194 | "iterate_all", |
195 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" | 195 | "SELECT zone_key, record_name, record_count, record_data, block_expiration_time, signature" |
196 | " FROM ns091records ORDER BY rvalue LIMIT 1 OFFSET $1", 1)) || | 196 | " FROM ns091records ORDER BY rvalue LIMIT 1 OFFSET $1", 1)) || |
197 | (GNUNET_OK != | 197 | (GNUNET_OK != |
198 | GNUNET_POSTGRES_prepare (plugin->dbh, | 198 | GNUNET_POSTGRES_prepare (plugin->dbh, |
@@ -223,8 +223,8 @@ TODO: removed | |||
223 | * @param name name to remove (at most 255 characters long) | 223 | * @param name name to remove (at most 255 characters long) |
224 | * @return GNUNET_OK on success | 224 | * @return GNUNET_OK on success |
225 | */ | 225 | */ |
226 | static int | 226 | static int |
227 | namestore_postgres_remove_records (void *cls, | 227 | namestore_postgres_remove_records (void *cls, |
228 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 228 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
229 | const char *name) | 229 | const char *name) |
230 | { | 230 | { |
@@ -267,12 +267,12 @@ namestore_postgres_remove_records (void *cls, | |||
267 | * @param name name that is being mapped (at most 255 characters long) | 267 | * @param name name that is being mapped (at most 255 characters long) |
268 | * @param rd_count number of entries in 'rd' array | 268 | * @param rd_count number of entries in 'rd' array |
269 | * @param rd array of records with data to store | 269 | * @param rd array of records with data to store |
270 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. | 270 | * @param signature signature of the record block, NULL if signature is unavailable (i.e. |
271 | * because the user queried for a particular record type only) | 271 | * because the user queried for a particular record type only) |
272 | * @return GNUNET_OK on success, else GNUNET_SYSERR | 272 | * @return GNUNET_OK on success, else GNUNET_SYSERR |
273 | */ | 273 | */ |
274 | static int | 274 | static int |
275 | namestore_postgres_put_records (void *cls, | 275 | namestore_postgres_put_records (void *cls, |
276 | const struct GNUNET_CRYPTO_EccPublicSignKey *zone_key, | 276 | const struct GNUNET_CRYPTO_EccPublicSignKey *zone_key, |
277 | struct GNUNET_TIME_Absolute expire, | 277 | struct GNUNET_TIME_Absolute expire, |
278 | const char *name, | 278 | const char *name, |
@@ -290,7 +290,7 @@ namestore_postgres_put_records (void *cls, | |||
290 | size_t data_size; | 290 | size_t data_size; |
291 | unsigned int i; | 291 | unsigned int i; |
292 | 292 | ||
293 | GNUNET_CRYPTO_short_hash (zone_key, | 293 | GNUNET_CRYPTO_short_hash (zone_key, |
294 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), | 294 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), |
295 | &zone); | 295 | &zone); |
296 | (void) namestore_postgres_remove_records (plugin, &zone, name); | 296 | (void) namestore_postgres_remove_records (plugin, &zone, name); |
@@ -336,7 +336,7 @@ namestore_postgres_put_records (void *cls, | |||
336 | sizeof (uint32_t), | 336 | sizeof (uint32_t), |
337 | data_size, | 337 | data_size, |
338 | sizeof (uint64_t), | 338 | sizeof (uint64_t), |
339 | sizeof (struct GNUNET_CRYPTO_EccSignature), | 339 | sizeof (struct GNUNET_CRYPTO_EccSignature), |
340 | sizeof (struct GNUNET_CRYPTO_ShortHashCode), | 340 | sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
341 | sizeof (struct GNUNET_CRYPTO_ShortHashCode), | 341 | sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
342 | sizeof (struct GNUNET_CRYPTO_ShortHashCode), | 342 | sizeof (struct GNUNET_CRYPTO_ShortHashCode), |
@@ -358,7 +358,7 @@ namestore_postgres_put_records (void *cls, | |||
358 | return GNUNET_SYSERR; | 358 | return GNUNET_SYSERR; |
359 | PQclear (ret); | 359 | PQclear (ret); |
360 | } | 360 | } |
361 | return GNUNET_OK; | 361 | return GNUNET_OK; |
362 | } | 362 | } |
363 | #endif | 363 | #endif |
364 | 364 | ||
@@ -404,7 +404,7 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
404 | if (0 == (cnt = PQntuples (res))) | 404 | if (0 == (cnt = PQntuples (res))) |
405 | { | 405 | { |
406 | /* no result */ | 406 | /* no result */ |
407 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 407 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
408 | "Ending iteration (no more results)\n"); | 408 | "Ending iteration (no more results)\n"); |
409 | PQclear (res); | 409 | PQclear (res); |
410 | 410 | ||
@@ -412,10 +412,10 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
412 | return GNUNET_NO; | 412 | return GNUNET_NO; |
413 | } | 413 | } |
414 | GNUNET_assert (1 == cnt); | 414 | GNUNET_assert (1 == cnt); |
415 | if ((6 != PQnfields (res)) || | 415 | if ((6 != PQnfields (res)) || |
416 | (sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) != PQgetlength (res, 0, 0)) || | 416 | (sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) != PQgetlength (res, 0, 0)) || |
417 | (sizeof (uint32_t) != PQfsize (res, 2)) || | 417 | (sizeof (uint32_t) != PQfsize (res, 2)) || |
418 | (sizeof (uint64_t) != PQfsize (res, 4)) || | 418 | (sizeof (uint64_t) != PQfsize (res, 4)) || |
419 | (sizeof (struct GNUNET_CRYPTO_EccSignature) != PQgetlength (res, 0, 5))) | 419 | (sizeof (struct GNUNET_CRYPTO_EccSignature) != PQgetlength (res, 0, 5))) |
420 | { | 420 | { |
421 | GNUNET_break (0); | 421 | GNUNET_break (0); |
@@ -444,7 +444,7 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
444 | { | 444 | { |
445 | struct GNUNET_NAMESTORE_RecordData rd[record_count]; | 445 | struct GNUNET_NAMESTORE_RecordData rd[record_count]; |
446 | char buf[name_len + 1]; | 446 | char buf[name_len + 1]; |
447 | 447 | ||
448 | memcpy (buf, name, name_len); | 448 | memcpy (buf, name, name_len); |
449 | buf[name_len] = '\0'; | 449 | buf[name_len] = '\0'; |
450 | if (GNUNET_OK != | 450 | if (GNUNET_OK != |
@@ -461,7 +461,7 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
461 | return GNUNET_OK; | 461 | return GNUNET_OK; |
462 | } | 462 | } |
463 | #endif | 463 | #endif |
464 | 464 | ||
465 | /** | 465 | /** |
466 | * Iterate over the results for a particular key and zone in the | 466 | * Iterate over the results for a particular key and zone in the |
467 | * datastore. Will return at most one result to the iterator. | 467 | * datastore. Will return at most one result to the iterator. |
@@ -474,8 +474,8 @@ get_record_and_call_iterator (struct Plugin *plugin, | |||
474 | * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error | 474 | * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error |
475 | * 'iter' will have been called unless the return value is 'GNUNET_SYSERR' | 475 | * 'iter' will have been called unless the return value is 'GNUNET_SYSERR' |
476 | */ | 476 | */ |
477 | static int | 477 | static int |
478 | namestore_postgres_iterate_records (void *cls, | 478 | namestore_postgres_iterate_records (void *cls, |
479 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, | 479 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, |
480 | uint64_t offset, | 480 | uint64_t offset, |
481 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 481 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
@@ -537,7 +537,7 @@ namestore_postgres_iterate_records (void *cls, | |||
537 | first_param = 0; | 537 | first_param = 0; |
538 | } | 538 | } |
539 | res = | 539 | res = |
540 | PQexecPrepared (plugin->dbh, stmt_name, num_params, | 540 | PQexecPrepared (plugin->dbh, stmt_name, num_params, |
541 | ¶mValues[first_param], | 541 | ¶mValues[first_param], |
542 | ¶mLengths[first_param], | 542 | ¶mLengths[first_param], |
543 | ¶mFormats[first_param], 1); | 543 | ¶mFormats[first_param], 1); |
@@ -561,7 +561,7 @@ namestore_postgres_iterate_records (void *cls, | |||
561 | * 'iter' will have been called unless the return value is 'GNUNET_SYSERR' | 561 | * 'iter' will have been called unless the return value is 'GNUNET_SYSERR' |
562 | */ | 562 | */ |
563 | static int | 563 | static int |
564 | namestore_postgres_zone_to_name (void *cls, | 564 | namestore_postgres_zone_to_name (void *cls, |
565 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, | 565 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, |
566 | const struct GNUNET_CRYPTO_EccPublicSignKey *value_zone, | 566 | const struct GNUNET_CRYPTO_EccPublicSignKey *value_zone, |
567 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) | 567 | GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) |
@@ -595,7 +595,7 @@ namestore_postgres_zone_to_name (void *cls, | |||
595 | * @param cls closure (internal context for the plugin) | 595 | * @param cls closure (internal context for the plugin) |
596 | * @param zone zone to delete | 596 | * @param zone zone to delete |
597 | */ | 597 | */ |
598 | static void | 598 | static void |
599 | namestore_postgres_delete_zone (void *cls, | 599 | namestore_postgres_delete_zone (void *cls, |
600 | const struct GNUNET_CRYPTO_ShortHashCode *zone) | 600 | const struct GNUNET_CRYPTO_ShortHashCode *zone) |
601 | { | 601 | { |
@@ -717,7 +717,7 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
717 | if (NULL != plugin.cfg) | 717 | if (NULL != plugin.cfg) |
718 | return NULL; /* can only initialize once! */ | 718 | return NULL; /* can only initialize once! */ |
719 | memset (&plugin, 0, sizeof (struct Plugin)); | 719 | memset (&plugin, 0, sizeof (struct Plugin)); |
720 | plugin.cfg = cfg; | 720 | plugin.cfg = cfg; |
721 | if (GNUNET_OK != database_setup (&plugin)) | 721 | if (GNUNET_OK != database_setup (&plugin)) |
722 | { | 722 | { |
723 | database_shutdown (&plugin); | 723 | database_shutdown (&plugin); |
@@ -733,7 +733,7 @@ libgnunet_plugin_namestore_postgres_init (void *cls) | |||
733 | api->iterate_records = &namestore_postgres_iterate_records; | 733 | api->iterate_records = &namestore_postgres_iterate_records; |
734 | api->zone_to_name = &namestore_postgres_zone_to_name; | 734 | api->zone_to_name = &namestore_postgres_zone_to_name; |
735 | /* api->delete_zone = &namestore_postgres_delete_zone; */ | 735 | /* api->delete_zone = &namestore_postgres_delete_zone; */ |
736 | LOG (GNUNET_ERROR_TYPE_INFO, | 736 | LOG (GNUNET_ERROR_TYPE_INFO, |
737 | _("Postgres database running\n")); | 737 | _("Postgres database running\n")); |
738 | return api; | 738 | return api; |
739 | } | 739 | } |
@@ -754,7 +754,7 @@ libgnunet_plugin_namestore_postgres_done (void *cls) | |||
754 | database_shutdown (plugin); | 754 | database_shutdown (plugin); |
755 | plugin->cfg = NULL; | 755 | plugin->cfg = NULL; |
756 | GNUNET_free (api); | 756 | GNUNET_free (api); |
757 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 757 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
758 | "postgres plugin is finished\n"); | 758 | "postgres plugin is finished\n"); |
759 | return NULL; | 759 | return NULL; |
760 | } | 760 | } |