From 4eb551a6fe7f5a69cef0311fe1c4fdf9fe765759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Thu, 22 Sep 2022 14:04:24 +0800 Subject: Revert "Merge regex.h, as it's only called 1 time" This reverts commit 3d51ee82115b8e6e619ba817ba8d48672c413845. --- shopify.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'shopify.c') diff --git a/shopify.c b/shopify.c index 1a26f92..b85217e 100644 --- a/shopify.c +++ b/shopify.c @@ -1,13 +1,12 @@ #include #include #include -#define PCRE2_CODE_UNIT_WIDTH 8 -#include +#include #include #include -#include #include "shopify.h" #include "crypt.h" +#include "regex.h" #include "request.h" #include "accesstoken.h" #include "sessiontoken.h" @@ -47,6 +46,7 @@ extern inline void crypt_init(); extern inline bool crypt_macmatch(const char *, const char *, const char *); extern inline void crypt_getnonce(char [], const size_t); +extern inline bool regex_match(const char *); extern inline void request_init(); extern inline void request_gettoken(const char *, const char *, const char *, const char *, char **); @@ -204,7 +204,6 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, while (sessions[nsessions].shop) nsessions++; qsort(sessions, nsessions, sizeof(struct shopify_session), keycmp); - char *shop = NULL; size_t shop_len = 0; char *session_token = NULL; @@ -219,29 +218,12 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, sizeof(struct parameter), keycmp))) shop = param->val; - if (!shop) { + if (!shop || !regex_match(shop)) { clear(params); free(params); return MHD_NO; } shop_len = strlen(shop); - - pcre2_code *re = pcre2_compile((PCRE2_SPTR) - "^[a-zA-Z0-9][a-zA-Z0-9\\-]*\\.myshopify\\.com", - PCRE2_ZERO_TERMINATED, 0, &(int){ 0 }, - &(PCRE2_SIZE){ 0 }, NULL); - pcre2_match_data *match_data - = pcre2_match_data_create_from_pattern(re, NULL); - int rc = pcre2_match(re, (PCRE2_SPTR)shop, strlen(shop), 0, 0, - match_data, NULL); - pcre2_match_data_free(match_data); - pcre2_code_free(re); - if (rc < 0) { - clear(params); - free(params); - return MHD_NO; - } - char *query = NULL; for (int i = 0; i < nparams; i++) { const char *key = params[i].key; -- cgit v1.2.3