mirror of https://git.kore.io/kore.git
Added cleanup for the module handlers and validators
This commit is contained in:
parent
55d2451b90
commit
7963a2deaa
|
@ -535,7 +535,9 @@ int kore_msg_register(u_int8_t,
|
||||||
void (*cb)(struct kore_msg *, const void *));
|
void (*cb)(struct kore_msg *, const void *));
|
||||||
|
|
||||||
void kore_domain_init(void);
|
void kore_domain_init(void);
|
||||||
|
void kore_domain_cleanup(void);
|
||||||
int kore_domain_new(char *);
|
int kore_domain_new(char *);
|
||||||
|
void kore_domain_free(struct kore_domain *);
|
||||||
void kore_module_init(void);
|
void kore_module_init(void);
|
||||||
void kore_module_reload(int);
|
void kore_module_reload(int);
|
||||||
void kore_module_onload(void);
|
void kore_module_onload(void);
|
||||||
|
@ -547,6 +549,7 @@ void kore_module_load(const char *, const char *);
|
||||||
void kore_domain_sslstart(struct kore_domain *);
|
void kore_domain_sslstart(struct kore_domain *);
|
||||||
int kore_module_handler_new(const char *, const char *,
|
int kore_module_handler_new(const char *, const char *,
|
||||||
const char *, const char *, int);
|
const char *, const char *, int);
|
||||||
|
void kore_module_handler_free(struct kore_module_handle *);
|
||||||
|
|
||||||
struct kore_domain *kore_domain_lookup(const char *);
|
struct kore_domain *kore_domain_lookup(const char *);
|
||||||
struct kore_module_handle *kore_module_handler_find(const char *,
|
struct kore_module_handle *kore_module_handler_find(const char *,
|
||||||
|
|
56
src/domain.c
56
src/domain.c
|
@ -42,6 +42,17 @@ kore_domain_init(void)
|
||||||
TAILQ_INIT(&domains);
|
TAILQ_INIT(&domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kore_domain_cleanup(void)
|
||||||
|
{
|
||||||
|
struct kore_domain *dom;
|
||||||
|
|
||||||
|
while ((dom=TAILQ_FIRST(&domains)) != NULL) {
|
||||||
|
TAILQ_REMOVE(&domains, dom, list);
|
||||||
|
kore_domain_free(dom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
kore_domain_new(char *domain)
|
kore_domain_new(char *domain)
|
||||||
{
|
{
|
||||||
|
@ -71,6 +82,49 @@ kore_domain_new(char *domain)
|
||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kore_domain_free(struct kore_domain *dom)
|
||||||
|
{
|
||||||
|
struct kore_module_handle *hdlr;
|
||||||
|
|
||||||
|
if (dom != NULL) {
|
||||||
|
|
||||||
|
if (primary_dom == dom) {
|
||||||
|
primary_dom = NULL;
|
||||||
|
}
|
||||||
|
TAILQ_REMOVE(&domains, dom, list);
|
||||||
|
|
||||||
|
if (dom->domain != NULL) {
|
||||||
|
kore_mem_free(dom->domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(KORE_NO_TLS)
|
||||||
|
if (dom->ssl_ctx != NULL) {
|
||||||
|
SSL_CTX_free(dom->ssl_ctx);
|
||||||
|
}
|
||||||
|
if (dom->cafile != NULL) {
|
||||||
|
kore_mem_free(dom->cafile);
|
||||||
|
}
|
||||||
|
if (dom->certkey != NULL) {
|
||||||
|
kore_mem_free(dom->certkey);
|
||||||
|
}
|
||||||
|
if (dom->certfile != NULL) {
|
||||||
|
kore_mem_free(dom->certfile);
|
||||||
|
}
|
||||||
|
if (dom->crlfile != NULL) {
|
||||||
|
kore_mem_free(dom->crlfile);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Drop all handlers associated with this domain */
|
||||||
|
while ((hdlr=TAILQ_FIRST(&(dom->handlers))) != NULL) {
|
||||||
|
TAILQ_REMOVE(&(dom->handlers), hdlr, list);
|
||||||
|
kore_module_handler_free(hdlr);
|
||||||
|
}
|
||||||
|
kore_mem_free(dom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
kore_domain_sslstart(struct kore_domain *dom)
|
kore_domain_sslstart(struct kore_domain *dom)
|
||||||
{
|
{
|
||||||
|
@ -179,7 +233,9 @@ kore_domain_sslstart(struct kore_domain *dom)
|
||||||
SSL_CTX_set_tlsext_servername_callback(dom->ssl_ctx, kore_tls_sni_cb);
|
SSL_CTX_set_tlsext_servername_callback(dom->ssl_ctx, kore_tls_sni_cb);
|
||||||
|
|
||||||
kore_mem_free(dom->certfile);
|
kore_mem_free(dom->certfile);
|
||||||
|
dom->certfile = NULL;
|
||||||
kore_mem_free(dom->certkey);
|
kore_mem_free(dom->certkey);
|
||||||
|
dom->certkey = NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -421,6 +421,7 @@ kore_server_start(void)
|
||||||
|
|
||||||
kore_platform_event_cleanup();
|
kore_platform_event_cleanup();
|
||||||
kore_connection_cleanup();
|
kore_connection_cleanup();
|
||||||
|
kore_domain_cleanup();
|
||||||
net_cleanup();
|
net_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
33
src/module.c
33
src/module.c
|
@ -185,9 +185,7 @@ kore_module_handler_new(const char *path, const char *domain,
|
||||||
if (hdlr->type == HANDLER_TYPE_DYNAMIC) {
|
if (hdlr->type == HANDLER_TYPE_DYNAMIC) {
|
||||||
if (regcomp(&(hdlr->rctx), hdlr->path,
|
if (regcomp(&(hdlr->rctx), hdlr->path,
|
||||||
REG_EXTENDED | REG_NOSUB)) {
|
REG_EXTENDED | REG_NOSUB)) {
|
||||||
kore_mem_free(hdlr->func);
|
kore_module_handler_free(hdlr);
|
||||||
kore_mem_free(hdlr->path);
|
|
||||||
kore_mem_free(hdlr);
|
|
||||||
kore_debug("regcomp() on %s failed", path);
|
kore_debug("regcomp() on %s failed", path);
|
||||||
return (KORE_RESULT_ERROR);
|
return (KORE_RESULT_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -197,6 +195,35 @@ kore_module_handler_new(const char *path, const char *domain,
|
||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kore_module_handler_free(struct kore_module_handle *hdlr)
|
||||||
|
{
|
||||||
|
struct kore_handler_params *param;
|
||||||
|
|
||||||
|
if (hdlr != NULL) {
|
||||||
|
if (hdlr->func != NULL) {
|
||||||
|
kore_mem_free(hdlr->func);
|
||||||
|
}
|
||||||
|
if (hdlr->path != NULL) {
|
||||||
|
kore_mem_free(hdlr->path);
|
||||||
|
}
|
||||||
|
if (hdlr->dom != NULL) {
|
||||||
|
TAILQ_REMOVE(&(hdlr->dom->handlers), hdlr, list);
|
||||||
|
}
|
||||||
|
regfree(&(hdlr->rctx));
|
||||||
|
|
||||||
|
/* Drop all validators associated with this handler */
|
||||||
|
while ((param=TAILQ_FIRST(&(hdlr->params))) != NULL) {
|
||||||
|
TAILQ_REMOVE(&(hdlr->params), param, list);
|
||||||
|
if (param->name != NULL) {
|
||||||
|
kore_mem_free(param->name);
|
||||||
|
}
|
||||||
|
kore_mem_free(param);
|
||||||
|
}
|
||||||
|
kore_mem_free(hdlr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct kore_module_handle *
|
struct kore_module_handle *
|
||||||
kore_module_handler_find(const char *domain, const char *path)
|
kore_module_handler_find(const char *domain, const char *path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -370,6 +370,7 @@ kore_worker_entry(struct kore_worker *kw)
|
||||||
|
|
||||||
kore_platform_event_cleanup();
|
kore_platform_event_cleanup();
|
||||||
kore_connection_cleanup();
|
kore_connection_cleanup();
|
||||||
|
kore_domain_cleanup();
|
||||||
#if !defined(KORE_NO_HTTP)
|
#if !defined(KORE_NO_HTTP)
|
||||||
http_cleanup();
|
http_cleanup();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue