Module: kamailio
Branch: master
Commit: 5126964ebf28af3be1391e8ed2153503b118ff2c
URL:
https://github.com/kamailio/kamailio/commit/5126964ebf28af3be1391e8ed215350…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-03-03T08:48:01+01:00
corex: process values for dns_cache params in mod init
- ensure the dns cache structure is properly initialized
---
Modified: src/modules/corex/corex_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/5126964ebf28af3be1391e8ed215350…
Patch:
https://github.com/kamailio/kamailio/commit/5126964ebf28af3be1391e8ed215350…
---
diff --git a/src/modules/corex/corex_mod.c b/src/modules/corex/corex_mod.c
index ee1ddd37f4..b4e0b67a87 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"
@@ -83,6 +84,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[] = {
@@ -186,6 +191,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");
@@ -204,6 +211,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");
@@ -336,6 +350,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;
@@ -347,11 +384,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;