diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-08-09 15:01:50 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-08-09 15:01:50 +0200 |
commit | ac7d956ad8d233bf25698c2abbf55d9202dfdf67 (patch) | |
tree | f99f353c29a610f8c2dec8b8b7427851cfbd0d27 /src/backend/taler-merchant-httpd_private-post-orders.c | |
parent | a864161cdc6e9288b1e4055fbb2c08c8b2286a59 (diff) |
implement #6467
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index 6fd65ae8..3c4e91e9 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -588,11 +588,12 @@ patch_order (struct MHD_Connection *connection, { const struct TALER_MERCHANTDB_InstanceSettings *settings = &hc->instance->settings; + const char *order_id; /* Add order_id if it doesn't exist. */ - if (NULL == - json_string_value (json_object_get (order, - "order_id"))) + order_id = json_string_value (json_object_get (order, + "order_id")); + if (NULL == order_id) { char buf[256]; time_t timer; @@ -600,6 +601,7 @@ patch_order (struct MHD_Connection *connection, size_t off; uint64_t rand; char *last; + json_t *jbuf; time (&timer); tm_info = localtime (&timer); @@ -623,9 +625,51 @@ patch_order (struct MHD_Connection *connection, &buf[off], sizeof (buf) - off); *last = '\0'; - json_object_set_new (order, - "order_id", - json_string (buf)); + jbuf = json_string (buf); + GNUNET_break (0 == + json_object_set_new (order, + "order_id", + jbuf)); + order_id = json_string_value (jbuf); + GNUNET_assert (NULL != order_id); + } + + /* Patch fulfillment URL with order_id (implements #6467). */ + { + const char *fulfillment_url; + + fulfillment_url = json_string_value (json_object_get (order, + "fulfillment_url")); + if (NULL != fulfillment_url) + /* The above condition should always be true; if not we do the error + handling later in execute_order() and just skip the logic here. */ + { + const char *pos; + + pos = strstr (fulfillment_url, + "${ORDER_ID}"); + if (NULL != pos) + { + /* replace ${ORDER_ID} with the real order_id */ + char *nurl; + + GNUNET_asprintf (&nurl, + "%.*s%s%s", + /* first output URL until ${ORDER_ID} */ + (int) (pos - fulfillment_url), + fulfillment_url, + /* replace ${ORDER_ID} with the right order_id */ + order_id, + /* append rest of original URL */ + pos + strlen ("${ORDER_ID}")); + /* replace in JSON of the order */ + GNUNET_break (0 == + json_object_set_new (order, + "fulfillment_url", + json_string (nurl))); + GNUNET_free (nurl); + } + } } /* Add timestamp if it doesn't exist */ |