diff options
-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 |