| 1 |
UID AVP DB Module |
| 2 |
|
| 3 |
Jiri Kuthan |
| 4 |
|
| 5 |
FhG FOKUS |
| 6 |
<[email protected]> |
| 7 |
|
| 8 |
Copyright © 2004, 2005 FhG FOKUS |
| 9 |
__________________________________________________________________ |
| 10 |
|
| 11 |
Table of Contents |
| 12 |
|
| 13 |
1. Admin Guide |
| 14 |
|
| 15 |
1. Overview |
| 16 |
2. Dependencies |
| 17 |
3. Parameters |
| 18 |
|
| 19 |
3.1. db_url (string) |
| 20 |
3.2. user_attrs_table (string) |
| 21 |
3.3. uri_attrs_table (string) |
| 22 |
3.4. uid_column (string) |
| 23 |
3.5. username_column (string) |
| 24 |
3.6. did_column (string) |
| 25 |
3.7. name_column (string) |
| 26 |
3.8. value_column (string) |
| 27 |
3.9. type_column (string) |
| 28 |
3.10. flags_column (string) |
| 29 |
3.11. scheme_column (string) |
| 30 |
3.12. attr_group (string) |
| 31 |
3.13. auto_unlock_extra_attrs (string) |
| 32 |
|
| 33 |
4. Functions |
| 34 |
|
| 35 |
4.1. load_attrs (track, id) |
| 36 |
4.2. load_extra_attrs (group_id, id) |
| 37 |
4.3. save_extra_attrs (group_id, id) |
| 38 |
4.4. remove_extra_attrs (group_id, id) |
| 39 |
4.5. lock_extra_attrs (group_id, id) |
| 40 |
4.6. unlock_extra_attrs (group_id, id) |
| 41 |
|
| 42 |
5. Example extra attributes usage |
| 43 |
|
| 44 |
List of Examples |
| 45 |
|
| 46 |
1.1. attribute group definition |
| 47 |
|
| 48 |
Chapter 1. Admin Guide |
| 49 |
|
| 50 |
Table of Contents |
| 51 |
|
| 52 |
1. Overview |
| 53 |
2. Dependencies |
| 54 |
3. Parameters |
| 55 |
|
| 56 |
3.1. db_url (string) |
| 57 |
3.2. user_attrs_table (string) |
| 58 |
3.3. uri_attrs_table (string) |
| 59 |
3.4. uid_column (string) |
| 60 |
3.5. username_column (string) |
| 61 |
3.6. did_column (string) |
| 62 |
3.7. name_column (string) |
| 63 |
3.8. value_column (string) |
| 64 |
3.9. type_column (string) |
| 65 |
3.10. flags_column (string) |
| 66 |
3.11. scheme_column (string) |
| 67 |
3.12. attr_group (string) |
| 68 |
3.13. auto_unlock_extra_attrs (string) |
| 69 |
|
| 70 |
4. Functions |
| 71 |
|
| 72 |
4.1. load_attrs (track, id) |
| 73 |
4.2. load_extra_attrs (group_id, id) |
| 74 |
4.3. save_extra_attrs (group_id, id) |
| 75 |
4.4. remove_extra_attrs (group_id, id) |
| 76 |
4.5. lock_extra_attrs (group_id, id) |
| 77 |
4.6. unlock_extra_attrs (group_id, id) |
| 78 |
|
| 79 |
5. Example extra attributes usage |
| 80 |
|
| 81 |
1. Overview |
| 82 |
|
| 83 |
This module contains several functions that can be used to manipulate |
| 84 |
the contents of AVPs (Attribute-Value pairs). The AVPs are variables |
| 85 |
attached to the SIP message being processed. Each variable has its name |
| 86 |
and value. AVPs can be used to store arbitrary data or as a means of |
| 87 |
inter-module communication. |
| 88 |
|
| 89 |
You may also want to check the avpops module which is more flexible and |
| 90 |
contains more functions. In future SER releases the avp module will be |
| 91 |
probably deprecated in favor of avpops module. |
| 92 |
|
| 93 |
Domain module operates in caching mode. Domain module reads the default |
| 94 |
values of AVPs into cache memory when the module is loaded. After that |
| 95 |
default values is re-read only when module is given avp_list_reload |
| 96 |
fifo command. Any changes in usr_preferences_types table must thus be |
| 97 |
followed by avp_list_reload command in order to reflect them in module |
| 98 |
behavior. |
| 99 |
|
| 100 |
2. Dependencies |
| 101 |
|
| 102 |
A database module, such as mysql, postgres, or dbtext. |
| 103 |
|
| 104 |
3. Parameters |
| 105 |
|
| 106 |
3.1. db_url (string) |
| 107 |
3.2. user_attrs_table (string) |
| 108 |
3.3. uri_attrs_table (string) |
| 109 |
3.4. uid_column (string) |
| 110 |
3.5. username_column (string) |
| 111 |
3.6. did_column (string) |
| 112 |
3.7. name_column (string) |
| 113 |
3.8. value_column (string) |
| 114 |
3.9. type_column (string) |
| 115 |
3.10. flags_column (string) |
| 116 |
3.11. scheme_column (string) |
| 117 |
3.12. attr_group (string) |
| 118 |
3.13. auto_unlock_extra_attrs (string) |
| 119 |
|
| 120 |
3.1. db_url (string) |
| 121 |
|
| 122 |
The URL of the database to be used. |
| 123 |
|
| 124 |
Default value is "mysql://ser:heslo@localhost/ser". |
| 125 |
|
| 126 |
3.2. user_attrs_table (string) |
| 127 |
|
| 128 |
Name of the table with user attributes. |
| 129 |
|
| 130 |
Default value is "user_attrs". |
| 131 |
|
| 132 |
3.3. uri_attrs_table (string) |
| 133 |
|
| 134 |
Name of the table with uri attributes. |
| 135 |
|
| 136 |
Default value is "uri_attrs". |
| 137 |
|
| 138 |
3.4. uid_column (string) |
| 139 |
|
| 140 |
Name of the column that stores UID in the user attributes table. |
| 141 |
|
| 142 |
Default value is "uid". |
| 143 |
|
| 144 |
3.5. username_column (string) |
| 145 |
|
| 146 |
Name of the column containing the username of the subscriber in uri |
| 147 |
attributes table. |
| 148 |
|
| 149 |
Default value is "username". |
| 150 |
|
| 151 |
3.6. did_column (string) |
| 152 |
|
| 153 |
Name of the column in uri attributes table containing the ID of domain |
| 154 |
that the subscriber belongs to. |
| 155 |
|
| 156 |
Default value is "did". |
| 157 |
|
| 158 |
3.7. name_column (string) |
| 159 |
|
| 160 |
The name of the column containing attribute names. |
| 161 |
|
| 162 |
Default value is "name". |
| 163 |
|
| 164 |
3.8. value_column (string) |
| 165 |
|
| 166 |
The name of the column containing attribute values. |
| 167 |
|
| 168 |
Default value is "value". |
| 169 |
|
| 170 |
3.9. type_column (string) |
| 171 |
|
| 172 |
The name of the column containing attribute value type. |
| 173 |
|
| 174 |
Default value is "type". |
| 175 |
|
| 176 |
3.10. flags_column (string) |
| 177 |
|
| 178 |
The name of the column containing attribute flags. |
| 179 |
|
| 180 |
Default value is "flags". |
| 181 |
|
| 182 |
3.11. scheme_column (string) |
| 183 |
|
| 184 |
The name of the column containing subscriber's scheme in uri |
| 185 |
attributes. |
| 186 |
|
| 187 |
Default value is "scheme". |
| 188 |
|
| 189 |
3.12. attr_group (string) |
| 190 |
|
| 191 |
'Extra attribute' group definition. It can be repeated to define more |
| 192 |
attribute groups. |
| 193 |
|
| 194 |
The group definition contains one or more assignments in the form |
| 195 |
key=value. Possible keys are: |
| 196 |
|
| 197 |
id |
| 198 |
Attribute group identifier. Must be set. |
| 199 |
|
| 200 |
table |
| 201 |
Table name used for storing attributes from this attribute |
| 202 |
group. Must be set. |
| 203 |
|
| 204 |
flag |
| 205 |
Attribute flag name used to mark attributes in this group. Must |
| 206 |
be set. |
| 207 |
|
| 208 |
key_column |
| 209 |
Column name holding key. Default value is “id”. |
| 210 |
|
| 211 |
name_column |
| 212 |
Column name used for storing attribute name. Default value is |
| 213 |
“name”. |
| 214 |
|
| 215 |
value_column |
| 216 |
Column name used for storing attribute value. Default value is |
| 217 |
“value”. |
| 218 |
|
| 219 |
type_column |
| 220 |
Column name used for storing attribute type. Default value is |
| 221 |
“type”. |
| 222 |
|
| 223 |
flags_column |
| 224 |
Column name used for storing attribute flags. Default value is |
| 225 |
“flags”. |
| 226 |
|
| 227 |
None defined by default. |
| 228 |
|
| 229 |
Example 1.1. attribute group definition |
| 230 |
modparam("avp_db", "attr_group", "id=dlg,flag=dialog_flag,table=dlg_attrs,key_co |
| 231 |
lumn=dlg_id"); |
| 232 |
|
| 233 |
Table used for these attributes: |
| 234 |
mysql> describe dlg_attrs; |
| 235 |
+--------+------------------+------+-----+---------+-------+ |
| 236 |
| Field | Type | Null | Key | Default | Extra | |
| 237 |
+--------+------------------+------+-----+---------+-------+ |
| 238 |
| dlg_id | varchar(256) | NO | MUL | | | |
| 239 |
| name | varchar(32) | NO | | | | |
| 240 |
| value | varchar(255) | YES | | NULL | | |
| 241 |
| type | int(11) | NO | | 0 | | |
| 242 |
| flags | int(10) unsigned | NO | | 0 | | |
| 243 |
+--------+------------------+------+-----+---------+-------+ |
| 244 |
5 rows in set (0.00 sec) |
| 245 |
|
| 246 |
Setting flags from code (all attrs beginning with “dlg_”): |
| 247 |
avpflags dialog_flag; |
| 248 |
... |
| 249 |
route { |
| 250 |
... |
| 251 |
setavpflag("$f./^dlg_/", "dialog_flag"); |
| 252 |
... |
| 253 |
} |
| 254 |
|
| 255 |
3.13. auto_unlock_extra_attrs (string) |
| 256 |
|
| 257 |
Determines the action when any of the 'extra attributes' lock is |
| 258 |
detected when routing script execution was finished. When the value of |
| 259 |
this parameter is zero (default) BUG level message is logged, but the |
| 260 |
lock is kept, so another process trying to obtain the lock might get |
| 261 |
stuck. If the value is nonzero, DEBUG level message is sent to the log |
| 262 |
and all the locks are released. |
| 263 |
|
| 264 |
Default value is 0. |
| 265 |
|
| 266 |
4. Functions |
| 267 |
|
| 268 |
4.1. load_attrs (track, id) |
| 269 |
4.2. load_extra_attrs (group_id, id) |
| 270 |
4.3. save_extra_attrs (group_id, id) |
| 271 |
4.4. remove_extra_attrs (group_id, id) |
| 272 |
4.5. lock_extra_attrs (group_id, id) |
| 273 |
4.6. unlock_extra_attrs (group_id, id) |
| 274 |
|
| 275 |
4.1. load_attrs (track, id) |
| 276 |
|
| 277 |
Loads attributes from the database. |
| 278 |
|
| 279 |
track |
| 280 |
|
| 281 |
$fu |
| 282 |
Load user attributes into from track. In this case the |
| 283 |
second parameter is UID used to search attributes. |
| 284 |
|
| 285 |
$tu |
| 286 |
Load user attributes into to track. In this case the |
| 287 |
second parameter is UID used to search attributes. |
| 288 |
|
| 289 |
$fr |
| 290 |
Load uri attributes into from track. In this case the |
| 291 |
second parameter is URI used to search attributes. |
| 292 |
|
| 293 |
$tr |
| 294 |
Load uri attributes into to track. In this case the second |
| 295 |
parameter is URI used to search attributes. |
| 296 |
|
| 297 |
id |
| 298 |
Identifier used for searching attributes. When searching for |
| 299 |
user attributes it is UID, when searching uri attributes it is |
| 300 |
URI. |
| 301 |
|
| 302 |
4.2. load_extra_attrs (group_id, id) |
| 303 |
|
| 304 |
Loads 'extra attributes' stored by previous call to save_extra_attrs. |
| 305 |
|
| 306 |
group_id |
| 307 |
Identifies attribute group, see Section 3.12, “attr_group |
| 308 |
(string)”. |
| 309 |
|
| 310 |
id |
| 311 |
Identifies attributes which should be loaded. |
| 312 |
|
| 313 |
4.3. save_extra_attrs (group_id, id) |
| 314 |
|
| 315 |
Saves 'extra attributes' flagged by group flag under given id. |
| 316 |
|
| 317 |
group_id |
| 318 |
Identifies attribute group, see Section 3.12, “attr_group |
| 319 |
(string)”. |
| 320 |
|
| 321 |
id |
| 322 |
Identifier stored with flagged attributes. |
| 323 |
|
| 324 |
4.4. remove_extra_attrs (group_id, id) |
| 325 |
|
| 326 |
Removes all extra attributes with given id. |
| 327 |
|
| 328 |
group_id |
| 329 |
Identifies attribute group, see Section 3.12, “attr_group |
| 330 |
(string)”. |
| 331 |
|
| 332 |
id |
| 333 |
Identifies attributes which should be removed. |
| 334 |
|
| 335 |
4.5. lock_extra_attrs (group_id, id) |
| 336 |
|
| 337 |
Locks extra attributes. Currently locks whole attribute group (not only |
| 338 |
id). |
| 339 |
|
| 340 |
group_id |
| 341 |
Identifies attribute group, see Section 3.12, “attr_group |
| 342 |
(string)”. |
| 343 |
|
| 344 |
id |
| 345 |
Identifies attributes which should be locked. |
| 346 |
|
| 347 |
4.6. unlock_extra_attrs (group_id, id) |
| 348 |
|
| 349 |
Unlocks extra attributes. Currently unlocks whole attribute group (not |
| 350 |
only id). |
| 351 |
|
| 352 |
group_id |
| 353 |
Identifies attribute group, see Section 3.12, “attr_group |
| 354 |
(string)”. |
| 355 |
|
| 356 |
id |
| 357 |
Identifies attributes which should be unlocked. |
| 358 |
|
| 359 |
5. Example extra attributes usage |
| 360 |
|
| 361 |
debug=3 |
| 362 |
memdbg=5 |
| 363 |
server_signature=0 |
| 364 |
sip_warning=0 |
| 365 |
check_via=yes; |
| 366 |
dns=no; |
| 367 |
rev_dns=no; |
| 368 |
|
| 369 |
children=4; |
| 370 |
tcp_children=4; |
| 371 |
tcp_max_connections=2048; |
| 372 |
port=5060 |
| 373 |
|
| 374 |
loadmodule "/home/kubartv/SER/lib/ser/modules/sl.so"; |
| 375 |
#loadmodule "/home/kubartv/SER/lib/ser/modules/maxfwd.so"; |
| 376 |
loadmodule "/home/kubartv/SER/lib/ser/modules/tm.so"; |
| 377 |
loadmodule "/home/kubartv/SER/lib/ser/modules/rr.so"; |
| 378 |
#loadmodule "/home/kubartv/SER/lib/ser/modules/xmlrpc.so"; |
| 379 |
loadmodule "/home/kubartv/SER/lib/ser/modules/mysql.so"; |
| 380 |
loadmodule "/home/kubartv/SER/lib/ser/modules/domain.so"; |
| 381 |
loadmodule "/home/kubartv/SER/lib/ser/modules/uri_db.so"; |
| 382 |
loadmodule "/home/kubartv/SER/lib/ser/modules/avp.so"; |
| 383 |
loadmodule "/home/kubartv/SER/lib/ser/modules/avp_db.so"; |
| 384 |
|
| 385 |
loadmodule "/home/kubartv/SER/lib/ser/modules/usrloc.so"; |
| 386 |
loadmodule "/home/kubartv/SER/lib/ser/modules/registrar.so"; |
| 387 |
loadmodule "/home/kubartv/SER/lib/ser/modules/xprint.so"; |
| 388 |
loadmodule "/home/kubartv/SER/lib/ser/modules/eval.so"; |
| 389 |
|
| 390 |
loadmodule "/home/kubartv/SER/lib/ser/modules/gflags.so" |
| 391 |
|
| 392 |
#modparam("maxfwd", "max_limit", 70); |
| 393 |
|
| 394 |
modparam("usrloc", "db_mode", 1); |
| 395 |
modparam("usrloc|avp_db", "db_url", "mysql://ser:[email protected]/ser") |
| 396 |
|
| 397 |
modparam("avp_db", "attr_group", "id=dlg,flag=dialog_flag,table=dlg_attrs,key_co |
| 398 |
lumn=dlg_id"); |
| 399 |
|
| 400 |
modparam("gflags", "load_global_attrs", 1); |
| 401 |
|
| 402 |
avpflags dialog_flag; |
| 403 |
|
| 404 |
route["create_dialog"] { |
| 405 |
# sets attributes needed by dialog (stored when processing reply) |
| 406 |
$dlg_caller = @contact; |
| 407 |
$dlg_caller_cseq = @cseq.num; |
| 408 |
$dlg_status = "new"; |
| 409 |
$dlg_init_method = @cseq.method; |
| 410 |
$dir = "caller2callee"; |
| 411 |
|
| 412 |
t_on_reply("dialog_creation_reply"); |
| 413 |
return 1; |
| 414 |
} |
| 415 |
|
| 416 |
onreply_route["dialog_creation_reply"] { |
| 417 |
xplog("L_ERR", "dialog creation reply (%rs, %@cseq.method) [%@from.tag, |
| 418 |
%@to.tag]\n"); |
| 419 |
|
| 420 |
$res = @msg.response.code; |
| 421 |
xplog("L_ERR", " ... response: %$res\n"); |
| 422 |
if (([email protected]) || (@to.tag=="")) { |
| 423 |
# don't create dialog from response without to tag |
| 424 |
break; |
| 425 |
} |
| 426 |
if ($res < 101) { |
| 427 |
xplog("L_ERR", " ... I won't create dialog from 100 response.\n" |
| 428 |
); |
| 429 |
break; |
| 430 |
} |
| 431 |
|
| 432 |
del_attr("$id"); # xlset_attr works strange when the attribute already e |
| 433 |
xists |
| 434 |
xlset_attr("$id", "call-id:%@call_id caller_tag:%@from.tag callee_tag:%@ |
| 435 |
to.tag"); |
| 436 |
if ($res > 299) { |
| 437 |
xplog("L_ERR", " ... dialog terminated\n"); |
| 438 |
remove_extra_attrs("dlg", "$id"); |
| 439 |
break; |
| 440 |
} |
| 441 |
|
| 442 |
xplog("L_ERR", " ... creating dialog '%$id'\n"); |
| 443 |
# generate dialog id |
| 444 |
|
| 445 |
lock_extra_attrs("dlg", "$id"); |
| 446 |
|
| 447 |
# TODO: try to load the dialog (early dialog may exist)? |
| 448 |
|
| 449 |
# update dialog data |
| 450 |
|
| 451 |
if (($dlg_status == "new") && ($res < 200)) { |
| 452 |
# early response may arrive after final one |
| 453 |
$dlg_callee = @contact; |
| 454 |
$dlg_status = "early"; |
| 455 |
xplog("L_ERR", " ... creating early dialog\n"); |
| 456 |
} |
| 457 |
if ($res >= 200) { |
| 458 |
$dlg_callee = @contact; |
| 459 |
$dlg_status = "confirmed"; |
| 460 |
$dlg_confirmed_at = @sys.now.local; |
| 461 |
xplog("L_ERR", " ... confirming dialog\n"); |
| 462 |
} |
| 463 |
|
| 464 |
route("save_dialog"); |
| 465 |
} |
| 466 |
|
| 467 |
route["save_dialog"] { |
| 468 |
if ($dlg_status == "destroyed") { |
| 469 |
xplog("L_ERR", " ... destroying dialog %$id\n"); |
| 470 |
|
| 471 |
# use this if you want to delete destroyed dialogs: |
| 472 |
# remove_extra_attrs("dlg", "$id"); |
| 473 |
|
| 474 |
# else if you want leave them in DB (with the time of terminatio |
| 475 |
n) |
| 476 |
$dlg_destroyed_at = @sys.now.local; |
| 477 |
|
| 478 |
# set flag for attributes with name beggining with dlg_ |
| 479 |
setavpflag("$f./^dlg_/", "dialog_flag"); |
| 480 |
save_extra_attrs("dlg", "$id"); |
| 481 |
} |
| 482 |
else { |
| 483 |
# set flag for attributes with name beggining with dlg_ |
| 484 |
setavpflag("$f./^dlg_/", "dialog_flag"); |
| 485 |
|
| 486 |
save_extra_attrs("dlg", "$id"); |
| 487 |
} |
| 488 |
unlock_extra_attrs("dlg", "$id"); |
| 489 |
} |
| 490 |
|
| 491 |
route["load_dialog_data"] { |
| 492 |
lock_extra_attrs("dlg", "$id"); |
| 493 |
|
| 494 |
del_attr("$dlg_init_method"); # used as flag of successful read of data |
| 495 |
|
| 496 |
# delete all used dlg attrs (because load_extra_attrs doesn't delete the |
| 497 |
m itself before adding) |
| 498 |
del_attr("$dlg_init_method"); |
| 499 |
del_attr("$dlg_caller"); |
| 500 |
del_attr("$dlg_callee"); |
| 501 |
del_attr("$dlg_caller_cseq"); |
| 502 |
del_attr("$dlg_callee_cseq"); |
| 503 |
del_attr("$dlg_status"); |
| 504 |
|
| 505 |
load_extra_attrs("dlg", "$id"); |
| 506 |
if (!$dlg_init_method) { |
| 507 |
# dialog was not loaded |
| 508 |
unlock_extra_attrs("dlg", "$id"); |
| 509 |
return -1; |
| 510 |
} |
| 511 |
return 1; |
| 512 |
} |
| 513 |
|
| 514 |
route["load_dialog"] { |
| 515 |
# tries to load dialog according tags and callid |
| 516 |
|
| 517 |
# try to load dialog |
| 518 |
del_attr("$id"); # xlset_attr works strange when the attribute already e |
| 519 |
xists |
| 520 |
xlset_attr("$id", "call-id:%@call_id caller_tag:%@from.tag callee_tag:%@ |
| 521 |
to.tag"); |
| 522 |
if (route("load_dialog_data")) { |
| 523 |
$dir = "caller2callee"; |
| 524 |
return 1; |
| 525 |
} |
| 526 |
|
| 527 |
# try to load dialog in other direction |
| 528 |
del_attr("$id"); # xlset_attr works strange when the attribute already e |
| 529 |
xists |
| 530 |
xlset_attr("$id", "call-id:%@call_id caller_tag:%@to.tag callee_tag:%@fr |
| 531 |
om.tag"); |
| 532 |
if (route("load_dialog_data")) { |
| 533 |
$dir = "callee2caller"; |
| 534 |
return 1; |
| 535 |
} |
| 536 |
|
| 537 |
$id = "error"; |
| 538 |
|
| 539 |
return -1; |
| 540 |
} |
| 541 |
|
| 542 |
route["update_dialog_reply"] { |
| 543 |
if ((@cseq.method == "INVITE") || (@cseq.method == "UPDATE")) { |
| 544 |
# target refresh for INVITE dialogs |
| 545 |
|
| 546 |
if ($dir == "caller2calle") { # if request from caller |
| 547 |
$dlg_callee = @contact; # update callee's contact (respo |
| 548 |
nse!) |
| 549 |
} |
| 550 |
else { |
| 551 |
$dlg_caller = @contact; |
| 552 |
} |
| 553 |
} |
| 554 |
if (@cseq.method=="BYE") { |
| 555 |
$dlg_status = "destroyed"; # will be removed in save_dialog |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
route["update_dialog"] { |
| 560 |
if ((@cseq.method == "INVITE") || (@cseq.method == "UPDATE")) { |
| 561 |
# target refresh for INVITE dialogs |
| 562 |
|
| 563 |
if ($dir == "caller2calle") { # if request from caller |
| 564 |
$dlg_caller = @contact; # update caller's contact (reque |
| 565 |
st!) |
| 566 |
} |
| 567 |
else { |
| 568 |
$dlg_callee = @contact; |
| 569 |
} |
| 570 |
} |
| 571 |
|
| 572 |
if ($dir == "caller2callee") { # if request from caller |
| 573 |
# TODO: verify CSeq before modifying and return 500 if lower tha |
| 574 |
n last one |
| 575 |
$dlg_caller_cseq = @cseq.num; |
| 576 |
} |
| 577 |
else { |
| 578 |
# TODO: verify CSeq before modifying and return 500 if lower tha |
| 579 |
n last one |
| 580 |
$dlg_callee_cseq = @cseq.num; |
| 581 |
} |
| 582 |
|
| 583 |
if (method=="BYE") { |
| 584 |
$dlg_status = "pre-destroyed"; # to see that BYE already went th |
| 585 |
rough |
| 586 |
} |
| 587 |
return 1; |
| 588 |
} |
| 589 |
|
| 590 |
route["trace_dialog"] { |
| 591 |
xplog("L_ERR", " ... dialog '%$id'\n"); |
| 592 |
xplog("L_ERR", " -> initial method: %$dlg_init_method\n"); |
| 593 |
xplog("L_ERR", " -> request dir: %$dir\n"); |
| 594 |
xplog("L_ERR", " -> caller: %$dlg_caller\n"); |
| 595 |
xplog("L_ERR", " -> caller's CSeq: %$dlg_caller_cseq\n"); |
| 596 |
xplog("L_ERR", " -> callee: %$dlg_callee\n"); |
| 597 |
xplog("L_ERR", " -> callee's CSeq: %$dlg_callee_cseq\n"); |
| 598 |
xplog("L_ERR", " -> status: %$dlg_status\n"); |
| 599 |
return 1; |
| 600 |
} |
| 601 |
|
| 602 |
onreply_route["dialog_reply"] { |
| 603 |
if ($id) { |
| 604 |
xplog("L_ERR", "In-dialog reply (%rs, %@cseq.method) [%@to.tag, |
| 605 |
%@from.tag]\n"); |
| 606 |
if (!route("load_dialog")) { |
| 607 |
xplog("L_ERR", "Can't load dialog data\n"); |
| 608 |
} |
| 609 |
else { |
| 610 |
route("update_dialog_reply"); |
| 611 |
route("trace_dialog"); |
| 612 |
route("save_dialog"); |
| 613 |
} |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
route { |
| 618 |
if (method=="SUBSCRIBE") { |
| 619 |
# here we support only INVITE/BYE dialogs |
| 620 |
sl_reply("400", "Unsupported"); |
| 621 |
break; |
| 622 |
} |
| 623 |
|
| 624 |
if (!lookup_domain("$td", "@to.uri.host")) { |
| 625 |
sl_send_reply("404", "Domain Not Found"); |
| 626 |
break; |
| 627 |
} |
| 628 |
|
| 629 |
if (!lookup_user("To")) { |
| 630 |
sl_send_reply("404", "Unknown user"); |
| 631 |
break; |
| 632 |
} |
| 633 |
|
| 634 |
if (method=="REGISTER") { |
| 635 |
save("location"); |
| 636 |
break; |
| 637 |
}; |
| 638 |
|
| 639 |
xplog("L_ERR", "----> processing request %@cseq.method\n"); |
| 640 |
|
| 641 |
if (!lookup_domain("$fd", "@from.uri.host")) { |
| 642 |
sl_send_reply("404", "From domain Not Found"); |
| 643 |
break; |
| 644 |
} |
| 645 |
|
| 646 |
if (!lookup_user("From")) { |
| 647 |
sl_send_reply("404", "Unknown user in From"); |
| 648 |
break; |
| 649 |
} |
| 650 |
|
| 651 |
if (method != "REGISTER") record_route(); |
| 652 |
|
| 653 |
# dialog needs transactions |
| 654 |
if (!t_newtran()) { |
| 655 |
sl_send_reply("500", "Can not start transaction"); |
| 656 |
drop; |
| 657 |
} |
| 658 |
|
| 659 |
# dialog creation/loading |
| 660 |
if ([email protected] || (@to.tag == "")) { |
| 661 |
# initial request or non-dialog message |
| 662 |
if (method=="INVITE") { |
| 663 |
route("create_dialog"); |
| 664 |
# we don't save the dialog here because AVPs will be set |
| 665 |
# when reply comes and the dialog will be stored then |
| 666 |
} |
| 667 |
else { |
| 668 |
xplog("L_ERR", "Non-dialog message: %@cseq\n"); |
| 669 |
} |
| 670 |
} |
| 671 |
else { |
| 672 |
# message within dialog |
| 673 |
if (route("load_dialog")) { |
| 674 |
route("update_dialog"); |
| 675 |
route("trace_dialog"); |
| 676 |
route("save_dialog"); |
| 677 |
t_on_reply("dialog_reply"); |
| 678 |
} |
| 679 |
else { |
| 680 |
xplog("L_ERR", "Message within unknown dialog: %@cseq, t |
| 681 |
o_tag=%@to.tag from_tag=%@from.tag\n"); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
if (loose_route()) { |
| 686 |
route(1); |
| 687 |
break; |
| 688 |
} |
| 689 |
|
| 690 |
if (!lookup("location")) { |
| 691 |
t_reply("404", "Not Found"); |
| 692 |
break; |
| 693 |
}; |
| 694 |
route(1); |
| 695 |
} |
| 696 |
|
| 697 |
route[1] |
| 698 |
{ |
| 699 |
xplog("L_ERR", "<---- request %@cseq.method processed\n"); |
| 700 |
# send it out now; use stateful forwarding as it works reliably |
| 701 |
# even for UDP2TCP |
| 702 |
if (!t_relay()) { |
| 703 |
sl_reply_error(); |
| 704 |
}; |
| 705 |
} |