aboutsummaryrefslogtreecommitdiff
path: root/src/mhd/mhd_parsing.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-04-15 11:10:18 +0200
committerChristian Grothoff <christian@grothoff.org>2024-04-15 11:10:18 +0200
commit570bb0303239b9f64311e5f40cba24f5cfe81ee1 (patch)
tree11f97bfccc1bcef660afe92eb27805c907ec723b /src/mhd/mhd_parsing.c
parentbae916ea62e8947092ab084a48bca721b30d6fef (diff)
API extension for challenger 0.11
Diffstat (limited to 'src/mhd/mhd_parsing.c')
-rw-r--r--src/mhd/mhd_parsing.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mhd/mhd_parsing.c b/src/mhd/mhd_parsing.c
index 2c3312cf2..771319bd5 100644
--- a/src/mhd/mhd_parsing.c
+++ b/src/mhd/mhd_parsing.c
@@ -508,4 +508,66 @@ TALER_MHD_check_content_length_ (struct MHD_Connection *connection,
}
+int
+TALER_MHD_check_accept (struct MHD_Connection *connection,
+ const char *header,
+ ...)
+{
+ bool ret = false;
+ const char *accept;
+ char *a;
+ char *saveptr;
+
+ accept = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ header);
+ if (NULL == accept)
+ return -2; /* no Accept header set */
+
+ a = GNUNET_strdup (accept);
+ for (char *t = strtok_r (a, ",", &saveptr);
+ NULL != t;
+ t = strtok_r (NULL, ",", &saveptr))
+ {
+ char *end;
+
+ /* skip leading whitespace */
+ while (isspace ((unsigned char) t[0]))
+ t++;
+ /* trim of ';q=' parameter and everything after space */
+ /* FIXME: eventually, we might want to parse the "q=$FLOAT"
+ part after the ';' and figure out which one is the
+ best/preferred match instead of returning a boolean... */
+ end = strchr (t, ';');
+ if (NULL != end)
+ *end = '\0';
+ end = strchr (t, ' ');
+ if (NULL != end)
+ *end = '\0';
+ {
+ va_list ap;
+ int off = 0;
+ const char *val;
+
+ va_start (ap,
+ header);
+ while (NULL != (val = va_arg (ap,
+ const char *)))
+ {
+ if (0 == strcasecmp (val,
+ t))
+ {
+ ret = off;
+ break;
+ }
+ off++;
+ }
+ va_end (ap);
+ }
+ }
+ GNUNET_free (a);
+ return ret;
+}
+
+
/* end of mhd_parsing.c */