aboutsummaryrefslogtreecommitdiff
path: root/src/namecache
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/namecache
parentb7f29be97540eca5c2d5d2c7802849aec87e70c0 (diff)
downloadgnunet-85cc361c21c0e1e45d1f2c0fd2ce7c3ee1e2528c.tar.gz
gnunet-85cc361c21c0e1e45d1f2c0fd2ce7c3ee1e2528c.zip
make some more use of libgnunetpq
Diffstat (limited to 'src/namecache')
-rw-r--r--src/namecache/Makefile.am1
-rw-r--r--src/namecache/plugin_namecache_postgres.c78
2 files changed, 32 insertions, 47 deletions
diff --git a/src/namecache/Makefile.am b/src/namecache/Makefile.am
index 9ab04aad5..cb4559552 100644
--- a/src/namecache/Makefile.am
+++ b/src/namecache/Makefile.am
@@ -133,6 +133,7 @@ libgnunet_plugin_namecache_postgres_la_SOURCES = \
133libgnunet_plugin_namecache_postgres_la_LIBADD = \ 133libgnunet_plugin_namecache_postgres_la_LIBADD = \
134 libgnunetnamecache.la \ 134 libgnunetnamecache.la \
135 $(top_builddir)/src/postgres/libgnunetpostgres.la \ 135 $(top_builddir)/src/postgres/libgnunetpostgres.la \
136 $(top_builddir)/src/pq/libgnunetpq.la \
136 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 137 $(top_builddir)/src/statistics/libgnunetstatistics.la \
137 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ 138 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \
138 $(LTLIBINTL) 139 $(LTLIBINTL)
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c
index 1b41dfd5e..bec8bffd2 100644
--- a/src/namecache/plugin_namecache_postgres.c
+++ b/src/namecache/plugin_namecache_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-2013, 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
@@ -28,6 +28,7 @@
28#include "gnunet_namecache_service.h" 28#include "gnunet_namecache_service.h"
29#include "gnunet_gnsrecord_lib.h" 29#include "gnunet_gnsrecord_lib.h"
30#include "gnunet_postgres_lib.h" 30#include "gnunet_postgres_lib.h"
31#include "gnunet_pq_lib.h"
31#include "namecache.h" 32#include "namecache.h"
32 33
33 34
@@ -184,19 +185,15 @@ static void
184namecache_postgres_expire_blocks (struct Plugin *plugin) 185namecache_postgres_expire_blocks (struct Plugin *plugin)
185{ 186{
186 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 187 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
187 struct GNUNET_TIME_AbsoluteNBO now_be = GNUNET_TIME_absolute_hton (now); 188 struct GNUNET_PQ_QueryParam params[] = {
188 const char *paramValues[] = { 189 GNUNET_PQ_query_param_absolute_time (&now),
189 (const char *) &now_be 190 GNUNET_PQ_query_param_end
190 }; 191 };
191 int paramLengths[] = {
192 sizeof (now_be)
193 };
194 const int paramFormats[] = { 1 };
195 PGresult *res; 192 PGresult *res;
196 193
197 res = 194 res = GNUNET_PQ_exec_prepared (plugin->dbh,
198 PQexecPrepared (plugin->dbh, "expire_blocks", 1, 195 "expire_blocks",
199 paramValues, paramLengths, paramFormats, 1); 196 params);
200 if (GNUNET_OK != 197 if (GNUNET_OK !=
201 GNUNET_POSTGRES_check_result (plugin->dbh, 198 GNUNET_POSTGRES_check_result (plugin->dbh,
202 res, 199 res,
@@ -220,20 +217,16 @@ delete_old_block (struct Plugin *plugin,
220 const struct GNUNET_HashCode *query, 217 const struct GNUNET_HashCode *query,
221 struct GNUNET_TIME_AbsoluteNBO expiration_time) 218 struct GNUNET_TIME_AbsoluteNBO expiration_time)
222{ 219{
223 const char *paramValues[] = { 220 struct GNUNET_PQ_QueryParam params[] = {
224 (const char *) query, 221 GNUNET_PQ_query_param_auto_from_type (query),
225 (const char *) &expiration_time 222 GNUNET_PQ_query_param_absolute_time_nbo (&expiration_time),
226 }; 223 GNUNET_PQ_query_param_end
227 int paramLengths[] = {
228 sizeof (*query),
229 sizeof (expiration_time)
230 }; 224 };
231 const int paramFormats[] = { 1, 1 };
232 PGresult *res; 225 PGresult *res;
233 226
234 res = 227 res = GNUNET_PQ_exec_prepared (plugin->dbh,
235 PQexecPrepared (plugin->dbh, "delete_block", 2, 228 "delete_block",
236 paramValues, paramLengths, paramFormats, 1); 229 params);
237 if (GNUNET_OK != 230 if (GNUNET_OK !=
238 GNUNET_POSTGRES_check_result (plugin->dbh, 231 GNUNET_POSTGRES_check_result (plugin->dbh,
239 res, 232 res,
@@ -261,17 +254,12 @@ namecache_postgres_cache_block (void *cls,
261 size_t block_size = ntohl (block->purpose.size) + 254 size_t block_size = ntohl (block->purpose.size) +
262 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) + 255 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) +
263 sizeof (struct GNUNET_CRYPTO_EcdsaSignature); 256 sizeof (struct GNUNET_CRYPTO_EcdsaSignature);
264 const char *paramValues[] = { 257 struct GNUNET_PQ_QueryParam params[] = {
265 (const char *) &query, 258 GNUNET_PQ_query_param_auto_from_type (&query),
266 (const char *) block, 259 GNUNET_PQ_query_param_fixed_size (block, block_size),
267 (const char *) &block->expiration_time 260 GNUNET_PQ_query_param_absolute_time_nbo (&block->expiration_time),
261 GNUNET_PQ_query_param_end
268 }; 262 };
269 int paramLengths[] = {
270 sizeof (query),
271 (int) block_size,
272 sizeof (block->expiration_time)
273 };
274 const int paramFormats[] = { 1, 1, 1 };
275 PGresult *res; 263 PGresult *res;
276 264
277 namecache_postgres_expire_blocks (plugin); 265 namecache_postgres_expire_blocks (plugin);
@@ -285,9 +273,9 @@ namecache_postgres_cache_block (void *cls,
285 } 273 }
286 delete_old_block (plugin, &query, block->expiration_time); 274 delete_old_block (plugin, &query, block->expiration_time);
287 275
288 res = 276 res = GNUNET_PQ_exec_prepared (plugin->dbh,
289 PQexecPrepared (plugin->dbh, "cache_block", 3, 277 "cache_block",
290 paramValues, paramLengths, paramFormats, 1); 278 params);
291 if (GNUNET_OK != 279 if (GNUNET_OK !=
292 GNUNET_POSTGRES_check_result (plugin->dbh, 280 GNUNET_POSTGRES_check_result (plugin->dbh,
293 res, 281 res,
@@ -316,22 +304,18 @@ namecache_postgres_lookup_block (void *cls,
316 GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls) 304 GNUNET_NAMECACHE_BlockCallback iter, void *iter_cls)
317{ 305{
318 struct Plugin *plugin = cls; 306 struct Plugin *plugin = cls;
319 const char *paramValues[] = { 307 struct GNUNET_PQ_QueryParam params[] = {
320 (const char *) query 308 GNUNET_PQ_query_param_auto_from_type (query),
321 }; 309 GNUNET_PQ_query_param_end
322 int paramLengths[] = {
323 sizeof (*query)
324 }; 310 };
325 const int paramFormats[] = { 1 };
326 PGresult *res; 311 PGresult *res;
327 unsigned int cnt; 312 unsigned int cnt;
328 size_t bsize; 313 size_t bsize;
329 const struct GNUNET_GNSRECORD_Block *block; 314 const struct GNUNET_GNSRECORD_Block *block;
330 315
331 res = PQexecPrepared (plugin->dbh, 316 res = GNUNET_PQ_exec_prepared (plugin->dbh,
332 "lookup_block", 1, 317 "lookup_block",
333 paramValues, paramLengths, paramFormats, 318 params);
334 1);
335 if (GNUNET_OK != 319 if (GNUNET_OK !=
336 GNUNET_POSTGRES_check_result (plugin->dbh, res, PGRES_TUPLES_OK, 320 GNUNET_POSTGRES_check_result (plugin->dbh, res, PGRES_TUPLES_OK,
337 "PQexecPrepared", 321 "PQexecPrepared",
@@ -387,8 +371,8 @@ database_shutdown (struct Plugin *plugin)
387/** 371/**
388 * Entry point for the plugin. 372 * Entry point for the plugin.
389 * 373 *
390 * @param cls the "struct GNUNET_NAMECACHE_PluginEnvironment*" 374 * @param cls the `struct GNUNET_NAMECACHE_PluginEnvironment *`
391 * @return NULL on error, othrewise the plugin context 375 * @return NULL on error, otherwise the plugin context
392 */ 376 */
393void * 377void *
394libgnunet_plugin_namecache_postgres_init (void *cls) 378libgnunet_plugin_namecache_postgres_init (void *cls)