Module: kamailio Branch: 5.4 Commit: c85594b4699763e0e7af8665b8036a6d9fd70090 URL: https://github.com/kamailio/kamailio/commit/c85594b4699763e0e7af8665b8036a6d...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2021-03-03T08:49:16+01:00
corex: process values for dns_cache params in mod init
- ensure the dns cache structure is properly initialized
(cherry picked from commit 5126964ebf28af3be1391e8ed2153503b118ff2c)
---
Modified: src/modules/corex/corex_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/c85594b4699763e0e7af8665b8036a6d... Patch: https://github.com/kamailio/kamailio/commit/c85594b4699763e0e7af8665b8036a6d...
---
diff --git a/src/modules/corex/corex_mod.c b/src/modules/corex/corex_mod.c index 8d0e649548..0b091a7b1f 100644 --- a/src/modules/corex/corex_mod.c +++ b/src/modules/corex/corex_mod.c @@ -31,6 +31,7 @@ #include "../../core/pvar.h" #include "../../core/fmsg.h" #include "../../core/kemi.h" +#include "../../core/str_list.h" #include "../../core/events.h" #include "../../core/onsend.h" #include "../../core/dns_cache.h" @@ -81,6 +82,10 @@ static int mod_init(void); static int child_init(int); static void mod_destroy(void);
+static str_list_t *corex_dns_cache_list = NULL; + +static int corex_dns_cache_param_add(str *pval); + static int corex_sip_reply_out(sr_event_param_t *evp);
static pv_export_t mod_pvs[] = { @@ -182,6 +187,8 @@ struct module_exports exports = { */ static int mod_init(void) { + str_list_t *sit; + if(corex_init_rpc()<0) { LM_ERR("failed to register RPC commands\n"); @@ -194,6 +201,13 @@ static int mod_init(void) return -1; }
+ for(sit = corex_dns_cache_list; sit!=NULL; sit=sit->next) { + if(corex_dns_cache_param_add(&sit->s)<0) { + LM_ERR("failed to add record: %.*s\n", sit->s.len, sit->s.s); + return -1; + } + } + if((nio_intercept > 0) && (nio_intercept_init() < 0)) { LM_ERR("failed to register network io intercept callback\n"); @@ -326,6 +340,29 @@ int corex_alias_subdomains_param(modparam_t type, void *val) }
int corex_dns_cache_param(modparam_t type, void *val) +{ + str_list_t *sit; + + if(val==NULL || ((str*)val)->s==NULL || ((str*)val)->len==0) { + LM_ERR("invalid parameter\n"); + return -1; + } + + sit = (str_list_t*)pkg_mallocxz(sizeof(str_list_t)); + if(sit==NULL) { + PKG_MEM_ERROR; + return -1; + } + sit->s = *((str*)val); + if(corex_dns_cache_list!=NULL) { + sit->next = corex_dns_cache_list; + } + corex_dns_cache_list = sit; + + return 0; +} + +static int corex_dns_cache_param_add(str *pval) { str sval; param_t* params_list = NULL; @@ -337,11 +374,11 @@ int corex_dns_cache_param(modparam_t type, void *val) int dns_ttl = 0; int dns_flags = 0;
- if(val==NULL) { + if(pval==NULL) { LM_ERR("invalid parameter\n"); goto error; } - sval = *((str*)val); + sval = *pval; if(sval.s==NULL || sval.len<=0) { LM_ERR("invalid parameter value\n"); goto error;