Browse code

- added misssing get_to_uid, reported by Jan Andres

Jan Janak authored on 04/02/2008 10:19:21
Showing 1 changed files
... ...
@@ -119,6 +119,57 @@ int get_from_uid(str* uid, struct sip_msg* msg)
119 119
 }
120 120
 
121 121
 
122
+int get_to_uid(str* uid, struct sip_msg* msg)
123
+{
124
+	static char buf[MAX_URI_SIZE];
125
+	struct to_body* to;
126
+	struct sip_uri puri;
127
+	char* p;
128
+	int_str val, name;
129
+
130
+	name.s = uid_name;
131
+	if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) {
132
+		*uid = val.s;
133
+		return 1;
134
+	} else {
135
+		if (msg->first_line.type == METHOD_REGISTER) {
136
+			if ((msg->to==0) && 
137
+				(parse_headers(msg, HDR_TO_F, 0) < 0 || msg->to == 0)) {
138
+				DBG("get_to_uid: Error while parsing To URI: "
139
+					" to header bad or missing\n");
140
+				return -1;
141
+			}
142
+			to = get_to(msg);
143
+			if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) {
144
+				DBG("get_to_uid: Error while parsing To URI\n");
145
+				return -1;
146
+			}
147
+			p = puri.user.s;
148
+			uid->len = puri.user.len;
149
+		} else {
150
+			if (!msg->parsed_uri_ok && (parse_sip_msg_uri(msg) < 0)) {
151
+				DBG("Error while parsing the Request-URI\n");
152
+				return -1;
153
+			}
154
+			p = msg->parsed_uri.user.s;
155
+			uid->len = msg->parsed_uri.user.len;
156
+		}
157
+			
158
+		if (uid->len > MAX_URI_SIZE) {
159
+			DBG("get_to_uid: Username too long\n");
160
+			return -1;
161
+		}
162
+		memcpy(buf, puri.user.s, puri.user.len);
163
+		uid->s = buf;
164
+		strlower(uid);
165
+
166
+		val.s = *uid;
167
+		add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val);
168
+		return 0;
169
+	}
170
+}
171
+
172
+
122 173
 /*
123 174
  * Set To UID
124 175
  */