ret =
PQexec (plugin->dbh,
- "CREATE TABLE gn090 ("
+ "CREATE TABLE gn090 ("
" repl INTEGER NOT NULL DEFAULT 0,"
" type INTEGER NOT NULL DEFAULT 0,"
" prio INTEGER NOT NULL DEFAULT 0,"
" rvalue BIGINT NOT NULL DEFAULT 0,"
" hash BYTEA NOT NULL DEFAULT '',"
" vhash BYTEA NOT NULL DEFAULT '',"
- " value BYTEA NOT NULL DEFAULT '')"
+ " value BYTEA NOT NULL DEFAULT '')"
"WITH OIDS");
if ( (NULL == ret) ||
((PQresultStatus (ret) != PGRES_COMMAND_OK) &&
"SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090", 0,
NULL, NULL, NULL, NULL, 1);
if (GNUNET_OK !=
- GNUNET_POSTGRES_check_result (plugin->dbh,
- ret,
- PGRES_TUPLES_OK,
- "PQexecParams",
+ GNUNET_POSTGRES_check_result (plugin->dbh,
+ ret,
+ PGRES_TUPLES_OK,
+ "PQexecParams",
"get_size"))
{
*estimate = 0;
* @param cont_cls continuation closure
*/
static void
-postgres_plugin_put (void *cls,
+postgres_plugin_put (void *cls,
const struct GNUNET_HashCode *key,
uint32_t size,
- const void *data,
+ const void *data,
enum GNUNET_BLOCK_Type type,
- uint32_t priority,
+ uint32_t priority,
uint32_t anonymity,
uint32_t replication,
- struct GNUNET_TIME_Absolute expiration,
+ struct GNUNET_TIME_Absolute expiration,
PluginPutCont cont,
void *cont_cls)
{
"put",
params);
if (GNUNET_OK !=
- GNUNET_POSTGRES_check_result (plugin->dbh,
- ret,
- PGRES_COMMAND_OK,
+ GNUNET_POSTGRES_check_result (plugin->dbh,
+ ret,
+ PGRES_COMMAND_OK,
"PQexecPrepared", "put"))
{
- cont (cont_cls, key, size,
- GNUNET_SYSERR,
+ cont (cont_cls, key, size,
+ GNUNET_SYSERR,
_("Postgress exec failure"));
return;
}
PQclear (ret);
- plugin->env->duc (plugin->env->cls,
+ plugin->env->duc (plugin->env->cls,
size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-postgres",
- "Stored %u bytes in database\n",
+ "Stored %u bytes in database\n",
(unsigned int) size);
cont (cont_cls, key, size, GNUNET_OK, NULL);
}
* @param line line number for error messages
*/
static void
-process_result (struct Plugin *plugin,
+process_result (struct Plugin *plugin,
PluginDatumProcessor proc,
void *proc_cls,
PGresult * res,
};
if (GNUNET_OK !=
- GNUNET_POSTGRES_check_result_ (plugin->dbh,
- res,
- PGRES_TUPLES_OK,
+ GNUNET_POSTGRES_check_result_ (plugin->dbh,
+ res,
+ PGRES_TUPLES_OK,
"PQexecPrepared",
"select",
filename, line))
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-postgres",
"Ending iteration (postgres error)\n");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
if (0 == PQntuples (res))
{
/* no result */
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-postgres",
"Ending iteration (no more results)\n");
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
PQclear (res);
return;
}
- if (1 != PQntuples (res))
+ if (1 != PQntuples (res))
{
GNUNET_break (0);
proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_break (0);
PQclear (res);
GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
- "delrow",
+ "delrow",
rowid);
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-postgres",
"Found result of size %u bytes and type %u in database\n",
- (unsigned int) size,
+ (unsigned int) size,
(unsigned int) utype);
iret = proc (proc_cls,
&key,
size,
data,
- (enum GNUNET_BLOCK_Type) utype,
+ (enum GNUNET_BLOCK_Type) utype,
priority,
anonymity,
expiration_time,
if (iret == GNUNET_NO)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Processor asked for item %u to be removed.\n",
+ "Processor asked for item %u to be removed.\n",
(unsigned int) rowid);
- if (GNUNET_OK ==
- GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
- "delrow",
+ if (GNUNET_OK ==
+ GNUNET_POSTGRES_delete_by_rowid (plugin->dbh,
+ "delrow",
rowid))
{
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-postgres",
"Deleting %u bytes from database\n",
(unsigned int) size);
plugin->env->duc (plugin->env->cls,
- (size + GNUNET_DATASTORE_ENTRY_OVERHEAD));
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"datastore-postgres",
"Deleted %u bytes from database\n",
(unsigned int) size);
* @param proc_cls closure for iter
*/
static void
-postgres_plugin_get_key (void *cls,
+postgres_plugin_get_key (void *cls,
uint64_t offset,
const struct GNUNET_HashCode *key,
const struct GNUNET_HashCode *vhash,
{
if (NULL != vhash)
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_auto_from_type (vhash),
GNUNET_PQ_query_param_uint32 (&utype),
}
else
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_uint32 (&utype),
GNUNET_PQ_query_param_end
{
if (NULL != vhash)
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_auto_from_type (vhash),
GNUNET_PQ_query_param_end
}
else
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_end
};
}
if (GNUNET_OK !=
- GNUNET_POSTGRES_check_result (plugin->dbh,
+ GNUNET_POSTGRES_check_result (plugin->dbh,
ret,
- PGRES_TUPLES_OK,
- "PQexecParams",
+ PGRES_TUPLES_OK,
+ "PQexecParams",
"count"))
{
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
- if ( (PQntuples (ret) != 1) ||
+ if ( (PQntuples (ret) != 1) ||
(PQnfields (ret) != 1) ||
(PQgetlength (ret, 0, 0) != sizeof (uint64_t)))
{
GNUNET_break (0);
PQclear (ret);
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
PQclear (ret);
if (0 == total)
{
- proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
+ proc (proc_cls, NULL, 0, NULL, 0, 0, 0,
GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
{
if (NULL != vhash)
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
- GNUNET_PQ_query_param_auto_from_type (&vhash),
+ GNUNET_PQ_query_param_auto_from_type (vhash),
GNUNET_PQ_query_param_uint32 (&utype),
GNUNET_PQ_query_param_uint64 (&limit_off),
GNUNET_PQ_query_param_end
}
else
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_uint32 (&utype),
GNUNET_PQ_query_param_uint64 (&limit_off),
{
if (NULL != vhash)
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
- GNUNET_PQ_query_param_auto_from_type (&vhash),
+ GNUNET_PQ_query_param_auto_from_type (vhash),
GNUNET_PQ_query_param_uint64 (&limit_off),
GNUNET_PQ_query_param_end
};
}
else
{
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (key),
GNUNET_PQ_query_param_uint64 (&limit_off),
GNUNET_PQ_query_param_end
}
process_result (plugin,
proc,
- proc_cls,
- ret,
+ proc_cls,
+ ret,
__FILE__, __LINE__);
}
* @param proc_cls closure for @a proc
*/
static void
-postgres_plugin_get_zero_anonymity (void *cls,
+postgres_plugin_get_zero_anonymity (void *cls,
uint64_t offset,
enum GNUNET_BLOCK_Type type,
- PluginDatumProcessor proc,
+ PluginDatumProcessor proc,
void *proc_cls)
{
struct Plugin *plugin = cls;
uint32_t utype = type;
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&utype),
GNUNET_PQ_query_param_uint64 (&offset),
GNUNET_PQ_query_param_end
"select_non_anonymous",
params);
- process_result (plugin,
+ process_result (plugin,
proc, proc_cls,
ret,
__FILE__, __LINE__);
* @param expiration expiration time for the content
* @param uid unique identifier for the datum;
* maybe 0 if no unique identifier is available
- * @return #GNUNET_SYSERR to abort the iteration,
+ * @return #GNUNET_SYSERR to abort the iteration,
* #GNUNET_OK to continue
* (continue on call to "next", of course),
* #GNUNET_NO to delete the item and continue (if supported)
const struct GNUNET_HashCode *key,
uint32_t size,
const void *data,
- enum GNUNET_BLOCK_Type type,
+ enum GNUNET_BLOCK_Type type,
uint32_t priority,
- uint32_t anonymity,
+ uint32_t anonymity,
struct GNUNET_TIME_Absolute expiration,
uint64_t uid)
{
struct Plugin *plugin = rc->plugin;
int ret;
uint32_t oid = (uint32_t) uid;
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&oid),
GNUNET_PQ_query_param_end
};
PGresult *qret;
- ret = rc->proc (rc->proc_cls,
- key,
- size, data,
+ ret = rc->proc (rc->proc_cls,
+ key,
+ size, data,
type,
- priority,
+ priority,
anonymity,
expiration, uid);
if (NULL == key)
"decrepl",
params);
if (GNUNET_OK !=
- GNUNET_POSTGRES_check_result (plugin->dbh,
- qret,
- PGRES_COMMAND_OK,
+ GNUNET_POSTGRES_check_result (plugin->dbh,
+ qret,
+ PGRES_COMMAND_OK,
"PQexecPrepared",
"decrepl"))
return GNUNET_SYSERR;
* @param proc_cls closure for @a proc
*/
static void
-postgres_plugin_get_replication (void *cls,
+postgres_plugin_get_replication (void *cls,
PluginDatumProcessor proc,
void *proc_cls)
{
rc.plugin = plugin;
rc.proc = proc;
rc.proc_cls = proc_cls;
- ret = PQexecPrepared (plugin->dbh,
+ ret = PQexecPrepared (plugin->dbh,
"select_replication_order", 0, NULL, NULL,
NULL, 1);
- process_result (plugin,
- &repl_proc,
- &rc,
- ret,
+ process_result (plugin,
+ &repl_proc,
+ &rc,
+ ret,
__FILE__, __LINE__);
}
* @param proc_cls closure for @a proc
*/
static void
-postgres_plugin_get_expiration (void *cls,
+postgres_plugin_get_expiration (void *cls,
PluginDatumProcessor proc,
void *proc_cls)
{
struct Plugin *plugin = cls;
struct GNUNET_TIME_Absolute now;
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_absolute_time (&now),
GNUNET_PQ_query_param_end
};
* @param cons_cls continuation closure
*/
static void
-postgres_plugin_update (void *cls,
- uint64_t uid,
+postgres_plugin_update (void *cls,
+ uint64_t uid,
int delta,
struct GNUNET_TIME_Absolute expire,
PluginUpdateCont cont,
struct Plugin *plugin = cls;
uint32_t idelta = delta;
uint32_t oid = (uint32_t) uid;
- struct GNUNET_PQ_QueryParam params[] = {
+ struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&idelta),
GNUNET_PQ_query_param_absolute_time (&expire),
GNUNET_PQ_query_param_uint32 (&oid),
params);
if (GNUNET_OK !=
GNUNET_POSTGRES_check_result (plugin->dbh,
- ret,
- PGRES_COMMAND_OK,
- "PQexecPrepared",
+ ret,
+ PGRES_COMMAND_OK,
+ "PQexecPrepared",
"update"))
{
- cont (cont_cls,
- GNUNET_SYSERR,
+ cont (cont_cls,
+ GNUNET_SYSERR,
NULL);
return;
}
PQclear (ret);
- cont (cont_cls,
- GNUNET_OK,
+ cont (cont_cls,
+ GNUNET_OK,
NULL);
}
-
/**
* Get all of the keys in the datastore.
*
struct GNUNET_HashCode key;
PGresult * res;
- res = PQexecPrepared (plugin->dbh,
- "get_keys",
+ res = PQexecPrepared (plugin->dbh,
+ "get_keys",
0, NULL, NULL, NULL, 1);
ret = PQntuples (res);
for (i=0;i<ret;i++)
{
- if (sizeof (struct GNUNET_HashCode) !=
+ if (sizeof (struct GNUNET_HashCode) !=
PQgetlength (res, i, 0))
{
- memcpy (&key,
- PQgetvalue (res, i, 0),
+ memcpy (&key,
+ PQgetvalue (res, i, 0),
sizeof (struct GNUNET_HashCode));
proc (proc_cls, &key, 1);
}
}
-
/**
* Drop database.
*
{
struct Plugin *plugin = cls;
- if (GNUNET_OK !=
- GNUNET_POSTGRES_exec (plugin->dbh, "DROP TABLE gn090"))
- GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
- "postgres",
+ if (GNUNET_OK !=
+ GNUNET_POSTGRES_exec (plugin->dbh,
+ "DROP TABLE gn090"))
+ GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
+ "postgres",
_("Failed to drop table from database.\n"));
}
api->get_zero_anonymity = &postgres_plugin_get_zero_anonymity;
api->get_keys = &postgres_plugin_get_keys;
api->drop = &postgres_plugin_drop;
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datastore-postgres",
+ GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
+ "datastore-postgres",
_("Postgres database running\n"));
return api;
}