gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r38183 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r38183 - gnunet/src/namestore
Date: Sun, 23 Oct 2016 17:58:23 +0200

Author: grothoff
Date: 2016-10-23 17:58:23 +0200 (Sun, 23 Oct 2016)
New Revision: 38183

Modified:
   gnunet/src/namestore/gnunet-namestore.c
   gnunet/src/namestore/plugin_rest_namestore.c
Log:
simplify gnunet-namestore / namestore_rest_plugin to avoid deprecated 
CLIENT_service_test

Modified: gnunet/src/namestore/gnunet-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-namestore.c     2016-10-23 15:54:01 UTC (rev 
38182)
+++ gnunet/src/namestore/gnunet-namestore.c     2016-10-23 15:58:23 UTC (rev 
38183)
@@ -753,27 +753,37 @@
 
 
 /**
- * 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,43 +1038,7 @@
 }
 
 
-/**
- * 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,
                 void **ctx,
@@ -1104,19 +1078,23 @@
 }
 
 
+/**
+ * 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 @@
                                    &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;
   }
@@ -1138,30 +1117,6 @@
 
 
 /**
- * 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.
  *
  * @param argc number of arguments from the command line

Modified: gnunet/src/namestore/plugin_rest_namestore.c
===================================================================
--- gnunet/src/namestore/plugin_rest_namestore.c        2016-10-23 15:54:01 UTC 
(rev 38182)
+++ gnunet/src/namestore/plugin_rest_namestore.c        2016-10-23 15:58:23 UTC 
(rev 38183)
@@ -967,22 +967,22 @@
                            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 @@
     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,52 +1018,19 @@
     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,
                 struct GNUNET_IDENTITY_Ego *ego,
@@ -1095,10 +1070,24 @@
   }
 }
 
+
+/**
+ * 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;
@@ -1105,15 +1094,16 @@
   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 @@
                                                    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);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]