From 0fb391c096c8396ac20180ef096bc7c8030bb80c Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 30 Jul 2020 12:05:53 -0400 Subject: [PATCH] [core] http_header_remove_token() --- src/http_header.c | 30 ++++++++++++++++++++++++++++++ src/http_header.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/http_header.c b/src/http_header.c index a4f5a573..4f203b4f 100644 --- a/src/http_header.c +++ b/src/http_header.c @@ -97,6 +97,36 @@ int http_header_str_contains_token (const char * const s, const uint32_t slen, c } +int http_header_remove_token (buffer * const b, const char * const m, const uint32_t mlen) +{ + /*(remove all instance of token from string)*/ + /*(note: does not handle quoted-string)*/ + int rc = 0; + for (char *s = b->ptr; s; ) { + while (*s == ' ' || *s == '\t' || *s == ',') ++s; + if (0 == strncasecmp(s, m, mlen)) { + s += mlen; + if (*s=='\0' || *s==' ' || *s=='\t' || *s==',' || *s==';') { + memset(s-mlen, ' ', mlen); + while (*s != '\0' && *s != ',') ++s; + rc = 1; + if (*s == ',') { + *s++ = ' '; + continue; + } + else { + for (s -= mlen; *s != ',' && s != b->ptr; --s) ; + buffer_string_set_length(b, (size_t)(s - b->ptr)); + break; + } + } + } + s = strchr(s, ','); + } + return rc; +} + + static inline void http_header_token_append(buffer * const vb, const char * const v, const uint32_t vlen) { if (!buffer_string_is_empty(vb)) buffer_append_string_len(vb, CONST_STR_LEN(", ")); diff --git a/src/http_header.h b/src/http_header.h index 72737ef5..45a18153 100644 --- a/src/http_header.h +++ b/src/http_header.h @@ -49,6 +49,8 @@ int http_header_str_to_code (const char * const s); __attribute_pure__ int http_header_str_contains_token (const char *s, uint32_t slen, const char *m, uint32_t mlen); +int http_header_remove_token (buffer * const b, const char * const m, const uint32_t mlen); + __attribute_pure__ buffer * http_header_response_get(const request_st *r, enum http_header_e id, const char *k, uint32_t klen); void http_header_response_unset(request_st *r, enum http_header_e id, const char *k, uint32_t klen);