summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-06-14 23:19:12 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-06-14 23:19:12 +0200
commit2363d21cc073208b45a22b010a3da090cb1b77b0 (patch)
treed06261169e42570df593516ebe61927f057e48c4
parentb5399d0bafb8e4bd058d4278d506ebada632bb2d (diff)
downloadtwister-2363d21cc073208b45a22b010a3da090cb1b77b0.tar.gz
twister-2363d21cc073208b45a22b010a3da090cb1b77b0.tar.bz2
twister-2363d21cc073208b45a22b010a3da090cb1b77b0.zip
porting 'delete-path'
-rw-r--r--src/twister/taler-twister-service.c75
-rw-r--r--src/twister/twister.h11
-rw-r--r--src/twister/twister_api.c23
3 files changed, 70 insertions, 39 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
index 034fa5a..f6a3b04 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -315,7 +315,7 @@ static unsigned int hack_response_code;
* Will point to a JSON object to delete. Only cares about
* _download_ objects.
*/
-static char delete_path[TWISTER_PATH_LENGTH] = {'\0'};
+static char *delete_path = NULL;
/**
* Will point to a JSON _string_ object
@@ -1250,10 +1250,9 @@ flip_object (struct MHD_Connection *con,
*
* @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.
+ * @return GNUNET_OK when the path was found, and deleted.
*/
-static void
+static int
delete_object (struct MHD_Connection *con,
struct HttpRequest *hr)
{
@@ -1264,7 +1263,11 @@ delete_object (struct MHD_Connection *con,
&parent,
&target,
hr->json))
- return;
+ {
+ TALER_LOG_INFO ("Path (%s) was not found on this object\n",
+ delete_path);
+ return GNUNET_NO;
+ }
/* here, element is the parent of the element to be deleted. */
int ret_deletion = -1;
@@ -1279,12 +1282,15 @@ delete_object (struct MHD_Connection *con,
NULL,
10));
}
- if (-1 == ret_deletion)
- TALER_LOG_WARNING ("Could not delete '%s'\n", target);
-
- delete_path[0] = '\0';
GNUNET_free (target);
- return;
+
+ if (-1 == ret_deletion)
+ {
+ TALER_LOG_WARNING ("Could not delete '%s'\n",
+ target);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
}
/**
@@ -1823,12 +1829,16 @@ create_response (void *cls,
}
}
- if ('\0' != delete_path[0])
+ if (NULL != delete_path)
{
TALER_LOG_DEBUG ("Will delete path: %s\n",
delete_path);
- delete_object (con,
- hr);
+ if (GNUNET_OK == delete_object (con,
+ hr))
+ {
+ GNUNET_free (delete_path);
+ delete_path = NULL;
+ }
}
if ('\0' != modify_path_dl[0])
@@ -2678,6 +2688,19 @@ handle_flip_path_ul (void *cls,
send_acknowledgement (c);
}
+/**
+ * Control handler for deleting JSON fields from response objects
+ *
+ * @param cls message queue for sending replies
+ * @param src received message
+ */
+static int
+check_delete_path (void *cls,
+ const struct TWISTER_DeletePath *src)
+{
+ return GNUNET_OK;
+}
+
/**
* Control handler for deleting JSON fields from response objects
@@ -2690,8 +2713,19 @@ handle_delete_path (void *cls,
const struct TWISTER_DeletePath *src)
{
struct GNUNET_SERVICE_Client *c = cls;
+ uint16_t tailsize;
+ char *payload;
+
+ tailsize = ntohs (src->header.size) - sizeof (*src);
+
+ GNUNET_assert
+ (tailsize == GNUNET_STRINGS_buffer_tokenize
+ ((const char *) &src[1],
+ tailsize,
+ 1,
+ &payload));
+ delete_path = GNUNET_strdup (payload);
- strcpy (delete_path, src->path);
send_acknowledgement (c);
}
@@ -2703,8 +2737,9 @@ handle_delete_path (void *cls,
* @param src received message
*/
static void
-handle_set_response_code (void *cls,
- const struct TWISTER_SetResponseCode *src)
+handle_set_response_code
+ (void *cls,
+ const struct TWISTER_SetResponseCode *src)
{
struct GNUNET_SERVICE_Client *c = cls;
@@ -2748,10 +2783,10 @@ GNUNET_SERVICE_MAIN
struct TWISTER_Malform,
NULL),
- GNUNET_MQ_hd_fixed_size (delete_path,
- TWISTER_MESSAGE_TYPE_DELETE_PATH,
- struct TWISTER_DeletePath,
- NULL),
+ GNUNET_MQ_hd_var_size (delete_path,
+ TWISTER_MESSAGE_TYPE_DELETE_PATH,
+ struct TWISTER_DeletePath,
+ NULL),
GNUNET_MQ_hd_var_size (flip_path_ul,
TWISTER_MESSAGE_TYPE_FLIP_PATH_UL,
diff --git a/src/twister/twister.h b/src/twister/twister.h
index 8c6c044..01f9363 100644
--- a/src/twister/twister.h
+++ b/src/twister/twister.h
@@ -125,17 +125,6 @@ struct TWISTER_DeletePath
* Type: #TWISTER_MESSAGE_TYPE_DELETE_PATH
*/
struct GNUNET_MessageHeader header;
-
- /**
- * The new response code, in big endian.
- */
- char path[TWISTER_PATH_LENGTH];
-
- /**
- * New value to use in place of the original.
- */
- char value[TWISTER_VALUE_LENGTH];
-
};
GNUNET_NETWORK_STRUCT_END
diff --git a/src/twister/twister_api.c b/src/twister/twister_api.c
index 978e7d1..4beaff5 100644
--- a/src/twister/twister_api.c
+++ b/src/twister/twister_api.c
@@ -33,7 +33,6 @@
GNUNET_log_from (kind, "twister-api",__VA_ARGS__)
-
/**
* Opaque handle for asynchronous operation.
*/
@@ -422,6 +421,7 @@ TALER_TWISTER_delete_path
struct TALER_TWISTER_Operation *op;
struct GNUNET_MQ_Envelope *env;
struct TWISTER_DeletePath *src; //FIXME 'src' right name?
+ uint16_t stralloc;
op = GNUNET_new (struct TALER_TWISTER_Operation);
op->h = h;
@@ -430,12 +430,20 @@ TALER_TWISTER_delete_path
GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
h->op_tail,
op);
- /* Prepare *env*elope. */
- env = GNUNET_MQ_msg
- (src, TWISTER_MESSAGE_TYPE_DELETE_PATH);
- /* Put data into the envelope. */
- strcpy (src->path, path);
- /* Send message. */
+
+ stralloc = strlen (path) + 1;
+
+
+ GNUNET_assert
+ (stralloc + sizeof (struct TWISTER_DeletePath) < UINT16_MAX);
+ env = GNUNET_MQ_msg_extra (src,
+ stralloc,
+ TWISTER_MESSAGE_TYPE_DELETE_PATH);
+ GNUNET_assert
+ (stralloc == GNUNET_STRINGS_buffer_fill ((char *) &src[1],
+ stralloc,
+ 1,
+ path));
GNUNET_MQ_send (h->mq, env);
return op;
}
@@ -470,7 +478,6 @@ TALER_TWISTER_modify_path_dl (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_DL);
/* Put data into the envelope. */