Browse code

fixes SER-304

allow use AVPs and SELECTs as the parameter for realm, e.g.
@authorization["$fd.digest_realm"].uri or
@proxy_authorization["@ruri.domain"].user

Michal Matyska authored on 06/09/2007 12:46:21
Showing 2 changed files
... ...
@@ -57,6 +57,7 @@
57 57
 #include "parser/parse_refer_to.h"
58 58
 #include "parser/parse_rpid.h"
59 59
 #include "dset.h"
60
+#include "sr_module.h"
60 61
 
61 62
 #define RETURN0_res(x) {*res=(x);return 0;}
62 63
 #define TRIM_RET0_res(x) {*res=(x);trim(res);return 0;} 
... ...
@@ -889,11 +890,32 @@ static struct hdr_field* get_credentials(struct sip_msg* msg, select_t* s)
889 889
 	str realm;
890 890
 	hdr_types_t hdr_type;
891 891
 
892
+	if (!msg) {
893
+		/* fix-up call check domain for fparam conversion */
894
+		int ret;
895
+		void * ptr;
896
+		char chr;
897
+		ptr=(void *)(s->params[1].v.s.s);
898
+		chr=s->params[1].v.s.s[s->params[1].v.s.len];
899
+		s->params[1].v.s.s[s->params[1].v.s.len]=0;
900
+		ret=fixup_var_str_12(&ptr,0);
901
+		s->params[1].v.s.s[s->params[1].v.s.len]=chr;
902
+		s->params[1].v.p=ptr;
903
+		s->params[1].type=SEL_PARAM_PTR;
904
+		return (void*)ret;
905
+	}
906
+	
907
+
892 908
 	     /* Try to find credentials with corresponding realm
893 909
 	      * in the message, parse them and return pointer to
894 910
 	      * parsed structure
895 911
 	      */
896
-	realm = s->params[1].v.s;
912
+	if (s->params[1].type==SEL_PARAM_PTR) {
913
+		if (get_str_fparam(&realm, msg, s->params[1].v.p)<0)
914
+			return 0;
915
+	} else {
916
+		realm = s->params[1].v.s;
917
+	}
897 918
 
898 919
 	switch (s->params[0].v.i) {
899 920
 	case SEL_AUTH_WWW:
... ...
@@ -925,14 +947,16 @@ int select_auth(str* res, select_t* s, struct sip_msg* msg)
925 925
 {
926 926
 	struct hdr_field* hdr;
927 927
 
928
-	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR) return -1;
928
+	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR
929
+	              && s->params[1].type != SEL_PARAM_PTR) return -1;
929 930
 
930 931
 	if (s->params[0].type != SEL_PARAM_DIV) {
931 932
 		BUG("Last parameter should have type DIV (converted)\n");
932 933
 		return -1;
933 934
 	}
934 935
 
935
-        hdr = get_credentials(msg, s);
936
+	hdr = get_credentials(msg, s);
937
+	if (!msg && !res) return (int)hdr;
936 938
 	if (!hdr) return -1;
937 939
 	RETURN0_res(hdr->body);
938 940
 }
... ...
@@ -945,6 +969,7 @@ int select_auth_param(str* res, select_t* s, struct sip_msg* msg)
945 945
 	if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1;
946 946
 
947 947
 	hdr = get_credentials(msg, s);
948
+	if (!msg && !res) return (int)hdr;
948 949
 	if (!hdr) return 1;
949 950
 	cred = &((auth_body_t*)hdr->parsed)->digest;
950 951
 
... ...
@@ -330,8 +330,8 @@ static select_row_t select_core[] = {
330 330
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("code"), select_msg_response_status, 0},
331 331
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("reason"), select_msg_response_reason, 0},
332 332
 
333
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("proxy_authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_PROXY},
334
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_WWW}, 
333
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("proxy_authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_PROXY | FIXUP_CALL},
334
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_WWW | FIXUP_CALL}, 
335 335
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("username"), select_auth_username, DIVERSION | SEL_AUTH_USERNAME},
336 336
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("realm"), select_auth_param, DIVERSION | SEL_AUTH_REALM},
337 337
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("nonce"), select_auth_param, DIVERSION | SEL_AUTH_NONCE},