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 890
 	str realm;
890 891
 	hdr_types_t hdr_type;
891 892
 
893
+	if (!msg) {
894
+		/* fix-up call check domain for fparam conversion */
895
+		int ret;
896
+		void * ptr;
897
+		char chr;
898
+		ptr=(void *)(s->params[1].v.s.s);
899
+		chr=s->params[1].v.s.s[s->params[1].v.s.len];
900
+		s->params[1].v.s.s[s->params[1].v.s.len]=0;
901
+		ret=fixup_var_str_12(&ptr,0);
902
+		s->params[1].v.s.s[s->params[1].v.s.len]=chr;
903
+		s->params[1].v.p=ptr;
904
+		s->params[1].type=SEL_PARAM_PTR;
905
+		return (void*)ret;
906
+	}
907
+	
908
+
892 909
 	     /* Try to find credentials with corresponding realm
893 910
 	      * in the message, parse them and return pointer to
894 911
 	      * parsed structure
895 912
 	      */
896
-	realm = s->params[1].v.s;
913
+	if (s->params[1].type==SEL_PARAM_PTR) {
914
+		if (get_str_fparam(&realm, msg, s->params[1].v.p)<0)
915
+			return 0;
916
+	} else {
917
+		realm = s->params[1].v.s;
918
+	}
897 919
 
898 920
 	switch (s->params[0].v.i) {
899 921
 	case SEL_AUTH_WWW:
... ...
@@ -925,14 +947,16 @@ int select_auth(str* res, select_t* s, struct sip_msg* msg)
925 947
 {
926 948
 	struct hdr_field* hdr;
927 949
 
928
-	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR) return -1;
950
+	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR
951
+	              && s->params[1].type != SEL_PARAM_PTR) return -1;
929 952
 
930 953
 	if (s->params[0].type != SEL_PARAM_DIV) {
931 954
 		BUG("Last parameter should have type DIV (converted)\n");
932 955
 		return -1;
933 956
 	}
934 957
 
935
-        hdr = get_credentials(msg, s);
958
+	hdr = get_credentials(msg, s);
959
+	if (!msg && !res) return (int)hdr;
936 960
 	if (!hdr) return -1;
937 961
 	RETURN0_res(hdr->body);
938 962
 }
... ...
@@ -945,6 +969,7 @@ int select_auth_param(str* res, select_t* s, struct sip_msg* msg)
945 969
 	if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1;
946 970
 
947 971
 	hdr = get_credentials(msg, s);
972
+	if (!msg && !res) return (int)hdr;
948 973
 	if (!hdr) return 1;
949 974
 	cred = &((auth_body_t*)hdr->parsed)->digest;
950 975
 
... ...
@@ -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},