... | ... |
@@ -76,7 +76,8 @@ loadmodule "/usr/local/lib/ser/modules/xmlrpc.so" |
76 | 76 |
|
77 | 77 |
# ----------------- setting script FLAGS ----------------------------- |
78 | 78 |
flags |
79 |
- FLAG_ACC : 1 # include message in accouting |
|
79 |
+ FLAG_ACC : 1, # include message in accouting |
|
80 |
+ FLAG_FAILUREROUTE : 2; # we are operating from a failure route |
|
80 | 81 |
|
81 | 82 |
avpflags |
82 | 83 |
dialog_cookie; # handled by rr module |
... | ... |
@@ -136,6 +137,11 @@ modparam("acc_db", "log_flag", "FLAG_ACC") |
136 | 137 |
# restarts the resend timer (see INBOUND route below) |
137 | 138 |
#modparam("tm", "restart_fr_on_each_reply", "0") |
138 | 139 |
|
140 |
+# -- xmlrpc params -- |
|
141 |
+# using a sub-route from the module is a lot safer then relying on the |
|
142 |
+# request method to distinguish HTTP from SIP |
|
143 |
+modparam("xmlrpc", "route", "RPC"); |
|
144 |
+ |
|
139 | 145 |
# ------------------------- request routing logic ------------------- |
140 | 146 |
|
141 | 147 |
# main routing logic |
... | ... |
@@ -167,7 +173,7 @@ route{ |
167 | 173 |
# check if the request is for a local user |
168 | 174 |
route(INBOUND); |
169 | 175 |
|
170 |
- # here you coud for example try to an ENUM lookup before |
|
176 |
+ # here you could for example try to do an ENUM lookup before |
|
171 | 177 |
# the call gets routed to the PSTN |
172 | 178 |
#route(ENUM); |
173 | 179 |
|
... | ... |
@@ -182,6 +188,17 @@ route[FORWARD] |
182 | 188 |
{ |
183 | 189 |
# here you could decide wether this call needs a RTP relay or not |
184 | 190 |
|
191 |
+ # if this is called from the failure route we need to open a new branch |
|
192 |
+ if (isflagset(FLAG_FAILUREROUTE)) { |
|
193 |
+ append_branch(); |
|
194 |
+ } |
|
195 |
+ |
|
196 |
+ # if this is an initial INVITE (without a To-tag) we might try another |
|
197 |
+ # (forwarding or voicemail) target after receiving an error |
|
198 |
+ if (method=="INVITE" && @to.tag=="") { |
|
199 |
+ t_on_failure("FAILURE_ROUTE"); |
|
200 |
+ } |
|
201 |
+ |
|
185 | 202 |
# send it out now; use stateful forwarding as it works reliably |
186 | 203 |
# even for UDP2TCP |
187 | 204 |
if (!t_relay()) { |
... | ... |
@@ -192,10 +209,6 @@ route[FORWARD] |
192 | 209 |
|
193 | 210 |
route[INIT] |
194 | 211 |
{ |
195 |
- # as soon as it is save to distinguish HTTP from SIP |
|
196 |
- # we can un-comment the next line |
|
197 |
- route(RPC); |
|
198 |
- |
|
199 | 212 |
# initial sanity checks -- messages with |
200 | 213 |
# max_forwards==0, or excessively long requests |
201 | 214 |
if (!mf_process_maxfwd_header("10")) { |
... | ... |
@@ -212,8 +225,8 @@ route[INIT] |
212 | 225 |
|
213 | 226 |
# or you cuold call here some of the check from the sanity module |
214 | 227 |
|
215 |
- # lets account all initial INVITEs and the BYEs |
|
216 |
- # if (method=="INVITE" && @to.tag=="" || method=="BYE") { |
|
228 |
+ # lets account all initial INVITEs |
|
229 |
+ # further in-dialog requests are accounted by a RR cookie (see below) |
|
217 | 230 |
if (method=="INVITE" && @to.tag=="") { |
218 | 231 |
setflag(FLAG_ACC); |
219 | 232 |
} |
... | ... |
@@ -230,7 +243,7 @@ route[RPC] |
230 | 243 |
drop; |
231 | 244 |
} |
232 | 245 |
|
233 |
- # lets see if a module want to answer this |
|
246 |
+ # lets see if a module wants to answer this |
|
234 | 247 |
dispatch_rpc(); |
235 | 248 |
drop; |
236 | 249 |
} |
... | ... |
@@ -426,6 +439,14 @@ route[INBOUND] |
426 | 439 |
#load_attrs("$tr", "@ruri"); |
427 | 440 |
#} |
428 | 441 |
|
442 |
+ # check for call forwarding of the callee |
|
443 |
+ # Note: the forwarding target has to be full routable URI |
|
444 |
+ # in this example |
|
445 |
+ if ($tu.fwd_always_target) { |
|
446 |
+ attr2uri("$tu.fwd_always_target"); |
|
447 |
+ route(FORWARD); |
|
448 |
+ } |
|
449 |
+ |
|
429 | 450 |
# native SIP destinations are handled using our USRLOC DB |
430 | 451 |
if (lookup_contacts("location")) { |
431 | 452 |
append_hf("P-hint: usrloc applied\r\n"); |
... | ... |
@@ -434,7 +455,7 @@ route[INBOUND] |
434 | 455 |
# of the callee (avoid too long ringing of his phones) |
435 | 456 |
# Note1: timer values have to be in ms now! |
436 | 457 |
# Note2: this makes even more sense if you switch to a voicemail |
437 |
- # in a FAILURE route |
|
458 |
+ # from the FAILURE_ROUTE below |
|
438 | 459 |
if ($t.fr_inv_timer) { |
439 | 460 |
if ($t.fr_timer) { |
440 | 461 |
t_set_fr("$t.fr_inv_timer", "$t.fr_timer"); |
... | ... |
@@ -475,3 +496,30 @@ route[PSTN] |
475 | 496 |
route(FORWARD); |
476 | 497 |
} |
477 | 498 |
} |
499 |
+ |
|
500 |
+failure_route[FAILURE_ROUTE] |
|
501 |
+{ |
|
502 |
+ # mark for the other routes that we are operating from here on from a |
|
503 |
+ # failure route |
|
504 |
+ setflag(FLAG_FAILUREROUTE); |
|
505 |
+ |
|
506 |
+ if (t_check_status("486|600")) { |
|
507 |
+ # if we received a busy and a busy target is set, forward it there |
|
508 |
+ # Note: again the forwarding target has to be a routeable URI |
|
509 |
+ if ($tu.fwd_busy_target) { |
|
510 |
+ attr2uri("$tu.fwd_busy_target"); |
|
511 |
+ route(FORWARD); |
|
512 |
+ } |
|
513 |
+ # alternatively you could forward the request to SEMS/voicemail here |
|
514 |
+ } |
|
515 |
+ else if (t_check_status("408|480")) { |
|
516 |
+ # if we received no answer and the noanswer target is set, |
|
517 |
+ # forward it there |
|
518 |
+ # Note: again the target has to be a routeable URI |
|
519 |
+ if ($tu.fwd_noanswer_target) { |
|
520 |
+ attr2uri("$tu.fwd_noanswer_target"); |
|
521 |
+ route(FORWARD); |
|
522 |
+ } |
|
523 |
+ # alternatively you could forward the request to SEMS/voicemail here |
|
524 |
+ } |
|
525 |
+} |