#include "gnunet_crypto_lib.h"
#include "gnunet_psyc_util_lib.h"
#include "psycstore.h"
-#include "gnunet_postgres_lib.h"
#include "gnunet_pq_lib.h"
/**
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, stmt, params))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "transaction_begin", params))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "transaction_commit", params))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "transaction_rollback", params))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
- GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "insert_channel_key", params))
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
+ "insert_channel_key",
+ params))
return GNUNET_SYSERR;
return GNUNET_OK;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "insert_slave_key", params))
return GNUNET_SYSERR;
uint64_t group_generation)
{
struct Plugin *plugin = cls;
-
- uint32_t idid_join = (uint32_t)did_join;
+ uint32_t idid_join = (uint32_t) did_join;
GNUNET_assert (TRANSACTION_NONE == plugin->transaction);
- if (announced_at > INT64_MAX ||
- effective_since > INT64_MAX ||
- group_generation > INT64_MAX)
+ if ( (announced_at > INT64_MAX) ||
+ (effective_since > INT64_MAX) ||
+ (group_generation > INT64_MAX) )
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (GNUNET_OK != channel_key_store (plugin, channel_key)
- || GNUNET_OK != slave_key_store (plugin, slave_key))
+ if ( (GNUNET_OK !=
+ channel_key_store (plugin, channel_key)) ||
+ (GNUNET_OK !=
+ slave_key_store (plugin, slave_key)) )
return GNUNET_SYSERR;
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
- GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "insert_membership", params))
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ GNUNET_PQ_eval_prepared_non_select (plugin->dbh,
+ "insert_membership",
+ params))
return GNUNET_SYSERR;
return GNUNET_OK;
GNUNET_PQ_result_spec_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, "select_membership",
params_select, results_select))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "insert_fragment", params_insert))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, "update_message_flags", params_update))
return GNUNET_SYSERR;
GNUNET_PQ_result_spec_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt,
params_select, results_select))
return GNUNET_SYSERR;
GNUNET_PQ_result_spec_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt,
params_select, results_select))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, stmt, params))
return GNUNET_SYSERR;
GNUNET_PQ_query_param_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_NO_RESULTS !=
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
GNUNET_PQ_eval_prepared_non_select (plugin->dbh, stmt, params))
return GNUNET_SYSERR;
GNUNET_PQ_result_spec_end
};
- if (GNUNET_PQ_STATUS_SUCCESS_ONE_RESULT !=
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
GNUNET_PQ_eval_prepared_singleton_select (plugin->dbh, stmt,
params_select, results_select))
return GNUNET_SYSERR;
}
+
+/**
+ * Closure for #get_state_cb.
+ */
+struct GetStateContext {
+ const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key;
+ // const char *name,
+ GNUNET_PSYCSTORE_StateCallback cb;
+ void *cb_cls;
+
+ const char *value_id;
+
+ /* I preserved this but I do not see the point since
+ * it cannot stop the loop early and gets overwritten ?? */
+ int ret;
+};
+
+
+/**
+ * Callback that retrieves the results of a SELECT statement
+ * reading form the state table.
+ *
+ * Only passed to GNUNET_PQ_eval_prepared_multi_select and
+ * has type GNUNET_PQ_PostgresResultHandler.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_result the number of results in @a result
+ */
+static void
+get_state_cb (void *cls,
+ PGresult *res,
+ unsigned int num_results)
+{
+ struct GetStateContext *c = cls;
+
+ for (unsigned int i=0;i<num_results;i++)
+ {
+ char *name = "";
+ void *value = NULL;
+ size_t value_size = 0;
+
+ struct GNUNET_PQ_ResultSpec results[] = {
+ GNUNET_PQ_result_spec_string ("name", &name),
+ GNUNET_PQ_result_spec_variable_size (c->value_id, &value, &value_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_YES != GNUNET_PQ_extract_result (res, results, i))
+ {
+ GNUNET_PQ_cleanup_result(results); /* previously invoked via PQclear?? */
+ break; /* nothing more?? */
+ }
+
+ c->ret = c->cb (c->cb_cls, (const char *) name, value, value_size);
+ GNUNET_PQ_cleanup_result(results);
+ }
+}
+
/**
* Retrieve all state variables for a channel with the given prefix.
*
const char *name, GNUNET_PSYCSTORE_StateCallback cb,
void *cb_cls)
{
- PGresult *res;
struct Plugin *plugin = cls;
- int ret = GNUNET_NO;
const char *stmt = "select_state_prefix";
GNUNET_PQ_query_param_end
};
- char *name2 = "";
- void *value_current = NULL;
- size_t value_size = 0;
-
- struct GNUNET_PQ_ResultSpec results[] = {
- GNUNET_PQ_result_spec_string ("name", &name2),
- GNUNET_PQ_result_spec_variable_size ("value_current", &value_current, &value_size),
- GNUNET_PQ_result_spec_end
+ struct GetStateContext gsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .value_id = "value_current",
+ .ret = GNUNET_NO
};
-/*
-+ enum GNUNET_PQ_QueryStatus res;
-+ struct ExtractResultContext erc;
-*/
-
- res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select);
- if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared", stmt))
- {
+ if (0 > GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
+ stmt, params_select,
+ &get_state_cb, &gsc))
return GNUNET_SYSERR;
- }
-
- int nrows = PQntuples (res);
- for (int row = 0; row < nrows; row++)
- {
- if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row))
- {
- break;
- }
-
- ret = cb (cb_cls, (const char *) name2,
- value_current,
- value_size);
- GNUNET_PQ_cleanup_result(results);
- }
-
- PQclear (res);
-
- return ret;
-
-/*
- erc.iter = iter;
- erc.iter_cls = iter_cls;
- res = GNUNET_PQ_eval_prepared_multi_select (plugin->dbh, stmt, params_select,
-+ &extract_result_cb, &erc);
-*/
+ return gsc.ret; /* GNUNET_OK ?? */
}
const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
GNUNET_PSYCSTORE_StateCallback cb, void *cb_cls)
{
- PGresult *res;
struct Plugin *plugin = cls;
- int ret = GNUNET_NO;
const char *stmt = "select_state_signed";
GNUNET_PQ_query_param_end
};
- char *name = "";
- void *value_signed = NULL;
- size_t value_size = 0;
-
- struct GNUNET_PQ_ResultSpec results[] = {
- GNUNET_PQ_result_spec_string ("name", &name),
- GNUNET_PQ_result_spec_variable_size ("value_signed", &value_signed, &value_size),
- GNUNET_PQ_result_spec_end
+ struct GetStateContext gsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .value_id = "value_signed",
+ .ret = GNUNET_NO
};
- res = GNUNET_PQ_exec_prepared (plugin->dbh, stmt, params_select);
- if (GNUNET_OK != GNUNET_POSTGRES_check_result (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
- "PQexecPrepared", stmt))
- {
+ if (0 > GNUNET_PQ_eval_prepared_multi_select (plugin->dbh,
+ stmt, params_select,
+ &get_state_cb, &gsc))
return GNUNET_SYSERR;
- }
-
- int nrows = PQntuples (res);
- for (int row = 0; row < nrows; row++)
- {
- if (GNUNET_OK != GNUNET_PQ_extract_result (res, results, row))
- {
- break;
- }
-
- ret = cb (cb_cls, (const char *) name,
- value_signed,
- value_size);
-
- GNUNET_PQ_cleanup_result (results);
- }
-
- PQclear (res);
-
- return ret;
+ return gsc.ret; /* GNUNET_OK ?? */
}