Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 12s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 12s
24 lines
720 B
C
24 lines
720 B
C
#include "utils.h"
|
|
|
|
#include <cJSON.h>
|
|
#include <mongoose.h>
|
|
|
|
#include "user.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);
|
|
}
|