This reverts commit 6bdbd8e2ab1ec15695cc156ff74f20af799a947b.
91 | 91 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,51 @@ |
1 |
+# |
|
2 |
+# ser osp module. |
|
3 |
+# |
|
4 |
+# This module enables ser to communicate with an Open Settlement |
|
5 |
+# Protocol (OSP) server. The Open Settlement Protocol is an ETSI |
|
6 |
+# defined standard for Inter-Domain VoIP pricing, authorization |
|
7 |
+# and usage exchange. The technical specifications for OSP |
|
8 |
+# (ETSI TS 101 321 V4.1.1) are available at www.etsi.org. |
|
9 |
+# |
|
10 |
+# Uli Abend was the original contributor to this module. |
|
11 |
+# |
|
12 |
+# Copyright (C) 2001-2005 Fhg Fokus |
|
13 |
+# |
|
14 |
+# This file is part of ser, a free SIP server. |
|
15 |
+# |
|
16 |
+# ser is free software; you can redistribute it and/or modify |
|
17 |
+# it under the terms of the GNU General Public License as published by |
|
18 |
+# the Free Software Foundation; either version 2 of the License, or |
|
19 |
+# (at your option) any later version |
|
20 |
+# |
|
21 |
+# For a license to use the ser software under conditions |
|
22 |
+# other than those described here, or to purchase support for this |
|
23 |
+# software, please contact iptel.org by e-mail at the following addresses: |
|
24 |
+# info@iptel.org |
|
25 |
+# |
|
26 |
+# ser is distributed in the hope that it will be useful, |
|
27 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
28 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
29 |
+# GNU General Public License for more details. |
|
30 |
+# |
|
31 |
+# You should have received a copy of the GNU General Public License |
|
32 |
+# along with this program; if not, write to the Free Software |
|
33 |
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
34 |
+# |
|
35 |
+ |
|
36 |
+# WARNING: do not run this directly, it should be run by the master Makefile |
|
37 |
+ |
|
38 |
+include ../../Makefile.defs |
|
39 |
+auto_gen= |
|
40 |
+NAME=osp.so |
|
41 |
+DEFS+=-D_POSIX_THREADS |
|
42 |
+ |
|
43 |
+LIBS=$(shell if [ -f /usr/local/lib/libosptk.a ]; then echo "-losptk" ; else echo "-losp" ; fi) |
|
44 |
+LIBS+=-lssl -lcrypto -lpthread -lm |
|
45 |
+ |
|
46 |
+ |
|
47 |
+ |
|
48 |
+DEFS+=-DSER_MOD_INTERFACE |
|
49 |
+ |
|
50 |
+include ../../Makefile.modules |
|
51 |
+ |
0 | 52 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,564 @@ |
1 |
+ OSP Module for Secure, Multi-Lateral Peering |
|
2 |
+ |
|
3 |
+ Ulrich Abend |
|
4 |
+ |
|
5 |
+ FhG Fokus |
|
6 |
+ |
|
7 |
+ Edited by |
|
8 |
+ |
|
9 |
+ Di-Shi Sun |
|
10 |
+ |
|
11 |
+ Copyright (c) 2003 FhG Fokus |
|
12 |
+ |
|
13 |
+ --------------------------------------------------------------------------- |
|
14 |
+ |
|
15 |
+ Table of Contents |
|
16 |
+ |
|
17 |
+ [1]User's Guide |
|
18 |
+ |
|
19 |
+ [2]Overview |
|
20 |
+ |
|
21 |
+ [3]Dependencies |
|
22 |
+ |
|
23 |
+ [4]Exported Parameters |
|
24 |
+ |
|
25 |
+ [5]sp1_uri, sp2_uri |
|
26 |
+ |
|
27 |
+ [6]device_ip |
|
28 |
+ |
|
29 |
+ [7]token_format |
|
30 |
+ |
|
31 |
+ [8]private_key, local_certificate, |
|
32 |
+ ca_certificates |
|
33 |
+ |
|
34 |
+ [9]sp1_weight, sp2_weight |
|
35 |
+ |
|
36 |
+ [10]device_port |
|
37 |
+ |
|
38 |
+ [11]enable_crypto_hardware_support |
|
39 |
+ |
|
40 |
+ [12]ssl_lifetime |
|
41 |
+ |
|
42 |
+ [13]persistence |
|
43 |
+ |
|
44 |
+ [14]retry_delay |
|
45 |
+ |
|
46 |
+ [15]retry_limit |
|
47 |
+ |
|
48 |
+ [16]timeout |
|
49 |
+ |
|
50 |
+ [17]max_destinations |
|
51 |
+ |
|
52 |
+ [18]validate_call_id |
|
53 |
+ |
|
54 |
+ [19]Exported Functions |
|
55 |
+ |
|
56 |
+ [20]checkospheader() |
|
57 |
+ |
|
58 |
+ [21]validateospheader() |
|
59 |
+ |
|
60 |
+ [22]requestosprouting() |
|
61 |
+ |
|
62 |
+ [23]preparefirstosproute() |
|
63 |
+ |
|
64 |
+ [24]preparenextosproute() |
|
65 |
+ |
|
66 |
+ [25]prepareallosproute() |
|
67 |
+ |
|
68 |
+ [26]reportospusage() |
|
69 |
+ |
|
70 |
+ [27]Developer's Guide |
|
71 |
+ |
|
72 |
+ [28]Frequently Asked Questions |
|
73 |
+ |
|
74 |
+ --------------------------------------------------------------------------- |
|
75 |
+ |
|
76 |
+ User's Guide |
|
77 |
+ |
|
78 |
+Overview |
|
79 |
+ |
|
80 |
+ The OSP module enables SER to support secure, multi-lateral peering using |
|
81 |
+ the OSP standard defined by ETSI (TS 101 321 V4.1.1). This module will |
|
82 |
+ enable your SER to: |
|
83 |
+ |
|
84 |
+ * Send a peering authorization request to a peering server. |
|
85 |
+ |
|
86 |
+ * Validate a digitally signed peering authorization token received in a |
|
87 |
+ SIP INVITE message. |
|
88 |
+ |
|
89 |
+ * Report usage information to a peering server. |
|
90 |
+ |
|
91 |
+ --------------------------------------------------------------------------- |
|
92 |
+ |
|
93 |
+Dependencies |
|
94 |
+ |
|
95 |
+ The OSP module depends on the following modules which must be loaded |
|
96 |
+ before the OSP module. |
|
97 |
+ |
|
98 |
+ * textops -- text based operation |
|
99 |
+ |
|
100 |
+ * OSP Toolkit -- The OSP Toolkit, available from www.sipfoundry.org/OSP, |
|
101 |
+ must be built before building SER with the OSP Module. See the |
|
102 |
+ document "Multi-lateral Peering with SER", located at |
|
103 |
+ http://developer.berlios.de/docman/?group_id=3799 for build |
|
104 |
+ instructions. |
|
105 |
+ |
|
106 |
+ --------------------------------------------------------------------------- |
|
107 |
+ |
|
108 |
+Exported Parameters |
|
109 |
+ |
|
110 |
+ sp1_uri, sp2_uri |
|
111 |
+ |
|
112 |
+ These string parameters define peering servers to be used for requesting |
|
113 |
+ peering authorization and routing information. sp1_uri must be configured. |
|
114 |
+ sp2_uri is required only if there are two peering servers. Each peering |
|
115 |
+ server address takes the form of a standard URL, and consists of up to |
|
116 |
+ four components: |
|
117 |
+ |
|
118 |
+ * An optional indication of the protocol to be used for communicating |
|
119 |
+ with the peering server. Both HTTP and HTTP secured with SSL/TLS are |
|
120 |
+ supported and are indicated by "http://" and "https://" respectively. |
|
121 |
+ If the protocol is not explicitly indicated, the SER defaults to HTTP |
|
122 |
+ secured with SSL. |
|
123 |
+ |
|
124 |
+ * The Internet domain name for the peering server. An IP address may |
|
125 |
+ also be used, provided it is enclosed in square brackets such as |
|
126 |
+ [172.16.1.1]. |
|
127 |
+ |
|
128 |
+ * An optional TCP port number for communicating with the peering server. |
|
129 |
+ If the port number is omitted, the SER defaults to port 1080 (for |
|
130 |
+ HTTP) or port 1443 (for HTTP secured with SSL). |
|
131 |
+ |
|
132 |
+ The uniform resource identifier for requests to the peering server. |
|
133 |
+ This component is not optional and must be included. |
|
134 |
+ |
|
135 |
+ Example 1. Setting the OSP servers |
|
136 |
+ |
|
137 |
+ modparam ("osp", "sp1_uri", "http://osptestserver.transnexus.com:1080/osp") |
|
138 |
+ modparam ("osp", "sp2_uri", "https://[1.2.3.4]:1443/osp") |
|
139 |
+ |
|
140 |
+ |
|
141 |
+ --------------------------------------------------------------------------- |
|
142 |
+ |
|
143 |
+ device_ip |
|
144 |
+ |
|
145 |
+ device_ip (string) is a recommended parameter that explicitly defines the |
|
146 |
+ IP address of SER in an peering request message (as SourceAlternate |
|
147 |
+ type=transport). The IP address must be in brackets as shown in the |
|
148 |
+ example below. |
|
149 |
+ |
|
150 |
+ Example 2. Setting the device IP address |
|
151 |
+ |
|
152 |
+ modparam ("osp", "device_ip", "[1.1.1.1]") |
|
153 |
+ |
|
154 |
+ |
|
155 |
+ --------------------------------------------------------------------------- |
|
156 |
+ |
|
157 |
+ token_format |
|
158 |
+ |
|
159 |
+ When SER receives a SIP INVITE with a peering token, the OSP Module will |
|
160 |
+ validate the token to determine whether or not the call has been |
|
161 |
+ authorized by a peering server. Peering tokens may, or may not, be |
|
162 |
+ digitally signed. The token format (integer) parameter defines if SER will |
|
163 |
+ validate signed or unsigned tokens or both. The values for token format |
|
164 |
+ are defined below. The default value is 2. |
|
165 |
+ |
|
166 |
+ 0 - Validate only signed tokens. Calls with valid signed tokens are |
|
167 |
+ allowed. |
|
168 |
+ |
|
169 |
+ 1 - Validate only unsigned tokens. Calls with valid unsigned tokens are |
|
170 |
+ allowed. |
|
171 |
+ |
|
172 |
+ 2 - Validate both signed and unsigned tokens are allowed. Calls with valid |
|
173 |
+ tokens are allowed. |
|
174 |
+ |
|
175 |
+ Example 3. Setting the token format |
|
176 |
+ |
|
177 |
+ modparam ("osp", "token_format", 2) |
|
178 |
+ |
|
179 |
+ |
|
180 |
+ --------------------------------------------------------------------------- |
|
181 |
+ |
|
182 |
+ private_key, local_certificate, ca_certificates |
|
183 |
+ |
|
184 |
+ These parameters identify files are used for validating peering |
|
185 |
+ authorization tokens and establishing a secure channel between SER and a |
|
186 |
+ peering server using SSL. The files are generated using the 'Enroll' |
|
187 |
+ utility from the OSP Toolkit. By default, the proxy will look for |
|
188 |
+ pkey.pem, localcert.pem, and cacart_0.pem in the default configuration |
|
189 |
+ directory. The default config directory is set at compile time using |
|
190 |
+ CFG_DIR and defaults to /usr/local/etc/ser/. The files may be copied to |
|
191 |
+ the expected file location or the parameters below may be changed. |
|
192 |
+ |
|
193 |
+ Example 4. Set authorization files |
|
194 |
+ |
|
195 |
+ If the default CFG_DIR value was used at compile time, the files will be |
|
196 |
+ loaded from: |
|
197 |
+ |
|
198 |
+ modparam ("osp", "private_key", "/usr/local/etc/ser/pkey.pem") |
|
199 |
+ modparam ("osp", "local_certificate", "/usr/local/etc/ser/localcert.pem") |
|
200 |
+ modparam ("osp", "ca_certificates", "/usr/local/etc/ser/cacert.pem") |
|
201 |
+ |
|
202 |
+ |
|
203 |
+ --------------------------------------------------------------------------- |
|
204 |
+ |
|
205 |
+ sp1_weight, sp2_weight |
|
206 |
+ |
|
207 |
+ These sp_weight (integer) parameters are used for load balancing peering |
|
208 |
+ requests to peering servers. These parameters are most effective when |
|
209 |
+ configured as factors of 1000. For example, if sp1_uri should manage twice |
|
210 |
+ the traffic load of sp2_uri, then set sp1_weight to 2000 and sp2_weight to |
|
211 |
+ 1000. Shared load balancing between peering servers is recommended. |
|
212 |
+ However, peering servers can be configured as primary and backup by |
|
213 |
+ assigning a sp_weight of 0 to the primary server and a non-zero sp_weight |
|
214 |
+ to the back-up server. The default values for sp1_weight and sp2_weight |
|
215 |
+ are 1000. |
|
216 |
+ |
|
217 |
+ Example 5. Setting the OSP server weights |
|
218 |
+ |
|
219 |
+ modparam ("osp", "sp1_weight", 1000) |
|
220 |
+ |
|
221 |
+ |
|
222 |
+ --------------------------------------------------------------------------- |
|
223 |
+ |
|
224 |
+ device_port |
|
225 |
+ |
|
226 |
+ The device_port (string) parameter is an optional field which includes the |
|
227 |
+ SIP port being used by SER in the peering request (as SourceAlternate |
|
228 |
+ type=network) to the peering server. If is not configured, this |
|
229 |
+ information is not included in the peering request. This field is useful |
|
230 |
+ if multiple SERs are running on the same Linux computer since it enables |
|
231 |
+ the peering server to administer different peering policies based on |
|
232 |
+ different SIP proxies. |
|
233 |
+ |
|
234 |
+ Example 6. Setting the device port |
|
235 |
+ |
|
236 |
+ modparam ("osp", "device_port", "5060") |
|
237 |
+ |
|
238 |
+ |
|
239 |
+ --------------------------------------------------------------------------- |
|
240 |
+ |
|
241 |
+ enable_crypto_hardware_support |
|
242 |
+ |
|
243 |
+ The enable_crypto_hardware_support (integer) parameter is used to set the |
|
244 |
+ cryptographic hardware acceleration engine in the openssl library. The |
|
245 |
+ default value is 0 (no crypto hardware is present). If crypto hardware is |
|
246 |
+ used, the value should be set to 1. |
|
247 |
+ |
|
248 |
+ Example 7. Setting the hardware support |
|
249 |
+ |
|
250 |
+ modparam ("osp", "enable_crypto_hardware_support", 0) |
|
251 |
+ |
|
252 |
+ |
|
253 |
+ --------------------------------------------------------------------------- |
|
254 |
+ |
|
255 |
+ ssl_lifetime |
|
256 |
+ |
|
257 |
+ The ssl_lifetime (integer) parameter defines the lifetime, in seconds, of |
|
258 |
+ a single SSL session key. Once this time limit is exceeded, the OSP Module |
|
259 |
+ will negotiate a new session key. Communication exchanges in progress will |
|
260 |
+ not be interrupted when this time limit expires. This is an optional field |
|
261 |
+ with default value is 200 seconds. |
|
262 |
+ |
|
263 |
+ Example 8. Setting the ssl lifetime |
|
264 |
+ |
|
265 |
+ modparam ("osp", "ssl_lifetime", 200) |
|
266 |
+ |
|
267 |
+ |
|
268 |
+ --------------------------------------------------------------------------- |
|
269 |
+ |
|
270 |
+ persistence |
|
271 |
+ |
|
272 |
+ The persistence (integer) parameter defines the time, in seconds, that an |
|
273 |
+ HTTP connection should be maintained after the completion of a |
|
274 |
+ communication exchange. The OSP Module will maintain the connection for |
|
275 |
+ this time period in anticipation of future communication exchanges to the |
|
276 |
+ same peering server. |
|
277 |
+ |
|
278 |
+ Example 9. Setting the persistence |
|
279 |
+ |
|
280 |
+ modparam ("osp", "persistence", 1000) |
|
281 |
+ |
|
282 |
+ |
|
283 |
+ --------------------------------------------------------------------------- |
|
284 |
+ |
|
285 |
+ retry_delay |
|
286 |
+ |
|
287 |
+ The retry_delay (integer) parameter defines the time, in seconds, between |
|
288 |
+ retrying connection attempts to an OSP peering server. After exhausting |
|
289 |
+ all peering servers the OSP Module will delay for this amount of time |
|
290 |
+ before resuming connection attempts. This is an optional field with |
|
291 |
+ default value is 1 second. |
|
292 |
+ |
|
293 |
+ Example 10. Setting the retry delay |
|
294 |
+ |
|
295 |
+ modparam ("osp", "retry_delay", 1) |
|
296 |
+ |
|
297 |
+ |
|
298 |
+ --------------------------------------------------------------------------- |
|
299 |
+ |
|
300 |
+ retry_limit |
|
301 |
+ |
|
302 |
+ The retry_limit (integer) parameter defines the maximum number of retries |
|
303 |
+ for connection attempts to an peering server. If no connection is |
|
304 |
+ established after this many retry attempts to all peering servers, the OSP |
|
305 |
+ Module will cease connection attempts and return appropriate error codes. |
|
306 |
+ This number does not count the initial connection attempt, so that a |
|
307 |
+ retry_limit of 1 will result in a total of two connection attempts to |
|
308 |
+ every peering server. The default value is 2. |
|
309 |
+ |
|
310 |
+ Example 11. Setting the retry limit |
|
311 |
+ |
|
312 |
+ modparam ("osp", "retry_limit", 2) |
|
313 |
+ |
|
314 |
+ |
|
315 |
+ --------------------------------------------------------------------------- |
|
316 |
+ |
|
317 |
+ timeout |
|
318 |
+ |
|
319 |
+ The timeout (integer) parameter defines the maximum time in milliseconds, |
|
320 |
+ to wait for a response from an peering server. If no response is received |
|
321 |
+ within this time, the current connection is aborted and the OSP Module |
|
322 |
+ attempts to contact the next peering server. The default value is 10 |
|
323 |
+ seconds. |
|
324 |
+ |
|
325 |
+ Example 12. Setting the timeout |
|
326 |
+ |
|
327 |
+ modparam ("osp", "timeout", 10) |
|
328 |
+ |
|
329 |
+ |
|
330 |
+ --------------------------------------------------------------------------- |
|
331 |
+ |
|
332 |
+ max_destinations |
|
333 |
+ |
|
334 |
+ The max_destinations (integer) parameter defines the maximum number of |
|
335 |
+ destinations that SER requests the peering server to return in a peering |
|
336 |
+ response. The default value is 5. |
|
337 |
+ |
|
338 |
+ Example 13. Setting the number of destination |
|
339 |
+ |
|
340 |
+ modparam ("osp", "max_destinations", 5) |
|
341 |
+ |
|
342 |
+ |
|
343 |
+ --------------------------------------------------------------------------- |
|
344 |
+ |
|
345 |
+ validate_call_id |
|
346 |
+ |
|
347 |
+ The validate_call_id (integer) parameter instructs the OSP module to |
|
348 |
+ validate call id in the peering token. If this value is set to 1, the OSP |
|
349 |
+ Module validates that the call id in the SIP INVITE message matches the |
|
350 |
+ call id in the peering token. If they do not match the INVITE is rejected. |
|
351 |
+ If this value is set to 0, the OSP Module will not validate the call id in |
|
352 |
+ the peering token. The default value is 1 |
|
353 |
+ |
|
354 |
+ Example 14. Instructing the module to validate call id |
|
355 |
+ |
|
356 |
+ modparam ("osp", "validate_call_id", 1) |
|
357 |
+ |
|
358 |
+ |
|
359 |
+ --------------------------------------------------------------------------- |
|
360 |
+ |
|
361 |
+Exported Functions |
|
362 |
+ |
|
363 |
+ checkospheader() |
|
364 |
+ |
|
365 |
+ This function checks for the existence of the OSP-Auth-Token header field. |
|
366 |
+ |
|
367 |
+ Example 15. checkospheader usage |
|
368 |
+ |
|
369 |
+ ... |
|
370 |
+ if (checkospheader()) { |
|
371 |
+ log("OSP header field found.\n"); |
|
372 |
+ } else { |
|
373 |
+ log("no OSP header field present\n"); |
|
374 |
+ }; |
|
375 |
+ ... |
|
376 |
+ |
|
377 |
+ |
|
378 |
+ --------------------------------------------------------------------------- |
|
379 |
+ |
|
380 |
+ validateospheader() |
|
381 |
+ |
|
382 |
+ This function validates an OSP-Token specified in the OSP-Auth-Tokenheader |
|
383 |
+ field of the SIP message. If a peering token is present, it will be |
|
384 |
+ validated locally. If no OSP header is found or the header token is |
|
385 |
+ invalid or expired, -1 is returned; on successful validation 1 is |
|
386 |
+ returned. |
|
387 |
+ |
|
388 |
+ Example 16. validateospheader usage |
|
389 |
+ |
|
390 |
+ ... |
|
391 |
+ if (validateospheader()) { |
|
392 |
+ log("valid OSP header found\n"); |
|
393 |
+ } else { |
|
394 |
+ log("OSP header not found, invalid or expired\n"); |
|
395 |
+ }; |
|
396 |
+ ... |
|
397 |
+ |
|
398 |
+ |
|
399 |
+ --------------------------------------------------------------------------- |
|
400 |
+ |
|
401 |
+ requestosprouting() |
|
402 |
+ |
|
403 |
+ This function launches a query to the peering server requesting the IP |
|
404 |
+ address of one or more destination peers serving the called party. If |
|
405 |
+ destination peers are available, the peering server will return the IP |
|
406 |
+ address and a peering authorization token for each destination peer. The |
|
407 |
+ OSP-Auth-Token Header field is inserted into the SIP message and the SIP |
|
408 |
+ uri is rewritten to the IP address of destination peer provided by the |
|
409 |
+ peering server. |
|
410 |
+ |
|
411 |
+ The address of the called party must be a valid E164 number, otherwise |
|
412 |
+ this function returns -1. If the transaction was accepted by the peering |
|
413 |
+ server, the uri is being rewritten and 1 returned, on errors (peering |
|
414 |
+ servers are not available, authentication failed or there is no route to |
|
415 |
+ destination or the route is blocked) -1 is returned. |
|
416 |
+ |
|
417 |
+ Example 17. requestosprouting usage |
|
418 |
+ |
|
419 |
+ ... |
|
420 |
+ if (requestosprouting()) { |
|
421 |
+ log("successfully queried OSP server, now relaying call\n"); |
|
422 |
+ } else { |
|
423 |
+ log("Authorization request was rejected from OSP server\n"); |
|
424 |
+ }; |
|
425 |
+ ... |
|
426 |
+ |
|
427 |
+ |
|
428 |
+ --------------------------------------------------------------------------- |
|
429 |
+ |
|
430 |
+ preparefirstosproute() |
|
431 |
+ |
|
432 |
+ This function tries to prepare the INVITE to be forwarded or redirected |
|
433 |
+ using the first destination in the list returned by the peering server. If |
|
434 |
+ the route could not be prepared, the function returns 'FALSE' back to the |
|
435 |
+ script, which can then decide how to handle the failure. |
|
436 |
+ |
|
437 |
+ Example 18. preparefirstosproute usage |
|
438 |
+ |
|
439 |
+ ... |
|
440 |
+ if (preparefirstosproute ()) { |
|
441 |
+ log("successfully prepared the first route, now relaying call\n"); |
|
442 |
+ } else { |
|
443 |
+ log("could not prepare the route. The first destination was blocked\n"); |
|
444 |
+ }; |
|
445 |
+ ... |
|
446 |
+ |
|
447 |
+ |
|
448 |
+ --------------------------------------------------------------------------- |
|
449 |
+ |
|
450 |
+ preparenextosproute() |
|
451 |
+ |
|
452 |
+ Once the call could not be completed through the first destination, this |
|
453 |
+ function tries to prepare the INVITE message using the next destination in |
|
454 |
+ the list returned by the peering Server. If it succeeds in preparing the |
|
455 |
+ route, the message is either redirected or relayed on (using the t_relay |
|
456 |
+ call), or else the function returns 'FALSE' back to the script, which can |
|
457 |
+ then decide how to handle the failure. |
|
458 |
+ |
|
459 |
+ Example 19. preparenextosproute usage |
|
460 |
+ |
|
461 |
+ ... |
|
462 |
+ if (preparenextosproute ()) { |
|
463 |
+ log("successfully prepared the next route, now relaying call\n"); |
|
464 |
+ } else { |
|
465 |
+ log("could not prepare the route. No next destination available\n"); |
|
466 |
+ }; |
|
467 |
+ ... |
|
468 |
+ |
|
469 |
+ |
|
470 |
+ --------------------------------------------------------------------------- |
|
471 |
+ |
|
472 |
+ prepareallosproute() |
|
473 |
+ |
|
474 |
+ This function tries to prepare all the routes in the list returned by the |
|
475 |
+ peering server. The message is then either forked off or redirected to the |
|
476 |
+ destination. If unsuccessful in preparing the routes a SIP 500 is sent |
|
477 |
+ back and a trace message is logged. |
|
478 |
+ |
|
479 |
+ Example 20. prepareallosproute usage |
|
480 |
+ |
|
481 |
+... |
|
482 |
+if (prepareallosproute ()) { |
|
483 |
+ log("successfully prepared the routes, now either forking or redirecting the call\n"); |
|
484 |
+} else { |
|
485 |
+ log("could not prepare the route. No destination available\n"); |
|
486 |
+}; |
|
487 |
+... |
|
488 |
+ |
|
489 |
+ |
|
490 |
+ --------------------------------------------------------------------------- |
|
491 |
+ |
|
492 |
+ reportospusage() |
|
493 |
+ |
|
494 |
+ This function should be called after receiving a BYE message. If the |
|
495 |
+ message contains an OSP cookie, the function will forward originating |
|
496 |
+ and/or terminating duration usage information to a peering server. The |
|
497 |
+ function returns TRUE if the BYE includes an OSP cookie. The actual usage |
|
498 |
+ message will be send on a different thread and will not delay BYE |
|
499 |
+ processing. The function should be called before relaying the message. |
|
500 |
+ |
|
501 |
+ Example 21. reportospusage usage |
|
502 |
+ |
|
503 |
+... |
|
504 |
+if (reportospusage ()) { |
|
505 |
+ log("OSP call duration usage will be reported\n"); |
|
506 |
+} else { |
|
507 |
+ log("The BYE message does not include OSP information, it was not authorized by an OSP server\n"); |
|
508 |
+}; |
|
509 |
+... |
|
510 |
+ |
|
511 |
+ |
|
512 |
+ --------------------------------------------------------------------------- |
|
513 |
+ |
|
514 |
+ Developer's Guide |
|
515 |
+ |
|
516 |
+ The functions of the OSP modules are not used by other SER modules. |
|
517 |
+ |
|
518 |
+ --------------------------------------------------------------------------- |
|
519 |
+ |
|
520 |
+ Frequently Asked Questions |
|
521 |
+ |
|
522 |
+ Q: [29]What platforms does this module work on? |
|
523 |
+ |
|
524 |
+ Q: [30]Where can I get more information on this module? |
|
525 |
+ |
|
526 |
+ Q: [31]Where can I get more information on OSP? |
|
527 |
+ |
|
528 |
+ Q: [32]How do I obtain an OSP server for testing? |
|
529 |
+ |
|
530 |
+ Q: [33]How are the exported functions used by the OSP module? |
|
531 |
+ |
|
532 |
+ Q: What platforms does this module work on? |
|
533 |
+ |
|
534 |
+ A: The module has been implemented using Linux, the underlying toolkit and |
|
535 |
+ the module code itself should compile and work on Solaris, *BSD, and |
|
536 |
+ probably most other unix platforms with ssl and pthreads available, but |
|
537 |
+ the OSP Module has only been tested Linux. |
|
538 |
+ |
|
539 |
+ Q: Where can I get more information on this module? |
|
540 |
+ |
|
541 |
+ A: Please see the document "Multi-Lateral Peering with SER" located at |
|
542 |
+ http://developer.berlios.de/docman/?group_id=3799 or post a message on the |
|
543 |
+ SER mailing list. You may also send an e-mail to support@transnexus.com. |
|
544 |
+ |
|
545 |
+ Q: Where can I get more information on OSP? |
|
546 |
+ |
|
547 |
+ A: The OSP technical specification (ETSI TS 101 321) may be obtained from |
|
548 |
+ www.etsi.org. Additional documentation on OSP is available from |
|
549 |
+ www.sipfoundry.org. |
|
550 |
+ |
|
551 |
+ Q: How do I obtain an OSP server for testing? |
|
552 |
+ |
|
553 |
+ A: OSP peering servers are available from the following sources: |
|
554 |
+ |
|
555 |
+ * OpenOSP server from www.sipfoundry.org is a complete OSP server |
|
556 |
+ |
|
557 |
+ * RAMS from www.sipfoundry.org is a new java based open source OSP |
|
558 |
+ |
|
559 |
+ * TransNexus provides free access to a hosted OSP peering server on the |
|
560 |
+ Internet for testing. Contact support@transnexus.com. |
|
561 |
+ |
|
562 |
+ Q: How are the exported functions used by the OSP module? |
|
563 |
+ |
|
564 |
+ A: See sample-osp-ser.cfg in modules/osp/etc for examples |
0 | 565 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,62 @@ |
1 |
+ |
|
2 |
+June 23, 2005 |
|
3 |
+ Implemented routing and authorization validation. The module can: |
|
4 |
+ o Request authorization and routing information from an OSP server |
|
5 |
+ o Use provided routes to: |
|
6 |
+ o Redirect the originating UI to all routes OR |
|
7 |
+ o Try all routes simultaneously using parallel forking OR |
|
8 |
+ o Try routes in the order they were received using sequential forking |
|
9 |
+ o Add and retrieve P-OSP-Auth-Token header |
|
10 |
+ o Perform local validation of the P-OSP-Auth-Token |
|
11 |
+ |
|
12 |
+September 12, 2005 |
|
13 |
+ o Bug 4863 - the module will remove OSP Auth token from the incoming Invite |
|
14 |
+ after validating the token and before forwarding Invite to the next hop. |
|
15 |
+ o Bug 4891 - added a new flag 'validate_call_id' for disabling call id |
|
16 |
+ validation in OSP tokens. The value is optional, call id validation |
|
17 |
+ can be turned off by setting the value to 0 (No). It may be used for |
|
18 |
+ interoperability issues with some OSP clients sending invalid call ids |
|
19 |
+ in Authorization Requests. |
|
20 |
+ o Bug 4986 - changed return value for 'prepareallosproutes' from |
|
21 |
+ 0 - stop routing logic to 1 - true |
|
22 |
+ o Bug 5039 - changed return value for 'preparenextosproute' when there is |
|
23 |
+ no more routes from 0 - stop routing logic to -1 - false |
|
24 |
+ o Bug 5039 - changed return value for 'preparenextosproute' when there is |
|
25 |
+ o Bug 4893 - sequential routing (in failure_route[1]) now checks for code |
|
26 |
+ 487 (Canceled) before trying the next OSP route. |
|
27 |
+ Note - this check does not work when UAC cancels the call while SER is |
|
28 |
+ trying to connect to an unresponsive UAS, code 408 (time out) masks |
|
29 |
+ code 487. See new function 't_was_cancelled' in the 'tm' module. |
|
30 |
+ o Bug 4892 - removed trailing binary chars from some log messages. |
|
31 |
+ o Bug 4987 - fixed a compile time error on Solaris |
|
32 |
+ o Bug 4946 - added README file |
|
33 |
+ |
|
34 |
+September 26, 2005 |
|
35 |
+ o Bug 5094 - don't route the call if OSP token validation fails. |
|
36 |
+ o Bug 5109 - send "100 Trying" message before requesting OSP routes. |
|
37 |
+ o Bug 5111 - fixed typos in error messages. |
|
38 |
+ o Bug 5153 - removed trailing binary chars from P-OSP-Auth-Token header |
|
39 |
+ value. |
|
40 |
+ |
|
41 |
+October 3, 2005 |
|
42 |
+ o Report OSP usage indications after the call set-up and tear down |
|
43 |
+ transactions complete. |
|
44 |
+ |
|
45 |
+October 17, 2005 |
|
46 |
+ o Report call set-up usage indication after receiving either 200 or 202. |
|
47 |
+ o Report termination cause code for duration usage indications as 10,016 |
|
48 |
+ instead of 1,016. |
|
49 |
+ o Improved error checking and logging. |
|
50 |
+ o Bug 5366 - removed a memory leak in usage reporting logic. |
|
51 |
+ |
|
52 |
+October 31, 2005 |
|
53 |
+ o Copied files from cvs.berlios.de:/cvsroot/osp-module to cvs.berlios.de:/cvsroot/ser |
|
54 |
+ |
|
55 |
+2006 September 5 |
|
56 |
+ o Using BRAND_ROUTE approach to add route specific header to avoid sending |
|
57 |
+ an OSP token to a non-OSP destination. |
|
58 |
+ o Using called number in Request-Line for token validation and auth request. |
|
59 |
+ o Sending DeviceInfo in "[x.x.x.x]" format in OSP AuthReq messages. |
|
60 |
+ o Using fromtag in RR to report who releases the call first. |
|
61 |
+ o Using AVP to add RR paramters for inserting OSP cookies. |
|
62 |
+ |
0 | 63 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,473 @@ |
1 |
+/* |
|
2 |
+ * ser osp module. |
|
3 |
+ * |
|
4 |
+ * This module enables ser to communicate with an Open Settlement |
|
5 |
+ * Protocol (OSP) server. The Open Settlement Protocol is an ETSI |
|
6 |
+ * defined standard for Inter-Domain VoIP pricing, authorization |
|
7 |
+ * and usage exchange. The technical specifications for OSP |
|
8 |
+ * (ETSI TS 101 321 V4.1.1) are available at www.etsi.org. |
|
9 |
+ * |
|
10 |
+ * Uli Abend was the original contributor to this module. |
|
11 |
+ * |
|
12 |
+ * Copyright (C) 2001-2005 Fhg Fokus |
|
13 |
+ * |
|
14 |
+ * This file is part of ser, a free SIP server. |
|
15 |
+ * |
|
16 |
+ * ser is free software; you can redistribute it and/or modify |
|
17 |
+ * it under the terms of the GNU General Public License as published by |
|
18 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
19 |
+ * (at your option) any later version |
|
20 |
+ * |
|
21 |
+ * For a license to use the ser software under conditions |
|
22 |
+ * other than those described here, or to purchase support for this |
|
23 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
24 |
+ * info@iptel.org |
|
25 |
+ * |
|
26 |
+ * ser is distributed in the hope that it will be useful, |
|
27 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
28 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
29 |
+ * GNU General Public License for more details. |
|
30 |
+ * |
|
31 |
+ * You should have received a copy of the GNU General Public License |
|
32 |
+ * along with this program; if not, write to the Free Software |
|
33 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
34 |
+ */ |
|
35 |
+ |
|
36 |
+#include <string.h> |
|
37 |
+#include <sys/socket.h> |
|
38 |
+#include <netinet/in.h> |
|
39 |
+#include <arpa/inet.h> |
|
40 |
+#include <stdio.h> |
|
41 |
+#include "../../str.h" |
|
42 |
+#include "../../dprint.h" |
|
43 |
+#include "../../usr_avp.h" |
|
44 |
+#include "destination.h" |
|
45 |
+#include "usage.h" |
|
46 |
+ |
|
47 |
+/* Name of AVP of OSP destination list */ |
|
48 |
+const str OSP_ORIGDEST_NAME = {"_osp_orig_dests_", 16}; |
|
49 |
+const str OSP_TERMDEST_NAME = {"_osp_term_dests_", 16}; |
|
50 |
+ |
|
51 |
+static int ospSaveDestination(osp_dest* dest, const str* name); |
|
52 |
+static void ospRecordCode(int code, osp_dest* dest); |
|
53 |
+static int ospIsToReportUsage(int code); |
|
54 |
+ |
|
55 |
+/* |
|
56 |
+ * Initialize destination structure |
|
57 |
+ * param dest Destination data structure |
|
58 |
+ * return initialized destination sturcture |
|
59 |
+ */ |
|
60 |
+osp_dest* ospInitDestination( |
|
61 |
+ osp_dest* dest) |
|
62 |
+{ |
|
63 |
+ LOG(L_DBG, "osp: ospInitDestion\n"); |
|
64 |
+ |
|
65 |
+ memset(dest, 0, sizeof(osp_dest)); |
|
66 |
+ |
|
67 |
+ dest->callidsize = sizeof(dest->callid); |
|
68 |
+ dest->tokensize = sizeof(dest->token); |
|
69 |
+ |
|
70 |
+ LOG(L_DBG, "osp: callidsize '%d' tokensize '%d'\n", dest->callidsize, dest->tokensize); |
|
71 |
+ |
|
72 |
+ return dest; |
|
73 |
+} |
|
74 |
+ |
|
75 |
+/* |
|
76 |
+ * Save destination as an AVP |
|
77 |
+ * name - OSP_ORIGDEST_NAME / OSP_TERMDEST_NAME |
|
78 |
+ * value - osp_dest wrapped in a string |
|
79 |
+ * param dest Destination structure |
|
80 |
+ * param name Name of AVP |
|
81 |
+ * return 0 success, -1 failure |
|
82 |
+ */ |
|
83 |
+static int ospSaveDestination( |
|
84 |
+ osp_dest* dest, |
|
85 |
+ const str* name) |
|
86 |
+{ |
|
87 |
+ str wrapper; |
|
88 |
+ int result = -1; |
|
89 |
+ |
|
90 |
+ LOG(L_DBG, "osp: ospSaveDestination\n"); |
|
91 |
+ |
|
92 |
+ wrapper.s = (char*)dest; |
|
93 |
+ wrapper.len = sizeof(osp_dest); |
|
94 |
+ |
|
95 |
+ /* |
|
96 |
+ * add_avp will make a private copy of both the name and value in shared memory |
|
97 |
+ * which will be released by TM at the end of the transaction |
|
98 |
+ */ |
|
99 |
+ if (add_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)*name, (int_str)wrapper) == 0) { |
|
100 |
+ result = 0; |
|
101 |
+ LOG(L_DBG, "osp: destination saved\n"); |
|
102 |
+ } else { |
|
103 |
+ LOG(L_ERR, "osp: ERROR: failed to save destination\n"); |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ return result; |
|
107 |
+} |
|
108 |
+ |
|
109 |
+/* |
|
110 |
+ * Save originate destination |
|
111 |
+ * param dest Originate destination structure |
|
112 |
+ * return 0 success, -1 failure |
|
113 |
+ */ |
|
114 |
+int ospSaveOrigDestination( |
|
115 |
+ osp_dest* dest) |
|
116 |
+{ |
|
117 |
+ LOG(L_DBG, "osp: ospSaveOrigDestination\n"); |
|
118 |
+ |
|
119 |
+ return ospSaveDestination(dest, &OSP_ORIGDEST_NAME); |
|
120 |
+} |
|
121 |
+ |
|
122 |
+/* |
|
123 |
+ * Save terminate destination |
|
124 |
+ * param dest Terminate destination structure |
|
125 |
+ * return 0 success, -1 failure |
|
126 |
+ */ |
|
127 |
+int ospSaveTermDestination( |
|
128 |
+ osp_dest* dest) |
|
129 |
+{ |
|
130 |
+ LOG(L_DBG, "osp: ospSaveTermDestination\n"); |
|
131 |
+ |
|
132 |
+ return ospSaveDestination(dest, &OSP_TERMDEST_NAME); |
|
133 |
+} |
|
134 |
+ |
|
135 |
+/* |
|
136 |
+ * Check if there is an unused and supported originate destination from an AVP |
|
137 |
+ * name - OSP_ORIGDEST_NAME |
|
138 |
+ * value - osp_dest wrapped in a string |
|
139 |
+ * search unused (used==0) & supported (support==1) |
|
140 |
+ * return 0 success, -1 failure |
|
141 |
+ */ |
|
142 |
+int ospCheckOrigDestination(void) |
|
143 |
+{ |
|
144 |
+ struct usr_avp* destavp = NULL; |
|
145 |
+ int_str destval; |
|
146 |
+ struct search_state state; |
|
147 |
+ osp_dest* dest = NULL; |
|
148 |
+ int result = -1; |
|
149 |
+ |
|
150 |
+ LOG(L_DBG, "osp: ospCheckOrigDestination\n"); |
|
151 |
+ |
|
152 |
+ for (destavp = search_first_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)OSP_ORIGDEST_NAME, &destval, &state); |
|
153 |
+ destavp != NULL; |
|
154 |
+ destavp = search_next_avp(&state, &destval)) |
|
155 |
+ { |
|
156 |
+ /* OSP destintaion is wrapped in a string */ |
|
157 |
+ dest = (osp_dest*)destval.s.s; |
|
158 |
+ |
|
159 |
+ if (dest->used == 0) { |
|
160 |
+ if (dest->supported == 1) { |
|
161 |
+ LOG(L_DBG, "osp: orig dest exist\n"); |
|
162 |
+ result = 0; |
|
163 |
+ break; |
|
164 |
+ } else { |
|
165 |
+ LOG(L_DBG, "osp: destination does not been supported\n"); |
|
166 |
+ } |
|
167 |
+ } else { |
|
168 |
+ LOG(L_DBG, "osp: destination has already been used\n"); |
|
169 |
+ } |
|
170 |
+ } |
|
171 |
+ |
|
172 |
+ if (result == -1) { |
|
173 |
+ LOG(L_DBG, "osp: there is not unused destination\n"); |
|
174 |
+ } |
|
175 |
+ |
|
176 |
+ return result; |
|
177 |
+} |
|
178 |
+ |
|
179 |
+/* |
|
180 |
+ * Retrieved an unused and supported originate destination from an AVP |
|
181 |
+ * name - OSP_ORIGDEST_NAME |
|
182 |
+ * value - osp_dest wrapped in a string |
|
183 |
+ * There can be 0, 1 or more originate destinations. |
|
184 |
+ * Find the 1st unused destination (used==0) & supported (support==1), |
|
185 |
+ * return it, and mark it as used (used==1). |
|
186 |
+ * return NULL on failure |
|
187 |
+ */ |
|
188 |
+osp_dest* ospGetNextOrigDestination(void) |
|
189 |
+{ |
|
190 |
+ struct usr_avp* destavp = NULL; |
|
191 |
+ int_str destval; |
|
192 |
+ struct search_state state; |
|
193 |
+ osp_dest* dest = NULL; |
|
194 |
+ osp_dest* result = NULL; |
|
195 |
+ |
|
196 |
+ LOG(L_DBG, "osp: ospGetNextOrigDestination\n"); |
|
197 |
+ |
|
198 |
+ for (destavp = search_first_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)OSP_ORIGDEST_NAME, &destval, &state); |
|
199 |
+ destavp != NULL; |
|
200 |
+ destavp = search_next_avp(&state, &destval)) |
|
201 |
+ { |
|
202 |
+ /* OSP destintaion is wrapped in a string */ |
|
203 |
+ dest = (osp_dest*)destval.s.s; |
|
204 |
+ |
|
205 |
+ if (dest->used == 0) { |
|
206 |
+ if (dest->supported == 1) { |
|
207 |
+ LOG(L_DBG, "osp: orig dest found\n"); |
|
208 |
+ dest->used = 1; |
|
209 |
+ result = dest; |
|
210 |
+ break; |
|
211 |
+ } else { |
|
212 |
+ /* Make it looks like used */ |
|
213 |
+ dest->used = 1; |
|
214 |
+ /* 111 means wrong protocol */ |
|
215 |
+ dest->lastcode = 111; |
|
216 |
+ LOG(L_DBG, "osp: destination does not been supported\n"); |
|
217 |
+ } |
|
218 |
+ } else { |
|
219 |
+ LOG(L_DBG, "osp: destination has already been used\n"); |
|
220 |
+ } |
|
221 |
+ } |
|
222 |
+ |
|
223 |
+ if (result == NULL) { |
|
224 |
+ LOG(L_DBG, "osp: there is not unused destination\n"); |
|
225 |
+ } |
|
226 |
+ |
|
227 |
+ return result; |
|
228 |
+} |
|
229 |
+ |
|
230 |
+/* |
|
231 |
+ * Retrieved the last used originate destination from an AVP |
|
232 |
+ * name - OSP_ORIGDEST_NAME |
|
233 |
+ * value - osp_dest wrapped in a string |
|
234 |
+ * There can be 0, 1 or more destinations. |
|
235 |
+ * Find the last used destination (used==1) & supported (support==1), |
|
236 |
+ * and return it. |
|
237 |
+ * In normal condition, this one is the current destination. But it may |
|
238 |
+ * be wrong for loop condition. |
|
239 |
+ * return NULL on failure |
|
240 |
+ */ |
|
241 |
+osp_dest* ospGetLastOrigDestination(void) |
|
242 |
+{ |
|
243 |
+ struct usr_avp* destavp = NULL; |
|
244 |
+ int_str destval; |
|
245 |
+ struct search_state state; |
|
246 |
+ osp_dest* dest = NULL; |
|
247 |
+ osp_dest* lastdest = NULL; |
|
248 |
+ |
|
249 |
+ LOG(L_DBG, "osp: ospGetLastOrigDesintaion\n"); |
|
250 |
+ |
|
251 |
+ for (destavp = search_first_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)OSP_ORIGDEST_NAME, &destval, &state); |
|
252 |
+ destavp != NULL; |
|
253 |
+ destavp = search_next_avp(&state, &destval)) |
|
254 |
+ { |
|
255 |
+ /* OSP destination is wrapped in a string */ |
|
256 |
+ dest = (osp_dest*)destval.s.s; |
|
257 |
+ |
|
258 |
+ if (dest->used == 1) { |
|
259 |
+ if (dest->supported == 1) { |
|
260 |
+ lastdest = dest; |
|
261 |
+ LOG(L_DBG, "osp: curent destination '%s'\n", lastdest->host); |
|
262 |
+ } |
|
263 |
+ } else { |
|
264 |
+ break; |
|
265 |
+ } |
|
266 |
+ } |
|
267 |
+ |
|
268 |
+ return lastdest; |
|
269 |
+} |
|
270 |
+ |
|
271 |
+/* |
|
272 |
+ * Retrieved the terminate destination from an AVP |
|
273 |
+ * name - OSP_TERMDEST_NAME |
|
274 |
+ * value - osp_dest wrapped in a string |
|
275 |
+ * There can be 0 or 1 term destinations. Find and return it. |
|
276 |
+ * return NULL on failure (no terminate destination) |
|
277 |
+ */ |
|
278 |
+osp_dest* ospGetTermDestination(void) |
|
279 |
+{ |
|
280 |
+ struct usr_avp* destavp = NULL; |
|
281 |
+ int_str destval; |
|
282 |
+ osp_dest* dest = NULL; |
|
283 |
+ |
|
284 |
+ LOG(L_DBG, "osp: ospGetTermDestination\n"); |
|
285 |
+ |
|
286 |
+ destavp = search_first_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)OSP_TERMDEST_NAME, &destval, NULL); |
|
287 |
+ |
|
288 |
+ if (destavp) { |
|
289 |
+ /* OSP destination is wrapped in a string */ |
|
290 |
+ dest = (osp_dest*)destval.s.s; |
|
291 |
+ |
|
292 |
+ LOG(L_DBG, "osp: term dest found\n"); |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+ return dest; |
|
296 |
+} |
|
297 |
+ |
|
298 |
+/* |
|
299 |
+ * Record destination status |
|
300 |
+ * param code Destination status |
|
301 |
+ * param dest Destination |
|
302 |
+ */ |
|
303 |
+static void ospRecordCode( |
|
304 |
+ int code, |
|
305 |
+ osp_dest* dest) |
|
306 |
+{ |
|
307 |
+ LOG(L_DBG, "osp: ospRecordCode\n"); |
|
308 |
+ |
|
309 |
+ LOG(L_DBG, "osp: code '%d'\n", code); |
|
310 |
+ dest->lastcode = code; |
|
311 |
+ |
|
312 |
+ switch (code) { |
|
313 |
+ case 100: |
|
314 |
+ if (!dest->time100) { |
|
315 |
+ dest->time100 = time(NULL); |
|
316 |
+ } else { |
|
317 |
+ LOG(L_DBG, "osp: 100 already recorded\n"); |
|
318 |
+ } |
|
319 |
+ break; |
|
320 |
+ case 180: |
|
321 |
+ case 181: |
|
322 |
+ case 182: |
|
323 |
+ case 183: |
|
324 |
+ if (!dest->time180) { |
|
325 |
+ dest->time180 = time(NULL); |
|
326 |
+ } else { |
|
327 |
+ LOG(L_DBG, "osp: 180, 181, 182 or 183 allready recorded\n"); |
|
328 |
+ } |
|
329 |
+ break; |
|
330 |
+ case 200: |
|
331 |
+ case 202: |
|
332 |
+ if (!dest->time200) { |
|
333 |
+ dest->time200 = time(NULL); |
|
334 |
+ } else { |
|
335 |
+ LOG(L_DBG, "osp: 200 or 202 allready recorded\n"); |
|
336 |
+ } |
|
337 |
+ break; |
|
338 |
+ default: |
|
339 |
+ LOG(L_DBG, "osp: will not record time for '%d'\n", code); |
|
340 |
+ } |
|
341 |
+} |
|
342 |
+ |
|
343 |
+/* |
|
344 |
+ * Check destination status for reporting usage |
|
345 |
+ * param code Destination status |
|
346 |
+ * return 1 should report, 0 should not report |
|
347 |
+ */ |
|
348 |
+static int ospIsToReportUsage( |
|
349 |
+ int code) |
|
350 |
+{ |
|
351 |
+ int istime = 0; |
|
352 |
+ |
|
353 |
+ LOG(L_DBG, "osp: ospIsToReportUsage\n"); |
|
354 |
+ |
|
355 |
+ LOG(L_DBG, "osp: code '%d'\n", code); |
|
356 |
+ if (code >= 200) { |
|
357 |
+ istime = 1; |
|
358 |
+ } |
|
359 |
+ |
|
360 |
+ return istime; |
|
361 |
+} |
|
362 |
+ |
|
363 |
+/* |
|
364 |
+ * Report call setup usage for both client and server side |
|
365 |
+ * param clientcode Client status |
|
366 |
+ * param servercode Server status |
|
367 |
+ */ |
|
368 |
+void ospRecordEvent( |
|
369 |
+ int clientcode, |
|
370 |
+ int servercode) |
|
371 |
+{ |
|
372 |
+ osp_dest* dest; |
|
373 |
+ |
|
374 |
+ LOG(L_DBG, "osp: ospRecordEvent\n"); |
|
375 |
+ |
|
376 |
+ LOG(L_DBG, "osp: client status '%d'\n", clientcode); |
|
377 |
+ if ((clientcode != 0) && (dest = ospGetLastOrigDestination())) { |
|
378 |
+ ospRecordCode(clientcode, dest); |
|
379 |
+ |
|
380 |
+ if (ospIsToReportUsage(servercode) == 1) { |
|
381 |
+ ospReportOrigSetupUsage(); |
|
382 |
+ } |
|
383 |
+ } |
|
384 |
+ |
|
385 |
+ LOG(L_DBG, "osp: server status '%d'\n", servercode); |
|
386 |
+ if ((servercode != 0) && (dest = ospGetTermDestination())) { |
|
387 |
+ ospRecordCode(servercode, dest); |
|
388 |
+ |
|
389 |
+ if (ospIsToReportUsage(servercode) == 1) { |
|
390 |
+ ospReportTermSetupUsage(); |
|
391 |
+ } |
|
392 |
+ } |
|
393 |
+} |
|
394 |
+ |
|
395 |
+/* |
|
396 |
+ * Dump destination information |
|
397 |
+ * param dest Destination |
|
398 |
+ */ |
|
399 |
+void ospDumpDestination( |
|
400 |
+ osp_dest* dest) |
|
401 |
+{ |
|
402 |
+ LOG(L_DBG, "osp: dest->host..........'%s'\n", dest->host); |
|
403 |
+ LOG(L_DBG, "osp: dest->used..........'%d'\n", dest->used); |
|
404 |
+ LOG(L_DBG, "osp: dest->lastcode......'%d'\n", dest->lastcode); |
|
405 |
+ LOG(L_DBG, "osp: dest->time100.......'%d'\n", (unsigned int)dest->time100); |
|
406 |
+ LOG(L_DBG, "osp: dest->time180.......'%d'\n", (unsigned int)dest->time180); |
|
407 |
+ LOG(L_DBG, "osp: dest->time200.......'%d'\n", (unsigned int)dest->time200); |
|
408 |
+} |
|
409 |
+ |
|
410 |
+/* |
|
411 |
+ * Dump all destination information |
|
412 |
+ */ |
|
413 |
+void ospDumpAllDestination(void) |
|
414 |
+{ |
|
415 |
+ struct usr_avp* destavp = NULL; |
|
416 |
+ int_str destval; |
|
417 |
+ struct search_state state; |
|
418 |
+ osp_dest* dest = NULL; |
|
419 |
+ int count = 0; |
|
420 |
+ |
|
421 |
+ LOG(L_DBG, "osp: ospDumpAllDestination\n"); |
|
422 |
+ |
|
423 |
+ for (destavp = search_first_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)OSP_ORIGDEST_NAME, &destval, &state); |
|
424 |
+ destavp != NULL; |
|
425 |
+ destavp = search_next_avp(&state, &destval)) |
|
426 |
+ { |
|
427 |
+ /* OSP destination is wrapped in a string */ |
|
428 |
+ dest = (osp_dest*)destval.s.s; |
|
429 |
+ |
|
430 |
+ LOG(L_DBG, "osp: ....originate '%d'....\n", count++); |
|
431 |
+ |
|
432 |
+ ospDumpDestination(dest); |
|
433 |
+ } |
|
434 |
+ if (count == 0) { |
|
435 |
+ LOG(L_DBG, "osp: there is not originate destination AVP\n"); |
|
436 |
+ } |
|
437 |
+ |
|
438 |
+ destavp = search_first_avp(AVP_NAME_STR | AVP_VAL_STR, (int_str)OSP_TERMDEST_NAME, &destval, NULL); |
|
439 |
+ |
|
440 |
+ if (destavp) { |
|
441 |
+ /* OSP destination is wrapped in a string */ |
|
442 |
+ dest = (osp_dest*)destval.s.s; |
|
443 |
+ |
|
444 |
+ LOG(L_DBG, "osp: ....terminate....\n"); |
|
445 |
+ |
|
446 |
+ ospDumpDestination(dest); |
|
447 |
+ } else { |
|
448 |
+ LOG(L_DBG, "osp: there is not terminate destination AVP\n"); |
|
449 |
+ } |
|
450 |
+} |
|
451 |
+ |
|
452 |
+/* |
|
453 |
+ * Convert address to "[x.x.x.x]" or "host.domain" format |
|
454 |
+ * param src Source address |
|
455 |
+ * param dst Destination address |
|
456 |
+ * param buffersize Size of dst buffer |
|
457 |
+ */ |
|
458 |
+void ospConvertAddress( |
|
459 |
+ char* src, |
|
460 |
+ char* dst, |
|
461 |
+ int buffersize) |
|
462 |
+{ |
|
463 |
+ struct in_addr inp; |
|
464 |
+ |
|
465 |
+ LOG(L_DBG, "osp: ospConvertAddress\n"); |
|
466 |
+ |
|
467 |
+ if (inet_aton(src, &inp) != 0) { |
|
468 |
+ snprintf(dst, buffersize, "[%s]", src); |
|
469 |
+ } else { |
|
470 |
+ snprintf(dst, buffersize, "%s", src); |
|
471 |
+ } |
|
472 |
+} |
|
473 |
+ |
0 | 474 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,84 @@ |
1 |
+/* |
|
2 |
+ * ser osp module. |
|
3 |
+ * |
|
4 |
+ * This module enables ser to communicate with an Open Settlement |
|
5 |
+ * Protocol (OSP) server. The Open Settlement Protocol is an ETSI |
|
6 |
+ * defined standard for Inter-Domain VoIP pricing, authorization |
|
7 |
+ * and usage exchange. The technical specifications for OSP |
|
8 |
+ * (ETSI TS 101 321 V4.1.1) are available at www.etsi.org. |
|
9 |
+ * |
|
10 |
+ * Uli Abend was the original contributor to this module. |
|
11 |
+ * |
|
12 |
+ * Copyright (C) 2001-2005 Fhg Fokus |
|
13 |
+ * |
|
14 |
+ * This file is part of ser, a free SIP server. |
|
15 |
+ * |
|
16 |
+ * ser is free software; you can redistribute it and/or modify |
|
17 |
+ * it under the terms of the GNU General Public License as published by |
|
18 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
19 |
+ * (at your option) any later version |
|
20 |
+ * |
|
21 |
+ * For a license to use the ser software under conditions |
|
22 |
+ * other than those described here, or to purchase support for this |
|
23 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
24 |
+ * info@iptel.org |
|
25 |
+ * |
|
26 |
+ * ser is distributed in the hope that it will be useful, |
|
27 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
28 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
29 |
+ * GNU General Public License for more details. |
|
30 |
+ * |
|
31 |
+ * You should have received a copy of the GNU General Public License |
|
32 |
+ * along with this program; if not, write to the Free Software |
|
33 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
34 |
+ */ |
|
35 |
+ |
|
36 |
+#ifndef _OSP_MOD_DESTINATION_H_ |
|
37 |
+#define _OSP_MOD_DESTINATION_H_ |
|
38 |
+ |
|
39 |
+#include <time.h> |
|
40 |
+#include "osp_mod.h" |
|
41 |
+ |
|
42 |
+typedef struct _osp_dest { |
|
43 |
+ char validafter[OSP_STRBUF_SIZE]; |
|
44 |
+ char validuntil[OSP_STRBUF_SIZE]; |
|
45 |
+ char callid[OSP_STRBUF_SIZE]; |
|
46 |
+ char called[OSP_STRBUF_SIZE]; |
|
47 |
+ char calling[OSP_STRBUF_SIZE]; |
|
48 |
+ char source[OSP_STRBUF_SIZE]; |
|
49 |
+ char srcdev[OSP_STRBUF_SIZE]; |
|
50 |
+ char host[OSP_STRBUF_SIZE]; |
|
51 |
+ char destdev[OSP_STRBUF_SIZE]; |
|
52 |
+ char networkid[OSP_STRBUF_SIZE]; |
|
53 |
+ unsigned char token[OSP_TOKENBUF_SIZE]; |
|
54 |
+ unsigned int callidsize; |
|
55 |
+ unsigned int tokensize; |
|
56 |
+ unsigned int timelimit; |
|
57 |
+ int lastcode; |
|
58 |
+ time_t authtime; |
|
59 |
+ time_t time100; |
|
60 |
+ time_t time180; |
|
61 |
+ time_t time200; |
|
62 |
+ int type; |
|
63 |
+ unsigned long long transid; |
|
64 |
+ int supported; |
|
65 |
+ int used; |
|
66 |
+ int reported; |
|
67 |
+ unsigned int destinationCount; |
|
68 |
+ char origcalled[OSP_STRBUF_SIZE]; |
|
69 |
+} osp_dest; |
|
70 |
+ |
|
71 |
+osp_dest* ospInitDestination(osp_dest* dest); |
|
72 |
+int ospSaveOrigDestination(osp_dest* dest); |
|
73 |
+int ospSaveTermDestination(osp_dest* dest); |
|
74 |
+int ospCheckOrigDestination(void); |
|
75 |
+osp_dest* ospGetNextOrigDestination(void); |
|
76 |
+osp_dest* ospGetLastOrigDestination(void); |
|
77 |
+osp_dest* ospGetTermDestination(void); |
|
78 |
+void ospRecordEvent(int clientcode, int servercode); |
|
79 |
+void ospDumpDestination(osp_dest* dest); |
|
80 |
+void ospDumpAllDestination(void); |
|
81 |
+void ospConvertAddress(char* src, char* dst, int buffersize); |
|
82 |
+ |
|
83 |
+#endif /* _OSP_MOD_DESTINATION_H_ */ |
|
84 |
+ |
0 | 5 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,54 @@ |
1 |
+<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
|
3 |
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [ |
|
4 |
+ |
|
5 |
+<!ENTITY user SYSTEM "osp_user.xml"> |
|
6 |
+<!ENTITY devel SYSTEM "osp_devel.xml"> |
|
7 |
+<!ENTITY faq SYSTEM "osp_faq.xml"> |
|
8 |
+ |
|
9 |
+<!-- Include general documentation entities --> |
|
10 |
+<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml"> |
|
11 |
+%docentities; |
|
12 |
+ |
|
13 |
+]> |
|
14 |
+ |
|
15 |
+<book> |
|
16 |
+ <bookinfo> |
|
17 |
+ <title>OSP Module for Secure, Multi-Lateral Peering</title> |
|
18 |
+ <productname class="trade">&sername;</productname> |
|
19 |
+ <authorgroup> |
|