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 (88ae598 -> 199d751)


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] branch master updated (88ae598 -> 199d751)
Date: Thu, 17 May 2018 22:19:05 +0200

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

marcello pushed a change to branch master
in repository twister.

    from 88ae598  reuse internal json to encode/decode upload data.
     new e87c597  Adding option to modify upload objects with custom values.
     new 01d0d3f  actual upload-object-modifying logic.
     new 199d751  fix one-char option name.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/taler_twister_service.h       | 16 +++++--
 src/include/taler_twister_testing_lib.h   | 15 +++---
 src/test/test_twister.sh                  |  6 +--
 src/twister/taler-twister-service.c       | 80 ++++++++++++++++++++++++-------
 src/twister/taler-twister.c               | 49 +++++++++++++++----
 src/twister/testing_api_cmd_exec_client.c | 67 ++++++++++++++++++++++----
 src/twister/twister.h                     | 12 +++--
 src/twister/twister_api.c                 | 41 +++++++++++++---
 8 files changed, 227 insertions(+), 59 deletions(-)

diff --git a/src/include/taler_twister_service.h 
b/src/include/taler_twister_service.h
index ae16847..2672865 100644
--- a/src/include/taler_twister_service.h
+++ b/src/include/taler_twister_service.h
@@ -89,12 +89,18 @@ struct TALER_TWISTER_Operation;
  * @return operation handle.
  */
 struct TALER_TWISTER_Operation *
-TALER_TWISTER_modify_path (struct TALER_TWISTER_Handle *h,
-                           const char *path,
-                           const char *value,
-                           GNUNET_SCHEDULER_TaskCallback cb,
-                           void *cb_cls);
+TALER_TWISTER_modify_path_dl (struct TALER_TWISTER_Handle *h,
+                              const char *path,
+                              const char *value,
+                              GNUNET_SCHEDULER_TaskCallback cb,
+                              void *cb_cls);
 
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_modify_path_ul (struct TALER_TWISTER_Handle *h,
+                              const char *path,
+                              const char *value,
+                              GNUNET_SCHEDULER_TaskCallback cb,
+                              void *cb_cls);
 /**
  * Randomly flip a character into the JSON string
  * object pointed to by @a path.
diff --git a/src/include/taler_twister_testing_lib.h 
b/src/include/taler_twister_testing_lib.h
index 9f3d7e5..6605eac 100644
--- a/src/include/taler_twister_testing_lib.h
+++ b/src/include/taler_twister_testing_lib.h
@@ -76,12 +76,15 @@ TALER_TESTING_cmd_delete_object (const char *label,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_modify_object (const char *label,
-                                 const char *config_filename,
-                                 const char *path,
-                                 const char *value);
-
-
+TALER_TESTING_cmd_modify_object_dl (const char *label,
+                                    const char *config_filename,
+                                    const char *path,
+                                    const char *value);
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_modify_object_ul (const char *label,
+                                    const char *config_filename,
+                                    const char *path,
+                                    const char *value);
 /**
  * This command makes the next response randomly malformed
  * (by truncating it).
diff --git a/src/test/test_twister.sh b/src/test/test_twister.sh
index f97b5db..f092e4b 100755
--- a/src/test/test_twister.sh
+++ b/src/test/test_twister.sh
@@ -67,7 +67,7 @@ fi
 
 # set boolean field
 taler-twister -c ./test_twister.conf \
-  --modobject "hello" \
+  -m "hello" \
   --value "true"
 modobject_body=$(curl -s ${TWISTER_URL})
 
@@ -83,7 +83,7 @@ fi
 
 # set field
 taler-twister -c ./test_twister.conf \
-  --modobject "hello" \
+  -m "hello" \
   --value "fake"
 modobject_body=$(curl -s ${TWISTER_URL})
 
@@ -98,7 +98,7 @@ fi
 
 # check if cumulative mods work.
 taler-twister -c ./test_twister.conf \
-  --modobject "hello" -V "world" \
+  -m "hello" -V "world" \
   --deleteobject "when"
 cum_mods=$(curl -s ${TWISTER_URL})
 
diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 6532cd4..01a490a 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -263,7 +263,8 @@ static char flip_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
 /**
  * Will point to a JSON object to modify
  */
-static char modify_path[TWISTER_PATH_LENGTH] = {'\0'};
+static char modify_path_dl[TWISTER_PATH_LENGTH] = {'\0'};
+static char modify_path_ul[TWISTER_PATH_LENGTH] = {'\0'};
 
 /**
  * If true, will randomly truncate the request body
@@ -974,7 +975,8 @@ walk_response_object (const char *path,
  */
 static void
 modify_object (struct MHD_Connection *con,
-               struct HttpRequest *hr)
+               json_t *json,
+               char *path)
 {
 
   char *target;
@@ -983,10 +985,10 @@ modify_object (struct MHD_Connection *con,
   json_t *new_value;
   json_error_t error;
 
-  if (GNUNET_OK != walk_response_object (modify_path,
+  if (GNUNET_OK != walk_response_object (path,
                                          &parent,
                                          &target,
-                                         hr->json))
+                                         json))
     return;
 
   /* At this point, the parent and the target are pointed to. */
@@ -1013,8 +1015,9 @@ modify_object (struct MHD_Connection *con,
     goto perform_modbody;
   }
 
-  TALER_LOG_ERROR ("Unvalid new value given: %s\n", modify_value);
-  modify_path[0] = '\0';
+  TALER_LOG_ERROR ("Unvalid new value given: %s\n",
+                   modify_value);
+  path[0] = '\0';
   GNUNET_free (target);
   json_decref (new_value);
   return;
@@ -1033,7 +1036,7 @@ modify_object (struct MHD_Connection *con,
     if (-1 == ret_modify)
       TALER_LOG_WARNING ("Could not replace '%s'\n", target);
 
-    modify_path[0] = '\0';
+    path[0] = '\0';
     GNUNET_free (target);
     json_decref (new_value);
     return;
@@ -1253,7 +1256,7 @@ create_response (void *cls,
     if ('\0' != flip_path_ul[0])
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Going to modify the upload object (%s)\n",
+                  "Going to flip the upload object (%s)\n",
                   hr->io_buf);
 
       hr->json = json_loads (hr->io_buf,
@@ -1275,6 +1278,32 @@ create_response (void *cls,
       json_decref (hr->json);
     }
 
+    if ('\0' != modify_path_ul[0])
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Going to modify the upload object (%s)\n",
+                  hr->io_buf);
+
+      hr->json = json_loads (hr->io_buf,
+                             JSON_REJECT_DUPLICATES,
+                             NULL);
+      modify_object (con,
+                     hr->json,
+                     modify_path_ul);
+
+      json_dumpb (hr->json,
+                  hr->io_buf,
+/* Existing io_len is enough to accomodate this encoding.  */
+                  hr->io_len, 
+                  JSON_COMPACT);
+
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Modified (?) upload object (%s)\n",
+                  hr->io_buf);
+      json_decref (hr->json);
+    }
+
+
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Generating curl request\n");
     hr->curl = curl_easy_init ();
@@ -1509,12 +1538,14 @@ create_response (void *cls,
     delete_object (con, hr);
   }
 
-  if ('\0' != modify_path[0])
+  if ('\0' != modify_path_dl[0])
   {
     TALER_LOG_DEBUG ("Will modify path: %s to value %s\n",
-                     modify_path,
+                     modify_path_dl,
                      modify_value);
-    modify_object (con, hr);
+    modify_object (con,
+                   hr->json,
+                   modify_path_dl);
   }
 
 
@@ -2018,12 +2049,24 @@ handle_malform_upload (void *cls,
  * @param src received message
  */
 static void
-handle_modify_path (void *cls,
-                    const struct TWISTER_ModifyPath *src)
+handle_modify_path_dl (void *cls,
+                       const struct TWISTER_ModifyPath *src)
 {
   struct GNUNET_SERVICE_Client *c = cls;
 
-  strcpy (modify_path, src->path);
+  strcpy (modify_path_dl, src->path);
+  strcpy (modify_value, src->value);
+
+  send_acknowledgement (c);
+}
+
+static void
+handle_modify_path_ul (void *cls,
+                       const struct TWISTER_ModifyPath *src)
+{
+  struct GNUNET_SERVICE_Client *c = cls;
+
+  strcpy (modify_path_ul, src->path);
   strcpy (modify_value, src->value);
 
   send_acknowledgement (c);
@@ -2103,8 +2146,13 @@ GNUNET_SERVICE_MAIN
                          struct TWISTER_SetResponseCode,
                          NULL),
 
- GNUNET_MQ_hd_fixed_size (modify_path,
-                         TWISTER_MESSAGE_TYPE_MODIFY_PATH,
+ GNUNET_MQ_hd_fixed_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),
 
diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c
index 6806f74..15bf77b 100644
--- a/src/twister/taler-twister.c
+++ b/src/twister/taler-twister.c
@@ -70,12 +70,15 @@ static char *flip_path_dl;
 static char *flip_path_ul;
 
 /**
- * Path to the object to modify.
+ * Path to the download object to modify.
  */
-static char *modify_path;
+static char *modify_path_dl;
+
+
+static char *modify_path_ul;
 
 /**
- * New value for the object pointed by `modify_path`.
+ * New value for the object pointed by `modify_path_(ul|dl)`.
  */
 static char *modify_value;
 
@@ -204,18 +207,38 @@ run (void *cls,
           NULL)) )
     num_ops++;
 
-  if (NULL != modify_path)
+  if (NULL != modify_path_ul)
   {
     if (NULL == modify_value)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "New value not given, give -V|--value also\n");
+      GNUNET_SCHEDULER_shutdown ();
       return;
     }
 
-    if (NULL != TALER_TWISTER_modify_path
+    if (NULL != TALER_TWISTER_modify_path_ul
         (tth,
-         modify_path,
+         modify_path_ul,
+         modify_value,
+         &handle_acknowledgement,
+         NULL))
+      num_ops++;
+  }
+
+  if (NULL != modify_path_dl)
+  {
+    if (NULL == modify_value)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  "New value not given, give -V|--value also\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+
+    if (NULL != TALER_TWISTER_modify_path_dl
+        (tth,
+         modify_path_dl,
          modify_value,
          &handle_acknowledgement,
          NULL))
@@ -243,12 +266,20 @@ main (int argc,
   struct GNUNET_GETOPT_CommandLineOption options[] = {
 
     GNUNET_GETOPT_option_string
+      ('X',
+       "modify-ul",
+       "PATH",
+       gettext_noop
+         ("Modify upload object pointed by PATH, require --value.\n"),
+       &modify_path_ul),
+
+    GNUNET_GETOPT_option_string
       ('m',
-       "modobject",
+       "modify-dl",
        "PATH",
        gettext_noop
-         ("Modify object pointed by PATH, require --value.\n"),
-       &modify_path),
+         ("Modify download object pointed by PATH, require --value.\n"),
+       &modify_path_dl),
 
     GNUNET_GETOPT_option_string
       ('F',
diff --git a/src/twister/testing_api_cmd_exec_client.c 
b/src/twister/testing_api_cmd_exec_client.c
index 8f651a5..60973b2 100644
--- a/src/twister/testing_api_cmd_exec_client.c
+++ b/src/twister/testing_api_cmd_exec_client.c
@@ -390,9 +390,9 @@ modify_object_traits (void *cls,
  * FIXME: document.
  */
 static void
-modify_object_run (void *cls,
-                   const struct TALER_TESTING_Command *cmd,
-                   struct TALER_TESTING_Interpreter *is)
+modify_object_dl_run (void *cls,
+                      const struct TALER_TESTING_Command *cmd,
+                      struct TALER_TESTING_Interpreter *is)
 {
   struct ModifyObjectState *mos = cls;
 
@@ -402,7 +402,32 @@ modify_object_run (void *cls,
                                        "taler-twister",
                                        "taler-twister",
                                        "-c", mos->config_filename,
-                                       "--modobject", mos->path,
+                                       "-m", mos->path,
+                                       "--value", mos->value,
+                                       NULL);
+  if (NULL == mos->proc)
+  {
+    GNUNET_break (0);
+    TALER_TESTING_interpreter_fail (is);
+    return;
+  }
+  TALER_TESTING_wait_for_sigchld (is);
+}
+
+static void
+modify_object_ul_run (void *cls,
+                      const struct TALER_TESTING_Command *cmd,
+                      struct TALER_TESTING_Interpreter *is)
+{
+  struct ModifyObjectState *mos = cls;
+
+  mos->proc = GNUNET_OS_start_process (GNUNET_NO,
+                                       GNUNET_OS_INHERIT_STD_ALL,
+                                       NULL, NULL, NULL,
+                                       "taler-twister",
+                                       "taler-twister",
+                                       "-c", mos->config_filename,
+                                       "-X", mos->path,
                                        "--value", mos->value,
                                        NULL);
   if (NULL == mos->proc)
@@ -854,10 +879,10 @@ TALER_TESTING_cmd_malform_response (const char *label,
  * @return the command
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_modify_object (const char *label,
-                                 const char *config_filename,
-                                 const char *path,
-                                 const char *value)
+TALER_TESTING_cmd_modify_object_dl (const char *label,
+                                    const char *config_filename,
+                                    const char *path,
+                                    const char *value)
 {
   struct ModifyObjectState *mos;
   struct TALER_TESTING_Command cmd;
@@ -868,10 +893,34 @@ TALER_TESTING_cmd_modify_object (const char *label,
   mos->config_filename = config_filename;
 
   cmd.label = label;
-  cmd.run = &modify_object_run;
+  cmd.run = &modify_object_dl_run;
   cmd.cleanup = &modify_object_cleanup;
   cmd.traits = &modify_object_traits;
   cmd.cls = mos;
 
   return cmd;
 }
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_modify_object_ul (const char *label,
+                                    const char *config_filename,
+                                    const char *path,
+                                    const char *value)
+{
+  struct ModifyObjectState *mos;
+  struct TALER_TESTING_Command cmd;
+
+  mos = GNUNET_new (struct ModifyObjectState);
+  mos->path = path;
+  mos->value = value;
+  mos->config_filename = config_filename;
+
+  cmd.label = label;
+  cmd.run = &modify_object_ul_run;
+  cmd.cleanup = &modify_object_cleanup;
+  cmd.traits = &modify_object_traits;
+  cmd.cls = mos;
+
+  return cmd;
+}
+
diff --git a/src/twister/twister.h b/src/twister/twister.h
index 59ae659..b22101c 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -45,15 +45,17 @@
 
 #define TWISTER_MESSAGE_TYPE_DELETE_PATH 3
 
-#define TWISTER_MESSAGE_TYPE_MODIFY_PATH 4
+#define TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL 4
 
-#define TWISTER_MESSAGE_TYPE_MALFORM 5
+#define TWISTER_MESSAGE_TYPE_MODIFY_PATH_UL 5
 
-#define TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD 6
+#define TWISTER_MESSAGE_TYPE_MALFORM 6
 
-#define TWISTER_MESSAGE_TYPE_FLIP_PATH_DL 7
+#define TWISTER_MESSAGE_TYPE_MALFORM_UPLOAD 7
 
-#define TWISTER_MESSAGE_TYPE_FLIP_PATH_UL 8
+#define TWISTER_MESSAGE_TYPE_FLIP_PATH_DL 8
+
+#define TWISTER_MESSAGE_TYPE_FLIP_PATH_UL 9
 
 GNUNET_NETWORK_STRUCT_BEGIN
 struct TWISTER_Malform
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 672e434..c85804a 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -399,11 +399,11 @@ TALER_TWISTER_delete_path
  * @return operation handle.
  */
 struct TALER_TWISTER_Operation *
-TALER_TWISTER_modify_path (struct TALER_TWISTER_Handle *h,
-                           const char *path,
-                           const char *value,
-                           GNUNET_SCHEDULER_TaskCallback cb,
-                           void *cb_cls)
+TALER_TWISTER_modify_path_dl (struct TALER_TWISTER_Handle *h,
+                              const char *path,
+                              const char *value,
+                              GNUNET_SCHEDULER_TaskCallback cb,
+                              void *cb_cls)
 {
   struct TALER_TWISTER_Operation *op;
   struct GNUNET_MQ_Envelope *env;
@@ -418,7 +418,36 @@ TALER_TWISTER_modify_path (struct TALER_TWISTER_Handle *h,
                                     op);
   /* Prepare *env*elope. */
   env = GNUNET_MQ_msg
-    (src, TWISTER_MESSAGE_TYPE_MODIFY_PATH);
+    (src, TWISTER_MESSAGE_TYPE_MODIFY_PATH_DL);
+  /* Put data into the envelope. */
+  strcpy (src->path, path);
+  strcpy (src->value, value);
+  /* Send message. */
+  GNUNET_MQ_send (h->mq, env);
+  return op;
+}
+
+struct TALER_TWISTER_Operation *
+TALER_TWISTER_modify_path_ul (struct TALER_TWISTER_Handle *h,
+                              const char *path,
+                              const char *value,
+                              GNUNET_SCHEDULER_TaskCallback cb,
+                              void *cb_cls)
+{
+  struct TALER_TWISTER_Operation *op;
+  struct GNUNET_MQ_Envelope *env;
+  struct TWISTER_ModifyPath *src;
+
+  op = GNUNET_new (struct TALER_TWISTER_Operation);
+  op->h = h;
+  op->cb = cb;
+  op->cb_cls = cb_cls;
+  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);

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



reply via email to

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