Module: kamailio
Branch: master
Commit: 1c402ddc4cc499700e186b65108303a2aaec6287
URL:
https://github.com/kamailio/kamailio/commit/1c402ddc4cc499700e186b65108303a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-11-26T08:49:02+01:00
core: new command line parameter --modparam
- allow setting a module parameter via command line
- format: --modparam=modname:paramname:type:valye
- type can be: 'i' for integer value; 's' for string value
- example:
kamailio --loadmodule=xprint.so --modparam=xprint:buf_size:i:2048
---
Modified: src/core/modparam.c
Modified: src/core/modparam.h
Modified: src/main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1c402ddc4cc499700e186b65108303a…
Patch:
https://github.com/kamailio/kamailio/commit/1c402ddc4cc499700e186b65108303a…
---
diff --git a/src/core/modparam.c b/src/core/modparam.c
index 72ad2fbc9e..1a7d8acd78 100644
--- a/src/core/modparam.c
+++ b/src/core/modparam.c
@@ -154,3 +154,63 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type,
void* val)
}
return 0;
}
+
+int set_mod_param_serialized(char* mval)
+{
+#define MPARAM_MBUF_SIZE 256
+ char mbuf[MPARAM_MBUF_SIZE];
+ char *mname = NULL;
+ char *mparam = NULL;
+ char *sval = NULL;
+ int ival = 0;
+ int ptype = PARAM_STRING;
+ char *p = NULL;
+
+ if(strlen(mval) >= MPARAM_MBUF_SIZE) {
+ LM_ERR("argument is too long: %s\n", mval);
+ return -1;
+ }
+ strcpy(mbuf, mval);
+ mname = mbuf;
+ p = strchr(mbuf, ':');
+ if(p==NULL) {
+ LM_ERR("invalid format for argument: %s\n", mval);
+ return -1;
+ }
+ *p = '\0';
+ p++;
+ mparam = p;
+ p = strchr(p, ':');
+ if(p==NULL) {
+ LM_ERR("invalid format for argument: %s\n", mval);
+ return -1;
+ }
+ *p = '\0';
+ p++;
+ if(*p=='i' || *p=='I') {
+ ptype = PARAM_INT;
+ } else if(*p=='s' || *p=='S') {
+ ptype = PARAM_STRING;
+ } else {
+ LM_ERR("invalid format for argument: %s\n", mval);
+ return -1;
+ }
+ p++;
+ if(*p!=':') {
+ LM_ERR("invalid format for argument: %s\n", mval);
+ return -1;
+ }
+ p++;
+ sval = p;
+
+ if(ptype == PARAM_STRING) {
+ return set_mod_param_regex(mname, mparam, PARAM_STRING, sval);
+ } else {
+ if(strlen(sval) <= 0) {
+ LM_ERR("invalid format for argument: %s\n", mval);
+ return -1;
+ }
+ strz2sint(sval, &ival);
+ return set_mod_param_regex(mname, mparam, PARAM_INT, (void*)(long)ival);
+ }
+}
diff --git a/src/core/modparam.h b/src/core/modparam.h
index 91c6867d59..0a4241ad4a 100644
--- a/src/core/modparam.h
+++ b/src/core/modparam.h
@@ -34,4 +34,6 @@ int set_mod_param(char* _mod, char* _name, modparam_t _type, void*
_val);
int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val);
+int set_mod_param_serialized(char* mval);
+
#endif
diff --git a/src/main.c b/src/main.c
index 31af3d2cef..0bc2e650dc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -78,6 +78,7 @@
#include "core/mem/shm_mem.h"
#include "core/shm_init.h"
#include "core/sr_module.h"
+#include "core/modparam.h"
#include "core/timer.h"
#include "core/parser/msg_parser.h"
#include "core/ip_addr.h"
@@ -196,6 +197,9 @@ Options:\n\
--loadmodule=name load the module specified by name\n\
-L path Modules search path (default: " MODS_DIR ")\n\
-m nr Size of shared memory allocated in Megabytes\n\
+ --modparam=modname:paramname:type:value set the module parameter\n\
+ type has to be 's' for string value and 'i' for int
value, \n\
+ example: --modparam=corex:alias_subdomains:s:" NAME ".org\n\
-M nr Size of private memory allocated, in Megabytes\n\
-n processes Number of child processes to fork per interface\n\
(default: 8)\n"
@@ -1924,6 +1928,7 @@ int main(int argc, char** argv)
{"substdefs", required_argument, 0, KARGOPTVAL + 3},
{"server-id", required_argument, 0, KARGOPTVAL + 4},
{"loadmodule", required_argument, 0, KARGOPTVAL + 5},
+ {"modparam", required_argument, 0, KARGOPTVAL + 6},
{0, 0, 0, 0 }
};
@@ -2140,6 +2145,7 @@ int main(int argc, char** argv)
case 's':
case 'Y':
case KARGOPTVAL+5:
+ case KARGOPTVAL+6:
break;
/* long options */
@@ -2239,6 +2245,12 @@ int main(int argc, char** argv)
goto error;
}
break;
+ case KARGOPTVAL+6:
+ if(set_mod_param_serialized(optarg) < 0) {
+ LM_ERR("failed to set modparam: %s\n", optarg);
+ goto error;
+ }
+ break;
default:
break;
}