summaryrefslogtreecommitdiff
path: root/registration.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-04 15:29:04 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-04 15:29:04 +0800
commitf8dbe8e0f771949f83e91b5e37a690e571a047ee (patch)
tree50cb474a2ebe8e0e730d38186dad87912c0d5f4d /registration.c
Separated client code
Diffstat (limited to 'registration.c')
-rw-r--r--registration.c34
1 files changed, 34 insertions, 0 deletions
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 <string.h>
+#include <emscripten/fetch.h>
+#else
+#include <curl/curl.h>
+#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
+}