Module: kamailio
Branch: master
Commit: 1984d4a063a175803b2852c14dcadd8839b4ad83
URL:
https://github.com/kamailio/kamailio/commit/1984d4a063a175803b2852c14dcadd8…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-06-27T15:53:49+02:00
core: parser - helper function to return URI format for local rcv socket
---
Modified: src/core/parser/msg_parser.c
Modified: src/core/parser/msg_parser.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1984d4a063a175803b2852c14dcadd8…
Patch:
https://github.com/kamailio/kamailio/commit/1984d4a063a175803b2852c14dcadd8…
---
diff --git a/src/core/parser/msg_parser.c b/src/core/parser/msg_parser.c
index 2a4f2bb593..84a7ba6ff5 100644
--- a/src/core/parser/msg_parser.c
+++ b/src/core/parser/msg_parser.c
@@ -1102,6 +1102,91 @@ int get_src_uri(sip_msg_t *m, int tmode, str *uri)
return 0;
}
+/**
+ * get received-on-socket ip, port and protocol in SIP URI format
+ * - tmode - 0: short format (transport=udp is not added, being default)
+ */
+int get_rcv_socket_uri(sip_msg_t *m, int tmode, str *uri)
+{
+ static char buf[MAX_URI_SIZE];
+ char* p;
+ str ip, port;
+ int len;
+ str proto;
+
+ if (!uri || !m || !m->rcv.bind_address) {
+ ERR("invalid parameter value\n");
+ return -1;
+ }
+
+ if(tmode==0) {
+ switch(m->rcv.proto) {
+ case PROTO_NONE:
+ case PROTO_UDP:
+ proto.s = 0; /* Do not add transport parameter, UDP is default */
+ proto.len = 0;
+ break;
+ default:
+ if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
+ ERR("unknown transport protocol\n");
+ return -1;
+ }
+ }
+ } else {
+ if(get_valid_proto_string(m->rcv.proto, 1, 0, &proto)<0) {
+ ERR("unknown transport protocol\n");
+ return -1;
+ }
+ }
+
+ ip.s = m->rcv.bind_address->address_str.s;
+ ip.len = m->rcv.bind_address->address_str.len;
+
+ port.s = m->rcv.bind_address->port_no_str.s;
+ port.len = m->rcv.bind_address->port_no_str.len;
+
+ len = 4 + ip.len + 2*(m->rcv.src_ip.af==AF_INET6)+ 1 + port.len;
+ if (proto.s) {
+ len += TRANSPORT_PARAM_LEN;
+ len += proto.len;
+ }
+
+ if (len > MAX_URI_SIZE) {
+ ERR("buffer too small\n");
+ return -1;
+ }
+
+ p = buf;
+ memcpy(p, "sip:", 4);
+ p += 4;
+
+ if (m->rcv.src_ip.af==AF_INET6)
+ *p++ = '[';
+ memcpy(p, ip.s, ip.len);
+ p += ip.len;
+ if (m->rcv.src_ip.af==AF_INET6)
+ *p++ = ']';
+
+ *p++ = ':';
+
+ memcpy(p, port.s, port.len);
+ p += port.len;
+
+ if (proto.s) {
+ memcpy(p, TRANSPORT_PARAM, TRANSPORT_PARAM_LEN);
+ p += TRANSPORT_PARAM_LEN;
+
+ memcpy(p, proto.s, proto.len);
+ p += proto.len;
+ }
+
+ uri->s = buf;
+ uri->len = len;
+
+ return 0;
+}
+
+
/*! \brief returns a pointer to the begining of the msg's body
*/
char* get_body(sip_msg_t* const msg)
diff --git a/src/core/parser/msg_parser.h b/src/core/parser/msg_parser.h
index 13a30d1570..dd5f498a12 100644
--- a/src/core/parser/msg_parser.h
+++ b/src/core/parser/msg_parser.h
@@ -498,4 +498,9 @@ void msg_ldata_reset(sip_msg_t*);
*/
int get_src_uri(sip_msg_t *m, int tmode, str *uri);
+/**
+ * get received-on-socket ip, port and protocol in SIP URI format
+ */
+int get_rcv_socket_uri(sip_msg_t *m, int tmode, str *uri);
+
#endif