diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/http.c | 17 | ||||
-rw-r--r-- | source/http.h | 5 | ||||
-rw-r--r-- | source/main.c | 2 |
3 files changed, 8 insertions, 16 deletions
diff --git a/source/http.c b/source/http.c index be62dce..2ac10fb 100644 --- a/source/http.c +++ b/source/http.c | |||
@@ -146,23 +146,13 @@ int submitToApi( | |||
146 | WOLFSSL_CTX* sslContext, | 146 | WOLFSSL_CTX* sslContext, |
147 | cJSON* data, | 147 | cJSON* data, |
148 | const char* username, | 148 | const char* username, |
149 | const char* password) | 149 | const char* token) |
150 | { | 150 | { |
151 | // Form request body. | 151 | // Form request body. |
152 | cJSON* jRequestBody = cJSON_CreateObject(); | 152 | cJSON* jRequestBody = cJSON_CreateObject(); |
153 | 153 | ||
154 | cJSON_AddItemToObject(jRequestBody, "game", data); | 154 | cJSON_AddItemToObject(jRequestBody, "game", data); |
155 | 155 | ||
156 | cJSON_AddItemToObject( | ||
157 | jRequestBody, | ||
158 | "username", | ||
159 | cJSON_CreateString(username)); | ||
160 | |||
161 | cJSON_AddItemToObject( | ||
162 | jRequestBody, | ||
163 | "password", | ||
164 | cJSON_CreateString(password)); | ||
165 | |||
166 | const char* requestBody = cJSON_PrintUnformatted(jRequestBody); | 156 | const char* requestBody = cJSON_PrintUnformatted(jRequestBody); |
167 | 157 | ||
168 | // Gather data from endpoint URL. | 158 | // Gather data from endpoint URL. |
@@ -304,7 +294,10 @@ int submitToApi( | |||
304 | r += sprintf(r, "POST %s HTTP/1.1\r\n", httpPath); | 294 | r += sprintf(r, "POST %s HTTP/1.1\r\n", httpPath); |
305 | r += sprintf(r, "Host: %s\r\n", httpHost); | 295 | r += sprintf(r, "Host: %s\r\n", httpHost); |
306 | r += sprintf(r, "Content-Type: application/json\r\n"); | 296 | r += sprintf(r, "Content-Type: application/json\r\n"); |
307 | r += sprintf(r, "Content-Length: %d\r\n\r\n", strlen(requestBody)); | 297 | r += sprintf(r, "Content-Length: %d\r\n", strlen(requestBody)); |
298 | r += sprintf(r, "X-User-Login: %s\r\n", username); | ||
299 | r += sprintf(r, "X-User-Token: %s\r\n", token); | ||
300 | r += sprintf(r, "\r\n"); | ||
308 | 301 | ||
309 | int result = tcpWrite( | 302 | int result = tcpWrite( |
310 | secure, | 303 | secure, |
diff --git a/source/http.h b/source/http.h index 9597a1d..ed8c017 100644 --- a/source/http.h +++ b/source/http.h | |||
@@ -24,14 +24,13 @@ typedef enum { | |||
24 | } http_res; | 24 | } http_res; |
25 | 25 | ||
26 | /** | 26 | /** |
27 | * Submits a JSON request to a web service. Takes ownership of the cJSON object, | 27 | * Submits a JSON request to a web service. Takes ownership of the cJSON object. |
28 | * because it needs to embed authentication data in it. | ||
29 | */ | 28 | */ |
30 | int submitToApi( | 29 | int submitToApi( |
31 | const char* endpoint, | 30 | const char* endpoint, |
32 | WOLFSSL_CTX* sslContext, | 31 | WOLFSSL_CTX* sslContext, |
33 | cJSON* data, | 32 | cJSON* data, |
34 | const char* username, | 33 | const char* username, |
35 | const char* password); | 34 | const char* token); |
36 | 35 | ||
37 | #endif /* end of include guard: HTTP_H_A46C206E */ | 36 | #endif /* end of include guard: HTTP_H_A46C206E */ |
diff --git a/source/main.c b/source/main.c index 6c97255..2ce314e 100644 --- a/source/main.c +++ b/source/main.c | |||
@@ -425,7 +425,7 @@ void* extractor(void* userdata) | |||
425 | sslContext, | 425 | sslContext, |
426 | root, | 426 | root, |
427 | cJSON_GetObjectItem(config, "username")->valuestring, | 427 | cJSON_GetObjectItem(config, "username")->valuestring, |
428 | cJSON_GetObjectItem(config, "password")->valuestring); | 428 | cJSON_GetObjectItem(config, "token")->valuestring); |
429 | 429 | ||
430 | printf("Result: %d\n", result); | 430 | printf("Result: %d\n", result); |
431 | 431 | ||