From 5746309cb4be2073d550ad7a6885e918631dbc38 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 15 Aug 2011 21:54:06 +0000 Subject: indentation --- src/datacache/datacache.c | 37 ++--- src/datacache/perf_datacache.c | 47 +++--- src/datacache/plugin_datacache_mysql.c | 247 +++++++++++------------------- src/datacache/plugin_datacache_postgres.c | 170 +++++++++----------- src/datacache/plugin_datacache_sqlite.c | 161 ++++++++----------- src/datacache/plugin_datacache_template.c | 14 +- src/datacache/test_datacache.c | 39 ++--- src/datacache/test_datacache_quota.c | 15 +- 8 files changed, 292 insertions(+), 438 deletions(-) (limited to 'src/datacache') diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index a17eb9628..9d12fbc3e 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c @@ -105,8 +105,8 @@ env_delete_notify (void *cls, const GNUNET_HashCode * key, size_t size) GNUNET_assert (h->utilization >= size); h->utilization -= size; GNUNET_CONTAINER_bloomfilter_remove (h->filter, key); - GNUNET_STATISTICS_update (h->stats, - gettext_noop ("# bytes stored"), -size, GNUNET_NO); + GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), -size, + GNUNET_NO); } @@ -131,16 +131,16 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_get_value_number (cfg, section, "QUOTA", "a)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("No `%s' specified for `%s' in configuration!\n"), - "QUOTA", section); + _("No `%s' specified for `%s' in configuration!\n"), "QUOTA", + section); return NULL; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, section, "DATABASE", &name)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("No `%s' specified for `%s' in configuration!\n"), - "DATABASE", section); + _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", + section); return NULL; } bf_size = quota / 32; /* 8 bit per entry, 1 bit per 32 kb in DB */ @@ -164,8 +164,8 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, ret->env.cls = ret; ret->env.delete_notify = &env_delete_notify; ret->env.quota = quota; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Loading `%s' datacache plugin\n"), name); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datacache plugin\n"), + name); GNUNET_asprintf (&libname, "libgnunet_plugin_datacache_%s", name); ret->short_name = name; ret->lib_name = libname; @@ -199,8 +199,8 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h) if (h->bloom_name != NULL) { if (0 != UNLINK (h->bloom_name)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", h->bloom_name); + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", + h->bloom_name); GNUNET_free (h->bloom_name); } GNUNET_STATISTICS_destroy (h->stats, GNUNET_NO); @@ -221,10 +221,8 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h) */ int GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, - const GNUNET_HashCode * key, - size_t size, - const char *data, - enum GNUNET_BLOCK_Type type, + const GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { uint32_t used; @@ -235,8 +233,8 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, GNUNET_break (0); return GNUNET_SYSERR; } - GNUNET_STATISTICS_update (h->stats, - gettext_noop ("# bytes stored"), size, GNUNET_NO); + GNUNET_STATISTICS_update (h->stats, gettext_noop ("# bytes stored"), size, + GNUNET_NO); GNUNET_CONTAINER_bloomfilter_add (h->filter, key); while (h->utilization + used > h->env.quota) GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls)); @@ -258,12 +256,11 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, */ unsigned int GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, - const GNUNET_HashCode * key, - enum GNUNET_BLOCK_Type type, + const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { - GNUNET_STATISTICS_update (h->stats, - gettext_noop ("# requests received"), 1, GNUNET_NO); + GNUNET_STATISTICS_update (h->stats, gettext_noop ("# requests received"), 1, + GNUNET_NO); if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, key)) { GNUNET_STATISTICS_update (h->stats, diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c index 3af76dbb6..a5dc02362 100644 --- a/src/datacache/perf_datacache.c +++ b/src/datacache/perf_datacache.c @@ -44,10 +44,9 @@ static const char *plugin_name; static int -checkIt (void *cls, - struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, - size_t size, const char *data, enum GNUNET_BLOCK_Type type) +checkIt (void *cls, struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, size_t size, const char *data, + enum GNUNET_BLOCK_Type type) { if ((size == sizeof (GNUNET_HashCode)) && (0 == memcmp (data, cls, size))) found++; @@ -56,9 +55,8 @@ checkIt (void *cls, static void -run (void *cls, - char *const *args, - const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_DATACACHE_Handle *h; GNUNET_HashCode k; @@ -86,21 +84,17 @@ run (void *cls, if (0 == i % (ITERATIONS / 80)) fprintf (stderr, "."); GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); - ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, - &k, - sizeof (GNUNET_HashCode), - (const char *) &n, - 1 + i % 16, exp)); + ASSERT (GNUNET_OK == + GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode), + (const char *) &n, 1 + i % 16, exp)); k = n; } fprintf (stderr, "\n"); - fprintf (stdout, "Stored %u items in %llums\n", - ITERATIONS, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value); + fprintf (stdout, "Stored %u items in %llums\n", ITERATIONS, + (unsigned long long) GNUNET_TIME_absolute_get_duration (start). + rel_value); GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name); - GAUGER (gstr, - "Time to PUT item in datacache", + GAUGER (gstr, "Time to PUT item in datacache", GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS, "ms/item"); start = GNUNET_TIME_absolute_get (); @@ -117,12 +111,10 @@ run (void *cls, fprintf (stdout, "Found %u/%u items in %llums (%u were deleted during storage processing)\n", found, ITERATIONS, - (unsigned long long) - GNUNET_TIME_absolute_get_duration (start).rel_value, - ITERATIONS - found); + (unsigned long long) GNUNET_TIME_absolute_get_duration (start). + rel_value, ITERATIONS - found); if (found > 0) - GAUGER (gstr, - "Time to GET item from datacache", + GAUGER (gstr, "Time to GET item from datacache", GNUNET_TIME_absolute_get_duration (start).rel_value / found, "ms/item"); GNUNET_DATACACHE_destroy (h); @@ -170,13 +162,12 @@ main (int argc, char *argv[]) else pos = (char *) plugin_name; - GNUNET_snprintf (cfg_name, - sizeof (cfg_name), - "perf_datacache_data_%s.conf", plugin_name); + GNUNET_snprintf (cfg_name, sizeof (cfg_name), "perf_datacache_data_%s.conf", + plugin_name); if (pos != plugin_name) pos[0] = '.'; - GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, - xargv, "perf-datacache", "nohelp", options, &run, NULL); + GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, + "perf-datacache", "nohelp", options, &run, NULL); if (ok != 0) fprintf (stderr, "Missed some perfcases: %d\n", ok); return ok; diff --git a/src/datacache/plugin_datacache_mysql.c b/src/datacache/plugin_datacache_mysql.c index f4530ccef..62787eea6 100644 --- a/src/datacache/plugin_datacache_mysql.c +++ b/src/datacache/plugin_datacache_mysql.c @@ -222,8 +222,8 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg) #endif GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); - if ((0 != STAT (cnffile, &st)) || - (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) + if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) || + (!S_ISREG (st.st_mode))) { if (configured == GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -303,9 +303,9 @@ iopen (struct Plugin *ret) mysql_options (ret->dbf, MYSQL_OPT_READ_TIMEOUT, (const void *) &timeout); mysql_options (ret->dbf, MYSQL_OPT_WRITE_TIMEOUT, (const void *) &timeout); mysql_dbname = NULL; - if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, - "datacache-mysql", - "DATABASE")) + if (GNUNET_YES == + GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql", + "DATABASE")) GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, "datacache-mysql", @@ -314,8 +314,9 @@ iopen (struct Plugin *ret) else mysql_dbname = GNUNET_strdup ("gnunet"); mysql_user = NULL; - if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, - "datacache-mysql", "USER")) + if (GNUNET_YES == + GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql", + "USER")) { GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, @@ -323,9 +324,9 @@ iopen (struct Plugin *ret) "USER", &mysql_user)); } mysql_password = NULL; - if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, - "datacache-mysql", - "PASSWORD")) + if (GNUNET_YES == + GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql", + "PASSWORD")) { GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, @@ -334,8 +335,9 @@ iopen (struct Plugin *ret) &mysql_password)); } mysql_server = NULL; - if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, - "datacache-mysql", "HOST")) + if (GNUNET_YES == + GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql", + "HOST")) { GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (ret->env->cfg, @@ -344,8 +346,9 @@ iopen (struct Plugin *ret) &mysql_server)); } mysql_port = 0; - if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (ret->env->cfg, - "datacache-mysql", "PORT")) + if (GNUNET_YES == + GNUNET_CONFIGURATION_have_value (ret->env->cfg, "datacache-mysql", + "PORT")) { GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (ret->env->cfg, @@ -450,8 +453,8 @@ prepare_statement (struct Plugin *plugin, * @return GNUNET_SYSERR on error, GNUNET_OK on success */ static int -init_params (struct Plugin *plugin, - struct GNUNET_MysqlStatementHandle *s, va_list ap) +init_params (struct Plugin *plugin, struct GNUNET_MysqlStatementHandle *s, + va_list ap) { MYSQL_BIND qbind[MAX_PARAM]; unsigned int pc; @@ -512,8 +515,8 @@ init_params (struct Plugin *plugin, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed at %s:%d with error: %s\n"), - "mysql_stmt_bind_param", - __FILE__, __LINE__, mysql_stmt_error (s->statement)); + "mysql_stmt_bind_param", __FILE__, __LINE__, + mysql_stmt_error (s->statement)); iclose (plugin); return GNUNET_SYSERR; } @@ -521,8 +524,8 @@ init_params (struct Plugin *plugin, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed at %s:%d with error: %s\n"), - "mysql_stmt_execute", - __FILE__, __LINE__, mysql_stmt_error (s->statement)); + "mysql_stmt_execute", __FILE__, __LINE__, + mysql_stmt_error (s->statement)); iclose (plugin); return GNUNET_SYSERR; } @@ -538,8 +541,7 @@ init_params (struct Plugin *plugin, * @param values values returned by MySQL * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort */ -typedef int (*GNUNET_MysqlDataProcessor) (void *cls, - unsigned int num_values, +typedef int (*GNUNET_MysqlDataProcessor) (void *cls, unsigned int num_values, MYSQL_BIND * values); @@ -561,12 +563,10 @@ typedef int (*GNUNET_MysqlDataProcessor) (void *cls, */ static int prepared_statement_run_select (struct Plugin *plugin, - struct GNUNET_MysqlStatementHandle - *s, - unsigned int result_size, - MYSQL_BIND * results, - GNUNET_MysqlDataProcessor - processor, void *processor_cls, ...) + struct GNUNET_MysqlStatementHandle *s, + unsigned int result_size, MYSQL_BIND * results, + GNUNET_MysqlDataProcessor processor, + void *processor_cls, ...) { va_list ap; int ret; @@ -596,8 +596,8 @@ prepared_statement_run_select (struct Plugin *plugin, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed at %s:%d with error: %s\n"), - "mysql_stmt_bind_result", - __FILE__, __LINE__, mysql_stmt_error (s->statement)); + "mysql_stmt_bind_result", __FILE__, __LINE__, + mysql_stmt_error (s->statement)); iclose (plugin); return GNUNET_SYSERR; } @@ -612,8 +612,8 @@ prepared_statement_run_select (struct Plugin *plugin, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed at %s:%d with error: %s\n"), - "mysql_stmt_fetch", - __FILE__, __LINE__, mysql_stmt_error (s->statement)); + "mysql_stmt_fetch", __FILE__, __LINE__, + mysql_stmt_error (s->statement)); iclose (plugin); return GNUNET_SYSERR; } @@ -676,17 +676,17 @@ static int itable (struct Plugin *plugin) { #define MRUNS(a) (GNUNET_OK != run_statement (plugin, a) ) - if (MRUNS ("CREATE TEMPORARY TABLE gn080dstore (" - " type INT(11) UNSIGNED NOT NULL DEFAULT 0," - " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0," - " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," - " hash BINARY(64) NOT NULL DEFAULT ''," - " vhash BINARY(64) NOT NULL DEFAULT ''," - " value BLOB NOT NULL DEFAULT ''," - " INDEX hashidx (hash(64),type,expire)," - " INDEX allidx (hash(64),vhash(64),type)," - " INDEX expireidx (puttime)" ") ENGINE=InnoDB") || - MRUNS ("SET AUTOCOMMIT = 1")) + if (MRUNS + ("CREATE TEMPORARY TABLE gn080dstore (" + " type INT(11) UNSIGNED NOT NULL DEFAULT 0," + " puttime BIGINT UNSIGNED NOT NULL DEFAULT 0," + " expire BIGINT UNSIGNED NOT NULL DEFAULT 0," + " hash BINARY(64) NOT NULL DEFAULT ''," + " vhash BINARY(64) NOT NULL DEFAULT ''," + " value BLOB NOT NULL DEFAULT ''," + " INDEX hashidx (hash(64),type,expire)," + " INDEX allidx (hash(64),vhash(64),type)," " INDEX expireidx (puttime)" + ") ENGINE=InnoDB") || MRUNS ("SET AUTOCOMMIT = 1")) return GNUNET_SYSERR; #undef MRUNS #define PINIT(a,b) (NULL == (a = prepared_statement_create(plugin, b))) @@ -714,11 +714,8 @@ itable (struct Plugin *plugin) * @return 0 on error, number of bytes used otherwise */ static size_t -mysql_plugin_put (void *cls, - const GNUNET_HashCode * key, - size_t size, - const char *data, - enum GNUNET_BLOCK_Type type, +mysql_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { struct Plugin *plugin = cls; @@ -745,23 +742,12 @@ mysql_plugin_put (void *cls, v_now = (unsigned long long) now.abs_value; v_discard_time = (unsigned long long) discard_time.abs_value; if (GNUNET_OK == - prepared_statement_run (plugin, - plugin->update_value, - NULL, - MYSQL_TYPE_LONGLONG, - &v_now, - GNUNET_YES, - MYSQL_TYPE_LONGLONG, - &v_discard_time, - GNUNET_YES, - MYSQL_TYPE_BLOB, - key, - sizeof (GNUNET_HashCode), - &k_length, - MYSQL_TYPE_BLOB, - &vhash, - sizeof (GNUNET_HashCode), - &h_length, + prepared_statement_run (plugin, plugin->update_value, NULL, + MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES, + MYSQL_TYPE_LONGLONG, &v_discard_time, GNUNET_YES, + MYSQL_TYPE_BLOB, key, sizeof (GNUNET_HashCode), + &k_length, MYSQL_TYPE_BLOB, &vhash, + sizeof (GNUNET_HashCode), &h_length, MYSQL_TYPE_LONG, &v_type, GNUNET_YES, -1)) return GNUNET_OK; @@ -770,29 +756,16 @@ mysql_plugin_put (void *cls, k_length = sizeof (GNUNET_HashCode); v_length = size; if (GNUNET_OK != - (ret = prepared_statement_run (plugin, - plugin->insert_value, - NULL, - MYSQL_TYPE_LONG, - &type, - GNUNET_YES, - MYSQL_TYPE_LONGLONG, - &v_now, - GNUNET_YES, - MYSQL_TYPE_LONGLONG, - &v_discard_time, - GNUNET_YES, - MYSQL_TYPE_BLOB, - key, - sizeof (GNUNET_HashCode), - &k_length, - MYSQL_TYPE_BLOB, - &vhash, - sizeof (GNUNET_HashCode), - &h_length, - MYSQL_TYPE_BLOB, - data, - (unsigned long) size, &v_length, -1))) + (ret = + prepared_statement_run (plugin, plugin->insert_value, NULL, + MYSQL_TYPE_LONG, &type, GNUNET_YES, + MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES, + MYSQL_TYPE_LONGLONG, &v_discard_time, GNUNET_YES, + MYSQL_TYPE_BLOB, key, sizeof (GNUNET_HashCode), + &k_length, MYSQL_TYPE_BLOB, &vhash, + sizeof (GNUNET_HashCode), &h_length, + MYSQL_TYPE_BLOB, data, (unsigned long) size, + &v_length, -1))) { if (ret == GNUNET_SYSERR) itable (plugin); @@ -821,10 +794,9 @@ return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values) * @return the number of results found */ static unsigned int -mysql_plugin_get (void *cls, - const GNUNET_HashCode * key, - enum GNUNET_BLOCK_Type type, - GNUNET_DATACACHE_Iterator iter, void *iter_cls) +mysql_plugin_get (void *cls, const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, + void *iter_cls) { struct Plugin *plugin = cls; MYSQL_BIND rbind[3]; @@ -852,22 +824,13 @@ mysql_plugin_get (void *cls, v_type = type; v_now = (unsigned long long) now.abs_value; if ((GNUNET_OK != - (ret = prepared_statement_run_select (plugin, - plugin->count_value, - 1, - rbind, - return_ok, - NULL, - MYSQL_TYPE_BLOB, - key, - sizeof - (GNUNET_HashCode), - &h_length, - MYSQL_TYPE_LONG, - &v_type, GNUNET_YES, - MYSQL_TYPE_LONGLONG, - &v_now, GNUNET_YES, - -1))) || (-1 == total)) + (ret = + prepared_statement_run_select (plugin, plugin->count_value, 1, rbind, + return_ok, NULL, MYSQL_TYPE_BLOB, key, + sizeof (GNUNET_HashCode), &h_length, + MYSQL_TYPE_LONG, &v_type, GNUNET_YES, + MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES, + -1))) || (-1 == total)) { if (ret == GNUNET_SYSERR) itable (plugin); @@ -890,25 +853,13 @@ mysql_plugin_get (void *cls, rbind[1].buffer = &v_expire; off = (off + 1) % total; if (GNUNET_OK != - (ret = prepared_statement_run_select (plugin, - plugin->select_value, - 2, - rbind, - return_ok, - NULL, - MYSQL_TYPE_BLOB, - key, - sizeof - (GNUNET_HashCode), - &h_length, - MYSQL_TYPE_LONG, - &v_type, - GNUNET_YES, - MYSQL_TYPE_LONGLONG, - &v_now, - GNUNET_YES, - MYSQL_TYPE_LONG, - &off, GNUNET_YES, -1))) + (ret = + prepared_statement_run_select (plugin, plugin->select_value, 2, rbind, + return_ok, NULL, MYSQL_TYPE_BLOB, key, + sizeof (GNUNET_HashCode), &h_length, + MYSQL_TYPE_LONG, &v_type, GNUNET_YES, + MYSQL_TYPE_LONGLONG, &v_now, GNUNET_YES, + MYSQL_TYPE_LONG, &off, GNUNET_YES, -1))) { if (ret == GNUNET_SYSERR) itable (plugin); @@ -965,32 +916,20 @@ mysql_plugin_del (void *cls) rbind[3].length = &v_length; rbind[3].buffer = buffer; if ((GNUNET_OK != - (ret = prepared_statement_run_select (plugin, - plugin->select_old_value, - 4, - rbind, - return_ok, - NULL, - -1))) || + (ret = + prepared_statement_run_select (plugin, plugin->select_old_value, 4, + rbind, return_ok, NULL, -1))) || (GNUNET_OK != - (ret = prepared_statement_run (plugin, - plugin->delete_value, - NULL, - MYSQL_TYPE_BLOB, - &v_key, - sizeof (GNUNET_HashCode), - &k_length, - MYSQL_TYPE_BLOB, - &vhash, - sizeof (GNUNET_HashCode), - &h_length, - MYSQL_TYPE_LONG, - &v_type, - GNUNET_YES, - MYSQL_TYPE_BLOB, - buffer, - (unsigned long) - sizeof (buffer), &v_length, -1)))) + (ret = + prepared_statement_run (plugin, plugin->delete_value, NULL, + MYSQL_TYPE_BLOB, &v_key, + sizeof (GNUNET_HashCode), &k_length, + MYSQL_TYPE_BLOB, &vhash, + sizeof (GNUNET_HashCode), &h_length, + MYSQL_TYPE_LONG, &v_type, GNUNET_YES, + MYSQL_TYPE_BLOB, buffer, + (unsigned long) sizeof (buffer), &v_length, + -1)))) { if (ret == GNUNET_SYSERR) itable (plugin); @@ -1036,8 +975,8 @@ libgnunet_plugin_datacache_mysql_init (void *cls) api->get = &mysql_plugin_get; api->put = &mysql_plugin_put; api->del = &mysql_plugin_del; - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, - "mysql", _("MySQL datacache running\n")); + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", + _("MySQL datacache running\n")); return api; } diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index fdc377b8f..c5730078a 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c @@ -61,9 +61,7 @@ struct Plugin * @return GNUNET_OK if the result is acceptable */ static int -check_result (struct Plugin *plugin, - PGresult * ret, - int expected_status, +check_result (struct Plugin *plugin, PGresult * ret, int expected_status, const char *command, const char *args, int line) { if (ret == NULL) @@ -78,9 +76,8 @@ check_result (struct Plugin *plugin, { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "datastore-postgres", - _("`%s:%s' failed at %s:%d with error: %s"), - command, args, __FILE__, line, - PQerrorMessage (plugin->dbh)); + _("`%s:%s' failed at %s:%d with error: %s"), command, args, + __FILE__, line, PQerrorMessage (plugin->dbh)); PQclear (ret); return GNUNET_SYSERR; } @@ -97,8 +94,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line) PGresult *ret; ret = PQexec (plugin->dbh, sql); - if (GNUNET_OK != check_result (plugin, - ret, PGRES_COMMAND_OK, "PQexec", sql, line)) + if (GNUNET_OK != + check_result (plugin, ret, PGRES_COMMAND_OK, "PQexec", sql, line)) return GNUNET_SYSERR; PQclear (ret); return GNUNET_OK; @@ -109,8 +106,8 @@ pq_exec (struct Plugin *plugin, const char *sql, int line) * Prepare SQL statement. */ static int -pq_prepare (struct Plugin *plugin, - const char *name, const char *sql, int nparms, int line) +pq_prepare (struct Plugin *plugin, const char *name, const char *sql, + int nparms, int line) { PGresult *ret; @@ -136,8 +133,8 @@ init_connection (struct Plugin *plugin) /* Open database and precompile statements */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, - "datacache-postgres", - "CONFIG", &conninfo)) + "datacache-postgres", "CONFIG", + &conninfo)) conninfo = NULL; plugin->dbh = PQconnectdb (conninfo == NULL ? "" : conninfo); GNUNET_free_non_null (conninfo); @@ -148,28 +145,27 @@ init_connection (struct Plugin *plugin) } if (PQstatus (plugin->dbh) != CONNECTION_OK) { - GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "datacache-postgres", _("Unable to initialize Postgres: %s"), PQerrorMessage (plugin->dbh)); PQfinish (plugin->dbh); plugin->dbh = NULL; return GNUNET_SYSERR; } - ret = PQexec (plugin->dbh, - "CREATE TEMPORARY TABLE gn090dc (" - " type INTEGER NOT NULL DEFAULT 0," - " discard_time BIGINT NOT NULL DEFAULT 0," - " key BYTEA NOT NULL DEFAULT ''," - " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); + ret = + PQexec (plugin->dbh, + "CREATE TEMPORARY TABLE gn090dc (" + " type INTEGER NOT NULL DEFAULT 0," + " discard_time BIGINT NOT NULL DEFAULT 0," + " key BYTEA NOT NULL DEFAULT ''," + " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); if ((ret == NULL) || ((PQresultStatus (ret) != PGRES_COMMAND_OK) && (0 != strcmp ("42P07", /* duplicate table */ PQresultErrorField (ret, PG_DIAG_SQLSTATE))))) { - (void) check_result (plugin, - ret, PGRES_COMMAND_OK, "CREATE TABLE", "gn090dc", - __LINE__); + (void) check_result (plugin, ret, PGRES_COMMAND_OK, "CREATE TABLE", + "gn090dc", __LINE__); PQfinish (plugin->dbh); plugin->dbh = NULL; return GNUNET_SYSERR; @@ -190,11 +186,12 @@ init_connection (struct Plugin *plugin) } PQclear (ret); #if 1 - ret = PQexec (plugin->dbh, - "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL"); + ret = + PQexec (plugin->dbh, + "ALTER TABLE gn090dc ALTER value SET STORAGE EXTERNAL"); if (GNUNET_OK != - check_result (plugin, - ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__)) + check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", + __LINE__)) { PQfinish (plugin->dbh); plugin->dbh = NULL; @@ -203,8 +200,8 @@ init_connection (struct Plugin *plugin) PQclear (ret); ret = PQexec (plugin->dbh, "ALTER TABLE gn090dc ALTER key SET STORAGE PLAIN"); if (GNUNET_OK != - check_result (plugin, - ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", __LINE__)) + check_result (plugin, ret, PGRES_COMMAND_OK, "ALTER TABLE", "gn090dc", + __LINE__)) { PQfinish (plugin->dbh); plugin->dbh = NULL; @@ -213,35 +210,22 @@ init_connection (struct Plugin *plugin) PQclear (ret); #endif if ((GNUNET_OK != - pq_prepare (plugin, - "getkt", + pq_prepare (plugin, "getkt", "SELECT discard_time,type,value FROM gn090dc " - "WHERE key=$1 AND type=$2 ", - 2, - __LINE__)) || + "WHERE key=$1 AND type=$2 ", 2, __LINE__)) || (GNUNET_OK != - pq_prepare (plugin, - "getk", + pq_prepare (plugin, "getk", "SELECT discard_time,type,value FROM gn090dc " - "WHERE key=$1", - 1, - __LINE__)) || + "WHERE key=$1", 1, __LINE__)) || (GNUNET_OK != - pq_prepare (plugin, - "getm", + pq_prepare (plugin, "getm", "SELECT length(value),oid,key FROM gn090dc " - "ORDER BY discard_time ASC LIMIT 1", - 0, - __LINE__)) || + "ORDER BY discard_time ASC LIMIT 1", 0, __LINE__)) || (GNUNET_OK != - pq_prepare (plugin, - "delrow", - "DELETE FROM gn090dc WHERE oid=$1", - 1, + pq_prepare (plugin, "delrow", "DELETE FROM gn090dc WHERE oid=$1", 1, __LINE__)) || (GNUNET_OK != - pq_prepare (plugin, - "put", + pq_prepare (plugin, "put", "INSERT INTO gn090dc (type, discard_time, key, value) " "VALUES ($1, $2, $3, $4)", 4, __LINE__))) { @@ -268,12 +252,11 @@ delete_by_rowid (struct Plugin *plugin, uint32_t rowid) const int paramFormats[] = { 1 }; PGresult *ret; - ret = PQexecPrepared (plugin->dbh, - "delrow", - 1, paramValues, paramLengths, paramFormats, 1); + ret = + PQexecPrepared (plugin->dbh, "delrow", 1, paramValues, paramLengths, + paramFormats, 1); if (GNUNET_OK != - check_result (plugin, - ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow", + check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "delrow", __LINE__)) { return GNUNET_SYSERR; @@ -295,11 +278,8 @@ delete_by_rowid (struct Plugin *plugin, uint32_t rowid) * @return 0 on error, number of bytes used otherwise */ static size_t -postgres_plugin_put (void *cls, - const GNUNET_HashCode * key, - size_t size, - const char *data, - enum GNUNET_BLOCK_Type type, +postgres_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { struct Plugin *plugin = cls; @@ -321,11 +301,12 @@ postgres_plugin_put (void *cls, }; const int paramFormats[] = { 1, 1, 1, 1 }; - ret = PQexecPrepared (plugin->dbh, - "put", 4, paramValues, paramLengths, paramFormats, 1); - if (GNUNET_OK != check_result (plugin, ret, - PGRES_COMMAND_OK, - "PQexecPrepared", "put", __LINE__)) + ret = + PQexecPrepared (plugin->dbh, "put", 4, paramValues, paramLengths, + paramFormats, 1); + if (GNUNET_OK != + check_result (plugin, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put", + __LINE__)) return GNUNET_SYSERR; PQclear (ret); return size + OVERHEAD; @@ -344,8 +325,7 @@ postgres_plugin_put (void *cls, * @return the number of results found */ static unsigned int -postgres_plugin_get (void *cls, - const GNUNET_HashCode * key, +postgres_plugin_get (void *cls, const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { @@ -368,19 +348,16 @@ postgres_plugin_get (void *cls, PGresult *res; cnt = 0; - res = PQexecPrepared (plugin->dbh, - (type == 0) ? "getk" : "getkt", - (type == 0) ? 1 : 2, - paramValues, paramLengths, paramFormats, 1); - if (GNUNET_OK != check_result (plugin, - res, - PGRES_TUPLES_OK, - "PQexecPrepared", - (type == 0) ? "getk" : "getkt", __LINE__)) + res = + PQexecPrepared (plugin->dbh, (type == 0) ? "getk" : "getkt", + (type == 0) ? 1 : 2, paramValues, paramLengths, + paramFormats, 1); + if (GNUNET_OK != + check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared", + (type == 0) ? "getk" : "getkt", __LINE__)) { #if DEBUG_POSTGRES - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres", "Ending iteration (postgres error)\n"); #endif return 0; @@ -390,8 +367,7 @@ postgres_plugin_get (void *cls, { /* no result */ #if DEBUG_POSTGRES - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres", "Ending iteration (no more results)\n"); #endif PQclear (res); @@ -402,8 +378,7 @@ postgres_plugin_get (void *cls, PQclear (res); return cnt; } - if ((3 != PQnfields (res)) || - (sizeof (uint64_t) != PQfsize (res, 0)) || + if ((3 != PQnfields (res)) || (sizeof (uint64_t) != PQfsize (res, 0)) || (sizeof (uint32_t) != PQfsize (res, 1))) { GNUNET_break (0); @@ -417,19 +392,16 @@ postgres_plugin_get (void *cls, type = ntohl (*(uint32_t *) PQgetvalue (res, i, 1)); size = PQgetlength (res, i, 2); #if DEBUG_POSTGRES - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres", "Found result of size %u bytes and type %u in database\n", (unsigned int) size, (unsigned int) type); #endif if (GNUNET_SYSERR == - iter (iter_cls, - expiration_time, - key, size, PQgetvalue (res, i, 2), (enum GNUNET_BLOCK_Type) type)) + iter (iter_cls, expiration_time, key, size, PQgetvalue (res, i, 2), + (enum GNUNET_BLOCK_Type) type)) { #if DEBUG_POSTGRES - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres", "Ending iteration (client error)\n"); #endif PQclear (res); @@ -458,14 +430,12 @@ postgres_plugin_del (void *cls) PGresult *res; res = PQexecPrepared (plugin->dbh, "getm", 0, NULL, NULL, NULL, 1); - if (GNUNET_OK != check_result (plugin, - res, - PGRES_TUPLES_OK, - "PQexecPrepared", "getm", __LINE__)) + if (GNUNET_OK != + check_result (plugin, res, PGRES_TUPLES_OK, "PQexecPrepared", "getm", + __LINE__)) { #if DEBUG_POSTGRES - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres", "Ending iteration (postgres error)\n"); #endif return 0; @@ -474,15 +444,13 @@ postgres_plugin_del (void *cls) { /* no result */ #if DEBUG_POSTGRES - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "datacache-postgres", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datacache-postgres", "Ending iteration (no more results)\n"); #endif PQclear (res); return GNUNET_SYSERR; } - if ((3 != PQnfields (res)) || - (sizeof (size) != PQfsize (res, 0)) || + if ((3 != PQnfields (res)) || (sizeof (size) != PQfsize (res, 0)) || (sizeof (oid) != PQfsize (res, 1)) || (sizeof (GNUNET_HashCode) != PQgetlength (res, 0, 2))) { @@ -528,8 +496,8 @@ libgnunet_plugin_datacache_postgres_init (void *cls) api->get = &postgres_plugin_get; api->put = &postgres_plugin_put; api->del = &postgres_plugin_del; - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, - "datacache-postgres", _("Postgres datacache running\n")); + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "datacache-postgres", + _("Postgres datacache running\n")); return api; } diff --git a/src/datacache/plugin_datacache_sqlite.c b/src/datacache/plugin_datacache_sqlite.c index 5f534227f..3d67ffc22 100644 --- a/src/datacache/plugin_datacache_sqlite.c +++ b/src/datacache/plugin_datacache_sqlite.c @@ -78,8 +78,8 @@ sq_prepare (sqlite3 * dbh, const char *zSql, /* SQL statement, UTF-8 encoded { /* OUT: Statement handle */ char *dummy; - return sqlite3_prepare (dbh, - zSql, strlen (zSql), ppStmt, (const char **) &dummy); + return sqlite3_prepare (dbh, zSql, strlen (zSql), ppStmt, + (const char **) &dummy); } @@ -95,11 +95,8 @@ sq_prepare (sqlite3 * dbh, const char *zSql, /* SQL statement, UTF-8 encoded * @return 0 on error, number of bytes used otherwise */ static size_t -sqlite_plugin_put (void *cls, - const GNUNET_HashCode * key, - size_t size, - const char *data, - enum GNUNET_BLOCK_Type type, +sqlite_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { struct Plugin *plugin = cls; @@ -109,48 +106,44 @@ sqlite_plugin_put (void *cls, #if DEBUG_DATACACHE_SQLITE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' of %u bytes with key `%4s' and expiration %llums\n", - "PUT", - (unsigned int) size, - GNUNET_h2s (key), + "PUT", (unsigned int) size, GNUNET_h2s (key), (unsigned long long) GNUNET_TIME_absolute_get_remaining (discard_time).rel_value); #endif dval = (int64_t) discard_time.abs_value; if (dval < 0) dval = INT64_MAX; - if (sq_prepare (plugin->dbh, - "INSERT INTO ds090 " - "(type, expire, key, value) " - "VALUES (?, ?, ?, ?)", &stmt) != SQLITE_OK) + if (sq_prepare + (plugin->dbh, + "INSERT INTO ds090 " "(type, expire, key, value) " "VALUES (?, ?, ?, ?)", + &stmt) != SQLITE_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); return 0; } if ((SQLITE_OK != sqlite3_bind_int (stmt, 1, type)) || (SQLITE_OK != sqlite3_bind_int64 (stmt, 2, dval)) || - (SQLITE_OK != sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode), - SQLITE_TRANSIENT)) || + (SQLITE_OK != + sqlite3_bind_blob (stmt, 3, key, sizeof (GNUNET_HashCode), + SQLITE_TRANSIENT)) || (SQLITE_OK != sqlite3_bind_blob (stmt, 4, data, size, SQLITE_TRANSIENT))) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_xxx"); sqlite3_finalize (stmt); return 0; } if (SQLITE_DONE != sqlite3_step (stmt)) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_step"); sqlite3_finalize (stmt); return 0; } if (SQLITE_OK != sqlite3_finalize (stmt)) - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_finalize"); return size + OVERHEAD; } @@ -168,10 +161,9 @@ sqlite_plugin_put (void *cls, * @return the number of results found */ static unsigned int -sqlite_plugin_get (void *cls, - const GNUNET_HashCode * key, - enum GNUNET_BLOCK_Type type, - GNUNET_DATACACHE_Iterator iter, void *iter_cls) +sqlite_plugin_get (void *cls, const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, + void *iter_cls) { struct Plugin *plugin = cls; sqlite3_stmt *stmt; @@ -187,16 +179,17 @@ sqlite_plugin_get (void *cls, now = GNUNET_TIME_absolute_get (); #if DEBUG_DATACACHE_SQLITE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Processing `%s' for key `%4s'\n", "GET", GNUNET_h2s (key)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Processing `%s' for key `%4s'\n", "GET", + GNUNET_h2s (key)); #endif - if (sq_prepare (plugin->dbh, - "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", - &stmt) != SQLITE_OK) + if (sq_prepare + (plugin->dbh, + "SELECT count(*) FROM ds090 WHERE key=? AND type=? AND expire >= ?", + &stmt) != SQLITE_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); return 0; } ntime = (int64_t) now.abs_value; @@ -204,12 +197,10 @@ sqlite_plugin_get (void *cls, if ((SQLITE_OK != sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT)) || - (SQLITE_OK != - sqlite3_bind_int (stmt, 2, type)) || + (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value))) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_xxx"); sqlite3_finalize (stmt); return 0; @@ -217,8 +208,7 @@ sqlite_plugin_get (void *cls, if (SQLITE_ROW != sqlite3_step (stmt)) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite_step"); sqlite3_finalize (stmt); return 0; @@ -233,27 +223,23 @@ sqlite_plugin_get (void *cls, while (cnt < total) { off = (off + 1) % total; - GNUNET_snprintf (scratch, - sizeof (scratch), + GNUNET_snprintf (scratch, sizeof (scratch), "SELECT value,expire FROM ds090 WHERE key=? AND type=? AND expire >= ? LIMIT 1 OFFSET %u", off); if (sq_prepare (plugin->dbh, scratch, &stmt) != SQLITE_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sq_prepare", __FILE__, __LINE__, - sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); return cnt; } if ((SQLITE_OK != sqlite3_bind_blob (stmt, 1, key, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT)) || - (SQLITE_OK != - sqlite3_bind_int (stmt, 2, type)) || + (SQLITE_OK != sqlite3_bind_int (stmt, 2, type)) || (SQLITE_OK != sqlite3_bind_int64 (stmt, 3, now.abs_value))) { - LOG_SQLITE (plugin->dbh, - GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + LOG_SQLITE (plugin->dbh, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "sqlite3_bind_xxx"); sqlite3_finalize (stmt); return cnt; @@ -301,13 +287,14 @@ sqlite_plugin_del (void *cls) #endif stmt = NULL; dstmt = NULL; - if (sq_prepare (plugin->dbh, - "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", - &stmt) != SQLITE_OK) + if (sq_prepare + (plugin->dbh, + "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1", + &stmt) != SQLITE_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); if (stmt != NULL) (void) sqlite3_finalize (stmt); return GNUNET_SYSERR; @@ -315,9 +302,8 @@ sqlite_plugin_del (void *cls) if (SQLITE_ROW != sqlite3_step (stmt)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sqlite3_step", __FILE__, __LINE__, - sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); (void) sqlite3_finalize (stmt); return GNUNET_SYSERR; } @@ -329,54 +315,44 @@ sqlite_plugin_del (void *cls) memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode)); if (SQLITE_OK != sqlite3_finalize (stmt)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sqlite3_step", __FILE__, __LINE__, - sqlite3_errmsg (plugin->dbh)); - if (sq_prepare (plugin->dbh, - "DELETE FROM ds090 " - "WHERE key=? AND value=? AND type=?", &dstmt) != SQLITE_OK) + _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); + if (sq_prepare + (plugin->dbh, "DELETE FROM ds090 " "WHERE key=? AND value=? AND type=?", + &dstmt) != SQLITE_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sq_prepare", __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sq_prepare", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); if (stmt != NULL) (void) sqlite3_finalize (stmt); return GNUNET_SYSERR; } if ((SQLITE_OK != - sqlite3_bind_blob (dstmt, - 1, &hc, - sizeof (GNUNET_HashCode), - SQLITE_TRANSIENT)) || - (SQLITE_OK != - sqlite3_bind_blob (dstmt, - 2, blob, - dsize, + sqlite3_bind_blob (dstmt, 1, &hc, sizeof (GNUNET_HashCode), SQLITE_TRANSIENT)) || - (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype))) + (SQLITE_OK != sqlite3_bind_blob (dstmt, 2, blob, dsize, SQLITE_TRANSIENT)) + || (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sqlite3_bind", __FILE__, __LINE__, - sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); (void) sqlite3_finalize (dstmt); return GNUNET_SYSERR; } if (sqlite3_step (dstmt) != SQLITE_DONE) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sqlite3_step", __FILE__, __LINE__, - sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); (void) sqlite3_finalize (dstmt); return GNUNET_SYSERR; } plugin->env->delete_notify (plugin->env->cls, &hc, dsize + OVERHEAD); if (SQLITE_OK != sqlite3_finalize (dstmt)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - _("`%s' failed at %s:%d with error: %s\n"), - "sqlite3_finalize", __FILE__, __LINE__, - sqlite3_errmsg (plugin->dbh)); + _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_finalize", + __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh)); return GNUNET_OK; } @@ -425,8 +401,7 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) SQLITE3_EXEC (dbh, "PRAGMA count_changes=OFF"); SQLITE3_EXEC (dbh, "PRAGMA page_size=4092"); SQLITE3_EXEC (dbh, - "CREATE TABLE ds090 (" - " type INTEGER NOT NULL DEFAULT 0," + "CREATE TABLE ds090 (" " type INTEGER NOT NULL DEFAULT 0," " expire INTEGER NOT NULL DEFAULT 0," " key BLOB NOT NULL DEFAULT ''," " value BLOB NOT NULL DEFAULT '')"); @@ -440,8 +415,8 @@ libgnunet_plugin_datacache_sqlite_init (void *cls) api->get = &sqlite_plugin_get; api->put = &sqlite_plugin_put; api->del = &sqlite_plugin_del; - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, - "sqlite", _("Sqlite datacache running\n")); + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "sqlite", + _("Sqlite datacache running\n")); return api; } @@ -474,22 +449,20 @@ libgnunet_plugin_datacache_sqlite_done (void *cls) #if SQLITE_VERSION_NUMBER >= 3007000 if (result == SQLITE_BUSY) { - GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, - "sqlite", + GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "sqlite", _ ("Tried to close sqlite without finalizing all prepared statements.\n")); stmt = sqlite3_next_stmt (plugin->dbh, NULL); while (stmt != NULL) { #if DEBUG_SQLITE - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "sqlite", "Closing statement %p\n", stmt); + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", + "Closing statement %p\n", stmt); #endif result = sqlite3_finalize (stmt); #if DEBUG_SQLITE if (result != SQLITE_OK) - GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, - "sqlite", + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "sqlite", "Failed to close statement %p: %d\n", stmt, result); #endif stmt = sqlite3_next_stmt (plugin->dbh, NULL); diff --git a/src/datacache/plugin_datacache_template.c b/src/datacache/plugin_datacache_template.c index 865f431d7..046c603ad 100644 --- a/src/datacache/plugin_datacache_template.c +++ b/src/datacache/plugin_datacache_template.c @@ -52,11 +52,8 @@ struct Plugin * @return 0 on error, number of bytes used otherwise */ static size_t -template_plugin_put (void *cls, - const GNUNET_HashCode * key, - size_t size, - const char *data, - enum GNUNET_BLOCK_Type type, +template_plugin_put (void *cls, const GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute discard_time) { GNUNET_break (0); @@ -76,8 +73,7 @@ template_plugin_put (void *cls, * @return the number of results found */ static unsigned int -template_plugin_get (void *cls, - const GNUNET_HashCode * key, +template_plugin_get (void *cls, const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls) { @@ -121,8 +117,8 @@ libgnunet_plugin_datacache_template_init (void *cls) api->get = &template_plugin_get; api->put = &template_plugin_put; api->del = &template_plugin_del; - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, - "template", _("Template datacache running\n")); + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "template", + _("Template datacache running\n")); return api; } diff --git a/src/datacache/test_datacache.c b/src/datacache/test_datacache.c index c04facc15..abf0209d8 100644 --- a/src/datacache/test_datacache.c +++ b/src/datacache/test_datacache.c @@ -39,10 +39,9 @@ static const char *plugin_name; static int -checkIt (void *cls, - struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, - size_t size, const char *data, enum GNUNET_BLOCK_Type type) +checkIt (void *cls, struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, size_t size, const char *data, + enum GNUNET_BLOCK_Type type) { if (size != sizeof (GNUNET_HashCode)) { @@ -59,9 +58,8 @@ checkIt (void *cls, static void -run (void *cls, - char *const *args, - const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_DATACACHE_Handle *h; GNUNET_HashCode k; @@ -83,11 +81,9 @@ run (void *cls, for (i = 0; i < 100; i++) { GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); - ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, - &k, - sizeof (GNUNET_HashCode), - (const char *) &n, - 1 + i % 16, exp)); + ASSERT (GNUNET_OK == + GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode), + (const char *) &n, 1 + i % 16, exp)); k = n; } memset (&k, 0, sizeof (GNUNET_HashCode)); @@ -100,12 +96,10 @@ run (void *cls, memset (&k, 42, sizeof (GNUNET_HashCode)); GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n); - ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, - &k, - sizeof (GNUNET_HashCode), - (const char *) &n, - 792, - GNUNET_TIME_UNIT_FOREVER_ABS)); + ASSERT (GNUNET_OK == + GNUNET_DATACACHE_put (h, &k, sizeof (GNUNET_HashCode), + (const char *) &n, 792, + GNUNET_TIME_UNIT_FOREVER_ABS)); ASSERT (0 != GNUNET_DATACACHE_get (h, &k, 792, &checkIt, &n)); GNUNET_DATACACHE_destroy (h); @@ -153,13 +147,12 @@ main (int argc, char *argv[]) else pos = (char *) plugin_name; - GNUNET_snprintf (cfg_name, - sizeof (cfg_name), - "test_datacache_data_%s.conf", plugin_name); + GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", + plugin_name); if (pos != plugin_name) pos[0] = '.'; - GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, - xargv, "test-datacache", "nohelp", options, &run, NULL); + GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, + "test-datacache", "nohelp", options, &run, NULL); if (ok != 0) fprintf (stderr, "Missed some testcases: %d\n", ok); return ok; diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c index f943844a4..ad8681cec 100644 --- a/src/datacache/test_datacache_quota.c +++ b/src/datacache/test_datacache_quota.c @@ -44,9 +44,8 @@ static const char *plugin_name; * some of the data from the last iteration is still there. */ static void -run (void *cls, - char *const *args, - const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_DATACACHE_Handle *h; GNUNET_HashCode k; @@ -140,14 +139,12 @@ main (int argc, char *argv[]) else pos = (char *) plugin_name; - GNUNET_snprintf (cfg_name, - sizeof (cfg_name), - "test_datacache_data_%s.conf", plugin_name); + GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datacache_data_%s.conf", + plugin_name); if (pos != plugin_name) pos[0] = '.'; - GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, - xargv, "test-datacache-quota", "nohelp", - options, &run, NULL); + GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, + "test-datacache-quota", "nohelp", options, &run, NULL); if (ok != 0) fprintf (stderr, "Missed some testcases: %d\n", ok); return ok; -- cgit v1.2.3