From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/reclaim-attribute/reclaim_attribute.c | 301 +++++++++++++++--------------- 1 file changed, 151 insertions(+), 150 deletions(-) (limited to 'src/reclaim-attribute/reclaim_attribute.c') diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 9ef648708..ac51a6b86 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c @@ -32,7 +32,8 @@ /** * Handle for a plugin */ -struct Plugin { +struct Plugin +{ /** * Name of the plugin */ @@ -71,18 +72,18 @@ static int initialized; * @param lib_ret the plugin API pointer */ static void -add_plugin(void *cls, const char *library_name, void *lib_ret) +add_plugin (void *cls, const char *library_name, void *lib_ret) { struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret; struct Plugin *plugin; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Loading attribute plugin `%s'\n", - library_name); - plugin = GNUNET_new(struct Plugin); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Loading attribute plugin `%s'\n", + library_name); + plugin = GNUNET_new (struct Plugin); plugin->api = api; - plugin->library_name = GNUNET_strdup(library_name); - GNUNET_array_append(attr_plugins, num_plugins, plugin); + plugin->library_name = GNUNET_strdup (library_name); + GNUNET_array_append (attr_plugins, num_plugins, plugin); } @@ -90,15 +91,15 @@ add_plugin(void *cls, const char *library_name, void *lib_ret) * Load plugins */ static void -init() +init () { if (GNUNET_YES == initialized) return; initialized = GNUNET_YES; - GNUNET_PLUGIN_load_all("libgnunet_plugin_reclaim_attribute_", - NULL, - &add_plugin, - NULL); + GNUNET_PLUGIN_load_all ("libgnunet_plugin_reclaim_attribute_", + NULL, + &add_plugin, + NULL); } @@ -109,20 +110,20 @@ init() * @return corresponding number, UINT32_MAX on error */ uint32_t -GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(const char *typename) +GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) { unsigned int i; struct Plugin *plugin; uint32_t ret; - init(); + init (); for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (UINT32_MAX != - (ret = plugin->api->typename_to_number(plugin->api->cls, typename))) - return ret; - } + { + plugin = attr_plugins[i]; + if (UINT32_MAX != + (ret = plugin->api->typename_to_number (plugin->api->cls, typename))) + return ret; + } return UINT32_MAX; } @@ -134,20 +135,20 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(const char *typename) * @return corresponding typestring, NULL on error */ const char * -GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(uint32_t type) +GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) { unsigned int i; struct Plugin *plugin; const char *ret; - init(); + init (); for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (NULL != - (ret = plugin->api->number_to_typename(plugin->api->cls, type))) - return ret; - } + { + plugin = attr_plugins[i]; + if (NULL != + (ret = plugin->api->number_to_typename (plugin->api->cls, type))) + return ret; + } return NULL; } @@ -163,25 +164,25 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename(uint32_t type) * @return #GNUNET_OK on success */ int -GNUNET_RECLAIM_ATTRIBUTE_string_to_value(uint32_t type, - const char *s, - void **data, - size_t *data_size) +GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, + const char *s, + void **data, + size_t *data_size) { unsigned int i; struct Plugin *plugin; - init(); + init (); for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (GNUNET_OK == plugin->api->string_to_value(plugin->api->cls, - type, - s, - data, - data_size)) - return GNUNET_OK; - } + { + plugin = attr_plugins[i]; + if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, + type, + s, + data, + data_size)) + return GNUNET_OK; + } return GNUNET_SYSERR; } @@ -195,24 +196,24 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value(uint32_t type, * @return NULL on error, otherwise human-readable representation of the claim */ char * -GNUNET_RECLAIM_ATTRIBUTE_value_to_string(uint32_t type, - const void *data, - size_t data_size) +GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, + const void *data, + size_t data_size) { unsigned int i; struct Plugin *plugin; char *ret; - init(); + init (); for (i = 0; i < num_plugins; i++) - { - plugin = attr_plugins[i]; - if (NULL != (ret = plugin->api->value_to_string(plugin->api->cls, - type, - data, - data_size))) - return ret; - } + { + plugin = attr_plugins[i]; + if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, + type, + data, + data_size))) + return ret; + } return NULL; } @@ -227,29 +228,29 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string(uint32_t type, * @return the new attribute */ struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -GNUNET_RECLAIM_ATTRIBUTE_claim_new(const char *attr_name, - uint32_t type, - const void *data, - size_t data_size) +GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, + uint32_t type, + const void *data, + size_t data_size) { struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; char *write_ptr; - char *attr_name_tmp = GNUNET_strdup(attr_name); + char *attr_name_tmp = GNUNET_strdup (attr_name); - GNUNET_STRINGS_utf8_tolower(attr_name, attr_name_tmp); + GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); - attr = GNUNET_malloc(sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + - strlen(attr_name_tmp) + 1 + data_size); + attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + + strlen (attr_name_tmp) + 1 + data_size); attr->type = type; attr->data_size = data_size; attr->version = 0; - write_ptr = (char *)&attr[1]; - GNUNET_memcpy(write_ptr, attr_name_tmp, strlen(attr_name_tmp) + 1); + write_ptr = (char *) &attr[1]; + GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); attr->name = write_ptr; - write_ptr += strlen(attr->name) + 1; - GNUNET_memcpy(write_ptr, data, data_size); + write_ptr += strlen (attr->name) + 1; + GNUNET_memcpy (write_ptr, data, data_size); attr->data = write_ptr; - GNUNET_free(attr_name_tmp); + GNUNET_free (attr_name_tmp); return attr; } @@ -263,7 +264,7 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new(const char *attr_name, * @param data_size claim payload size */ void -GNUNET_RECLAIM_ATTRIBUTE_list_add( +GNUNET_RECLAIM_ATTRIBUTE_list_add ( struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, const char *attr_name, uint32_t type, @@ -272,12 +273,12 @@ GNUNET_RECLAIM_ATTRIBUTE_list_add( { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; - le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); + le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); le->claim = - GNUNET_RECLAIM_ATTRIBUTE_claim_new(attr_name, type, data, data_size); - GNUNET_CONTAINER_DLL_insert(claim_list->list_head, - claim_list->list_tail, - le); + GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); + GNUNET_CONTAINER_DLL_insert (claim_list->list_head, + claim_list->list_tail, + le); } @@ -288,14 +289,14 @@ GNUNET_RECLAIM_ATTRIBUTE_list_add( * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size( +GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; size_t len = 0; for (le = attrs->list_head; NULL != le; le = le->next) - len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(le->claim); + len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); return len; } @@ -308,7 +309,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size( * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTRIBUTE_list_serialize( +GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, char *result) { @@ -320,11 +321,11 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize( write_ptr = result; total_len = 0; for (le = attrs->list_head; NULL != le; le = le->next) - { - len = GNUNET_RECLAIM_ATTRIBUTE_serialize(le->claim, write_ptr); - total_len += len; - write_ptr += len; - } + { + len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr); + total_len += len; + write_ptr += len; + } return total_len; } @@ -337,7 +338,7 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize( * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller */ struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * -GNUNET_RECLAIM_ATTRIBUTE_list_deserialize(const char *data, size_t data_size) +GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; @@ -347,21 +348,21 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize(const char *data, size_t data_size) if (data_size < sizeof(struct Attribute)) return NULL; - attrs = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); + attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); read_ptr = data; while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) - { - le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - le->claim = - GNUNET_RECLAIM_ATTRIBUTE_deserialize(read_ptr, - data_size - (read_ptr - data)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Deserialized attribute %s\n", - le->claim->name); - GNUNET_CONTAINER_DLL_insert(attrs->list_head, attrs->list_tail, le); - attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size(le->claim); - read_ptr += attr_len; - } + { + le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); + le->claim = + GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, + data_size - (read_ptr - data)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Deserialized attribute %s\n", + le->claim->name); + GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); + attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); + read_ptr += attr_len; + } return attrs; } @@ -372,28 +373,28 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize(const char *data, size_t data_size) * @return copied claim list */ struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * -GNUNET_RECLAIM_ATTRIBUTE_list_dup( +GNUNET_RECLAIM_ATTRIBUTE_list_dup ( const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le; struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; - result = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); + result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); for (le = attrs->list_head; NULL != le; le = le->next) - { - result_le = GNUNET_new(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); - result_le->claim = - GNUNET_RECLAIM_ATTRIBUTE_claim_new(le->claim->name, - le->claim->type, - le->claim->data, - le->claim->data_size); - result_le->claim->version = le->claim->version; - result_le->claim->id = le->claim->id; - GNUNET_CONTAINER_DLL_insert(result->list_head, - result->list_tail, - result_le); - } + { + result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); + result_le->claim = + GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, + le->claim->type, + le->claim->data, + le->claim->data_size); + result_le->claim->version = le->claim->version; + result_le->claim->id = le->claim->id; + GNUNET_CONTAINER_DLL_insert (result->list_head, + result->list_tail, + result_le); + } return result; } @@ -404,20 +405,20 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup( * @param attrs list to destroy */ void -GNUNET_RECLAIM_ATTRIBUTE_list_destroy( +GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) { struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; for (le = attrs->list_head; NULL != le;) - { - GNUNET_free(le->claim); - tmp_le = le; - le = le->next; - GNUNET_free(tmp_le); - } - GNUNET_free(attrs); + { + GNUNET_free (le->claim); + tmp_le = le; + le = le->next; + GNUNET_free (tmp_le); + } + GNUNET_free (attrs); } @@ -428,10 +429,10 @@ GNUNET_RECLAIM_ATTRIBUTE_list_destroy( * @return the required buffer size */ size_t -GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size( +GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) { - return sizeof(struct Attribute) + strlen(attr->name) + attr->data_size; + return sizeof(struct Attribute) + strlen (attr->name) + attr->data_size; } @@ -443,7 +444,7 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size( * @return length of serialized data */ size_t -GNUNET_RECLAIM_ATTRIBUTE_serialize( +GNUNET_RECLAIM_ATTRIBUTE_serialize ( const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, char *result) { @@ -452,23 +453,23 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize( struct Attribute *attr_ser; char *write_ptr; - attr_ser = (struct Attribute *)result; - attr_ser->attribute_type = htons(attr->type); - attr_ser->attribute_version = htonl(attr->version); - attr_ser->attribute_id = GNUNET_htonll(attr->id); - name_len = strlen(attr->name); - attr_ser->name_len = htons(name_len); - write_ptr = (char *)&attr_ser[1]; - GNUNET_memcpy(write_ptr, attr->name, name_len); + attr_ser = (struct Attribute *) result; + attr_ser->attribute_type = htons (attr->type); + attr_ser->attribute_version = htonl (attr->version); + attr_ser->attribute_id = GNUNET_htonll (attr->id); + name_len = strlen (attr->name); + attr_ser->name_len = htons (name_len); + write_ptr = (char *) &attr_ser[1]; + GNUNET_memcpy (write_ptr, attr->name, name_len); write_ptr += name_len; // TODO plugin-ize // data_len_ser = plugin->serialize_attribute_value (attr, // &attr_ser[1]); data_len_ser = attr->data_size; - GNUNET_memcpy(write_ptr, attr->data, attr->data_size); - attr_ser->data_size = htons(data_len_ser); + GNUNET_memcpy (write_ptr, attr->data, attr->data_size); + attr_ser->data_size = htons (data_len_ser); - return sizeof(struct Attribute) + strlen(attr->name) + attr->data_size; + return sizeof(struct Attribute) + strlen (attr->name) + attr->data_size; } @@ -481,7 +482,7 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize( * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller */ struct GNUNET_RECLAIM_ATTRIBUTE_Claim * -GNUNET_RECLAIM_ATTRIBUTE_deserialize(const char *data, size_t data_size) +GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) { struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; struct Attribute *attr_ser; @@ -492,29 +493,29 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize(const char *data, size_t data_size) if (data_size < sizeof(struct Attribute)) return NULL; - attr_ser = (struct Attribute *)data; - data_len = ntohs(attr_ser->data_size); - name_len = ntohs(attr_ser->name_len); + attr_ser = (struct Attribute *) data; + data_len = ntohs (attr_ser->data_size); + name_len = ntohs (attr_ser->name_len); if (data_size < sizeof(struct Attribute) + data_len + name_len) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Buffer too small to deserialize\n"); - return NULL; - } - attr = GNUNET_malloc(sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + - data_len + name_len + 1); - attr->type = ntohs(attr_ser->attribute_type); - attr->version = ntohl(attr_ser->attribute_version); - attr->id = GNUNET_ntohll(attr_ser->attribute_id); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Buffer too small to deserialize\n"); + return NULL; + } + attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + + data_len + name_len + 1); + attr->type = ntohs (attr_ser->attribute_type); + attr->version = ntohl (attr_ser->attribute_version); + attr->id = GNUNET_ntohll (attr_ser->attribute_id); attr->data_size = data_len; - write_ptr = (char *)&attr[1]; - GNUNET_memcpy(write_ptr, &attr_ser[1], name_len); + write_ptr = (char *) &attr[1]; + GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); write_ptr[name_len] = '\0'; attr->name = write_ptr; write_ptr += name_len + 1; - GNUNET_memcpy(write_ptr, (char *)&attr_ser[1] + name_len, attr->data_size); + GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); attr->data = write_ptr; return attr; } -- cgit v1.2.3