summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-21 10:34:26 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-21 10:34:26 +0800
commit07560d8d578c8f4a1bd105fb324598474bda7842 (patch)
treea03d36ce2f5eb5e1208161a108b0d9c151995529
parenta09480e52b741d962d051bb561d3ca1bf10177b9 (diff)
Now lib user decides what to pu in index
-rw-r--r--shopify.c23
-rw-r--r--shopify.h4
2 files changed, 9 insertions, 18 deletions
diff --git a/shopify.c b/shopify.c
index 12acad9..007d2fd 100644
--- a/shopify.c
+++ b/shopify.c
@@ -71,7 +71,7 @@ struct container {
const char *redir_url;
const char *app_id;
const char *scopes;
- const char *index;
+ char *(*html)(const char *);
const char *js_dir;
const struct shopify_api *apis;
struct shopify_session *sessions;
@@ -365,18 +365,9 @@ static enum MHD_Result handle_request(void *cls, struct MHD_Connection *con,
}
} else if (session && session->access_token) {
if (embedded) {
- int fd = open(container->index, O_RDONLY);
- struct stat sb;
- fstat(fd, &sb);
- char html[sb.st_size + 1];
- read(fd, html, sb.st_size);
- close(fd);
- const size_t index_len = sb.st_size - strlen("%s") * 4
- + api_key_len + host_len + app_url_len * 2;
- char index[index_len + 1];
- sprintf(index, html, api_key, host, app_url, app_url);
- res = MHD_create_response_from_buffer(index_len, index,
- MHD_RESPMEM_MUST_COPY);
+ char *html = container->html(host);
+ res = MHD_create_response_from_buffer(strlen(html),
+ html, MHD_RESPMEM_MUST_FREE);
MHD_add_response_header(res, "Content-Security-Policy",
header);
ret = MHD_queue_response(con, MHD_HTTP_OK, res);
@@ -433,8 +424,8 @@ 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 *scopes, const char *index, const char *js_dir,
- const struct shopify_api apis[])
+ const char *scopes, char *(*html)(const char *host),
+ const char *js_dir, const struct shopify_api apis[])
{
crypt_init();
request_init();
@@ -450,7 +441,7 @@ void shopify_app(const char *api_key, const char *api_secret_key,
redir_url,
app_id,
scopes,
- index,
+ html,
js_dir,
apis,
sessions
diff --git a/shopify.h b/shopify.h
index e919773..20dd485 100644
--- a/shopify.h
+++ b/shopify.h
@@ -21,8 +21,8 @@ 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 *scopes, const char *index, const char *js_dir,
- const struct shopify_api apis[]);
+ const char *scopes, char *(*html)(const char *host),
+ const char *js_dir, const struct shopify_api apis[]);
void shopify_graphql(const char *query, const struct shopify_session *session,
char **json);