Browse code

- extract uid from message when not available.

Jan Janak authored on 20/11/2005 23:55:05
Showing 2 changed files
... ...
@@ -26,6 +26,9 @@
26 26
  */
27 27
 
28 28
 #include "id.h"
29
+#include "parser/parse_from.h"
30
+#include "parser/parse_uri.h"
31
+#include "ut.h"
29 32
 
30 33
 
31 34
 /*
... ...
@@ -52,8 +55,11 @@ void set_from_uid(str* uid)
52 55
 /*
53 56
  * Set From UID
54 57
  */
55
-int get_from_uid(str* uid)
58
+int get_from_uid(str* uid, struct sip_msg* msg)
56 59
 {
60
+	static char buf[MAX_URI_SIZE];
61
+	struct to_body* from;
62
+	struct sip_uri puri;
57 63
 	static str name_s = STR_STATIC_INIT(AVP_UID);
58 64
 	int_str name, val;
59 65
 
... ...
@@ -62,8 +68,28 @@ int get_from_uid(str* uid)
62 68
 		*uid = *val.s;
63 69
 		return 1;
64 70
 	} else {
65
-		uid->s = 0;
66
-		uid->len = 0;
71
+		     /* Get From URI username */
72
+		if (parse_from_header(msg) < 0) {
73
+			LOG(L_ERR, "get_from_uid: Error while parsing From header\n");
74
+			return -1;
75
+		}
76
+		from = get_from(msg);
77
+		if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) {
78
+			LOG(L_ERR, "get_from_uid: Error while parsing From URI\n");
79
+			return -1;
80
+		}
81
+		
82
+		if (puri.user.len > MAX_URI_SIZE) {
83
+			LOG(L_ERR, "get_from_uid: Username too long\n");
84
+			return -1;
85
+		}
86
+		memcpy(buf, puri.user.s, puri.user.len);
87
+		uid->s = buf;
88
+		uid->len = puri.user.len;
89
+		strlower(uid);
90
+
91
+		val.s = uid;
92
+		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
67 93
 		return 0;
68 94
 	}
69 95
 }
... ...
@@ -89,12 +115,14 @@ void set_to_uid(str* uid)
89 115
 }
90 116
 
91 117
 
92
-
93 118
 /*
94
- * Set To UID
119
+ * Get To UID
95 120
  */
96
-int get_to_uid(str* uid)
121
+int get_to_uid(str* uid, struct sip_msg* msg)
97 122
 {
123
+	static char buf[MAX_URI_SIZE];
124
+	struct to_body* to;
125
+	struct sip_uri puri;
98 126
 	static str name_s = STR_STATIC_INIT(AVP_UID);
99 127
 	int_str name, val;
100 128
 
... ...
@@ -103,8 +131,23 @@ int get_to_uid(str* uid)
103 131
 		*uid = *val.s;
104 132
 		return 1;
105 133
 	} else {
106
-		uid->s = 0;
107
-		uid->len = 0;
134
+		to = get_to(msg);
135
+		if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) {
136
+			LOG(L_ERR, "get_to_uid: Error while parsing To URI\n");
137
+			return -1;
138
+		}
139
+		
140
+		if (puri.user.len > MAX_URI_SIZE) {
141
+			LOG(L_ERR, "get_to_uid: Username too long\n");
142
+			return -1;
143
+		}
144
+		memcpy(buf, puri.user.s, puri.user.len);
145
+		uid->s = buf;
146
+		uid->len = puri.user.len;
147
+		strlower(uid);
148
+
149
+		val.s = uid;
150
+		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
108 151
 		return 0;
109 152
 	}
110 153
 }
... ...
@@ -113,18 +156,36 @@ int get_to_uid(str* uid)
113 156
 /*
114 157
  * Return the current domain id
115 158
  */
116
-int get_did(str* did)
159
+int get_did(str* did, struct sip_msg* msg)
117 160
 {
161
+	static char buf[MAX_URI_SIZE];
162
+	struct to_body* from;
163
+	struct sip_uri puri;
118 164
 	static str name_s = STR_STATIC_INIT(AVP_DID);
119 165
 	int_str name, val;
120
-	
166
+
121 167
 	name.s = &name_s;
122
-	if (search_first_avp(AVP_DOMAIN | AVP_NAME_STR, name, &val, 0)) {
168
+	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
123 169
 		*did = *val.s;
124 170
 		return 1;
125 171
 	} else {
126
-		did->s = 0;
127
-		did->len = 0;
172
+		from = get_to(msg);
173
+		if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) {
174
+			LOG(L_ERR, "get_did: Error while parsing From URI\n");
175
+			return -1;
176
+		}
177
+		
178
+		if (puri.host.len > MAX_URI_SIZE) {
179
+			LOG(L_ERR, "get_did: Username too long\n");
180
+			return -1;
181
+		}
182
+		memcpy(buf, puri.host.s, puri.host.len);
183
+		did->s = buf;
184
+		did->len = puri.host.len;
185
+		strlower(did);
186
+
187
+		val.s = did;
188
+		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
128 189
 		return 0;
129
-	}	
190
+	}
130 191
 }
... ...
@@ -31,6 +31,7 @@
31 31
 
32 32
 #include "str.h"
33 33
 #include "usr_avp.h"
34
+#include "parser/msg_parser.h"
34 35
 
35 36
 
36 37
 /*
... ...
@@ -40,9 +41,9 @@ void set_from_uid(str* uid);
40 41
 
41 42
 
42 43
 /*
43
- * Set From UID
44
+ * Get From UID
44 45
  */
45
-int get_from_uid(str* uid);
46
+int get_from_uid(str* uid, struct sip_msg* msg);
46 47
 
47 48
 /*
48 49
  * Set To UID
... ...
@@ -51,15 +52,15 @@ void set_to_uid(str* uid);
51 52
 
52 53
 
53 54
 /*
54
- * Set To UID
55
+ * Ge To UID
55 56
  */
56
-int set_to_uid(str* uid);
57
+int get_to_uid(str* uid, struct sip_msg* msg);
57 58
 
58 59
 
59 60
 /*
60 61
  * Return the current domain id
61 62
  */
62
-int get_did(str* did);
63
+int get_did(str* did, struct sip_msg* msg);
63 64
 
64 65
 
65 66
 #endif /* _ID_H */