gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35371 - in gnunet/src: gns rest


From: gnunet
Subject: [GNUnet-SVN] r35371 - in gnunet/src: gns rest
Date: Wed, 11 Mar 2015 18:39:32 +0100

Author: schanzen
Date: 2015-03-11 18:39:32 +0100 (Wed, 11 Mar 2015)
New Revision: 35371

Modified:
   gnunet/src/gns/plugin_rest_gns.c
   gnunet/src/rest/gnunet-rest-server.c
Log:
- fixes, intendation

Modified: gnunet/src/gns/plugin_rest_gns.c
===================================================================
--- gnunet/src/gns/plugin_rest_gns.c    2015-03-11 12:54:22 UTC (rev 35370)
+++ gnunet/src/gns/plugin_rest_gns.c    2015-03-11 17:39:32 UTC (rev 35371)
@@ -1,22 +1,22 @@
 /*
-     This file is part of GNUnet.
-     Copyright (C) 2012-2015 Christian Grothoff (and other contributing 
authors)
+   This file is part of GNUnet.
+   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+   GNUnet is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, 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
-     General Public License for more details.
+   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
+   General Public License for more details.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
+   You should have received a copy of the GNU General Public License
+   along with GNUnet; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+   */
 /**
  * @author Martin Schanzenbach
  * @file gns/plugin_rest_gns.c
@@ -47,103 +47,145 @@
 
 struct LookupHandle
 {
-    /**
-     * Handle to GNS service.
-     */
-    struct GNUNET_GNS_Handle *gns;
-    
-    /**
-     * Desired timeout for the lookup (default is no timeout).
-     */
-    struct GNUNET_TIME_Relative timeout;
-    
-    /**
-     * Handle to lookup request
-     */
-    struct GNUNET_GNS_LookupRequest *lookup_request;
+  /**
+   * Handle to GNS service.
+   */
+  struct GNUNET_GNS_Handle *gns;
 
-    /**
-     * Lookup an ego with the identity service.
-     */
-    struct GNUNET_IDENTITY_EgoLookup *el;
+  /**
+   * Desired timeout for the lookup (default is no timeout).
+   */
+  struct GNUNET_TIME_Relative timeout;
 
-    /**
-     * Handle for identity service.
-     */
-    struct GNUNET_IDENTITY_Handle *identity;
+  /**
+   * Handle to lookup request
+   */
+  struct GNUNET_GNS_LookupRequest *lookup_request;
 
-    /**
-     * Active operation on identity service.
-     */
-    struct GNUNET_IDENTITY_Operation *id_op;
-    /**
-     * ID of a task associated with the resolution process.
-     */
-    struct GNUNET_SCHEDULER_Task * timeout_task;    
-    
-    json_t *json_root;
+  /**
+   * Lookup an ego with the identity service.
+   */
+  struct GNUNET_IDENTITY_EgoLookup *el;
 
-    GNUNET_REST_ResultProcessor proc;
+  /**
+   * Handle for identity service.
+   */
+  struct GNUNET_IDENTITY_Handle *identity;
 
-    char *name;
+  /**
+   * Active operation on identity service.
+   */
+  struct GNUNET_IDENTITY_Operation *id_op;
 
-    const char *ego_str;
+  /**
+   * ID of a task associated with the resolution process.
+   */
+  struct GNUNET_SCHEDULER_Task * timeout_task;    
 
-    const char *pkey_str;
+  /**
+   * The root of the received JSON or NULL
+   */
+  json_t *json_root;
 
-    int type;
+  /**
+   * The plugin result processor
+   */
+  GNUNET_REST_ResultProcessor proc;
 
-    struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
+  /**
+   * The closure of the result processor
+   */
+  void *proc_cls;
 
-    struct GNUNET_CRYPTO_EcdsaPublicKey pkeym;
-    
-    enum GNUNET_GNS_LocalOptions options;
-    
-    struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
-    void *proc_cls;
+  /**
+   * The name to look up
+   */
+  char *name;
+
+  /**
+   * The ego to use
+   * In string representation from JSON
+   */
+  const char *ego_str;
+
+  /**
+   * The Pkey to use
+   * In stirng representation from JSON
+   */
+  const char *pkey_str;
+
+  /**
+   * The record type to look up
+   */
+  int type;
+
+  /**
+   * The public key of to use for lookup
+   */
+  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
+
+  /**
+   * The public key to use for lookup
+   */
+  struct GNUNET_CRYPTO_EcdsaPublicKey pkeym;
+
+  /**
+   * The resolver options
+   */
+  enum GNUNET_GNS_LocalOptions options;
+
+  /**
+   * the shorten key
+   */
+  struct GNUNET_CRYPTO_EcdsaPrivateKey shorten_key;
+
 };
 
+/**
+ * Cleanup lookup handle
+ * @praram handle Handle to clean up
+ */
 void
 cleanup_handle (struct LookupHandle *handle)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                    "Cleaning up\n");
-    if (NULL != handle->json_root)
-        json_decref (handle->json_root);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Cleaning up\n");
+  if (NULL != handle->json_root)
+    json_decref (handle->json_root);
 
-    if (NULL != handle->name)
-       GNUNET_free (handle->name);
-    if (NULL != handle->el)
-    {
-        GNUNET_IDENTITY_ego_lookup_cancel (handle->el);
-        handle->el = NULL;
-    }
-    if (NULL != handle->id_op)
-    {
-        GNUNET_IDENTITY_cancel (handle->id_op);
-        handle->id_op = NULL;
-    }
-    if (NULL != handle->lookup_request)
-    {
-        GNUNET_GNS_lookup_cancel (handle->lookup_request);
-        handle->lookup_request = NULL;
-    }
-    if (NULL != handle->identity)
-    {
-        GNUNET_IDENTITY_disconnect (handle->identity);
-        handle->identity = NULL;
-    }
-    if (NULL != handle->gns)
-    {
-        GNUNET_GNS_disconnect (handle->gns);
-        handle->gns = NULL;
-    }
+  if (NULL != handle->name)
+    GNUNET_free (handle->name);
+  if (NULL != handle->el)
+  {
+    GNUNET_IDENTITY_ego_lookup_cancel (handle->el);
+    handle->el = NULL;
+  }
+  if (NULL != handle->id_op)
+  {
+    GNUNET_IDENTITY_cancel (handle->id_op);
+    handle->id_op = NULL;
+  }
+  if (NULL != handle->lookup_request)
+  {
+    GNUNET_GNS_lookup_cancel (handle->lookup_request);
+    handle->lookup_request = NULL;
+  }
+  if (NULL != handle->identity)
+  {
+    GNUNET_IDENTITY_disconnect (handle->identity);
+    handle->identity = NULL;
+  }
+  if (NULL != handle->gns)
+  {
+    GNUNET_GNS_disconnect (handle->gns);
+    handle->gns = NULL;
+  }
 
-    if (NULL != handle->timeout_task)
-    {
-        GNUNET_SCHEDULER_cancel (handle->timeout_task);
-    }
-    GNUNET_free (handle);
+  if (NULL != handle->timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (handle->timeout_task);
+  }
+  GNUNET_free (handle);
 }
 
 
@@ -155,12 +197,11 @@
  */
 static void
 do_error (void *cls,
-         const struct GNUNET_SCHEDULER_TaskContext *tc)
+          const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct LookupHandle *handle = cls;
-  
+  handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
   cleanup_handle (handle);
-  handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
 }
 
 /**
@@ -172,10 +213,8 @@
  */
 static void
 process_lookup_result (void *cls, uint32_t rd_count,
-               const struct GNUNET_GNSRECORD_Data *rd)
+                       const struct GNUNET_GNSRECORD_Data *rd)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                              "result \n");
   struct LookupHandle *handle = cls;
   uint32_t i;
   const char *typename;
@@ -186,30 +225,28 @@
   json_t *result_array;
   json_t *record_obj;
 
-
   result_root = json_object();
   result_name = json_string (handle->name);
   result_array = json_array();
   json_object_set (result_root, "name", result_name);
   json_decref (result_name);
+  handle->lookup_request = NULL;
 
-  handle->lookup_request = NULL;
-  
   for (i=0; i<rd_count; i++)
   {
     if ( (rd[i].record_type != handle->type) &&
-     (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
+         (GNUNET_GNSRECORD_TYPE_ANY != handle->type) )
       continue;
     typename = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
     string_val = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
-                           rd[i].data,
-                           rd[i].data_size);
+                                                   rd[i].data,
+                                                   rd[i].data_size);
     if (NULL == string_val)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-           "Record %u of type %d malformed, skipping\n",
-           (unsigned int) i,
-           (int) rd[i].record_type);
+                  "Record %u of type %d malformed, skipping\n",
+                  (unsigned int) i,
+                  (int) rd[i].record_type);
       continue;
     }
     else
@@ -242,30 +279,27 @@
 static void
 lookup_with_keys (struct LookupHandle *handle, const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                              "Lookup w/ keys \n");
   if (UINT32_MAX == handle->type)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-             _("Invalid typename specified, assuming `ANY'\n"));
+                _("Invalid typename specified, assuming `ANY'\n"));
     handle->type = GNUNET_GNSRECORD_TYPE_ANY;
   }
-
   if (NULL != handle->name)
   {
     handle->lookup_request = GNUNET_GNS_lookup (handle->gns,
-                    handle->name,
-                    &handle->pkey,
-                    handle->type,
-                    handle->options,
-                    shorten_key,
-                    &process_lookup_result,
-                    handle);
+                                                handle->name,
+                                                &handle->pkey,
+                                                handle->type,
+                                                handle->options,
+                                                shorten_key,
+                                                &process_lookup_result,
+                                                handle);
   }
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-         _("Please specify name to lookup!\n"));
+                _("Please specify name to lookup!\n"));
     handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
     cleanup_handle (handle);
     return;
@@ -286,12 +320,10 @@
  */
 static void
 identity_shorten_cb (void *cls,
-             struct GNUNET_IDENTITY_Ego *ego,
-             void **ctx,
-             const char *name)
+                     struct GNUNET_IDENTITY_Ego *ego,
+                     void **ctx,
+                     const char *name)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                              "shorten \n");
   struct LookupHandle *handle = cls;
 
   handle->id_op = NULL;
@@ -299,7 +331,7 @@
     lookup_with_keys (handle, NULL);
   else
     lookup_with_keys (handle,
-              GNUNET_IDENTITY_ego_get_private_key (ego));
+                      GNUNET_IDENTITY_ego_get_private_key (ego));
 }
 
 /**
@@ -311,14 +343,12 @@
 static void
 lookup_with_public_key (struct LookupHandle *handle)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                  "Lookup w/ pkey \n");
   handle->pkeym = handle->pkey;
   GNUNET_break (NULL == handle->id_op);
   handle->id_op = GNUNET_IDENTITY_get (handle->identity,
-                   "gns-short",
-                   &identity_shorten_cb,
-                   handle);
+                                       "gns-short",
+                                       &identity_shorten_cb,
+                                       handle);
   if (NULL == handle->id_op)
   {
     GNUNET_break (0);
@@ -335,7 +365,7 @@
  */
 static void
 identity_zone_cb (void *cls,
-          const struct GNUNET_IDENTITY_Ego *ego)
+                  const struct GNUNET_IDENTITY_Ego *ego)
 {
   struct LookupHandle *handle = cls;
 
@@ -343,7 +373,7 @@
   if (NULL == ego)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-         _("Ego for not found, cannot perform lookup.\n"));
+                _("Ego for not found, cannot perform lookup.\n"));
     handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
     cleanup_handle (handle);
     return;
@@ -370,20 +400,18 @@
  */
 static void
 identity_master_cb (void *cls,
-            struct GNUNET_IDENTITY_Ego *ego,
-            void **ctx,
-            const char *name)
+                    struct GNUNET_IDENTITY_Ego *ego,
+                    void **ctx,
+                    const char *name)
 {
   const char *dot;
   struct LookupHandle *handle = cls;
-    
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Master cb \n");
+
   handle->id_op = NULL;
   if (NULL == ego)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-         _("Ego for `gns-master' not found, cannot perform lookup.  Did you 
run gnunet-gns-import.sh?\n"));
+                _("Ego for `gns-master' not found, cannot perform lookup.  Did 
you run gnunet-gns-import.sh?\n"));
     handle->proc (handle->proc_cls, NULL, 0, GNUNET_SYSERR);
     cleanup_handle (handle);
     return;
@@ -401,93 +429,98 @@
   lookup_with_public_key (handle);
 }
 
+/**
+ * Parse REST uri for name and record type
+ *
+ * @param url Url to parse
+ * @param handle lookup handle to populate
+ * @return GNUNET_SYSERR on error
+ */
 int
 parse_url (const char *url, struct LookupHandle *handle)
 {
-    char *name;
-    char *type;
-    char tmp_url[strlen(url)+1];
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Parsing %s\n", url);
-    strcpy (tmp_url, url);
+  char *name;
+  char *type;
+  char tmp_url[strlen(url)+1];
+  char *tok;
 
-    char *tok = strtok ((char*)tmp_url, "/");
-    
-    
-    if (NULL == tok)
-        return GNUNET_SYSERR;
-
-    name = strtok (NULL, "/");
-
-    if (NULL == name)
-        return GNUNET_SYSERR;
-
-    GNUNET_asprintf (&handle->name,
-                     "%s",
-                     name);
-
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-            "Got name: %s\n", handle->name);
-
-    type = strtok (NULL, "/");
-
-    if (NULL == type)
-    {
-        handle->type = GNUNET_GNSRECORD_TYPE_ANY;
-        return GNUNET_OK;
-    }
-
-    handle->type = GNUNET_GNSRECORD_typename_to_number (type);
- 
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-            "Got type: %s\n", type);   
+  strcpy (tmp_url, url);
+  tok = strtok ((char*)tmp_url, "/");
+  if (NULL == tok)
+    return GNUNET_SYSERR;
+  name = strtok (NULL, "/");
+  if (NULL == name)
+    return GNUNET_SYSERR;
+  GNUNET_asprintf (&handle->name,
+                   "%s",
+                   name);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Got name: %s\n", handle->name);
+  type = strtok (NULL, "/");
+  if (NULL == type)
+  {
+    handle->type = GNUNET_GNSRECORD_TYPE_ANY;
     return GNUNET_OK;
+  }
+  handle->type = GNUNET_GNSRECORD_typename_to_number (type);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Got type: %s\n", type);   
+  return GNUNET_OK;
 }
 
+/**
+ * Parse json from REST request
+ *
+ * @param data REST data
+ * @param data_size data size
+ * @param handle Handle to populate
+ * @return GNUNET_SYSERR on error
+ */
 int
 parse_json (const char *data, size_t data_size, struct LookupHandle *handle)
 {
-    json_error_t error;
-    json_t *pkey_json;
-    json_t *ego_json;
-    json_t *options_json;
+  json_error_t error;
+  json_t *pkey_json;
+  json_t *ego_json;
+  json_t *options_json;
 
-    char term_data[data_size+1];
-    term_data[data_size] = '\0';
+  char term_data[data_size+1];
+  term_data[data_size] = '\0';
 
-    memcpy (term_data, data, data_size);
+  memcpy (term_data, data, data_size);
 
-    handle->json_root = json_loads (term_data, 0, &error);
+  handle->json_root = json_loads (term_data, 0, &error);
 
-    if (NULL == handle->json_root)
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, error.text);
-        return GNUNET_SYSERR;
-    }
+  if (NULL == handle->json_root)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, error.text);
+    return GNUNET_SYSERR;
+  }
 
-    if(!json_is_object(handle->json_root))
-    {
-        return GNUNET_SYSERR;
-    }
-   
-    ego_json = json_object_get (handle->json_root, "ego");
-    
-    if(json_is_string(ego_json))
-    {
-        handle->ego_str = json_string_value (ego_json);
-    }
+  if(!json_is_object(handle->json_root))
+  {
+    return GNUNET_SYSERR;
+  }
 
-    pkey_json = json_object_get (handle->json_root, "pkey");
-    if(json_is_string(pkey_json))
-    {
-        handle->pkey_str = json_string_value (pkey_json);
-    }
+  ego_json = json_object_get (handle->json_root, "ego");
 
-    options_json = json_object_get (handle->json_root, "options");
-    if(json_is_integer (options_json))
-    {
-        handle->options = json_integer_value (options_json);
-    }
-    return GNUNET_OK;
+  if(json_is_string(ego_json))
+  {
+    handle->ego_str = json_string_value (ego_json);
+  }
+
+  pkey_json = json_object_get (handle->json_root, "pkey");
+  if(json_is_string(pkey_json))
+  {
+    handle->pkey_str = json_string_value (pkey_json);
+  }
+
+  options_json = json_object_get (handle->json_root, "options");
+  if(json_is_integer (options_json))
+  {
+    handle->options = json_integer_value (options_json);
+  }
+  return GNUNET_OK;
 }
 
 
@@ -510,103 +543,90 @@
                          GNUNET_REST_ResultProcessor proc,
                          void *proc_cls)
 {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                        "In plugin\n");
-    struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
-    
-    handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; //TODO read from json
+  struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
+  handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
 
-    //parse name and type from url
-    if (GNUNET_OK != parse_url (url, handle))
+  //parse name and type from url
+  if (GNUNET_OK != parse_url (url, handle))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
+    proc (proc_cls, NULL, 0, GNUNET_SYSERR);
+    cleanup_handle (handle);
+    return;
+  }
+
+  handle->proc_cls = proc_cls;
+  handle->proc = proc;
+  if (0 < data_size)
+  {
+    if (GNUNET_OK != parse_json (data, data_size, handle))
     {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing url...\n");
-        proc (proc_cls, NULL, 0, GNUNET_SYSERR);
-        cleanup_handle (handle);
-        return;
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing json...\n");
+      proc (proc_cls, NULL, 0, GNUNET_SYSERR);
+      cleanup_handle (handle);
+      return;
     }
- 
-    handle->proc_cls = proc_cls;
-    handle->proc = proc;
- 
-    if (0 < data_size)
-    {
-        if (GNUNET_OK != parse_json (data, data_size, handle))
-        {
-            GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing json...\n");
-            proc (proc_cls, NULL, 0, GNUNET_SYSERR);
-            cleanup_handle (handle);
-            return;
-        }
-    }
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                        "Connecting...\n");
-    handle->gns = GNUNET_GNS_connect (cfg);
-    handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connecting...\n");
+  handle->gns = GNUNET_GNS_connect (cfg);
+  handle->identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
+  handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
+                                                       &do_error, handle);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Connected\n");
 
-    handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
-                                  &do_error, handle);
+  if (NULL == handle->gns)
+  {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                        "Connected\n");
+                "Connecting to GNS failed\n");
+    proc (proc_cls, NULL, 0, GNUNET_SYSERR);
+    cleanup_handle (handle);
+    return;
+  }
 
-    if (NULL == handle->gns)
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                        "Connecting to GNS failed\n");
-        proc (proc_cls, NULL, 0, GNUNET_SYSERR);
-        cleanup_handle (handle);
-        return;
-    }
-
-    if (NULL != handle->pkey_str)
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                      "pkey_str\n");
-        if (GNUNET_OK !=
+  if (NULL != handle->pkey_str)
+  {
+    if (GNUNET_OK !=
         GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->pkey_str,
                                                     strlen(handle->pkey_str),
                                                     &(handle->pkey)))
-        {
-            proc (proc_cls, NULL, 0, GNUNET_SYSERR);
-            cleanup_handle (handle);
-            return;
-        }
-        lookup_with_public_key (handle);
-
-    }
-    if (NULL != handle->ego_str)
     {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                      "ego_str\n");
-        handle->el = GNUNET_IDENTITY_ego_lookup (cfg,
-                handle->ego_str,
-                &identity_zone_cb,
-                handle);
-        return;
+      proc (proc_cls, NULL, 0, GNUNET_SYSERR);
+      cleanup_handle (handle);
+      return;
     }
-    if ( (NULL != handle->name) &&
-            (strlen (handle->name) > 4) &&
-            (0 == strcmp (".zkey",
-                          &handle->name[strlen (handle->name) - 4])) )
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                      "zkey\n");
-        /* no zone required, use 'anonymous' zone */
-        GNUNET_CRYPTO_ecdsa_key_get_public
-            (GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
-             &(handle->pkey));
-        lookup_with_public_key (handle);
-    }
-    else
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                                      "gns_master\n");
-        GNUNET_break (NULL == handle->id_op);
-        handle->id_op = GNUNET_IDENTITY_get (handle->identity,
-                "gns-master",
-                &identity_master_cb,
-                handle);
-        GNUNET_assert (NULL != handle->id_op);
-    }
+    lookup_with_public_key (handle);
+
+  }
+  if (NULL != handle->ego_str)
+  {
+    handle->el = GNUNET_IDENTITY_ego_lookup (cfg,
+                                             handle->ego_str,
+                                             &identity_zone_cb,
+                                             handle);
+    return;
+  }
+  if ( (NULL != handle->name) &&
+       (strlen (handle->name) > 4) &&
+       (0 == strcmp (".zkey",
+                     &handle->name[strlen (handle->name) - 4])) )
+  {
+    /* no zone required, use 'anonymous' zone */
+    GNUNET_CRYPTO_ecdsa_key_get_public
+      (GNUNET_CRYPTO_ecdsa_key_get_anonymous (),
+       &(handle->pkey));
+    lookup_with_public_key (handle);
+  }
+  else
+  {
+    GNUNET_break (NULL == handle->id_op);
+    handle->id_op = GNUNET_IDENTITY_get (handle->identity,
+                                         "gns-master",
+                                         &identity_master_cb,
+                                         handle);
+    GNUNET_assert (NULL != handle->id_op);
+  }
 }
 
 /**
@@ -631,7 +651,7 @@
   api->name = API_NAMESPACE;
   api->process_request = &rest_gns_process_request;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-       _("GNS REST API initialized\n"));
+              _("GNS REST API initialized\n"));
   return api;
 }
 
@@ -651,7 +671,7 @@
   plugin->cfg = NULL;
   GNUNET_free (api);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-       "GNS REST plugin is finished\n");
+              "GNS REST plugin is finished\n");
   return NULL;
 }
 

Modified: gnunet/src/rest/gnunet-rest-server.c
===================================================================
--- gnunet/src/rest/gnunet-rest-server.c        2015-03-11 12:54:22 UTC (rev 
35370)
+++ gnunet/src/rest/gnunet-rest-server.c        2015-03-11 17:39:32 UTC (rev 
35371)
@@ -1,22 +1,22 @@
 /*
-     This file is part of GNUnet.
-     Copyright (C) 2012-2015 Christian Grothoff (and other contributing 
authors)
+   This file is part of GNUnet.
+   Copyright (C) 2012-2015 Christian Grothoff (and other contributing authors)
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+   GNUnet is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, 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
-     General Public License for more details.
+   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
+   General Public License for more details.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
+   You should have received a copy of the GNU General Public License
+   along with GNUnet; see the file COPYING.  If not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+   */
 /**
  * @author Martin Schanzenbach
  * @file src/rest/gnunet-rest-server.c
@@ -119,15 +119,15 @@
  */
 struct MhdConnectionHandle
 {
-    struct MHD_Connection *con;
-    
-    struct MHD_Response *response;
+  struct MHD_Connection *con;
 
-    struct GNUNET_REST_Plugin *plugin;
+  struct MHD_Response *response;
 
-    int status;
+  struct GNUNET_REST_Plugin *plugin;
 
-    int state;
+  int status;
+
+  int state;
 };
 
 /* ************************* Global helpers ********************* */
@@ -146,8 +146,6 @@
 
 /**
  * Run MHD now, we have extra data ready for the callback.
- *
- * @param hd the daemon to run now.
  */
 static void
 run_mhd_now ()
@@ -156,7 +154,7 @@
       httpd_task)
     GNUNET_SCHEDULER_cancel (httpd_task);
   httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd,
-                         NULL);
+                                         NULL);
 }
 
 /**
@@ -173,14 +171,14 @@
                  size_t len,
                  int status)
 {
-    struct MhdConnectionHandle *handle = cls;
-    struct MHD_Response *resp = MHD_create_response_from_buffer (len,
-                                                                (void*)data,
-                                                                
MHD_RESPMEM_MUST_COPY);
-    (void) MHD_add_response_header 
(resp,MHD_HTTP_HEADER_CONTENT_TYPE,"application/json");
-    handle->status = status;
-    handle->response = resp;
-    run_mhd_now(); 
+  struct MhdConnectionHandle *handle = cls;
+  struct MHD_Response *resp = MHD_create_response_from_buffer (len,
+                                                               (void*)data,
+                                                               
MHD_RESPMEM_MUST_COPY);
+  (void) MHD_add_response_header 
(resp,MHD_HTTP_HEADER_CONTENT_TYPE,"application/json");
+  handle->status = status;
+  handle->response = resp;
+  run_mhd_now(); 
 }
 
 /* ********************************* MHD response generation 
******************* */
@@ -218,90 +216,90 @@
                  size_t *upload_data_size,
                  void **con_cls)
 {
-    char *plugin_name;
-    struct GNUNET_HashCode key;
-    struct MhdConnectionHandle *con_handle;
-       
-    con_handle = *con_cls;
-     
-    if (NULL == *con_cls)
+  char *plugin_name;
+  struct GNUNET_HashCode key;
+  struct MhdConnectionHandle *con_handle;
+
+  con_handle = *con_cls;
+
+  if (NULL == *con_cls)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "New connection %s\n", url);
+    char tmp_url[strlen(url)+1];
+    strcpy (tmp_url, url);
+    con_handle = GNUNET_new (struct MhdConnectionHandle);
+    con_handle->con = con;
+    con_handle->state = GN_REST_STATE_INIT;
+    *con_cls = con_handle;
+
+    plugin_name = strtok(tmp_url, "/");
+
+    if (NULL != plugin_name)
     {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                              "New connection %s\n", url);
-        char tmp_url[strlen(url)+1];
-        strcpy (tmp_url, url);
-        con_handle = GNUNET_new (struct MhdConnectionHandle);
-        con_handle->con = con;
-        con_handle->state = GN_REST_STATE_INIT;
-        *con_cls = con_handle;
-        
-        plugin_name = strtok(tmp_url, "/");
+      GNUNET_CRYPTO_hash (plugin_name, strlen (plugin_name), &key);
 
-        if (NULL != plugin_name)
-        {
-            GNUNET_CRYPTO_hash (plugin_name, strlen (plugin_name), &key);
+      con_handle->plugin = GNUNET_CONTAINER_multihashmap_get (plugin_map,
+                                                              &key);
+    }
+    else
+      con_handle->plugin = NULL;
 
-            con_handle->plugin = GNUNET_CONTAINER_multihashmap_get (plugin_map,
-                                                    &key);
-        }
-        else
-            con_handle->plugin = NULL;
-    
-        if (NULL == con_handle->plugin)
-        {
-            GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+    if (NULL == con_handle->plugin)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "Queueing response with MHD\n");
-            GNUNET_free (con_handle);
-            MHD_queue_response (con,
-                              MHD_HTTP_INTERNAL_SERVER_ERROR,
-                              failure_response);
-        }
-        return MHD_YES;
+      GNUNET_free (con_handle);
+      MHD_queue_response (con,
+                          MHD_HTTP_INTERNAL_SERVER_ERROR,
+                          failure_response);
     }
-                GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Size %d\n", *upload_data_size);
-    if (GN_REST_STATE_INIT == con_handle->state)
+    return MHD_YES;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Size %d\n", *upload_data_size);
+  if (GN_REST_STATE_INIT == con_handle->state)
+  {
+    if (0 != *upload_data_size)
     {
-        if (0 != *upload_data_size)
-        {
-            con_handle->state = GN_REST_STATE_UPLOAD;
+      con_handle->state = GN_REST_STATE_UPLOAD;
 
-            con_handle->plugin->process_request (meth,
-                                     url,
-                                     upload_data,
-                                     *upload_data_size,
-                                     &plugin_callback,
-                                     con_handle);
-            *upload_data_size = 0;
-   
-        }
-        else 
-        {
-            con_handle->state = GN_REST_STATE_RECV;
-            con_handle->plugin->process_request (meth,
-                                     url,
-                                     NULL,
-                                     0,
-                                     &plugin_callback,
-                                     con_handle);
-        }
+      con_handle->plugin->process_request (meth,
+                                           url,
+                                           upload_data,
+                                           *upload_data_size,
+                                           &plugin_callback,
+                                           con_handle);
+      *upload_data_size = 0;
+
     }
-    if (NULL != con_handle->response)
+    else 
     {
+      con_handle->state = GN_REST_STATE_RECV;
+      con_handle->plugin->process_request (meth,
+                                           url,
+                                           NULL,
+                                           0,
+                                           &plugin_callback,
+                                           con_handle);
+    }
+  }
+  if (NULL != con_handle->response)
+  {
 
-GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Queueing response from plugin with MHD\n");
-        if (GNUNET_OK == con_handle->status) {
-            return MHD_queue_response (con,
-                            MHD_HTTP_OK,
-                            con_handle->response);
-        } else {
-            return MHD_queue_response (con,
-                    MHD_HTTP_BAD_REQUEST,
-                    con_handle->response);
-        }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Queueing response from plugin with MHD\n");
+    if (GNUNET_OK == con_handle->status) {
+      return MHD_queue_response (con,
+                                 MHD_HTTP_OK,
+                                 con_handle->response);
+    } else {
+      return MHD_queue_response (con,
+                                 MHD_HTTP_BAD_REQUEST,
+                                 con_handle->response);
     }
-    return MHD_YES;
+  }
+  return MHD_YES;
 }
 
 /* ******************** MHD HTTP setup and event loop ******************** */
@@ -405,19 +403,19 @@
   if (NULL != httpd_task)
     GNUNET_SCHEDULER_cancel (httpd_task);
   if ( (MHD_YES != haveto) &&
-    (-1 == max))
+       (-1 == max))
   {
     /* daemon is idle, kill after timeout */
     httpd_task = GNUNET_SCHEDULER_add_delayed (MHD_CACHE_TIMEOUT,
-                           &kill_httpd_task,
-                           NULL);
+                                               &kill_httpd_task,
+                                               NULL);
   }
   else
   {
     httpd_task =
       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
-                   tv, wrs, wws,
-                   &do_httpd, NULL);
+                                   tv, wrs, wws,
+                                   &do_httpd, NULL);
   }
   if (NULL != wrs)
     GNUNET_NETWORK_fdset_destroy (wrs);
@@ -484,10 +482,10 @@
   if (MHD_YES != MHD_add_connection (httpd, fd, addr, len))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-        _("Failed to pass client to MHD\n"));
+                _("Failed to pass client to MHD\n"));
     return;
   }
-  
+
   schedule_httpd ();
 }
 
@@ -588,31 +586,29 @@
              const char *libname,
              void *lib_ret)
 {
-    struct GNUNET_REST_Plugin *plugin = lib_ret;
-    struct GNUNET_HashCode key;
-    if (NULL == lib_ret)
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                    "Could not load plugin `%s'\n",
-                    libname);
-        return;
-    }
-    
-    GNUNET_CRYPTO_hash (plugin->name, strlen (plugin->name), &key);
-
-    if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (plugin_map,
-                                       &key,
-                                       plugin,
-                                       
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
-    {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+  struct GNUNET_REST_Plugin *plugin = lib_ret;
+  struct GNUNET_HashCode key;
+  if (NULL == lib_ret)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Could not load plugin `%s'\n",
+                libname);
+    return;
+  }
+  GNUNET_CRYPTO_hash (plugin->name, strlen (plugin->name), &key);
+  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (plugin_map,
+                                                      &key,
+                                                      plugin,
+                                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Could not load add plugin `%s'\n",
                 libname);
-        return;
-    }
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Loaded plugin `%s'\n",
-                libname);
+    return;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Loaded plugin `%s'\n",
+              libname);
 }
 
 /**
@@ -627,78 +623,72 @@
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-    cfg = c;
-    
-    plugin_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
+  cfg = c;
+  plugin_map = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
 
-    /* Load plugins */
-    GNUNET_PLUGIN_load_all ("libgnunet_plugin_rest",
-                                     (void *) cfg,
-                                     &load_plugin,
-                                     NULL);
-    
-
-    /* Open listen socket proxy */
-    lsock6 = bind_v6 ();
-    if (NULL == lsock6)
-        GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+  /* Open listen socket proxy */
+  lsock6 = bind_v6 ();
+  if (NULL == lsock6)
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+  else
+  {
+    if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock6, 5))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
+      GNUNET_NETWORK_socket_close (lsock6);
+      lsock6 = NULL;
+    }
     else
     {
-        if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock6, 5))
-        {
-            GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
-            GNUNET_NETWORK_socket_close (lsock6);
-            lsock6 = NULL;
-        }
-        else
-        {
-            ltask6 = GNUNET_SCHEDULER_add_read_net 
(GNUNET_TIME_UNIT_FOREVER_REL,
-                                                      lsock6, &do_accept, 
lsock6);
-        }
+      ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+                                              lsock6, &do_accept, lsock6);
     }
-    lsock4 = bind_v4 ();
-    if (NULL == lsock4)
-        GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+  }
+  lsock4 = bind_v4 ();
+  if (NULL == lsock4)
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+  else
+  {
+    if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock4, 5))
+    {
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
+      GNUNET_NETWORK_socket_close (lsock4);
+      lsock4 = NULL;
+    }
     else
     {
-        if (GNUNET_OK != GNUNET_NETWORK_socket_listen (lsock4, 5))
-        {
-            GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen");
-            GNUNET_NETWORK_socket_close (lsock4);
-            lsock4 = NULL;
-        }
-        else
-        {
-            ltask4 = GNUNET_SCHEDULER_add_read_net 
(GNUNET_TIME_UNIT_FOREVER_REL,
-                                                      lsock4, &do_accept, 
lsock4);
-        }
+      ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+                                              lsock4, &do_accept, lsock4);
     }
-    if ( (NULL == lsock4) &&
-         (NULL == lsock6) )
-    {
-        GNUNET_SCHEDULER_shutdown ();
-        return;
-    } 
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+  }
+  if ( (NULL == lsock4) &&
+       (NULL == lsock6) )
+  {
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  } 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Service listens on port %u\n",
               port);
-    httpd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET,
-                                   0,
-                                   NULL, NULL,
-                                   &create_response, NULL,
-                                   MHD_OPTION_CONNECTION_TIMEOUT, (unsigned 
int) 16,
-                                   MHD_OPTION_NOTIFY_COMPLETED, 
&mhd_completed_cb, NULL,
-                                   MHD_OPTION_END);
-    if (NULL == httpd)
-    {
-        GNUNET_SCHEDULER_shutdown ();
-        return;
-    }
-    
-    
-
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                            &do_shutdown, NULL);
+  httpd = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET,
+                            0,
+                            NULL, NULL,
+                            &create_response, NULL,
+                            MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
+                            MHD_OPTION_NOTIFY_COMPLETED, &mhd_completed_cb, 
NULL,
+                            MHD_OPTION_END);
+  if (NULL == httpd)
+  {
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  /* Load plugins */
+  GNUNET_PLUGIN_load_all ("libgnunet_plugin_rest",
+                          (void *) cfg,
+                          &load_plugin,
+                          NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                &do_shutdown, NULL);
 }
 
 /**
@@ -713,34 +703,33 @@
 int
 main (int argc, char *const *argv)
 {
-    static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-        {'p', "port", NULL,
-            gettext_noop ("listen on specified port (default: 7776)"), 1,
-            &GNUNET_GETOPT_set_ulong, &port},
-        GNUNET_GETOPT_OPTION_END
-    };
-    static const char* err_page =
-        "<html><head><title>gnunet-rest-service</title>"
-        "</head><body>ERROR</body></html>";
-    int ret;
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    {'p', "port", NULL,
+      gettext_noop ("listen on specified port (default: 7776)"), 1,
+      &GNUNET_GETOPT_set_ulong, &port},
+    GNUNET_GETOPT_OPTION_END
+  };
+  static const char* err_page =
+    "{}";
+  int ret;
 
-    if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
-        return 2;
-    GNUNET_log_setup ("gnunet-rest-service", "WARNING", NULL);
-    failure_response = MHD_create_response_from_buffer (strlen(err_page),
-                                                        (void*)err_page,
-                                                        
MHD_RESPMEM_PERSISTENT);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                          "Start\n");
-    ret =
-        (GNUNET_OK ==
-         GNUNET_PROGRAM_run (argc, argv, "gnunet-rest-service",
-                             _("GNUnet REST service"),
-                             options,
-                             &run, NULL)) ? 0: 1;
-    MHD_destroy_response (failure_response);
-    GNUNET_free_non_null ((char *) argv);
-    return ret;
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+  GNUNET_log_setup ("gnunet-rest-service", "WARNING", NULL);
+  failure_response = MHD_create_response_from_buffer (strlen(err_page),
+                                                      (void*)err_page,
+                                                      MHD_RESPMEM_PERSISTENT);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Start\n");
+  ret =
+    (GNUNET_OK ==
+     GNUNET_PROGRAM_run (argc, argv, "gnunet-rest-server",
+                         _("GNUnet REST server"),
+                         options,
+                         &run, NULL)) ? 0: 1;
+  MHD_destroy_response (failure_response);
+  GNUNET_free_non_null ((char *) argv);
+  return ret;
 }
 
-/* end of gnunet-rest-service.c */
+/* end of gnunet-rest-server.c */




reply via email to

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