From c703bfd4f88fb7810622cadebc31a07863ca81f9 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: Fri, 16 Sep 2022 09:15:51 +0800 Subject: Shorten macro names --- shopify.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/shopify.c b/shopify.c index 773172f..dab7881 100644 --- a/shopify.c +++ b/shopify.c @@ -9,12 +9,12 @@ #include "session.h" #include "token.h" -#define AUTHORIZE_URL \ +#define AUTH_URL \ "https://%s/oauth/authorize?client_id=%s&scope=%s&redirect_uri=%s%s"\ "&state=%s" -#define AUTHORIZE_URL_LEN strlen(AUTHORIZE_URL) - strlen("%s") * 6 +#define AUTH_URL_LEN strlen(AUTH_URL) - strlen("%s") * 6 -#define PAGE \ +#define REDIR_PAGE \ "\n"\ "\n"\ "\t\n"\ @@ -33,13 +33,13 @@ "\t\t\n"\ "\t\n"\ "\n" -#define PAGE_LEN strlen(PAGE) - strlen("%s") * 3 +#define REDIR_PAGE_LEN strlen(REDIR_PAGE) - strlen("%s") * 3 -#define FRAME "frame-ancestors https://%s https://admin.shopify.com;" -#define FRAME_LEN strlen(FRAME) - strlen("%s") +#define FRAME_HEADER "frame-ancestors https://%s https://admin.shopify.com;" +#define FRAME_HEADER_LEN strlen(FRAME_HEADER) - strlen("%s") -#define EMBEDDEDAPP_URL "https://%s/apps/%s/" -#define EMBEDDEDAPP_URL_LEN strlen(EMBEDDEDAPP_URL) - strlen("%s") * 2 +#define EMBED_URL "https://%s/apps/%s/" +#define EMBED_URL_LEN strlen(EMBED_URL) - strlen("%s") * 2 extern inline void crypt_init(); extern inline bool crypt_maccmp(const char *, const char *, const char *); @@ -166,8 +166,8 @@ bool shopify_valid(struct MHD_Connection *conn, const char *url, static inline int redirect(const char *host, const char *id, struct MHD_Connection *conn, struct MHD_Response **resp) { - char url[EMBEDDEDAPP_URL_LEN + strlen(host) + strlen(id) + 1]; - sprintf(url, EMBEDDEDAPP_URL, host, id); + char url[EMBED_URL_LEN + strlen(host) + strlen(id) + 1]; + sprintf(url, EMBED_URL, host, id); *resp = MHD_create_response_from_buffer(0, "", MHD_RESPMEM_PERSISTENT); MHD_add_response_header(*resp, "Location", url); return MHD_queue_response(conn, MHD_HTTP_PERMANENT_REDIRECT, *resp); @@ -202,8 +202,8 @@ enum MHD_Result shopify_respond(const struct shopify_param params[], struct session *session = bsearch(&(struct session){ shop }, sessions, nsessions, sizeof(struct session), keycmp); const size_t key_len = strlen(key); - char frame[FRAME_LEN + shop_len + 1]; - sprintf(frame, FRAME, shop); + char frame[FRAME_HEADER_LEN + shop_len + 1]; + sprintf(frame, FRAME_HEADER, shop); enum MHD_Result ret; if (!strcmp(url, redir_url)) { const char *code = ((struct shopify_param *)bsearch( @@ -239,11 +239,11 @@ enum MHD_Result shopify_respond(const struct shopify_param params[], static const size_t nonce_len = 64; char nonce[nonce_len + 1]; crypt_getnonce(nonce, nonce_len); - const size_t authorize_url_len = AUTHORIZE_URL_LEN + const size_t authorize_url_len = AUTH_URL_LEN + decoded_host_len + key_len + scopes_len + strlen(app_url) + strlen(redir_url) + nonce_len; char authorize_url[authorize_url_len + 1]; - sprintf(authorize_url, AUTHORIZE_URL, decoded_host, key, scopes, + sprintf(authorize_url, AUTH_URL, decoded_host, key, scopes, app_url, redir_url, nonce); free(scopes); sessions = realloc(sessions, sizeof(struct session) @@ -254,10 +254,10 @@ enum MHD_Result shopify_respond(const struct shopify_param params[], strcpy(sessions[nsessions].nonce, nonce); sessions[nsessions + 1].shop = NULL; if (embedded) { - const size_t page_len = PAGE_LEN + key_len + const size_t page_len = REDIR_PAGE_LEN + key_len + strlen(host) + authorize_url_len; char page[page_len + 1]; - sprintf(page, PAGE, key, host, authorize_url); + sprintf(page, REDIR_PAGE, key, host, authorize_url); *resp = MHD_create_response_from_buffer(page_len, page, MHD_RESPMEM_MUST_COPY); MHD_add_response_header(*resp, -- cgit v1.2.3