소스 검색

- added call forwarding (always, on busy and on no answer)
- fixed several comments
- moved XMLRPC to module callback because it is safer

Nils Ohlmeier 18 년 전
부모
커밋
7cc2f6e12b
1개의 변경된 파일58개의 추가작업 그리고 10개의 파일을 삭제
  1. 58 10
      etc/ser.cfg

+ 58 - 10
etc/ser.cfg

@@ -76,7 +76,8 @@ loadmodule "/usr/local/lib/ser/modules/xmlrpc.so"
 
 # ----------------- setting script FLAGS -----------------------------
 flags
-  FLAG_ACC         : 1  # include message in accouting
+  FLAG_ACC          : 1,  # include message in accouting
+  FLAG_FAILUREROUTE : 2;  # we are operating from a failure route
 
 avpflags
   dialog_cookie;        # handled by rr module
@@ -136,6 +137,11 @@ modparam("acc_db", "log_flag", "FLAG_ACC")
 # restarts the resend timer (see INBOUND route below)
 #modparam("tm", "restart_fr_on_each_reply", "0")
 
+# -- xmlrpc params --
+# using a sub-route from the module is a lot safer then relying on the
+# request method to distinguish HTTP from SIP
+modparam("xmlrpc", "route", "RPC");
+
 # -------------------------  request routing logic -------------------
 
 # main routing logic
@@ -167,7 +173,7 @@ route{
 	# check if the request is for a local user
 	route(INBOUND);
 
-	# here you coud for example try to an ENUM lookup before
+	# here you could for example try to do an ENUM lookup before
 	# the call gets routed to the PSTN
 	#route(ENUM);
 
@@ -182,6 +188,17 @@ route[FORWARD]
 {
 	# here you could decide wether this call needs a RTP relay or not
 
+	# if this is called from the failure route we need to open a new branch
+	if (isflagset(FLAG_FAILUREROUTE)) {
+		append_branch();
+	}
+
+	# if this is an initial INVITE (without a To-tag) we might try another
+	# (forwarding or voicemail) target after receiving an error
+	if (method=="INVITE" && @to.tag=="") {
+		t_on_failure("FAILURE_ROUTE");
+	}
+
 	# send it out now; use stateful forwarding as it works reliably
 	# even for UDP2TCP
 	if (!t_relay()) {
@@ -192,10 +209,6 @@ route[FORWARD]
 
 route[INIT]
 {
-	# as soon as it is save to distinguish HTTP from SIP
-	# we can un-comment the next line
-	route(RPC);
-
 	# initial sanity checks -- messages with
 	# max_forwards==0, or excessively long requests
 	if (!mf_process_maxfwd_header("10")) {
@@ -212,8 +225,8 @@ route[INIT]
 
 	# or you cuold call here some of the check from the sanity module
 
-	# lets account all initial INVITEs and the BYEs
-	# if (method=="INVITE" && @to.tag=="" || method=="BYE") {
+	# lets account all initial INVITEs
+	# further in-dialog requests are accounted by a RR cookie (see below)
 	if (method=="INVITE" && @to.tag=="") {
 		setflag(FLAG_ACC);
 	}
@@ -230,7 +243,7 @@ route[RPC]
 			drop;
 		}
 
-		# lets see if a module want to answer this
+		# lets see if a module wants to answer this
 		dispatch_rpc();
 		drop;
 	}
@@ -426,6 +439,14 @@ route[INBOUND]
 			#load_attrs("$tr", "@ruri");
 		#}
 
+		# check for call forwarding of the callee
+		# Note: the forwarding target has to be full routable URI
+		#       in this example
+		if ($tu.fwd_always_target) {
+			attr2uri("$tu.fwd_always_target");
+			route(FORWARD);
+		}
+
 		# native SIP destinations are handled using our USRLOC DB
 		if (lookup_contacts("location")) {
 			append_hf("P-hint: usrloc applied\r\n");
@@ -434,7 +455,7 @@ route[INBOUND]
 			# of the callee (avoid too long ringing of his phones)
 			# Note1: timer values have to be in ms now!
 			# Note2: this makes even more sense if you switch to a voicemail
-			#        in a FAILURE route
+			#        from the FAILURE_ROUTE below
 			if ($t.fr_inv_timer) {
 				if ($t.fr_timer) {
 					t_set_fr("$t.fr_inv_timer", "$t.fr_timer");
@@ -475,3 +496,30 @@ route[PSTN]
 		route(FORWARD);
 	}
 }
+
+failure_route[FAILURE_ROUTE]
+{
+	# mark for the other routes that we are operating from here on from a
+	# failure route
+	setflag(FLAG_FAILUREROUTE);
+
+	if (t_check_status("486|600")) {
+		# if we received a busy and a busy target is set, forward it there
+		# Note: again the forwarding target has to be a routeable URI
+		if ($tu.fwd_busy_target) {
+			attr2uri("$tu.fwd_busy_target");
+			route(FORWARD);
+		}
+		# alternatively you could forward the request to SEMS/voicemail here
+	}
+	else if (t_check_status("408|480")) {
+		# if we received no answer and the noanswer target is set,
+		# forward it there
+		# Note: again the target has to be a routeable URI
+		if ($tu.fwd_noanswer_target) {
+			attr2uri("$tu.fwd_noanswer_target");
+			route(FORWARD);
+		}
+		# alternatively you could forward the request to SEMS/voicemail here
+	}
+}