From f8dbe8e0f771949f83e91b5e37a690e571a047ee 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: Sun, 4 Jul 2021 15:29:04 +0800 Subject: Separated client code --- registration.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 registration.c (limited to 'registration.c') diff --git a/registration.c b/registration.c new file mode 100644 index 0000000..695cf53 --- /dev/null +++ b/registration.c @@ -0,0 +1,34 @@ +#ifdef __EMSCRIPTEN__ +#include +#include +#else +#include +#endif + +void sign_up(const char *brand, const char *certificate) +{ +#ifdef __EMSCRIPTEN__ + emscripten_fetch_attr_t attr; + emscripten_fetch_attr_init(&attr); + attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; + strcpy(attr.requestMethod, "POST"); + attr.requestData = brand; + attr.requestDataSize = strlen(brand); + emscripten_fetch(&attr, "register"); + (void)certificate; +#else + curl_global_init(CURL_GLOBAL_SSL); + CURL *curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + if (certificate) + curl_easy_setopt(curl, CURLOPT_CAINFO, certificate); +#ifdef DEBUG + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); +#endif + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, brand); + curl_easy_setopt(curl, CURLOPT_URL, SAMPLEURL"/register"); + curl_easy_perform(curl); + curl_easy_cleanup(curl); + curl_global_cleanup(); +#endif +} -- cgit v1.2.3