From 660c6da4fcbca6bd2cb15599dfe3c6d53b890c7f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 10 Nov 2009 08:16:49 +0000 Subject: [PATCH] indent --- src/util/client.c | 4 +- src/util/common_allocation.c | 8 +- src/util/configuration.c | 178 ++++++++++++++++++---------------- src/util/connection.c | 24 +++-- src/util/container_slist.c | 4 +- src/util/network.c | 4 +- src/util/service.c | 3 +- src/util/test_bio.c | 24 ++--- src/util/test_configuration.c | 35 ++++--- src/util/test_peer.c | 84 +++++++++------- 10 files changed, 197 insertions(+), 171 deletions(-) diff --git a/src/util/client.c b/src/util/client.c index 4d158ab2f..80ea6d644 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -362,8 +362,8 @@ check_complete (struct GNUNET_CLIENT_Connection *conn) { if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) && (conn->received_pos >= - ntohs (((const struct GNUNET_MessageHeader *) conn-> - received_buf)->size))) + ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)-> + size))) conn->msg_complete = GNUNET_YES; } diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 1e546b962..5be7caaa7 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -32,11 +32,11 @@ #endif #if 0 - #define W32_MEM_LIMIT 200000000 +#define W32_MEM_LIMIT 200000000 #endif #ifdef W32_MEM_LIMIT - static LONG mem_used = 0; +static LONG mem_used = 0; #endif /** @@ -66,7 +66,7 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) void *result; #ifdef W32_MEM_LIMIT - size += sizeof(size_t); + size += sizeof (size_t); if (mem_used + size > W32_MEM_LIMIT) return NULL; #endif @@ -109,7 +109,7 @@ GNUNET_xrealloc_ (void *ptr, const char *filename, int linenumber) { #ifdef W32_MEM_LIMIT - n += sizeof(size_t); + n += sizeof (size_t); ptr = &((size_t *) ptr)[-1]; mem_used = mem_used - *((size_t *) ptr) + n; #endif diff --git a/src/util/configuration.c b/src/util/configuration.c index d64ca8e83..250f9d3d5 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -102,9 +102,10 @@ struct GNUNET_CONFIGURATION_Handle * Used for diffing a configuration object against * the default one */ -struct GNUNNET_CONFIGURATION_Diff_Handle{ - struct GNUNET_CONFIGURATION_Handle* cfgNew; - struct GNUNET_CONFIGURATION_Handle* cfgDiff; +struct GNUNNET_CONFIGURATION_Diff_Handle +{ + struct GNUNET_CONFIGURATION_Handle *cfgNew; + struct GNUNET_CONFIGURATION_Handle *cfgDiff; }; @@ -479,71 +480,81 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param option option name of the value (of the default conf.) * @param value value to copy (of the default conf.) */ -void -compareEntries( - void *cls, - const char *section, - const char *option, - const char *value) +void +compareEntries (void *cls, + const char *section, const char *option, const char *value) { - struct ConfigSection *secNew; - struct ConfigEntry *entNew; - struct GNUNNET_CONFIGURATION_Diff_Handle* cfgDiff = (struct GNUNNET_CONFIGURATION_Diff_Handle*)cls; - - secNew = findSection(cfgDiff->cfgNew, section); - entNew = findEntry(cfgDiff->cfgNew, section, option); - if (secNew && strcmp(entNew->val, value) != 0) { - /* Value in the new configuration has been changed */ - /* Add the changed value to the diff configuration object */ - struct ConfigEntry *diffEntry = NULL; - struct ConfigSection *diffSection = NULL; - - diffSection = cfgDiff->cfgDiff->sections; - if (diffSection == NULL) { - /* First section */ - diffSection = GNUNET_malloc(sizeof(struct ConfigSection)); - memcpy(diffSection, secNew, sizeof(struct ConfigSection)); - cfgDiff->cfgDiff->sections = diffSection; - diffSection->entries = NULL; - diffSection->next = NULL; - } - else { - while ((strcmp(diffSection->name, secNew->name) != 0) && (diffSection->next != NULL)) { - diffSection = diffSection->next; - } - if (strcmp(diffSection->name, secNew->name) != 0) { - /* Section not found in diffs configuration */ - diffSection->next = GNUNET_malloc(sizeof(struct ConfigSection)); - memcpy(diffSection->next, secNew, sizeof(struct ConfigSection)); - diffSection->next->entries = NULL; - diffSection->next->next = NULL; - } - else { - diffEntry = diffSection->entries; - } - } - - if (diffEntry == NULL) { - /* First Entry */ - diffEntry = GNUNET_malloc(sizeof(struct ConfigEntry)); - memcpy(diffEntry, entNew, sizeof(struct ConfigEntry)); - if (diffSection->next == NULL) - /* The first Entry of the first Section */ - diffSection->entries = diffEntry; - else - /* The first entry of the non-first Section */ - diffSection->next->entries = diffEntry; - diffEntry->next = NULL; - } - else { - while (diffEntry->next != NULL) { - diffEntry = diffEntry->next; - } - diffEntry->next = GNUNET_malloc(sizeof(struct ConfigEntry)); - memcpy(diffEntry->next, entNew, sizeof(struct ConfigEntry)); - diffEntry->next->next = NULL; - } - } + struct ConfigSection *secNew; + struct ConfigEntry *entNew; + struct GNUNNET_CONFIGURATION_Diff_Handle *cfgDiff = + (struct GNUNNET_CONFIGURATION_Diff_Handle *) cls; + + secNew = findSection (cfgDiff->cfgNew, section); + entNew = findEntry (cfgDiff->cfgNew, section, option); + if (secNew && strcmp (entNew->val, value) != 0) + { + /* Value in the new configuration has been changed */ + /* Add the changed value to the diff configuration object */ + struct ConfigEntry *diffEntry = NULL; + struct ConfigSection *diffSection = NULL; + + diffSection = cfgDiff->cfgDiff->sections; + if (diffSection == NULL) + { + /* First section */ + diffSection = GNUNET_malloc (sizeof (struct ConfigSection)); + memcpy (diffSection, secNew, sizeof (struct ConfigSection)); + cfgDiff->cfgDiff->sections = diffSection; + diffSection->entries = NULL; + diffSection->next = NULL; + } + else + { + while ((strcmp (diffSection->name, secNew->name) != 0) + && (diffSection->next != NULL)) + { + diffSection = diffSection->next; + } + if (strcmp (diffSection->name, secNew->name) != 0) + { + /* Section not found in diffs configuration */ + diffSection->next = + GNUNET_malloc (sizeof (struct ConfigSection)); + memcpy (diffSection->next, secNew, + sizeof (struct ConfigSection)); + diffSection->next->entries = NULL; + diffSection->next->next = NULL; + } + else + { + diffEntry = diffSection->entries; + } + } + + if (diffEntry == NULL) + { + /* First Entry */ + diffEntry = GNUNET_malloc (sizeof (struct ConfigEntry)); + memcpy (diffEntry, entNew, sizeof (struct ConfigEntry)); + if (diffSection->next == NULL) + /* The first Entry of the first Section */ + diffSection->entries = diffEntry; + else + /* The first entry of the non-first Section */ + diffSection->next->entries = diffEntry; + diffEntry->next = NULL; + } + else + { + while (diffEntry->next != NULL) + { + diffEntry = diffEntry->next; + } + diffEntry->next = GNUNET_malloc (sizeof (struct ConfigEntry)); + memcpy (diffEntry->next, entNew, sizeof (struct ConfigEntry)); + diffEntry->next->next = NULL; + } + } } @@ -555,24 +566,23 @@ compareEntries( * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_write_diffs( - struct GNUNET_CONFIGURATION_Handle *cfgDefault, - struct GNUNET_CONFIGURATION_Handle *cfgNew, - const char* filename - ) +GNUNET_CONFIGURATION_write_diffs (struct GNUNET_CONFIGURATION_Handle + *cfgDefault, + struct GNUNET_CONFIGURATION_Handle *cfgNew, + const char *filename) { - int ret; - struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle; - diffHandle.cfgDiff = GNUNET_CONFIGURATION_create(); - diffHandle.cfgDiff->sections = NULL; - diffHandle.cfgNew = cfgNew; - GNUNET_CONFIGURATION_iterate(cfgDefault, compareEntries, &diffHandle); - - ret = GNUNET_CONFIGURATION_write(diffHandle.cfgDiff, filename); - - /* Housekeeping */ - GNUNET_CONFIGURATION_destroy(diffHandle.cfgDiff); - return ret; + int ret; + struct GNUNNET_CONFIGURATION_Diff_Handle diffHandle; + diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); + diffHandle.cfgDiff->sections = NULL; + diffHandle.cfgNew = cfgNew; + GNUNET_CONFIGURATION_iterate (cfgDefault, compareEntries, &diffHandle); + + ret = GNUNET_CONFIGURATION_write (diffHandle.cfgDiff, filename); + + /* Housekeeping */ + GNUNET_CONFIGURATION_destroy (diffHandle.cfgDiff); + return ret; } diff --git a/src/util/connection.c b/src/util/connection.c index 886ae140c..e09c0cd9e 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -817,12 +817,11 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched, ret->port = port; ret->hostname = GNUNET_strdup (hostname); ret->dns_active = GNUNET_RESOLVER_ip_get (sched, - cfg, - ret->hostname, - AF_UNSPEC, - GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, - ret); + cfg, + ret->hostname, + AF_UNSPEC, + GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, + &try_connect_using_address, ret); return ret; } @@ -971,9 +970,8 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive from `%s' encounters error: time out by %llums... (%p)\n", GNUNET_a2s (sh->addr, sh->addrlen), - GNUNET_TIME_absolute_get_duration (sh-> - receive_timeout).value, - sh); + GNUNET_TIME_absolute_get_duration (sh->receive_timeout). + value, sh); #endif signal_timeout (sh); return; @@ -1320,8 +1318,8 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); RETRY: ret = GNUNET_NETWORK_socket_send (sock->sock, - &sock-> - write_buffer[sock->write_buffer_pos], + &sock->write_buffer[sock-> + write_buffer_pos], have); if (ret == -1) { @@ -1418,8 +1416,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle #endif sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched, GNUNET_TIME_absolute_get_remaining - (sock-> - nth.transmit_timeout), + (sock->nth. + transmit_timeout), sock->sock, &transmit_ready, sock); diff --git a/src/util/container_slist.c b/src/util/container_slist.c index 715dcee32..ab547f313 100644 --- a/src/util/container_slist.c +++ b/src/util/container_slist.c @@ -336,7 +336,9 @@ GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, * Release an iterator * @param i iterator */ -void GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i) +void +GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator + *i) { GNUNET_free (i); } diff --git a/src/util/network.c b/src/util/network.c index 2707e9432..5d7370003 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -976,7 +976,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, on_next = GNUNET_YES; } } - GNUNET_CONTAINER_slist_iter_destroy (i); + GNUNET_CONTAINER_slist_iter_destroy (i); } /* Poll for faulty pipes */ @@ -1043,7 +1043,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, } select_loop_end: if (retcode == 0 && nfds == 0) - Sleep(GNUNET_MIN(100, limit - GetTickCount())); + Sleep (GNUNET_MIN (100, limit - GetTickCount ())); } while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); if (retcode != -1) diff --git a/src/util/service.c b/src/util/service.c index 2c84e91f4..75161f71f 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -799,7 +799,8 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) { if (GNUNET_SYSERR == (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, - sctx->serviceName, + sctx-> + serviceName, "DISABLEV6"))) return GNUNET_SYSERR; } diff --git a/src/util/test_bio.c b/src/util/test_bio.c index b005cb057..1eda86a6f 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c @@ -49,8 +49,7 @@ test_normal_rw () GNUNET_assert (NULL != fileW); GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING)); GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW, metaDataW)); - GNUNET_assert (GNUNET_OK == - GNUNET_BIO_write_int64 (fileW, TESTNUMBER64)); + GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int64 (fileW, TESTNUMBER64)); GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW)); fileR = GNUNET_BIO_read_open (fileName); @@ -199,14 +198,16 @@ test_bigmeta_rw () } static int -test_directory_r(){ +test_directory_r () +{ char *msg; char readResult[200]; struct GNUNET_BIO_ReadHandle *fileR; fileR = GNUNET_BIO_read_open ("/dev"); GNUNET_assert (NULL != fileR); - GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (fileR, "Read error", readResult, 65537)); + GNUNET_assert (GNUNET_SYSERR == + GNUNET_BIO_read (fileR, "Read error", readResult, 65537)); msg = NULL; GNUNET_BIO_read_close (fileR, &msg); GNUNET_free (msg); @@ -240,7 +241,7 @@ test_nullfile_rw () fileW = GNUNET_BIO_write_open ("/dev/full"); GNUNET_assert (NULL != fileW); GNUNET_assert (GNUNET_SYSERR == - GNUNET_BIO_write (fileW, fileNameNO, sizeof(fileNameNO))); + GNUNET_BIO_write (fileW, fileNameNO, sizeof (fileNameNO))); GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_string (fileW, TESTSTRING)); GNUNET_assert (GNUNET_SYSERR == @@ -384,14 +385,15 @@ check_file_rw () { GNUNET_assert (0 == test_normal_rw ()); GNUNET_assert (0 == test_nullfile_rw ()); - GNUNET_assert (0 == test_directory_r()); + GNUNET_assert (0 == test_directory_r ()); return 0; } int -main (int argc, char *argv[]){ - GNUNET_assert (0 == check_file_rw()); - GNUNET_assert (0 == check_metadata_rw()); - GNUNET_assert (0 == check_string_rw()); - return 0; +main (int argc, char *argv[]) +{ + GNUNET_assert (0 == check_file_rw ()); + GNUNET_assert (0 == check_metadata_rw ()); + GNUNET_assert (0 == check_string_rw ()); + return 0; } /* end of main */ diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index 150b8d6b4..3cd076f0f 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c @@ -231,23 +231,26 @@ main (int argc, char *argv[]) // return 1; // } // - struct GNUNET_CONFIGURATION_Handle* cfgDefault = GNUNET_CONFIGURATION_create (); - struct GNUNET_CONFIGURATION_Handle* cfgNew = GNUNET_CONFIGURATION_create(); + struct GNUNET_CONFIGURATION_Handle *cfgDefault = + GNUNET_CONFIGURATION_create (); + struct GNUNET_CONFIGURATION_Handle *cfgNew = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != - GNUNET_CONFIGURATION_parse (cfgDefault, "src/util/test_configuration_data.conf")) - { - fprintf (stderr, "Failed to parse configuration file\n"); - GNUNET_CONFIGURATION_destroy (cfgDefault); - return 1; - } + GNUNET_CONFIGURATION_parse (cfgDefault, + "src/util/test_configuration_data.conf")) + { + fprintf (stderr, "Failed to parse configuration file\n"); + GNUNET_CONFIGURATION_destroy (cfgDefault); + return 1; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_parse (cfgNew, "/Users/soufi/Desktop/test_configuration_data.conf")) - { - fprintf (stderr, "Failed to parse configuration file\n"); - GNUNET_CONFIGURATION_destroy (cfgNew); - return 1; - } - - GNUNET_CONFIGURATION_write_diffs(cfgDefault, cfgNew, "/tmp/safey.conf"); + GNUNET_CONFIGURATION_parse (cfgNew, + "/Users/soufi/Desktop/test_configuration_data.conf")) + { + fprintf (stderr, "Failed to parse configuration file\n"); + GNUNET_CONFIGURATION_destroy (cfgNew); + return 1; + } + + GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfgNew, "/tmp/safey.conf"); return 0; } diff --git a/src/util/test_peer.c b/src/util/test_peer.c index 0f4a227d3..e2fd100fd 100644 --- a/src/util/test_peer.c +++ b/src/util/test_peer.c @@ -36,70 +36,80 @@ static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS]; -static void generatePeerIdList() +static void +generatePeerIdList () { int i; - for (i = 0; i < NUMBER_OF_PEERS; i++ ) { - GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &pidArr[i].hashPubKey); + for (i = 0; i < NUMBER_OF_PEERS; i++) + { + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, + &pidArr[i].hashPubKey); #ifdef DEBUG - printf ("Peer %d: %s\n", - i, - GNUNET_i2s (&pidArr[i])); + printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); #endif - } + } } -static int check() +static int +check () { int i; GNUNET_PEER_Id pid; - + /* Insert Peers into PeerEntry table and hashmap */ - for (i=0; i < NUMBER_OF_PEERS; i++) { - pid = GNUNET_PEER_intern(&pidArr[i]); - if ( pid != (i + 1)) { - fprintf(stderr, "Unexpected Peer ID returned by intern function \n"); - return 1; + for (i = 0; i < NUMBER_OF_PEERS; i++) + { + pid = GNUNET_PEER_intern (&pidArr[i]); + if (pid != (i + 1)) + { + fprintf (stderr, + "Unexpected Peer ID returned by intern function \n"); + return 1; + } } - } - + /* Referencing the first 3 peers once again */ - for (i = 0; i < 3; i++) { - pid = GNUNET_PEER_intern(&pidArr[i]); - if (pid != (i + 1)) { - fprintf(stderr, "Unexpcted Peer ID returned by intern function \n"); - return 1; + for (i = 0; i < 3; i++) + { + pid = GNUNET_PEER_intern (&pidArr[i]); + if (pid != (i + 1)) + { + fprintf (stderr, + "Unexpcted Peer ID returned by intern function \n"); + return 1; + } } - } - + /* Dereferencing the first 3 peers once [decrementing their reference count] */ { - GNUNET_PEER_Id ids[] = {1, 2, 3}; - GNUNET_PEER_decrement_rcs(ids, 3); + GNUNET_PEER_Id ids[] = { 1, 2, 3 }; + GNUNET_PEER_decrement_rcs (ids, 3); } - + /* re-referencing the first 3 peers using the change_rc function */ - for (i = 0; i < 3; i++) { - GNUNET_PEER_change_rc(i, 1); - } - + for (i = 0; i < 3; i++) + { + GNUNET_PEER_change_rc (i, 1); + } + /* Removing the second Peer from the PeerEntry hash map */ - GNUNET_PEER_change_rc(2, -2); - + GNUNET_PEER_change_rc (2, -2); + /* convert the pid of the first PeerEntry into that of the third */ - GNUNET_PEER_resolve(1, &pidArr[3]); - + GNUNET_PEER_resolve (1, &pidArr[3]); + return 0; } -int main() +int +main () { GNUNET_log_setup ("test-peer", "ERROR", NULL); - generatePeerIdList(); - return check(); + generatePeerIdList (); + return check (); } /* end of test_peer.c */ -- 2.25.1