From d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb Mon Sep 17 00:00:00 2001 From: ng0 Date: Sun, 8 Sep 2019 12:33:09 +0000 Subject: uncrustify as demanded. --- src/identity/gnunet-identity.c | 360 +++++----- src/identity/gnunet-service-identity.c | 1059 ++++++++++++++-------------- src/identity/identity.h | 29 +- src/identity/identity_api.c | 605 ++++++++-------- src/identity/identity_api_lookup.c | 122 ++-- src/identity/identity_api_suffix_lookup.c | 122 ++-- src/identity/plugin_rest_identity.c | 1090 ++++++++++++++--------------- src/identity/test_identity.c | 225 +++--- src/identity/test_identity_defaults.c | 178 ++--- 9 files changed, 1887 insertions(+), 1903 deletions(-) (limited to 'src/identity') diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 41878fc1e..d86fd2166 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file identity/gnunet-identity.c * @brief IDENTITY management command line tool @@ -112,29 +112,29 @@ static int global_ret; * @param cls NULL */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { if (NULL != set_op) - { - GNUNET_IDENTITY_cancel (set_op); - set_op = NULL; - } + { + GNUNET_IDENTITY_cancel(set_op); + set_op = NULL; + } if (NULL != create_op) - { - GNUNET_IDENTITY_cancel (create_op); - create_op = NULL; - } + { + GNUNET_IDENTITY_cancel(create_op); + create_op = NULL; + } if (NULL != delete_op) - { - GNUNET_IDENTITY_cancel (delete_op); - delete_op = NULL; - } + { + GNUNET_IDENTITY_cancel(delete_op); + delete_op = NULL; + } if (NULL != set_ego) - { - GNUNET_free (set_ego); - set_ego = NULL; - } - GNUNET_IDENTITY_disconnect (sh); + { + GNUNET_free(set_ego); + set_ego = NULL; + } + GNUNET_IDENTITY_disconnect(sh); sh = NULL; } @@ -143,15 +143,15 @@ shutdown_task (void *cls) * Test if we are finished yet. */ static void -test_finished () +test_finished() { if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) && - (NULL == set_subsystem) && (! list) && (! monitor)) - { - if (TIMEOUT_STATUS_CODE == global_ret) - global_ret = 0; - GNUNET_SCHEDULER_shutdown (); - } + (NULL == set_subsystem) && (!list) && (!monitor)) + { + if (TIMEOUT_STATUS_CODE == global_ret) + global_ret = 0; + GNUNET_SCHEDULER_shutdown(); + } } @@ -162,14 +162,14 @@ test_finished () * @param emsg NULL on success, otherwise an error message */ static void -delete_finished (void *cls, const char *emsg) +delete_finished(void *cls, const char *emsg) { struct GNUNET_IDENTITY_Operation **op = cls; *op = NULL; if (NULL != emsg) - fprintf (stderr, "%s\n", gettext (emsg)); - test_finished (); + fprintf(stderr, "%s\n", gettext(emsg)); + test_finished(); } @@ -181,40 +181,40 @@ delete_finished (void *cls, const char *emsg) * @param emsg error message, NULL on success */ static void -create_finished (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, - const char *emsg) +create_finished(void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, + const char *emsg) { struct GNUNET_IDENTITY_Operation **op = cls; *op = NULL; if (NULL == pk) - { - fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg); - global_ret = 1; - } - else if (verbose) - { - struct GNUNET_CRYPTO_EcdsaPublicKey pub; - char *pubs; - - GNUNET_CRYPTO_ecdsa_key_get_public (pk, &pub); - pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub); - if (private_keys) { - char *privs; - - privs = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); - fprintf (stdout, "%s - %s\n", pubs, privs); - GNUNET_free (privs); + fprintf(stderr, _("Failed to create ego: %s\n"), emsg); + global_ret = 1; } - else + else if (verbose) { - fprintf (stdout, "%s\n", pubs); + struct GNUNET_CRYPTO_EcdsaPublicKey pub; + char *pubs; + + GNUNET_CRYPTO_ecdsa_key_get_public(pk, &pub); + pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pub); + if (private_keys) + { + char *privs; + + privs = GNUNET_CRYPTO_ecdsa_private_key_to_string(pk); + fprintf(stdout, "%s - %s\n", pubs, privs); + GNUNET_free(privs); + } + else + { + fprintf(stdout, "%s\n", pubs); + } + GNUNET_free(pubs); } - GNUNET_free (pubs); - } - test_finished (); + test_finished(); } @@ -225,15 +225,15 @@ create_finished (void *cls, * @param emsg error message (NULL on success) */ static void -set_done (void *cls, const char *emsg) +set_done(void *cls, const char *emsg) { set_op = NULL; if (NULL != emsg) - { - fprintf (stderr, _ ("Failed to set default ego: %s\n"), emsg); - global_ret = 1; - } - test_finished (); + { + fprintf(stderr, _("Failed to set default ego: %s\n"), emsg); + global_ret = 1; + } + test_finished(); } @@ -269,72 +269,72 @@ set_done (void *cls, const char *emsg) * @param identifier identifier assigned by the user for this ego, * NULL if the user just deleted the ego and it * must thus no longer be used -*/ + */ static void -print_ego (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *identifier) +print_ego(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { struct GNUNET_CRYPTO_EcdsaPublicKey pk; char *s; char *privs; if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) && - (NULL != identifier) && (0 == strcmp (identifier, set_ego))) - { - set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL); - GNUNET_free (set_subsystem); - set_subsystem = NULL; - GNUNET_free (set_ego); - set_ego = NULL; - } + (NULL != identifier) && (0 == strcmp(identifier, set_ego))) + { + set_op = GNUNET_IDENTITY_set(sh, set_subsystem, ego, &set_done, NULL); + GNUNET_free(set_subsystem); + set_subsystem = NULL; + GNUNET_free(set_ego); + set_ego = NULL; + } if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem)) - { - fprintf (stderr, - "Could not set ego to `%s' for subsystem `%s', ego not known\n", - set_ego, - set_subsystem); - GNUNET_free (set_subsystem); - set_subsystem = NULL; - GNUNET_free (set_ego); - set_ego = NULL; - } - if ((NULL == ego) && (! monitor)) - { - list = 0; - test_finished (); - return; - } - if (! (list | monitor)) + { + fprintf(stderr, + "Could not set ego to `%s' for subsystem `%s', ego not known\n", + set_ego, + set_subsystem); + GNUNET_free(set_subsystem); + set_subsystem = NULL; + GNUNET_free(set_ego); + set_ego = NULL; + } + if ((NULL == ego) && (!monitor)) + { + list = 0; + test_finished(); + return; + } + if (!(list | monitor)) return; if ((NULL == ego) || (NULL == identifier)) return; - if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego))) + if ((NULL != set_ego) && (0 != strcmp(identifier, set_ego))) return; - GNUNET_IDENTITY_ego_get_public_key (ego, &pk); - s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); - privs = GNUNET_CRYPTO_ecdsa_private_key_to_string ( - GNUNET_IDENTITY_ego_get_private_key (ego)); + GNUNET_IDENTITY_ego_get_public_key(ego, &pk); + s = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); + privs = GNUNET_CRYPTO_ecdsa_private_key_to_string( + GNUNET_IDENTITY_ego_get_private_key(ego)); if ((monitor) || (NULL != identifier)) - { - if (quiet) { - if (private_keys) - fprintf (stdout, "%s - %s\n", s, privs); + if (quiet) + { + if (private_keys) + fprintf(stdout, "%s - %s\n", s, privs); + else + fprintf(stdout, "%s\n", s); + } else - fprintf (stdout, "%s\n", s); + { + if (private_keys) + fprintf(stdout, "%s - %s - %s\n", identifier, s, privs); + else + fprintf(stdout, "%s - %s\n", identifier, s); + } } - else - { - if (private_keys) - fprintf (stdout, "%s - %s - %s\n", identifier, s, privs); - else - fprintf (stdout, "%s - %s\n", identifier, s); - } - } - GNUNET_free (privs); - GNUNET_free (s); + GNUNET_free(privs); + GNUNET_free(s); } @@ -347,30 +347,30 @@ print_ego (void *cls, * @param cfg configuration */ 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) { if ((NULL != set_subsystem) && (NULL == set_ego)) - { - fprintf (stderr, "Option -s requires option -e to be specified as well.\n"); - return; - } - sh = GNUNET_IDENTITY_connect (cfg, - (monitor | list) || (NULL != set_ego) || - (NULL != set_subsystem) - ? &print_ego - : NULL, - NULL); + { + fprintf(stderr, "Option -s requires option -e to be specified as well.\n"); + return; + } + sh = GNUNET_IDENTITY_connect(cfg, + (monitor | list) || (NULL != set_ego) || + (NULL != set_subsystem) + ? &print_ego + : NULL, + NULL); if (NULL != delete_ego) delete_op = - GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op); + GNUNET_IDENTITY_delete(sh, delete_ego, &delete_finished, &delete_op); if (NULL != create_ego) create_op = - GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); - test_finished (); + GNUNET_IDENTITY_create(sh, create_ego, &create_finished, &create_op); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); + test_finished(); } @@ -382,64 +382,64 @@ run (void *cls, * @return 0 ok, 1 on error */ int -main (int argc, char *const *argv) +main(int argc, char *const *argv) { struct GNUNET_GETOPT_CommandLineOption options[] = - {GNUNET_GETOPT_option_string ('C', - "create", - "NAME", - gettext_noop ("create ego NAME"), - &create_ego), - GNUNET_GETOPT_option_string ('D', - "delete", - "NAME", - gettext_noop ("delete ego NAME "), - &delete_ego), - GNUNET_GETOPT_option_flag ('d', - "display", - gettext_noop ("display all egos"), - &list), - GNUNET_GETOPT_option_flag ('q', - "quiet", - gettext_noop ("reduce output"), - &quiet), - GNUNET_GETOPT_option_string ( - 'e', - "ego", - "NAME", - gettext_noop ( - "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"), - &set_ego), - GNUNET_GETOPT_option_flag ('m', - "monitor", - gettext_noop ("run in monitor mode egos"), - &monitor), - GNUNET_GETOPT_option_flag ('p', - "private-keys", - gettext_noop ("display private keys as well"), - &private_keys), - GNUNET_GETOPT_option_string ( - 's', - "set", - "SUBSYSTEM", - gettext_noop ( - "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), - &set_subsystem), - GNUNET_GETOPT_option_verbose (&verbose), - GNUNET_GETOPT_OPTION_END}; + { GNUNET_GETOPT_option_string('C', + "create", + "NAME", + gettext_noop("create ego NAME"), + &create_ego), + GNUNET_GETOPT_option_string('D', + "delete", + "NAME", + gettext_noop("delete ego NAME "), + &delete_ego), + GNUNET_GETOPT_option_flag('d', + "display", + gettext_noop("display all egos"), + &list), + GNUNET_GETOPT_option_flag('q', + "quiet", + gettext_noop("reduce output"), + &quiet), + GNUNET_GETOPT_option_string( + 'e', + "ego", + "NAME", + gettext_noop( + "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"), + &set_ego), + GNUNET_GETOPT_option_flag('m', + "monitor", + gettext_noop("run in monitor mode egos"), + &monitor), + GNUNET_GETOPT_option_flag('p', + "private-keys", + gettext_noop("display private keys as well"), + &private_keys), + GNUNET_GETOPT_option_string( + 's', + "set", + "SUBSYSTEM", + gettext_noop( + "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), + &set_subsystem), + GNUNET_GETOPT_option_verbose(&verbose), + GNUNET_GETOPT_OPTION_END }; int res; - if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) + if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) return 4; global_ret = TIMEOUT_STATUS_CODE; /* timeout */ - res = GNUNET_PROGRAM_run (argc, - argv, - "gnunet-identity", - gettext_noop ("Maintain egos"), - options, - &run, - NULL); - GNUNET_free ((void *) argv); + res = GNUNET_PROGRAM_run(argc, + argv, + "gnunet-identity", + gettext_noop("Maintain egos"), + options, + &run, + NULL); + GNUNET_free((void *)argv); if (GNUNET_OK != res) return 3; diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 34fad3272..f399b2566 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c @@ -1,19 +1,19 @@ /* - This file is part of GNUnet. - Copyright (C) 2013 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + This file is part of GNUnet. + Copyright (C) 2013 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later */ @@ -42,9 +42,7 @@ /** * Information we keep about each ego. */ -struct Ego -{ - +struct Ego { /** * We keep egos in a DLL. */ @@ -116,15 +114,15 @@ static struct Ego *ego_tail; * @return full filename for the given ego */ static char * -get_ego_filename (struct Ego *ego) +get_ego_filename(struct Ego *ego) { char *filename; - GNUNET_asprintf (&filename, - "%s%s%s", - ego_directory, - DIR_SEPARATOR_STR, - ego->identifier); + GNUNET_asprintf(&filename, + "%s%s%s", + ego_directory, + DIR_SEPARATOR_STR, + ego->identifier); return filename; } @@ -136,11 +134,11 @@ get_ego_filename (struct Ego *ego) * @param app_ctx @a client */ static void -client_disconnect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - void *app_ctx) +client_disconnect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + void *app_ctx) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); } @@ -153,9 +151,9 @@ client_disconnect_cb (void *cls, * @return internal namestore client structure for this client */ static void * -client_connect_cb (void *cls, - struct GNUNET_SERVICE_Client *client, - struct GNUNET_MQ_Handle *mq) +client_connect_cb(void *cls, + struct GNUNET_SERVICE_Client *client, + struct GNUNET_MQ_Handle *mq) { return client; } @@ -166,33 +164,33 @@ client_connect_cb (void *cls, * @param cls unused */ static void -shutdown_task (void *cls) +shutdown_task(void *cls) { struct Ego *e; if (NULL != nc) - { - GNUNET_notification_context_destroy (nc); - nc = NULL; - } + { + GNUNET_notification_context_destroy(nc); + nc = NULL; + } if (NULL != stats) - { - GNUNET_STATISTICS_destroy (stats, GNUNET_NO); - stats = NULL; - } - GNUNET_CONFIGURATION_destroy (subsystem_cfg); + { + GNUNET_STATISTICS_destroy(stats, GNUNET_NO); + stats = NULL; + } + GNUNET_CONFIGURATION_destroy(subsystem_cfg); subsystem_cfg = NULL; - GNUNET_free (subsystem_cfg_file); + GNUNET_free(subsystem_cfg_file); subsystem_cfg_file = NULL; - GNUNET_free (ego_directory); + GNUNET_free(ego_directory); ego_directory = NULL; while (NULL != (e = ego_head)) - { - GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); - GNUNET_free (e->pk); - GNUNET_free (e->identifier); - GNUNET_free (e); - } + { + GNUNET_CONTAINER_DLL_remove(ego_head, ego_tail, e); + GNUNET_free(e->pk); + GNUNET_free(e->identifier); + GNUNET_free(e); + } } @@ -204,9 +202,9 @@ shutdown_task (void *cls) * @param emsg error message to include (or NULL for none) */ static void -send_result_code (struct GNUNET_SERVICE_Client *client, - uint32_t result_code, - const char *emsg) +send_result_code(struct GNUNET_SERVICE_Client *client, + uint32_t result_code, + const char *emsg) { struct ResultCodeMessage *rcm; struct GNUNET_MQ_Envelope *env; @@ -215,17 +213,17 @@ send_result_code (struct GNUNET_SERVICE_Client *client, if (NULL == emsg) elen = 0; else - elen = strlen (emsg) + 1; + elen = strlen(emsg) + 1; env = - GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); - rcm->result_code = htonl (result_code); + GNUNET_MQ_msg_extra(rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); + rcm->result_code = htonl(result_code); if (0 < elen) - GNUNET_memcpy (&rcm[1], emsg, elen); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending result %d (%s) to client\n", - (int) result_code, - emsg); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); + GNUNET_memcpy(&rcm[1], emsg, elen); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Sending result %d (%s) to client\n", + (int)result_code, + emsg); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); } @@ -236,18 +234,18 @@ send_result_code (struct GNUNET_SERVICE_Client *client, * @return corresponding update message */ static struct GNUNET_MQ_Envelope * -create_update_message (struct Ego *ego) +create_update_message(struct Ego *ego) { struct UpdateMessage *um; struct GNUNET_MQ_Envelope *env; size_t name_len; - name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); - env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); - um->name_len = htons (name_len); - um->end_of_list = htons (GNUNET_NO); + name_len = (NULL == ego->identifier) ? 0 : (strlen(ego->identifier) + 1); + env = GNUNET_MQ_msg_extra(um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); + um->name_len = htons(name_len); + um->end_of_list = htons(GNUNET_NO); um->private_key = *ego->pk; - GNUNET_memcpy (&um[1], ego->identifier, name_len); + GNUNET_memcpy(&um[1], ego->identifier, name_len); return env; } @@ -260,20 +258,20 @@ create_update_message (struct Ego *ego) * @return corresponding set default message */ static struct GNUNET_MQ_Envelope * -create_set_default_message (struct Ego *ego, const char *servicename) +create_set_default_message(struct Ego *ego, const char *servicename) { struct SetDefaultMessage *sdm; struct GNUNET_MQ_Envelope *env; size_t name_len; - name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1); - env = GNUNET_MQ_msg_extra (sdm, - name_len, - GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); - sdm->name_len = htons (name_len); - sdm->reserved = htons (0); + name_len = (NULL == servicename) ? 0 : (strlen(servicename) + 1); + env = GNUNET_MQ_msg_extra(sdm, + name_len, + GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); + sdm->name_len = htons(name_len); + sdm->reserved = htons(0); sdm->private_key = *ego->pk; - GNUNET_memcpy (&sdm[1], servicename, name_len); + GNUNET_memcpy(&sdm[1], servicename, name_len); return env; } @@ -288,27 +286,27 @@ create_set_default_message (struct Ego *ego, const char *servicename) * @param message the message received */ static void -handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) +handle_start_message(void *cls, const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVICE_Client *client = cls; struct UpdateMessage *ume; struct GNUNET_MQ_Envelope *env; struct Ego *ego; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); - GNUNET_SERVICE_client_mark_monitor (client); - GNUNET_SERVICE_client_disable_continue_warning (client); - GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client)); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); + GNUNET_SERVICE_client_mark_monitor(client); + GNUNET_SERVICE_client_disable_continue_warning(client); + GNUNET_notification_context_add(nc, GNUNET_SERVICE_client_get_mq(client)); for (ego = ego_head; NULL != ego; ego = ego->next) - { - env = create_update_message (ego); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); - } - env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); - ume->end_of_list = htons (GNUNET_YES); - ume->name_len = htons (0); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); - GNUNET_SERVICE_client_continue (client); + { + env = create_update_message(ego); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); + } + env = GNUNET_MQ_msg_extra(ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); + ume->end_of_list = htons(GNUNET_YES); + ume->name_len = htons(0); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); + GNUNET_SERVICE_client_continue(client); } @@ -321,9 +319,9 @@ handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) * @return #GNUNET_SYSERR if message was ill-formed */ static int -check_lookup_message (void *cls, const struct LookupMessage *message) +check_lookup_message(void *cls, const struct LookupMessage *message) { - GNUNET_MQ_check_zero_termination (message); + GNUNET_MQ_check_zero_termination(message); return GNUNET_OK; } @@ -336,26 +334,26 @@ check_lookup_message (void *cls, const struct LookupMessage *message) * @param message the message received */ static void -handle_lookup_message (void *cls, const struct LookupMessage *message) +handle_lookup_message(void *cls, const struct LookupMessage *message) { struct GNUNET_SERVICE_Client *client = cls; const char *name; struct GNUNET_MQ_Envelope *env; struct Ego *ego; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); - name = (const char *) &message[1]; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); + name = (const char *)&message[1]; for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 != strcasecmp (name, ego->identifier)) - continue; - env = create_update_message (ego); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); - GNUNET_SERVICE_client_continue (client); - return; - } - send_result_code (client, 0, "ego not found"); - GNUNET_SERVICE_client_continue (client); + { + if (0 != strcasecmp(name, ego->identifier)) + continue; + env = create_update_message(ego); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); + GNUNET_SERVICE_client_continue(client); + return; + } + send_result_code(client, 0, "ego not found"); + GNUNET_SERVICE_client_continue(client); } @@ -368,9 +366,9 @@ handle_lookup_message (void *cls, const struct LookupMessage *message) * @return #GNUNET_SYSERR if message was ill-formed */ static int -check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) +check_lookup_by_suffix_message(void *cls, const struct LookupMessage *message) { - GNUNET_MQ_check_zero_termination (message); + GNUNET_MQ_check_zero_termination(message); return GNUNET_OK; } @@ -383,41 +381,40 @@ check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) * @param message the message received */ static void -handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) +handle_lookup_by_suffix_message(void *cls, const struct LookupMessage *message) { struct GNUNET_SERVICE_Client *client = cls; const char *name; struct GNUNET_MQ_Envelope *env; struct Ego *lprefix; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received LOOKUP_BY_SUFFIX message from client\n"); - name = (const char *) &message[1]; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received LOOKUP_BY_SUFFIX message from client\n"); + name = (const char *)&message[1]; lprefix = NULL; for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) - { - - if ((strlen (ego->identifier) <= strlen (name)) && - (0 == strcmp (ego->identifier, - &name[strlen (name) - strlen (ego->identifier)])) && - ((strlen (name) == strlen (ego->identifier)) || - ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) && - ((NULL == lprefix) || - (strlen (ego->identifier) > strlen (lprefix->identifier)))) { - /* found better match, update! */ - lprefix = ego; + if ((strlen(ego->identifier) <= strlen(name)) && + (0 == strcmp(ego->identifier, + &name[strlen(name) - strlen(ego->identifier)])) && + ((strlen(name) == strlen(ego->identifier)) || + ('.' == name[strlen(name) - strlen(ego->identifier) - 1])) && + ((NULL == lprefix) || + (strlen(ego->identifier) > strlen(lprefix->identifier)))) + { + /* found better match, update! */ + lprefix = ego; + } } - } if (NULL != lprefix) - { - env = create_update_message (lprefix); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); - GNUNET_SERVICE_client_continue (client); - return; - } - send_result_code (client, 0, "ego not found"); - GNUNET_SERVICE_client_continue (client); + { + env = create_update_message(lprefix); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); + GNUNET_SERVICE_client_continue(client); + return; + } + send_result_code(client, 0, "ego not found"); + GNUNET_SERVICE_client_continue(client); } @@ -429,26 +426,26 @@ handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_get_default_message (void *cls, const struct GetDefaultMessage *msg) +check_get_default_message(void *cls, const struct GetDefaultMessage *msg) { uint16_t size; uint16_t name_len; const char *name; - size = ntohs (msg->header.size); - if (size <= sizeof (struct GetDefaultMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - name = (const char *) &msg[1]; - name_len = ntohs (msg->name_len); - if ((name_len + sizeof (struct GetDefaultMessage) != size) || - (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + size = ntohs(msg->header.size); + if (size <= sizeof(struct GetDefaultMessage)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + name = (const char *)&msg[1]; + name_len = ntohs(msg->name_len); + if ((name_len + sizeof(struct GetDefaultMessage) != size) || + (0 != ntohs(msg->reserved)) || ('\0' != name[name_len - 1])) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -462,7 +459,7 @@ check_get_default_message (void *cls, const struct GetDefaultMessage *msg) * @param message the message received */ static void -handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) +handle_get_default_message(void *cls, const struct GetDefaultMessage *gdm) { struct GNUNET_MQ_Envelope *env; struct GNUNET_SERVICE_Client *client = cls; @@ -471,41 +468,41 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) char *identifier; - name = GNUNET_strdup ((const char *) &gdm[1]); - GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received GET_DEFAULT for service `%s' from client\n", - name); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, - name, - "DEFAULT_IDENTIFIER", - &identifier)) - { - send_result_code (client, 1, gettext_noop ("no default known")); - GNUNET_SERVICE_client_continue (client); - GNUNET_free (name); - return; - } - for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 == strcmp (ego->identifier, identifier)) + name = GNUNET_strdup((const char *)&gdm[1]); + GNUNET_STRINGS_utf8_tolower((const char *)&gdm[1], name); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received GET_DEFAULT for service `%s' from client\n", + name); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg, + name, + "DEFAULT_IDENTIFIER", + &identifier)) { - env = create_set_default_message (ego, name); - GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); - GNUNET_SERVICE_client_continue (client); - GNUNET_free (identifier); - GNUNET_free (name); + send_result_code(client, 1, gettext_noop("no default known")); + GNUNET_SERVICE_client_continue(client); + GNUNET_free(name); return; } - } - GNUNET_free (identifier); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); - GNUNET_free (name); - send_result_code (client, - 1, - gettext_noop ( - "default configured, but ego unknown (internal error)")); - GNUNET_SERVICE_client_continue (client); + for (ego = ego_head; NULL != ego; ego = ego->next) + { + if (0 == strcmp(ego->identifier, identifier)) + { + env = create_set_default_message(ego, name); + GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); + GNUNET_SERVICE_client_continue(client); + GNUNET_free(identifier); + GNUNET_free(name); + return; + } + } + GNUNET_free(identifier); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); + GNUNET_free(name); + send_result_code(client, + 1, + gettext_noop( + "default configured, but ego unknown (internal error)")); + GNUNET_SERVICE_client_continue(client); } @@ -517,10 +514,10 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) * @return 0 if the keys are equal */ static int -key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) +key_cmp(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) { - return GNUNET_memcmp (pk1, pk2); + return GNUNET_memcmp(pk1, pk2); } /** @@ -531,31 +528,31 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, * @return #GNUNET_OK if @a msg is well-formed */ static int -check_set_default_message (void *cls, const struct SetDefaultMessage *msg) +check_set_default_message(void *cls, const struct SetDefaultMessage *msg) { uint16_t size; uint16_t name_len; const char *str; - size = ntohs (msg->header.size); - if (size <= sizeof (struct SetDefaultMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - name_len = ntohs (msg->name_len); - GNUNET_break (0 == ntohs (msg->reserved)); - if (name_len + sizeof (struct SetDefaultMessage) != size) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - str = (const char *) &msg[1]; + size = ntohs(msg->header.size); + if (size <= sizeof(struct SetDefaultMessage)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + name_len = ntohs(msg->name_len); + GNUNET_break(0 == ntohs(msg->reserved)); + if (name_len + sizeof(struct SetDefaultMessage) != size) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + str = (const char *)&msg[1]; if ('\0' != str[name_len - 1]) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -568,43 +565,43 @@ check_set_default_message (void *cls, const struct SetDefaultMessage *msg) * @param message the message received */ static void -handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) +handle_set_default_message(void *cls, const struct SetDefaultMessage *sdm) { struct Ego *ego; struct GNUNET_SERVICE_Client *client = cls; char *str; - str = GNUNET_strdup ((const char *) &sdm[1]); - GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str); + str = GNUNET_strdup((const char *)&sdm[1]); + GNUNET_STRINGS_utf8_tolower((const char *)&sdm[1], str); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received SET_DEFAULT for service `%s' from client\n", - str); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received SET_DEFAULT for service `%s' from client\n", + str); for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 == key_cmp (ego->pk, &sdm->private_key)) { - GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, - str, - "DEFAULT_IDENTIFIER", - ego->identifier); - if (GNUNET_OK != - GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) - GNUNET_log ( - GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to write subsystem default identifier map to `%s'.\n"), - subsystem_cfg_file); - send_result_code (client, 0, NULL); - GNUNET_SERVICE_client_continue (client); - GNUNET_free (str); - return; + if (0 == key_cmp(ego->pk, &sdm->private_key)) + { + GNUNET_CONFIGURATION_set_value_string(subsystem_cfg, + str, + "DEFAULT_IDENTIFIER", + ego->identifier); + if (GNUNET_OK != + GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file)) + GNUNET_log( + GNUNET_ERROR_TYPE_ERROR, + _("Failed to write subsystem default identifier map to `%s'.\n"), + subsystem_cfg_file); + send_result_code(client, 0, NULL); + GNUNET_SERVICE_client_continue(client); + GNUNET_free(str); + return; + } } - } - send_result_code (client, - 1, - _ ("Unknown ego specified for service (internal error)")); - GNUNET_free (str); - GNUNET_SERVICE_client_continue (client); + send_result_code(client, + 1, + _("Unknown ego specified for service (internal error)")); + GNUNET_free(str); + GNUNET_SERVICE_client_continue(client); } @@ -614,21 +611,21 @@ handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) * @param ego ego to send the update for */ static void -notify_listeners (struct Ego *ego) +notify_listeners(struct Ego *ego) { struct UpdateMessage *um; size_t name_len; - name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); - um = GNUNET_malloc (sizeof (struct UpdateMessage) + name_len); - um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); - um->header.size = htons (sizeof (struct UpdateMessage) + name_len); - um->name_len = htons (name_len); - um->end_of_list = htons (GNUNET_NO); + name_len = (NULL == ego->identifier) ? 0 : (strlen(ego->identifier) + 1); + um = GNUNET_malloc(sizeof(struct UpdateMessage) + name_len); + um->header.type = htons(GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); + um->header.size = htons(sizeof(struct UpdateMessage) + name_len); + um->name_len = htons(name_len); + um->end_of_list = htons(GNUNET_NO); um->private_key = *ego->pk; - GNUNET_memcpy (&um[1], ego->identifier, name_len); - GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); - GNUNET_free (um); + GNUNET_memcpy(&um[1], ego->identifier, name_len); + GNUNET_notification_context_broadcast(nc, &um->header, GNUNET_NO); + GNUNET_free(um); } /** @@ -639,32 +636,31 @@ notify_listeners (struct Ego *ego) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_create_message (void *cls, const struct CreateRequestMessage *msg) +check_create_message(void *cls, const struct CreateRequestMessage *msg) { - uint16_t size; uint16_t name_len; const char *str; - size = ntohs (msg->header.size); - if (size <= sizeof (struct CreateRequestMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - name_len = ntohs (msg->name_len); - GNUNET_break (0 == ntohs (msg->reserved)); - if (name_len + sizeof (struct CreateRequestMessage) != size) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - str = (const char *) &msg[1]; + size = ntohs(msg->header.size); + if (size <= sizeof(struct CreateRequestMessage)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + name_len = ntohs(msg->name_len); + GNUNET_break(0 == ntohs(msg->reserved)); + if (name_len + sizeof(struct CreateRequestMessage) != size) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + str = (const char *)&msg[1]; if ('\0' != str[name_len - 1]) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -677,56 +673,55 @@ check_create_message (void *cls, const struct CreateRequestMessage *msg) * @param message the message received */ static void -handle_create_message (void *cls, const struct CreateRequestMessage *crm) +handle_create_message(void *cls, const struct CreateRequestMessage *crm) { struct GNUNET_SERVICE_Client *client = cls; struct Ego *ego; char *str; char *fn; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); - str = GNUNET_strdup ((const char *) &crm[1]); - GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); + str = GNUNET_strdup((const char *)&crm[1]); + GNUNET_STRINGS_utf8_tolower((const char *)&crm[1], str); for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 == strcmp (ego->identifier, str)) { - send_result_code (client, - 1, - gettext_noop ( - "identifier already in use for another ego")); - GNUNET_SERVICE_client_continue (client); - GNUNET_free (str); - return; + if (0 == strcmp(ego->identifier, str)) + { + send_result_code(client, + 1, + gettext_noop( + "identifier already in use for another ego")); + GNUNET_SERVICE_client_continue(client); + GNUNET_free(str); + return; + } } - } - ego = GNUNET_new (struct Ego); - ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); + ego = GNUNET_new(struct Ego); + ego->pk = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); *ego->pk = crm->private_key; - ego->identifier = GNUNET_strdup (str); - GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); - send_result_code (client, 0, NULL); - fn = get_ego_filename (ego); - (void) GNUNET_DISK_directory_create_for_file (fn); - if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != - GNUNET_DISK_fn_write (fn, - &crm->private_key, - sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); - GNUNET_free (fn); - GNUNET_free (str); - notify_listeners (ego); - GNUNET_SERVICE_client_continue (client); + ego->identifier = GNUNET_strdup(str); + GNUNET_CONTAINER_DLL_insert(ego_head, ego_tail, ego); + send_result_code(client, 0, NULL); + fn = get_ego_filename(ego); + (void)GNUNET_DISK_directory_create_for_file(fn); + if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) != + GNUNET_DISK_fn_write(fn, + &crm->private_key, + sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", fn); + GNUNET_free(fn); + GNUNET_free(str); + notify_listeners(ego); + GNUNET_SERVICE_client_continue(client); } /** * Closure for 'handle_ego_rename'. */ -struct RenameContext -{ +struct RenameContext { /** * Old name. */ @@ -746,26 +741,26 @@ struct RenameContext * @param section a section in the configuration to process */ static void -handle_ego_rename (void *cls, const char *section) +handle_ego_rename(void *cls, const char *section) { struct RenameContext *rc = cls; char *id; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, - section, - "DEFAULT_IDENTIFIER", - &id)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg, + section, + "DEFAULT_IDENTIFIER", + &id)) return; - if (0 != strcmp (id, rc->old_name)) - { - GNUNET_free (id); - return; - } - GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, - section, - "DEFAULT_IDENTIFIER", - rc->new_name); - GNUNET_free (id); + if (0 != strcmp(id, rc->old_name)) + { + GNUNET_free(id); + return; + } + GNUNET_CONFIGURATION_set_value_string(subsystem_cfg, + section, + "DEFAULT_IDENTIFIER", + rc->new_name); + GNUNET_free(id); } /** @@ -776,7 +771,7 @@ handle_ego_rename (void *cls, const char *section) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_rename_message (void *cls, const struct RenameMessage *msg) +check_rename_message(void *cls, const struct RenameMessage *msg) { uint16_t size; uint16_t old_name_len; @@ -784,23 +779,23 @@ check_rename_message (void *cls, const struct RenameMessage *msg) const char *old_name; const char *new_name; - size = ntohs (msg->header.size); - if (size <= sizeof (struct RenameMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - old_name_len = ntohs (msg->old_name_len); - new_name_len = ntohs (msg->new_name_len); - old_name = (const char *) &msg[1]; + size = ntohs(msg->header.size); + if (size <= sizeof(struct RenameMessage)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + old_name_len = ntohs(msg->old_name_len); + new_name_len = ntohs(msg->new_name_len); + old_name = (const char *)&msg[1]; new_name = &old_name[old_name_len]; - if ((old_name_len + new_name_len + sizeof (struct RenameMessage) != size) || + if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) || ('\0' != old_name[old_name_len - 1]) || ('\0' != new_name[new_name_len - 1])) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -815,7 +810,7 @@ check_rename_message (void *cls, const struct RenameMessage *msg) * @param message the message received */ static void -handle_rename_message (void *cls, const struct RenameMessage *rm) +handle_rename_message(void *cls, const struct RenameMessage *rm) { uint16_t old_name_len; struct Ego *ego; @@ -827,65 +822,65 @@ handle_rename_message (void *cls, const struct RenameMessage *rm) char *fn_new; const char *old_name_tmp; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); - old_name_len = ntohs (rm->old_name_len); - old_name_tmp = (const char *) &rm[1]; - old_name = GNUNET_strdup (old_name_tmp); - GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name); - new_name = GNUNET_strdup (&old_name_tmp[old_name_len]); - GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); + old_name_len = ntohs(rm->old_name_len); + old_name_tmp = (const char *)&rm[1]; + old_name = GNUNET_strdup(old_name_tmp); + GNUNET_STRINGS_utf8_tolower(old_name_tmp, old_name); + new_name = GNUNET_strdup(&old_name_tmp[old_name_len]); + GNUNET_STRINGS_utf8_tolower(&old_name_tmp[old_name_len], new_name); /* check if new name is already in use */ for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 == strcmp (ego->identifier, new_name)) { - send_result_code (client, 1, gettext_noop ("target name already exists")); - GNUNET_SERVICE_client_continue (client); - GNUNET_free (old_name); - GNUNET_free (new_name); - return; + if (0 == strcmp(ego->identifier, new_name)) + { + send_result_code(client, 1, gettext_noop("target name already exists")); + GNUNET_SERVICE_client_continue(client); + GNUNET_free(old_name); + GNUNET_free(new_name); + return; + } } - } /* locate old name and, if found, perform rename */ for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 == strcmp (ego->identifier, old_name)) { - fn_old = get_ego_filename (ego); - GNUNET_free (ego->identifier); - rename_ctx.old_name = old_name; - rename_ctx.new_name = new_name; - GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, - &handle_ego_rename, - &rename_ctx); - if (GNUNET_OK != - GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) - GNUNET_log ( - GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to write subsystem default identifier map to `%s'.\n"), - subsystem_cfg_file); - ego->identifier = GNUNET_strdup (new_name); - fn_new = get_ego_filename (ego); - if (0 != rename (fn_old, fn_new)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); - GNUNET_free (fn_old); - GNUNET_free (fn_new); - GNUNET_free (old_name); - GNUNET_free (new_name); - notify_listeners (ego); - send_result_code (client, 0, NULL); - GNUNET_SERVICE_client_continue (client); - return; + if (0 == strcmp(ego->identifier, old_name)) + { + fn_old = get_ego_filename(ego); + GNUNET_free(ego->identifier); + rename_ctx.old_name = old_name; + rename_ctx.new_name = new_name; + GNUNET_CONFIGURATION_iterate_sections(subsystem_cfg, + &handle_ego_rename, + &rename_ctx); + if (GNUNET_OK != + GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file)) + GNUNET_log( + GNUNET_ERROR_TYPE_ERROR, + _("Failed to write subsystem default identifier map to `%s'.\n"), + subsystem_cfg_file); + ego->identifier = GNUNET_strdup(new_name); + fn_new = get_ego_filename(ego); + if (0 != rename(fn_old, fn_new)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); + GNUNET_free(fn_old); + GNUNET_free(fn_new); + GNUNET_free(old_name); + GNUNET_free(new_name); + notify_listeners(ego); + send_result_code(client, 0, NULL); + GNUNET_SERVICE_client_continue(client); + return; + } } - } /* failed to locate old name */ - send_result_code (client, 1, gettext_noop ("no matching ego found")); - GNUNET_free (old_name); - GNUNET_free (new_name); - GNUNET_SERVICE_client_continue (client); + send_result_code(client, 1, gettext_noop("no matching ego found")); + GNUNET_free(old_name); + GNUNET_free(new_name); + GNUNET_SERVICE_client_continue(client); } @@ -897,26 +892,26 @@ handle_rename_message (void *cls, const struct RenameMessage *rm) * @param section a section in the configuration to process */ static void -handle_ego_delete (void *cls, const char *section) +handle_ego_delete(void *cls, const char *section) { const char *identifier = cls; char *id; - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, - section, - "DEFAULT_IDENTIFIER", - &id)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg, + section, + "DEFAULT_IDENTIFIER", + &id)) return; - if (0 != strcmp (id, identifier)) - { - GNUNET_free (id); - return; - } - GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, - section, - "DEFAULT_IDENTIFIER", - NULL); - GNUNET_free (id); + if (0 != strcmp(id, identifier)) + { + GNUNET_free(id); + return; + } + GNUNET_CONFIGURATION_set_value_string(subsystem_cfg, + section, + "DEFAULT_IDENTIFIER", + NULL); + GNUNET_free(id); } /** @@ -927,26 +922,26 @@ handle_ego_delete (void *cls, const char *section) * @return #GNUNET_OK if @a msg is well-formed */ static int -check_delete_message (void *cls, const struct DeleteMessage *msg) +check_delete_message(void *cls, const struct DeleteMessage *msg) { uint16_t size; uint16_t name_len; const char *name; - size = ntohs (msg->header.size); - if (size <= sizeof (struct DeleteMessage)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - name = (const char *) &msg[1]; - name_len = ntohs (msg->name_len); - if ((name_len + sizeof (struct DeleteMessage) != size) || - (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + size = ntohs(msg->header.size); + if (size <= sizeof(struct DeleteMessage)) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + name = (const char *)&msg[1]; + name_len = ntohs(msg->name_len); + if ((name_len + sizeof(struct DeleteMessage) != size) || + (0 != ntohs(msg->reserved)) || ('\0' != name[name_len - 1])) + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -960,50 +955,50 @@ check_delete_message (void *cls, const struct DeleteMessage *msg) * @param message the message received */ static void -handle_delete_message (void *cls, const struct DeleteMessage *dm) +handle_delete_message(void *cls, const struct DeleteMessage *dm) { struct Ego *ego; char *name; char *fn; struct GNUNET_SERVICE_Client *client = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); - name = GNUNET_strdup ((const char *) &dm[1]); - GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); + name = GNUNET_strdup((const char *)&dm[1]); + GNUNET_STRINGS_utf8_tolower((const char *)&dm[1], name); for (ego = ego_head; NULL != ego; ego = ego->next) - { - if (0 == strcmp (ego->identifier, name)) { - GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); - GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, - &handle_ego_delete, - ego->identifier); - if (GNUNET_OK != - GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) - GNUNET_log ( - GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to write subsystem default identifier map to `%s'.\n"), - subsystem_cfg_file); - fn = get_ego_filename (ego); - if (0 != unlink (fn)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); - GNUNET_free (fn); - GNUNET_free (ego->identifier); - ego->identifier = NULL; - notify_listeners (ego); - GNUNET_free (ego->pk); - GNUNET_free (ego); - GNUNET_free (name); - send_result_code (client, 0, NULL); - GNUNET_SERVICE_client_continue (client); - return; + if (0 == strcmp(ego->identifier, name)) + { + GNUNET_CONTAINER_DLL_remove(ego_head, ego_tail, ego); + GNUNET_CONFIGURATION_iterate_sections(subsystem_cfg, + &handle_ego_delete, + ego->identifier); + if (GNUNET_OK != + GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file)) + GNUNET_log( + GNUNET_ERROR_TYPE_ERROR, + _("Failed to write subsystem default identifier map to `%s'.\n"), + subsystem_cfg_file); + fn = get_ego_filename(ego); + if (0 != unlink(fn)) + GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + GNUNET_free(fn); + GNUNET_free(ego->identifier); + ego->identifier = NULL; + notify_listeners(ego); + GNUNET_free(ego->pk); + GNUNET_free(ego); + GNUNET_free(name); + send_result_code(client, 0, NULL); + GNUNET_SERVICE_client_continue(client); + return; + } } - } - send_result_code (client, 1, gettext_noop ("no matching ego found")); - GNUNET_free (name); - GNUNET_SERVICE_client_continue (client); + send_result_code(client, 1, gettext_noop("no matching ego found")); + GNUNET_free(name); + GNUNET_SERVICE_client_continue(client); } @@ -1018,30 +1013,30 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) * #GNUNET_SYSERR to abort iteration with error! */ static int -process_ego_file (void *cls, const char *filename) +process_ego_file(void *cls, const char *filename) { struct Ego *ego; const char *fn; - fn = strrchr (filename, (int) DIR_SEPARATOR); + fn = strrchr(filename, (int)DIR_SEPARATOR); if (NULL == fn) - { - GNUNET_break (0); - return GNUNET_OK; - } - ego = GNUNET_new (struct Ego); - ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename); + { + GNUNET_break(0); + return GNUNET_OK; + } + ego = GNUNET_new(struct Ego); + ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file(filename); if (NULL == ego->pk) - { - GNUNET_free (ego); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ ("Failed to parse ego information in `%s'\n"), - filename); - return GNUNET_OK; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); - ego->identifier = GNUNET_strdup (fn + 1); - GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); + { + GNUNET_free(ego); + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, + _("Failed to parse ego information in `%s'\n"), + filename); + return GNUNET_OK; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); + ego->identifier = GNUNET_strdup(fn + 1); + GNUNET_CONTAINER_DLL_insert(ego_head, ego_tail, ego); return GNUNET_OK; } @@ -1054,103 +1049,103 @@ process_ego_file (void *cls, const char *filename) * @param c configuration to use */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *c, - struct GNUNET_SERVICE_Handle *service) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *c, + struct GNUNET_SERVICE_Handle *service) { cfg = c; - nc = GNUNET_notification_context_create (1); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, - "identity", - "EGODIR", - &ego_directory)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); - GNUNET_SCHEDULER_shutdown (); - return; - } + nc = GNUNET_notification_context_create(1); + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, + "identity", + "EGODIR", + &ego_directory)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); + GNUNET_SCHEDULER_shutdown(); + return; + } if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, - "identity", - "SUBSYSTEM_CFG", - &subsystem_cfg_file)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "identity", - "SUBSYSTEM_CFG"); - GNUNET_SCHEDULER_shutdown (); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Loading subsystem configuration `%s'\n", - subsystem_cfg_file); - subsystem_cfg = GNUNET_CONFIGURATION_create (); - if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) && + GNUNET_CONFIGURATION_get_value_filename(cfg, + "identity", + "SUBSYSTEM_CFG", + &subsystem_cfg_file)) + { + GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, + "identity", + "SUBSYSTEM_CFG"); + GNUNET_SCHEDULER_shutdown(); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Loading subsystem configuration `%s'\n", + subsystem_cfg_file); + subsystem_cfg = GNUNET_CONFIGURATION_create(); + if ((GNUNET_YES == GNUNET_DISK_file_test(subsystem_cfg_file)) && (GNUNET_OK != - GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file))) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ( - "Failed to parse subsystem identity configuration file `%s'\n"), - subsystem_cfg_file); - GNUNET_SCHEDULER_shutdown (); - return; - } - stats = GNUNET_STATISTICS_create ("identity", cfg); - if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ ("Failed to create directory `%s' for storing egos\n"), - ego_directory); - } - GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); - GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + GNUNET_CONFIGURATION_parse(subsystem_cfg, subsystem_cfg_file))) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _( + "Failed to parse subsystem identity configuration file `%s'\n"), + subsystem_cfg_file); + GNUNET_SCHEDULER_shutdown(); + return; + } + stats = GNUNET_STATISTICS_create("identity", cfg); + if (GNUNET_OK != GNUNET_DISK_directory_create(ego_directory)) + { + GNUNET_log(GNUNET_ERROR_TYPE_ERROR, + _("Failed to create directory `%s' for storing egos\n"), + ego_directory); + } + GNUNET_DISK_directory_scan(ego_directory, &process_ego_file, NULL); + GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); } /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN ( +GNUNET_SERVICE_MAIN( "identity", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, - GNUNET_MQ_hd_fixed_size (start_message, - GNUNET_MESSAGE_TYPE_IDENTITY_START, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_hd_var_size (lookup_message, - GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, - struct LookupMessage, - NULL), - GNUNET_MQ_hd_var_size (lookup_by_suffix_message, - GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, - struct LookupMessage, - NULL), - GNUNET_MQ_hd_var_size (get_default_message, - GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, - struct GetDefaultMessage, - NULL), - GNUNET_MQ_hd_var_size (set_default_message, - GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, - struct SetDefaultMessage, - NULL), - GNUNET_MQ_hd_var_size (create_message, - GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, - struct CreateRequestMessage, - NULL), - GNUNET_MQ_hd_var_size (rename_message, - GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, - struct RenameMessage, - NULL), - GNUNET_MQ_hd_var_size (delete_message, - GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, - struct DeleteMessage, - NULL), - GNUNET_MQ_handler_end ()); + GNUNET_MQ_hd_fixed_size(start_message, + GNUNET_MESSAGE_TYPE_IDENTITY_START, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_hd_var_size(lookup_message, + GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, + struct LookupMessage, + NULL), + GNUNET_MQ_hd_var_size(lookup_by_suffix_message, + GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, + struct LookupMessage, + NULL), + GNUNET_MQ_hd_var_size(get_default_message, + GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, + struct GetDefaultMessage, + NULL), + GNUNET_MQ_hd_var_size(set_default_message, + GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, + struct SetDefaultMessage, + NULL), + GNUNET_MQ_hd_var_size(create_message, + GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, + struct CreateRequestMessage, + NULL), + GNUNET_MQ_hd_var_size(rename_message, + GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, + struct RenameMessage, + NULL), + GNUNET_MQ_hd_var_size(delete_message, + GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, + struct DeleteMessage, + NULL), + GNUNET_MQ_handler_end()); /* end of gnunet-service-identity.c */ diff --git a/src/identity/identity.h b/src/identity/identity.h index 6ef16e39d..6a4090ad8 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @author Christian Grothoff @@ -39,8 +39,7 @@ GNUNET_NETWORK_STRUCT_BEGIN * GET_DEFAULT maybe answered with this message on failure; * CREATE and RENAME will always be answered with this message. */ -struct ResultCodeMessage -{ +struct ResultCodeMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE */ @@ -59,8 +58,7 @@ struct ResultCodeMessage /** * Client informs service about desire to lookup a (single) pseudonym. */ -struct LookupMessage -{ +struct LookupMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP or * #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX @@ -74,8 +72,7 @@ struct LookupMessage /** * Service informs client about status of a pseudonym. */ -struct UpdateMessage -{ +struct UpdateMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE */ @@ -105,8 +102,7 @@ struct UpdateMessage * Client requests knowledge about default identity for * a subsystem from identity service. */ -struct GetDefaultMessage -{ +struct GetDefaultMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT */ @@ -131,8 +127,7 @@ struct GetDefaultMessage * Used from service to client as a result to the GET_DEFAULT * message, used from client to service to SET_DEFAULT. */ -struct SetDefaultMessage -{ +struct SetDefaultMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT */ @@ -161,8 +156,7 @@ struct SetDefaultMessage * Client requests creation of an identity. Service * will respond with a result code. */ -struct CreateRequestMessage -{ +struct CreateRequestMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE */ @@ -191,8 +185,7 @@ struct CreateRequestMessage * Client requests renaming of an identity. Service * will respond with a result code. */ -struct RenameMessage -{ +struct RenameMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME */ @@ -217,8 +210,7 @@ struct RenameMessage * Client requests deletion of an identity. Service * will respond with a result code. */ -struct DeleteMessage -{ +struct DeleteMessage { /** * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE */ @@ -242,8 +234,7 @@ GNUNET_NETWORK_STRUCT_END /** * Handle for an ego. */ -struct GNUNET_IDENTITY_Ego -{ +struct GNUNET_IDENTITY_Ego { /** * Private key associated with this ego. */ diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index c463da641..530ee2d13 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file identity/identity_api.c @@ -30,15 +30,13 @@ #include "gnunet_identity_service.h" #include "identity.h" -#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) /** * Handle for an operation with the identity service. */ -struct GNUNET_IDENTITY_Operation -{ - +struct GNUNET_IDENTITY_Operation { /** * Main identity handle. */ @@ -93,8 +91,7 @@ struct GNUNET_IDENTITY_Operation /** * Handle for the service. */ -struct GNUNET_IDENTITY_Handle -{ +struct GNUNET_IDENTITY_Handle { /** * Configuration to use. */ @@ -154,7 +151,7 @@ struct GNUNET_IDENTITY_Handle * @return handle for the anonymous user, must not be freed */ const struct GNUNET_IDENTITY_Ego * -GNUNET_IDENTITY_ego_get_anonymous () +GNUNET_IDENTITY_ego_get_anonymous() { static struct GNUNET_IDENTITY_Ego anon; struct GNUNET_CRYPTO_EcdsaPublicKey pub; @@ -162,9 +159,9 @@ GNUNET_IDENTITY_ego_get_anonymous () if (NULL != anon.pk) return &anon; anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) - GNUNET_CRYPTO_ecdsa_key_get_anonymous (); - GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &anon.id); + GNUNET_CRYPTO_ecdsa_key_get_anonymous(); + GNUNET_CRYPTO_ecdsa_key_get_public(anon.pk, &pub); + GNUNET_CRYPTO_hash(&pub, sizeof(pub), &anon.id); return &anon; } @@ -175,7 +172,7 @@ GNUNET_IDENTITY_ego_get_anonymous () * @param cls handle to the identity service. */ static void -reconnect (void *cls); +reconnect(void *cls); /** @@ -187,18 +184,18 @@ reconnect (void *cls); * @return #GNUNET_OK (continue to iterate) */ static int -free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) +free_ego(void *cls, const struct GNUNET_HashCode *key, void *value) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_IDENTITY_Ego *ego = value; if (NULL != h->cb) - h->cb (h->cb_cls, ego, &ego->ctx, NULL); - GNUNET_free (ego->pk); - GNUNET_free (ego->name); - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); - GNUNET_free (ego); + h->cb(h->cb_cls, ego, &ego->ctx, NULL); + GNUNET_free(ego->pk); + GNUNET_free(ego->name); + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_remove(h->egos, key, value)); + GNUNET_free(ego); return GNUNET_OK; } @@ -209,38 +206,38 @@ free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) * @param h transport service to reconnect */ static void -reschedule_connect (struct GNUNET_IDENTITY_Handle *h) +reschedule_connect(struct GNUNET_IDENTITY_Handle *h) { struct GNUNET_IDENTITY_Operation *op; - GNUNET_assert (NULL == h->reconnect_task); + GNUNET_assert(NULL == h->reconnect_task); if (NULL != h->mq) - { - GNUNET_MQ_destroy (h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy(h->mq); + h->mq = NULL; + } while (NULL != (op = h->op_head)) - { - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); - if (NULL != op->cont) - op->cont (op->cls, "Error in communication with the identity service"); - else if (NULL != op->cb) - op->cb (op->cls, NULL, NULL, NULL); - else if (NULL != op->create_cont) - op->create_cont (op->cls, - NULL, - "Failed to communicate with the identity service"); - GNUNET_free_non_null (op->pk); - GNUNET_free (op); - } - GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Scheduling task to reconnect to identity service in %s.\n", - GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); + { + GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); + if (NULL != op->cont) + op->cont(op->cls, "Error in communication with the identity service"); + else if (NULL != op->cb) + op->cb(op->cls, NULL, NULL, NULL); + else if (NULL != op->create_cont) + op->create_cont(op->cls, + NULL, + "Failed to communicate with the identity service"); + GNUNET_free_non_null(op->pk); + GNUNET_free(op); + } + GNUNET_CONTAINER_multihashmap_iterate(h->egos, &free_ego, h); + LOG(GNUNET_ERROR_TYPE_DEBUG, + "Scheduling task to reconnect to identity service in %s.\n", + GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); h->reconnect_task = - GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); - h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); + GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); + h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); } @@ -253,11 +250,11 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) * @param error error code */ static void -mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_IDENTITY_Handle *h = cls; - reschedule_connect (h); + reschedule_connect(h); } @@ -270,10 +267,10 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) { - if (sizeof (*rcm) != htons (rcm->header.size)) - GNUNET_MQ_check_zero_termination (rcm); + if (sizeof(*rcm) != htons(rcm->header.size)) + GNUNET_MQ_check_zero_termination(rcm); return GNUNET_OK; } @@ -285,29 +282,29 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @param rcm result message received */ static void -handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_IDENTITY_Operation *op; - uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm); - const char *str = (0 == size) ? NULL : (const char *) &rcm[1]; + uint16_t size = ntohs(rcm->header.size) - sizeof(*rcm); + const char *str = (0 == size) ? NULL : (const char *)&rcm[1]; op = h->op_head; if (NULL == op) - { - GNUNET_break (0); - reschedule_connect (h); - return; - } - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + { + GNUNET_break(0); + reschedule_connect(h); + return; + } + GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); if (NULL != op->cont) - op->cont (op->cls, str); + op->cont(op->cls, str); else if (NULL != op->cb) - op->cb (op->cls, NULL, NULL, NULL); + op->cb(op->cls, NULL, NULL, NULL); else if (NULL != op->create_cont) - op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str); - GNUNET_free_non_null (op->pk); - GNUNET_free (op); + op->create_cont(op->cls, (NULL == str) ? op->pk : NULL, str); + GNUNET_free_non_null(op->pk); + GNUNET_free(op); } @@ -319,18 +316,18 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_update (void *cls, const struct UpdateMessage *um) +check_identity_update(void *cls, const struct UpdateMessage *um) { - uint16_t size = ntohs (um->header.size); - uint16_t name_len = ntohs (um->name_len); - const char *str = (const char *) &um[1]; + uint16_t size = ntohs(um->header.size); + uint16_t name_len = ntohs(um->name_len); + const char *str = (const char *)&um[1]; - if ((size != name_len + sizeof (struct UpdateMessage)) || + if ((size != name_len + sizeof(struct UpdateMessage)) || ((0 != name_len) && ('\0' != str[name_len - 1]))) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -342,70 +339,70 @@ check_identity_update (void *cls, const struct UpdateMessage *um) * @param um message received */ static void -handle_identity_update (void *cls, const struct UpdateMessage *um) +handle_identity_update(void *cls, const struct UpdateMessage *um) { struct GNUNET_IDENTITY_Handle *h = cls; - uint16_t name_len = ntohs (um->name_len); - const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; + uint16_t name_len = ntohs(um->name_len); + const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_HashCode id; struct GNUNET_IDENTITY_Ego *ego; - if (GNUNET_YES == ntohs (um->end_of_list)) - { - /* end of initial list of data */ - if (NULL != h->cb) - h->cb (h->cb_cls, NULL, NULL, NULL); - return; - } - GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); - ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); - if (NULL == ego) - { - /* ego was created */ - if (NULL == str) + if (GNUNET_YES == ntohs(um->end_of_list)) { - /* deletion of unknown ego? not allowed */ - GNUNET_break (0); - reschedule_connect (h); + /* end of initial list of data */ + if (NULL != h->cb) + h->cb(h->cb_cls, NULL, NULL, NULL); return; } - ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); - ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); - *ego->pk = um->private_key; - ego->name = GNUNET_strdup (str); - ego->id = id; - GNUNET_assert (GNUNET_YES == - GNUNET_CONTAINER_multihashmap_put ( - h->egos, - &ego->id, - ego, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); - } + GNUNET_CRYPTO_ecdsa_key_get_public(&um->private_key, &pub); + GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); + ego = GNUNET_CONTAINER_multihashmap_get(h->egos, &id); + if (NULL == ego) + { + /* ego was created */ + if (NULL == str) + { + /* deletion of unknown ego? not allowed */ + GNUNET_break(0); + reschedule_connect(h); + return; + } + ego = GNUNET_new(struct GNUNET_IDENTITY_Ego); + ego->pk = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); + *ego->pk = um->private_key; + ego->name = GNUNET_strdup(str); + ego->id = id; + GNUNET_assert(GNUNET_YES == + GNUNET_CONTAINER_multihashmap_put( + h->egos, + &ego->id, + ego, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); + } if (NULL == str) - { - /* ego was deleted */ - GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos, + { + /* ego was deleted */ + GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(h->egos, &ego->id, ego)); - } + } else - { - /* ego changed name */ - GNUNET_free (ego->name); - ego->name = GNUNET_strdup (str); - } + { + /* ego changed name */ + GNUNET_free(ego->name); + ego->name = GNUNET_strdup(str); + } /* inform application about change */ if (NULL != h->cb) - h->cb (h->cb_cls, ego, &ego->ctx, str); + h->cb(h->cb_cls, ego, &ego->ctx, str); /* complete deletion */ if (NULL == str) - { - GNUNET_free (ego->pk); - GNUNET_free (ego->name); - GNUNET_free (ego); - } + { + GNUNET_free(ego->pk); + GNUNET_free(ego->name); + GNUNET_free(ego); + } } @@ -418,18 +415,18 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) +check_identity_set_default(void *cls, const struct SetDefaultMessage *sdm) { - uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm); - uint16_t name_len = ntohs (sdm->name_len); - const char *str = (const char *) &sdm[1]; + uint16_t size = ntohs(sdm->header.size) - sizeof(*sdm); + uint16_t name_len = ntohs(sdm->name_len); + const char *str = (const char *)&sdm[1]; if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1]))) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - GNUNET_break (0 == ntohs (sdm->reserved)); + { + GNUNET_break(0); + return GNUNET_SYSERR; + } + GNUNET_break(0 == ntohs(sdm->reserved)); return GNUNET_OK; } @@ -442,7 +439,7 @@ check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) * @param sdm message received */ static void -handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) +handle_identity_set_default(void *cls, const struct SetDefaultMessage *sdm) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_IDENTITY_Operation *op; @@ -450,28 +447,28 @@ handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) struct GNUNET_HashCode id; struct GNUNET_IDENTITY_Ego *ego; - GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); - ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); + GNUNET_CRYPTO_ecdsa_key_get_public(&sdm->private_key, &pub); + GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); + ego = GNUNET_CONTAINER_multihashmap_get(h->egos, &id); if (NULL == ego) - { - GNUNET_break (0); - reschedule_connect (h); - return; - } + { + GNUNET_break(0); + reschedule_connect(h); + return; + } op = h->op_head; if (NULL == op) - { - GNUNET_break (0); - reschedule_connect (h); - return; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Received SET_DEFAULT message from identity service\n"); - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); + { + GNUNET_break(0); + reschedule_connect(h); + return; + } + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Received SET_DEFAULT message from identity service\n"); + GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); if (NULL != op->cb) - op->cb (op->cls, ego, &ego->ctx, ego->name); - GNUNET_free (op); + op->cb(op->cls, ego, &ego->ctx, ego->name); + GNUNET_free(op); } @@ -481,38 +478,38 @@ handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) * @param cls handle to the identity service. */ static void -reconnect (void *cls) +reconnect(void *cls) { struct GNUNET_IDENTITY_Handle *h = cls; struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (identity_result_code, - GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, - struct ResultCodeMessage, - h), - GNUNET_MQ_hd_var_size (identity_update, - GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, - struct UpdateMessage, - h), - GNUNET_MQ_hd_var_size (identity_set_default, - GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, - struct SetDefaultMessage, - h), - GNUNET_MQ_handler_end ()}; + { GNUNET_MQ_hd_var_size(identity_result_code, + GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, + struct ResultCodeMessage, + h), + GNUNET_MQ_hd_var_size(identity_update, + GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, + struct UpdateMessage, + h), + GNUNET_MQ_hd_var_size(identity_set_default, + GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, + struct SetDefaultMessage, + h), + GNUNET_MQ_handler_end() }; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; h->reconnect_task = NULL; - LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); - GNUNET_assert (NULL == h->mq); + LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); + GNUNET_assert(NULL == h->mq); h->mq = - GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h); + GNUNET_CLIENT_connect(h->cfg, "identity", handlers, &mq_error_handler, h); if (NULL == h->mq) return; if (NULL != h->cb) - { - env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); - GNUNET_MQ_send (h->mq, env); - } + { + env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); + GNUNET_MQ_send(h->mq, env); + } } @@ -525,23 +522,23 @@ reconnect (void *cls) * @return handle to use */ struct GNUNET_IDENTITY_Handle * -GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_IDENTITY_Callback cb, - void *cb_cls) +GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_IDENTITY_Callback cb, + void *cb_cls) { struct GNUNET_IDENTITY_Handle *h; - h = GNUNET_new (struct GNUNET_IDENTITY_Handle); + h = GNUNET_new(struct GNUNET_IDENTITY_Handle); h->cfg = cfg; h->cb = cb; h->cb_cls = cb_cls; - h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); - reconnect (h); + h->egos = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_YES); + reconnect(h); if (NULL == h->mq) - { - GNUNET_free (h); - return NULL; - } + { + GNUNET_free(h); + return NULL; + } return h; } @@ -553,7 +550,7 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return associated ECC key, valid as long as the ego is valid */ const struct GNUNET_CRYPTO_EcdsaPrivateKey * -GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) +GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego) { return ego->pk; } @@ -566,10 +563,10 @@ GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) * @param pk set to ego's public key */ void -GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, - struct GNUNET_CRYPTO_EcdsaPublicKey *pk) +GNUNET_IDENTITY_ego_get_public_key(const struct GNUNET_IDENTITY_Ego *ego, + struct GNUNET_CRYPTO_EcdsaPublicKey *pk) { - GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk); + GNUNET_CRYPTO_ecdsa_key_get_public(ego->pk, pk); } @@ -584,10 +581,10 @@ GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, * @return handle to abort the operation */ struct GNUNET_IDENTITY_Operation * -GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, - const char *service_name, - GNUNET_IDENTITY_Callback cb, - void *cb_cls) +GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h, + const char *service_name, + GNUNET_IDENTITY_Callback cb, + void *cb_cls) { struct GNUNET_IDENTITY_Operation *op; struct GNUNET_MQ_Envelope *env; @@ -596,24 +593,24 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, if (NULL == h->mq) return NULL; - GNUNET_assert (NULL != h->cb); - slen = strlen (service_name) + 1; - if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GetDefaultMessage)) - { - GNUNET_break (0); - return NULL; - } - op = GNUNET_new (struct GNUNET_IDENTITY_Operation); + GNUNET_assert(NULL != h->cb); + slen = strlen(service_name) + 1; + if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage)) + { + GNUNET_break(0); + return NULL; + } + op = GNUNET_new(struct GNUNET_IDENTITY_Operation); op->h = h; op->cb = cb; op->cls = cb_cls; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); + GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); env = - GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT); - gdm->name_len = htons (slen); - gdm->reserved = htons (0); - GNUNET_memcpy (&gdm[1], service_name, slen); - GNUNET_MQ_send (h->mq, env); + GNUNET_MQ_msg_extra(gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT); + gdm->name_len = htons(slen); + gdm->reserved = htons(0); + GNUNET_memcpy(&gdm[1], service_name, slen); + GNUNET_MQ_send(h->mq, env); return op; } @@ -629,11 +626,11 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, * @return handle to abort the operation */ struct GNUNET_IDENTITY_Operation * -GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, - const char *service_name, - struct GNUNET_IDENTITY_Ego *ego, - GNUNET_IDENTITY_Continuation cont, - void *cont_cls) +GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h, + const char *service_name, + struct GNUNET_IDENTITY_Ego *ego, + GNUNET_IDENTITY_Continuation cont, + void *cont_cls) { struct GNUNET_IDENTITY_Operation *op; struct GNUNET_MQ_Envelope *env; @@ -642,25 +639,25 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, if (NULL == h->mq) return NULL; - GNUNET_assert (NULL != h->cb); - slen = strlen (service_name) + 1; - if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct SetDefaultMessage)) - { - GNUNET_break (0); - return NULL; - } - op = GNUNET_new (struct GNUNET_IDENTITY_Operation); + GNUNET_assert(NULL != h->cb); + slen = strlen(service_name) + 1; + if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage)) + { + GNUNET_break(0); + return NULL; + } + op = GNUNET_new(struct GNUNET_IDENTITY_Operation); op->h = h; op->cont = cont; op->cls = cont_cls; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); + GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); env = - GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); - sdm->name_len = htons (slen); - sdm->reserved = htons (0); + GNUNET_MQ_msg_extra(sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); + sdm->name_len = htons(slen); + sdm->reserved = htons(0); sdm->private_key = *ego->pk; - GNUNET_memcpy (&sdm[1], service_name, slen); - GNUNET_MQ_send (h->mq, env); + GNUNET_memcpy(&sdm[1], service_name, slen); + GNUNET_MQ_send(h->mq, env); return op; } @@ -675,10 +672,10 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, * @return handle to abort the operation */ struct GNUNET_IDENTITY_Operation * -GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, - const char *name, - GNUNET_IDENTITY_CreateContinuation cont, - void *cont_cls) +GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, + const char *name, + GNUNET_IDENTITY_CreateContinuation cont, + void *cont_cls) { struct GNUNET_IDENTITY_Operation *op; struct GNUNET_MQ_Envelope *env; @@ -688,25 +685,25 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, if (NULL == h->mq) return NULL; - slen = strlen (name) + 1; - if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage)) - { - GNUNET_break (0); - return NULL; - } - op = GNUNET_new (struct GNUNET_IDENTITY_Operation); + slen = strlen(name) + 1; + if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct CreateRequestMessage)) + { + GNUNET_break(0); + return NULL; + } + op = GNUNET_new(struct GNUNET_IDENTITY_Operation); op->h = h; op->create_cont = cont; op->cls = cont_cls; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); - crm->name_len = htons (slen); - crm->reserved = htons (0); - pk = GNUNET_CRYPTO_ecdsa_key_create (); + GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); + env = GNUNET_MQ_msg_extra(crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); + crm->name_len = htons(slen); + crm->reserved = htons(0); + pk = GNUNET_CRYPTO_ecdsa_key_create(); crm->private_key = *pk; op->pk = pk; - GNUNET_memcpy (&crm[1], name, slen); - GNUNET_MQ_send (h->mq, env); + GNUNET_memcpy(&crm[1], name, slen); + GNUNET_MQ_send(h->mq, env); return op; } @@ -722,11 +719,11 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, * @return handle to abort the operation */ struct GNUNET_IDENTITY_Operation * -GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, - const char *old_name, - const char *new_name, - GNUNET_IDENTITY_Continuation cb, - void *cb_cls) +GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, + const char *old_name, + const char *new_name, + GNUNET_IDENTITY_Continuation cb, + void *cb_cls) { struct GNUNET_IDENTITY_Operation *op; struct GNUNET_MQ_Envelope *env; @@ -737,30 +734,30 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, if (NULL == h->mq) return NULL; - slen_old = strlen (old_name) + 1; - slen_new = strlen (new_name) + 1; + slen_old = strlen(old_name) + 1; + slen_new = strlen(new_name) + 1; if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) || (slen_new >= GNUNET_MAX_MESSAGE_SIZE) || (slen_old + slen_new >= - GNUNET_MAX_MESSAGE_SIZE - sizeof (struct RenameMessage))) - { - GNUNET_break (0); - return NULL; - } - op = GNUNET_new (struct GNUNET_IDENTITY_Operation); + GNUNET_MAX_MESSAGE_SIZE - sizeof(struct RenameMessage))) + { + GNUNET_break(0); + return NULL; + } + op = GNUNET_new(struct GNUNET_IDENTITY_Operation); op->h = h; op->cont = cb; op->cls = cb_cls; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - env = GNUNET_MQ_msg_extra (grm, - slen_old + slen_new, - GNUNET_MESSAGE_TYPE_IDENTITY_RENAME); - grm->old_name_len = htons (slen_old); - grm->new_name_len = htons (slen_new); - dst = (char *) &grm[1]; - GNUNET_memcpy (dst, old_name, slen_old); - GNUNET_memcpy (&dst[slen_old], new_name, slen_new); - GNUNET_MQ_send (h->mq, env); + GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); + env = GNUNET_MQ_msg_extra(grm, + slen_old + slen_new, + GNUNET_MESSAGE_TYPE_IDENTITY_RENAME); + grm->old_name_len = htons(slen_old); + grm->new_name_len = htons(slen_new); + dst = (char *)&grm[1]; + GNUNET_memcpy(dst, old_name, slen_old); + GNUNET_memcpy(&dst[slen_old], new_name, slen_new); + GNUNET_MQ_send(h->mq, env); return op; } @@ -775,10 +772,10 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, * @return handle to abort the operation */ struct GNUNET_IDENTITY_Operation * -GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, - const char *name, - GNUNET_IDENTITY_Continuation cb, - void *cb_cls) +GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, + const char *name, + GNUNET_IDENTITY_Continuation cb, + void *cb_cls) { struct GNUNET_IDENTITY_Operation *op; struct GNUNET_MQ_Envelope *env; @@ -787,22 +784,22 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, if (NULL == h->mq) return NULL; - slen = strlen (name) + 1; - if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct DeleteMessage)) - { - GNUNET_break (0); - return NULL; - } - op = GNUNET_new (struct GNUNET_IDENTITY_Operation); + slen = strlen(name) + 1; + if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct DeleteMessage)) + { + GNUNET_break(0); + return NULL; + } + op = GNUNET_new(struct GNUNET_IDENTITY_Operation); op->h = h; op->cont = cb; op->cls = cb_cls; - GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); - env = GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE); - gdm->name_len = htons (slen); - gdm->reserved = htons (0); - GNUNET_memcpy (&gdm[1], name, slen); - GNUNET_MQ_send (h->mq, env); + GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); + env = GNUNET_MQ_msg_extra(gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE); + gdm->name_len = htons(slen); + gdm->reserved = htons(0); + GNUNET_memcpy(&gdm[1], name, slen); + GNUNET_MQ_send(h->mq, env); return op; } @@ -816,16 +813,16 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, * @param op operation to cancel */ void -GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) +GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op) { op->cont = NULL; op->cb = NULL; op->create_cont = NULL; if (NULL != op->pk) - { - GNUNET_free (op->pk); - op->pk = NULL; - } + { + GNUNET_free(op->pk); + op->pk = NULL; + } } @@ -835,35 +832,35 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) * @param h handle to destroy */ void -GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) +GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h) { struct GNUNET_IDENTITY_Operation *op; - GNUNET_assert (NULL != h); + GNUNET_assert(NULL != h); if (h->reconnect_task != NULL) - { - GNUNET_SCHEDULER_cancel (h->reconnect_task); - h->reconnect_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(h->reconnect_task); + h->reconnect_task = NULL; + } if (NULL != h->egos) - { - GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); - GNUNET_CONTAINER_multihashmap_destroy (h->egos); - h->egos = NULL; - } + { + GNUNET_CONTAINER_multihashmap_iterate(h->egos, &free_ego, h); + GNUNET_CONTAINER_multihashmap_destroy(h->egos); + h->egos = NULL; + } while (NULL != (op = h->op_head)) - { - GNUNET_break (NULL == op->cont); - GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); - GNUNET_free_non_null (op->pk); - GNUNET_free (op); - } + { + GNUNET_break(NULL == op->cont); + GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); + GNUNET_free_non_null(op->pk); + GNUNET_free(op); + } if (NULL != h->mq) - { - GNUNET_MQ_destroy (h->mq); - h->mq = NULL; - } - GNUNET_free (h); + { + GNUNET_MQ_destroy(h->mq); + h->mq = NULL; + } + GNUNET_free(h); } /* end of identity_api.c */ diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c index 56ebf6f47..faf647c07 100644 --- a/src/identity/identity_api_lookup.c +++ b/src/identity/identity_api_lookup.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file identity/identity_api_lookup.c @@ -28,15 +28,13 @@ #include "gnunet_identity_service.h" #include "identity.h" -#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) /** * Handle for ego lookup. */ -struct GNUNET_IDENTITY_EgoLookup -{ - +struct GNUNET_IDENTITY_EgoLookup { /** * Connection to service. */ @@ -68,10 +66,10 @@ struct GNUNET_IDENTITY_EgoLookup * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) { - if (sizeof (*rcm) != htons (rcm->header.size)) - GNUNET_MQ_check_zero_termination (rcm); + if (sizeof(*rcm) != htons(rcm->header.size)) + GNUNET_MQ_check_zero_termination(rcm); return GNUNET_OK; } @@ -83,12 +81,12 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @param rcm result message received */ static void -handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) { struct GNUNET_IDENTITY_EgoLookup *el = cls; - el->cb (el->cb_cls, NULL); - GNUNET_IDENTITY_ego_lookup_cancel (el); + el->cb(el->cb_cls, NULL); + GNUNET_IDENTITY_ego_lookup_cancel(el); } @@ -100,18 +98,18 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_update (void *cls, const struct UpdateMessage *um) +check_identity_update(void *cls, const struct UpdateMessage *um) { - uint16_t size = ntohs (um->header.size); - uint16_t name_len = ntohs (um->name_len); - const char *str = (const char *) &um[1]; + uint16_t size = ntohs(um->header.size); + uint16_t name_len = ntohs(um->name_len); + const char *str = (const char *)&um[1]; - if ((size != name_len + sizeof (struct UpdateMessage)) || + if ((size != name_len + sizeof(struct UpdateMessage)) || ((0 != name_len) && ('\0' != str[name_len - 1]))) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -123,23 +121,23 @@ check_identity_update (void *cls, const struct UpdateMessage *um) * @param um message received */ static void -handle_identity_update (void *cls, const struct UpdateMessage *um) +handle_identity_update(void *cls, const struct UpdateMessage *um) { struct GNUNET_IDENTITY_EgoLookup *el = cls; - uint16_t name_len = ntohs (um->name_len); - const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; + uint16_t name_len = ntohs(um->name_len); + const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_HashCode id; struct GNUNET_IDENTITY_Ego ego; - GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); - GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); - GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); - ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key; - ego.name = (char *) str; + GNUNET_break(GNUNET_YES != ntohs(um->end_of_list)); + GNUNET_CRYPTO_ecdsa_key_get_public(&um->private_key, &pub); + GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); + ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *)&um->private_key; + ego.name = (char *)str; ego.id = id; - el->cb (el->cb_cls, &ego); - GNUNET_IDENTITY_ego_lookup_cancel (el); + el->cb(el->cb_cls, &ego); + GNUNET_IDENTITY_ego_lookup_cancel(el); } @@ -152,11 +150,11 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) * @param error error code */ static void -mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_IDENTITY_EgoLookup *el = cls; - el->cb (el->cb_cls, NULL); + el->cb(el->cb_cls, NULL); } @@ -170,46 +168,46 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) * @return NULL on error */ struct GNUNET_IDENTITY_EgoLookup * -GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *name, - GNUNET_IDENTITY_EgoCallback cb, - void *cb_cls) +GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *name, + GNUNET_IDENTITY_EgoCallback cb, + void *cb_cls) { struct GNUNET_IDENTITY_EgoLookup *el; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *req; size_t nlen; - GNUNET_assert (NULL != cb); - el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup); + GNUNET_assert(NULL != cb); + el = GNUNET_new(struct GNUNET_IDENTITY_EgoLookup); el->cb = cb; el->cb_cls = cb_cls; { struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (identity_result_code, - GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, - struct ResultCodeMessage, - el), - GNUNET_MQ_hd_var_size (identity_update, - GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, - struct UpdateMessage, - el), - GNUNET_MQ_handler_end ()}; + { GNUNET_MQ_hd_var_size(identity_result_code, + GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, + struct ResultCodeMessage, + el), + GNUNET_MQ_hd_var_size(identity_update, + GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, + struct UpdateMessage, + el), + GNUNET_MQ_handler_end() }; el->mq = - GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); + GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el); } if (NULL == el->mq) - { - GNUNET_break (0); - GNUNET_free (el); - return NULL; - } - el->name = GNUNET_strdup (name); - nlen = strlen (name) + 1; - env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP); - memcpy (&req[1], name, nlen); - GNUNET_MQ_send (el->mq, env); + { + GNUNET_break(0); + GNUNET_free(el); + return NULL; + } + el->name = GNUNET_strdup(name); + nlen = strlen(name) + 1; + env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP); + memcpy(&req[1], name, nlen); + GNUNET_MQ_send(el->mq, env); return el; } @@ -220,11 +218,11 @@ GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param el handle for lookup to abort */ void -GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el) +GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el) { - GNUNET_MQ_destroy (el->mq); - GNUNET_free (el->name); - GNUNET_free (el); + GNUNET_MQ_destroy(el->mq); + GNUNET_free(el->name); + GNUNET_free(el); } diff --git a/src/identity/identity_api_suffix_lookup.c b/src/identity/identity_api_suffix_lookup.c index 685030e40..51d8f39a6 100644 --- a/src/identity/identity_api_suffix_lookup.c +++ b/src/identity/identity_api_suffix_lookup.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file identity/identity_api_suffix_lookup.c @@ -28,15 +28,13 @@ #include "gnunet_identity_service.h" #include "identity.h" -#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) /** * Handle for ego lookup. */ -struct GNUNET_IDENTITY_EgoSuffixLookup -{ - +struct GNUNET_IDENTITY_EgoSuffixLookup { /** * Connection to service. */ @@ -68,11 +66,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) { - (void) cls; - if (sizeof (*rcm) != htons (rcm->header.size)) - GNUNET_MQ_check_zero_termination (rcm); + (void)cls; + if (sizeof(*rcm) != htons(rcm->header.size)) + GNUNET_MQ_check_zero_termination(rcm); return GNUNET_OK; } @@ -84,13 +82,13 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @param rcm result message received */ static void -handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) +handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) { struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; - (void) rcm; - el->cb (el->cb_cls, NULL, NULL); - GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); + (void)rcm; + el->cb(el->cb_cls, NULL, NULL); + GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); } @@ -102,19 +100,19 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) * @return #GNUNET_OK if the message is well-formed */ static int -check_identity_update (void *cls, const struct UpdateMessage *um) +check_identity_update(void *cls, const struct UpdateMessage *um) { - uint16_t size = ntohs (um->header.size); - uint16_t name_len = ntohs (um->name_len); - const char *str = (const char *) &um[1]; + uint16_t size = ntohs(um->header.size); + uint16_t name_len = ntohs(um->name_len); + const char *str = (const char *)&um[1]; - (void) cls; - if ((size != name_len + sizeof (struct UpdateMessage)) || + (void)cls; + if ((size != name_len + sizeof(struct UpdateMessage)) || ((0 != name_len) && ('\0' != str[name_len - 1]))) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } + { + GNUNET_break(0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -126,14 +124,14 @@ check_identity_update (void *cls, const struct UpdateMessage *um) * @param um message received */ static void -handle_identity_update (void *cls, const struct UpdateMessage *um) +handle_identity_update(void *cls, const struct UpdateMessage *um) { struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; - uint16_t name_len = ntohs (um->name_len); - const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; + uint16_t name_len = ntohs(um->name_len); + const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; - el->cb (el->cb_cls, &um->private_key, str); - GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); + el->cb(el->cb_cls, &um->private_key, str); + GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); } @@ -146,13 +144,13 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) * @param error error code */ static void -mq_error_handler (void *cls, enum GNUNET_MQ_Error error) +mq_error_handler(void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; - (void) error; - el->cb (el->cb_cls, NULL, NULL); - GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); + (void)error; + el->cb(el->cb_cls, NULL, NULL); + GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); } @@ -166,46 +164,46 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) * @return NULL on error */ struct GNUNET_IDENTITY_EgoSuffixLookup * -GNUNET_IDENTITY_ego_lookup_by_suffix (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *suffix, - GNUNET_IDENTITY_EgoSuffixCallback cb, - void *cb_cls) +GNUNET_IDENTITY_ego_lookup_by_suffix(const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *suffix, + GNUNET_IDENTITY_EgoSuffixCallback cb, + void *cb_cls) { struct GNUNET_IDENTITY_EgoSuffixLookup *el; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *req; size_t nlen; - GNUNET_assert (NULL != cb); - el = GNUNET_new (struct GNUNET_IDENTITY_EgoSuffixLookup); + GNUNET_assert(NULL != cb); + el = GNUNET_new(struct GNUNET_IDENTITY_EgoSuffixLookup); el->cb = cb; el->cb_cls = cb_cls; { struct GNUNET_MQ_MessageHandler handlers[] = - {GNUNET_MQ_hd_var_size (identity_result_code, - GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, - struct ResultCodeMessage, - el), - GNUNET_MQ_hd_var_size (identity_update, - GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, - struct UpdateMessage, - el), - GNUNET_MQ_handler_end ()}; + { GNUNET_MQ_hd_var_size(identity_result_code, + GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, + struct ResultCodeMessage, + el), + GNUNET_MQ_hd_var_size(identity_update, + GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, + struct UpdateMessage, + el), + GNUNET_MQ_handler_end() }; el->mq = - GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); + GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el); } if (NULL == el->mq) - { - GNUNET_break (0); - GNUNET_free (el); - return NULL; - } - el->suffix = GNUNET_strdup (suffix); - nlen = strlen (suffix) + 1; - env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); - memcpy (&req[1], suffix, nlen); - GNUNET_MQ_send (el->mq, env); + { + GNUNET_break(0); + GNUNET_free(el); + return NULL; + } + el->suffix = GNUNET_strdup(suffix); + nlen = strlen(suffix) + 1; + env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); + memcpy(&req[1], suffix, nlen); + GNUNET_MQ_send(el->mq, env); return el; } @@ -216,11 +214,11 @@ GNUNET_IDENTITY_ego_lookup_by_suffix (const struct GNUNET_CONFIGURATION_Handle * * @param el handle for lookup to abort */ void -GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (struct GNUNET_IDENTITY_EgoSuffixLookup *el) +GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(struct GNUNET_IDENTITY_EgoSuffixLookup *el) { - GNUNET_MQ_destroy (el->mq); - GNUNET_free (el->suffix); - GNUNET_free (el); + GNUNET_MQ_destroy(el->mq); + GNUNET_free(el->suffix); + GNUNET_free(el); } diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index ac1965a75..1f6ec94ee 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c @@ -1,6 +1,6 @@ /* - This file is part of GNUnet. - Copyright (C) 2012-2015 GNUnet e.V. + This file is part of GNUnet. + Copyright (C) 2012-2015 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -129,16 +129,14 @@ static char *allow_methods; /** * @brief struct returned by the initialization function of the plugin */ -struct Plugin -{ +struct Plugin { const struct GNUNET_CONFIGURATION_Handle *cfg; }; /** * The ego list */ -struct EgoEntry -{ +struct EgoEntry { /** * DLL */ @@ -168,8 +166,7 @@ struct EgoEntry /** * The request handle */ -struct RequestHandle -{ +struct RequestHandle { /** * The data from the REST request */ @@ -257,38 +254,38 @@ struct RequestHandle * @param handle Handle to clean up */ static void -cleanup_handle (void *cls) +cleanup_handle(void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; struct EgoEntry *ego_tmp; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); if (NULL != handle->timeout_task) - { - GNUNET_SCHEDULER_cancel (handle->timeout_task); - handle->timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel(handle->timeout_task); + handle->timeout_task = NULL; + } if (NULL != handle->url) - GNUNET_free (handle->url); + GNUNET_free(handle->url); if (NULL != handle->emsg) - GNUNET_free (handle->emsg); + GNUNET_free(handle->emsg); if (NULL != handle->name) - GNUNET_free (handle->name); + GNUNET_free(handle->name); if (NULL != handle->identity_handle) - GNUNET_IDENTITY_disconnect (handle->identity_handle); + GNUNET_IDENTITY_disconnect(handle->identity_handle); for (ego_entry = handle->ego_head; NULL != ego_entry;) - { - ego_tmp = ego_entry; - ego_entry = ego_entry->next; - GNUNET_free (ego_tmp->identifier); - GNUNET_free (ego_tmp->keystring); - GNUNET_free (ego_tmp); - } - - GNUNET_free (handle); + { + ego_tmp = ego_entry; + ego_entry = ego_entry->next; + GNUNET_free(ego_tmp->identifier); + GNUNET_free(ego_tmp->keystring); + GNUNET_free(ego_tmp); + } + + GNUNET_free(handle); } /** @@ -297,26 +294,26 @@ cleanup_handle (void *cls) * @param cls the `struct RequestHandle` */ static void -do_error (void *cls) +do_error(void *cls) { struct RequestHandle *handle = cls; struct MHD_Response *resp; - json_t *json_error = json_object (); + json_t *json_error = json_object(); char *response; if (NULL == handle->emsg) - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_ERROR_UNKNOWN); + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_ERROR_UNKNOWN); - json_object_set_new (json_error, "error", json_string (handle->emsg)); + json_object_set_new(json_error, "error", json_string(handle->emsg)); if (0 == handle->response_code) handle->response_code = MHD_HTTP_OK; - response = json_dumps (json_error, 0); - resp = GNUNET_REST_create_response (response); - handle->proc (handle->proc_cls, resp, handle->response_code); - json_decref (json_error); - GNUNET_free (response); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); + response = json_dumps(json_error, 0); + resp = GNUNET_REST_create_response(response); + handle->proc(handle->proc_cls, resp, handle->response_code); + json_decref(json_error); + GNUNET_free(response); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); } @@ -330,29 +327,30 @@ do_error (void *cls) * @return EgoEntry or NULL if not found */ struct EgoEntry * -get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) +get_egoentry(struct RequestHandle *handle, char *pubkey, char *name) { struct EgoEntry *ego_entry; + if (NULL != pubkey) - { - for (ego_entry = handle->ego_head; NULL != ego_entry; - ego_entry = ego_entry->next) { - if (0 != strcasecmp (pubkey, ego_entry->keystring)) - continue; - return ego_entry; + for (ego_entry = handle->ego_head; NULL != ego_entry; + ego_entry = ego_entry->next) + { + if (0 != strcasecmp(pubkey, ego_entry->keystring)) + continue; + return ego_entry; + } } - } if (NULL != name) - { - for (ego_entry = handle->ego_head; NULL != ego_entry; - ego_entry = ego_entry->next) { - if (0 != strcasecmp (name, ego_entry->identifier)) - continue; - return ego_entry; + for (ego_entry = handle->ego_head; NULL != ego_entry; + ego_entry = ego_entry->next) + { + if (0 != strcasecmp(name, ego_entry->identifier)) + continue; + return ego_entry; + } } - } return NULL; } @@ -366,10 +364,10 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) * @param name the id of the ego */ static void -ego_get_for_subsystem (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *name) +ego_get_for_subsystem(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *name) { struct RequestHandle *handle = cls; struct MHD_Response *resp; @@ -379,34 +377,34 @@ ego_get_for_subsystem (void *cls, char *public_key_string; if (NULL == ego) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } - GNUNET_IDENTITY_ego_get_public_key (ego, &public_key); - public_key_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (&public_key); + GNUNET_IDENTITY_ego_get_public_key(ego, &public_key); + public_key_string = GNUNET_CRYPTO_ecdsa_public_key_to_string(&public_key); // create json with subsystem identity - json_root = json_object (); - json_object_set_new (json_root, - GNUNET_REST_IDENTITY_PARAM_PUBKEY, - json_string (public_key_string)); - json_object_set_new (json_root, - GNUNET_REST_IDENTITY_PARAM_NAME, - json_string (name)); - - result_str = json_dumps (json_root, 0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); - resp = GNUNET_REST_create_response (result_str); - - json_decref (json_root); - handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_free (result_str); - GNUNET_free (public_key_string); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); + json_root = json_object(); + json_object_set_new(json_root, + GNUNET_REST_IDENTITY_PARAM_PUBKEY, + json_string(public_key_string)); + json_object_set_new(json_root, + GNUNET_REST_IDENTITY_PARAM_NAME, + json_string(name)); + + result_str = json_dumps(json_root, 0); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); + resp = GNUNET_REST_create_response(result_str); + + json_decref(json_root); + handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); + GNUNET_free(result_str); + GNUNET_free(public_key_string); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); } /** @@ -417,35 +415,35 @@ ego_get_for_subsystem (void *cls, * @param cls the RequestHandle */ void -ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_get_subsystem(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; char *subsystem; - if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) - { - handle->emsg = GNUNET_strdup ("Missing subsystem name"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - subsystem = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; + if (strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen(handle->url)) + { + handle->emsg = GNUNET_strdup("Missing subsystem name"); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + subsystem = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; //requested default identity of subsystem - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); - handle->op = GNUNET_IDENTITY_get (handle->identity_handle, - subsystem, - &ego_get_for_subsystem, - handle); + handle->op = GNUNET_IDENTITY_get(handle->identity_handle, + subsystem, + &ego_get_for_subsystem, + handle); if (NULL == handle->op) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } } @@ -457,9 +455,9 @@ ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -468,30 +466,30 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, json_t *json_ego; char *result_str; - json_root = json_array (); + json_root = json_array(); //Return ego/egos for (ego_entry = handle->ego_head; NULL != ego_entry; ego_entry = ego_entry->next) - { - json_ego = json_object (); - json_object_set_new (json_ego, - GNUNET_REST_IDENTITY_PARAM_PUBKEY, - json_string (ego_entry->keystring)); - json_object_set_new (json_ego, - GNUNET_REST_IDENTITY_PARAM_NAME, - json_string (ego_entry->identifier)); - json_array_append (json_root, json_ego); - json_decref (json_ego); - } - - result_str = json_dumps (json_root, 0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); - resp = GNUNET_REST_create_response (result_str); - - json_decref (json_root); - handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_free (result_str); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); + { + json_ego = json_object(); + json_object_set_new(json_ego, + GNUNET_REST_IDENTITY_PARAM_PUBKEY, + json_string(ego_entry->keystring)); + json_object_set_new(json_ego, + GNUNET_REST_IDENTITY_PARAM_NAME, + json_string(ego_entry->identifier)); + json_array_append(json_root, json_ego); + json_decref(json_ego); + } + + result_str = json_dumps(json_root, 0); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); + resp = GNUNET_REST_create_response(result_str); + + json_decref(json_root); + handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); + GNUNET_free(result_str); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); } @@ -502,28 +500,28 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, * @param ego_entry the struct EgoEntry for the response */ void -ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) +ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry) { struct MHD_Response *resp; json_t *json_ego; char *result_str; - json_ego = json_object (); - json_object_set_new (json_ego, - GNUNET_REST_IDENTITY_PARAM_PUBKEY, - json_string (ego_entry->keystring)); - json_object_set_new (json_ego, - GNUNET_REST_IDENTITY_PARAM_NAME, - json_string (ego_entry->identifier)); - - result_str = json_dumps (json_ego, 0); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); - resp = GNUNET_REST_create_response (result_str); - handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); - - json_decref (json_ego); - GNUNET_free (result_str); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); + json_ego = json_object(); + json_object_set_new(json_ego, + GNUNET_REST_IDENTITY_PARAM_PUBKEY, + json_string(ego_entry->keystring)); + json_object_set_new(json_ego, + GNUNET_REST_IDENTITY_PARAM_NAME, + json_string(ego_entry->identifier)); + + result_str = json_dumps(json_ego, 0); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); + resp = GNUNET_REST_create_response(result_str); + handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); + + json_decref(json_ego); + GNUNET_free(result_str); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); } @@ -535,9 +533,9 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) * @param cls the RequestHandle */ void -ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -545,25 +543,25 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, keystring = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; - ego_entry = get_egoentry (handle, keystring, NULL); + if (strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; + ego_entry = get_egoentry(handle, keystring, NULL); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - - ego_get_response (handle, ego_entry); + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + + ego_get_response(handle, ego_entry); } /** @@ -574,9 +572,9 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -584,25 +582,25 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, egoname = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; - ego_entry = get_egoentry (handle, NULL, egoname); + if (strlen(GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + egoname = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; + ego_entry = get_egoentry(handle, NULL, egoname); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - - ego_get_response (handle, ego_entry); + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + + ego_get_response(handle, ego_entry); } @@ -613,25 +611,25 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, * @param emsg error message */ static void -do_finished (void *cls, const char *emsg) +do_finished(void *cls, const char *emsg) { struct RequestHandle *handle = cls; struct MHD_Response *resp; handle->op = NULL; if (NULL != emsg) - { - handle->emsg = GNUNET_strdup (emsg); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->emsg = GNUNET_strdup(emsg); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } if (0 == handle->response_code) - { - handle->response_code = MHD_HTTP_NO_CONTENT; - } - resp = GNUNET_REST_create_response (NULL); - handle->proc (handle->proc_cls, resp, handle->response_code); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); + { + handle->response_code = MHD_HTTP_NO_CONTENT; + } + resp = GNUNET_REST_create_response(NULL); + handle->proc(handle->proc_cls, resp, handle->response_code); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); } @@ -643,14 +641,14 @@ do_finished (void *cls, const char *emsg) * @param emsg error message */ static void -do_finished_create (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, - const char *emsg) +do_finished_create(void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, + const char *emsg) { struct RequestHandle *handle = cls; - (void) pk; - do_finished (handle, emsg); + (void)pk; + do_finished(handle, emsg); } @@ -661,7 +659,7 @@ do_finished_create (void *cls, * @param ego_entry the struct EgoEntry we want to edit */ void -ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) +ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry) { struct EgoEntry *ego_entry_tmp; struct MHD_Response *resp; @@ -673,79 +671,78 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) //if no data if (0 >= handle->data_size) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } //if not json term_data[handle->data_size] = '\0'; - GNUNET_memcpy (term_data, handle->data, handle->data_size); - data_js = json_loads (term_data, JSON_DECODE_ANY, &err); + GNUNET_memcpy(term_data, handle->data, handle->data_size); + data_js = json_loads(term_data, JSON_DECODE_ANY, &err); if (NULL == data_js) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } newname = NULL; //NEW NAME json_state = 0; - json_state = json_unpack (data_js, - "{s:s!}", - GNUNET_REST_IDENTITY_PARAM_NEWNAME, - &newname); + json_state = json_unpack(data_js, + "{s:s!}", + GNUNET_REST_IDENTITY_PARAM_NEWNAME, + &newname); //Change name with pubkey or name identifier if (0 != json_state) - { - - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } if (NULL == newname) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } - - if (0 >= strlen (newname)) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } - - ego_entry_tmp = get_egoentry (handle, NULL, newname); + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } + + if (0 >= strlen(newname)) + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } + + ego_entry_tmp = get_egoentry(handle, NULL, newname); if (NULL != ego_entry_tmp) - { - //Ego with same name not allowed (even if its the ego we change) - resp = GNUNET_REST_create_response (NULL); - handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); - json_decref (data_js); - return; - } - handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, - ego_entry->identifier, - newname, - &do_finished, - handle); + { + //Ego with same name not allowed (even if its the ego we change) + resp = GNUNET_REST_create_response(NULL); + handle->proc(handle->proc_cls, resp, MHD_HTTP_CONFLICT); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); + json_decref(data_js); + return; + } + handle->op = GNUNET_IDENTITY_rename(handle->identity_handle, + ego_entry->identifier, + newname, + &do_finished, + handle); if (NULL == handle->op) - { - handle->emsg = GNUNET_strdup ("Rename failed"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } - json_decref (data_js); + { + handle->emsg = GNUNET_strdup("Rename failed"); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } + json_decref(data_js); return; } @@ -758,9 +755,9 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) * @param cls the RequestHandle */ void -ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -768,25 +765,25 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, keystring = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; - ego_entry = get_egoentry (handle, keystring, NULL); + if (strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; + ego_entry = get_egoentry(handle, keystring, NULL); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - - ego_edit (handle, ego_entry); + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + + ego_edit(handle, ego_entry); } /** @@ -797,9 +794,9 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -807,25 +804,25 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, name = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; - ego_entry = get_egoentry (handle, NULL, name); + if (strlen(GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + name = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; + ego_entry = get_egoentry(handle, NULL, name); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - - ego_edit (handle, ego_entry); + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + + ego_edit(handle, ego_entry); } /** @@ -836,9 +833,9 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_edit_subsystem(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -851,88 +848,88 @@ ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, name = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; - ego_entry = get_egoentry (handle, NULL, name); + if (strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + name = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; + ego_entry = get_egoentry(handle, NULL, name); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } //if no data if (0 >= handle->data_size) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } //if not json term_data[handle->data_size] = '\0'; - GNUNET_memcpy (term_data, handle->data, handle->data_size); - data_js = json_loads (term_data, JSON_DECODE_ANY, &err); + GNUNET_memcpy(term_data, handle->data, handle->data_size); + data_js = json_loads(term_data, JSON_DECODE_ANY, &err); if (NULL == data_js) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } newsubsys = NULL; //SUBSYSTEM json_state = 0; - json_state = json_unpack (data_js, - "{s:s!}", - GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, - &newsubsys); + json_state = json_unpack(data_js, + "{s:s!}", + GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, + &newsubsys); //Change subsystem with pubkey or name identifier if (0 != json_state) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } if (NULL == newsubsys) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } - - if (0 >= strlen (newsubsys)) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } + + if (0 >= strlen(newsubsys)) + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } handle->response_code = MHD_HTTP_NO_CONTENT; - handle->op = GNUNET_IDENTITY_set (handle->identity_handle, - newsubsys, - ego_entry->ego, - &do_finished, - handle); + handle->op = GNUNET_IDENTITY_set(handle->identity_handle, + newsubsys, + ego_entry->ego, + &do_finished, + handle); if (NULL == handle->op) - { - handle->emsg = GNUNET_strdup ("Setting subsystem failed"); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - json_decref (data_js); + { + handle->emsg = GNUNET_strdup("Setting subsystem failed"); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + json_decref(data_js); return; } @@ -944,9 +941,9 @@ ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_create (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_create(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -957,73 +954,73 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, int json_unpack_state; char term_data[handle->data_size + 1]; - if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) - { - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + if (strlen(GNUNET_REST_API_NS_IDENTITY) != strlen(handle->url)) + { + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } if (0 >= handle->data_size) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } term_data[handle->data_size] = '\0'; - GNUNET_memcpy (term_data, handle->data, handle->data_size); - data_js = json_loads (term_data, JSON_DECODE_ANY, &err); + GNUNET_memcpy(term_data, handle->data, handle->data_size); + data_js = json_loads(term_data, JSON_DECODE_ANY, &err); if (NULL == data_js) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } json_unpack_state = 0; json_unpack_state = - json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); + json_unpack(data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); if (0 != json_unpack_state) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } if (NULL == egoname) - { - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - json_decref (data_js); - return; - } - if (0 >= strlen (egoname)) - { - json_decref (data_js); - handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - GNUNET_STRINGS_utf8_tolower (egoname, egoname); + { + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + json_decref(data_js); + return; + } + if (0 >= strlen(egoname)) + { + json_decref(data_js); + handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + GNUNET_STRINGS_utf8_tolower(egoname, egoname); for (ego_entry = handle->ego_head; NULL != ego_entry; ego_entry = ego_entry->next) - { - if (0 == strcasecmp (egoname, ego_entry->identifier)) { - resp = GNUNET_REST_create_response (NULL); - handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); - json_decref (data_js); - return; + if (0 == strcasecmp(egoname, ego_entry->identifier)) + { + resp = GNUNET_REST_create_response(NULL); + handle->proc(handle->proc_cls, resp, MHD_HTTP_CONFLICT); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); + json_decref(data_js); + return; + } } - } - handle->name = GNUNET_strdup (egoname); - json_decref (data_js); + handle->name = GNUNET_strdup(egoname); + json_decref(data_js); handle->response_code = MHD_HTTP_CREATED; - handle->op = GNUNET_IDENTITY_create (handle->identity_handle, - handle->name, - &do_finished_create, - handle); + handle->op = GNUNET_IDENTITY_create(handle->identity_handle, + handle->name, + &do_finished_create, + handle); } /** @@ -1034,9 +1031,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -1044,29 +1041,29 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, keystring = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; - ego_entry = get_egoentry (handle, keystring, NULL); + if (strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; + ego_entry = get_egoentry(handle, keystring, NULL); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } handle->response_code = MHD_HTTP_NO_CONTENT; - handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, - ego_entry->identifier, - &do_finished, - handle); + handle->op = GNUNET_IDENTITY_delete(handle->identity_handle, + ego_entry->identifier, + &do_finished, + handle); } @@ -1078,9 +1075,9 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ void -ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; @@ -1088,29 +1085,29 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, name = NULL; - if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } - name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; - ego_entry = get_egoentry (handle, NULL, name); + if (strlen(GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen(handle->url)) + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } + name = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; + ego_entry = get_egoentry(handle, NULL, name); if (NULL == ego_entry) - { - handle->response_code = MHD_HTTP_NOT_FOUND; - handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); - GNUNET_SCHEDULER_add_now (&do_error, handle); - return; - } + { + handle->response_code = MHD_HTTP_NOT_FOUND; + handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); + GNUNET_SCHEDULER_add_now(&do_error, handle); + return; + } handle->response_code = MHD_HTTP_NO_CONTENT; - handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, - ego_entry->identifier, - &do_finished, - handle); + handle->op = GNUNET_IDENTITY_delete(handle->identity_handle, + ego_entry->identifier, + &do_finished, + handle); } @@ -1122,18 +1119,18 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, * @param cls the RequestHandle */ static void -options_cont (struct GNUNET_REST_RequestHandle *con_handle, - const char *url, - void *cls) +options_cont(struct GNUNET_REST_RequestHandle *con_handle, + const char *url, + void *cls) { struct MHD_Response *resp; struct RequestHandle *handle = cls; //For now, independent of path return all options - resp = GNUNET_REST_create_response (NULL); - MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); - handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); - GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); + resp = GNUNET_REST_create_response(NULL); + MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); + handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); + GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); return; } @@ -1143,39 +1140,39 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, * @param handle the request handle */ static void -init_cont (struct RequestHandle *handle) +init_cont(struct RequestHandle *handle) { struct GNUNET_REST_RequestHandlerError err; static const struct GNUNET_REST_RequestHandler handlers[] = - {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ALL, &ego_get_all}, - {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_get_pubkey}, - {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name}, - {MHD_HTTP_METHOD_GET, - GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, - &ego_get_subsystem}, - {MHD_HTTP_METHOD_PUT, - GNUNET_REST_API_NS_IDENTITY_PUBKEY, - &ego_edit_pubkey}, - {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name}, - {MHD_HTTP_METHOD_PUT, - GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, - &ego_edit_subsystem}, - {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create}, - {MHD_HTTP_METHOD_DELETE, - GNUNET_REST_API_NS_IDENTITY_PUBKEY, - &ego_delete_pubkey}, - {MHD_HTTP_METHOD_DELETE, - GNUNET_REST_API_NS_IDENTITY_NAME, - &ego_delete_name}, - {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont}, - GNUNET_REST_HANDLER_END}; + { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ALL, &ego_get_all }, + { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_get_pubkey }, + { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, + { MHD_HTTP_METHOD_GET, + GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, + &ego_get_subsystem }, + { MHD_HTTP_METHOD_PUT, + GNUNET_REST_API_NS_IDENTITY_PUBKEY, + &ego_edit_pubkey }, + { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, + { MHD_HTTP_METHOD_PUT, + GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, + &ego_edit_subsystem }, + { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, + { MHD_HTTP_METHOD_DELETE, + GNUNET_REST_API_NS_IDENTITY_PUBKEY, + &ego_delete_pubkey }, + { MHD_HTTP_METHOD_DELETE, + GNUNET_REST_API_NS_IDENTITY_NAME, + &ego_delete_name }, + { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, + GNUNET_REST_HANDLER_END }; if (GNUNET_NO == - GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) - { - handle->response_code = err.error_code; - GNUNET_SCHEDULER_add_now (&do_error, handle); - } + GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) + { + handle->response_code = err.error_code; + GNUNET_SCHEDULER_add_now(&do_error, handle); + } } /** @@ -1212,32 +1209,32 @@ init_cont (struct RequestHandle *handle) * must thus no longer be used */ static void -init_egos (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *identifier) +init_egos(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { struct RequestHandle *handle = cls; struct EgoEntry *ego_entry; struct GNUNET_CRYPTO_EcdsaPublicKey pk; if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) - { - handle->state = ID_REST_STATE_POST_INIT; - init_cont (handle); - return; - } + { + handle->state = ID_REST_STATE_POST_INIT; + init_cont(handle); + return; + } if (ID_REST_STATE_INIT == handle->state) - { - ego_entry = GNUNET_new (struct EgoEntry); - GNUNET_IDENTITY_ego_get_public_key (ego, &pk); - ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); - ego_entry->ego = ego; - GNUNET_asprintf (&ego_entry->identifier, "%s", identifier); - GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, - handle->ego_tail, - ego_entry); - } + { + ego_entry = GNUNET_new(struct EgoEntry); + GNUNET_IDENTITY_ego_get_public_key(ego, &pk); + ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); + ego_entry->ego = ego; + GNUNET_asprintf(&ego_entry->identifier, "%s", identifier); + GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, + handle->ego_tail, + ego_entry); + } } /** @@ -1252,11 +1249,11 @@ init_egos (void *cls, * @return GNUNET_OK if request accepted */ static void -rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, - GNUNET_REST_ResultProcessor proc, - void *proc_cls) +rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, + GNUNET_REST_ResultProcessor proc, + void *proc_cls) { - struct RequestHandle *handle = GNUNET_new (struct RequestHandle); + struct RequestHandle *handle = GNUNET_new(struct RequestHandle); handle->response_code = 0; handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; @@ -1266,17 +1263,17 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, handle->data = rest_handle->data; handle->data_size = rest_handle->data_size; - handle->url = GNUNET_strdup (rest_handle->url); - if (handle->url[strlen (handle->url) - 1] == '/') - handle->url[strlen (handle->url) - 1] = '\0'; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); + handle->url = GNUNET_strdup(rest_handle->url); + if (handle->url[strlen(handle->url) - 1] == '/') + handle->url[strlen(handle->url) - 1] = '\0'; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); - handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &init_egos, handle); + handle->identity_handle = GNUNET_IDENTITY_connect(cfg, &init_egos, handle); handle->timeout_task = - GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); + GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); } /** @@ -1286,7 +1283,7 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, * @return NULL on error, otherwise the plugin context */ void * -libgnunet_plugin_rest_identity_init (void *cls) +libgnunet_plugin_rest_identity_init(void *cls) { static struct Plugin plugin; struct GNUNET_REST_Plugin *api; @@ -1294,21 +1291,21 @@ libgnunet_plugin_rest_identity_init (void *cls) cfg = cls; if (NULL != plugin.cfg) return NULL; /* can only initialize once! */ - memset (&plugin, 0, sizeof (struct Plugin)); + memset(&plugin, 0, sizeof(struct Plugin)); plugin.cfg = cfg; - api = GNUNET_new (struct GNUNET_REST_Plugin); + api = GNUNET_new(struct GNUNET_REST_Plugin); api->cls = &plugin; api->name = GNUNET_REST_API_NS_IDENTITY; api->process_request = &rest_process_request; - GNUNET_asprintf (&allow_methods, - "%s, %s, %s, %s, %s", - MHD_HTTP_METHOD_GET, - MHD_HTTP_METHOD_POST, - MHD_HTTP_METHOD_PUT, - MHD_HTTP_METHOD_DELETE, - MHD_HTTP_METHOD_OPTIONS); - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); + GNUNET_asprintf(&allow_methods, + "%s, %s, %s, %s, %s", + MHD_HTTP_METHOD_GET, + MHD_HTTP_METHOD_POST, + MHD_HTTP_METHOD_PUT, + MHD_HTTP_METHOD_DELETE, + MHD_HTTP_METHOD_OPTIONS); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Identity REST API initialized\n")); return api; } @@ -1319,15 +1316,16 @@ libgnunet_plugin_rest_identity_init (void *cls) * @return always NULL */ void * -libgnunet_plugin_rest_identity_done (void *cls) +libgnunet_plugin_rest_identity_done(void *cls) { struct GNUNET_REST_Plugin *api = cls; struct Plugin *plugin = api->cls; + plugin->cfg = NULL; - GNUNET_free_non_null (allow_methods); - GNUNET_free (api); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n"); + GNUNET_free_non_null(allow_methods); + GNUNET_free(api); + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n"); return NULL; } diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index 74c052917..7f7371422 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file identity/test_identity.c @@ -29,7 +29,7 @@ #include "gnunet_testing_lib.h" -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) /** @@ -54,33 +54,33 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task; #define CHECK(cond) \ do \ - { \ - if (! (cond)) \ - { \ - GNUNET_break (0); \ - end (); \ - return; \ - } \ - } while (0) + { \ + if (!(cond)) \ + { \ + GNUNET_break(0); \ + end(); \ + return; \ + } \ + } while (0) /** * Clean up all resources used. */ static void -cleanup (void *cls) +cleanup(void *cls) { - (void) cls; + (void)cls; if (NULL != op) - { - GNUNET_IDENTITY_cancel (op); - op = NULL; - } + { + GNUNET_IDENTITY_cancel(op); + op = NULL; + } if (NULL != h) - { - GNUNET_IDENTITY_disconnect (h); - h = NULL; - } + { + GNUNET_IDENTITY_disconnect(h); + h = NULL; + } } @@ -90,9 +90,9 @@ cleanup (void *cls) * @param cls NULL */ static void -endbadly (void *cls) +endbadly(void *cls) { - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); } @@ -100,14 +100,14 @@ endbadly (void *cls) * Finish the testcase (successfully). */ static void -end () +end() { if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_SCHEDULER_cancel(endbadly_task); + endbadly_task = NULL; + } + GNUNET_SCHEDULER_shutdown(); } @@ -123,57 +123,64 @@ end () * must thus no longer be used */ static void -notification_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *identifier) +notification_cb(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { static struct GNUNET_IDENTITY_Ego *my_ego; static int round; switch (round) - { - case 0: /* end of initial iteration */ - CHECK (NULL == ego); - CHECK (NULL == identifier); - break; - case 1: /* create */ - CHECK (NULL != ego); - CHECK (NULL != identifier); - CHECK (0 == strcmp (identifier, "test-id")); - my_ego = ego; - *ctx = &round; - break; - case 2: /* rename */ - CHECK (my_ego == ego); - CHECK (NULL != identifier); - CHECK (0 == strcmp (identifier, "test")); - CHECK (*ctx == &round); - break; - case 3: /* reconnect-down */ - CHECK (my_ego == ego); - CHECK (NULL == identifier); - CHECK (*ctx == &round); - *ctx = NULL; - break; - case 4: /* reconnect-up */ - CHECK (NULL != identifier); - CHECK (0 == strcmp (identifier, "test")); - my_ego = ego; - *ctx = &round; - break; - case 5: /* end of iteration after reconnect */ - CHECK (NULL == ego); - CHECK (NULL == identifier); - break; - case 6: /* delete */ - CHECK (my_ego == ego); - CHECK (*ctx == &round); - *ctx = NULL; - break; - default: - CHECK (0); - } + { + case 0: /* end of initial iteration */ + CHECK(NULL == ego); + CHECK(NULL == identifier); + break; + + case 1: /* create */ + CHECK(NULL != ego); + CHECK(NULL != identifier); + CHECK(0 == strcmp(identifier, "test-id")); + my_ego = ego; + *ctx = &round; + break; + + case 2: /* rename */ + CHECK(my_ego == ego); + CHECK(NULL != identifier); + CHECK(0 == strcmp(identifier, "test")); + CHECK(*ctx == &round); + break; + + case 3: /* reconnect-down */ + CHECK(my_ego == ego); + CHECK(NULL == identifier); + CHECK(*ctx == &round); + *ctx = NULL; + break; + + case 4: /* reconnect-up */ + CHECK(NULL != identifier); + CHECK(0 == strcmp(identifier, "test")); + my_ego = ego; + *ctx = &round; + break; + + case 5: /* end of iteration after reconnect */ + CHECK(NULL == ego); + CHECK(NULL == identifier); + break; + + case 6: /* delete */ + CHECK(my_ego == ego); + CHECK(*ctx == &round); + *ctx = NULL; + break; + + default: + CHECK(0); + } round++; } @@ -185,12 +192,12 @@ notification_cb (void *cls, * @param emsg (should also be NULL) */ static void -delete_cont (void *cls, const char *emsg) +delete_cont(void *cls, const char *emsg) { op = NULL; - CHECK (NULL == emsg); + CHECK(NULL == emsg); res = 0; - end (); + end(); } @@ -200,9 +207,9 @@ delete_cont (void *cls, const char *emsg) * @param cls NULL */ static void -finally_delete (void *cls) +finally_delete(void *cls) { - op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL); + op = GNUNET_IDENTITY_delete(h, "test", &delete_cont, NULL); } @@ -213,13 +220,13 @@ finally_delete (void *cls) * @param emsg (should also be NULL) */ static void -fail_rename_cont (void *cls, const char *emsg) +fail_rename_cont(void *cls, const char *emsg) { - CHECK (NULL != emsg); + CHECK(NULL != emsg); op = NULL; - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &finally_delete, - NULL); + GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, + &finally_delete, + NULL); } @@ -230,10 +237,10 @@ fail_rename_cont (void *cls, const char *emsg) * @param emsg (should also be NULL) */ static void -success_rename_cont (void *cls, const char *emsg) +success_rename_cont(void *cls, const char *emsg) { - CHECK (NULL == emsg); - op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL); + CHECK(NULL == emsg); + op = GNUNET_IDENTITY_rename(h, "test-id", "test", &fail_rename_cont, NULL); } @@ -245,14 +252,14 @@ success_rename_cont (void *cls, const char *emsg) * @param emsg error message */ static void -create_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, - const char *emsg) +create_cb(void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, + const char *emsg) { - CHECK (NULL != pk); - CHECK (NULL == emsg); + CHECK(NULL != pk); + CHECK(NULL == emsg); op = - GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL); + GNUNET_IDENTITY_rename(h, "test-id", "test", &success_rename_cont, NULL); } @@ -264,30 +271,30 @@ create_cb (void *cls, * @param peer handle to access more of the peer (not used) */ static void -run (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); - GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); - h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); - CHECK (NULL != h); - op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); + endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); + GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); + h = GNUNET_IDENTITY_connect(cfg, ¬ification_cb, NULL); + CHECK(NULL != h); + op = GNUNET_IDENTITY_create(h, "test-id", &create_cb, NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); + GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); res = 1; - if (0 != GNUNET_TESTING_service_run ("test-identity", - "identity", - "test_identity.conf", - &run, - NULL)) + if (0 != GNUNET_TESTING_service_run("test-identity", + "identity", + "test_identity.conf", + &run, + NULL)) return 1; - GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); + GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); return res; } diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c index 71e70e7ba..6e14022c6 100644 --- a/src/identity/test_identity_defaults.c +++ b/src/identity/test_identity_defaults.c @@ -16,7 +16,7 @@ along with this program. If not, see . SPDX-License-Identifier: AGPL3.0-or-later -*/ + */ /** * @file identity/test_identity.c @@ -29,7 +29,7 @@ #include "gnunet_testing_lib.h" -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) /** @@ -54,33 +54,33 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task; #define CHECK(cond) \ do \ - { \ - if (! (cond)) \ - { \ - GNUNET_break (0); \ - end (); \ - return; \ - } \ - } while (0) + { \ + if (!(cond)) \ + { \ + GNUNET_break(0); \ + end(); \ + return; \ + } \ + } while (0) /** * Clean up all resources used. */ static void -cleanup (void *cls) +cleanup(void *cls) { - (void) cls; + (void)cls; if (NULL != op) - { - GNUNET_IDENTITY_cancel (op); - op = NULL; - } + { + GNUNET_IDENTITY_cancel(op); + op = NULL; + } if (NULL != h) - { - GNUNET_IDENTITY_disconnect (h); - h = NULL; - } + { + GNUNET_IDENTITY_disconnect(h); + h = NULL; + } } @@ -90,9 +90,9 @@ cleanup (void *cls) * @param cls NULL */ static void -endbadly (void *cls) +endbadly(void *cls) { - GNUNET_SCHEDULER_shutdown (); + GNUNET_SCHEDULER_shutdown(); res = 1; } @@ -101,14 +101,14 @@ endbadly (void *cls) * Termiante the testcase. */ static void -end () +end() { if (NULL != endbadly_task) - { - GNUNET_SCHEDULER_cancel (endbadly_task); - endbadly_task = NULL; - } - GNUNET_SCHEDULER_shutdown (); + { + GNUNET_SCHEDULER_cancel(endbadly_task); + endbadly_task = NULL; + } + GNUNET_SCHEDULER_shutdown(); } @@ -119,12 +119,12 @@ end () * @param emsg (should also be NULL) */ static void -delete_cont (void *cls, const char *emsg) +delete_cont(void *cls, const char *emsg) { op = NULL; - CHECK (NULL == emsg); + CHECK(NULL == emsg); res = 0; - end (); + end(); } @@ -135,16 +135,16 @@ delete_cont (void *cls, const char *emsg) * @param emsg (should also be NULL) */ static void -get_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *identifier) +get_cb(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { op = NULL; - CHECK (NULL != ego); - CHECK (NULL != identifier); - CHECK (0 == strcmp (identifier, "test-id")); - op = GNUNET_IDENTITY_delete (h, "test-id", &delete_cont, NULL); + CHECK(NULL != ego); + CHECK(NULL != identifier); + CHECK(0 == strcmp(identifier, "test-id")); + op = GNUNET_IDENTITY_delete(h, "test-id", &delete_cont, NULL); } @@ -160,15 +160,15 @@ get_cb (void *cls, * must thus no longer be used */ static void -dummy_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *identifier) +dummy_cb(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { - (void) cls; - (void) ego; - (void) ctx; - (void) identifier; + (void)cls; + (void)ego; + (void)ctx; + (void)identifier; } @@ -180,15 +180,15 @@ dummy_cb (void *cls, * @param peer handle to access more of the peer (not used) */ static void -run_get (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run_get(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); - GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); - h = GNUNET_IDENTITY_connect (cfg, &dummy_cb, NULL); - CHECK (NULL != h); - op = GNUNET_IDENTITY_get (h, "test-service", &get_cb, NULL); + endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); + GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); + h = GNUNET_IDENTITY_connect(cfg, &dummy_cb, NULL); + CHECK(NULL != h); + op = GNUNET_IDENTITY_get(h, "test-service", &get_cb, NULL); } @@ -199,11 +199,11 @@ run_get (void *cls, * @param emsg (should also be NULL) */ static void -success_set_cont (void *cls, const char *emsg) +success_set_cont(void *cls, const char *emsg) { op = NULL; - CHECK (NULL == emsg); - end (); + CHECK(NULL == emsg); + end(); } @@ -219,16 +219,16 @@ success_set_cont (void *cls, const char *emsg) * must thus no longer be used */ static void -notification_cb (void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *identifier) +notification_cb(void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *identifier) { if (NULL == ego) return; /* skip first call */ if (NULL == identifier) return; /* deletion / shutdown */ - op = GNUNET_IDENTITY_set (h, "test-service", ego, &success_set_cont, NULL); + op = GNUNET_IDENTITY_set(h, "test-service", ego, &success_set_cont, NULL); } @@ -240,12 +240,12 @@ notification_cb (void *cls, * @param emsg error message */ static void -create_cb (void *cls, - const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, - const char *emsg) +create_cb(void *cls, + const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, + const char *emsg) { - CHECK (NULL == emsg); - CHECK (NULL != pk); + CHECK(NULL == emsg); + CHECK(NULL != pk); op = NULL; } @@ -258,36 +258,36 @@ create_cb (void *cls, * @param peer handle to access more of the peer (not used) */ static void -run_set (void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTING_Peer *peer) +run_set(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer) { - endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); - GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); - h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); - CHECK (NULL != h); - op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); + endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); + GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); + h = GNUNET_IDENTITY_connect(cfg, ¬ification_cb, NULL); + CHECK(NULL != h); + op = GNUNET_IDENTITY_create(h, "test-id", &create_cb, NULL); } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); + GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); res = 1; - if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", - "identity", - "test_identity.conf", - &run_set, - NULL)) + if (0 != GNUNET_TESTING_service_run("test-identity-defaults", + "identity", + "test_identity.conf", + &run_set, + NULL)) return 1; - if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", - "identity", - "test_identity.conf", - &run_get, - NULL)) + if (0 != GNUNET_TESTING_service_run("test-identity-defaults", + "identity", + "test_identity.conf", + &run_get, + NULL)) return 1; - GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); + GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); return res; } -- cgit v1.2.3