[sr-dev] git:master: modules:ims_usrloc_scscf: add new contact match mode CONTACT_PORT_IP_ONLY

Richard Good richard.good at smilecoms.com
Thu Apr 3 15:25:25 CEST 2014


Module: sip-router
Branch: master
Commit: afb7ae6b66b077225687c4529150b9ce053b0b8c
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=afb7ae6b66b077225687c4529150b9ce053b0b8c

Author: Richard Good <richard.good at smilecoms.com>
Committer: Richard Good <richard.good at smilecoms.com>
Date:   Thu Apr  3 15:23:49 2014 +0200

modules:ims_usrloc_scscf: add new contact match mode CONTACT_PORT_IP_ONLY
	new match mode CONTACT_PORT_IP_ONLY allows to match contact based
	only on port and IP - ignoring user part
	Useful as some IMS clients use contact as IMPI at IP:PORT and others use E164 at IP:PORT

---

 modules/ims_usrloc_scscf/impurecord.c |   53 +++++++++++++++++++++++++++++++++
 modules/ims_usrloc_scscf/ul_mod.h     |    1 +
 2 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/modules/ims_usrloc_scscf/impurecord.c b/modules/ims_usrloc_scscf/impurecord.c
index 184c4a3..f4468ce 100644
--- a/modules/ims_usrloc_scscf/impurecord.c
+++ b/modules/ims_usrloc_scscf/impurecord.c
@@ -515,6 +515,35 @@ int delete_ucontact(impurecord_t* _r, struct ucontact* _c) {
     return ret;
 }
 
+
+/* function to convert contact aor to only have data after @ - ie strip user part */
+inline int aor_to_contact(str* aor, str* contact) {
+	char* p;
+	int ret = 0;	//success
+
+	contact->s = aor->s;
+	contact->len = aor->len;
+	if (memcmp(aor->s, "sip:", 4) == 0) {
+		contact->s = aor->s + 4;
+		contact->len-=4;
+	}
+
+	if ((p=memchr(contact->s, '@', contact->len))) {
+		contact->len -= (p - contact->s + 1);
+		contact->s = p+1;
+	}
+
+	if ((p=memchr(contact->s, ';', contact->len))) {
+		contact->len = p - contact->s;
+	}
+
+	if ((p=memchr(contact->s, '>', contact->len))) {
+		contact->len = p - contact->s;
+	}
+
+	return ret;
+}
+
 /*!
  * \brief Match a contact record to a contact string
  * \param ptr contact record
@@ -533,6 +562,27 @@ static inline struct ucontact* contact_match(ucontact_t* ptr, str* _c) {
 }
 
 /*!
+ * \brief Match a contact record to a contact string but only compare the ip port portion
+ * \param ptr contact record
+ * \param _c contact string
+ * \return ptr on successfull match, 0 when they not match
+ */
+static inline struct ucontact* contact_port_ip_match(ucontact_t* ptr, str* _c) {
+    str string_ip_port, contact_ip_port;
+    aor_to_contact(_c, &string_ip_port);//strip userpart from test contact
+
+    while (ptr) {
+	aor_to_contact(&ptr->c, &contact_ip_port);//strip userpart from contact
+	if ((string_ip_port.len == contact_ip_port.len) && !memcmp(string_ip_port.s, contact_ip_port.s, string_ip_port.len)) {
+            return ptr;
+        }
+
+        ptr = ptr->next;
+    }
+    return 0;
+}
+
+/*!
  * \brief Match a contact record to a contact string and callid
  * \param ptr contact record
  * \param _c contact string
@@ -609,6 +659,9 @@ int get_ucontact(impurecord_t* _r, str* _c, str* _callid, str* _path, int _cseq,
         case CONTACT_PATH:
             ptr = contact_path_match(_r->contacts, _c, _path);
             break;
+	case CONTACT_PORT_IP_ONLY:
+	    ptr = contact_port_ip_match(_r->contacts, _c);
+	    break;
         default:
             LM_CRIT("unknown matching_mode %d\n", matching_mode);
             return -1;
diff --git a/modules/ims_usrloc_scscf/ul_mod.h b/modules/ims_usrloc_scscf/ul_mod.h
index d14726e..a7e2203 100644
--- a/modules/ims_usrloc_scscf/ul_mod.h
+++ b/modules/ims_usrloc_scscf/ul_mod.h
@@ -91,6 +91,7 @@ extern extract_sdialog_info_t pres_extract_sdialog_info;
 #define CONTACT_ONLY            (0)
 #define CONTACT_CALLID          (1)
 #define CONTACT_PATH		(2)
+#define CONTACT_PORT_IP_ONLY    (3)
 
 extern int matching_mode;
 




More information about the sr-dev mailing list