2026-02-26 19:44:21 +00:00
|
|
|
#include "msg.h"
|
|
|
|
|
|
|
|
|
|
#include <blue/ds/string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2026-03-10 19:12:14 +00:00
|
|
|
struct msg_definition *msg_definition_create(const char *name, long long id)
|
2026-02-26 19:44:21 +00:00
|
|
|
{
|
|
|
|
|
struct msg_definition *out = malloc(sizeof *out);
|
|
|
|
|
if (!out) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(out, 0x0, sizeof *out);
|
|
|
|
|
|
|
|
|
|
out->msg_name = b_strdup(name);
|
2026-03-10 19:12:14 +00:00
|
|
|
out->msg_id = id;
|
2026-02-26 19:44:21 +00:00
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void msg_definition_destroy(struct msg_definition *msg)
|
|
|
|
|
{
|
|
|
|
|
b_queue_entry *entry = b_queue_pop_front(&msg->msg_params);
|
|
|
|
|
while (entry) {
|
|
|
|
|
struct msg_parameter *param
|
|
|
|
|
= b_unbox(struct msg_parameter, entry, p_entry);
|
|
|
|
|
free(param->p_name);
|
|
|
|
|
free(param);
|
|
|
|
|
entry = b_queue_pop_front(&msg->msg_params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry = b_queue_pop_front(&msg->msg_results);
|
|
|
|
|
while (entry) {
|
|
|
|
|
struct msg_parameter *param
|
|
|
|
|
= b_unbox(struct msg_parameter, entry, p_entry);
|
|
|
|
|
free(param->p_name);
|
|
|
|
|
free(param);
|
|
|
|
|
entry = b_queue_pop_front(&msg->msg_results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(msg->msg_name);
|
|
|
|
|
free(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool msg_definition_has_param(struct msg_definition *msg, const char *name)
|
|
|
|
|
{
|
|
|
|
|
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
|
|
|
|
while (entry) {
|
|
|
|
|
struct msg_parameter *param
|
|
|
|
|
= b_unbox(struct msg_parameter, entry, p_entry);
|
|
|
|
|
if (!strcmp(param->p_name, name)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry = b_queue_next(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool msg_definition_has_result(struct msg_definition *msg, const char *name)
|
|
|
|
|
{
|
|
|
|
|
b_queue_entry *entry = b_queue_first(&msg->msg_results);
|
|
|
|
|
while (entry) {
|
|
|
|
|
struct msg_parameter *param
|
|
|
|
|
= b_unbox(struct msg_parameter, entry, p_entry);
|
|
|
|
|
if (!strcmp(param->p_name, name)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry = b_queue_next(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_definition_add_param(
|
|
|
|
|
struct msg_definition *msg,
|
|
|
|
|
const struct type *type,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct msg_parameter *param = malloc(sizeof *param);
|
|
|
|
|
if (!param) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(param, 0x0, sizeof *param);
|
|
|
|
|
|
|
|
|
|
param->p_type = type;
|
|
|
|
|
param->p_name = b_strdup(name);
|
|
|
|
|
|
|
|
|
|
b_queue_push_back(&msg->msg_params, ¶m->p_entry);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_definition_add_result(
|
|
|
|
|
struct msg_definition *msg,
|
|
|
|
|
const struct type *type,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct msg_parameter *param = malloc(sizeof *param);
|
|
|
|
|
if (!param) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(param, 0x0, sizeof *param);
|
|
|
|
|
|
|
|
|
|
param->p_type = type;
|
|
|
|
|
param->p_name = b_strdup(name);
|
|
|
|
|
|
|
|
|
|
b_queue_push_back(&msg->msg_results, ¶m->p_entry);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|