diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-08-10 16:10:52 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-08-10 16:10:52 -0400 |
commit | 280bbb526c245ac69762e989816cb4c4848cd22c (patch) | |
tree | 0b9f6a19629ab04597ae52186d0d38769f9f6c6b /src/lib/merchant_api_common.c | |
parent | 119de8db9e317e46ebe800524b806809d2b435b0 (diff) | |
download | merchant-280bbb526c245ac69762e989816cb4c4848cd22c.tar.gz merchant-280bbb526c245ac69762e989816cb4c4848cd22c.tar.bz2 merchant-280bbb526c245ac69762e989816cb4c4848cd22c.zip |
implement parse refund uri (untested) & add more tests for pay uri
Diffstat (limited to 'src/lib/merchant_api_common.c')
-rw-r--r-- | src/lib/merchant_api_common.c | 134 |
1 files changed, 109 insertions, 25 deletions
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c index 9745f772..123ad5bb 100644 --- a/src/lib/merchant_api_common.c +++ b/src/lib/merchant_api_common.c @@ -211,27 +211,6 @@ parse_taler_uri_scheme_action (const char *uri, /** - * Finds the last occurrence of @e c in the string @e str. - * - * @param str the string to search in. - * @param c the character to search for. - * @return pointer to the last occurrence of @e c in @e str, if it exists, - * otherwise NULL. - */ -static char * -strchr_last (char *str, - char c) -{ - for (size_t i = strlen (str) - 1; i >= 0; --i) - { - if (c == str[i]) - return &str[i]; - } - return NULL; -} - - -/** * Extracts information from a taler://pay URI. * * @param pay_uri the URI to parse. @@ -263,8 +242,8 @@ TALER_MERCHANT_parse_pay_uri (const char *pay_uri, { char *mpp; char *order_id; - char *session_id = strchr_last (path, - '/'); + char *session_id = strrchr (path, + '/'); struct TALER_ClaimTokenP *claim_token = NULL; char *ssid; @@ -276,8 +255,8 @@ TALER_MERCHANT_parse_pay_uri (const char *pay_uri, *session_id = '\0'; ++session_id; - order_id = strchr_last (path, - '/'); + order_id = strrchr (path, + '/'); if (NULL == order_id) { GNUNET_free (path); @@ -370,3 +349,108 @@ TALER_MERCHANT_parse_pay_uri_free ( GNUNET_free (parse_data->claim_token); GNUNET_free (parse_data->ssid); } + + +/** + * Extracts information from a taler://refund URI. + * + * @param refund_uri the URI to parse. + * @param[out] parse_data data extracted from the URI. Must be free'd. + * @return GNUNET_SYSERR if @e refund_uri is malformed, GNUNET_OK otherwise. + */ +int +TALER_MERCHANT_parse_refund_uri ( + const char *refund_uri, + struct TALER_MERCHANT_RefundUriData *parse_data) +{ + char *path; + { + char *action; + + if ((GNUNET_OK != + parse_taler_uri_scheme_action (refund_uri, + &action, + &path)) || + (0 != strcmp ("refund", + action))) + { + GNUNET_free (action); + GNUNET_free (path); + return GNUNET_SYSERR; + } + GNUNET_free (action); + } + + { + char *mpp; + char *order_id; + char *last_seg = strrchr (path, + '/'); + char *ssid; + + if (NULL == last_seg) + { + GNUNET_free (path); + return GNUNET_SYSERR; + } + *last_seg = '\0'; + ++last_seg; + + order_id = strrchr (path, + '/'); + if (NULL == order_id) + { + GNUNET_free (path); + return GNUNET_SYSERR; + } + *order_id = '\0'; + ++order_id; + + ssid = strchr (last_seg, + '#'); + if (NULL != ssid) + { + *ssid = '\0'; + ++ssid; + } + + if (0 != strlen (last_seg)) + { + GNUNET_free (path); + return GNUNET_SYSERR; + } + + mpp = strchr (path, + '/'); + if (NULL != mpp) + { + *mpp = '\0'; + ++mpp; + } + + parse_data->merchant_host = GNUNET_strdup (path); + parse_data->merchant_prefix_path = + (NULL == mpp) ? NULL : GNUNET_strdup (mpp); + parse_data->order_id = GNUNET_strdup (order_id); + parse_data->ssid = + (NULL == ssid) ? NULL : GNUNET_strdup (ssid); + } + GNUNET_free (path); + return GNUNET_OK; +} + + +/** + * Frees data contained in the result of parsing a taler://refund URI. + * + * @param parse_data the data to free. + */ +void +TALER_MERCHANT_parse_refund_uri_free ( + struct TALER_MERCHANT_RefundUriData *parse_data) +{ + GNUNET_free (parse_data->merchant_host); + GNUNET_free (parse_data->merchant_prefix_path); + GNUNET_free (parse_data->order_id); + GNUNET_free (parse_data->ssid); +} |