[sr-dev] git:master: Move assert_identity to ims_usrloc_pcscf as we may have more than one IMPI per Port /IP/Proto

Carsten Bock carsten at ng-voice.com
Thu Sep 26 20:23:09 CEST 2013


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

Author: Carsten Bock <carsten at ng-voice.com>
Committer: Carsten Bock <carsten at ng-voice.com>
Date:   Thu Sep 26 20:21:11 2013 +0200

Move assert_identity to ims_usrloc_pcscf as we may have more than one IMPI per Port/IP/Proto

---

 modules/ims_registrar_pcscf/service_routes.c |   42 ++++-----------------
 modules/ims_usrloc_pcscf/udomain.c           |   50 +++++++++++++++++++++++---
 modules/ims_usrloc_pcscf/udomain.h           |    1 +
 modules/ims_usrloc_pcscf/usrloc.c            |    1 +
 modules/ims_usrloc_pcscf/usrloc.h            |    3 ++
 5 files changed, 58 insertions(+), 39 deletions(-)

diff --git a/modules/ims_registrar_pcscf/service_routes.c b/modules/ims_registrar_pcscf/service_routes.c
index e53cdd0..42590b5 100644
--- a/modules/ims_registrar_pcscf/service_routes.c
+++ b/modules/ims_registrar_pcscf/service_routes.c
@@ -390,40 +390,14 @@ str * get_asserted_identity(struct sip_msg* _m) {
  * Add proper asserted identies based on registration
  */
 int assert_identity(struct sip_msg* _m, udomain_t* _d, str identity) {
-	// Get the contact:
-	pcontact_t * c = getContactP(_m, _d);
-	// Public identities of this contact
-	ppublic_t * p;
-	
-	// Contact not found => Identity not asserted.
-	if (c == NULL) return -2;
-
-	/* Lock this record while working with the data: */
-	ul.lock_udomain(_d, &c->aor);
-
-	LM_DBG("Checking identity: %.*s\n", identity.len, identity.s);
-
-	LM_DBG("AOR of contact: %.*s\n", c->aor.len, c->aor.s);
-
-	for (p = c->head; p; p = p->next) {
-		LM_DBG("Public identity: %.*s\n", p->public_identity.len, p->public_identity.s);
-		/* Check length: */
-		if (identity.len == p->public_identity.len) {
-			/* Check contents: */
-			if (strncasecmp(identity.s, p->public_identity.s, identity.len) == 0) {
-				LM_DBG("Match!\n");
-				goto success;
-			}
-		} else LM_DBG("Length does not match.\n");
-	}
+	str received_host = {0, 0};
+	char srcip[50];	
 
-	// We should only get here, if we failed:
-	/* Unlock domain */
-	ul.unlock_udomain(_d, &c->aor);
-	return -1;
-success:
-	/* Unlock domain */
-	ul.unlock_udomain(_d, &c->aor);
-	return 1;
+	received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
+	received_host.s = srcip;
+	if (ul.assert_identity(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &identity) == 0)
+		return -1;
+	else
+		return 1;
 }
 
diff --git a/modules/ims_usrloc_pcscf/udomain.c b/modules/ims_usrloc_pcscf/udomain.c
index 8c0d370..3d2d46c 100644
--- a/modules/ims_usrloc_pcscf/udomain.c
+++ b/modules/ims_usrloc_pcscf/udomain.c
@@ -433,12 +433,43 @@ int get_pcontact_by_src(udomain_t* _d, str * _host, unsigned short _port, unsign
 	int i;
 	struct pcontact* c;
 
-	if (_d->table) {
-		for(i = 0; i < _d->size; i++) {
+	for(i=0; i<_d->size; i++)
+	{
+		c = _d->table[i].first;
+		while(c) {
+			LM_DBG("Port %d (search %d), Proto %d (search %d), reg_state %s (search %s)\n",
+				c->received_port, _port, c->received_proto, _proto, 
+				reg_state_to_string(c->reg_state), reg_state_to_string(PCONTACT_REGISTERED)
+				);
+			// First check, if Proto and Port matches:
+			if ((c->reg_state == PCONTACT_REGISTERED) && (c->received_port == _port) && (c->received_proto == _proto)) {
+				LM_DBG("Received host len %d (search %d)\n", c->received_host.len, _host->len);
+				// Then check the length:
+				if (c->received_host.len == _host->len) {
+					LM_DBG("Received host %.*s (search %.*s)\n",
+						c->received_host.len, c->received_host.s,
+						_host->len, _host->s);
+
+					// Finally really compare the "received_host"
+					if (!memcmp(c->received_host.s, _host->s, _host->len)) {
+						*_c = c;
+						return 0;
+					}
+				}
+			}
+			c = c->next;
 		}
 	}
+	return 1; /* Nothing found */
+}
 
 
+int assert_identity(udomain_t* _d, str * _host, unsigned short _port, unsigned short _proto, str * _identity) {
+	int i;
+	struct pcontact* c;
+	// Public identities of this contact
+	struct ppublic * p;
+
 	for(i=0; i<_d->size; i++)
 	{
 		c = _d->table[i].first;
@@ -458,15 +489,24 @@ int get_pcontact_by_src(udomain_t* _d, str * _host, unsigned short _port, unsign
 
 					// Finally really compare the "received_host"
 					if (!memcmp(c->received_host.s, _host->s, _host->len)) {
-						*_c = c;
-						return 0;
+						for (p = c->head; p; p = p->next) {
+							LM_DBG("Public identity: %.*s\n", p->public_identity.len, p->public_identity.s);
+							/* Check length: */
+							if (_identity->len == p->public_identity.len) {
+								/* Check contents: */
+								if (strncasecmp(_identity->s, p->public_identity.s, _identity->len) == 0) {
+									LM_DBG("Match!\n");
+									return 1;
+								}
+							} else LM_DBG("Length does not match.\n");
+						}
 					}
 				}
 			}
 			c = c->next;
 		}
 	}
-	return 1; /* Nothing found */
+	return 0; /* Nothing found */
 }
 
 int delete_pcontact(udomain_t* _d, str* _aor, struct pcontact* _c)
diff --git a/modules/ims_usrloc_pcscf/udomain.h b/modules/ims_usrloc_pcscf/udomain.h
index f2c74c6..23e4d58 100644
--- a/modules/ims_usrloc_pcscf/udomain.h
+++ b/modules/ims_usrloc_pcscf/udomain.h
@@ -78,6 +78,7 @@ int update_pcontact(struct udomain* _d, struct pcontact_info* _ci, struct pconta
 int insert_pcontact(struct udomain* _d, str* _contact, struct pcontact_info* _ci, struct pcontact** _r);
 int get_pcontact(udomain_t* _d, str* _aor, struct pcontact** _r);
 int get_pcontact_by_src(udomain_t* _d, str * _host, unsigned short _port, unsigned short _proto, struct pcontact** _c);
+int assert_identity(udomain_t* _d, str * _host, unsigned short _port, unsigned short _proto, str * _identity);
 int delete_pcontact(udomain_t* _d, str* _aor, struct pcontact* _r);
 
 #endif
diff --git a/modules/ims_usrloc_pcscf/usrloc.c b/modules/ims_usrloc_pcscf/usrloc.c
index 3a444b4..5d483b5 100644
--- a/modules/ims_usrloc_pcscf/usrloc.c
+++ b/modules/ims_usrloc_pcscf/usrloc.c
@@ -72,6 +72,7 @@ int bind_usrloc(usrloc_api_t* api) {
 	api->delete_pcontact = delete_pcontact;
 	api->get_pcontact = get_pcontact;
 	api->get_pcontact_by_src = get_pcontact_by_src;
+	api->assert_identity = assert_identity;
 
 	api->update_pcontact = update_pcontact;
 	api->update_rx_regsession = update_rx_regsession;
diff --git a/modules/ims_usrloc_pcscf/usrloc.h b/modules/ims_usrloc_pcscf/usrloc.h
index 38d4a2e..28724af 100644
--- a/modules/ims_usrloc_pcscf/usrloc.h
+++ b/modules/ims_usrloc_pcscf/usrloc.h
@@ -195,6 +195,8 @@ typedef int (*get_pcontact_t)(struct udomain* _d, str* _contact, struct pcontact
 
 typedef int (*get_pcontact_by_src_t)(struct udomain* _d, str * _host, unsigned short _port, unsigned short _proto, struct pcontact** _c);
 
+typedef int (*assert_identity_t)(struct udomain* _d, str * _host, unsigned short _port, unsigned short _proto, str * _identity);
+
 typedef int (*insert_pcontact_t)(struct udomain* _d, str* _aor, struct pcontact_info* ci, struct pcontact** _c);
 typedef int (*delete_pcontact_t)(struct udomain* _d, str* _aor, struct pcontact* _c);
 typedef int (*update_pcontact_t)(struct udomain* _d, struct pcontact_info* ci, struct pcontact* _c);
@@ -220,6 +222,7 @@ typedef struct usrloc_api {
 	delete_pcontact_t delete_pcontact;
 	get_pcontact_t get_pcontact;
 	get_pcontact_by_src_t get_pcontact_by_src;
+	assert_identity_t assert_identity;
 
 	update_pcontact_t update_pcontact;
 	update_rx_regsession_t update_rx_regsession;




More information about the sr-dev mailing list