Browse Source

restructured in a separate route block

Jiri Kuthan 22 years ago
parent
commit
bb18021e46
1 changed files with 34 additions and 26 deletions
  1. 34 26
      examples/welcome.cfg

+ 34 - 26
examples/welcome.cfg

@@ -16,7 +16,6 @@ children=4
 log_stderror=yes # (cmd line: -E)
 log_stderror=yes # (cmd line: -E)
 
 
 mhomed=yes
 mhomed=yes
-listen=192.168.2.16
 
 
 fifo="/tmp/ser_fifo"
 fifo="/tmp/ser_fifo"
 
 
@@ -77,32 +76,10 @@ route{
 	if (uri==myself) {
 	if (uri==myself) {
 
 
 		if (method=="REGISTER") {
 		if (method=="REGISTER") {
+			# save location before initiating welcome
 			save("location");
 			save("location");
-			if (!exec_msg('
-				# config: 
-				# --announcement server
-				ANS="sip:[email protected]"
-				# --SIP domain
-				DOMAIN="192.168.2.16"
-				# ----
-				# check if first time ...
-				SIP_UID=`echo $SIP_HF_TO | sed -e "s/^.*sip:\([a-zA-Z0-9_\.]*\)@.*$/\1/g"`
-				QUERY="select flag from subscriber 
-						where username=\"$SIP_UID\";
-					update subscriber set flag=\"x\" 
-						where username=\"$SIP_UID\" ";
-				mysql -Bsuser -pheslo -e "$QUERY" ser| grep "^x$" > /dev/null
-				# ... if so, c-t-d to announcement server
-				if [ "$?" -ne 0 ] ; then
-					# flag was not set to x yet -- first-time registration;
-					# initiate a call from telephone of the user to an announcement server
-					${HOME}/sip_router/examples/ctd.sh "sip:$SIP_UID@$DOMAIN" "$ANS" > /dev/null 2>&1
-				fi
-			')) {
-				sl_send_reply("500", "register/exec failed");
-				break;
-			};
-
+			# welcome message
+			route(3);
 			break;
 			break;
 		};
 		};
 
 
@@ -114,3 +91,34 @@ route{
 	};
 	};
 	t_relay();
 	t_relay();
 }
 }
+
+# welcome message -- if a REGISTER succeeded, look if it is the first-time;
+# if so, initiate click-to-dial transaction to set up call to an announcement
+# server; edit the config values first to make it work
+route[3] {
+	if (!exec_msg('
+		# config: 
+		# --announcement server URI
+		ANS="sip:[email protected]"
+		# --SIP domain
+		DOMAIN="192.168.2.16"
+		# ctd
+		CTD=${HOME}/sip_router/examples/ctd.sh
+		# ------------------------------------
+		# check if first time ...
+		SIP_UID=`echo $SIP_HF_TO | sed -e "s/^.*sip:\([a-zA-Z0-9_\.]*\)@.*$/\1/g"`
+		QUERY="select flag from subscriber 
+				where username=\"$SIP_UID\";
+			update subscriber set flag=\"x\" 
+				where username=\"$SIP_UID\" ";
+			mysql -Bsuser -pheslo -e "$QUERY" ser| grep "^x$" > /dev/null
+		# ... if so, c-t-d to announcement server
+		if [ "$?" -ne 0 ] ; then
+		# flag was not set to x yet -- first-time registration;
+		# initiate a call from telephone of the user to an announcement server
+			$CTD "sip:$SIP_UID@$DOMAIN" "$ANS" > /dev/null 2>&1
+		fi
+	')) {
+		log(1, "welcome exec failed\n");
+	}
+}