| 1 |
sca Module |
| 2 |
|
| 3 |
Andrew Mortensen |
| 4 |
|
| 5 |
University of Pennsylvania |
| 6 |
|
| 7 |
Victor Seva |
| 8 |
|
| 9 |
Sipwise GmbH |
| 10 |
|
| 11 |
Copyright © 2012 Andrew Mortensen, [email protected] |
| 12 |
|
| 13 |
Copyright © 2024 Sipwise GmbH |
| 14 |
__________________________________________________________________ |
| 15 |
|
| 16 |
Table of Contents |
| 17 |
|
| 18 |
1. Admin Guide |
| 19 |
|
| 20 |
1. Overview |
| 21 |
2. Dependencies |
| 22 |
|
| 23 |
2.1. Modules |
| 24 |
|
| 25 |
3. Parameters |
| 26 |
|
| 27 |
3.1. hash_table_size (integer) |
| 28 |
3.2. call_info_max_expires (integer) |
| 29 |
3.3. line_seize_max_expires (integer) |
| 30 |
3.4. purge_expired_interval (integer) |
| 31 |
3.5. db_url (str) |
| 32 |
3.6. subs_table (str) |
| 33 |
3.7. db_update_interval (integer) |
| 34 |
3.8. onhold_bflag (integer) |
| 35 |
3.9. server_address (string) |
| 36 |
3.10. contact_fallback (string) |
| 37 |
3.11. from_uri_avp (string) |
| 38 |
3.12. to_uri_avp (string) |
| 39 |
|
| 40 |
4. Functions |
| 41 |
|
| 42 |
4.1. sca_handle_subscribe([to_uri, [from_uri]]) |
| 43 |
4.2. sca_call_info_update([mask, to, from]) |
| 44 |
|
| 45 |
5. Exported RPC Commands |
| 46 |
|
| 47 |
5.1. sca.all_subscriptions |
| 48 |
5.2. sca.all_appearances |
| 49 |
5.3. sca.seize_appearance |
| 50 |
5.4. sca.update_appearance |
| 51 |
5.5. sca.release_appearance |
| 52 |
|
| 53 |
6. Sample kamailio.cfg with SCA |
| 54 |
|
| 55 |
List of Examples |
| 56 |
|
| 57 |
1.1. Set hash_table_size: |
| 58 |
1.2. Set call_info_max_expires: |
| 59 |
1.3. Set line_seize_max_expires: |
| 60 |
1.4. Set purge_expired_interval: |
| 61 |
1.5. Set db_url parameter: |
| 62 |
1.6. Set subs_table parameter: |
| 63 |
1.7. Set db_update_interval: |
| 64 |
1.8. Set onhold_bflag parameter |
| 65 |
1.9. Set server_address parameter |
| 66 |
1.10. Set contact_fallback parameter |
| 67 |
1.11. Set from_uri_avp parameter |
| 68 |
1.12. Set to_uri_avp parameter |
| 69 |
1.13. sca_handle_subscribe usage: |
| 70 |
1.14. sca_call_info_update usage: |
| 71 |
1.15. kamailio.cfg |
| 72 |
|
| 73 |
Chapter 1. Admin Guide |
| 74 |
|
| 75 |
Table of Contents |
| 76 |
|
| 77 |
1. Overview |
| 78 |
2. Dependencies |
| 79 |
|
| 80 |
2.1. Modules |
| 81 |
|
| 82 |
3. Parameters |
| 83 |
|
| 84 |
3.1. hash_table_size (integer) |
| 85 |
3.2. call_info_max_expires (integer) |
| 86 |
3.3. line_seize_max_expires (integer) |
| 87 |
3.4. purge_expired_interval (integer) |
| 88 |
3.5. db_url (str) |
| 89 |
3.6. subs_table (str) |
| 90 |
3.7. db_update_interval (integer) |
| 91 |
3.8. onhold_bflag (integer) |
| 92 |
3.9. server_address (string) |
| 93 |
3.10. contact_fallback (string) |
| 94 |
3.11. from_uri_avp (string) |
| 95 |
3.12. to_uri_avp (string) |
| 96 |
|
| 97 |
4. Functions |
| 98 |
|
| 99 |
4.1. sca_handle_subscribe([to_uri, [from_uri]]) |
| 100 |
4.2. sca_call_info_update([mask, to, from]) |
| 101 |
|
| 102 |
5. Exported RPC Commands |
| 103 |
|
| 104 |
5.1. sca.all_subscriptions |
| 105 |
5.2. sca.all_appearances |
| 106 |
5.3. sca.seize_appearance |
| 107 |
5.4. sca.update_appearance |
| 108 |
5.5. sca.release_appearance |
| 109 |
|
| 110 |
6. Sample kamailio.cfg with SCA |
| 111 |
|
| 112 |
1. Overview |
| 113 |
|
| 114 |
The sca module implements Shared Call Appearances. It handles SUBSCRIBE |
| 115 |
messages for call-info and line-seize events, and sends call-info |
| 116 |
NOTIFYs to line subscribers to implement line bridging. The module |
| 117 |
implements SCA as defined in Broadworks SIP Access Side Extensions |
| 118 |
Interface Specifications, Release 13.0, version 1, sections 2, 3 and 4. |
| 119 |
|
| 120 |
SCA group members receive call state notifications when other group |
| 121 |
members participate in calls. An SCA caller can place a call on hold, |
| 122 |
and the call may be retrieved from hold by another member of the group. |
| 123 |
|
| 124 |
Subscribers to SCA call-info events SUBSCRIBE to their |
| 125 |
address-of-record (AoR), asking the application server to send |
| 126 |
call-info NOTIFYs with line state information as lines in the |
| 127 |
subscriber group are used. |
| 128 |
|
| 129 |
For example, when an SCA subscriber takes the phone off hook, it sends |
| 130 |
a line-seize SUBSCRIBE to the application server. The application |
| 131 |
server acknowledges the request, and sends to the subscriber a |
| 132 |
line-seize NOTIFY with the appearance index of the line claimed for the |
| 133 |
subscriber. The application also sends call-info NOTIFYs to the other |
| 134 |
SCA subscribers to the AoR, letting them know that an appearance within |
| 135 |
the group has gone off hook. Subscribers update their display |
| 136 |
appropriately. |
| 137 |
|
| 138 |
Subscribers to an SCA address-of-record will receive call-info NOTIFYs |
| 139 |
when a member of the group seizes a line (seized); receives a 180 |
| 140 |
ringing response from the remote party (ringing); receives a 183 |
| 141 |
progressing response from the remote party (progressing); when the |
| 142 |
remote party answers the call (active); when either party in the call |
| 143 |
places the call on hold (held); and when an SCA line goes back on hook |
| 144 |
(idle). |
| 145 |
|
| 146 |
The call-info subscriber information is stored in memory and is |
| 147 |
periodically written to the database. Call state information is stored |
| 148 |
in memory. A future release may periodically write call state to the |
| 149 |
database, as well. The database is purely for restoring subscriptions |
| 150 |
after a restart of the application server. Subscriber information is |
| 151 |
also flushed to the database when the service is stopped. |
| 152 |
|
| 153 |
At the time of this writing, Polycom and Cisco handsets are known to |
| 154 |
implement the call-info and line-seize event packages defined in the |
| 155 |
document, which may be found freely on the web. |
| 156 |
|
| 157 |
To date, this module has only been tested with Polycom Soundpoint 550s |
| 158 |
and 650s running Polycom SIP 3.3.4. |
| 159 |
|
| 160 |
2. Dependencies |
| 161 |
|
| 162 |
2.1. Modules |
| 163 |
|
| 164 |
2.1. Modules |
| 165 |
|
| 166 |
The following modules must be loaded before this module: |
| 167 |
* a database module |
| 168 |
* sl |
| 169 |
* tm |
| 170 |
|
| 171 |
3. Parameters |
| 172 |
|
| 173 |
3.1. hash_table_size (integer) |
| 174 |
3.2. call_info_max_expires (integer) |
| 175 |
3.3. line_seize_max_expires (integer) |
| 176 |
3.4. purge_expired_interval (integer) |
| 177 |
3.5. db_url (str) |
| 178 |
3.6. subs_table (str) |
| 179 |
3.7. db_update_interval (integer) |
| 180 |
3.8. onhold_bflag (integer) |
| 181 |
3.9. server_address (string) |
| 182 |
3.10. contact_fallback (string) |
| 183 |
3.11. from_uri_avp (string) |
| 184 |
3.12. to_uri_avp (string) |
| 185 |
|
| 186 |
3.1. hash_table_size (integer) |
| 187 |
|
| 188 |
Size, as a power of two, of the shared memory hash table containing the |
| 189 |
call-info subscriptions and the appearance state. A larger power of two |
| 190 |
means better performance (fewer collisions, making for fewer subscriber |
| 191 |
URI comparisons) at the expense of increased shared memory use. |
| 192 |
|
| 193 |
Default value is 9 (2 ^ 9 == 512). |
| 194 |
|
| 195 |
Example 1.1. Set hash_table_size: |
| 196 |
... |
| 197 |
# create shared memory hash table with 2^8 (256) slots |
| 198 |
modparam( "sca", "hash_table_size", 8 ) |
| 199 |
... |
| 200 |
|
| 201 |
3.2. call_info_max_expires (integer) |
| 202 |
|
| 203 |
The maximum allowed call-info subscription time in seconds. |
| 204 |
|
| 205 |
Default value is 3600 (1 hour). |
| 206 |
|
| 207 |
Example 1.2. Set call_info_max_expires: |
| 208 |
... |
| 209 |
modparam( "sca", "call_info_max_expires", 1800 ) |
| 210 |
... |
| 211 |
|
| 212 |
3.3. line_seize_max_expires (integer) |
| 213 |
|
| 214 |
The maximum allowed line-seize subscription time in seconds. |
| 215 |
|
| 216 |
Default value is 15 (15 seconds). |
| 217 |
|
| 218 |
A maximum line-seize subscription time of 15 seconds is recommended in |
| 219 |
the SIP Access Side Extensions document. This interval is purposely |
| 220 |
short to prevent a client from seizing an appearance without making a |
| 221 |
call for extended periods of time. |
| 222 |
|
| 223 |
Example 1.3. Set line_seize_max_expires: |
| 224 |
... |
| 225 |
modparam( "sca", "line_seize_max_expires", 30 ) |
| 226 |
... |
| 227 |
|
| 228 |
3.4. purge_expired_interval (integer) |
| 229 |
|
| 230 |
The period of time in seconds between purges of expired call-info and |
| 231 |
line-seize subscriptions. |
| 232 |
|
| 233 |
Default value is 120 (2 minutes). |
| 234 |
|
| 235 |
On finding an expired subscription, the module removes the subscription |
| 236 |
from the shared memory hash table, and sends a NOTIFY with |
| 237 |
Subscription-State "terminated;expired" header value to the subscriber. |
| 238 |
It also NOTIFYs other members of the group, in the event that the |
| 239 |
expired subscription was a line-seize. |
| 240 |
|
| 241 |
Example 1.4. Set purge_expired_interval: |
| 242 |
... |
| 243 |
modparam( "sca", "purge_expired_interval", 60 ) |
| 244 |
... |
| 245 |
|
| 246 |
3.5. db_url (str) |
| 247 |
|
| 248 |
URL of database to which subscribers will be written. |
| 249 |
|
| 250 |
Default value is mysql://kamailio:kamailiorw@localhost/kamailio |
| 251 |
|
| 252 |
Example 1.5. Set db_url parameter: |
| 253 |
... |
| 254 |
modparam( "sca", "db_url", "mysql://kamailio:kamailiorw@localhost/kamailio" ) |
| 255 |
... |
| 256 |
|
| 257 |
3.6. subs_table (str) |
| 258 |
|
| 259 |
Name of the database table where call-info subscriptions are written. |
| 260 |
|
| 261 |
Default value is “sca_subscriptions”. |
| 262 |
|
| 263 |
Example 1.6. Set subs_table parameter: |
| 264 |
... |
| 265 |
modparam( "sca", "subs_table", "call_info_subscriptions" ) |
| 266 |
... |
| 267 |
|
| 268 |
3.7. db_update_interval (integer) |
| 269 |
|
| 270 |
Period in seconds between writes of call-info subscriber information to |
| 271 |
the database. |
| 272 |
|
| 273 |
Default value is 300 (5 minutes). |
| 274 |
|
| 275 |
Example 1.7. Set db_update_interval: |
| 276 |
... |
| 277 |
modparam( "sca", "db_update_interval", 120 ) |
| 278 |
... |
| 279 |
|
| 280 |
3.8. onhold_bflag (integer) |
| 281 |
|
| 282 |
When bflag is set the media will be treated as on-hold and sdp parse |
| 283 |
will be skipped. If the bflag is not set the sdp will be parsed to |
| 284 |
detect on-hold. |
| 285 |
|
| 286 |
Default value is -1 (disabled). |
| 287 |
|
| 288 |
Example 1.8. Set onhold_bflag parameter |
| 289 |
... |
| 290 |
modparam("sca", "onhold_bflag", 15) |
| 291 |
... |
| 292 |
|
| 293 |
3.9. server_address (string) |
| 294 |
|
| 295 |
The server address which will become the value of Contact header filed |
| 296 |
for reply messages. |
| 297 |
|
| 298 |
Default value is "" (disabled). |
| 299 |
|
| 300 |
Example 1.9. Set server_address parameter |
| 301 |
... |
| 302 |
modparam("sca", "server_address", "sip:10.10.10.10:5060") |
| 303 |
... |
| 304 |
|
| 305 |
3.10. contact_fallback (string) |
| 306 |
|
| 307 |
contact used if defined when no contact is found in processed message. |
| 308 |
|
| 309 |
Default value is "" (disabled). |
| 310 |
|
| 311 |
Example 1.10. Set contact_fallback parameter |
| 312 |
... |
| 313 |
modparam("sca", "contact_fallback", "sip:127.0.0.1:5085;transport=udp") |
| 314 |
... |
| 315 |
|
| 316 |
3.11. from_uri_avp (string) |
| 317 |
|
| 318 |
avp that will store the From URI used. |
| 319 |
|
| 320 |
Default value is "" (disabled). |
| 321 |
|
| 322 |
Example 1.11. Set from_uri_avp parameter |
| 323 |
... |
| 324 |
modparam("sca", "from_uri_avp", "$avp(sca_from)") |
| 325 |
... |
| 326 |
|
| 327 |
3.12. to_uri_avp (string) |
| 328 |
|
| 329 |
avp that will store the To URI used. |
| 330 |
|
| 331 |
Default value is "" (disabled). |
| 332 |
|
| 333 |
Example 1.12. Set to_uri_avp parameter |
| 334 |
... |
| 335 |
modparam("sca", "to_uri_avp", "$avp(sca_to)") |
| 336 |
... |
| 337 |
|
| 338 |
4. Functions |
| 339 |
|
| 340 |
4.1. sca_handle_subscribe([to_uri, [from_uri]]) |
| 341 |
4.2. sca_call_info_update([mask, to, from]) |
| 342 |
|
| 343 |
4.1. sca_handle_subscribe([to_uri, [from_uri]]) |
| 344 |
|
| 345 |
The function handling call-info and line-seize SUBSCRIBE requests. It |
| 346 |
stores or updates the subscriptions in shared memory, and sends NOTIFYs |
| 347 |
to the subscriber and other members of the group as needed. |
| 348 |
|
| 349 |
If to_uri or from_uri are defined, those values will be used instead of |
| 350 |
the SIP header. Both parameters can be a string or a pseudo variable |
| 351 |
holding a string value. |
| 352 |
|
| 353 |
For example, a line-seize SUBSCRIBE will cause the module to reserve an |
| 354 |
appearance index for the subscriber; send a line-seize NOTIFY to the |
| 355 |
subscriber indicating which appearance index it must use; and send |
| 356 |
call-info NOTIFYs to other subscribers to the address-of-record letting |
| 357 |
them know the appearance is off hook. |
| 358 |
|
| 359 |
This function can be used from the REQUEST_ROUTE. |
| 360 |
|
| 361 |
Return code: |
| 362 |
* 1 - successful |
| 363 |
* -1 - failed, error logged |
| 364 |
|
| 365 |
Example 1.13. sca_handle_subscribe usage: |
| 366 |
... |
| 367 |
if ( is_method( "SUBSCRIBE" )) { |
| 368 |
if ( $hdr(Event) == "call-info" || $hdr(Event) == "line-seize" ) { |
| 369 |
if($var(fix_uri) != 0) { |
| 370 |
sca_handle_subscribe($var(to_uri), $avp(from_uri)); |
| 371 |
} else { |
| 372 |
sca_handle_subscribe(); |
| 373 |
} |
| 374 |
exit; |
| 375 |
} |
| 376 |
} |
| 377 |
... |
| 378 |
|
| 379 |
4.2. sca_call_info_update([mask, to, from]) |
| 380 |
|
| 381 |
* mask - integer (optional) |
| 382 |
controls what to check as shared line (BOTH, CALLER, CALLEE) |
| 383 |
+ 0 - SCA_CALL_INFO_SHARED_NONE (default) check both |
| 384 |
+ 1 - SCA_CALL_INFO_SHARED_CALLER |
| 385 |
+ 2 - SCA_CALL_INFO_SHARED_CALLEE |
| 386 |
* to - string (optional) |
| 387 |
string to use as To and skip parsing To header from the message. |
| 388 |
The parameter allows pseudo-variables usage |
| 389 |
* from - string (optional) |
| 390 |
string to use as From and skip parsing From header from the |
| 391 |
message. The parameter allows pseudo-variables usage |
| 392 |
|
| 393 |
The sca_call_info_update function updates call state for SCA |
| 394 |
appearances. If a request or response packet contains a Call-Info |
| 395 |
header, the function extracts call state from the header and sends |
| 396 |
NOTIFYs to subscribers if needed. If no Call-Info header is included in |
| 397 |
the packet, the module looks up the To and From URIs to see if either |
| 398 |
are SCA addresses-of-record. If either the To or From URI are SCA AoRs, |
| 399 |
the function looks up the appearance by dialog and updates call state |
| 400 |
as needed, sending NOTIFYs to members of the group if the call state |
| 401 |
has changed. |
| 402 |
|
| 403 |
The sca_call_info_update function updates call state for INVITE, |
| 404 |
CANCEL, BYE, PRACK and REFER requests and responses. |
| 405 |
|
| 406 |
This function can be used from the REQUEST_ROUTE, REPLY_ROUTE, and |
| 407 |
FAILURE_ROUTE. |
| 408 |
|
| 409 |
Return code: |
| 410 |
* 1 - successful |
| 411 |
* -1 - failed, error logged |
| 412 |
|
| 413 |
Example 1.14. sca_call_info_update usage: |
| 414 |
... |
| 415 |
route |
| 416 |
{ |
| 417 |
... |
| 418 |
sca_call_info_update(0, "$var(to)", "$var(from)@$var(domain)"); |
| 419 |
... |
| 420 |
} |
| 421 |
|
| 422 |
onreply_route[REPLY_ROUTE] |
| 423 |
{ |
| 424 |
... |
| 425 |
if ( status =~ "[456][0-9][0-9]" ) { |
| 426 |
# don't update SCA state here, since there may be |
| 427 |
# failure route processing (e.g., call forwarding). |
| 428 |
# update state in failure route instead. |
| 429 |
break; |
| 430 |
} |
| 431 |
|
| 432 |
sca_call_info_update(); |
| 433 |
... |
| 434 |
} |
| 435 |
|
| 436 |
failure_route[FAILURE_ROUTE] |
| 437 |
{ |
| 438 |
... |
| 439 |
sca_call_info_update(); |
| 440 |
... |
| 441 |
} |
| 442 |
... |
| 443 |
|
| 444 |
5. Exported RPC Commands |
| 445 |
|
| 446 |
5.1. sca.all_subscriptions |
| 447 |
5.2. sca.all_appearances |
| 448 |
5.3. sca.seize_appearance |
| 449 |
5.4. sca.update_appearance |
| 450 |
5.5. sca.release_appearance |
| 451 |
|
| 452 |
5.1. sca.all_subscriptions |
| 453 |
|
| 454 |
List all current call-info and line-seize subscriptions. |
| 455 |
|
| 456 |
Name: sca.all_subscriptions |
| 457 |
|
| 458 |
Parameters: none |
| 459 |
|
| 460 |
Example: |
| 461 |
kamcmd sca.all_subscriptions |
| 462 |
|
| 463 |
5.2. sca.all_appearances |
| 464 |
|
| 465 |
List all SCA appearances with non-idle state. |
| 466 |
|
| 467 |
Name: sca.all_appearances |
| 468 |
|
| 469 |
Parameters: none |
| 470 |
|
| 471 |
Example: |
| 472 |
kamcmd sca.all_appearances |
| 473 |
|
| 474 |
5.3. sca.seize_appearance |
| 475 |
|
| 476 |
Seize an appearance index for a specific contact within an SCA group, |
| 477 |
and notify other members of the group that the appearance is off hook. |
| 478 |
Useful for testing SCA signaling. |
| 479 |
|
| 480 |
Name: sca.seize_appearance |
| 481 |
|
| 482 |
Parameters: 2 |
| 483 |
* SCA Address-of-Record |
| 484 |
* SCA Contact URI |
| 485 |
|
| 486 |
Example: |
| 487 |
# seize next available appearance of sip:[email protected] |
| 488 |
# for contact sip:[email protected] |
| 489 |
kamcmd sca.seize_appearance sip:[email protected] si |
| 490 |
p:[email protected] |
| 491 |
|
| 492 |
5.4. sca.update_appearance |
| 493 |
|
| 494 |
Update the state of an in-use appearance index, and notify other |
| 495 |
members of the group. Useful for testing SCA signaling. |
| 496 |
|
| 497 |
Name: sca.update_appearance |
| 498 |
|
| 499 |
Parameters: 3 or 4 |
| 500 |
* SCA Address-of-Record |
| 501 |
* Index of In-Use Appearance |
| 502 |
* Appearance State (seized, ringing, progressing, active, held, |
| 503 |
held-private) |
| 504 |
* Appearance Display Info (Optional) |
| 505 |
|
| 506 |
Example: |
| 507 |
# update in-use appearance index 3 of sip:[email protected] |
| 508 |
# state held. |
| 509 |
kamcmd sca.update_appearance sip:[email protected] 3 |
| 510 |
held |
| 511 |
|
| 512 |
5.5. sca.release_appearance |
| 513 |
|
| 514 |
Set a non-idle appearance index to idle and NOTIFY members of the |
| 515 |
group. |
| 516 |
|
| 517 |
Name: sca.release_appearance |
| 518 |
|
| 519 |
Parameters: 2 |
| 520 |
* SCA Address-of-Record |
| 521 |
* Appearance Index |
| 522 |
|
| 523 |
Example: |
| 524 |
# release appearance of sip:[email protected] with |
| 525 |
# appearance index 3 |
| 526 |
kamcmd sca.release_appearance sip:[email protected] |
| 527 |
3 |
| 528 |
|
| 529 |
6. Sample kamailio.cfg with SCA |
| 530 |
|
| 531 |
The following is a basic kamailio.cfg providing Shared Call Appearances |
| 532 |
to local subscribers. It has been tested with Polycom handsets. |
| 533 |
|
| 534 |
Example 1.15. kamailio.cfg |
| 535 |
## |
| 536 |
#!KAMAILIO |
| 537 |
# |
| 538 |
# example kamailio.cfg with Shared Call Appearances (SCA) |
| 539 |
|
| 540 |
#!define WITH_AUTH |
| 541 |
#!define WITH_MYSQL |
| 542 |
#!define WITH_SCA |
| 543 |
|
| 544 |
####### Defined Values ######### |
| 545 |
|
| 546 |
#!ifdef WITH_MYSQL |
| 547 |
# - database URL - used to connect to database server by modules such |
| 548 |
# as: auth_db, acc, usrloc, a.s.o. |
| 549 |
#!ifndef DBURL |
| 550 |
#!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio" |
| 551 |
#!endif |
| 552 |
#!endif |
| 553 |
|
| 554 |
####### Global Parameters ######### |
| 555 |
|
| 556 |
#!ifdef WITH_DEBUG |
| 557 |
debug=4 |
| 558 |
log_stderror=yes |
| 559 |
#!else |
| 560 |
debug=2 |
| 561 |
log_stderror=no |
| 562 |
#!endif |
| 563 |
|
| 564 |
memdbg=5 |
| 565 |
memlog=5 |
| 566 |
|
| 567 |
log_facility=LOG_LOCAL0 |
| 568 |
|
| 569 |
fork=yes |
| 570 |
children=4 |
| 571 |
|
| 572 |
listen=udp:10.0.0.10:5060 |
| 573 |
port=5060 |
| 574 |
|
| 575 |
####### Modules Section ######## |
| 576 |
|
| 577 |
# set paths to location of modules (to sources or installation folders) |
| 578 |
#!ifdef WITH_SRCPATH |
| 579 |
mpath="modules_k:modules" |
| 580 |
#!else |
| 581 |
mpath="/usr/local/kamailio/lib64/kamailio/modules_k/:/usr/local/kamailio/lib64/k |
| 582 |
amailio/modules/" |
| 583 |
#!endif |
| 584 |
|
| 585 |
#!ifdef WITH_MYSQL |
| 586 |
loadmodule "db_mysql.so" |
| 587 |
#!endif |
| 588 |
|
| 589 |
loadmodule "tm.so" |
| 590 |
loadmodule "sl.so" |
| 591 |
loadmodule "rr.so" |
| 592 |
loadmodule "pv.so" |
| 593 |
loadmodule "maxfwd.so" |
| 594 |
loadmodule "usrloc.so" |
| 595 |
loadmodule "registrar.so" |
| 596 |
loadmodule "textops.so" |
| 597 |
loadmodule "siputils.so" |
| 598 |
loadmodule "xlog.so" |
| 599 |
loadmodule "sanity.so" |
| 600 |
loadmodule "ctl.so" |
| 601 |
loadmodule "cfg_rpc.so" |
| 602 |
|
| 603 |
#!ifdef WITH_AUTH |
| 604 |
loadmodule "auth.so" |
| 605 |
loadmodule "auth_db.so" |
| 606 |
#!ifdef WITH_IPAUTH |
| 607 |
loadmodule "permissions.so" |
| 608 |
#!endif |
| 609 |
#!endif |
| 610 |
|
| 611 |
#!ifdef WITH_SCA |
| 612 |
loadmodule "sca.so" |
| 613 |
#!endif |
| 614 |
|
| 615 |
|
| 616 |
# ----------------- setting module-specific parameters --------------- |
| 617 |
|
| 618 |
|
| 619 |
# ----- tm params ----- |
| 620 |
# auto-discard branches from previous serial forking leg |
| 621 |
modparam("tm", "failure_reply_mode", 3) |
| 622 |
# default retransmission timeout: 30sec |
| 623 |
modparam("tm", "fr_timer", 30000) |
| 624 |
# default invite retransmission timeout after 1xx: 120sec |
| 625 |
modparam("tm", "fr_inv_timer", 120000) |
| 626 |
|
| 627 |
|
| 628 |
# ----- rr params ----- |
| 629 |
# add value to ;lr param to cope with most of the UAs |
| 630 |
modparam("rr", "enable_full_lr", 1) |
| 631 |
# do not append from tag to the RR (no need for this script) |
| 632 |
modparam("rr", "append_fromtag", 0) |
| 633 |
|
| 634 |
|
| 635 |
# ----- registrar params ----- |
| 636 |
modparam("registrar", "method_filtering", 1) |
| 637 |
/* uncomment the next line to disable parallel forking via location */ |
| 638 |
# modparam("registrar", "append_branches", 0) |
| 639 |
/* uncomment the next line not to allow more than 10 contacts per AOR */ |
| 640 |
#modparam("registrar", "max_contacts", 10) |
| 641 |
# max value for expires of registrations |
| 642 |
modparam("registrar", "max_expires", 3600) |
| 643 |
# set it to 1 to enable GRUU |
| 644 |
modparam("registrar", "gruu_enabled", 0) |
| 645 |
|
| 646 |
|
| 647 |
# ----- usrloc params ----- |
| 648 |
/* enable DB persistency for location entries */ |
| 649 |
#!ifdef WITH_USRLOCDB |
| 650 |
modparam("usrloc", "db_url", DBURL) |
| 651 |
modparam("usrloc", "db_mode", 2) |
| 652 |
modparam("usrloc", "use_domain", 0) |
| 653 |
#!endif |
| 654 |
|
| 655 |
|
| 656 |
# ----- auth_db params ----- |
| 657 |
#!ifdef WITH_AUTH |
| 658 |
modparam("auth_db", "db_url", DBURL) |
| 659 |
modparam("auth_db", "calculate_ha1", yes) |
| 660 |
modparam("auth_db", "password_column", "password") |
| 661 |
modparam("auth_db", "load_credentials", "") |
| 662 |
|
| 663 |
# ----- permissions params ----- |
| 664 |
#!ifdef WITH_IPAUTH |
| 665 |
modparam("permissions", "db_url", DBURL) |
| 666 |
modparam("permissions", "db_mode", 1) |
| 667 |
#!endif |
| 668 |
|
| 669 |
#!endif |
| 670 |
|
| 671 |
# ----- sca params ----- |
| 672 |
#!ifdef WITH_SCA |
| 673 |
modparam("sca", "call_info_max_expires", 300) |
| 674 |
modparam("sca", "db_url", DBURL) |
| 675 |
#!endif |
| 676 |
|
| 677 |
|
| 678 |
####### Routing Logic ######## |
| 679 |
|
| 680 |
# Main SIP request routing logic |
| 681 |
# - processing of any incoming SIP request starts with this route |
| 682 |
# - note: this is the same as route { ... } |
| 683 |
request_route { |
| 684 |
|
| 685 |
# per request initial checks |
| 686 |
route(REQINIT); |
| 687 |
|
| 688 |
# CANCEL processing |
| 689 |
if (is_method("CANCEL")) |
| 690 |
{ |
| 691 |
if (t_check_trans()) { |
| 692 |
route(SCA); |
| 693 |
t_relay(); |
| 694 |
} |
| 695 |
exit; |
| 696 |
} |
| 697 |
|
| 698 |
# handle requests within SIP dialogs |
| 699 |
route(WITHINDLG); |
| 700 |
|
| 701 |
### only initial requests (no To tag) |
| 702 |
|
| 703 |
t_check_trans(); |
| 704 |
|
| 705 |
# authentication |
| 706 |
route(AUTH); |
| 707 |
|
| 708 |
# record routing for dialog forming requests (in case they are routed) |
| 709 |
# - remove preloaded route headers |
| 710 |
remove_hf("Route"); |
| 711 |
if (is_method("INVITE|SUBSCRIBE")) |
| 712 |
record_route(); |
| 713 |
|
| 714 |
# dispatch requests to foreign domains |
| 715 |
route(SIPOUT); |
| 716 |
|
| 717 |
# handle registrations |
| 718 |
route(REGISTRAR); |
| 719 |
|
| 720 |
if ($rU==$null) |
| 721 |
{ |
| 722 |
# request with no Username in RURI |
| 723 |
sl_send_reply("484","Address Incomplete"); |
| 724 |
exit; |
| 725 |
} |
| 726 |
|
| 727 |
# user location service |
| 728 |
route(LOCATION); |
| 729 |
|
| 730 |
route(RELAY); |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
route[RELAY] { |
| 735 |
|
| 736 |
# enable additional event routes for forwarded requests |
| 737 |
if (is_method("INVITE|BYE|SUBSCRIBE|PRACK|REFER|UPDATE")) { |
| 738 |
if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY"); |
| 739 |
} |
| 740 |
if (is_method("INVITE")) { |
| 741 |
if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE"); |
| 742 |
} |
| 743 |
|
| 744 |
route(SCA); |
| 745 |
|
| 746 |
if (!t_relay()) { |
| 747 |
sl_reply_error(); |
| 748 |
} |
| 749 |
exit; |
| 750 |
} |
| 751 |
|
| 752 |
# Per SIP request initial checks |
| 753 |
route[REQINIT] { |
| 754 |
if (!mf_process_maxfwd_header("10")) { |
| 755 |
sl_send_reply("483","Too Many Hops"); |
| 756 |
exit; |
| 757 |
} |
| 758 |
|
| 759 |
if(!sanity_check("1511", "7")) |
| 760 |
{ |
| 761 |
xlog("Malformed SIP message from $si:$sp\n"); |
| 762 |
exit; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
# Handle requests within SIP dialogs |
| 767 |
route[WITHINDLG] { |
| 768 |
if (has_totag()) { |
| 769 |
# sequential request within a dialog should |
| 770 |
# take the path determined by record-routing |
| 771 |
if (loose_route()) { |
| 772 |
if ( is_method("NOTIFY") ) { |
| 773 |
# Add Record-Route for in-dialog NOTIFY as per R |
| 774 |
FC 6665. |
| 775 |
record_route(); |
| 776 |
} |
| 777 |
route(RELAY); |
| 778 |
} else { |
| 779 |
if (is_method("SUBSCRIBE") && uri == myself) { |
| 780 |
# in-dialog subscribe requests |
| 781 |
route(SCA); |
| 782 |
exit; |
| 783 |
} |
| 784 |
if ( is_method("ACK") ) { |
| 785 |
if ( t_check_trans() ) { |
| 786 |
# no loose-route, but stateful ACK; |
| 787 |
# must be an ACK after a 487 |
| 788 |
# or e.g. 404 from upstream server |
| 789 |
t_relay(); |
| 790 |
exit; |
| 791 |
} else { |
| 792 |
# ACK without matching transaction ... i |
| 793 |
gnore and discard |
| 794 |
exit; |
| 795 |
} |
| 796 |
} |
| 797 |
sl_send_reply("404","Not here"); |
| 798 |
} |
| 799 |
exit; |
| 800 |
} |
| 801 |
} |
| 802 |
|
| 803 |
# Handle SIP registrations |
| 804 |
route[REGISTRAR] { |
| 805 |
if (is_method("REGISTER")) |
| 806 |
{ |
| 807 |
if (!save("location")) |
| 808 |
sl_reply_error(); |
| 809 |
|
| 810 |
exit; |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
# USER location service |
| 815 |
route[LOCATION] { |
| 816 |
$avp(oexten) = $rU; |
| 817 |
if (!lookup("location")) { |
| 818 |
$var(rc) = $rc; |
| 819 |
t_newtran(); |
| 820 |
switch ($var(rc)) { |
| 821 |
case -1: |
| 822 |
case -3: |
| 823 |
send_reply("404", "Not Found"); |
| 824 |
exit; |
| 825 |
case -2: |
| 826 |
send_reply("405", "Method Not Allowed"); |
| 827 |
exit; |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
# Authentication route |
| 833 |
route[AUTH] { |
| 834 |
#!ifdef WITH_AUTH |
| 835 |
|
| 836 |
#!ifdef WITH_IPAUTH |
| 837 |
if((!is_method("REGISTER")) && allow_source_address()) |
| 838 |
{ |
| 839 |
# source IP allowed |
| 840 |
return; |
| 841 |
} |
| 842 |
#!endif |
| 843 |
|
| 844 |
if (is_method("REGISTER") || from_uri==myself) |
| 845 |
{ |
| 846 |
# authenticate requests |
| 847 |
if (!auth_check("$fd", "subscriber", "1")) { |
| 848 |
auth_challenge("$fd", "0"); |
| 849 |
exit; |
| 850 |
} |
| 851 |
# user authenticated - remove auth header |
| 852 |
if(!is_method("REGISTER|PUBLISH")) |
| 853 |
consume_credentials(); |
| 854 |
} |
| 855 |
# if caller is not local subscriber, then check if it calls |
| 856 |
# a local destination, otherwise deny, not an open relay here |
| 857 |
if (from_uri!=myself && uri!=myself) |
| 858 |
{ |
| 859 |
sl_send_reply("403","Not relaying"); |
| 860 |
exit; |
| 861 |
} |
| 862 |
|
| 863 |
#!endif |
| 864 |
return; |
| 865 |
} |
| 866 |
|
| 867 |
# Shared Call Appearances handling |
| 868 |
route[SCA] { |
| 869 |
#!ifdef WITH_SCA |
| 870 |
if(is_method("SUBSCRIBE")) { |
| 871 |
if ($hdr(Event) == "call-info" || $hdr(Event) == "line-seize") { |
| 872 |
xdbg("SCA: $hdr(Event) SUBSCRIBE $ru from $si:$sp"); |
| 873 |
sca_handle_subscribe(); |
| 874 |
exit; |
| 875 |
} |
| 876 |
|
| 877 |
return; |
| 878 |
} |
| 879 |
|
| 880 |
if (!is_method("BYE|CANCEL|INVITE|PRACK|REFER")) { |
| 881 |
return; |
| 882 |
} |
| 883 |
|
| 884 |
# this updates appearance state and NOTIFYs SCA subscribers as |
| 885 |
# necessary. it also removes the Call-Info header, if found. |
| 886 |
sca_call_info_update(); |
| 887 |
#!endif |
| 888 |
|
| 889 |
return; |
| 890 |
} |
| 891 |
|
| 892 |
# Routing to foreign domains |
| 893 |
route[SIPOUT] { |
| 894 |
if (!uri==myself) |
| 895 |
{ |
| 896 |
append_hf("P-hint: outbound\r\n"); |
| 897 |
route(RELAY); |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
# XMLRPC routing |
| 902 |
#!ifdef WITH_XMLRPC |
| 903 |
route[XMLRPC] { |
| 904 |
# allow XMLRPC from localhost |
| 905 |
if ((method=="POST" || method=="GET") |
| 906 |
&& (src_ip==127.0.0.1)) { |
| 907 |
# close connection only for xmlrpclib user agents (there is a bu |
| 908 |
g in |
| 909 |
# xmlrpclib: it waits for EOF before interpreting the response). |
| 910 |
if ($hdr(User-Agent) =~ "xmlrpclib") |
| 911 |
set_reply_close(); |
| 912 |
set_reply_no_connect(); |
| 913 |
dispatch_rpc(); |
| 914 |
exit; |
| 915 |
} |
| 916 |
send_reply("403", "Forbidden"); |
| 917 |
exit; |
| 918 |
} |
| 919 |
#!endif |
| 920 |
|
| 921 |
# manage incoming replies |
| 922 |
onreply_route[MANAGE_REPLY] { |
| 923 |
xdbg("incoming reply\n"); |
| 924 |
|
| 925 |
if (status =~ "[456][0-9][0-9]") { |
| 926 |
# don't update SCA state here, since there may be |
| 927 |
# failure route processing (e.g., call forwarding). |
| 928 |
# update state in failure route instead. |
| 929 |
return; |
| 930 |
} |
| 931 |
|
| 932 |
route(SCA); |
| 933 |
} |
| 934 |
|
| 935 |
# manage failure routing cases |
| 936 |
failure_route[MANAGE_FAILURE] { |
| 937 |
if (t_is_canceled()) { |
| 938 |
exit; |
| 939 |
} |
| 940 |
|
| 941 |
route(SCA); |
| 942 |
} |