From ddfe3b37cf47d13c417a0ba6fad1be9547c53cbd 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: Mon, 19 Sep 2022 10:23:26 +0800 Subject: The WASM is run before JS getToken Prepare for processing Authorization header. --- shopify.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/shopify.c b/shopify.c index 593fc33..e1bf2b3 100644 --- a/shopify.c +++ b/shopify.c @@ -75,21 +75,28 @@ struct container { static struct shopify_session *sessions; -static enum MHD_Result getparam(void *cls, enum MHD_ValueKind kind, +static enum MHD_Result iterate(void *cls, enum MHD_ValueKind kind, const char *key, const char *val) { - if (kind == MHD_GET_ARGUMENT_KIND) { - struct parameter **params = cls; - int nparams = 0; - while ((*params)[nparams].key) - nparams++; - *params = realloc(*params, sizeof(struct parameter) - * (nparams + 2)); - (*params)[nparams].key = malloc(strlen(key) + 1); - strcpy((*params)[nparams].key, key); - (*params)[nparams].val = malloc(strlen(val) + 1); - strcpy((*params)[nparams].val, val); - (*params)[nparams + 1].key = NULL; + switch (kind) { + case MHD_GET_ARGUMENT_KIND: + ; + struct parameter **params = cls; + int nparams = 0; + while ((*params)[nparams].key) + nparams++; + *params = realloc(*params, sizeof(struct parameter) + * (nparams + 2)); + (*params)[nparams].key = malloc(strlen(key) + 1); + strcpy((*params)[nparams].key, key); + (*params)[nparams].val = malloc(strlen(val) + 1); + strcpy((*params)[nparams].val, val); + (*params)[nparams + 1].key = NULL; + break; + case MHD_HEADER_KIND: + printf("%s: %s\n", key, val); + default: + break; } return MHD_YES; } @@ -130,8 +137,8 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, *con_cls = params; return MHD_YES; } - MHD_get_connection_values(con, MHD_GET_ARGUMENT_KIND, getparam, - ¶ms); + MHD_get_connection_values(con, MHD_GET_ARGUMENT_KIND, iterate, ¶ms); + MHD_get_connection_values(con, MHD_HEADER_KIND, iterate, NULL); int nparams = 0; while (params[nparams].key) nparams++; @@ -235,10 +242,10 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, read(fd, html, sb.st_size); close(fd); const size_t index_len = sb.st_size - - strlen("%s") * 4 + app_url_len * 2 - + key_len + host_len; + - strlen("%s") * 4 + key_len + host_len + + app_url_len * 2; char index[index_len + 1]; - sprintf(index, html, app_url, key, host, + sprintf(index, html, key, host, app_url, app_url); res = MHD_create_response_from_buffer(index_len, index, MHD_RESPMEM_MUST_COPY); -- cgit v1.2.3