Files
auth_service_c/src/utils.c
T
2025-08-22 17:46:38 +07:00

22 lines
721 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);
}