Files
auth_service_c/src/user.c
T
wt 604363a577
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Failing after 12s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Failing after 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Failing after 10s
hot fix
2025-08-27 13:33:15 +07:00

63 lines
1.3 KiB
C

#include "user.h"
#include <cJSON.h>
#include <mongoose.h>
request_with_token *new_request_with_token(char *token, cJSON *body,
char *error) {
request_with_token *data = malloc(sizeof(request_with_token));
data->token = token;
data->body = body;
data->error = error;
return data;
}
void free_request_with_token(request_with_token *data) {
if (!data) {
return;
}
if (data->body != nullptr) {
cJSON_Delete(data->body);
}
if (data->token != nullptr) {
free(data->token);
}
if (data->error != nullptr) {
free(data->error);
}
free(data);
}
User *new_user(int id, const char *username, const char *password,
const char *email, const char *group, bool is_superuser) {
User *user = malloc(sizeof(User));
if (user == NULL) {
return NULL;
}
user->id = id;
user->username = strdup(username);
user->password = strdup(password);
user->email = strdup(email);
user->group = strdup(group);
user->is_superuser = is_superuser;
return user;
}
void free_user(User *user) {
if (!user) {
return;
}
if (user->username != nullptr) {
free(user->username);
}
if (user->password != nullptr) {
free(user->password);
}
if (user->email != nullptr) {
free(user->email);
}
if (user->group != nullptr) {
free(user->group);
}
free(user);
}