refactor: worker struct and remove pipe
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
#include "utils/config.h"
|
||||
|
||||
#include <cyaml/cyaml.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utils/debug.h"
|
||||
|
||||
static const cyaml_config_t cyaml_config = {
|
||||
.log_fn = cyaml_log,
|
||||
.mem_fn = cyaml_mem,
|
||||
.log_level = CYAML_LOG_WARNING,
|
||||
};
|
||||
|
||||
static const cyaml_schema_field_t virtual_hosts_fields[] = {
|
||||
CYAML_FIELD_STRING_PTR("domain", CYAML_FLAG_POINTER, struct cws_vhost, domain, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_STRING_PTR("root", CYAML_FLAG_POINTER, struct cws_vhost, root, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_BOOL("ssl", CYAML_FLAG_DEFAULT, struct cws_vhost, ssl),
|
||||
CYAML_FIELD_STRING_PTR("cert", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, struct cws_vhost, cert, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_STRING_PTR("key", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, struct cws_vhost, key, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_END,
|
||||
};
|
||||
|
||||
static cyaml_schema_value_t virtual_hosts_schema = {
|
||||
CYAML_VALUE_MAPPING(CYAML_FLAG_DEFAULT, struct cws_vhost, virtual_hosts_fields),
|
||||
};
|
||||
|
||||
static const cyaml_schema_field_t top_schema_fields[] = {
|
||||
CYAML_FIELD_STRING_PTR("hostname", CYAML_FLAG_POINTER, struct cws_config, hostname, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_STRING_PTR("port", CYAML_FLAG_POINTER, struct cws_config, port, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_SEQUENCE("virtual_hosts", CYAML_FLAG_POINTER, struct cws_config, virtual_hosts, &virtual_hosts_schema, 0, CYAML_UNLIMITED),
|
||||
CYAML_FIELD_END,
|
||||
};
|
||||
|
||||
static cyaml_schema_value_t top_schema = {
|
||||
CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct cws_config, top_schema_fields),
|
||||
};
|
||||
|
||||
cws_config_s *cws_config_init(void) {
|
||||
char *path = "config.yaml";
|
||||
cws_config_s *config;
|
||||
|
||||
cyaml_err_t err = cyaml_load_file(path, &cyaml_config, &top_schema, (cyaml_data_t **)&config, NULL);
|
||||
if (err != CYAML_OK) {
|
||||
CWS_LOG_ERROR("%s", cyaml_strerror(err));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
void cws_config_free(cws_config_s *config) {
|
||||
cyaml_err_t err = cyaml_free(&cyaml_config, &top_schema, config, 0);
|
||||
if (err != CYAML_OK) {
|
||||
/* TODO: Handle */
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
#include "utils/utils.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -69,6 +71,6 @@ bool my_int_equal_fn(const void *a, const void *b) {
|
||||
|
||||
void my_int_free_key_fn(void *key) {
|
||||
int fd = *(int *)key;
|
||||
sock_close(fd);
|
||||
close(fd);
|
||||
free(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user