initial commit

This commit is contained in:
wt committed 2025-08-18 22:46:46 +07:00
commit 22dc118616
17 files changed
+33251

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#include "utils.h"
#include "user.h"
#include <cJSON.h>
#include <mongoose.h>
request_with_token *check_body(const struct mg_http_message *hm) {
if (hm->body.len == 0) {
return new_request_with_token(nullptr, nullptr, (char *)"must have token");
}
cJSON *json_body = cJSON_Parse(hm->body.buf);
const cJSON *token = cJSON_GetObjectItem(json_body, "token");
if (token == NULL) {
const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL) {
return new_request_with_token(nullptr, nullptr, (char *)error_ptr);
}
return new_request_with_token(nullptr, nullptr, (char *)"must have token");
}
return new_request_with_token(strdup(token->valuestring), json_body, nullptr);
}