diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-05 21:00:07 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-05 21:00:07 +0800 |
commit | 4bcf7322f3e8fc9f16afd7a17e1bbf68199810ec (patch) | |
tree | 5af8b967ad98c54a7ff3ab5df67284770ef2dffa /registration.c | |
parent | f9185b9d09a277b06296f62cb109745566fa18a0 (diff) |
Allocate memory for POST data on Fetch API
Otherwise it might get lost before it reaches the server.
Diffstat (limited to 'registration.c')
-rw-r--r-- | registration.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/registration.c b/registration.c index 1693f09..3da97b8 100644 --- a/registration.c +++ b/registration.c @@ -1,10 +1,21 @@ #ifdef __EMSCRIPTEN__ +#include <stdlib.h> #include <string.h> #include <emscripten/fetch.h> #else #include <curl/curl.h> #endif +#ifdef __EMSCRIPTEN__ + +static void cleanup(struct emscripten_fetch_t *fetch) +{ + free(fetch->userData); + emscripten_fetch_close(fetch); +} + +#endif + void sign_up(const char *brand, const char *certificate) { #ifdef __EMSCRIPTEN__ @@ -12,8 +23,13 @@ void sign_up(const char *brand, const char *certificate) emscripten_fetch_attr_init(&attr); attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; strcpy(attr.requestMethod, "POST"); - attr.requestData = brand; - attr.requestDataSize = strlen(brand) + 1; + char *data = malloc(strlen(brand) + 1); + strcpy(data, brand); + attr.requestData = data; + attr.requestDataSize = strlen(data) + 1; + attr.userData = data; + attr.onsuccess = cleanup; + attr.onerror = cleanup; emscripten_fetch(&attr, "register"); (void)certificate; #else |