diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-06-14 15:17:11 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-06-14 15:17:11 +0200 |
commit | 458d1ac531f52e7802e054bfd151631af4d9d6e0 (patch) | |
tree | da08479965817d153994a5aad662879e63efa62d /src/lib/merchant_api_get_tips.c | |
parent | 573a2270a09266199ac0062b18b2aacab13a8c59 (diff) | |
download | merchant-458d1ac531f52e7802e054bfd151631af4d9d6e0.tar.gz merchant-458d1ac531f52e7802e054bfd151631af4d9d6e0.tar.bz2 merchant-458d1ac531f52e7802e054bfd151631af4d9d6e0.zip |
clean up logic: use new EXCHANGE_YNA enum, avoid crazy macro construction to build URLs, use full power of TALER_url_join() instead
Diffstat (limited to 'src/lib/merchant_api_get_tips.c')
-rw-r--r-- | src/lib/merchant_api_get_tips.c | 103 |
1 files changed, 23 insertions, 80 deletions
diff --git a/src/lib/merchant_api_get_tips.c b/src/lib/merchant_api_get_tips.c index 63bcb940..d15ed820 100644 --- a/src/lib/merchant_api_get_tips.c +++ b/src/lib/merchant_api_get_tips.c @@ -243,7 +243,7 @@ TALER_MERCHANT_tips_get ( struct TALER_MERCHANT_TipsGetHandle * TALER_MERCHANT_tips_get2 (struct GNUNET_CURL_Context *ctx, const char *backend_url, - enum TALER_MERCHANT_YesNoAll expired, + enum TALER_EXCHANGE_YesNoAll expired, int64_t limit, uint64_t offset, TALER_MERCHANT_TipsGetCallback cb, @@ -265,90 +265,33 @@ TALER_MERCHANT_tips_get2 (struct GNUNET_CURL_Context *ctx, /* build tgh->url with the various optional arguments */ { - struct GNUNET_Buffer buf = { 0 }; - bool first = true; - /** - * Macro to append @a a and @a b to @a buf, using - * the right separators between key (@a a) and - * value (@a b). Uses "first" to decide between - * using "?" and "&" as the separator. - * - * @param a a key - * @param b a value - */ -#define APPEND(a,b) \ - do { \ - if (first) \ - GNUNET_buffer_write_str (&buf, \ - "?"); \ - else \ - GNUNET_buffer_write_str (&buf, \ - "&"); \ - first = false; \ - GNUNET_buffer_write_str (&buf, (a)); \ - GNUNET_buffer_write_str (&buf, "="); \ - GNUNET_buffer_write_str (&buf, (b)); \ - } while (0) + char cbuf[30]; + char lbuf[30]; + bool have_offset; - { - char *url; + GNUNET_snprintf (lbuf, + sizeof (lbuf), + "%lld", + (long long) limit); - url = TALER_url_join (backend_url, - "private/tips", - NULL); - if (NULL == url) - goto finished; - GNUNET_buffer_write_str (&buf, - url); - GNUNET_free (url); - } - if (TALER_MERCHANT_YNA_NO != expired) - APPEND ("expired", - (TALER_MERCHANT_YNA_YES == expired) ? "yes" : "all"); if (limit > 0) - { - if (0 != offset) - { - char cbuf[30]; - - GNUNET_snprintf (cbuf, - sizeof (cbuf), - "%llu", - (unsigned long long) offset); - APPEND ("offset", - cbuf); - } - } + have_offset = (0 != offset); else - { - if (UINT64_MAX != offset) - { - char cbuf[30]; - - GNUNET_snprintf (cbuf, - sizeof (cbuf), - "%llu", - (unsigned long long) offset); - APPEND ("offset", - cbuf); - } - } - if (-20 != limit) - { - char cbuf[30]; - - GNUNET_snprintf (cbuf, - sizeof (cbuf), - "%lld", - (long long) limit); - APPEND ("limit", - cbuf); - } - tgh->url = GNUNET_buffer_reap_str (&buf); -#undef APPEND + have_offset = (UINT64_MAX != offset); + GNUNET_snprintf (cbuf, + sizeof (cbuf), + "%llu", + (unsigned long long) offset); + tgh->url = TALER_url_join (backend_url, + "private/tips", + "expired", + (TALER_EXCHANGE_YNA_ALL != expired) + ? TALER_yna_to_string (expired) + : NULL, + "offset", (have_offset) ? cbuf : NULL, + "limit", (-20 != limit) ? lbuf : NULL, + NULL); } - -finished: if (NULL == tgh->url) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |