diff --git a/include/lnm/common.h b/include/lnm/common.h index 8cc982e..95511cc 100644 --- a/include/lnm/common.h +++ b/include/lnm/common.h @@ -86,4 +86,17 @@ uint64_t lnm_atoi(const char *s, size_t len); */ uint64_t lnm_digits(uint64_t num); +/** + * Find the first case-insensitive occurence of s2 in s1. + * + * @param out pointer to store start of match in + * @param s1 pointer to string to look in + * @param s1_len length of s1 + * @param s2 string to search for in s1 + * @param s2_len length of s2 + * @return true if found, false otherwise + */ +bool lnm_stristr(const char **out, const char *s1, size_t s1_len, + const char *s2, size_t s2_len); + #endif diff --git a/src/http/lnm_http_req.c b/src/http/lnm_http_req.c index cc453b2..3d12fcb 100644 --- a/src/http/lnm_http_req.c +++ b/src/http/lnm_http_req.c @@ -113,3 +113,15 @@ lnm_err lnm_http_req_header_get_s(lnm_http_req_hdr *out, lnm_http_req *req, return lnm_err_not_found; } + +lnm_err lnm_http_req_header_param(lnm_http_req_hdr_param *param, + const lnm_http_req_hdr *header, + const char *key) { + size_t key_len = strlen(key); + + const char *s; + if (lnm_stristr(&s, header->name.s, header->name.len - 1, key, key_len) && (header->name.s[key_len] == '=')) { + // Value runs till end of header or next semi-colon + + } +} diff --git a/src/lnm_utils.c b/src/lnm_utils.c index 85094bd..b2c98ed 100644 --- a/src/lnm_utils.c +++ b/src/lnm_utils.c @@ -55,3 +55,19 @@ uint64_t lnm_digits(uint64_t num) { return digits; } + +bool lnm_stristr(const char **out, const char *s1, size_t s1_len, + const char *s2, size_t s2_len) { + while (s1_len >= s2_len) { + if (lnm_strnieq(s1, s1_len, s2, s2_len)) { + *out = s1; + + return true; + } + + s1_len--; + s1++; + } + + return false; +}