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 52
 /*
53 53
  * Set From UID
54 54
  */
55
-int get_from_uid(str* uid)
55
+int get_from_uid(str* uid, struct sip_msg* msg)
56 56
 {
57
+	static char buf[MAX_URI_SIZE];
58
+	struct to_body* from;
59
+	struct sip_uri puri;
57 60
 	static str name_s = STR_STATIC_INIT(AVP_UID);
58 61
 	int_str name, val;
59 62
 
... ...
@@ -62,8 +68,28 @@ int get_from_uid(str* uid)
62 62
 		*uid = *val.s;
63 63
 		return 1;
64 64
 	} else {
65
-		uid->s = 0;
66
-		uid->len = 0;
65
+		     /* Get From URI username */
66
+		if (parse_from_header(msg) < 0) {
67
+			LOG(L_ERR, "get_from_uid: Error while parsing From header\n");
68
+			return -1;
69
+		}
70
+		from = get_from(msg);
71
+		if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) {
72
+			LOG(L_ERR, "get_from_uid: Error while parsing From URI\n");
73
+			return -1;
74
+		}
75
+		
76
+		if (puri.user.len > MAX_URI_SIZE) {
77
+			LOG(L_ERR, "get_from_uid: Username too long\n");
78
+			return -1;
79
+		}
80
+		memcpy(buf, puri.user.s, puri.user.len);
81
+		uid->s = buf;
82
+		uid->len = puri.user.len;
83
+		strlower(uid);
84
+
85
+		val.s = uid;
86
+		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
67 87
 		return 0;
68 88
 	}
69 89
 }
... ...
@@ -89,12 +115,14 @@ void set_to_uid(str* uid)
89 89
 }
90 90
 
91 91
 
92
-
93 92
 /*
94
- * Set To UID
93
+ * Get To UID
95 94
  */
96
-int get_to_uid(str* uid)
95
+int get_to_uid(str* uid, struct sip_msg* msg)
97 96
 {
97
+	static char buf[MAX_URI_SIZE];
98
+	struct to_body* to;
99
+	struct sip_uri puri;
98 100
 	static str name_s = STR_STATIC_INIT(AVP_UID);
99 101
 	int_str name, val;
100 102
 
... ...
@@ -103,8 +131,23 @@ int get_to_uid(str* uid)
103 103
 		*uid = *val.s;
104 104
 		return 1;
105 105
 	} else {
106
-		uid->s = 0;
107
-		uid->len = 0;
106
+		to = get_to(msg);
107
+		if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) {
108
+			LOG(L_ERR, "get_to_uid: Error while parsing To URI\n");
109
+			return -1;
110
+		}
111
+		
112
+		if (puri.user.len > MAX_URI_SIZE) {
113
+			LOG(L_ERR, "get_to_uid: Username too long\n");
114
+			return -1;
115
+		}
116
+		memcpy(buf, puri.user.s, puri.user.len);
117
+		uid->s = buf;
118
+		uid->len = puri.user.len;
119
+		strlower(uid);
120
+
121
+		val.s = uid;
122
+		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
108 123
 		return 0;
109 124
 	}
110 125
 }
... ...
@@ -113,18 +156,36 @@ int get_to_uid(str* uid)
113 113
 /*
114 114
  * Return the current domain id
115 115
  */
116
-int get_did(str* did)
116
+int get_did(str* did, struct sip_msg* msg)
117 117
 {
118
+	static char buf[MAX_URI_SIZE];
119
+	struct to_body* from;
120
+	struct sip_uri puri;
118 121
 	static str name_s = STR_STATIC_INIT(AVP_DID);
119 122
 	int_str name, val;
120
-	
123
+
121 124
 	name.s = &name_s;
122
-	if (search_first_avp(AVP_DOMAIN | AVP_NAME_STR, name, &val, 0)) {
125
+	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
123 126
 		*did = *val.s;
124 127
 		return 1;
125 128
 	} else {
126
-		did->s = 0;
127
-		did->len = 0;
129
+		from = get_to(msg);
130
+		if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) {
131
+			LOG(L_ERR, "get_did: Error while parsing From URI\n");
132
+			return -1;
133
+		}
134
+		
135
+		if (puri.host.len > MAX_URI_SIZE) {
136
+			LOG(L_ERR, "get_did: Username too long\n");
137
+			return -1;
138
+		}
139
+		memcpy(buf, puri.host.s, puri.host.len);
140
+		did->s = buf;
141
+		did->len = puri.host.len;
142
+		strlower(did);
143
+
144
+		val.s = did;
145
+		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
128 146
 		return 0;
129
-	}	
147
+	}
130 148
 }
... ...
@@ -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 40
 
41 41
 
42 42
 /*
43
- * Set From UID
43
+ * Get From UID
44 44
  */
45
-int get_from_uid(str* uid);
45
+int get_from_uid(str* uid, struct sip_msg* msg);
46 46
 
47 47
 /*
48 48
  * Set To UID
... ...
@@ -51,15 +52,15 @@ void set_to_uid(str* uid);
51 51
 
52 52
 
53 53
 /*
54
- * Set To UID
54
+ * Ge To UID
55 55
  */
56
-int set_to_uid(str* uid);
56
+int get_to_uid(str* uid, struct sip_msg* msg);
57 57
 
58 58
 
59 59
 /*
60 60
  * Return the current domain id
61 61
  */
62
-int get_did(str* did);
62
+int get_did(str* did, struct sip_msg* msg);
63 63
 
64 64
 
65 65
 #endif /* _ID_H */