/**
- * 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 */
}
-/**
- * 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,
}
+/**
+ * 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);
&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;
}
}
-/**
- * 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.
*
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
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)
{
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,
}
}
+
+/**
+ * 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),
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);