- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,228 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2005 iptelorg GmbH |
|
3 |
- * |
|
4 |
- * This file is part of Kamailio, a free SIP server. |
|
5 |
- * |
|
6 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
7 |
- * it under the terms of the GNU General Public License as published by |
|
8 |
- * the Free Software Foundation; either version 2 of the License, or |
|
9 |
- * (at your option) any later version |
|
10 |
- * |
|
11 |
- * Kamailio is distributed in the hope that it will be useful, |
|
12 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
- * GNU General Public License for more details. |
|
15 |
- * |
|
16 |
- * You should have received a copy of the GNU General Public License |
|
17 |
- * along with this program; if not, write to the Free Software |
|
18 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
- */ |
|
20 |
- |
|
21 |
-/*! |
|
22 |
- * \file |
|
23 |
- * \brief Kamailio core :: UID handling |
|
24 |
- * \ingroup core |
|
25 |
- * Module: \ref core |
|
26 |
- */ |
|
27 |
- |
|
28 |
-#include "id.h" |
|
29 |
-#include "parser/parse_from.h" |
|
30 |
-#include "parser/parse_uri.h" |
|
31 |
-#include "parser/digest/digest.h" |
|
32 |
-#include "ut.h" |
|
33 |
- |
|
34 |
-static str uid_name = STR_STATIC_INIT(AVP_UID); |
|
35 |
-static str did_name = STR_STATIC_INIT(AVP_DID); |
|
36 |
- |
|
37 |
- |
|
38 |
-/** |
|
39 |
- * Set From UID |
|
40 |
- */ |
|
41 |
-int set_from_uid(str* uid) |
|
42 |
-{ |
|
43 |
- struct search_state s; |
|
44 |
- int_str val, name; |
|
45 |
- avp_t* a; |
|
46 |
- |
|
47 |
- name.s = uid_name; |
|
48 |
- a = search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, 0, &s); |
|
49 |
- while(a) { |
|
50 |
- destroy_avp(a); |
|
51 |
- a = search_next_avp(&s, 0); |
|
52 |
- } |
|
53 |
- |
|
54 |
- val.s = *uid; |
|
55 |
- return add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
56 |
-} |
|
57 |
- |
|
58 |
- |
|
59 |
-/** Extract username attribute from authorized credentials */ |
|
60 |
-static inline str* cred_user(struct sip_msg* msg) |
|
61 |
-{ |
|
62 |
- struct hdr_field* h; |
|
63 |
- auth_body_t* cred; |
|
64 |
- |
|
65 |
- get_authorized_cred(msg->proxy_auth, &h); |
|
66 |
- if (!h) get_authorized_cred(msg->authorization, &h); |
|
67 |
- if (!h) return 0; |
|
68 |
- cred = (auth_body_t*)(h->parsed); |
|
69 |
- if (!cred || !cred->digest.username.user.len) return 0; |
|
70 |
- return &cred->digest.username.user; |
|
71 |
-} |
|
72 |
- |
|
73 |
-/** |
|
74 |
- * Set From UID |
|
75 |
- */ |
|
76 |
-int get_from_uid(str* uid, struct sip_msg* msg) |
|
77 |
-{ |
|
78 |
- static char buf[MAX_URI_SIZE]; |
|
79 |
- struct to_body* from; |
|
80 |
- struct sip_uri puri; |
|
81 |
- str* du; |
|
82 |
- int_str val, name; |
|
83 |
- |
|
84 |
- name.s = uid_name; |
|
85 |
- if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) { |
|
86 |
- *uid = val.s; |
|
87 |
- return 1; |
|
88 |
- } else { |
|
89 |
- du = cred_user(msg); |
|
90 |
- if (du) { |
|
91 |
- /* Try digest username first */ |
|
92 |
- *uid = *du; |
|
93 |
- } else { |
|
94 |
- /* Get From URI username */ |
|
95 |
- if (parse_from_header(msg) < 0) { |
|
96 |
- LM_ERR("unable to parse From header\n"); |
|
97 |
- return -1; |
|
98 |
- } |
|
99 |
- from = get_from(msg); |
|
100 |
- if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) { |
|
101 |
- LM_ERR("unable to parsie From URI\n"); |
|
102 |
- return -1; |
|
103 |
- } |
|
104 |
- |
|
105 |
- if (puri.user.len > MAX_URI_SIZE) { |
|
106 |
- LM_ERR("username too long\n"); |
|
107 |
- return -1; |
|
108 |
- } |
|
109 |
- memcpy(buf, puri.user.s, puri.user.len); |
|
110 |
- uid->s = buf; |
|
111 |
- uid->len = puri.user.len; |
|
112 |
- strlower(uid); |
|
113 |
- } |
|
114 |
- |
|
115 |
- val.s = *uid; |
|
116 |
- add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
117 |
- return 0; |
|
118 |
- } |
|
119 |
-} |
|
120 |
- |
|
121 |
-/** Get to UID |
|
122 |
- */ |
|
123 |
-int get_to_uid(str* uid, struct sip_msg* msg) |
|
124 |
-{ |
|
125 |
- static char buf[MAX_URI_SIZE]; |
|
126 |
- struct to_body* to; |
|
127 |
- struct sip_uri puri; |
|
128 |
- char* p; |
|
129 |
- int_str val, name; |
|
130 |
- |
|
131 |
- name.s = uid_name; |
|
132 |
- if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) { |
|
133 |
- *uid = val.s; |
|
134 |
- return 1; |
|
135 |
- } else { |
|
136 |
- if (msg->REQ_METHOD == METHOD_REGISTER) { |
|
137 |
- if ((msg->to==0) && |
|
138 |
- (parse_headers(msg, HDR_TO_F, 0) < 0 || msg->to == 0)) { |
|
139 |
- LM_DBG("Error while parsing To URI: 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 |
- LM_DBG("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 |
- LM_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 |
- LM_DBG("Username too long\n"); |
|
160 |
- return -1; |
|
161 |
- } |
|
162 |
- if (p == NULL || uid->len == 0) { |
|
163 |
- LM_DBG("Username is empty\n"); |
|
164 |
- return -1; |
|
165 |
- } |
|
166 |
- memcpy(buf, p, uid->len); |
|
167 |
- uid->s = buf; |
|
168 |
- strlower(uid); |
|
169 |
- |
|
170 |
- val.s = *uid; |
|
171 |
- add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
172 |
- return 0; |
|
173 |
- } |
|
174 |
-} |
|
175 |
- |
|
176 |
- |
|
177 |
-/** |
|
178 |
- * Set To UID |
|
179 |
- */ |
|
180 |
-int set_to_uid(str* uid) |
|
181 |
-{ |
|
182 |
- struct search_state s; |
|
183 |
- int_str val, name; |
|
184 |
- avp_t* a; |
|
185 |
- |
|
186 |
- name.s = uid_name; |
|
187 |
- a = search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, 0, &s); |
|
188 |
- while(a) { |
|
189 |
- destroy_avp(a); |
|
190 |
- a = search_next_avp(&s, 0); |
|
191 |
- } |
|
192 |
- |
|
193 |
- val.s = *uid; |
|
194 |
- return add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
195 |
-} |
|
196 |
- |
|
197 |
- |
|
198 |
-/** |
|
199 |
- * Return current To domain id |
|
200 |
- */ |
|
201 |
-int get_to_did(str* did, struct sip_msg* msg) |
|
202 |
-{ |
|
203 |
- int_str val, name; |
|
204 |
- |
|
205 |
- name.s = did_name; |
|
206 |
- if (search_first_avp(AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) { |
|
207 |
- *did = val.s; |
|
208 |
- return 1; |
|
209 |
- } |
|
210 |
- return 0; |
|
211 |
-} |
|
212 |
- |
|
213 |
- |
|
214 |
-/** |
|
215 |
- * Return current To domain id |
|
216 |
- */ |
|
217 |
-int get_from_did(str* did, struct sip_msg* msg) |
|
218 |
-{ |
|
219 |
- int_str val, name; |
|
220 |
- |
|
221 |
- name.s = did_name; |
|
222 |
- if (search_first_avp(AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) { |
|
223 |
- *did = val.s; |
|
224 |
- return 1; |
|
225 |
- } |
|
226 |
- return 0; |
|
227 |
-} |
|
228 |
- |
... | ... |
@@ -136,20 +136,19 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
136 | 136 |
if (msg->REQ_METHOD == METHOD_REGISTER) { |
137 | 137 |
if ((msg->to==0) && |
138 | 138 |
(parse_headers(msg, HDR_TO_F, 0) < 0 || msg->to == 0)) { |
139 |
- DBG("get_to_uid: Error while parsing To URI: " |
|
140 |
- " to header bad or missing\n"); |
|
139 |
+ LM_DBG("Error while parsing To URI: to header bad or missing\n"); |
|
141 | 140 |
return -1; |
142 | 141 |
} |
143 | 142 |
to = get_to(msg); |
144 | 143 |
if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) { |
145 |
- DBG("get_to_uid: Error while parsing To URI\n"); |
|
144 |
+ LM_DBG("Error while parsing To URI\n"); |
|
146 | 145 |
return -1; |
147 | 146 |
} |
148 | 147 |
p = puri.user.s; |
149 | 148 |
uid->len = puri.user.len; |
150 | 149 |
} else { |
151 | 150 |
if (!msg->parsed_uri_ok && (parse_sip_msg_uri(msg) < 0)) { |
152 |
- DBG("Error while parsing the Request-URI\n"); |
|
151 |
+ LM_DBG("Error while parsing the Request-URI\n"); |
|
153 | 152 |
return -1; |
154 | 153 |
} |
155 | 154 |
p = msg->parsed_uri.user.s; |
... | ... |
@@ -157,11 +156,11 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
157 | 156 |
} |
158 | 157 |
|
159 | 158 |
if (uid->len > MAX_URI_SIZE) { |
160 |
- DBG("get_to_uid: Username too long\n"); |
|
159 |
+ LM_DBG("Username too long\n"); |
|
161 | 160 |
return -1; |
162 | 161 |
} |
163 | 162 |
if (p == NULL || uid->len == 0) { |
164 |
- DBG("get_to_uid: Username is empty\n"); |
|
163 |
+ LM_DBG("Username is empty\n"); |
|
165 | 164 |
return -1; |
166 | 165 |
} |
167 | 166 |
memcpy(buf, p, uid->len); |
... | ... |
@@ -8,11 +8,6 @@ |
8 | 8 |
* the Free Software Foundation; either version 2 of the License, or |
9 | 9 |
* (at your option) any later version |
10 | 10 |
* |
11 |
- * For a license to use the ser software under conditions |
|
12 |
- * other than those described here, or to purchase support for this |
|
13 |
- * software, please contact iptel.org by e-mail at the following addresses: |
|
14 |
- * info@iptel.org |
|
15 |
- * |
|
16 | 11 |
* Kamailio is distributed in the hope that it will be useful, |
17 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
... | ... |
@@ -1,11 +1,9 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 |
- * |
|
4 | 2 |
* Copyright (C) 2005 iptelorg GmbH |
5 | 3 |
* |
6 |
- * This file is part of ser, a free SIP server. |
|
4 |
+ * This file is part of Kamailio, a free SIP server. |
|
7 | 5 |
* |
8 |
- * ser is free software; you can redistribute it and/or modify |
|
6 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
9 | 7 |
* it under the terms of the GNU General Public License as published by |
10 | 8 |
* the Free Software Foundation; either version 2 of the License, or |
11 | 9 |
* (at your option) any later version |
... | ... |
@@ -15,7 +13,7 @@ |
15 | 13 |
* software, please contact iptel.org by e-mail at the following addresses: |
16 | 14 |
* info@iptel.org |
17 | 15 |
* |
18 |
- * ser is distributed in the hope that it will be useful, |
|
16 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
19 | 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | 19 |
* GNU General Public License for more details. |
... | ... |
@@ -27,7 +25,7 @@ |
27 | 25 |
|
28 | 26 |
/*! |
29 | 27 |
* \file |
30 |
- * \brief SIP-router core :: |
|
28 |
+ * \brief Kamailio core :: UID handling |
|
31 | 29 |
* \ingroup core |
32 | 30 |
* Module: \ref core |
33 | 31 |
*/ |
... | ... |
@@ -42,7 +40,7 @@ static str uid_name = STR_STATIC_INIT(AVP_UID); |
42 | 40 |
static str did_name = STR_STATIC_INIT(AVP_DID); |
43 | 41 |
|
44 | 42 |
|
45 |
-/* |
|
43 |
+/** |
|
46 | 44 |
* Set From UID |
47 | 45 |
*/ |
48 | 46 |
int set_from_uid(str* uid) |
... | ... |
@@ -63,7 +61,7 @@ int set_from_uid(str* uid) |
63 | 61 |
} |
64 | 62 |
|
65 | 63 |
|
66 |
-/* Extract username attribute from authorized credentials */ |
|
64 |
+/** Extract username attribute from authorized credentials */ |
|
67 | 65 |
static inline str* cred_user(struct sip_msg* msg) |
68 | 66 |
{ |
69 | 67 |
struct hdr_field* h; |
... | ... |
@@ -77,7 +75,7 @@ static inline str* cred_user(struct sip_msg* msg) |
77 | 75 |
return &cred->digest.username.user; |
78 | 76 |
} |
79 | 77 |
|
80 |
-/* |
|
78 |
+/** |
|
81 | 79 |
* Set From UID |
82 | 80 |
*/ |
83 | 81 |
int get_from_uid(str* uid, struct sip_msg* msg) |
... | ... |
@@ -125,7 +123,8 @@ int get_from_uid(str* uid, struct sip_msg* msg) |
125 | 123 |
} |
126 | 124 |
} |
127 | 125 |
|
128 |
- |
|
126 |
+/** Get to UID |
|
127 |
+ */ |
|
129 | 128 |
int get_to_uid(str* uid, struct sip_msg* msg) |
130 | 129 |
{ |
131 | 130 |
static char buf[MAX_URI_SIZE]; |
... | ... |
@@ -181,7 +180,7 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
181 | 180 |
} |
182 | 181 |
|
183 | 182 |
|
184 |
-/* |
|
183 |
+/** |
|
185 | 184 |
* Set To UID |
186 | 185 |
*/ |
187 | 186 |
int set_to_uid(str* uid) |
... | ... |
@@ -202,7 +201,7 @@ int set_to_uid(str* uid) |
202 | 201 |
} |
203 | 202 |
|
204 | 203 |
|
205 |
-/* |
|
204 |
+/** |
|
206 | 205 |
* Return current To domain id |
207 | 206 |
*/ |
208 | 207 |
int get_to_did(str* did, struct sip_msg* msg) |
... | ... |
@@ -218,7 +217,7 @@ int get_to_did(str* did, struct sip_msg* msg) |
218 | 217 |
} |
219 | 218 |
|
220 | 219 |
|
221 |
-/* |
|
220 |
+/** |
|
222 | 221 |
* Return current To domain id |
223 | 222 |
*/ |
224 | 223 |
int get_from_did(str* did, struct sip_msg* msg) |
... | ... |
@@ -100,17 +100,17 @@ int get_from_uid(str* uid, struct sip_msg* msg) |
100 | 100 |
} else { |
101 | 101 |
/* Get From URI username */ |
102 | 102 |
if (parse_from_header(msg) < 0) { |
103 |
- LOG(L_ERR, "get_from_uid: Error while parsing From header\n"); |
|
103 |
+ LM_ERR("unable to parse From header\n"); |
|
104 | 104 |
return -1; |
105 | 105 |
} |
106 | 106 |
from = get_from(msg); |
107 | 107 |
if (parse_uri(from->uri.s, from->uri.len, &puri) == -1) { |
108 |
- LOG(L_ERR, "get_from_uid: Error while parsing From URI\n"); |
|
108 |
+ LM_ERR("unable to parsie From URI\n"); |
|
109 | 109 |
return -1; |
110 | 110 |
} |
111 | 111 |
|
112 | 112 |
if (puri.user.len > MAX_URI_SIZE) { |
113 |
- LOG(L_ERR, "get_from_uid: Username too long\n"); |
|
113 |
+ LM_ERR("username too long\n"); |
|
114 | 114 |
return -1; |
115 | 115 |
} |
116 | 116 |
memcpy(buf, puri.user.s, puri.user.len); |
... | ... |
@@ -22,7 +22,7 @@ |
22 | 22 |
* |
23 | 23 |
* You should have received a copy of the GNU General Public License |
24 | 24 |
* along with this program; if not, write to the Free Software |
25 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
25 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
26 | 26 |
*/ |
27 | 27 |
|
28 | 28 |
/*! |
Please fill in after the :: to explain the function of this file.
... | ... |
@@ -25,6 +25,13 @@ |
25 | 25 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
26 | 26 |
*/ |
27 | 27 |
|
28 |
+/*! |
|
29 |
+ * \file |
|
30 |
+ * \brief SIP-router core :: |
|
31 |
+ * \ingroup core |
|
32 |
+ * Module: \ref core |
|
33 |
+ */ |
|
34 |
+ |
|
28 | 35 |
#include "id.h" |
29 | 36 |
#include "parser/parse_from.h" |
30 | 37 |
#include "parser/parse_uri.h" |
Sponsored by: Sippy Software, Inc.
Debugging: mpatrol
... | ... |
@@ -159,6 +159,10 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
159 | 159 |
DBG("get_to_uid: Username too long\n"); |
160 | 160 |
return -1; |
161 | 161 |
} |
162 |
+ if (p == NULL || uid->len == 0) { |
|
163 |
+ DBG("get_to_uid: Username is empty\n"); |
|
164 |
+ return -1; |
|
165 |
+ } |
|
162 | 166 |
memcpy(buf, p, uid->len); |
163 | 167 |
uid->s = buf; |
164 | 168 |
strlower(uid); |
... | ... |
@@ -132,7 +132,7 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
132 | 132 |
*uid = val.s; |
133 | 133 |
return 1; |
134 | 134 |
} else { |
135 |
- if (msg->first_line.type == METHOD_REGISTER) { |
|
135 |
+ if (msg->REQ_METHOD == METHOD_REGISTER) { |
|
136 | 136 |
if ((msg->to==0) && |
137 | 137 |
(parse_headers(msg, HDR_TO_F, 0) < 0 || msg->to == 0)) { |
138 | 138 |
DBG("get_to_uid: Error while parsing To URI: " |
... | ... |
@@ -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 |
*/ |
... | ... |
@@ -140,78 +140,6 @@ int set_to_uid(str* uid) |
140 | 140 |
} |
141 | 141 |
|
142 | 142 |
|
143 |
-/** Retrieves the UID of the callee. This function retrieves the UID (unique |
|
144 |
- * identifier) of the party being called. The function first searches the list |
|
145 |
- * of available attributes and if it finds an attribute with name "uid" then |
|
146 |
- * the value of the attribute is returned. If no such attribute can be found |
|
147 |
- * then the function retrieves the username from To header field of REGISTER |
|
148 |
- * requests (because that is the party being registered), or the username from |
|
149 |
- * the Reqeuest-URI of other requests. The username is then used as the UID |
|
150 |
- * string identifying the callee. If no attribute with the UID was found and |
|
151 |
- * the function successfully retrieved the UID from the SIP message then, in |
|
152 |
- * addition to storing the result in the first parameter, the function will |
|
153 |
- * also create the attribute named "uid" which will contain the UID. The |
|
154 |
- * function is not reentrant because it uses an internal static buffer to |
|
155 |
- * store the result. |
|
156 |
- * @param uid A pointer to ::str variable where the result will be stored, the |
|
157 |
- * pointer in the variable will be updated to point to a static |
|
158 |
- * buffer in the function. |
|
159 |
- * @param msg The SIP message being processed. |
|
160 |
- * @return 1 is returned when the attribute with UID exists and it is used, 0 |
|
161 |
- * is returned when the function retrieved the UID from the SIP |
|
162 |
- * message and created the attribute, -1 is returned on error. |
|
163 |
- */ |
|
164 |
-int get_to_uid(str* uid, struct sip_msg* msg) |
|
165 |
-{ |
|
166 |
- static char buf[MAX_URI_SIZE]; |
|
167 |
- struct to_body* to; |
|
168 |
- struct sip_uri puri; |
|
169 |
- char* p; |
|
170 |
- int_str val, name; |
|
171 |
- |
|
172 |
- name.s = uid_name; |
|
173 |
- if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) { |
|
174 |
- *uid = val.s; |
|
175 |
- return 1; |
|
176 |
- } else { |
|
177 |
- if (msg->first_line.type == METHOD_REGISTER) { |
|
178 |
- if ((msg->to==0) && |
|
179 |
- (parse_headers(msg, HDR_TO_F, 0) < 0 || msg->to == 0)) { |
|
180 |
- DBG("get_to_uid: Error while parsing To URI: " |
|
181 |
- " to header bad or missing\n"); |
|
182 |
- return -1; |
|
183 |
- } |
|
184 |
- to = get_to(msg); |
|
185 |
- if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) { |
|
186 |
- DBG("get_to_uid: Error while parsing To URI\n"); |
|
187 |
- return -1; |
|
188 |
- } |
|
189 |
- p = puri.user.s; |
|
190 |
- uid->len = puri.user.len; |
|
191 |
- } else { |
|
192 |
- if (!msg->parsed_uri_ok && (parse_sip_msg_uri(msg) < 0)) { |
|
193 |
- DBG("Error while parsing the Request-URI\n"); |
|
194 |
- return -1; |
|
195 |
- } |
|
196 |
- p = msg->parsed_uri.user.s; |
|
197 |
- uid->len = msg->parsed_uri.user.len; |
|
198 |
- } |
|
199 |
- |
|
200 |
- if (uid->len > MAX_URI_SIZE) { |
|
201 |
- DBG("get_to_uid: Username too long\n"); |
|
202 |
- return -1; |
|
203 |
- } |
|
204 |
- memcpy(buf, puri.user.s, puri.user.len); |
|
205 |
- uid->s = buf; |
|
206 |
- strlower(uid); |
|
207 |
- |
|
208 |
- val.s = *uid; |
|
209 |
- add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
210 |
- return 0; |
|
211 |
- } |
|
212 |
-} |
|
213 |
- |
|
214 |
- |
|
215 | 143 |
/* |
216 | 144 |
* Return current To domain id |
217 | 145 |
*/ |
... | ... |
@@ -140,7 +140,7 @@ int set_to_uid(str* uid) |
140 | 140 |
} |
141 | 141 |
|
142 | 142 |
|
143 |
-/* Retrieves the UID of the callee. This function retrieves the UID (unique |
|
143 |
+/** Retrieves the UID of the callee. This function retrieves the UID (unique |
|
144 | 144 |
* identifier) of the party being called. The function first searches the list |
145 | 145 |
* of available attributes and if it finds an attribute with name "uid" then |
146 | 146 |
* the value of the attribute is returned. If no such attribute can be found |
... | ... |
@@ -140,14 +140,33 @@ int set_to_uid(str* uid) |
140 | 140 |
} |
141 | 141 |
|
142 | 142 |
|
143 |
-/* |
|
144 |
- * Get To UID |
|
143 |
+/* Retrieves the UID of the callee. This function retrieves the UID (unique |
|
144 |
+ * identifier) of the party being called. The function first searches the list |
|
145 |
+ * of available attributes and if it finds an attribute with name "uid" then |
|
146 |
+ * the value of the attribute is returned. If no such attribute can be found |
|
147 |
+ * then the function retrieves the username from To header field of REGISTER |
|
148 |
+ * requests (because that is the party being registered), or the username from |
|
149 |
+ * the Reqeuest-URI of other requests. The username is then used as the UID |
|
150 |
+ * string identifying the callee. If no attribute with the UID was found and |
|
151 |
+ * the function successfully retrieved the UID from the SIP message then, in |
|
152 |
+ * addition to storing the result in the first parameter, the function will |
|
153 |
+ * also create the attribute named "uid" which will contain the UID. The |
|
154 |
+ * function is not reentrant because it uses an internal static buffer to |
|
155 |
+ * store the result. |
|
156 |
+ * @param uid A pointer to ::str variable where the result will be stored, the |
|
157 |
+ * pointer in the variable will be updated to point to a static |
|
158 |
+ * buffer in the function. |
|
159 |
+ * @param msg The SIP message being processed. |
|
160 |
+ * @return 1 is returned when the attribute with UID exists and it is used, 0 |
|
161 |
+ * is returned when the function retrieved the UID from the SIP |
|
162 |
+ * message and created the attribute, -1 is returned on error. |
|
145 | 163 |
*/ |
146 | 164 |
int get_to_uid(str* uid, struct sip_msg* msg) |
147 | 165 |
{ |
148 | 166 |
static char buf[MAX_URI_SIZE]; |
149 | 167 |
struct to_body* to; |
150 | 168 |
struct sip_uri puri; |
169 |
+ char* p; |
|
151 | 170 |
int_str val, name; |
152 | 171 |
|
153 | 172 |
name.s = uid_name; |
... | ... |
@@ -155,25 +174,35 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
155 | 174 |
*uid = val.s; |
156 | 175 |
return 1; |
157 | 176 |
} else { |
158 |
- if ((msg->to==0) && |
|
159 |
- (parse_headers(msg, HDR_TO_F, 0)<0 || msg->to==0)) { |
|
160 |
- LOG(L_ERR, "get_to_uid: Error while parsing To URI: " |
|
177 |
+ if (msg->first_line.type == METHOD_REGISTER) { |
|
178 |
+ if ((msg->to==0) && |
|
179 |
+ (parse_headers(msg, HDR_TO_F, 0) < 0 || msg->to == 0)) { |
|
180 |
+ DBG("get_to_uid: Error while parsing To URI: " |
|
161 | 181 |
" to header bad or missing\n"); |
162 |
- return -1; |
|
163 |
- } |
|
164 |
- to = get_to(msg); |
|
165 |
- if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) { |
|
166 |
- LOG(L_ERR, "get_to_uid: Error while parsing To URI\n"); |
|
167 |
- return -1; |
|
182 |
+ return -1; |
|
183 |
+ } |
|
184 |
+ to = get_to(msg); |
|
185 |
+ if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) { |
|
186 |
+ DBG("get_to_uid: Error while parsing To URI\n"); |
|
187 |
+ return -1; |
|
188 |
+ } |
|
189 |
+ p = puri.user.s; |
|
190 |
+ uid->len = puri.user.len; |
|
191 |
+ } else { |
|
192 |
+ if (!msg->parsed_uri_ok && (parse_sip_msg_uri(msg) < 0)) { |
|
193 |
+ DBG("Error while parsing the Request-URI\n"); |
|
194 |
+ return -1; |
|
195 |
+ } |
|
196 |
+ p = msg->parsed_uri.user.s; |
|
197 |
+ uid->len = msg->parsed_uri.user.len; |
|
168 | 198 |
} |
169 |
- |
|
170 |
- if (puri.user.len > MAX_URI_SIZE) { |
|
171 |
- LOG(L_ERR, "get_to_uid: Username too long\n"); |
|
199 |
+ |
|
200 |
+ if (uid->len > MAX_URI_SIZE) { |
|
201 |
+ DBG("get_to_uid: Username too long\n"); |
|
172 | 202 |
return -1; |
173 | 203 |
} |
174 | 204 |
memcpy(buf, puri.user.s, puri.user.len); |
175 | 205 |
uid->s = buf; |
176 |
- uid->len = puri.user.len; |
|
177 | 206 |
strlower(uid); |
178 | 207 |
|
179 | 208 |
val.s = *uid; |
... | ... |
@@ -38,7 +38,7 @@ static str did_name = STR_STATIC_INIT(AVP_DID); |
38 | 38 |
/* |
39 | 39 |
* Set From UID |
40 | 40 |
*/ |
41 |
-void set_from_uid(str* uid) |
|
41 |
+int set_from_uid(str* uid) |
|
42 | 42 |
{ |
43 | 43 |
struct search_state s; |
44 | 44 |
int_str val, name; |
... | ... |
@@ -52,7 +52,7 @@ void set_from_uid(str* uid) |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
val.s = *uid; |
55 |
- add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
55 |
+ return add_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
56 | 56 |
} |
57 | 57 |
|
58 | 58 |
|
... | ... |
@@ -122,7 +122,7 @@ int get_from_uid(str* uid, struct sip_msg* msg) |
122 | 122 |
/* |
123 | 123 |
* Set To UID |
124 | 124 |
*/ |
125 |
-void set_to_uid(str* uid) |
|
125 |
+int set_to_uid(str* uid) |
|
126 | 126 |
{ |
127 | 127 |
struct search_state s; |
128 | 128 |
int_str val, name; |
... | ... |
@@ -136,7 +136,7 @@ void set_to_uid(str* uid) |
136 | 136 |
} |
137 | 137 |
|
138 | 138 |
val.s = *uid; |
139 |
- add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
139 |
+ return add_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR | AVP_VAL_STR, name, val); |
|
140 | 140 |
} |
141 | 141 |
|
142 | 142 |
|
... | ... |
@@ -155,8 +155,10 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
155 | 155 |
*uid = val.s; |
156 | 156 |
return 1; |
157 | 157 |
} else { |
158 |
- if (parse_headers(msg, HDR_TO_F, 0) < 0) { |
|
159 |
- LOG(L_ERR, "get_to_uid: Error while parsing To URI (parse_headers)\n"); |
|
158 |
+ if ((msg->to==0) && |
|
159 |
+ (parse_headers(msg, HDR_TO_F, 0)<0 || msg->to==0)) { |
|
160 |
+ LOG(L_ERR, "get_to_uid: Error while parsing To URI: " |
|
161 |
+ " to header bad or missing\n"); |
|
160 | 162 |
return -1; |
161 | 163 |
} |
162 | 164 |
to = get_to(msg); |
... | ... |
@@ -155,6 +155,10 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
155 | 155 |
*uid = val.s; |
156 | 156 |
return 1; |
157 | 157 |
} else { |
158 |
+ if (parse_headers(msg, HDR_TO_F, 0) < 0) { |
|
159 |
+ LOG(L_ERR, "get_to_uid: Error while parsing To URI (parse_headers)\n"); |
|
160 |
+ return -1; |
|
161 |
+ } |
|
158 | 162 |
to = get_to(msg); |
159 | 163 |
if (parse_uri(to->uri.s, to->uri.len, &puri) == -1) { |
160 | 164 |
LOG(L_ERR, "get_to_uid: Error while parsing To URI\n"); |
... | ... |
@@ -31,6 +31,9 @@ |
31 | 31 |
#include "parser/digest/digest.h" |
32 | 32 |
#include "ut.h" |
33 | 33 |
|
34 |
+static str uid_name = STR_STATIC_INIT(AVP_UID); |
|
35 |
+static str did_name = STR_STATIC_INIT(AVP_DID); |
|
36 |
+ |
|
34 | 37 |
|
35 | 38 |
/* |
36 | 39 |
* Set From UID |
... | ... |
@@ -38,9 +41,10 @@ |
38 | 41 |
void set_from_uid(str* uid) |
39 | 42 |
{ |
40 | 43 |
struct search_state s; |
41 |
- int_str name, val; |
|
44 |
+ int_str val, name; |
|
42 | 45 |
avp_t* a; |
43 | 46 |
|
47 |
+ name.s = uid_name; |
|
44 | 48 |
a = search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, 0, &s); |
45 | 49 |
while(a) { |
46 | 50 |
destroy_avp(a); |
... | ... |
@@ -75,10 +79,9 @@ int get_from_uid(str* uid, struct sip_msg* msg) |
75 | 79 |
struct to_body* from; |
76 | 80 |
struct sip_uri puri; |
77 | 81 |
str* du; |
78 |
- static str name_s = STR_STATIC_INIT(AVP_UID); |
|
79 |
- int_str name, val; |
|
82 |
+ int_str val, name; |
|
80 | 83 |
|
81 |
- name.s = name_s; |
|
84 |
+ name.s = uid_name; |
|
82 | 85 |
if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) { |
83 | 86 |
*uid = val.s; |
84 | 87 |
return 1; |
... | ... |
@@ -122,9 +125,10 @@ int get_from_uid(str* uid, struct sip_msg* msg) |
122 | 125 |
void set_to_uid(str* uid) |
123 | 126 |
{ |
124 | 127 |
struct search_state s; |
125 |
- int_str name, val; |
|
128 |
+ int_str val, name; |
|
126 | 129 |
avp_t* a; |
127 | 130 |
|
131 |
+ name.s = uid_name; |
|
128 | 132 |
a = search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, 0, &s); |
129 | 133 |
while(a) { |
130 | 134 |
destroy_avp(a); |
... | ... |
@@ -144,10 +148,9 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
144 | 148 |
static char buf[MAX_URI_SIZE]; |
145 | 149 |
struct to_body* to; |
146 | 150 |
struct sip_uri puri; |
147 |
- static str name_s = STR_STATIC_INIT(AVP_UID); |
|
148 |
- int_str name, val; |
|
151 |
+ int_str val, name; |
|
149 | 152 |
|
150 |
- name.s = name_s; |
|
153 |
+ name.s = uid_name; |
|
151 | 154 |
if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) { |
152 | 155 |
*uid = val.s; |
153 | 156 |
return 1; |
... | ... |
@@ -179,11 +182,10 @@ int get_to_uid(str* uid, struct sip_msg* msg) |
179 | 182 |
*/ |
180 | 183 |
int get_to_did(str* did, struct sip_msg* msg) |
181 | 184 |
{ |
182 |
- static str name_s = STR_STATIC_INIT(AVP_DID); |
|
183 |
- int_str name, val; |
|
185 |
+ int_str val, name; |
|
184 | 186 |
|
185 |
- name.s = name_s; |
|
186 |
- if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) { |
|
187 |
+ name.s = did_name; |
|
188 |
+ if (search_first_avp(AVP_TRACK_TO | AVP_NAME_STR, name, &val, 0)) { |
|
187 | 189 |
*did = val.s; |
188 | 190 |
return 1; |
189 | 191 |
} |
... | ... |
@@ -196,11 +198,10 @@ int get_to_did(str* did, struct sip_msg* msg) |
196 | 198 |
*/ |
197 | 199 |
int get_from_did(str* did, struct sip_msg* msg) |
198 | 200 |
{ |
199 |
- static str name_s = STR_STATIC_INIT(AVP_DID); |
|
200 |
- int_str name, val; |
|
201 |
+ int_str val, name; |
|
201 | 202 |
|
202 |
- name.s = name_s; |
|
203 |
- if (search_first_avp(AVP_CLASS_USER | AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) { |
|
203 |
+ name.s = did_name; |
|
204 |
+ if (search_first_avp(AVP_TRACK_FROM | AVP_NAME_STR, name, &val, 0)) { |
|
204 | 205 |
*did = val.s; |
205 | 206 |
return 1; |
206 | 207 |
} |
... | ... |
@@ -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; |