Module: kamailio Branch: master Commit: 85a4047f80c8b79db7d93dd704224eb3c608c97d URL: https://github.com/kamailio/kamailio/commit/85a4047f80c8b79db7d93dd704224eb3...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2019-01-27T10:50:20+01:00
exec: added exec_cmd("...") function
- execute the command without setting any env variables - lightweight version for exec_msg()
---
Modified: src/modules/exec/exec_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/85a4047f80c8b79db7d93dd704224eb3... Patch: https://github.com/kamailio/kamailio/commit/85a4047f80c8b79db7d93dd704224eb3...
---
diff --git a/src/modules/exec/exec_mod.c b/src/modules/exec/exec_mod.c index a9410ee844..f0e1b986a9 100644 --- a/src/modules/exec/exec_mod.c +++ b/src/modules/exec/exec_mod.c @@ -53,6 +53,7 @@ static int mod_init(void); static int w_exec_dset(struct sip_msg *msg, char *cmd, char *foo); static int w_exec_msg(struct sip_msg *msg, char *cmd, char *foo); static int w_exec_avp(struct sip_msg *msg, char *cmd, char *avpl); +static int w_exec_cmd(struct sip_msg *msg, char *cmd, char *foo);
static int exec_avp_fixup(void **param, int param_no);
@@ -69,8 +70,10 @@ static cmd_export_t cmds[] = { REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE}, {"exec_avp", (cmd_function)w_exec_avp, 1, fixup_spve_null, 0, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE}, - {"exec_avp", (cmd_function)w_exec_avp, 2, exec_avp_fixup, 0, + {"exec_avp", (cmd_function)w_exec_avp, 2, exec_avp_fixup, 0, REQUEST_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE}, + {"exec_cmd", (cmd_function)w_exec_cmd, 1, fixup_spve_null, 0, + ANY_ROUTE}, {0, 0, 0, 0, 0, 0} };
@@ -265,6 +268,34 @@ static int exec_avp_fixup(void **param, int param_no) return 0; }
+static int ki_exec_cmd(sip_msg_t *msg, str *cmd) +{ + int ret; + + if(cmd == 0 || cmd->s == 0) + return -1; + + LM_DBG("executing [%s]\n", cmd->s); + + ret = exec_msg(msg, cmd->s); + + LM_DBG("execution return code: %d\n", ret); + + return (ret == 0) ? 1 : ret; +} + +static int w_exec_cmd(struct sip_msg *msg, char *cmd, char *foo) +{ + str command; + + if(fixup_get_svalue(msg, (gparam_p)cmd, &command) != 0) { + LM_ERR("invalid command parameter"); + return -1; + } + return ki_exec_cmd(msg, &command); +} + + /** * */ @@ -285,6 +316,11 @@ static sr_kemi_t sr_kemi_exec_exports[] = { { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("exec"), str_init("exec_cmd"), + SR_KEMIP_INT, ki_exec_cmd, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } };