[sr-dev] git:master: modules/ims_registrar_pcscf: Added new exported function pcscf_assert_called_identity

Richard Good richard.good at smilecoms.com
Tue Feb 11 07:52:55 CET 2014


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

Author: Richard Good <richard.good at smilecoms.com>
Committer: Richard Good <richard.good at smilecoms.com>
Date:   Tue Feb 11 08:49:44 2014 +0200

modules/ims_registrar_pcscf: Added new exported function pcscf_assert_called_identity
	pcscf_assert_called_identity function used to assert the identity for SIP responses
	Function retrieves Called-Party-ID AVP from SIP request and adds to SIP response as P-Asserted-Identity as per TS 24.229 section 5.2.6.4.4

---

 modules/ims_registrar_pcscf/reg_mod.c        |    8 ++-
 modules/ims_registrar_pcscf/save.h           |    1 +
 modules/ims_registrar_pcscf/service_routes.c |   85 ++++++++++++++++++++++---
 modules/ims_registrar_pcscf/service_routes.h |    5 ++
 4 files changed, 87 insertions(+), 12 deletions(-)

diff --git a/modules/ims_registrar_pcscf/reg_mod.c b/modules/ims_registrar_pcscf/reg_mod.c
index 7aa000f..ff622ff 100644
--- a/modules/ims_registrar_pcscf/reg_mod.c
+++ b/modules/ims_registrar_pcscf/reg_mod.c
@@ -104,6 +104,7 @@ static int w_is_registered(struct sip_msg* _m, char* _d, char* _foo);
 static int w_reginfo_handle_notify(struct sip_msg* _m, char* _d, char* _foo);
 
 static int w_assert_identity(struct sip_msg* _m, char* _d, char* _preferred_uri);
+static int w_assert_called_identity(struct sip_msg* _m, char* _d, char* _foo);
 
 /*! \brief Fixup functions */
 static int domain_fixup(void** param, int param_no);
@@ -131,9 +132,10 @@ static cmd_export_t cmds[] = {
 	{"pcscf_follows_service_routes", (cmd_function)w_follows_service_routes,       	1,  	save_fixup2, 	0,		REQUEST_ROUTE },
 	{"pcscf_force_service_routes", (cmd_function)w_force_service_routes,       	1,  	save_fixup2, 	0,		REQUEST_ROUTE },
 
-	{"pcscf_is_registered", (cmd_function)w_is_registered,       	1,  	save_fixup2, 	0,		REQUEST_ROUTE },
+	{"pcscf_is_registered", (cmd_function)w_is_registered,       	1,  	save_fixup2, 	0,		REQUEST_ROUTE|ONREPLY_ROUTE },
 
 	{"pcscf_assert_identity", (cmd_function)w_assert_identity,      2,  	assert_identity_fixup, 	0,		REQUEST_ROUTE },
+	{"pcscf_assert_called_identity", (cmd_function)w_assert_called_identity,      1,  	assert_identity_fixup, 	0,		ONREPLY_ROUTE },
 
 	{"reginfo_handle_notify", (cmd_function)w_reginfo_handle_notify, 1, domain_fixup, 0, REQUEST_ROUTE},
 	
@@ -416,6 +418,10 @@ static int w_assert_identity(struct sip_msg* _m, char* _d, char* _preferred_uri)
 	return assert_identity( _m, (udomain_t*)_d, identity);
 }
 
+static int w_assert_called_identity(struct sip_msg* _m, char* _d, char* _foo) {
+	return assert_called_identity( _m, (udomain_t*)_d);
+}
+
 /*
  * Get the asserted Identity for the current user
  */
diff --git a/modules/ims_registrar_pcscf/save.h b/modules/ims_registrar_pcscf/save.h
index f400145..d11d84b 100644
--- a/modules/ims_registrar_pcscf/save.h
+++ b/modules/ims_registrar_pcscf/save.h
@@ -56,6 +56,7 @@
 int save(struct sip_msg* _m, udomain_t* _d, int _cflags);
 int save_pending(struct sip_msg* _m, udomain_t* _d);
 int unregister(struct sip_msg* _m, char* _d, char* _uri);
+struct sip_msg* get_request_from_reply(struct sip_msg* reply);
 
 
 #endif /* SAVE_H */
diff --git a/modules/ims_registrar_pcscf/service_routes.c b/modules/ims_registrar_pcscf/service_routes.c
index 937d152..452548a 100644
--- a/modules/ims_registrar_pcscf/service_routes.c
+++ b/modules/ims_registrar_pcscf/service_routes.c
@@ -22,6 +22,7 @@
 
 #include "service_routes.h"
 #include "reg_mod.h"
+#include "save.h"
 #include "../../data_lump.h"
 #include "../../lib/ims/ims_getters.h"
 
@@ -418,25 +419,31 @@ str * get_asserted_identity(struct sip_msg* _m) {
 }
 
 /**
- * Add proper asserted identies based on registration
+ * checked if passed identity is an asserted identity
  */
 int assert_identity(struct sip_msg* _m, udomain_t* _d, str identity) {
 	// Public identities of this contact
 	struct ppublic * p;
-
+	//remove <> braces if there are
+	if(identity.s[0]=='<' && identity.s[identity.len-1]=='>') {
+		identity.s++;
+		identity.len -= 2;
+	}
+	LM_DBG("Identity to assert: %.*s\n", identity.len, identity.s);
+	
 	if (getContactP(_m, _d) != NULL) {
 		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");
+			    /* 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");
+			}
 		}
-	}
 	LM_WARN("Contact not found based on Contact, trying IP/Port/Proto\n");
 	str received_host = {0, 0};
 	char srcip[50];	
@@ -449,3 +456,59 @@ int assert_identity(struct sip_msg* _m, udomain_t* _d, str identity) {
 		return 1;
 }
 
+
+/**
+ * Add proper asserted identities based on registration
+ */
+
+static str p_asserted_identity_s={"P-Asserted-Identity: ",21};
+static str p_asserted_identity_m={"<",1};
+static str p_asserted_identity_e={">\r\n",3};
+
+int assert_called_identity(struct sip_msg* _m, udomain_t* _d) {
+	
+	int ret=CSCF_RETURN_FALSE;
+	str called_party_id={0,0},x={0,0};
+	struct sip_msg* req;
+	struct hdr_field *h=0;
+		
+	//get request from reply
+	req = get_request_from_reply(_m);
+	if (!req) {
+		LM_ERR("Unable to get request from reply for REGISTER. No transaction\n");
+		goto error;
+	}
+	
+	called_party_id = cscf_get_called_party_id(req, &h);
+	
+		
+	if (!called_party_id.len){
+		goto error;	
+	}else{
+		LM_DBG("Called Party ID from request: %.*s\n", called_party_id.len, called_party_id.s);	
+		x.len = p_asserted_identity_s.len+p_asserted_identity_m.len+called_party_id.len+p_asserted_identity_e.len;
+		x.s = pkg_malloc(x.len);
+		if (!x.s){
+			LM_ERR("P_assert_called_identity: Error allocating %d bytes\n",	x.len);
+			x.len=0;
+			goto error;		
+		}
+		x.len=0;
+		STR_APPEND(x,p_asserted_identity_s);
+		STR_APPEND(x,p_asserted_identity_m);
+		STR_APPEND(x,called_party_id);
+		STR_APPEND(x,p_asserted_identity_e);
+		
+		if (cscf_add_header(_m,&x,HDR_OTHER_T))
+			ret = CSCF_RETURN_TRUE;
+		else
+		    goto error;
+	}
+	
+	return ret;
+	
+error:
+	ret=CSCF_RETURN_FALSE;
+	return ret;
+}
+
diff --git a/modules/ims_registrar_pcscf/service_routes.h b/modules/ims_registrar_pcscf/service_routes.h
index dc7aef7..f9db932 100644
--- a/modules/ims_registrar_pcscf/service_routes.h
+++ b/modules/ims_registrar_pcscf/service_routes.h
@@ -51,4 +51,9 @@ str * get_asserted_identity(struct sip_msg* _m);
  */
 int assert_identity(struct sip_msg* _m, udomain_t* _d, str identity);
 
+/**
+ * Assert a given called identity of a user
+ */
+int assert_called_identity(struct sip_msg* _m, udomain_t* _d);
+
 #endif /* SERVICE_ROUTES_H */




More information about the sr-dev mailing list