Browse Source

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 18 years ago
parent
commit
ebf528da31
2 changed files with 30 additions and 5 deletions
  1. 28 3
      select_core.c
  2. 2 2
      select_core.h

+ 28 - 3
select_core.c

@@ -57,6 +57,7 @@
 #include "parser/parse_refer_to.h"
 #include "parser/parse_refer_to.h"
 #include "parser/parse_rpid.h"
 #include "parser/parse_rpid.h"
 #include "dset.h"
 #include "dset.h"
+#include "sr_module.h"
 
 
 #define RETURN0_res(x) {*res=(x);return 0;}
 #define RETURN0_res(x) {*res=(x);return 0;}
 #define TRIM_RET0_res(x) {*res=(x);trim(res);return 0;} 
 #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)
 	str realm;
 	str realm;
 	hdr_types_t hdr_type;
 	hdr_types_t hdr_type;
 
 
+	if (!msg) {
+		/* fix-up call check domain for fparam conversion */
+		int ret;
+		void * ptr;
+		char chr;
+		ptr=(void *)(s->params[1].v.s.s);
+		chr=s->params[1].v.s.s[s->params[1].v.s.len];
+		s->params[1].v.s.s[s->params[1].v.s.len]=0;
+		ret=fixup_var_str_12(&ptr,0);
+		s->params[1].v.s.s[s->params[1].v.s.len]=chr;
+		s->params[1].v.p=ptr;
+		s->params[1].type=SEL_PARAM_PTR;
+		return (void*)ret;
+	}
+	
+
 	     /* Try to find credentials with corresponding realm
 	     /* Try to find credentials with corresponding realm
 	      * in the message, parse them and return pointer to
 	      * in the message, parse them and return pointer to
 	      * parsed structure
 	      * parsed structure
 	      */
 	      */
-	realm = s->params[1].v.s;
+	if (s->params[1].type==SEL_PARAM_PTR) {
+		if (get_str_fparam(&realm, msg, s->params[1].v.p)<0)
+			return 0;
+	} else {
+		realm = s->params[1].v.s;
+	}
 
 
 	switch (s->params[0].v.i) {
 	switch (s->params[0].v.i) {
 	case SEL_AUTH_WWW:
 	case SEL_AUTH_WWW:
@@ -925,14 +947,16 @@ int select_auth(str* res, select_t* s, struct sip_msg* msg)
 {
 {
 	struct hdr_field* hdr;
 	struct hdr_field* hdr;
 
 
-	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR) return -1;
+	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR
+	              && s->params[1].type != SEL_PARAM_PTR) return -1;
 
 
 	if (s->params[0].type != SEL_PARAM_DIV) {
 	if (s->params[0].type != SEL_PARAM_DIV) {
 		BUG("Last parameter should have type DIV (converted)\n");
 		BUG("Last parameter should have type DIV (converted)\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
-        hdr = get_credentials(msg, s);
+	hdr = get_credentials(msg, s);
+	if (!msg && !res) return (int)hdr;
 	if (!hdr) return -1;
 	if (!hdr) return -1;
 	RETURN0_res(hdr->body);
 	RETURN0_res(hdr->body);
 }
 }
@@ -945,6 +969,7 @@ int select_auth_param(str* res, select_t* s, struct sip_msg* msg)
 	if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1;
 	if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1;
 
 
 	hdr = get_credentials(msg, s);
 	hdr = get_credentials(msg, s);
+	if (!msg && !res) return (int)hdr;
 	if (!hdr) return 1;
 	if (!hdr) return 1;
 	cred = &((auth_body_t*)hdr->parsed)->digest;
 	cred = &((auth_body_t*)hdr->parsed)->digest;
 
 

+ 2 - 2
select_core.h

@@ -330,8 +330,8 @@ static select_row_t select_core[] = {
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("code"), select_msg_response_status, 0},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("code"), select_msg_response_status, 0},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("reason"), select_msg_response_reason, 0},
 	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("reason"), select_msg_response_reason, 0},
 
 
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("proxy_authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_PROXY},
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_WWW}, 
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("proxy_authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_PROXY | FIXUP_CALL},
+	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("authorization"), select_auth, CONSUME_NEXT_STR | DIVERSION | SEL_AUTH_WWW | FIXUP_CALL}, 
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("username"), select_auth_username, DIVERSION | SEL_AUTH_USERNAME},
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("username"), select_auth_username, DIVERSION | SEL_AUTH_USERNAME},
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("realm"), select_auth_param, DIVERSION | SEL_AUTH_REALM},
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("realm"), select_auth_param, DIVERSION | SEL_AUTH_REALM},
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("nonce"), select_auth_param, DIVERSION | SEL_AUTH_NONCE},
 	{ select_auth, SEL_PARAM_STR, STR_STATIC_INIT("nonce"), select_auth_param, DIVERSION | SEL_AUTH_NONCE},