From 6b13a87d2165669c5b0f4a16b4c599d9cf0ac1db Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 25 Aug 2016 11:33:14 +0000 Subject: [PATCH] -nicer indentation --- src/gnsrecord/gnsrecord_serialization.c | 14 +-- src/namestore/gnunet-namestore.c | 50 +++++++--- src/namestore/gnunet-service-namestore.c | 55 +++++----- src/namestore/plugin_namestore_sqlite.c | 122 ++++++++++++++++------- src/util/strings.c | 3 +- src/vpn/gnunet-service-vpn.c | 4 +- 6 files changed, 167 insertions(+), 81 deletions(-) diff --git a/src/gnsrecord/gnsrecord_serialization.c b/src/gnsrecord/gnsrecord_serialization.c index e2cabafd3..190f62fc2 100644 --- a/src/gnsrecord/gnsrecord_serialization.c +++ b/src/gnsrecord/gnsrecord_serialization.c @@ -48,7 +48,7 @@ struct NetworkRecord /** * Expiration time for the DNS record; relative or absolute depends - * on 'flags', network byte order. + * on @e flags, network byte order. */ uint64_t expiration_time GNUNET_PACKED; @@ -119,24 +119,26 @@ GNUNET_GNSRECORD_records_serialize (unsigned int rd_count, off = 0; for (i=0;i dest_size) return -1; - GNUNET_memcpy (&dest[off], &rec, sizeof (rec)); + GNUNET_memcpy (&dest[off], + &rec, + sizeof (rec)); off += sizeof (rec); if (off + rd[i].data_size > dest_size) return -1; - GNUNET_memcpy (&dest[off], rd[i].data, rd[i].data_size); + GNUNET_memcpy (&dest[off], + rd[i].data, + rd[i].data_size); off += rd[i].data_size; } return off; @@ -177,13 +179,11 @@ GNUNET_GNSRECORD_records_deserialize (size_t len, return GNUNET_SYSERR; dest[i].data = &src[off]; off += dest[i].data_size; -#if 0 LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserialized record %u with flags %d and expiration time %llu\n", i, dest[i].flags, (unsigned long long) dest[i].expiration_time); -#endif } return GNUNET_OK; } diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 82213497c..9e654cc34 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -411,7 +411,8 @@ display_record (void *cls, rd[i].data_size); if (NULL == s) { - FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"), + FPRINTF (stdout, + _("\tCorrupt or unsupported record of type %u\n"), (unsigned int) rd[i].record_type); continue; } @@ -579,7 +580,9 @@ get_existing_record (void *cls, break; } memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data)); - GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_GNSRECORD_Data)); + GNUNET_memcpy (&rdn[1], + rd, + rd_count * sizeof (struct GNUNET_GNSRECORD_Data)); rde = &rdn[0]; rde->data = data; rde->data_size = data_size; @@ -846,7 +849,8 @@ testservice_task (void *cls, { fprintf (stderr, _("Missing option `%s' for operation `%s'\n"), - "-e", _("add")); + "-e", + _("add")); GNUNET_SCHEDULER_shutdown (); ret = 1; return; @@ -862,12 +866,19 @@ testservice_task (void *cls, &etime_rel)) { etime_is_rel = GNUNET_YES; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Storing record with relative expiration time of %s\n", + GNUNET_STRINGS_relative_time_to_string (etime_rel, + GNUNET_NO)); } else if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_absolute (expirationstring, &etime_abs)) { etime_is_rel = GNUNET_NO; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Storing record with absolute expiration time of %s\n", + GNUNET_STRINGS_absolute_time_to_string (etime_abs)); } else { @@ -996,8 +1007,11 @@ testservice_task (void *cls, ret = 1; return; } - add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, &zone_pkey, nickstring, - &add_continuation, &add_qe_uri); + add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, + &zone_pkey, + nickstring, + &add_continuation, + &add_qe_uri); } if (monitor) { @@ -1084,7 +1098,8 @@ id_connect_cb (void *cls, { get_default = GNUNET_IDENTITY_get (idh, "namestore", - &default_ego_cb, (void *) cfg); + &default_ego_cb, + (void *) cfg); } } @@ -1093,6 +1108,7 @@ static void testservice_id_task (void *cls, int result) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; + if (result != GNUNET_YES) { fprintf (stderr, @@ -1101,11 +1117,14 @@ testservice_id_task (void *cls, int result) ret = -1; return; } - GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + (void *) cfg); if (NULL == ego_name) { - idh = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, (void *) cfg); + idh = GNUNET_IDENTITY_connect (cfg, + &id_connect_cb, + (void *) cfg); if (NULL == idh) fprintf (stderr, _("Cannot connect to identity service\n")); ret = -1; @@ -1127,7 +1146,9 @@ testservice_id_task (void *cls, int result) * @param cfg configuration */ static void -run (void *cls, char *const *args, const char *cfgfile, +run (void *cls, + char *const *args, + const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { if ( (NULL != args[0]) && (NULL == uri) ) @@ -1148,7 +1169,8 @@ run (void *cls, char *const *args, const char *cfgfile, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main (int argc, + char *const *argv) { is_public = -1; is_shadow = -1; @@ -1202,9 +1224,13 @@ main (int argc, char *const *argv) if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; - GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL); + GNUNET_log_setup ("gnunet-namestore", + "WARNING", + NULL); if (GNUNET_OK != - GNUNET_PROGRAM_run (argc, argv, "gnunet-namestore", + GNUNET_PROGRAM_run (argc, + argv, + "gnunet-namestore", _("GNUnet zone manipulation tool"), options, &run, NULL)) diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 593763894..05bcd94ce 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c @@ -472,20 +472,19 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) static void -merge_with_nick_records ( const struct GNUNET_GNSRECORD_Data *nick_rd, - unsigned int rdc2, - const struct GNUNET_GNSRECORD_Data *rd2, - unsigned int *rdc_res, - struct GNUNET_GNSRECORD_Data **rd_res) +merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, + unsigned int rdc2, + const struct GNUNET_GNSRECORD_Data *rd2, + unsigned int *rdc_res, + struct GNUNET_GNSRECORD_Data **rd_res) { uint64_t latest_expiration; - int c; size_t req; char *data; int record_offset; size_t data_offset; - (*rdc_res) = 1 + rdc2; + (*rdc_res) = 1 + rdc2; if (0 == 1 + rdc2) { (*rd_res) = NULL; @@ -493,16 +492,16 @@ merge_with_nick_records ( const struct GNUNET_GNSRECORD_Data *nick_rd, } req = 0; - for (c=0; c< 1; c++) + for (unsigned int c=0; c< 1; c++) req += sizeof (struct GNUNET_GNSRECORD_Data) + nick_rd[c].data_size; - for (c=0; c< rdc2; c++) + for (unsigned int c=0; c< rdc2; c++) req += sizeof (struct GNUNET_GNSRECORD_Data) + rd2[c].data_size; (*rd_res) = GNUNET_malloc (req); data = (char *) &(*rd_res)[1 + rdc2]; data_offset = 0; latest_expiration = 0; - for (c=0; c< rdc2; c++) + for (unsigned int c=0; c< rdc2; c++) { if (0 != (rd2[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) { @@ -514,19 +513,17 @@ merge_with_nick_records ( const struct GNUNET_GNSRECORD_Data *nick_rd, latest_expiration = rd2[c].expiration_time; (*rd_res)[c] = rd2[c]; (*rd_res)[c].data = (void *) &data[data_offset]; - // WTF? GNUNET_memcpy ((void *) (*rd_res)[c].data, rd2[c].data, rd2[c].data_size); data_offset += (*rd_res)[c].data_size; } record_offset = rdc2; - for (c=0; c< 1; c++) + for (unsigned int c=0; c< 1; c++) { (*rd_res)[c+record_offset] = nick_rd[c]; (*rd_res)[c+record_offset].expiration_time = latest_expiration; (*rd_res)[c+record_offset].data = (void *) &data[data_offset]; - // WTF? GNUNET_memcpy ((void *) (*rd_res)[c+record_offset].data, nick_rd[c].data, nick_rd[c].data_size); @@ -571,15 +568,17 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, if ((NULL != nick) && (0 != strcmp(name, GNUNET_GNS_MASTERZONE_STR))) { nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; - merge_with_nick_records (nick, rd_count, rd, &res_count, &res); - //fprintf (stderr, "Merging %u records for `%s' with NICK records\n",rd_count, name); + merge_with_nick_records (nick, + rd_count, + rd, + &res_count, + &res); GNUNET_free (nick); } else { res_count = rd_count; res = (struct GNUNET_GNSRECORD_Data *) rd; - //fprintf (stderr, "Not merging %u records for `%s' with NICK records\n",rd_count, name); } name_len = strlen (name) + 1; @@ -599,8 +598,7 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, rd_ser = &name_tmp[name_len]; GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending `%s' message with %u records and size %zu\n", - "RECORD_RESULT", + "Sending RECORD_RESULT message with %u records and size %zu\n", res_count, msg_size); GNUNET_SERVER_notification_context_unicast (nc, @@ -776,7 +774,9 @@ lookup_it (void *cls, rlc->found = GNUNET_YES; if (0 != rd_count) { - if ((NULL != rlc->nick) && (0 != strcmp(label, GNUNET_GNS_MASTERZONE_STR))) + if ( (NULL != rlc->nick) && + (0 != strcmp (label, + GNUNET_GNS_MASTERZONE_STR)) ) { /* Merge */ rd_res = NULL; @@ -786,10 +786,14 @@ lookup_it (void *cls, rd_count, rd, &rdc_res, &rd_res); - rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res); + rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, + rd_res); rlc->res_rd_count = rdc_res; rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); - GNUNET_GNSRECORD_records_serialize (rdc_res, rd_res, rlc->rd_ser_len , rlc->res_rd); + GNUNET_GNSRECORD_records_serialize (rdc_res, + rd_res, + rlc->rd_ser_len, + rlc->res_rd); GNUNET_free (rd_res); GNUNET_free (rlc->nick); @@ -797,10 +801,14 @@ lookup_it (void *cls, } else { - rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); + rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, + rd); rlc->res_rd_count = rd_count; rlc->res_rd = GNUNET_malloc (rlc->rd_ser_len); - GNUNET_GNSRECORD_records_serialize (rd_count, rd, rlc->rd_ser_len , rlc->res_rd); + GNUNET_GNSRECORD_records_serialize (rd_count, + rd, + rlc->rd_ser_len, + rlc->res_rd); } } else @@ -923,7 +931,6 @@ handle_record_lookup (void *cls, client, &llr_msg->gns_header.header, GNUNET_NO); - GNUNET_free_non_null (rlc.res_rd); GNUNET_free (llr_msg); } diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index e93f800c3..d64ce10a8 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c @@ -137,16 +137,20 @@ create_indices (sqlite3 * dbh) { /* create indices */ if ( (SQLITE_OK != - sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_reverse ON ns097records (zone_private_key,pkey)", + sqlite3_exec (dbh, + "CREATE INDEX IF NOT EXISTS ir_pkey_reverse ON ns097records (zone_private_key,pkey)", NULL, NULL, NULL)) || (SQLITE_OK != - sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON ns097records (zone_private_key,rvalue)", + sqlite3_exec (dbh, + "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON ns097records (zone_private_key,rvalue)", NULL, NULL, NULL)) || (SQLITE_OK != - sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS it_iter ON ns097records (rvalue)", + sqlite3_exec (dbh, + "CREATE INDEX IF NOT EXISTS it_iter ON ns097records (rvalue)", NULL, NULL, NULL)) ) LOG (GNUNET_ERROR_TYPE_ERROR, - "Failed to create indices: %s\n", sqlite3_errmsg (dbh)); + "Failed to create indices: %s\n", + sqlite3_errmsg (dbh)); } @@ -178,16 +182,21 @@ database_setup (struct Plugin *plugin) #endif if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, "namestore-sqlite", - "FILENAME", &afsdir)) + GNUNET_CONFIGURATION_get_value_filename (plugin->cfg, + "namestore-sqlite", + "FILENAME", + &afsdir)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "namestore-sqlite", "FILENAME"); + "namestore-sqlite", + "FILENAME"); return GNUNET_SYSERR; } - if (GNUNET_OK != GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK != + GNUNET_DISK_file_test (afsdir)) { - if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (afsdir)) + if (GNUNET_OK != + GNUNET_DISK_directory_create_for_file (afsdir)) { GNUNET_break (0); GNUNET_free (afsdir); @@ -206,28 +215,37 @@ database_setup (struct Plugin *plugin) return GNUNET_SYSERR; } CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA temp_store=MEMORY", NULL, NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA temp_store=MEMORY", NULL, NULL, ENULL)); CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA synchronous=NORMAL", NULL, NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA synchronous=NORMAL", NULL, NULL, ENULL)); CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA legacy_file_format=OFF", NULL, NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA legacy_file_format=OFF", NULL, NULL, ENULL)); CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA auto_vacuum=INCREMENTAL", NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA auto_vacuum=INCREMENTAL", NULL, NULL, ENULL)); CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA encoding=\"UTF-8\"", NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA encoding=\"UTF-8\"", NULL, NULL, ENULL)); CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, ENULL)); CHECK (SQLITE_OK == - sqlite3_exec (plugin->dbh, "PRAGMA page_size=4092", NULL, NULL, + sqlite3_exec (plugin->dbh, + "PRAGMA page_size=4092", NULL, NULL, ENULL)); - CHECK (SQLITE_OK == sqlite3_busy_timeout (plugin->dbh, BUSY_TIMEOUT_MS)); + CHECK (SQLITE_OK == + sqlite3_busy_timeout (plugin->dbh, + BUSY_TIMEOUT_MS)); /* Create table */ @@ -248,7 +266,8 @@ database_setup (struct Plugin *plugin) ")", NULL, NULL, NULL) != SQLITE_OK)) { - LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); + LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR, + "sqlite3_exec"); sqlite3_finalize (stmt); return GNUNET_SYSERR; } @@ -371,14 +390,17 @@ namestore_sqlite_store_records (void *cls, for (i=0;i 64 * 65536) { GNUNET_break (0); @@ -387,17 +409,29 @@ namestore_sqlite_store_records (void *cls, { char data[data_size]; - if (data_size != GNUNET_GNSRECORD_records_serialize (rd_count, rd, - data_size, data)) + if (data_size != + GNUNET_GNSRECORD_records_serialize (rd_count, + rd, + data_size, + data)) { GNUNET_break (0); return GNUNET_SYSERR; } /* First delete 'old' records */ - if ((SQLITE_OK != sqlite3_bind_blob (plugin->delete_records, 1, - zone_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), SQLITE_STATIC)) || - (SQLITE_OK != sqlite3_bind_text (plugin->delete_records, 2, label, -1, SQLITE_STATIC))) + if ((SQLITE_OK != + sqlite3_bind_blob (plugin->delete_records, + 1, + zone_key, + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), + SQLITE_STATIC)) || + (SQLITE_OK != + sqlite3_bind_text (plugin->delete_records, + 2, + label, + -1, + SQLITE_STATIC))) { LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, @@ -416,14 +450,30 @@ namestore_sqlite_store_records (void *cls, if (0 != rd_count) { - if ((SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 1, - zone_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), SQLITE_STATIC)) || - (SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 2, - &pkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), SQLITE_STATIC)) || - (SQLITE_OK != sqlite3_bind_int64 (plugin->store_records, 3, rvalue)) || - (SQLITE_OK != sqlite3_bind_int (plugin->store_records, 4, rd_count)) || - (SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 5, data, data_size, SQLITE_STATIC)) || - (SQLITE_OK != sqlite3_bind_text (plugin->store_records, 6, label, -1, SQLITE_STATIC))) + if ((SQLITE_OK != + sqlite3_bind_blob (plugin->store_records, + 1, + zone_key, + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), + SQLITE_STATIC)) || + (SQLITE_OK != + sqlite3_bind_blob (plugin->store_records, + 2, + &pkey, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), + SQLITE_STATIC)) || + (SQLITE_OK != + sqlite3_bind_int64 (plugin->store_records, 3, rvalue)) || + (SQLITE_OK != + sqlite3_bind_int (plugin->store_records, 4, rd_count)) || + (SQLITE_OK != + sqlite3_bind_blob (plugin->store_records, 5, + data, data_size, + SQLITE_STATIC)) || + (SQLITE_OK != + sqlite3_bind_text (plugin->store_records, 6, + label, -1, + SQLITE_STATIC))) { LOG_SQLITE (plugin, GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, diff --git a/src/util/strings.c b/src/util/strings.c index 21470628e..8d10a81b8 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -354,7 +354,8 @@ GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, struct tm tv; time_t t; - if (0 == strcasecmp ("end of time", fancy_time)) + if (0 == strcasecmp ("end of time", + fancy_time)) { *atime = GNUNET_TIME_UNIT_FOREVER_ABS; return GNUNET_OK; diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 52b1e764e..629b59173 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c @@ -2749,6 +2749,7 @@ service_redirect_to_service (void *cls, &v4, &v6)) { + GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; @@ -2762,7 +2763,8 @@ service_redirect_to_service (void *cls, /* failure, we're done */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to allocate IP address for new destination\n")); - GNUNET_SERVER_receive_done (client, GNUNET_OK); + GNUNET_SERVER_receive_done (client, + GNUNET_OK); return; } -- 2.25.1