diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-04-15 11:10:18 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-04-15 11:10:18 +0200 |
commit | 570bb0303239b9f64311e5f40cba24f5cfe81ee1 (patch) | |
tree | 11f97bfccc1bcef660afe92eb27805c907ec723b /src/mhd | |
parent | bae916ea62e8947092ab084a48bca721b30d6fef (diff) | |
download | exchange-570bb0303239b9f64311e5f40cba24f5cfe81ee1.tar.xz |
API extension for challenger 0.11
Diffstat (limited to 'src/mhd')
-rw-r--r-- | src/mhd/Makefile.am | 2 | ||||
-rw-r--r-- | src/mhd/mhd_legal.c | 1 | ||||
-rw-r--r-- | src/mhd/mhd_parsing.c | 62 |
3 files changed, 64 insertions, 1 deletions
diff --git a/src/mhd/Makefile.am b/src/mhd/Makefile.am index d36bba42f..cd3fe7701 100644 --- a/src/mhd/Makefile.am +++ b/src/mhd/Makefile.am @@ -16,7 +16,7 @@ libtalermhd_la_SOURCES = \ mhd_responses.c \ mhd_run.c libtalermhd_la_LDFLAGS = \ - -version-info 2:0:2 \ + -version-info 3:0:3 \ -no-undefined libtalermhd_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ diff --git a/src/mhd/mhd_legal.c b/src/mhd/mhd_legal.c index 9630452eb..8353a6901 100644 --- a/src/mhd/mhd_legal.c +++ b/src/mhd/mhd_legal.c @@ -131,6 +131,7 @@ mime_matches (const char *accept_pattern, if ( (NULL == da) || (NULL == dm) ) return (0 == strcmp ("*", accept_pattern)); + // FIXME: use TALER_MHD_check_accept() here! /* 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... */ 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 */ |