From 0759122e4c7dd17af9f981040e44c747579478b6 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 6 Jun 2023 01:58:42 +0200 Subject: Split wildcard_cmp into its own component Future commits will make use of this function outside handler.c. --- handler.c | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) (limited to 'handler.c') diff --git a/handler.c b/handler.c index 795d503..9103db0 100644 --- a/handler.c +++ b/handler.c @@ -3,6 +3,7 @@ #include "handler.h" #include "http.h" #include "server.h" +#include "wildcard_cmp.h" #include #include #include @@ -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) { -- cgit v1.2.3