Module: sip-router
Branch: master
Commit: f4c26ffb8e0aaf05def0adc64bdcf07e8173c984
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f4c26ff…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Jul 21 12:32:30 2014 +0200
corex: new function send_data(uri, data)
- send arbitrary formated data to uri
- uri param has to be a valid sip uri
- both parameters can include pseudo-variables
---
modules/corex/corex_lib.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
modules/corex/corex_lib.h | 1 +
modules/corex/corex_mod.c | 22 +++++++++++++
3 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/modules/corex/corex_lib.c b/modules/corex/corex_lib.c
index 23c9a8c..dcbe550 100644
--- a/modules/corex/corex_lib.c
+++ b/modules/corex/corex_lib.c
@@ -302,3 +302,78 @@ int corex_send(sip_msg_t *msg, gparam_t *pu, enum sip_protos proto)
error:
return ret;
}
+
+/**
+ *
+ */
+int corex_send_data(str *puri, str *pdata)
+{
+ struct dest_info dst;
+ sip_uri_t next_hop;
+ int ret = 0;
+ char proto;
+
+ if(parse_uri(puri->s, puri->len, &next_hop)<0)
+ {
+ LM_ERR("bad dst sip uri <%.*s>\n", puri->len, puri->s);
+ return -1;
+ }
+
+ init_dest_info(&dst);
+ LM_DBG("sending data to sip uri <%.*s>\n", puri->len, puri->s);
+ proto = next_hop.proto;
+ if(sip_hostport2su(&dst.to, &next_hop.host, next_hop.port_no,
+ &proto)!=0) {
+ LM_ERR("failed to resolve [%.*s]\n", next_hop.host.len,
+ ZSW(next_hop.host.s));
+ return -1;
+ }
+ dst.proto = proto;
+ if(dst.proto==PROTO_NONE) dst.proto = PROTO_UDP;
+
+ if (dst.proto == PROTO_UDP)
+ {
+ dst.send_sock=get_send_socket(0, &dst.to, PROTO_UDP);
+ if (dst.send_sock!=0) {
+ ret=udp_send(&dst, pdata->s, pdata->len);
+ } else {
+ LM_ERR("no socket for dst sip uri <%.*s>\n", puri->len,
puri->s);
+ ret=-1;
+ }
+ }
+#ifdef USE_TCP
+ else if(dst.proto == PROTO_TCP) {
+ /*tcp*/
+ dst.id=0;
+ ret=tcp_send(&dst, 0, pdata->s, pdata->len);
+ }
+#endif
+#ifdef USE_TLS
+ else if(dst.proto == PROTO_TLS) {
+ /*tls*/
+ dst.id=0;
+ ret=tcp_send(&dst, 0, pdata->s, pdata->len);
+ }
+#endif
+#ifdef USE_SCTP
+ else if(dst.proto == PROTO_SCTP) {
+ /*sctp*/
+ dst.send_sock=get_send_socket(0, &dst.to, PROTO_SCTP);
+ if (dst.send_sock!=0) {
+ ret=sctp_core_msg_send(&dst, pdata->s, pdata->len);
+ } else {
+ LM_ERR("no socket for dst sip uri <%.*s>\n", puri->len,
puri->s);
+ ret=-1;
+ }
+ }
+#endif
+ else {
+ LM_ERR("unknown proto [%d] for dst sip uri <%.*s>\n",
+ dst.proto, puri->len, puri->s);
+ ret=-1;
+ }
+
+ if (ret>=0) ret=1;
+
+ return ret;
+}
diff --git a/modules/corex/corex_lib.h b/modules/corex/corex_lib.h
index 433e28a..5f2f872 100644
--- a/modules/corex/corex_lib.h
+++ b/modules/corex/corex_lib.h
@@ -26,6 +26,7 @@
int corex_append_branch(sip_msg_t *msg, gparam_t *pu, gparam_t *pq);
int corex_send(sip_msg_t *msg, gparam_t *pu, enum sip_protos proto);
+int corex_send_data(str *puri, str *pdata);
int corex_add_alias_subdomains(char* aliasval);
diff --git a/modules/corex/corex_mod.c b/modules/corex/corex_mod.c
index 8d62498..5cd4aec 100644
--- a/modules/corex/corex_mod.c
+++ b/modules/corex/corex_mod.c
@@ -37,6 +37,7 @@ MODULE_VERSION
static int w_append_branch(sip_msg_t *msg, char *su, char *sq);
static int w_send(sip_msg_t *msg, char *su, char *sq);
static int w_send_tcp(sip_msg_t *msg, char *su, char *sq);
+static int w_send_data(sip_msg_t *msg, char *suri, char *sdata);
int corex_alias_subdomains_param(modparam_t type, void *val);
@@ -66,6 +67,8 @@ static cmd_export_t cmds[]={
0, REQUEST_ROUTE | FAILURE_ROUTE },
{"send_tcp", (cmd_function)w_send_tcp, 1, fixup_spve_null,
0, REQUEST_ROUTE | FAILURE_ROUTE },
+ {"send_data", (cmd_function)w_send_data, 2, fixup_spve_spve,
+ 0, ANY_ROUTE },
{0, 0, 0, 0, 0, 0}
@@ -157,6 +160,25 @@ static int w_send_tcp(sip_msg_t *msg, char *su, char *sq)
return 1;
}
+static int w_send_data(sip_msg_t *msg, char *suri, char *sdata)
+{
+ str uri;
+ str data;
+
+ if (fixup_get_svalue(msg, (gparam_t*)suri, &uri))
+ {
+ LM_ERR("cannot get the destination parameter\n");
+ return -1;
+ }
+ if (fixup_get_svalue(msg, (gparam_t*)sdata, &data))
+ {
+ LM_ERR("cannot get the destination parameter\n");
+ return -1;
+ }
+ if(corex_send_data(&uri, &data) < 0)
+ return -1;
+ return 1;
+}
int corex_alias_subdomains_param(modparam_t type, void *val)
{