Browse code

- fix (redesign) how credentials realm is extracted from msg / fixed at startup reported by Alfred E. Heggestad When compiling with gcc-3.4.3 on solaris/sparc I get some warnings: select_core.c: In function `get_credentials': select_core.c:896: warning: cast to pointer from integer of different size select_core.c: In function `select_auth': select_core.c:950: warning: cast from pointer to integer of different size select_core.c: In function `select_auth_param': select_core.c:963: warning: cast from pointer to integer of different size

- when select is unresolvable during fixing print its name in the error message to easily correct script

Michal Matyska authored on 07/01/2008 12:14:11
Showing 2 changed files
... ...
@@ -74,8 +74,10 @@ int select_level = 0;
74 74
 int w_parse_select(char**p, select_t* sel)
75 75
 {
76 76
 	str name;
77
+	char* select_name;
77 78
 	
78 79
 	if (**p=='@') (*p)++;
80
+	select_name=*p;
79 81
 	sel->n=0;
80 82
 	while (isalpha((unsigned char)*(*p))) {
81 83
 		if (sel->n > MAX_SELECT_PARAMS -2) {
... ...
@@ -132,12 +134,12 @@ int w_parse_select(char**p, select_t* sel)
132 132
 		(*p)++;
133 133
 	};
134 134
 	if (sel->n==0) {
135
-		ERR("parse_select: invalid select\n");
135
+		ERR("parse_select: invalid select '%s'\n", select_name);
136 136
 		goto error;
137 137
 	};
138 138
 	DBG("parse_select: end, total elements: %d, calling resolve_select\n", sel->n);
139 139
 	if (resolve_select(sel)<0) {
140
-		ERR("parse_select: error while resolve_select\n");
140
+		ERR("parse_select: error while resolve_select '%s'\n", select_name);
141 141
 		goto error;
142 142
 	}
143 143
 	return 0;
... ...
@@ -883,36 +883,38 @@ int select_cseq_method(str* res, select_t* s, struct sip_msg* msg)
883 883
 	return 0;
884 884
 }
885 885
 
886
-static struct hdr_field* get_credentials(struct sip_msg* msg, select_t* s)
886
+int get_credentials(struct sip_msg* msg, select_t* s, struct hdr_field** hdr)
887 887
 {
888 888
 	int ret;
889
-	struct hdr_field* hdr;
890 889
 	str realm;
891 890
 	hdr_types_t hdr_type;
892 891
 
892
+	*hdr = NULL;
893
+
893 894
 	if (!msg) {
894 895
 		/* fix-up call check domain for fparam conversion */
895
-		int ret;
896 896
 		void * ptr;
897 897
 		char chr;
898 898
 		ptr=(void *)(s->params[1].v.s.s);
899 899
 		chr=s->params[1].v.s.s[s->params[1].v.s.len];
900 900
 		s->params[1].v.s.s[s->params[1].v.s.len]=0;
901 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;
902
+		if (ret>=0) {
903
+			s->params[1].v.s.s[s->params[1].v.s.len]=chr;
904
+			s->params[1].v.p=ptr;
905
+			s->params[1].type=SEL_PARAM_PTR;
906
+		}
907
+		return ret;
906 908
 	}
907 909
 	
908 910
 
909
-	     /* Try to find credentials with corresponding realm
910
-	      * in the message, parse them and return pointer to
911
-	      * parsed structure
912
-	      */
911
+	/* Try to find credentials with corresponding realm
912
+	 * in the message, parse them and return pointer to
913
+	 * parsed structure
914
+	 */
913 915
 	if (s->params[1].type==SEL_PARAM_PTR) {
914 916
 		if (get_str_fparam(&realm, msg, s->params[1].v.p)<0)
915
-			return 0;
917
+			return -1;
916 918
 	} else {
917 919
 		realm = s->params[1].v.s;
918 920
 	}
... ...
@@ -928,23 +930,17 @@ static struct hdr_field* get_credentials(struct sip_msg* msg, select_t* s)
928 928
 
929 929
 	default:
930 930
 		BUG("Unexpected parameter value \"%d\"\n", s->params[0].v.i);
931
-		return 0;
932
-	}
933
-
934
-	ret = find_credentials(msg, &realm, hdr_type, &hdr);
935
-	if (ret < 0) {
936
-		ERR("Error while looking for credentials\n");
937
-		return 0;
938
-	} else if (ret > 0) {
939
-		return 0;
931
+		return -1;
940 932
 	}
941 933
 
942
-	return hdr;
934
+	ret = find_credentials(msg, &realm, hdr_type, hdr);
935
+	return ret;
943 936
 }
944 937
 
945 938
 
946 939
 int select_auth(str* res, select_t* s, struct sip_msg* msg)
947 940
 {
941
+	int ret;
948 942
 	struct hdr_field* hdr;
949 943
 
950 944
 	if (s->n != 2 && s->params[1].type != SEL_PARAM_STR
... ...
@@ -955,22 +951,21 @@ int select_auth(str* res, select_t* s, struct sip_msg* msg)
955 955
 		return -1;
956 956
 	}
957 957
 
958
-	hdr = get_credentials(msg, s);
959
-	if (!msg && !res) return (int)hdr;
960
-	if (!hdr) return -1;
958
+	ret = get_credentials(msg, s, &hdr);
959
+	if (!hdr) return ret;
961 960
 	RETURN0_res(hdr->body);
962 961
 }
963 962
 
964 963
 int select_auth_param(str* res, select_t* s, struct sip_msg* msg)
965 964
 {
965
+	int ret;
966 966
 	struct hdr_field* hdr;
967 967
 	dig_cred_t* cred;
968 968
 
969 969
 	if ((s->n != 3 && s->n != 4) || (s->params[s->n - 1].type != SEL_PARAM_DIV)) return -1;
970 970
 
971
-	hdr = get_credentials(msg, s);
972
-	if (!msg && !res) return (int)hdr;
973
-	if (!hdr) return 1;
971
+	ret = get_credentials(msg, s, &hdr);
972
+	if (!hdr) return ret;
974 973
 	cred = &((auth_body_t*)hdr->parsed)->digest;
975 974
 
976 975
 	switch(s->params[s->n - 1].v.i) {