Module: kamailio
Branch: master
Commit: 684ae26119e3921c6e7b39556339b4f1d77f7d36
URL:
https://github.com/kamailio/kamailio/commit/684ae26119e3921c6e7b39556339b4f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-04-10T12:28:53+02:00
corex: added set_source_address() function
---
Modified: src/modules/corex/corex_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/684ae26119e3921c6e7b39556339b4f…
Patch:
https://github.com/kamailio/kamailio/commit/684ae26119e3921c6e7b39556339b4f…
---
diff --git a/src/modules/corex/corex_mod.c b/src/modules/corex/corex_mod.c
index 9781115783..c78ba1bb22 100644
--- a/src/modules/corex/corex_mod.c
+++ b/src/modules/corex/corex_mod.c
@@ -25,6 +25,8 @@
#include "../../core/sr_module.h"
#include "../../core/dprint.h"
#include "../../core/ut.h"
+#include "../../core/socket_info.h"
+#include "../../core/resolve.h"
#include "../../core/lvalue.h"
#include "../../core/pvar.h"
#include "../../core/kemi.h"
@@ -51,6 +53,7 @@ static int w_resetxflag(struct sip_msg *msg, char *flag, str *s2);
static int w_setxflag(struct sip_msg *msg, char *flag, char *s2);
static int w_set_send_socket(sip_msg_t *msg, char *psock, char *p2);
static int w_set_recv_socket(sip_msg_t *msg, char *psock, char *p2);
+static int w_set_source_address(sip_msg_t *msg, char *paddr, char *p2);
static int fixup_file_op(void** param, int param_no);
@@ -106,6 +109,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE },
{"set_recv_socket", (cmd_function)w_set_recv_socket, 1, fixup_spve_null,
0, ANY_ROUTE },
+ {"set_source_address", (cmd_function)w_set_source_address, 1,
fixup_spve_null,
+ 0, ANY_ROUTE },
{0, 0, 0, 0, 0, 0}
};
@@ -635,6 +640,53 @@ static int w_set_recv_socket(sip_msg_t *msg, char *psock, char *p2)
return ki_set_recv_socket(msg, &ssock);
}
+/**
+ *
+ */
+static int ki_set_source_address(sip_msg_t *msg, str *saddr)
+{
+ sr_phostp_t rp;
+ union sockaddr_union faddr;
+ char cproto;
+ int ret;
+
+ if(msg==NULL || saddr==NULL || saddr->len<=0) {
+ LM_ERR("bad parameters\n");
+ return -1;
+ }
+
+ if(parse_protohostport(saddr, &rp)<0) {
+ LM_ERR("failed to parse the address [%.*s]\n", saddr->len, saddr->s);
+ return -1;
+ }
+
+ cproto = (char)rp.proto;
+ ret = sip_hostport2su(&faddr, &rp.host, (unsigned short)rp.port, &cproto);
+ if(ret!=0) {
+ LM_ERR("failed to resolve address [%.*s]\n", saddr->len, saddr->s);
+ return -1;
+ }
+
+ msg->rcv.src_su=faddr;
+ su2ip_addr(&msg->rcv.src_ip, &faddr);
+ msg->rcv.src_port=rp.port;
+
+ return 1;
+}
+
+/**
+ *
+ */
+static int w_set_source_address(sip_msg_t *msg, char *paddr, char *p2)
+{
+ str saddr;
+ if (fixup_get_svalue(msg, (gparam_t*)paddr, &saddr) != 0 || saddr.len<=0) {
+ LM_ERR("cannot get source address value\n");
+ return -1;
+ }
+ return ki_set_source_address(msg, &saddr);
+}
+
/**
*
*/
@@ -680,6 +732,11 @@ static sr_kemi_t sr_kemi_corex_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("corex"), str_init("set_source_address"),
+ SR_KEMIP_INT, ki_set_source_address,
+ { 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 } }
};