struct GNUNET_GNSRECORD_Data *dest)
{
struct NetworkRecord rec;
- unsigned int i;
size_t off;
off = 0;
- for (i=0;i<rd_count;i++)
+ for (unsigned int i=0;i<rd_count;i++)
{
if (off + sizeof (rec) > len)
return GNUNET_SYSERR;
GNUNET_DISK_directory_remove (const char *filename);
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option);
+
+
/**
* Implementation of "mkdir -p"
*
GNUNET_SQ_cleanup_result (struct GNUNET_SQ_ResultSpec *rs);
+
+/* ******************** sq_prepare.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_PrepareStatement {
+
+ /**
+ * Actual SQL statement.
+ */
+ const char *sql;
+
+ /**
+ * Where to store handle?
+ */
+ sqlite3_stmt **pstmt;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_PREPARE_END { NULL, NULL }
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+ sqlite3_stmt **pstmt);
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database handle
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+ const struct GNUNET_SQ_PrepareStatement *ps);
+
+
+/* ******************** sq_exec.c functions ************** */
+
+
+/**
+ * Information needed to run a list of SQL statements using
+ * #GNUNET_SQ_exec_statements().
+ */
+struct GNUNET_SQ_ExecuteStatement {
+
+ /**
+ * Actual SQL statement.
+ */
+ const char *sql;
+
+ /**
+ * Should we ignore errors?
+ */
+ int ignore_errors;
+
+};
+
+
+/**
+ * Terminator for executable statement list.
+ */
+#define GNUNET_SQ_EXECUTE_STATEMENT_END { NULL, GNUNET_SYSERR }
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql);
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql);
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ * statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
+ * #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+ const struct GNUNET_SQ_ExecuteStatement *es);
+
+
+
#endif /* GNUNET_SQ_LIB_H_ */
/* end of include/gnunet_sq_lib.h */
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013, 2014 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2014, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* @brief namestore for the GNUnet naming system
* @author Matthias Wachs
* @author Christian Grothoff
+ *
+ * TODO:
+ * - run testcases, make sure everything works!
*/
#include "platform.h"
#include "gnunet_util_lib.h"
*/
uint64_t limit;
+ /**
+ * How many more requests may we receive from the iterator
+ * before it is at the limit we gave it? Will be below or
+ * equal to @e limit. The effective limit for monitor
+ * events is thus @e iteration_cnt - @e limit!
+ */
+ uint64_t iteration_cnt;
+
+ /**
+ * Are we (still) in the initial iteration pass?
+ */
+ int in_first_iteration;
+
+ /**
+ * Is there a store activity waiting for this monitor? We only raise the
+ * flag when it happens and search the DLL for the store activity when we
+ * had a limit increase. If we cannot find any waiting store activity at
+ * that time, we clear the flag again.
+ */
+ int sa_waiting;
+
};
};
+/**
+ * Information for an ongoing #handle_record_store() operation.
+ * Needed as we may wait for monitors to be ready for the notification.
+ */
+struct StoreActivity
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct StoreActivity *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct StoreActivity *prev;
+
+ /**
+ * Which client triggered the store activity?
+ */
+ struct NamestoreClient *nc;
+
+ /**
+ * Copy of the original store message (as data fields in @e rd will
+ * point into it!).
+ */
+ const struct RecordStoreMessage *rsm;
+
+ /**
+ * Array of record data to store (without NICK unless this is about
+ * #GNUNET_GNS_EMPTY_LABEL_AT). Length is in @e rd_count.
+ */
+ struct GNUNET_GNSRECORD_Data *rd;
+
+ /**
+ * Next zone monitor that still needs to be notified about this PUT.
+ */
+ struct ZoneMonitor *zm_pos;
+
+ /**
+ * Label nicely canonicalized (lower case).
+ */
+ char *conv_name;
+
+ /**
+ * How many records do we try to store?
+ */
+ unsigned int rd_count;
+
+};
+
+
/**
* Public key of all zeros.
*/
*/
static struct ZoneMonitor *monitor_tail;
+/**
+ * Head of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_head;
+
+/**
+ * Tail of DLL of monitor-blocked store activities.
+ */
+static struct StoreActivity *sa_tail;
+
/**
* Notification context shared by all monitors.
*/
/**
- * Called whenever a client is disconnected.
- * Frees our resources associated with that client.
+ * Release memory used by @a sa.
*
- * @param cls closure
- * @param client identification of the client
- * @param app_ctx the `struct NamestoreClient` of @a client
+ * @param sa activity to free
*/
static void
-client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
-{
- struct NamestoreClient *nc = app_ctx;
- struct ZoneIteration *no;
- struct ZoneMonitor *zm;
- struct CacheOperation *cop;
-
- (void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected\n",
- client);
- for (zm = monitor_head; NULL != zm; zm = zm->next)
- {
- if (nc == zm->nc)
- {
- GNUNET_CONTAINER_DLL_remove (monitor_head,
- monitor_tail,
- zm);
- if (NULL != zm->task)
- {
- GNUNET_SCHEDULER_cancel (zm->task);
- zm->task = NULL;
- }
- GNUNET_free (zm);
- break;
- }
- }
- while (NULL != (no = nc->op_head))
- {
- GNUNET_CONTAINER_DLL_remove (nc->op_head,
- nc->op_tail,
- no);
- GNUNET_free (no);
- }
- for (cop = cop_head; NULL != cop; cop = cop->next)
- if (nc == cop->nc)
- cop->nc = NULL;
- GNUNET_free (nc);
-}
-
-
-/**
- * Add a client to our list of active clients.
- *
- * @param cls NULL
- * @param client client to add
- * @param mq message queue for @a client
- * @return internal namestore client structure for this client
- */
-static void *
-client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+free_store_activity (struct StoreActivity *sa)
{
- struct NamestoreClient *nc;
-
- (void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p connected\n",
- client);
- nc = GNUNET_new (struct NamestoreClient);
- nc->client = client;
- nc->mq = mq;
- return nc;
+ GNUNET_CONTAINER_DLL_remove (sa_head,
+ sa_tail,
+ sa);
+ GNUNET_array_grow (sa->rd,
+ sa->rd_count,
+ 0);
+ GNUNET_free (sa->conv_name);
+ GNUNET_free (sa);
}
}
+/**
+ * Continue processing the @a sa.
+ *
+ * @param sa store activity to process
+ */
+static void
+continue_store_activity (struct StoreActivity *sa)
+{
+ const struct RecordStoreMessage *rp_msg = sa->rsm;
+
+ for (struct ZoneMonitor *zm = sa->zm_pos;
+ NULL != zm;
+ zm = sa->zm_pos)
+ {
+ if ( (0 != memcmp (&rp_msg->private_key,
+ &zm->zone,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) &&
+ (0 != memcmp (&zm->zone,
+ &zero,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
+ sa->zm_pos = zm->next; /* not interesting to this monitor */
+ if (zm->limit == zm->iteration_cnt)
+ {
+ zm->sa_waiting = GNUNET_YES;
+ return; /* blocked on zone monitor */
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Notifying monitor about changes under label `%s'\n",
+ sa->conv_name);
+ zm->limit--;
+ send_lookup_response (zm->nc,
+ 0,
+ &rp_msg->private_key,
+ sa->conv_name,
+ sa->rd_count,
+ sa->rd);
+ sa->zm_pos = zm->next;
+ }
+ /* great, done with the monitors, unpack (again) for refresh_block operation */
+ {
+ size_t name_len;
+ size_t rd_ser_len;
+ uint32_t rid;
+ const char *name_tmp;
+ const char *rd_ser;
+ unsigned int rd_count;
+
+ rid = ntohl (rp_msg->gns_header.r_id);
+ name_len = ntohs (rp_msg->name_len);
+ rd_count = ntohs (rp_msg->rd_count);
+ rd_ser_len = ntohs (rp_msg->rd_len);
+ name_tmp = (const char *) &rp_msg[1];
+ rd_ser = &name_tmp[name_len];
+ {
+ struct GNUNET_GNSRECORD_Data rd[rd_count];
+
+ /* We did this before, must succeed again */
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
+ rd_ser,
+ rd_count,
+ rd));
+ refresh_block (sa->nc,
+ rid,
+ &rp_msg->private_key,
+ sa->conv_name,
+ rd_count,
+ rd);
+ }
+ }
+ GNUNET_SERVICE_client_continue (sa->nc->client);
+ free_store_activity (sa);
+}
+
+
+/**
+ * Called whenever a client is disconnected.
+ * Frees our resources associated with that client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param app_ctx the `struct NamestoreClient` of @a client
+ */
+static void
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
+{
+ struct NamestoreClient *nc = app_ctx;
+ struct ZoneIteration *no;
+ struct CacheOperation *cop;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p disconnected\n",
+ client);
+ for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next)
+ {
+ if (nc != zm->nc)
+ continue;
+ GNUNET_CONTAINER_DLL_remove (monitor_head,
+ monitor_tail,
+ zm);
+ if (NULL != zm->task)
+ {
+ GNUNET_SCHEDULER_cancel (zm->task);
+ zm->task = NULL;
+ }
+ for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+ {
+ if (zm == sa->zm_pos)
+ {
+ sa->zm_pos = zm->next;
+ continue_store_activity (sa);
+ }
+ }
+ GNUNET_free (zm);
+ break;
+ }
+ for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+ {
+ if (sa->nc == nc)
+ {
+ free_store_activity (sa);
+ break; /* there can only be one per nc */
+ }
+ }
+ while (NULL != (no = nc->op_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (nc->op_head,
+ nc->op_tail,
+ no);
+ GNUNET_free (no);
+ }
+ for (cop = cop_head; NULL != cop; cop = cop->next)
+ if (nc == cop->nc)
+ cop->nc = NULL;
+ GNUNET_free (nc);
+}
+
+
+/**
+ * Add a client to our list of active clients.
+ *
+ * @param cls NULL
+ * @param client client to add
+ * @param mq message queue for @a client
+ * @return internal namestore client structure for this client
+ */
+static void *
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct NamestoreClient *nc;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p connected\n",
+ client);
+ nc = GNUNET_new (struct NamestoreClient);
+ nc->client = client;
+ nc->mq = mq;
+ return nc;
+}
+
+
/**
* Closure for #lookup_it().
*/
const char *rd_ser;
unsigned int rd_count;
int res;
- struct ZoneMonitor *zm;
+ struct StoreActivity *sa;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received NAMESTORE_RECORD_STORE message\n");
name_tmp = (const char *) &rp_msg[1];
rd_ser = &name_tmp[name_len];
{
- struct GNUNET_GNSRECORD_Data rd[rd_count];
+ struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(rd_count)];
+ struct GNUNET_GNSRECORD_Data rd_clean[GNUNET_NZL(rd_count)];
+ unsigned int rd_clean_off;
if (GNUNET_OK !=
GNUNET_GNSRECORD_records_deserialize (rd_ser_len,
}
else
{
- struct GNUNET_GNSRECORD_Data rd_clean[rd_count];
- unsigned int rd_clean_off;
-
/* remove "NICK" records, unless this is for the
#GNUNET_GNS_EMPTY_LABEL_AT label */
rd_clean_off = 0;
conv_name,
rd_clean_off,
rd_clean);
- if (GNUNET_OK == res)
- {
- for (zm = monitor_head; NULL != zm; zm = zm->next)
- {
- if ( (0 == memcmp (&rp_msg->private_key,
- &zm->zone,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) ||
- (0 == memcmp (&zm->zone,
- &zero,
- sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Notifying monitor about changes under label `%s'\n",
- conv_name);
- send_lookup_response (zm->nc,
- 0,
- &rp_msg->private_key,
- conv_name,
- rd_count, rd);
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Monitor is for another zone\n");
- }
- if (NULL == monitor_head)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No monitors active\n");
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error storing record: %d\n",
- res);
- }
}
- if (GNUNET_OK == res)
+
+ if (GNUNET_OK != res)
{
- refresh_block (nc,
- rid,
- &rp_msg->private_key,
- conv_name,
- rd_count,
- rd);
+ /* store not successful, not need to tell monitors */
+ send_store_response (nc,
+ res,
+ rid);
GNUNET_SERVICE_client_continue (nc->client);
GNUNET_free (conv_name);
return;
}
- GNUNET_free (conv_name);
+
+ sa = GNUNET_malloc (sizeof (struct StoreActivity) +
+ ntohs (rp_msg->gns_header.header.size));
+ GNUNET_CONTAINER_DLL_insert (sa_head,
+ sa_tail,
+ sa);
+ sa->nc = nc;
+ sa->rsm = (const struct RecordStoreMessage *) &sa[1];
+ memcpy (&sa[1],
+ rp_msg,
+ ntohs (rp_msg->gns_header.header.size));
+ sa->zm_pos = monitor_head;
+ sa->conv_name = conv_name;
+ GNUNET_array_grow (sa->rd,
+ sa->rd_count,
+ rd_clean_off);
+ memcpy (sa->rd,
+ rd_clean,
+ sizeof (struct GNUNET_GNSRECORD_Data) * rd_clean_off);
+ continue_store_activity (sa);
}
- send_store_response (nc,
- res,
- rid);
- GNUNET_SERVICE_client_continue (nc->client);
}
struct ZoneToNameResponseMessage *ztnr_msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
- "ZONE_TO_NAME");
+ "Received ZONE_TO_NAME message\n");
ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id);
ztn_ctx.nc = nc;
ztn_ctx.success = GNUNET_NO;
}
+/**
+ * Function called when the monitor is ready for more data, and we
+ * should thus unblock PUT operations that were blocked on the
+ * monitor not being ready.
+ */
+static void
+monitor_unblock (struct ZoneMonitor *zm)
+{
+ struct StoreActivity *sa = sa_head;
+
+ while ( (NULL != sa) &&
+ (zm->limit > zm->iteration_cnt) )
+ {
+ struct StoreActivity *sn = sa->next;
+
+ if (sa->zm_pos == zm)
+ continue_store_activity (sa);
+ sa = sn;
+ }
+ if (zm->limit > zm->iteration_cnt)
+ zm->sa_waiting = GNUNET_NO;
+}
+
+
/**
* Send 'sync' message to zone monitor, we're now in sync.
*
GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC);
GNUNET_MQ_send (zm->nc->mq,
env);
+ /* mark iteration done */
+ zm->in_first_iteration = GNUNET_NO;
+ zm->iteration_cnt = 0;
+ if ( (zm->limit > 0) &&
+ (zm->sa_waiting) )
+ monitor_unblock (zm);
}
/**
- * Obtain the next datum during the zone monitor's zone intiial iteration.
+ * Obtain the next datum during the zone monitor's zone initial iteration.
*
* @param cls zone monitor that does its initial iteration
*/
static void
-monitor_next (void *cls);
+monitor_iteration_next (void *cls);
/**
"Monitor notifications sent",
1,
GNUNET_NO);
+ zm->limit--;
+ zm->iteration_cnt--;
send_lookup_response (zm->nc,
0,
zone_key,
name,
rd_count,
rd);
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
- zm);
+ if ( (0 == zm->iteration_cnt) &&
+ (0 != zm->limit) )
+ {
+ /* We are done with the current iteration batch, AND the
+ client would right now accept more, so go again! */
+ GNUNET_assert (NULL == zm->task);
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+ zm);
+ }
}
zm = GNUNET_new (struct ZoneMonitor);
zm->nc = nc;
zm->zone = zis_msg->zone;
+ zm->limit = 1;
+ zm->in_first_iteration = (GNUNET_YES == ntohl (zis_msg->iterate_first));
GNUNET_CONTAINER_DLL_insert (monitor_head,
monitor_tail,
zm);
GNUNET_SERVICE_client_continue (nc->client);
GNUNET_notification_context_add (monitor_nc,
nc->mq);
- if (GNUNET_YES == ntohl (zis_msg->iterate_first))
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
+ if (zm->in_first_iteration)
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
zm);
else
monitor_sync (zm);
* @param cls zone monitor that does its initial iteration
*/
static void
-monitor_next (void *cls)
+monitor_iteration_next (void *cls)
{
struct ZoneMonitor *zm = cls;
int ret;
zm->task = NULL;
+ GNUNET_assert (0 == zm->iteration_cnt);
+ if (zm->limit > 16)
+ zm->iteration_cnt = zm->limit / 2; /* leave half for monitor events */
+ else
+ zm->iteration_cnt = zm->limit; /* use it all */
ret = GSN_database->iterate_records (GSN_database->cls,
(0 == memcmp (&zm->zone,
&zero,
? NULL
: &zm->zone,
zm->seq,
- 1,
+ zm->iteration_cnt,
&monitor_iterate_cb,
zm);
if (GNUNET_SYSERR == ret)
return;
}
zm->limit += inc;
-#if 0
- if (GNUNET_YES == ntohl (zis_msg->iterate_first))
- zm->task = GNUNET_SCHEDULER_add_now (&monitor_next,
- zm);
- else
- monitor_sync (zm);
-#endif
+ if ( (zm->in_first_iteration) &&
+ (zm->limit == inc) )
+ {
+ /* We are still iterating, and the previous iteration must
+ have stopped due to the client's limit, so continue it! */
+ GNUNET_assert (NULL == zm->task);
+ zm->task = GNUNET_SCHEDULER_add_now (&monitor_iteration_next,
+ zm);
+ }
+ GNUNET_assert (zm->iteration_cnt <= zm->limit);
+ if ( (zm->limit > zm->iteration_cnt) &&
+ (zm->sa_waiting) )
+ monitor_unblock (zm);
}
&record_data_b64);
}
GNUNET_asprintf (&line,
- "%s,%lu,%u,%s,%s\n",
+ "%s,%llu,%u,%s,%s\n",
zone_private_key,
- entry->rvalue,
- entry->record_count,
+ (unsigned long long) entry->rvalue,
+ (unsigned int) entry->record_count,
record_data_b64,
entry->label);
GNUNET_free (record_data_b64);
};
-/**
- * @brief Prepare a SQL statement
- *
- * @param dbh handle to the database
- * @param zSql SQL statement, UTF-8 encoded
- * @param ppStmt set to the prepared statement
- * @return 0 on success
- */
-static int
-sq_prepare (sqlite3 *dbh,
- const char *zSql,
- sqlite3_stmt **ppStmt)
-{
- char *dummy;
- int result;
-
- result =
- sqlite3_prepare_v2 (dbh,
- zSql,
- strlen (zSql),
- ppStmt,
- (const char **) &dummy);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Prepared `%s' / %p: %d\n",
- zSql,
- *ppStmt,
- result);
- return result;
-}
-
-
-/**
- * Create our database indices.
- *
- * @param dbh handle to the database
- */
-static void
-create_indices (sqlite3 * dbh)
-{
- /* create indices */
- if ( (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
- "ON ns098records (zone_private_key,pkey)",
- NULL, NULL, NULL)) ||
- (SQLITE_OK !=
- sqlite3_exec (dbh,
- "CREATE INDEX IF NOT EXISTS ir_pkey_iter "
- "ON ns098records (zone_private_key,uid)",
- NULL, NULL, NULL)) )
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create indices: %s\n",
- sqlite3_errmsg (dbh));
-}
-
-
-#if 0
-#define CHECK(a) GNUNET_break(a)
-#define ENULL NULL
-#else
-#define ENULL &e
-#define ENULL_DEFINED 1
-#define CHECK(a) if (! (a)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s\n", e); sqlite3_free(e); }
-#endif
-
-
/**
* Initialize the database connections and associated
* data structures (create tables and indices
static int
database_setup (struct Plugin *plugin)
{
- sqlite3_stmt *stmt;
- char *afsdir;
-#if ENULL_DEFINED
- char *e;
-#endif
+ char *sqlite_filename;
+ struct GNUNET_SQ_ExecuteStatement es[] = {
+ GNUNET_SQ_make_try_execute ("PRAGMA temp_store=MEMORY"),
+ GNUNET_SQ_make_try_execute ("PRAGMA synchronous=NORMAL"),
+ GNUNET_SQ_make_try_execute ("PRAGMA legacy_file_format=OFF"),
+ GNUNET_SQ_make_try_execute ("PRAGMA auto_vacuum=INCREMENTAL"),
+ GNUNET_SQ_make_try_execute ("PRAGMA encoding=\"UTF-8\""),
+ GNUNET_SQ_make_try_execute ("PRAGMA locking_mode=EXCLUSIVE"),
+ GNUNET_SQ_make_try_execute ("PRAGMA page_size=4092"),
+ GNUNET_SQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records ("
+ " uid INTEGER PRIMARY KEY,"
+ " zone_private_key BLOB NOT NULL,"
+ " pkey BLOB,"
+ " rvalue INT8 NOT NULL,"
+ " record_count INT NOT NULL,"
+ " record_data BLOB NOT NULL,"
+ " label TEXT NOT NULL"
+ ")"),
+ GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse "
+ "ON ns098records (zone_private_key,pkey)"),
+ GNUNET_SQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter "
+ "ON ns098records (zone_private_key,uid)"),
+ GNUNET_SQ_EXECUTE_STATEMENT_END
+ };
+ struct GNUNET_SQ_PrepareStatement ps[] = {
+ GNUNET_SQ_make_prepare ("INSERT INTO ns098records "
+ "(zone_private_key,pkey,rvalue,record_count,record_data,label)"
+ " VALUES (?, ?, ?, ?, ?, ?)",
+ &plugin->store_records),
+ GNUNET_SQ_make_prepare ("DELETE FROM ns098records "
+ "WHERE zone_private_key=? AND label=?",
+ &plugin->delete_records),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND pkey=?",
+ &plugin->zone_to_name),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND _rowid_ >= ?"
+ " ORDER BY _rowid_ ASC"
+ " LIMIT ?",
+ &plugin->iterate_zone),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
+ " FROM ns098records"
+ " WHERE _rowid_ >= ?"
+ " ORDER BY _rowid_ ASC"
+ " LIMIT ?",
+ &plugin->iterate_all_zones),
+ GNUNET_SQ_make_prepare ("SELECT uid,record_count,record_data,label,zone_private_key"
+ " FROM ns098records"
+ " WHERE zone_private_key=? AND label=?",
+ &plugin->lookup_label),
+ GNUNET_SQ_PREPARE_END
+ };
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (plugin->cfg,
"namestore-sqlite",
"FILENAME",
- &afsdir))
+ &sqlite_filename))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"namestore-sqlite",
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_test (afsdir))
+ GNUNET_DISK_file_test (sqlite_filename))
{
if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (afsdir))
+ GNUNET_DISK_directory_create_for_file (sqlite_filename))
{
GNUNET_break (0);
- GNUNET_free (afsdir);
+ GNUNET_free (sqlite_filename);
return GNUNET_SYSERR;
}
}
- /* afsdir should be UTF-8-encoded. If it isn't, it's a bug */
- plugin->fn = afsdir;
+ /* sqlite_filename should be UTF-8-encoded. If it isn't, it's a bug */
+ plugin->fn = sqlite_filename;
/* Open database and precompile statements */
- if (sqlite3_open (plugin->fn, &plugin->dbh) != SQLITE_OK)
+ if (SQLITE_OK !=
+ sqlite3_open (plugin->fn,
+ &plugin->dbh))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_("Unable to initialize SQLite: %s.\n"),
sqlite3_errmsg (plugin->dbh));
return GNUNET_SYSERR;
}
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA temp_store=MEMORY", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA synchronous=NORMAL", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA legacy_file_format=OFF", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA auto_vacuum=INCREMENTAL", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA encoding=\"UTF-8\"", NULL,
- NULL, ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL,
- ENULL));
- CHECK (SQLITE_OK ==
- sqlite3_exec (plugin->dbh,
- "PRAGMA page_size=4092", NULL, NULL,
- ENULL));
-
- CHECK (SQLITE_OK ==
- sqlite3_busy_timeout (plugin->dbh,
- BUSY_TIMEOUT_MS));
-
-
- /* Create table */
- CHECK (SQLITE_OK ==
- sq_prepare (plugin->dbh,
- "SELECT 1 FROM sqlite_master WHERE tbl_name = 'ns098records'",
- &stmt));
- if ( (sqlite3_step (stmt) == SQLITE_DONE) &&
- (SQLITE_OK !=
- sqlite3_exec (plugin->dbh,
- "CREATE TABLE ns098records ("
- " uid INTEGER PRIMARY KEY,"
- " zone_private_key BLOB NOT NULL,"
- " pkey BLOB,"
- " rvalue INT8 NOT NULL,"
- " record_count INT NOT NULL,"
- " record_data BLOB NOT NULL,"
- " label TEXT NOT NULL"
- ")",
- NULL, NULL, NULL)) )
+ GNUNET_break (SQLITE_OK ==
+ sqlite3_busy_timeout (plugin->dbh,
+ BUSY_TIMEOUT_MS));
+ if (GNUNET_OK !=
+ GNUNET_SQ_exec_statements (plugin->dbh,
+ es))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "sqlite3_exec");
- sqlite3_finalize (stmt);
+ GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to setup database at `%s'\n"),
+ plugin->fn);
return GNUNET_SYSERR;
}
- sqlite3_finalize (stmt);
-
- create_indices (plugin->dbh);
-
- if ( (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
- " VALUES (?, ?, ?, ?, ?, ?)",
- &plugin->store_records)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "DELETE FROM ns098records WHERE zone_private_key=? AND label=?",
- &plugin->delete_records)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label"
- " FROM ns098records"
- " WHERE zone_private_key=? AND pkey=?",
- &plugin->zone_to_name)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label"
- " FROM ns098records"
- " WHERE zone_private_key=? AND _rowid_ >= ?"
- " ORDER BY _rowid_ ASC"
- " LIMIT ?",
- &plugin->iterate_zone)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label,zone_private_key"
- " FROM ns098records"
- " WHERE _rowid_ >= ?"
- " ORDER BY _rowid_ ASC"
- " LIMIT ?",
- &plugin->iterate_all_zones)) ||
- (SQLITE_OK !=
- sq_prepare (plugin->dbh,
- "SELECT uid,record_count,record_data,label,zone_private_key"
- " FROM ns098records"
- " WHERE zone_private_key=? AND label=?",
- &plugin->lookup_label))
- )
+
+ if (GNUNET_OK !=
+ GNUNET_SQ_prepare (plugin->dbh,
+ ps))
{
- LOG_SQLITE (plugin,
- GNUNET_ERROR_TYPE_ERROR,
- "precompiling");
+ GNUNET_break (0);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to setup database at `%s'\n"),
+ plugin->fn);
return GNUNET_SYSERR;
}
return GNUNET_OK;
//static const char * name = "dummy.dummy.gnunet";
static const char * name = "d";
-static char *directory;
static void
cleanup ()
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, TEST_NICK, &nick_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ privkey,
+ TEST_NICK,
+ &nick_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-nick",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
//static const char * name = "dummy.dummy.gnunet";
static const char * name = "d";
-static char *directory;
static void
cleanup ()
* Re-establish the connection to the service.
*
* @param cls handle to use to re-connect.
- * @param tc scheduler context
*/
static void
endbadly (void *cls)
{
+ endbadly_task = NULL;
if (NULL != nsqe)
{
GNUNET_NAMESTORE_cancel (nsqe);
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL );
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
/* Done */
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
- GNUNET_SCHEDULER_add_now (&end, NULL );
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
const char *name = cls;
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-private",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMECACHE_QueueEntry *ncqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nsh);
GNUNET_break (NULL != nch);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow",
res = 1;
}
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
return res;
}
static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
-static char *directory;
static void
cleanup ()
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
- record_expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), EXPIRATION);
+ record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
+ EXPIRATION);
records[0].expiration_time = record_expiration.abs_value_us;
records[0].record_type = TEST_RECORD_TYPE;
records[0].data_size = TEST_RECORD_DATALEN;
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-lookup-shadow-filter",
res = 1;
}
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
return res;
}
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
-static char *directory;
static void
do_shutdown ()
GNUNET_NAMESTORE_zone_monitor_stop (zm);
zm = NULL;
}
-
if (NULL != ns_ops[0])
{
GNUNET_NAMESTORE_cancel(ns_ops[0]);
GNUNET_NAMESTORE_cancel(ns_ops[2]);
ns_ops[2] = NULL;
}
-
if (NULL != nsh)
{
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
}
-
GNUNET_free_non_null(s_name_1);
GNUNET_free_non_null(s_name_2);
GNUNET_free_non_null(s_name_3);
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
res = 1;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
/* Start monitoring */
return;
}
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record 3\n");
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
"Created record 1\n");
GNUNET_asprintf(&s_name_1, "dummy1");
s_rd_1 = create_record(1);
- GNUNET_assert (NULL != (ns_ops[0] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_1,
- 1, s_rd_1, &put_cont, s_name_1)));
+ GNUNET_assert (NULL != (ns_ops[0] =
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_1,
+ 1,
+ s_rd_1,
+ &put_cont,
+ s_name_1)));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
s_rd_2 = create_record(1);
- GNUNET_assert (NULL != (ns_ops[1] = GNUNET_NAMESTORE_records_store(nsh, privkey, s_name_2,
- 1, s_rd_2, &put_cont, s_name_2)));
-
-
+ GNUNET_assert (NULL != (ns_ops[1] =
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ s_name_2,
+ 1,
+ s_rd_2,
+ &put_cont,
+ s_name_2)));
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
const char *plugin_name;
char *cfg_name;
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-monitoring",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
struct GNUNET_NAMESTORE_QueueEntry * ns_ops[3];
-static char *directory;
-
static void
do_shutdown ()
const struct GNUNET_CONFIGURATION_Handle *mycfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (mycfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
res = 1;
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
cfg = mycfg;
- endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
/* Connect to namestore */
nsh = GNUNET_NAMESTORE_connect (cfg);
if (NULL == nsh)
return;
}
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-monitoring-existing",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
&pubkey);
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
rd.flags = 0;
- memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
+ memset ((char *) rd.data,
+ 'a',
+ TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-remove",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_assert (NULL != cls);
nsqe = NULL;
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- switch (success) {
+ switch (success)
+ {
case GNUNET_NO:
/* We expected GNUNET_NO, since record was not found */
GNUNET_SCHEDULER_add_now (&end, NULL);
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-remove-non-existing-record",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
static void
cleanup ()
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
const char * name = "dummy.dummy.gnunet";
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
/*
This file is part of GNUnet.
- Copyright (C) 2012, 2013 GNUnet e.V.
+ Copyright (C) 2012, 2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* @file namestore/test_namestore_api_store_update.c
* @brief testcase for namestore_api.c: store a record, update it and perform a lookup
* @author Matthias Wachs
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_namecache_service.h"
#define TEST_RECORD_DATA 'a'
-
#define TEST_RECORD_TYPE2 4321
#define TEST_RECORD_DATALEN2 234
static const char *name = "dummy";
-static char *directory;
+/**
+ * Terminate test with error.
+ *
+ * @param cls handle to use to re-connect.
+ */
static void
-cleanup ()
+endbadly (void *cls)
{
- if (NULL != nsh)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- if (NULL != nch)
- {
- GNUNET_NAMECACHE_disconnect (nch);
- nch = NULL;
- }
- if (NULL != privkey)
- {
- GNUNET_free (privkey);
- privkey = NULL;
- }
+ GNUNET_break (0);
+ endbadly_task = NULL;
GNUNET_SCHEDULER_shutdown ();
+ res = 1;
}
-/**
- * Re-establish the connection to the service.
- *
- * @param cls handle to use to re-connect.
- */
static void
-endbadly (void *cls)
+end (void *cls)
{
+ if (NULL != endbadly_task)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = NULL;
+ }
if (NULL != nsqe)
{
GNUNET_NAMESTORE_cancel (nsqe);
GNUNET_NAMECACHE_cancel (ncqe);
ncqe = NULL;
}
- cleanup ();
- res = 1;
-}
-
-
-static void
-end (void *cls)
-{
- cleanup ();
- res = 0;
+ if (NULL != nsh)
+ {
+ GNUNET_NAMESTORE_disconnect (nsh);
+ nsh = NULL;
+ }
+ if (NULL != nch)
+ {
+ GNUNET_NAMECACHE_disconnect (nch);
+ nch = NULL;
+ }
+ if (NULL != privkey)
+ {
+ GNUNET_free (privkey);
+ privkey = NULL;
+ }
}
static void
-put_cont (void *cls, int32_t success, const char *emsg);
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg);
static void
if (GNUNET_NO == update_performed)
{
char rd_cmp_data[TEST_RECORD_DATALEN];
- memset (rd_cmp_data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ memset (rd_cmp_data,
+ TEST_RECORD_DATA,
+ TEST_RECORD_DATALEN);
GNUNET_assert (TEST_RECORD_TYPE == rd[0].record_type);
GNUNET_assert (TEST_RECORD_DATALEN == rd[0].data_size);
- GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN));
+ GNUNET_assert (0 == memcmp (&rd_cmp_data,
+ rd[0].data,
+ TEST_RECORD_DATALEN));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Block was decrypted successfully, updating record \n");
rd_new.record_type = TEST_RECORD_TYPE2;
rd_new.data_size = TEST_RECORD_DATALEN2;
rd_new.data = GNUNET_malloc (TEST_RECORD_DATALEN2);
- memset ((char *) rd_new.data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+ memset ((char *) rd_new.data,
+ TEST_RECORD_DATA2,
+ TEST_RECORD_DATALEN2);
- nsqe = GNUNET_NAMESTORE_records_store (nsh, privkey, name,
- 1, &rd_new, &put_cont, (void *) name);
+ nsqe = GNUNET_NAMESTORE_records_store (nsh,
+ privkey,
+ name,
+ 1,
+ &rd_new,
+ &put_cont,
+ (void *) name);
update_performed = GNUNET_YES;
}
else
{
char rd_cmp_data[TEST_RECORD_DATALEN2];
- memset (rd_cmp_data, TEST_RECORD_DATA2, TEST_RECORD_DATALEN2);
+ memset (rd_cmp_data,
+ TEST_RECORD_DATA2,
+ TEST_RECORD_DATALEN2);
GNUNET_assert (TEST_RECORD_TYPE2 == rd[0].record_type);
GNUNET_assert (TEST_RECORD_DATALEN2 == rd[0].data_size);
- GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[0].data, TEST_RECORD_DATALEN2));
-
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = NULL;
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_assert (0 == memcmp (&rd_cmp_data,
+ rd[0].data,
+ TEST_RECORD_DATALEN2));
+ GNUNET_SCHEDULER_shutdown ();
+ res = 0;
}
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Namecache returned no block for `%s'\n"),
name);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Namecache returned block, decrypting \n");
- GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt(block,
- &pubkey, name, &rd_decrypt_cb, (void *) name));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_GNSRECORD_block_decrypt (block,
+ &pubkey,
+ name,
+ &rd_decrypt_cb,
+ (void *) name));
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
const char *name = cls;
struct GNUNET_HashCode derived_hash;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Looking in namecache for `%s'\n",
GNUNET_h2s (&derived_hash));
- ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash,
+ ncqe = GNUNET_NAMECACHE_lookup_block (nch,
+ &derived_hash,
&name_lookup_proc, (void *) name);
}
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_GNSRECORD_Data rd;
- char *hostkey_file;
-
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory));
- GNUNET_DISK_directory_remove (directory);
update_performed = GNUNET_NO;
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
- &endbadly, NULL);
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ &endbadly,
+ NULL);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_ecdsa_key_get_public (privkey, &pubkey);
-
+ GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
+ &pubkey);
rd.flags = GNUNET_GNSRECORD_RF_NONE;
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
- memset ((char *) rd.data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
+ memset ((char *) rd.data,
+ TEST_RECORD_DATA,
+ TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
nch = GNUNET_NAMECACHE_connect (cfg);
GNUNET_break (NULL != nch);
nsqe = GNUNET_NAMESTORE_records_store (nsh,
- privkey, name,
- 1, &rd,
- &put_cont, (void *) name);
+ privkey,
+ name,
+ 1,
+ &rd,
+ &put_cont,
+ (void *) name);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
const char *plugin_name;
char *cfg_name;
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-store-update",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
-/* end of test_namestore_api_store_update.c*/
+/* end of test_namestore_api_store_update.c */
/*
This file is part of GNUnet.
- Copyright (C) 2013 GNUnet e.V.
+ Copyright (C) 2013, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
-
/**
* Re-establish the connection to the service.
static void
endbadly (void *cls)
{
- if (NULL != zi)
- {
- GNUNET_NAMESTORE_zone_iteration_stop (zi);
- zi = NULL;
- }
- if (nsh != NULL)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- GNUNET_free_non_null(s_name_1);
- GNUNET_free_non_null(s_name_2);
- GNUNET_free_non_null(s_name_3);
-
- if (s_rd_1 != NULL)
- {
- GNUNET_free ((void *)s_rd_1->data);
- GNUNET_free (s_rd_1);
- }
- if (s_rd_2 != NULL)
- {
- GNUNET_free ((void *)s_rd_2->data);
- GNUNET_free (s_rd_2);
- }
- if (s_rd_3 != NULL)
- {
- GNUNET_free ((void *)s_rd_3->data);
- GNUNET_free (s_rd_3);
- }
-
- if (privkey != NULL)
- GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
- GNUNET_free (privkey2);
- privkey2 = NULL;
+ endbadly_task = NULL;
+ GNUNET_SCHEDULER_shutdown ();
res = 1;
}
GNUNET_NAMESTORE_zone_iteration_stop (zi);
zi = NULL;
}
- if (endbadly_task != NULL)
+ if (NULL != endbadly_task)
{
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
-
- if (privkey != NULL)
+ if (NULL != privkey)
+ {
GNUNET_free (privkey);
- privkey = NULL;
-
- if (privkey2 != NULL)
+ privkey = NULL;
+ }
+ if (NULL != privkey2)
+ {
GNUNET_free (privkey2);
- privkey2 = NULL;
-
+ privkey2 = NULL;
+ }
GNUNET_free (s_name_1);
GNUNET_free (s_name_2);
GNUNET_free (s_name_3);
- if (s_rd_1 != NULL)
+ if (NULL != s_rd_1)
{
GNUNET_free ((void *)s_rd_1->data);
GNUNET_free (s_rd_1);
}
- if (s_rd_2 != NULL)
+ if (NULL != s_rd_2)
{
GNUNET_free ((void *)s_rd_2->data);
GNUNET_free (s_rd_2);
}
- if (s_rd_3 != NULL)
+ if (NULL != s_rd_3)
{
GNUNET_free ((void *)s_rd_3->data);
GNUNET_free (s_rd_3);
}
- if (nsh != NULL)
+ if (NULL != nsh)
+ {
GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
+ nsh = NULL;
+ }
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received last result, iteration done after receing %u results\n",
returned_records);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
int failed = GNUNET_NO;
GNUNET_assert (NULL != zone);
- if (0 == memcmp (zone, privkey, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ if (0 == memcmp (zone,
+ privkey,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
if (0 == strcmp (label, s_name_1))
{
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing result failed: got name `%s' for first zone\n", label);
+ "Comparing result failed: got name `%s' for first zone\n",
+ label);
failed = GNUNET_YES;
GNUNET_break (0);
}
}
- else if (0 == memcmp (zone, privkey2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
+ else if (0 == memcmp (zone,
+ privkey2,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))
{
if (0 == strcmp (label, s_name_3))
{
else
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Comparing result failed: got name `%s' for first zone\n", label);
+ "Comparing result failed: got name `%s' for first zone\n",
+ label);
failed = GNUNET_YES;
GNUNET_break (0);
}
else
{
GNUNET_break (0);
- GNUNET_SCHEDULER_add_now (&end, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
}
}
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
static int c = 0;
if (success == GNUNET_OK)
{
c++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Created record %u \n",
+ c);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records: `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to created records: `%s'\n",
emsg);
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
{
res = 1;
returned_records = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "All records created, starting iteration over all zones \n");
zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
NULL,
&fail_cb,
NULL);
if (zi == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
- if (NULL != endbadly_task)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
}
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
struct GNUNET_GNSRECORD_Data * rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected empty zone but received zone private key\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
if ((NULL != label) || (NULL != rd) || (0 != rd_count))
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Expected no zone content but received data\n"));
GNUNET_break (0);
- if (endbadly_task != NULL)
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ res = 1;
return;
}
GNUNET_assert (0);
"zonefiles%s%s",
DIR_SEPARATOR_STR,
"HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Using zonekey file `%s' \n",
+ hostkey_file);
privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey2 != NULL);
privkey,
s_name_1,
1, s_rd_1,
- &put_cont, NULL);
-
+ &put_cont,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
GNUNET_asprintf(&s_name_2, "dummy2");
1, s_rd_2,
&put_cont,
NULL);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 3\n");
-
/* name in different zone */
GNUNET_asprintf(&s_name_3, "dummy3");
s_rd_3 = create_record(1);
- GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3,
- 1, s_rd_3,
- &put_cont, NULL);
+ GNUNET_NAMESTORE_records_store (nsh,
+ privkey2,
+ s_name_3,
+ 1,
+ s_rd_3,
+ &put_cont,
+ NULL);
}
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
+
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
/* first, iterate over empty namestore */
- zi = GNUNET_NAMESTORE_zone_iteration_start(nsh,
- NULL,
- &fail_cb,
- NULL,
- &empty_zone_proc,
- nsh,
- &empty_zone_end,
- NULL);
+ zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
+ NULL,
+ &fail_cb,
+ NULL,
+ &empty_zone_proc,
+ nsh,
+ &empty_zone_end,
+ NULL);
if (NULL == zi)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create zone iterator\n");
GNUNET_break (0);
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ res = 1;
+ GNUNET_SCHEDULER_shutdown ();
}
}
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
-static char *directory;
/**
* Re-establish the connection to the service.
static void
-put_cont (void *cls, int32_t success, const char *emsg)
+put_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
static int c = 0;
static struct GNUNET_GNSRECORD_Data *
create_record (unsigned int count)
{
- unsigned int c;
struct GNUNET_GNSRECORD_Data * rd;
- rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
- for (c = 0; c < count; c++)
+ rd = GNUNET_new_array (count,
+ struct GNUNET_GNSRECORD_Data);
+ for (unsigned int c = 0; c < count; c++)
{
rd[c].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS).abs_value_us;
rd[c].record_type = 1111;
static void
-nick_2_cont (void *cls, int32_t success, const char *emsg)
+nick_2_cont (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Nick added : %s\n",
static void
empty_zone_end (void *cls)
{
- char *hostkey_file;
GNUNET_assert (nsh == cls);
-
zi = NULL;
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
-
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
- nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey);
+ nsqe = GNUNET_NAMESTORE_set_nick (nsh,
+ privkey,
+ ZONE_NICK_1,
+ &nick_1_cont,
+ &privkey);
if (NULL == nsqe)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly,
+ NULL);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-nick",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static struct GNUNET_GNSRECORD_Data *s_rd_3;
-static char *directory;
/**
* Re-establish the connection to the service.
static void
empty_zone_proc_end (void *cls)
{
- char *hostkey_file;
-
zi = NULL;
- GNUNET_asprintf (&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s'\n",
- hostkey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey != NULL);
-
- GNUNET_asprintf(&hostkey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s' \n",
- hostkey_file);
- privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
- GNUNET_free (hostkey_file);
+ privkey2 = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (privkey2 != NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 1\n");
-
- GNUNET_asprintf(&s_name_1, "dummy1");
+ GNUNET_asprintf (&s_name_1,
+ "dummy1");
s_rd_1 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Created record 2 \n");
- GNUNET_asprintf(&s_name_2, "dummy2");
+ GNUNET_asprintf (&s_name_2,
+ "dummy2");
s_rd_2 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey,
"Created record 3\n");
/* name in different zone */
- GNUNET_asprintf(&s_name_3, "dummy3");
+ GNUNET_asprintf (&s_name_3,
+ "dummy3");
s_rd_3 = create_record (1);
GNUNET_NAMESTORE_records_store (nsh,
privkey2,
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
"Failed to create zone iterator\n");
GNUNET_break (0);
GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly,
+ NULL);
}
}
"test_namestore_api_%s.conf",
plugin_name);
res = 1;
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-iteration-specific-zone",
cfg_name,
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
static int res;
-static char *directory;
-
static struct GNUNET_NAMESTORE_QueueEntry *qe;
{
(void) cls;
(void) peer;
- directory = NULL;
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "PATHS",
- "GNUNET_TEST_HOME",
- &directory));
- GNUNET_DISK_directory_remove (directory);
-
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly,
NULL);
GNUNET_SCHEDULER_add_shutdown (&end,
NULL);
GNUNET_asprintf (&s_name, "dummy");
- /* load privat key */
- {
- char *zonekey_file;
-
- GNUNET_asprintf (&zonekey_file,
- "zonefiles%s%s",
- DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Using zonekey file `%s'\n",
- zonekey_file);
- privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
- GNUNET_free (zonekey_file);
- }
+ privkey = GNUNET_CRYPTO_ecdsa_key_create ();
GNUNET_assert (NULL != privkey);
/* get public key */
GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
GNUNET_asprintf (&cfg_name,
"test_namestore_api_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
res = 1;
if (0 !=
GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
{
res = 1;
}
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TEST_HOME");
GNUNET_free (cfg_name);
- if (NULL != directory)
- {
- GNUNET_DISK_directory_remove (directory);
- GNUNET_free (directory);
- }
return res;
}
sizeof (cfg_name),
"test_plugin_namestore_%s.conf",
plugin_name);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TMP");
GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
xargv,
"test-plugin-namestore",
options,
&run,
NULL);
+ GNUNET_DISK_purge_cfg_dir (cfg_name,
+ "GNUNET_TMP");
if (ok != 0)
FPRINTF (stderr,
"Missed some testcases: %d\n",
# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
if MINGW
WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
libgnunetsq_la_SOURCES = \
sq.c \
+ sq_exec.c \
+ sq_prepare.c \
sq_query_helper.c \
sq_result_helper.c
libgnunetsq_la_LIBADD = -lsqlite3 \
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_exec.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors are fatal.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_execute (const char *sql)
+ {
+ struct GNUNET_SQ_ExecuteStatement es = {
+ .sql = sql,
+ .ignore_errors = GNUNET_NO
+ };
+
+ return es;
+}
+
+
+
+/**
+ * Create a `struct GNUNET_SQ_ExecuteStatement` where errors should
+ * be tolerated.
+ *
+ * @param sql actual SQL statement
+ * @return initialized struct
+ */
+struct GNUNET_SQ_ExecuteStatement
+GNUNET_SQ_make_try_execute (const char *sql)
+{
+ struct GNUNET_SQ_ExecuteStatement es = {
+ .sql = sql,
+ .ignore_errors = GNUNET_YES
+ };
+
+ return es;
+}
+
+
+/**
+ * Request execution of an array of statements @a es from Postgres.
+ *
+ * @param dbh database to execute the statements over
+ * @param es #GNUNET_PQ_PREPARED_STATEMENT_END-terminated array of prepared
+ * statements.
+ * @return #GNUNET_OK on success (modulo statements where errors can be ignored)
+ * #GNUNET_SYSERR on error
+ */
+int
+GNUNET_SQ_exec_statements (sqlite3 *dbh,
+ const struct GNUNET_SQ_ExecuteStatement *es)
+{
+ for (unsigned int i=0;NULL != es[i].sql;i++)
+ {
+ char *emsg = NULL;
+
+ if (SQLITE_OK !=
+ sqlite3_exec (dbh,
+ es[i].sql,
+ NULL,
+ NULL,
+ &emsg))
+ {
+ if (es[i].ignore_errors)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to run SQL `%s': %s\n",
+ es[i].sql,
+ emsg);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run SQL `%s': %s\n",
+ es[i].sql,
+ emsg);
+ sqlite3_free (emsg);
+ return GNUNET_SYSERR;
+ }
+ sqlite3_free (emsg);
+ }
+ }
+ return GNUNET_OK;
+}
+
+/* end of sq_exec */
--- /dev/null
+/*
+ This file is part of GNUnet
+ Copyright (C) 2018 GNUnet e.V.
+
+ GNUnet is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNUnet; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file sq/sq_prepare.c
+ * @brief helper functions for executing SQL statements
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_sq_lib.h"
+
+
+/**
+ * Create a `struct GNUNET_SQ_PrepareStatement`
+ *
+ * @param sql actual SQL statement
+ * @param pstmt where to store the handle
+ * @return initialized struct
+ */
+struct GNUNET_SQ_PrepareStatement
+GNUNET_SQ_make_prepare (const char *sql,
+ sqlite3_stmt **pstmt)
+{
+ struct GNUNET_SQ_PrepareStatement ps = {
+ .sql = sql,
+ .pstmt = pstmt
+ };
+
+ return ps;
+}
+
+
+
+/**
+ * Prepare all statements given in the (NULL,NULL)-terminated
+ * array at @a ps
+ *
+ * @param dbh database to use
+ * @param ps array of statements to prepare
+ * @return #GNUNET_OK on success
+ */
+int
+GNUNET_SQ_prepare (sqlite3 *dbh,
+ const struct GNUNET_SQ_PrepareStatement *ps)
+{
+ for (unsigned int i=0;NULL != ps[i].sql;i++)
+ {
+ const char *epos = NULL;
+ int ret;
+
+ if (SQLITE_OK !=
+ (ret = sqlite3_prepare_v2 (dbh,
+ ps[i].sql,
+ strlen (ps[i].sql),
+ ps[i].pstmt,
+ &epos)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to prepare SQL `%s': error %d at %s\n",
+ ps[i].sql,
+ ret,
+ epos);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+/* end of sq_prepare.c */
/*
This file is part of GNUnet.
- Copyright (C) 2001--2013, 2016 GNUnet e.V.
+ Copyright (C) 2001--2013, 2016, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
return GNUNET_OK;
}
+
+/**
+ * Remove the directory given under @a option in
+ * section [PATHS] in configuration under @a cfg_filename
+ *
+ * @param cfg_filename configuration file to parse
+ * @param option option with the dir name to purge
+ */
+void
+GNUNET_DISK_purge_cfg_dir (const char *cfg_filename,
+ const char *option)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ char *tmpname;
+
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (cfg,
+ cfg_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PATHS",
+ option,
+ &tmpname))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "PATHS",
+ option);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ return;
+ }
+ GNUNET_CONFIGURATION_destroy (cfg);
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_directory_remove (tmpname))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "remove",
+ tmpname);
+ GNUNET_free (tmpname);
+ return;
+ }
+ GNUNET_free (tmpname);
+}
+
+
+
/* end of disk.c */