From: Christian Grothoff Date: Sun, 23 Oct 2016 15:58:23 +0000 (+0000) Subject: simplify gnunet-namestore / namestore_rest_plugin to avoid deprecated CLIENT_service_test X-Git-Tag: initial-import-from-subversion-38251~69 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac;p=oweals%2Fgnunet.git simplify gnunet-namestore / namestore_rest_plugin to avoid deprecated CLIENT_service_test --- diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 8f0c14fa0..457e77022 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c @@ -753,27 +753,37 @@ del_monitor (void *cls, /** - * Function called with the result from the check if the namestore - * service is actually running. If it is, we start the actual - * operation. + * Callback invoked from identity service with ego information. + * An @a ego of NULL means the ego was not found. * - * @param cls closure with our configuration - * @param result #GNUNET_YES if the namestore service is running + * @param cls closure with the configuration + * @param ego an ego known to identity service, or NULL */ static void -testservice_task (void *cls, - int result) +identity_cb (void *cls, + const struct GNUNET_IDENTITY_Ego *ego) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct GNUNET_CRYPTO_EcdsaPublicKey pub; struct GNUNET_GNSRECORD_Data rd; - if (GNUNET_YES != result) + el = NULL; + if (NULL == ego) { - FPRINTF (stderr, _("Service `%s' is not running\n"), - "namestore"); + if (NULL != ego_name) + { + fprintf (stderr, + _("Ego `%s' not known to identity service\n"), + ego_name); + } + GNUNET_SCHEDULER_shutdown (); + ret = -1; return; } + zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); + GNUNET_free_non_null (ego_name); + ego_name = NULL; + if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) ) { /* nothing more to be done */ @@ -1028,42 +1038,6 @@ testservice_task (void *cls, } -/** - * Callback invoked from identity service with ego information. - * An @a ego of NULL means the ego was not found. - * - * @param cls closure with the configuration - * @param ego an ego known to identity service, or NULL - */ -static void -identity_cb (void *cls, - const struct GNUNET_IDENTITY_Ego *ego) -{ - const struct GNUNET_CONFIGURATION_Handle *cfg = cls; - - el = NULL; - if (NULL == ego) - { - if (NULL != ego_name) - { - fprintf (stderr, - _("Ego `%s' not known to identity service\n"), - ego_name); - } - GNUNET_SCHEDULER_shutdown (); - ret = -1; - return; - } - zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); - GNUNET_free_non_null (ego_name); - ego_name = NULL; - GNUNET_CLIENT_service_test ("namestore", cfg, - GNUNET_TIME_UNIT_SECONDS, - &testservice_task, - (void *) cfg); -} - - static void default_ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, @@ -1104,19 +1078,23 @@ id_connect_cb (void *cls, } +/** + * Main function that will be run. + * + * @param cls closure + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param cfg configuration + */ static void -testservice_id_task (void *cls, int result) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { - const struct GNUNET_CONFIGURATION_Handle *cfg = cls; + if ( (NULL != args[0]) && (NULL == uri) ) + uri = GNUNET_strdup (args[0]); - if (result != GNUNET_YES) - { - fprintf (stderr, - _("Identity service is not running\n")); - GNUNET_SCHEDULER_shutdown (); - ret = -1; - return; - } GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); @@ -1126,7 +1104,8 @@ testservice_id_task (void *cls, int result) &id_connect_cb, (void *) cfg); if (NULL == idh) - fprintf (stderr, _("Cannot connect to identity service\n")); + fprintf (stderr, + _("Cannot connect to identity service\n")); ret = -1; return; } @@ -1137,30 +1116,6 @@ testservice_id_task (void *cls, int result) } -/** - * Main function that will be run. - * - * @param cls closure - * @param args remaining command-line arguments - * @param cfgfile name of the configuration file used (for saving, can be NULL!) - * @param cfg configuration - */ -static void -run (void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - if ( (NULL != args[0]) && (NULL == uri) ) - uri = GNUNET_strdup (args[0]); - - GNUNET_CLIENT_service_test ("identity", cfg, - GNUNET_TIME_UNIT_SECONDS, - &testservice_id_task, - (void *) cfg); -} - - /** * The main function for gnunet-namestore. * diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index 58ab46ca9..0d36cf445 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c @@ -967,22 +967,22 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, allow_methods); handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); cleanup_handle (handle); - return; } + /** - * Function called with the result from the check if the namestore - * service is actually running. If it is, we start the actual - * operation. + * Callback invoked from identity service with ego information. + * An @a ego of NULL means the ego was not found. * - * @param cls closure with our configuration - * @param result #GNUNET_YES if the namestore service is running + * @param cls closure with the configuration + * @param ego an ego known to identity service, or NULL */ static void -testservice_task (void *cls, - int result) +identity_cb (void *cls, + const struct GNUNET_IDENTITY_Ego *ego) { struct RequestHandle *handle = cls; + struct MHD_Response *resp; struct GNUNET_REST_RequestHandlerError err; static const struct GNUNET_REST_RequestHandler handlers[] = { {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse @@ -994,13 +994,21 @@ testservice_task (void *cls, GNUNET_REST_HANDLER_END }; - if (GNUNET_YES != result) + handle->ego_lookup = NULL; + if (NULL == ego) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Service `%s' is not running\n"), - "namestore"); - GNUNET_SCHEDULER_add_now (&do_error, handle); + if (NULL != handle->ego_name) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Ego `%s' not known to identity service\n"), + handle->ego_name); + } + resp = GNUNET_REST_create_response (NULL); + handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); + cleanup_handle (handle); return; } + handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); if (NULL == handle->ns_handle) { @@ -1010,51 +1018,18 @@ testservice_task (void *cls, return; } - if (GNUNET_OK != GNUNET_JSONAPI_handle_request (handle->rest_handle, - handlers, - &err, - handle)) + if (GNUNET_OK != + GNUNET_JSONAPI_handle_request (handle->rest_handle, + handlers, + &err, + handle)) { handle->response_code = err.error_code; - GNUNET_SCHEDULER_add_now (&do_error, (void*) handle); + GNUNET_SCHEDULER_add_now (&do_error, + (void *) handle); } - } -/** - * Callback invoked from identity service with ego information. - * An @a ego of NULL means the ego was not found. - * - * @param cls closure with the configuration - * @param ego an ego known to identity service, or NULL - */ -static void -identity_cb (void *cls, - const struct GNUNET_IDENTITY_Ego *ego) -{ - struct RequestHandle *handle = cls; - struct MHD_Response *resp; - - handle->ego_lookup = NULL; - if (NULL == ego) - { - if (NULL != handle->ego_name) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Ego `%s' not known to identity service\n"), - handle->ego_name); - } - resp = GNUNET_REST_create_response (NULL); - handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); - cleanup_handle (handle); - return; - } - handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); - GNUNET_CLIENT_service_test ("namestore", handle->cfg, - GNUNET_TIME_UNIT_SECONDS, - &testservice_task, - (void *) handle); -} static void default_ego_cb (void *cls, @@ -1095,25 +1070,40 @@ id_connect_cb (void *cls, } } + +/** + * Function processing the REST call + * + * @param method HTTP method + * @param url URL of the HTTP request + * @param data body of the HTTP request (optional) + * @param data_size length of the body + * @param proc callback function for the result + * @param proc_cls closure for callback function + * @return #GNUNET_OK if request accepted + */ static void -testservice_id_task (void *cls, int result) +rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, + GNUNET_REST_ResultProcessor proc, + void *proc_cls) { - struct RequestHandle *handle = cls; + struct RequestHandle *handle = GNUNET_new (struct RequestHandle); struct MHD_Response *resp; struct GNUNET_HashCode key; char *ego; char *name; char *type; - if (result != GNUNET_YES) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Identity service is not running\n")); - resp = GNUNET_REST_create_response (NULL); - handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); - cleanup_handle (handle); - return; - } + handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; + handle->proc_cls = proc_cls; + handle->proc = proc; + handle->rest_handle = rest_handle; + 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->cfg = cfg; ego = NULL; GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO, strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO), @@ -1160,41 +1150,6 @@ testservice_id_task (void *cls, int result) handle->ego_name, &identity_cb, handle); -} - -/** - * Function processing the REST call - * - * @param method HTTP method - * @param url URL of the HTTP request - * @param data body of the HTTP request (optional) - * @param data_size length of the body - * @param proc callback function for the result - * @param proc_cls closure for callback function - * @return GNUNET_OK if request accepted - */ -static void -rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, - GNUNET_REST_ResultProcessor proc, - void *proc_cls) -{ - struct RequestHandle *handle = GNUNET_new (struct RequestHandle); - - handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; - handle->proc_cls = proc_cls; - handle->proc = proc; - handle->rest_handle = rest_handle; - 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->cfg = cfg; - GNUNET_CLIENT_service_test ("identity", - cfg, - GNUNET_TIME_UNIT_SECONDS, - &testservice_id_task, - handle); handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);