diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-05-28 12:58:26 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-06-06 01:55:05 +0200 |
| commit | 2648076370b06752a3c3fe70dc47868b66ced7fa (patch) | |
| tree | 9a0d7f4dfc1cc4e48c4afcca9be74e96c8824b8c /handler.c | |
| parent | 17502e7e32c041761dc383a481861997aee7ad28 (diff) | |
WIP searchsearch
wildcard_cmp: Allow case-insensitive searches
Diffstat (limited to 'handler.c')
| -rw-r--r-- | handler.c | 45 |
1 files changed, 2 insertions, 43 deletions
@@ -3,6 +3,7 @@ #include "handler.h" #include "http.h" #include "server.h" +#include "wildcard_cmp.h" #include <errno.h> #include <stdbool.h> #include <stddef.h> @@ -47,48 +48,6 @@ static int on_write(const void *const buf, const size_t n, void *const user) return server_write(buf, n, c->c); } -static int wildcard_cmp(const char *s, const char *p) -{ - while (*p && *s) - { - const char *const wc = strchr(p, '*'); - - if (!wc) - return strcmp(s, p); - - const size_t n = wc - p; - - if (n) - { - const int r = strncmp(s, p, n); - - if (r) - return r; - - p += n; - s += n; - } - else if (*(wc + 1) == *s) - { - p = wc + 1; - s += n; - } - else if (*(wc + 1) == '*') - p++; - else - { - s++; - p += n; - } - } - - while (*p) - if (*p++ != '*') - return -1; - - return 0; -} - static int on_payload(const struct http_payload *const p, struct http_response *const r, void *const user) { @@ -99,7 +58,7 @@ static int on_payload(const struct http_payload *const p, { const struct elem *const e = &h->elem[i]; - if (e->op == p->op && !wildcard_cmp(p->resource, e->url)) + if (e->op == p->op && !wildcard_cmp(p->resource, e->url, true)) return e->f(p, r, e->user); } |
