aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore
diff options
context:
space:
mode:
authorJeffrey Burdges <burdges@gnunet.org>2017-06-05 02:42:33 +0200
committerJeffrey Burdges <burdges@gnunet.org>2017-06-05 02:42:33 +0200
commit6a04c1c5fc8e8d6a8e17c0e217ffbfc868a09592 (patch)
treed44ad6ab03504173eb9cb117c7791c45dde9747a /src/psycstore
parentb14f2e69adb39f4eaaaf3e26a847f29d256a1c68 (diff)
downloadgnunet-6a04c1c5fc8e8d6a8e17c0e217ffbfc868a09592.tar.gz
gnunet-6a04c1c5fc8e8d6a8e17c0e217ffbfc868a09592.zip
Final changes to switch to PQ form.
Again the ?? comments should be investigated
Diffstat (limited to 'src/psycstore')
-rw-r--r--src/psycstore/plugin_psycstore_postgres.c159
1 files changed, 76 insertions, 83 deletions
diff --git a/src/psycstore/plugin_psycstore_postgres.c b/src/psycstore/plugin_psycstore_postgres.c
index 49dd6ca8e..fe0d53455 100644
--- a/src/psycstore/plugin_psycstore_postgres.c
+++ b/src/psycstore/plugin_psycstore_postgres.c
@@ -1316,6 +1316,64 @@ state_get (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
1316} 1316}
1317 1317
1318 1318
1319
1320/**
1321 * Closure for #fragment_rows.
1322 */
1323struct GetStateContext {
1324 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key;
1325 // const char *name,
1326 GNUNET_PSYCSTORE_StateCallback cb;
1327 void *cb_cls;
1328
1329 const char *value_id;
1330
1331 /* I preserved this but I do not see the point since
1332 * it cannot stop the loop early and gets overwritten ?? */
1333 int ret;
1334};
1335
1336
1337/**
1338 * Callback that retrieves the results of a SELECT statement
1339 * reading form the state table.
1340 *
1341 * Only passed to GNUNET_PQ_eval_prepared_multi_select and
1342 * has type GNUNET_PQ_PostgresResultHandler.
1343 *
1344 * @param cls closure
1345 * @param result the postgres result
1346 * @param num_result the number of results in @a result
1347 */
1348void get_state (void *cls,
1349 PGresult *res,
1350 unsigned int num_results)
1351{
1352 struct GetStateContext *c = cls;
1353
1354 for (unsigned int i=0;i<num_results;i++)
1355 {
1356 char *name = "";
1357 void *value = NULL;
1358 size_t value_size = 0;
1359
1360 struct GNUNET_PQ_ResultSpec results[] = {
1361 GNUNET_PQ_result_spec_string ("name", &name),
1362 GNUNET_PQ_result_spec_variable_size (c->value_id, &value, &value_size),
1363 GNUNET_PQ_result_spec_end
1364 };
1365
1366 if (GNUNET_YES != GNUNET_PQ_extract_result (res, results, i))
1367 {
1368 GNUNET_PQ_cleanup_result(results); /* previously invoked via PQclear?? */
1369 break; /* nothing more?? */
1370 }
1371
1372 c->ret = c->cb (c->cb_cls, (const char *) name, value, value_size);
1373 GNUNET_PQ_cleanup_result(results);
1374 }
1375}
1376
1319/** 1377/**
1320 * Retrieve all state variables for a channel with the given prefix. 1378 * Retrieve all state variables for a channel with the given prefix.
1321 * 1379 *
@@ -1328,9 +1386,7 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_
1328 const char *name, GNUNET_PSYCSTORE_StateCallback cb, 1386 const char *name, GNUNET_PSYCSTORE_StateCallback cb,
1329 void *cb_cls) 1387 void *cb_cls)
1330{ 1388{
1331 PGresult *res;
1332 struct Plugin *plugin = cls; 1389 struct Plugin *plugin = cls;
1333 int ret = GNUNET_NO;
1334 1390
1335 const char *stmt = "select_state_prefix"; 1391 const char *stmt = "select_state_prefix";
1336 1392
@@ -1344,54 +1400,18 @@ state_get_prefix (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *channel_
1344 GNUNET_PQ_query_param_end 1400 GNUNET_PQ_query_param_end
1345 }; 1401 };
1346 1402
1347 char *name2 = ""; 1403 struct GetStateContext gsc = {
1348 void *value_current = NULL; 1404 .cb = cb,
1349 size_t value_size = 0; 1405 .cb_cls = cb_cls,
1350 1406 .value_id = "value_current",
1351 struct GNUNET_PQ_ResultSpec results[] = { 1407 .ret = GNUNET_NO
1352 GNUNET_PQ_result_spec_string ("name", &name2),
1353 GNUNET_PQ_result_spec_variable_size ("value_current", &value_current, &value_size),
1354 GNUNET_PQ_result_spec_end
1355 }; 1408 };
1356 1409
1357/* 1410 if (0 > GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
1358+ enum GNUNET_PQ_QueryStatus res; 1411 stmt, params_select,
1359+ struct ExtractResultContext erc; 1412 &get_state, &gsc))
1360*/
1361
1362 res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select);
1363 if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh,
1364 res,
1365 PGRES_TUPLES_OK,
1366 "PQexecPrepared", stmt))
1367 {
1368 return GNUNET_SYSERR; 1413 return GNUNET_SYSERR;
1369 } 1414 return gsc.ret; /* GNUNET_OK ?? */
1370
1371 int nrows = PQntuples (res);
1372 for (int row = 0; row < nrows; row++)
1373 {
1374 if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row))
1375 {
1376 break;
1377 }
1378
1379 ret = cb (cb_cls, (const char *) name2,
1380 value_current,
1381 value_size);
1382 GNUNET_PQ_cleanup_result(results);
1383 }
1384
1385 PQclear (res);
1386
1387 return ret;
1388
1389/*
1390 erc.iter = iter;
1391 erc.iter_cls = iter_cls;
1392 res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, stmt, params_select,
1393+ &extract_result_cb, &erc);
1394*/
1395} 1415}
1396 1416
1397 1417
@@ -1407,9 +1427,7 @@ state_get_signed (void *cls,
1407 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key, 1427 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
1408 GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls) 1428 GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls)
1409{ 1429{
1410 PGresult *res;
1411 struct Plugin *plugin = cls; 1430 struct Plugin *plugin = cls;
1412 int ret = GNUNET_NO;
1413 1431
1414 const char *stmt = "select_state_signed"; 1432 const char *stmt = "select_state_signed";
1415 1433
@@ -1418,43 +1436,18 @@ state_get_signed (void *cls,
1418 GNUNET_PQ_query_param_end 1436 GNUNET_PQ_query_param_end
1419 }; 1437 };
1420 1438
1421 char *name = ""; 1439 struct GetStateContext gsc = {
1422 void *value_signed = NULL; 1440 .cb = cb,
1423 size_t value_size = 0; 1441 .cb_cls = cb_cls,
1424 1442 .value_id = "value_signed",
1425 struct GNUNET_PQ_ResultSpec results[] = { 1443 .ret = GNUNET_NO
1426 GNUNET_PQ_result_spec_string ("name", &name),
1427 GNUNET_PQ_result_spec_variable_size ("value_signed", &value_signed, &value_size),
1428 GNUNET_PQ_result_spec_end
1429 }; 1444 };
1430 1445
1431 res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select); 1446 if (0 > GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
1432 if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh, 1447 stmt, params_select,
1433 res, 1448 &get_state, &gsc))
1434 PGRES_TUPLES_OK,
1435 "PQexecPrepared", stmt))
1436 {
1437 return GNUNET_SYSERR; 1449 return GNUNET_SYSERR;
1438 } 1450 return gsc.ret; /* GNUNET_OK ?? */
1439
1440 int nrows = PQntuples (res);
1441 for (int row = 0; row < nrows; row++)
1442 {
1443 if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row))
1444 {
1445 break;
1446 }
1447
1448 ret = cb (cb_cls, (const char *) name,
1449 value_signed,
1450 value_size);
1451
1452 GNUNET_PQ_cleanup_result (results);
1453 }
1454
1455 PQclear (res);
1456
1457 return ret;
1458} 1451}
1459 1452
1460 1453