Module: sip-router
Branch: master
Commit: d6b98639bd6f11661d61060c58597d53b01dadd0
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d6b9863…
Author: Jason Penton <jason.penton(a)gmail.com>
Committer: Jason Penton <jason.penton(a)gmail.com>
Date: Fri Aug 8 08:33:56 2014 +0200
lib/ims: When getting IMPI, only check check realm credentials if a realm is passed in
---
lib/ims/ims_getters.c | 66 ++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 57 insertions(+), 9 deletions(-)
diff --git a/lib/ims/ims_getters.c b/lib/ims/ims_getters.c
index 00151f7..1751641 100644
--- a/lib/ims/ims_getters.c
+++ b/lib/ims/ims_getters.c
@@ -122,23 +122,32 @@ str cscf_get_private_identity(struct sip_msg *msg, str realm)
{
str pi={0,0};
struct hdr_field* h=0;
- int ret,i;
+ int ret,i,res;
if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
return pi;
}
-
+
+ h = msg->authorization;
if (!msg->authorization){
goto fallback;
}
+
+ if (realm.len && realm.s) {
+ ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
+ if (ret < 0) {
+ goto fallback;
+ } else
+ if (ret > 0) {
+ goto fallback;
+ }
+ }
- ret = find_credentials(msg, &realm, HDR_AUTHORIZATION_F, &h);
- if (ret < 0) {
- goto fallback;
- } else
- if (ret > 0) {
- goto fallback;
- }
+ res = parse_credentials(h);
+ if (res != 0) {
+ LOG(L_ERR, "Error while parsing credentials\n");
+ return pi;
+ }
if (h) pi=((auth_body_t*)h->parsed)->digest.username.whole;
@@ -157,6 +166,45 @@ str cscf_get_private_identity(struct sip_msg *msg, str realm)
}
/**
+ * Returns the Private Identity extracted from the Authorization header.
+ * If none found there takes the SIP URI in To without the "sip:" prefix
+ * \todo - remove the fallback case to the To header
+ * @param msg - the SIP message
+ * @param realm - the realm to match in an Authorization header
+ * @returns the str containing the private id, no mem dup
+ */
+str cscf_get_private_identity_no_realm(struct sip_msg *msg, str realm)
+{
+ str pi={0,0};
+ struct hdr_field* h=0;
+ int ret,i;
+
+ if (parse_headers(msg,HDR_AUTHORIZATION_F,0)!=0) {
+ return pi;
+ }
+
+ if (!msg->authorization){
+ goto fallback;
+ }
+
+ h = msg->authorization;
+ if (h) pi=((auth_body_t*)h->parsed)->digest.username.whole;
+
+ goto done;
+
+ fallback:
+ pi = cscf_get_public_identity(msg);
+ if (pi.len>4&&strncasecmp(pi.s,"sip:",4)==0) {pi.s+=4;pi.len-=4;}
+ for(i=0;i<pi.len;i++)
+ if (pi.s[i]==';') {
+ pi.len=i;
+ break;
+ }
+ done:
+ return pi;
+}
+
+/**
* Returns the Public Identity extracted from the To header
* @param msg - the SIP message
* @returns the str containing the public id, no mem dup