From: Christian Grothoff Date: Sun, 15 Mar 2020 21:06:28 +0000 (+0100) Subject: add function that logically belongs to libgnunetcurl instead of in multiple Taler... X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7de26292b744122b20e9cd6ecea95a2273311587;p=oweals%2Fgnunet.git add function that logically belongs to libgnunetcurl instead of in multiple Taler binaries --- diff --git a/src/curl/curl.c b/src/curl/curl.c index 01c7c5fca..da486ecc1 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c @@ -189,7 +189,8 @@ GNUNET_CURL_init (GNUNET_CURL_RescheduleCallback cb, void *cb_cls) if (curl_fail) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Curl was not initialised properly\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Curl was not initialised properly\n"); return NULL; } if (NULL == (multi = curl_multi_init ())) @@ -227,6 +228,27 @@ GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, } +/** + * Return #GNUNET_YES if given a valid scope ID and + * #GNUNET_NO otherwise. See #setup_job_headers, + * logic related to + * #GNUNET_CURL_enable_async_scope_header() for the + * code that generates such a @a scope_id. + * + * @returns #GNUNET_YES iff given a valid scope ID + */ +int +GNUNET_CURL_is_valid_scope_id (const char *scope_id) +{ + if (strlen (scope_id) >= 64) + return GNUNET_NO; + for (size_t i = 0; i < strlen (scope_id); i++) + if (! (isalnum (scope_id[i]) || (scope_id[i] == '-'))) + return GNUNET_NO; + return GNUNET_YES; +} + + /** * Callback used when downloading the reply to an HTTP request. * Just appends all of the data to the `buf` in the diff --git a/src/include/gnunet_curl_lib.h b/src/include/gnunet_curl_lib.h index 8e981e91e..875cfa3bd 100644 --- a/src/include/gnunet_curl_lib.h +++ b/src/include/gnunet_curl_lib.h @@ -360,8 +360,21 @@ GNUNET_CURL_gnunet_scheduler_reschedule (void *cls); * @param header_name name of the header to send. */ void -GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, const - char *header_name); +GNUNET_CURL_enable_async_scope_header (struct GNUNET_CURL_Context *ctx, + const char *header_name); + + +/** + * Return #GNUNET_YES if given a valid scope ID and + * #GNUNET_NO otherwise. See + * #GNUNET_CURL_enable_async_scope_header() for the + * code that generates such a @a scope_id in an HTTP + * header. + * + * @returns #GNUNET_YES iff given a valid scope ID + */ +int +GNUNET_CURL_is_valid_scope_id (const char *scope_id); #endif