summaryrefslogtreecommitdiff
path: root/src/libtipidee
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-24 09:59:08 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-24 09:59:08 +0000
commit37d2f8cb438f68eaa1da8a56ea9ce5023091f128 (patch)
tree81672ad4254ea18e7d240230ba47ef6743d491ad /src/libtipidee
parent907f1c64369095b5b2d5f6fb23a8b937720d94cc (diff)
downloadtipidee-37d2f8cb438f68eaa1da8a56ea9ce5023091f128.tar.xz
Full custom header support, switch not made yet
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee')
-rw-r--r--src/libtipidee/deps-lib/tipidee2
-rw-r--r--src/libtipidee/tipidee_conf_get_argv.c7
-rw-r--r--src/libtipidee/tipidee_conf_get_responseheaders.c22
-rw-r--r--src/libtipidee/tipidee_response_header_preparebuiltin.c28
4 files changed, 56 insertions, 3 deletions
diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee
index 93e261a..d406e5c 100644
--- a/src/libtipidee/deps-lib/tipidee
+++ b/src/libtipidee/deps-lib/tipidee
@@ -4,6 +4,7 @@ tipidee_conf_get_argv.o
tipidee_conf_get_content_type.o
tipidee_conf_get_errorfile.o
tipidee_conf_get_redirection.o
+tipidee_conf_get_responseheaders.o
tipidee_conf_get_string.o
tipidee_conf_get_uint32.o
tipidee_conf_init.o
@@ -24,6 +25,7 @@ tipidee_response_header_common_put.o
tipidee_response_header_date.o
tipidee_response_header_date_fmt.o
tipidee_response_header_lastmodified.o
+tipidee_response_header_preparebuiltin.o
tipidee_response_status.o
tipidee_rql_read.o
tipidee_uri_parse.o
diff --git a/src/libtipidee/tipidee_conf_get_argv.c b/src/libtipidee/tipidee_conf_get_argv.c
index 0dd016e..79c24e6 100644
--- a/src/libtipidee/tipidee_conf_get_argv.c
+++ b/src/libtipidee/tipidee_conf_get_argv.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <errno.h>
+#include <stdint.h>
#include <string.h>
#include <skalibs/cdb.h>
@@ -9,11 +10,11 @@
#include <skalibs/posixishard.h>
-unsigned int tipidee_conf_get_argv (tipidee_conf const *conf, char const *key, char const **argv, unsigned int max, size_t *maxlen)
+uint32_t tipidee_conf_get_argv (tipidee_conf const *conf, char const *key, char const **argv, uint32_t max, size_t *maxlen)
{
cdb_data data ;
- size_t curlen = 0 ;
- unsigned int n = 0, pos = 0 ;
+ size_t curlen = 0, pos = 0 ;
+ uint32_t n = 0 ;
if (!tipidee_conf_get(conf, key, &data)) return 0 ;
if (data.s[data.len-1]) return (errno = EPROTO, 0) ;
while (pos < data.len)
diff --git a/src/libtipidee/tipidee_conf_get_responseheaders.c b/src/libtipidee/tipidee_conf_get_responseheaders.c
new file mode 100644
index 0000000..ee8c786
--- /dev/null
+++ b/src/libtipidee/tipidee_conf_get_responseheaders.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <stddef.h>
+#include <errno.h>
+#include <string.h>
+
+#include <skalibs/uint32.h>
+#include <skalibs/cdb.h>
+
+#include <tipidee/conf.h>
+
+#include <skalibs/posixishard.h>
+
+char const *tipidee_conf_get_responseheaders (tipidee_conf const *conf, char const *key, uint32_t *len, uint32_t *n)
+{
+ cdb_data data ;
+ if (!tipidee_conf_get(conf, key, &data)) return NULL ;
+ if (data.len < 4) return (errno = EPROTO, NULL) ;
+ uint32_unpack_big(data.s + data.len - 4, n) ;
+ *len = data.len - 4 ;
+ return data.s ;
+}
diff --git a/src/libtipidee/tipidee_response_header_preparebuiltin.c b/src/libtipidee/tipidee_response_header_preparebuiltin.c
new file mode 100644
index 0000000..a04b666
--- /dev/null
+++ b/src/libtipidee/tipidee_response_header_preparebuiltin.c
@@ -0,0 +1,28 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <tipidee/response.h>
+
+int tipidee_response_header_preparebuiltin (tipidee_response_header *tab, uint32_t n, char const *s, size_t len)
+{
+ size_t pos = 0 ;
+ for (uint32_t i = 0 ; i < n ; i++)
+ {
+ char const *next ;
+ tab[i].key = s + pos ;
+ next = memchr(s + pos, 0, len - pos) ;
+ if (!next) return 0 ;
+ pos = next - s ;
+ if (pos++ >= len) return 0 ;
+ tab[i].options = (uint8_t)s[pos] ;
+ if (pos++ >= len) return 0 ;
+ tab[i].value = s + pos ;
+ next = memchr(s + pos, 0, len - pos) ;
+ if (!next) return 0 ;
+ pos = next - s ;
+ if (pos++ >= len) return 0 ;
+ }
+ return pos == len ;
+}