diff options
-rw-r--r-- | accesstoken.h | 4 | ||||
-rw-r--r-- | base64.h | 2 | ||||
-rw-r--r-- | crypt.h | 2 | ||||
-rw-r--r-- | session.h | 2 | ||||
-rw-r--r-- | shopify.c | 21 | ||||
-rw-r--r-- | shopify.h | 2 |
6 files changed, 16 insertions, 17 deletions
diff --git a/accesstoken.h b/accesstoken.h index 009cdb0..31d0d29 100644 --- a/accesstoken.h +++ b/accesstoken.h @@ -18,8 +18,8 @@ static inline void accesstoken_parse(const char *tok, "scope")) { const char *val = json_object_get_string( json_object_iter_peek_value(&iter)); - session->scope = malloc(strlen(val) + 1); - strcpy(session->scope, val); + session->scopes = malloc(strlen(val) + 1); + strcpy(session->scopes, val); } json_object_iter_next(&iter); } @@ -1,6 +1,6 @@ #include <gnutls/gnutls.h> -static inline void base64_decode(const char *host, char **dec_host) +static inline void base64_getdecoded(const char *host, char **dec_host) { gnutls_datum_t result; gnutls_base64_decode2(&(gnutls_datum_t){ @@ -5,7 +5,7 @@ static inline void crypt_init() gcry_check_version("1.9.4"); } -static inline bool crypt_maccmp(const char *key, const char *query, +static inline bool crypt_macmatch(const char *key, const char *query, const char *hmac) { gcry_mac_hd_t hd; @@ -2,5 +2,5 @@ struct shopify_session { char *shop; char *nonce; char *access_token; - char *scope; + char *scopes; }; @@ -45,10 +45,10 @@ #define EMBEDDED_URL_LEN strlen(EMBEDDED_URL) - strlen("%s") * 2 extern inline void crypt_init(); -extern inline bool crypt_maccmp(const char *, const char *, const char *); +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 base64_decode(const char *, char **); +extern inline void base64_getdecoded(const char *, char **); extern inline void config_getscopes(const char *, char **); extern inline void request_init(); extern inline void request_gettoken(const char *, const char *, const char *, @@ -70,7 +70,7 @@ struct container { const char *app_url; const char *redir_url; const char *app_id; - const char *scope; + const char *scopes; const char *index; const struct shopify_api *apis; struct shopify_session *sessions; @@ -204,7 +204,7 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, sizeof(struct parameter), keycmp))) hmac = param->val; - if (!hmac || !crypt_maccmp(secret_key, query, hmac)) { + if (!hmac || !crypt_macmatch(secret_key, query, hmac)) { free(query); clear(params); free(params); @@ -260,7 +260,6 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, shop_len = sizeof(char) * (next - pair); shop = malloc(shop_len + 1); strlcpy(shop, pair, shop_len + 1); - printf("Shop: %s\n", shop); free(tofree); if (!regex_match(shop) || !sessiontoken_isvalid(session_token, secret_key)) { @@ -281,7 +280,7 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, param = bsearch(&(struct parameter){ "embedded" }, params, nparams, sizeof(struct parameter), keycmp); embedded = param && !strcmp(param->val, "1"); - base64_decode(host, &dec_host); + base64_getdecoded(host, &dec_host); } const char *key = container->key; const size_t key_len = strlen(key); @@ -345,7 +344,7 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, } else { const size_t dec_host_len = strlen(dec_host); char *scopes = NULL; - config_getscopes(container->scope, &scopes); + config_getscopes(container->scopes, &scopes); const size_t scopes_len = strlen(scopes); static const size_t nonce_len = 64; char nonce[nonce_len + 1]; @@ -391,7 +390,7 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con, void shopify_app(const char *api_key, const char *api_secret_key, const char *app_url, const char *redir_url, const char *app_id, - const char *scope, const char *index, + const char *scopes, const char *index, const struct shopify_api apis[]) { crypt_init(); @@ -407,7 +406,7 @@ void shopify_app(const char *api_key, const char *api_secret_key, app_url, redir_url, app_id, - scope, + scopes, index, apis, sessions @@ -416,8 +415,8 @@ void shopify_app(const char *api_key, const char *api_secret_key, MHD_stop_daemon(daemon); int i = 0; while (sessions[i].shop) { - if (sessions[i].scope) - free(sessions[i].scope); + if (sessions[i].scopes) + free(sessions[i].scopes); if (sessions[i].access_token) free(sessions[i].access_token); free(sessions[i].nonce); @@ -16,7 +16,7 @@ extern "C" { void shopify_app(const char *api_key, const char *api_secret_key, const char *app_url, const char *redir_url, const char *app_id, - const char *scope, const char *index, + const char *scopes, const char *index, const struct shopify_api apis[]); void shopify_graphql(const char *query, const struct shopify_session *session, char **json); |