Browse code

modules/ims_auth: use IMS lib for getting IMPI/IMPUs (cleanup)

Jason Penton authored on 08/08/2014 06:34:48
Showing 4 changed files
... ...
@@ -329,14 +329,14 @@ int challenge(struct sip_msg* msg, char* str1, char* str2, int is_proxy_auth, ch
329 329
     }
330 330
 
331 331
     /* get the private_identity */
332
-    private_identity = get_private_identity(msg, realm, is_proxy_auth);
332
+    private_identity = cscf_get_private_identity(msg, realm);
333 333
     if (!private_identity.len) {
334 334
         LM_ERR("No private identity specified (Authorization: username)\n");
335 335
         stateful_request_reply(msg, 403, MSG_403_NO_PRIVATE);
336 336
         return CSCF_RETURN_BREAK;
337 337
     }
338 338
     /* get the public_identity */
339
-    public_identity = get_public_identity(msg);
339
+    public_identity = cscf_get_public_identity(msg);
340 340
     if (!public_identity.len) {
341 341
         LM_ERR("No public identity specified (To:)\n");
342 342
         stateful_request_reply(msg, 403, MSG_403_NO_PUBLIC);
... ...
@@ -517,14 +517,14 @@ int www_resync_auth(struct sip_msg* msg, char* _route, char* str1, char* str2) {
517 517
     }
518 518
 
519 519
     /* get the private_identity */
520
-    private_identity = get_private_identity(msg, realm, is_proxy_auth);
520
+    private_identity = cscf_get_private_identity(msg, realm);
521 521
     if (!private_identity.len) {
522 522
         LM_ERR("No private identity specified (Authorization: username)\n");
523 523
         stateful_request_reply(msg, 403, MSG_403_NO_PRIVATE);
524 524
         return CSCF_RETURN_BREAK;
525 525
     }
526 526
     /* get the public_identity */
527
-    public_identity = get_public_identity(msg);
527
+    public_identity = cscf_get_public_identity(msg);
528 528
     if (!public_identity.len) {
529 529
         LM_ERR("No public identity specified (To:)\n");
530 530
         stateful_request_reply(msg, 403, MSG_403_NO_PUBLIC);
... ...
@@ -743,13 +743,13 @@ int authenticate(struct sip_msg* msg, char* _realm, char* str2, int is_proxy_aut
743 743
         return 0; //CSCF_RETURN_BREAK;
744 744
     }
745 745
 
746
-    private_identity = get_private_identity(msg, realm, is_proxy_auth);
746
+    private_identity = cscf_get_private_identity(msg, realm);
747 747
     if (!private_identity.len) {
748 748
         LM_ERR("private identity missing\n");
749 749
         return AUTH_NO_CREDENTIALS;
750 750
     }
751 751
 
752
-    public_identity = get_public_identity(msg);
752
+    public_identity = cscf_get_public_identity(msg);
753 753
     if (!public_identity.len) {
754 754
         LM_ERR("public identity missing\n");
755 755
         return AUTH_NO_CREDENTIALS;
... ...
@@ -138,7 +138,7 @@ void async_cdp_callback(int is_timeout, void *param, AAAMessage *maa, long elaps
138 138
     }
139 139
 
140 140
     /* get the private_identity */
141
-    private_identity = get_private_identity(t->uas.request, data->realm, data->is_proxy_auth);
141
+    private_identity = cscf_get_private_identity(t->uas.request, data->realm);
142 142
     if (!private_identity.len) {
143 143
         LM_ERR("No private identity specified (Authorization: username)\n");
144 144
         stateful_request_reply_async(t, t->uas.request, 403, MSG_403_NO_PRIVATE);
... ...
@@ -146,7 +146,7 @@ void async_cdp_callback(int is_timeout, void *param, AAAMessage *maa, long elaps
146 146
         goto error;
147 147
     }
148 148
     /* get the public_identity */
149
-    public_identity = get_public_identity(t->uas.request);
149
+    public_identity = cscf_get_public_identity(t->uas.request);
150 150
     if (!public_identity.len) {
151 151
         LM_ERR("No public identity specified (To:)\n");
152 152
         stateful_request_reply_async(t, t->uas.request, 403, MSG_403_NO_PUBLIC);
... ...
@@ -141,90 +141,6 @@ inline int ims_find_credentials(struct sip_msg* _m, str* _realm,
141 141
 	return 1;
142 142
 }
143 143
 
144
-
145
-/**
146
- * Returns the Private Identity extracted from the Authorization header.
147
- * If none found there takes the SIP URI in To without the "sip:" prefix
148
- * \todo - remove the fallback case to the To header
149
- * @param msg - the SIP message
150
- * @param realm - the realm to match in an Authorization header
151
- * @param is_proxy_auth 0 if the header is Authorization, anything else for Proxy-Authorization
152
- * @returns the str containing the private id, no mem dup
153
- */
154
-str get_private_identity(struct sip_msg *msg, str realm, int is_proxy_auth)
155
-{
156
-	str pi={0,0};
157
-	struct hdr_field* h=0;
158
-	int ret,i;
159
-
160
-	if (parse_headers(msg, is_proxy_auth ? HDR_PROXYAUTH_F : HDR_AUTHORIZATION_F,0)!=0) {
161
-		return pi;
162
-	}
163
-
164
-	if (!(is_proxy_auth ? msg->proxy_auth : msg->authorization)){
165
-		goto fallback;
166
-	}
167
-
168
-	ret = find_credentials(msg, &realm, is_proxy_auth ? HDR_PROXYAUTH_F : HDR_AUTHORIZATION_F, &h);
169
-	if (ret < 0) {
170
-		goto fallback;
171
-	} else 
172
-		if (ret > 0) {
173
-			goto fallback;
174
-		}
175
-	
176
-	if (h) pi=((auth_body_t*)h->parsed)->digest.username.whole;
177
-
178
-	goto done;
179
-		
180
-fallback:
181
-	pi = get_public_identity(msg);
182
-	if (pi.len>4&&strncasecmp(pi.s,"sip:",4)==0) {pi.s+=4;pi.len-=4;}
183
-	for(i=0;i<pi.len;i++)
184
-		if (pi.s[i]==';') {
185
-			pi.len=i;
186
-			break;
187
-		}
188
-done:	
189
-	return pi;	
190
-}
191
-
192
-/**
193
- * Returns the Public Identity extracted from the From header
194
- * @param msg - the SIP message
195
- * @returns the str containing the public id, no mem dup
196
- */
197
-str get_public_identity(struct sip_msg *msg)
198
-{
199
-	str pu={0,0};
200
-	struct to_body *from;
201
-	int i;
202
-	
203
-	if (parse_headers(msg,HDR_TO_F,0)!=0) {
204
-		return pu;
205
-	}
206
-	
207
-	if ( get_from(msg) == NULL ) {
208
-		from = (struct to_body*) pkg_malloc(sizeof(struct to_body));
209
-		if (!from) {
210
-			LM_ERR("out of pkg memory\n");
211
-			return pu;
212
-		}
213
-		parse_to( msg->from->body.s, msg->from->body.s + msg->from->body.len, from );
214
-        msg->from->parsed = from;
215
-	}
216
-	else from=(struct to_body *) msg->from->parsed;
217
-
218
-	pu = from->uri;
219
-	
220
-	/* truncate to sip:username@host or tel:number */
221
-	for(i=4;i<pu.len;i++)
222
-		if (pu.s[i]==';' || pu.s[i]=='?' ||pu.s[i]==':'){
223
-			pu.len = i;
224
-		}
225
-	return pu;
226
-}
227
-
228 144
 /**
229 145
  * Looks for the nonce and response parameters in the Authorization header and returns them
230 146
  * @param msg - the SIP message
... ...
@@ -54,8 +54,6 @@
54 54
 #include "../../parser/parse_content.h"
55 55
 #include "../../data_lump_rpl.h"
56 56
 
57
-str get_private_identity(struct sip_msg *msg, str realm, int is_proxy_auth);
58
-str get_public_identity(struct sip_msg *msg);
59 57
 int get_nonce_response(struct sip_msg *msg, str realm,str *nonce,str *response,
60 58
                 enum qop_type *qop,str *qop_str,str *nc,str *cnonce,str *uri, int is_proxy_auth);
61 59
 str ims_get_body(struct sip_msg * msg);