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: porting modify UL/DL


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] branch master updated: porting modify UL/DL
Date: Fri, 14 Jun 2019 23:55:28 +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 d1afe98  porting modify UL/DL
d1afe98 is described below

commit d1afe98957cae44bca603ffc14267cce64de5cff
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Jun 14 23:55:17 2019 +0200

    porting modify UL/DL
---
 src/twister/taler-twister-service.c | 130 +++++++++++++++++++++++++++---------
 src/twister/twister_api.c           |  40 +++++++----
 2 files changed, 126 insertions(+), 44 deletions(-)

diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 0987ae2..2e82b1f 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -335,13 +335,13 @@ static char *flip_path_ul = NULL;
  * Will point to a JSON object to modify.
  * Only checked against _download_ objects.
  */
-static char modify_path_dl[TWISTER_PATH_LENGTH] = {'\0'};
+static char *modify_path_dl = NULL;
 
 /**
  * Will point to a JSON object to modify.
  * Only checked against _upload_ objects.
  */
-static char modify_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
+static char *modify_path_ul = NULL;
 
 /**
  * If true, will randomly truncate the request body
@@ -356,10 +356,10 @@ static unsigned int malform_upload = GNUNET_NO;
 static unsigned int malform = GNUNET_NO;
 
 /**
- * New value to give the modified field.  Both
- * for upload and download mods.
+ * New value to give the modified field.
+ * Both for upload and download mods.
  */
-static char modify_value[TWISTER_VALUE_LENGTH];
+static char *modify_value = NULL;
 
 /**
  * Size of the malformed body to be uploaded to the
@@ -1072,7 +1072,7 @@ walk_object (const char *path,
  * @param json the JSON object to modify.
  * @param path the path to the field to modify.
  */
-static void
+static int
 modify_object (struct MHD_Connection *con,
                json_t *json,
                char *path)
@@ -1088,7 +1088,11 @@ modify_object (struct MHD_Connection *con,
                                 &parent,
                                 &target,
                                 json))
-    return;
+  {
+    TALER_LOG_INFO ("Path (%s) was not found on this object\n",
+                    path);
+    return GNUNET_NO;
+  }
 
   /* At this point, the parent and the target are pointed to. */
 
@@ -1116,10 +1120,9 @@ modify_object (struct MHD_Connection *con,
 
   TALER_LOG_ERROR ("Unvalid new value given: %s\n",
                    modify_value);
-  path[0] = '\0';
   GNUNET_free (target);
   json_decref (new_value);
-  return;
+  return GNUNET_SYSERR;
 
   perform_modbody:
     ret_modify = -1;
@@ -1132,13 +1135,17 @@ modify_object (struct MHD_Connection *con,
         (parent,
          (unsigned int) strtoul (target, NULL, 10),
          new_value);
-    if (-1 == ret_modify)
-      TALER_LOG_WARNING ("Could not replace '%s'\n", target);
 
-    path[0] = '\0';
     GNUNET_free (target);
     json_decref (new_value);
-    return;
+
+    if (-1 == ret_modify)
+    {
+      TALER_LOG_WARNING ("Could not replace '%s'\n", target);
+      return GNUNET_SYSERR;
+    }
+
+    return GNUNET_OK;
 }
 
 
@@ -1592,15 +1599,26 @@ create_response (void *cls,
       }
     }
 
-    if ('\0' != modify_path_ul[0])
+    if (NULL != modify_path_ul)
     {
+      int ret;
+
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Will try to modify: %s\n",
                   flip_path_ul);
 
-      modify_object (con,
-                     hr->json,
-                     modify_path_ul);
+      ret = modify_object (con,
+                           hr->json,
+                           modify_path_ul);
+
+      if ((GNUNET_OK == ret) || (GNUNET_SYSERR == ret))
+      {
+        GNUNET_free (modify_path_ul);
+        GNUNET_free (modify_value);
+
+        modify_path_ul = NULL;
+        modify_value = NULL;
+      }
     }
 
     /* Existing io_len is enough to accomodate this encoding. */
@@ -1841,14 +1859,26 @@ create_response (void *cls,
     }
   }
 
-  if ('\0' != modify_path_dl[0])
+  if (NULL != modify_path_dl)
   {
+    int ret;
+
     TALER_LOG_DEBUG ("Will modify path: %s to value %s\n",
                      modify_path_dl,
                      modify_value);
-    modify_object (con,
-                   hr->json,
-                   modify_path_dl);
+
+    ret = modify_object (con,
+                         hr->json,
+                         modify_path_dl);
+
+    if ((GNUNET_OK == ret) || (GNUNET_SYSERR == ret))
+    {
+      GNUNET_free (modify_path_dl);
+      GNUNET_free (modify_value);
+
+      modify_path_dl = NULL;
+      modify_value = NULL;
+    }
   }
 
   if (NULL != hr->json)
@@ -2572,6 +2602,18 @@ handle_malform_upload (void *cls,
   send_acknowledgement (c);
 }
 
+/**
+ * Control handler for deleting JSON response objects
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static int
+check_modify_path_dl (void *cls,
+                      const struct TWISTER_ModifyPath *src)
+{
+  return GNUNET_OK;
+}
 
 /**
  * Control handler for deleting JSON response objects
@@ -2584,12 +2626,38 @@ handle_modify_path_dl (void *cls,
                        const struct TWISTER_ModifyPath *src)
 {
   struct GNUNET_SERVICE_Client *c = cls;
+  uint16_t tailsize;
+  char *payload_path;
+  char *payload_value;
+
+  tailsize = ntohs (src->header.size) - sizeof (*src);
+
+  GNUNET_assert
+    (tailsize == GNUNET_STRINGS_buffer_tokenize
+      ((const char *) &src[1],
+       tailsize,
+       2,
+       &payload_path,
+       &payload_value));
+
+  modify_path_dl = GNUNET_strdup (payload_path);
+  modify_value = GNUNET_strdup (payload_value);
 
-  strcpy (modify_path_dl, src->path);
-  strcpy (modify_value, src->value);
   send_acknowledgement (c);
 }
 
+/**
+ * Control handler for deleting JSON response objects
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static int
+check_modify_path_ul (void *cls,
+                      const struct TWISTER_ModifyPath *src)
+{
+  return GNUNET_OK;
+}
 
 /**
  * Control handler for deleting JSON request objects;
@@ -2762,15 +2830,15 @@ GNUNET_SERVICE_MAIN
                          struct TWISTER_SetResponseCode,
                          NULL),
 
- GNUNET_MQ_hd_fixed_size (modify_path_ul,
-                         TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL,
-                         struct TWISTER_ModifyPath,
-                         NULL),
+ GNUNET_MQ_hd_var_size (modify_path_ul,
+                       TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL,
+                       struct TWISTER_ModifyPath,
+                       NULL),
 
- GNUNET_MQ_hd_fixed_size (modify_path_dl,
-                         TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL,
-                         struct TWISTER_ModifyPath,
-                         NULL),
+ GNUNET_MQ_hd_var_size (modify_path_dl,
+                       TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL,
+                       struct TWISTER_ModifyPath,
+                       NULL),
 
  GNUNET_MQ_hd_fixed_size (malform_upload,
                          TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD,
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 4beaff5..faa879d 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -470,6 +470,7 @@ TALER_TWISTER_modify_path_dl (struct TALER_TWISTER_Handle 
*h,
   struct TALER_TWISTER_Operation *op;
   struct GNUNET_MQ_Envelope *env;
   struct TWISTER_ModifyPath *src;
+  uint16_t stralloc;
 
   op = GNUNET_new (struct TALER_TWISTER_Operation);
   op->h = h;
@@ -478,12 +479,19 @@ TALER_TWISTER_modify_path_dl (struct TALER_TWISTER_Handle 
*h,
   GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
                                     h->op_tail,
                                     op);
-  env = GNUNET_MQ_msg
-    (src, TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL);
-  /* Put data into the envelope. */
-  strcpy (src->path, path);
-  strcpy (src->value, value);
-  /* Send message. */
+
+  stralloc = strlen (path) + strlen (value) + 2;
+  GNUNET_assert (sizeof (*src) + stralloc < UINT16_MAX);
+  env = GNUNET_MQ_msg_extra (src,
+                             stralloc,
+                             TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL);
+
+  GNUNET_assert
+    (stralloc == GNUNET_STRINGS_buffer_fill ((char *) &src[1],
+                                             stralloc,
+                                             2,
+                                             path,
+                                             value));
   GNUNET_MQ_send (h->mq, env);
   return op;
 }
@@ -511,6 +519,7 @@ TALER_TWISTER_modify_path_ul (struct TALER_TWISTER_Handle 
*h,
   struct TALER_TWISTER_Operation *op;
   struct GNUNET_MQ_Envelope *env;
   struct TWISTER_ModifyPath *src;
+  uint16_t stralloc;
 
   op = GNUNET_new (struct TALER_TWISTER_Operation);
   op->h = h;
@@ -519,13 +528,18 @@ TALER_TWISTER_modify_path_ul (struct TALER_TWISTER_Handle 
*h,
   GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
                                     h->op_tail,
                                     op);
-  /* Prepare *env*elope. */
-  env = GNUNET_MQ_msg
-    (src, TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL);
-  /* Put data into the envelope. */
-  strcpy (src->path, path);
-  strcpy (src->value, value);
-  /* Send message. */
+
+  stralloc = strlen (path) + strlen (value) + 2;
+  GNUNET_assert (sizeof (*src) + stralloc < UINT16_MAX);
+  env = GNUNET_MQ_msg_extra (src,
+                             stralloc,
+                             TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL);
+  GNUNET_assert
+    (stralloc == GNUNET_STRINGS_buffer_fill ((char *) &src[1],
+                                             stralloc,
+                                             2,
+                                             path,
+                                             value));
   GNUNET_MQ_send (h->mq, env);
   return op;
 }

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



reply via email to

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