summaryrefslogtreecommitdiff
path: root/registration.c
blob: 3da97b89feda9ef45fe2bd3b9d7455e9e30cdac3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#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__
	emscripten_fetch_attr_t attr;
	emscripten_fetch_attr_init(&attr);
	attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
	strcpy(attr.requestMethod, "POST");
	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
	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
}