Browse code

- When retrieving from uid - try digest username first, then proceed to from

Jan Janak authored on 30/11/2005 16:10:12
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 #include "id.h"
29 29
 #include "parser/parse_from.h"
30 30
 #include "parser/parse_uri.h"
31
+#include "parser/digest/digest.h"
31 32
 #include "ut.h"
32 33
 
33 34
 
... ...
@@ -51,6 +52,20 @@ void set_from_uid(str* uid)
51 52
 }
52 53
 
53 54
 
55
+/* Extract username attribute from authorized credentials */
56
+static inline str* cred_user(struct sip_msg* msg)
57
+{
58
+	struct hdr_field* h;
59
+	auth_body_t* cred;
60
+
61
+	get_authorized_cred(msg->proxy_auth, &h);
62
+	if (!h) get_authorized_cred(msg->authorization, &h);
63
+	if (!h) return 0;
64
+	cred = (auth_body_t*)(h->parsed);
65
+	if (!cred || !cred->digest.username.user.len) return 0;
66
+	return &cred->digest.username.user;
67
+}
68
+
54 69
 /*
55 70
  * Set From UID
56 71
  */
... ...
@@ -59,6 +74,7 @@ int get_from_uid(str* uid, struct sip_msg* msg)
59 74
 	static char buf[MAX_URI_SIZE];
60 75
 	struct to_body* from;
61 76
 	struct sip_uri puri;
77
+	str* du;
62 78
 	static str name_s = STR_STATIC_INIT(AVP_UID);
63 79
 	int_str name, val;
64 80
 
... ...
@@ -67,26 +83,32 @@ int get_from_uid(str* uid, struct sip_msg* msg)
67 83
 		*uid = val.s;
68 84
 		return 1;
69 85
 	} else {
70
-		     /* Get From URI username */
71
-		if (parse_from_header(msg) < 0) {
72
-			LOG(L_ERR, "get_from_uid: Error while parsing From header\n");
73
-			return -1;
74
-		}
75
-		from = get_from(msg);
76
-		if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) {
77
-			LOG(L_ERR, "get_from_uid: Error while parsing From URI\n");
78
-			return -1;
79
-		}
86
+		du = cred_user(msg);
87
+		if (du) {
88
+			     /* Try digest username first */
89
+			*uid = *du;
90
+		} else {
91
+			     /* Get From URI username */
92
+			if (parse_from_header(msg) < 0) {
93
+				LOG(L_ERR, "get_from_uid: Error while parsing From header\n");
94
+				return -1;
95
+			}
96
+			from = get_from(msg);
97
+			if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) {
98
+				LOG(L_ERR, "get_from_uid: Error while parsing From URI\n");
99
+				return -1;
100
+			}
80 101
 		
81
-		if (puri.user.len > MAX_URI_SIZE) {
82
-			LOG(L_ERR, "get_from_uid: Username too long\n");
83
-			return -1;
102
+			if (puri.user.len > MAX_URI_SIZE) {
103
+				LOG(L_ERR, "get_from_uid: Username too long\n");
104
+				return -1;
105
+			}
106
+			memcpy(buf, puri.user.s, puri.user.len);
107
+			uid->s = buf;
108
+			uid->len = puri.user.len;
109
+			strlower(uid);
84 110
 		}
85
-		memcpy(buf, puri.user.s, puri.user.len);
86
-		uid->s = buf;
87
-		uid->len = puri.user.len;
88
-		strlower(uid);
89
-
111
+		
90 112
 		val.s = *uid;
91 113
 		add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val);
92 114
 		return 0;