gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-twister] branch master updated: Fixing comments from


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] branch master updated: Fixing comments from main twister service.
Date: Tue, 29 May 2018 15:29:05 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository twister.

The following commit(s) were added to refs/heads/master by this push:
     new 7fb2c7c  Fixing comments from main twister service.
7fb2c7c is described below

commit 7fb2c7c349b57e019ee356b7888fe8b9e4793398
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue May 29 15:28:38 2018 +0200

    Fixing comments from main twister service.
---
 src/twister/taler-twister-service.c | 245 ++++++++++++++----------------------
 1 file changed, 91 insertions(+), 154 deletions(-)

diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 01a490a..003e2f8 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -51,12 +51,6 @@
 #define LOG_CURL_EASY(level,fun,rc) \
   GNUNET_log(level, _("%s failed at %s:%d: `%s'\n"), fun, __FILE__, __LINE__, 
curl_easy_strerror (rc))
 
-/**
- * Constant value to make sure the
- * final } from JSONs gets dropped, when truncating.
- */
-#define TRUNC_SIZE 4
-
 /* ******** Datastructures for HTTP handling ********** */
 
 
@@ -196,7 +190,6 @@ struct HttpRequest
    * Request processing state machine.
    */
   enum RequestState state;
-
 };
 
 
@@ -239,31 +232,44 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
  */
 static char *target_server_base_url;
 
-/* ************************** Transformations ***************** */
+/* ******************* Transformations ***************** */
 
 /**
  * Set to non-zero if we should change the next response code.
- * In this case, this is the value we should use.
+ * In this case, this is the value to use.
  */
 static unsigned int hack_response_code;
 
 /**
- * Will point to a JSON object to delete
+ * Will point to a JSON object to delete.  Only cares about
+ * _download_ objects.
  */
 static char delete_path[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
- * Will point to a JSON string object which will get a
- * character flipped.
+ * Will point to a JSON _string_ object
+ * which will get a character flipped.
+ * Only checked against _download_ objects.
  */
 static char flip_path_dl[TWISTER_PATH_LENGTH] = {'\0'};
 
+/**
+ * Will point to a JSON _string_ object
+ * which will get a character flipped.
+ * Only checked against _upload_ objects.
+ */
 static char flip_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
- * Will point to a JSON object to modify
+ * Will point to a JSON object to modify.
+ * Only checked against _download_ objects.
  */
 static char modify_path_dl[TWISTER_PATH_LENGTH] = {'\0'};
+
+/**
+ * Will point to a JSON object to modify.
+ * Only checked against _upload_ objects.
+ */
 static char modify_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
@@ -273,13 +279,14 @@ static char modify_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
 static unsigned int malform_upload = GNUNET_NO;
 
 /**
- * If true, will randomly truncate the response before
- * returning to the client.
+ * If true, will randomly truncate the response body
+ * before returning to the client.
  */
 static unsigned int malform = GNUNET_NO;
 
 /**
- * New value.
+ * New value to give the modified field.  Both
+ * for upload and download mods.
  */
 static char modify_value[TWISTER_VALUE_LENGTH];
 
@@ -289,13 +296,8 @@ static char modify_value[TWISTER_VALUE_LENGTH];
  */
 static size_t malformed_size;
 
-/**
- * Will point to the path if it has to be deleted
- */
-
 /* ********************* Global helpers ****************** */
 
-
 /**
  * Run MHD now, we have extra data ready for the callback.
  */
@@ -303,14 +305,13 @@ static void
 run_mhd_now (void);
 
 
-/* ************************* HTTP handling with cURL *********************** */
+/* *************** HTTP handling with cURL ***************** */
 
 
 /**
- * We're getting an HTTP response header from cURL.
- * Convert it to the MHD response headers.  Mostly copies
- * the headers, but makes special adjustments based on
- * control requests.
+ * Transform _one_ CURL header into MHD format and put it
+ * into the response headers list; mostly copies the headers,
+ * but makes special adjustments based on control requests.
  *
  * @param buffer curl buffer with a single
  *        line of header data; not 0-terminated!
@@ -366,86 +367,8 @@ curl_check_hdr (void *buffer,
     return bytes;
   }
 
-  /* custom logic for certain header types */
-#if 0
-  char *new_location;
-  char *new_cookie_hdr;
-
-  new_cookie_hdr = NULL;
-  if ( (NULL != hr->leho) &&
-       (0 == strcasecmp (hdr_type,
-                         MHD_HTTP_HEADER_SET_COOKIE)) )
-
-  {
-    new_cookie_hdr = GNUNET_malloc (strlen (hdr_val) +
-                                    strlen (hr->domain) + 1);
-    offset = 0;
-    domain_matched = GNUNET_NO; /* make sure we match domain at most once */
-    for (tok = strtok (hdr_val, ";"); NULL != tok; tok = strtok (NULL, ";"))
-    {
-      if ( (0 == strncasecmp (tok, " domain", strlen (" domain"))) &&
-           (GNUNET_NO == domain_matched) )
-      {
-        domain_matched = GNUNET_YES;
-        cookie_domain = tok + strlen (" domain") + 1;
-        if (strlen (cookie_domain) < strlen (hr->leho))
-        {
-          delta_cdomain = strlen (hr->leho) - strlen (cookie_domain);
-          if (0 == strcasecmp (cookie_domain, hr->leho + delta_cdomain))
-          {
-            offset += sprintf (new_cookie_hdr + offset,
-                               " domain=%s;",
-                               hr->domain);
-            continue;
-          }
-        }
-        else if (0 == strcmp (cookie_domain, hr->leho))
-        {
-          offset += sprintf (new_cookie_hdr + offset,
-                             " domain=%s;",
-                             hr->domain);
-          continue;
-        }
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                    _("Cookie domain `%s' supplied by server is invalid\n"),
-                    tok);
-      }
-      GNUNET_memcpy (new_cookie_hdr + offset, tok, strlen (tok));
-      offset += strlen (tok);
-      new_cookie_hdr[offset++] = ';';
-    }
-    hdr_val = new_cookie_hdr;
-  }
-
-  new_location = NULL;
-  if (0 == strcasecmp (MHD_HTTP_HEADER_LOCATION, hdr_type))
-  {
-    char *leho_host;
-
-    GNUNET_asprintf (&leho_host,
-                     (HTTPS_PORT != hr->port)
-                     ? "http://%s";
-                     : "https://%s";,
-                     hr->leho);
-    if (0 == strncmp (leho_host,
-                      hdr_val,
-                      strlen (leho_host)))
-    {
-      GNUNET_asprintf (&new_location,
-                       "%s%s%s",
-                       (HTTPS_PORT != hr->port)
-                       ? "http://";
-                       : "https://";,
-                       hr->domain,
-                       hdr_val + strlen (leho_host));
-      hdr_val = new_location;
-    }
-    GNUNET_free (leho_host);
-  }
-  GNUNET_free_non_null (new_location);
-  GNUNET_free_non_null (new_cookie_hdr);
-#endif
-  /* MHD does not allow certain characters in values, remove those */
+  /* MHD does not allow certain characters in values,
+   * remove those */
   if (NULL != (tok = strchr (hdr_val, '\n')))
     *tok = '\0';
   if (NULL != (tok = strchr (hdr_val, '\r')))
@@ -471,7 +394,13 @@ curl_check_hdr (void *buffer,
 
 
 /**
- * FIXME: document
+ * Create the MHD response with CURL's as starting base;
+ * mainly set the response code and parses the response into
+ * JSON, if it is such.
+ *
+ * @param hr pointer to where to store the new data.  Despite
+ *        its name, the struct contains response data as well.
+ * @return #GNUNET_OK if it succeeds.
  */
 static int
 create_mhd_response_from_hr (struct HttpRequest *hr)
@@ -502,24 +431,6 @@ create_mhd_response_from_hr (struct HttpRequest *hr)
                          hr->io_len,
                          JSON_DECODE_ANY,
                          &error);
-#if 0
-  if (NULL != hr->leho)
-  {
-    char *cors_hdr;
-
-    GNUNET_asprintf (&cors_hdr,
-                     (HTTPS_PORT == hr->port)
-                     ? "https://%s";
-                     : "http://%s";,
-                     hr->leho);
-
-    GNUNET_break (MHD_YES ==
-                  MHD_add_response_header (hr->response,
-                                           
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
-                                           cors_hdr));
-    GNUNET_free (cors_hdr);
-  }
-#endif
   return GNUNET_OK;
 }
 
@@ -569,7 +480,7 @@ curl_download_cb (void *ptr,
 
 /**
  * cURL callback for uploaded (PUT/POST) data.
- * Copies from our `io_buf` to make it available to curl.
+ * Copies from our `io_buf` to make it available to cURL.
  *
  * @param buf where to write the data
  * @param size number of bytes per member
@@ -717,7 +628,7 @@ curl_download_prepare ()
  * Task that is run when we are ready to receive
  * more data from curl.
  *
- * @param cls closure, NULL
+ * @param cls closure, usually NULL.
  */
 static void
 curl_task_download (void *cls)
@@ -819,9 +730,8 @@ curl_task_download (void *cls)
 
 
 /**
- * Read HTTP request header field from the request.
- * Copies the fields over to the 'headers' that will be
- * given to curl.  However, substitutions may be applied.
+ * "Filter" function that translates MHD request headers to
+ * cURL's.
  *
  * @param cls our `struct HttpRequest`
  * @param kind value kind
@@ -840,12 +750,6 @@ con_val_iter (void *cls,
   char *new_value = NULL;
 
   (void) kind;
-#if 0
-  if ( (0 == strcasecmp (MHD_HTTP_HEADER_HOST, key)) &&
-       (NULL != hr->leho) )
-    value = hr->leho;
-#endif
-
   if (GNUNET_YES == malform_upload)
   {
     if (0 == strcmp ("Content-Length", key))
@@ -873,19 +777,17 @@ con_val_iter (void *cls,
 }
 
 /**
- * Walk a JSON object (tipically a response we got
- * from a proxied service), and return the last token
- * from the path, plus the parent object of the object
- * targeted by path.
+ * Walk a JSON object preparing its modification.
  *
- * @param path the path pointing to a object in the response
+ * @param path the path pointing to a object to modify.
  * @param[out] parent will point to the parent of the targeted
- *             object
- * @param[out] response parsed original response, to be decref'd
- *             by the caller.
+ *             object.  This parent will be the "handle" to pass
+ *             to the jansson modification function.
  * @param[out] target last token of the path.  E.g. given a x.y.z,
- *             will point to 'z'.  To be freed by the caller.
- * @param hr contains original response.
+ *             will point to 'z'.  This value will also be passed
+ *             to the jansson modification function.
+ *             To be freed by the caller.
+ * @param json the object to be walked over.
  *
  * @return GNUNET_OK if @a path was valid.
  */
@@ -971,7 +873,13 @@ walk_response_object (const char *path,
 }
 
 /**
- * TODO.
+ * Modify a JSON object.  NOTE, the new value to set is
+ * taken from the global value `modify_value'.
+ *
+ * @param con HTTP connection handle.
+ *        FIXME: deprecated, to be removed.
+ * @param json the JSON object to modify.
+ * @param path the path to the field to modify.
  */
 static void
 modify_object (struct MHD_Connection *con,
@@ -1042,6 +950,14 @@ modify_object (struct MHD_Connection *con,
     return;
 }
 
+
+/**
+ * Flip a random character to the string pointed to by @a path.
+ *
+ * @param con FIXME deprecated.
+ * @param json the object whose filed will be flipped.
+ * @param flip_path the path to the string-field to flip.
+ */
 static void
 flip_object (struct MHD_Connection *con,
              json_t *json,
@@ -1111,8 +1027,10 @@ flip_object (struct MHD_Connection *con,
  * will look for it into the next response).  Will flush the
  * operation once the wanted object has been found.
  *
+ * @param con FIXME deprecated.
+ * @param hr contains the object whose field will be deleted.
  * @return MHD_YES / MHD_NO depending on successful / failing
- * response queueing.
+ *         response queueing.
  */
 static void
 delete_object (struct MHD_Connection *con,
@@ -1500,6 +1418,7 @@ create_response (void *cls,
       hr->curl = NULL;
       return MHD_NO;
     }
+
     MHD_get_connection_values (con,
                                MHD_HEADER_KIND,
                                &con_val_iter,
@@ -1728,7 +1647,8 @@ kill_httpd (void)
 /**
  * Task run whenever HTTP server operations are pending.
  *
- * @param cls the `struct MhdHttpList *` of the daemon that is being run
+ * @param cls the `struct MhdHttpList *`
+ *        of the daemon that is being run
  */
 static void
 do_httpd (void *cls);
@@ -1836,7 +1756,7 @@ run_mhd_now (void)
 }
 
 
-/* ******************* General / main code ********************* */
+/* *************** General / main code *************** */
 
 
 /**
@@ -1993,7 +1913,9 @@ client_disconnect_cb (void *cls,
 
 
 /**
- * Comment!
+ * Send confirmation that the operation was handled.
+ *
+ * @param c handle to the client waiting for confirmation.
  */
 static void
 send_acknowledgement (struct GNUNET_SERVICE_Client *c)
@@ -2043,7 +1965,7 @@ handle_malform_upload (void *cls,
 }
 
 /**
- * Control handler for deleting JSON objects
+ * Control handler for deleting JSON response objects
  *
  * @param cls message queue for sending replies
  * @param src received message
@@ -2060,6 +1982,14 @@ handle_modify_path_dl (void *cls,
   send_acknowledgement (c);
 }
 
+
+/**
+ * Control handler for deleting JSON request objects;
+ * (means request to the proxied services)
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
 static void
 handle_modify_path_ul (void *cls,
                        const struct TWISTER_ModifyPath *src)
@@ -2073,7 +2003,7 @@ handle_modify_path_ul (void *cls,
 }
 
 /**
- * Control handler for deleting JSON objects
+ * Control handler for flipping JSON strings into response objects
  *
  * @param cls message queue for sending replies
  * @param src received message
@@ -2088,6 +2018,13 @@ handle_flip_path_dl (void *cls,
   send_acknowledgement (c);
 }
 
+
+/**
+ * Control handler for flipping JSON strings into request objects
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
 static void
 handle_flip_path_ul (void *cls,
                      const struct TWISTER_FlipPath *src)
@@ -2099,7 +2036,7 @@ handle_flip_path_ul (void *cls,
 }
 
 /**
- * Control handler for deleting JSON objects
+ * Control handler for deleting JSON fields from response objects
  *
  * @param cls message queue for sending replies
  * @param src received message

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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