Browse code

- support for from and to attributes

Jan Janak authored on 24/11/2005 15:04:41
Showing 2 changed files
... ...
@@ -40,18 +40,17 @@ void set_from_uid(str* uid)
40 40
 	int_str name, val;
41 41
 	avp_t* a;
42 42
 
43
-	a = search_first_avp(AVP_USER | AVP_NAME_STR, name, 0, &s);
43
+	a = search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, 0, &s);
44 44
 	while(a) {
45 45
 		destroy_avp(a);
46 46
 		a = search_next_avp(&s, 0);
47 47
 	}
48 48
 
49
-	val.s = uid;
50
-	add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
49
+	val.s = *uid;
50
+	add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val);
51 51
 }
52 52
 
53 53
 
54
-
55 54
 /*
56 55
  * Set From UID
57 56
  */
... ...
@@ -63,9 +62,9 @@ int get_from_uid(str* uid, struct sip_msg* msg)
63 63
 	static str name_s = STR_STATIC_INIT(AVP_UID);
64 64
 	int_str name, val;
65 65
 
66
-	name.s = &name_s;
67
-	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
68
-		*uid = *val.s;
66
+	name.s = name_s;
67
+	if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) {
68
+		*uid = val.s;
69 69
 		return 1;
70 70
 	} else {
71 71
 		     /* Get From URI username */
... ...
@@ -88,8 +87,8 @@ int get_from_uid(str* uid, struct sip_msg* msg)
88 88
 		uid->len = puri.user.len;
89 89
 		strlower(uid);
90 90
 
91
-		val.s = uid;
92
-		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
91
+		val.s = *uid;
92
+		add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val);
93 93
 		return 0;
94 94
 	}
95 95
 }
... ...
@@ -104,14 +103,14 @@ void set_to_uid(str* uid)
104 104
 	int_str name, val;
105 105
 	avp_t* a;
106 106
 
107
-	a = search_first_avp(AVP_USER | AVP_NAME_STR, name, 0, &s);
107
+	a = search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, 0, &s);
108 108
 	while(a) {
109 109
 		destroy_avp(a);
110 110
 		a = search_next_avp(&s, 0);
111 111
 	}
112 112
 
113
-	val.s = uid;
114
-	add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
113
+	val.s = *uid;
114
+	add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val);
115 115
 }
116 116
 
117 117
 
... ...
@@ -126,9 +125,9 @@ int get_to_uid(str* uid, struct sip_msg* msg)
126 126
 	static str name_s = STR_STATIC_INIT(AVP_UID);
127 127
 	int_str name, val;
128 128
 
129
-	name.s = &name_s;
130
-	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
131
-		*uid = *val.s;
129
+	name.s = name_s;
130
+	if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) {
131
+		*uid = val.s;
132 132
 		return 1;
133 133
 	} else {
134 134
 		to = get_to(msg);
... ...
@@ -146,46 +145,43 @@ int get_to_uid(str* uid, struct sip_msg* msg)
146 146
 		uid->len = puri.user.len;
147 147
 		strlower(uid);
148 148
 
149
-		val.s = uid;
150
-		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
149
+		val.s = *uid;
150
+		add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val);
151 151
 		return 0;
152 152
 	}
153 153
 }
154 154
 
155 155
 
156 156
 /*
157
- * Return the current domain id
157
+ * Return current To domain id
158 158
  */
159
-int get_did(str* did, struct sip_msg* msg)
159
+int get_to_did(str* did, struct sip_msg* msg)
160 160
 {
161
-	static char buf[MAX_URI_SIZE];
162
-	struct to_body* from;
163
-	struct sip_uri puri;
164 161
 	static str name_s = STR_STATIC_INIT(AVP_DID);
165 162
 	int_str name, val;
166 163
 
167
-	name.s = &name_s;
168
-	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
169
-		*did = *val.s;
164
+	name.s = name_s;
165
+	if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) {
166
+		*did = val.s;
170 167
 		return 1;
171
-	} else {
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);
168
+	} 
169
+	return 0;
170
+}
186 171
 
187
-		val.s = did;
188
-		add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
189
-		return 0;
190
-	}
172
+
173
+/*
174
+ * Return current To domain id
175
+ */
176
+int get_from_did(str* did, struct sip_msg* msg)
177
+{
178
+	static str name_s = STR_STATIC_INIT(AVP_DID);
179
+	int_str name, val;
180
+
181
+	name.s = name_s;
182
+	if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) {
183
+		*did = val.s;
184
+		return 1;
185
+	} 
186
+	return 0;
191 187
 }
188
+
... ...
@@ -58,9 +58,15 @@ int get_to_uid(str* uid, struct sip_msg* msg);
58 58
 
59 59
 
60 60
 /*
61
- * Return the current domain id
61
+ * Return current To domain id
62 62
  */
63
-int get_did(str* did, struct sip_msg* msg);
63
+int get_to_did(str* did, struct sip_msg* msg);
64
+
65
+
66
+/*
67
+ * Return current From domain id
68
+ */
69
+int get_from_did(str* did, struct sip_msg* msg);
64 70
 
65 71
 
66 72
 #endif /* _ID_H */