Browse code

restructured in a separate route block

Jiri Kuthan authored on 22/06/2003 00:08:38
Showing 1 changed files
... ...
@@ -16,7 +16,6 @@ children=4
16 16
 log_stderror=yes # (cmd line: -E)
17 17
 
18 18
 mhomed=yes
19
-listen=192.168.2.16
20 19
 
21 20
 fifo="/tmp/ser_fifo"
22 21
 
... ...
@@ -77,32 +76,10 @@ route{
77 76
 	if (uri==myself) {
78 77
 
79 78
 		if (method=="REGISTER") {
79
+			# save location before initiating welcome
80 80
 			save("location");
81
-			if (!exec_msg('
82
-				# config: 
83
-				# --announcement server
84
-				ANS="sip:7170@iptel.org"
85
-				# --SIP domain
86
-				DOMAIN="192.168.2.16"
87
-				# ----
88
-				# check if first time ...
89
-				SIP_UID=`echo $SIP_HF_TO | sed -e "s/^.*sip:\([a-zA-Z0-9_\.]*\)@.*$/\1/g"`
90
-				QUERY="select flag from subscriber 
91
-						where username=\"$SIP_UID\";
92
-					update subscriber set flag=\"x\" 
93
-						where username=\"$SIP_UID\" ";
94
-				mysql -Bsuser -pheslo -e "$QUERY" ser| grep "^x$" > /dev/null
95
-				# ... if so, c-t-d to announcement server
96
-				if [ "$?" -ne 0 ] ; then
97
-					# flag was not set to x yet -- first-time registration;
98
-					# initiate a call from telephone of the user to an announcement server
99
-					${HOME}/sip_router/examples/ctd.sh "sip:$SIP_UID@$DOMAIN" "$ANS" > /dev/null 2>&1
100
-				fi
101
-			')) {
102
-				sl_send_reply("500", "register/exec failed");
103
-				break;
104
-			};
105
-
81
+			# welcome message
82
+			route(3);
106 83
 			break;
107 84
 		};
108 85
 
... ...
@@ -114,3 +91,34 @@ route{
114 91
 	};
115 92
 	t_relay();
116 93
 }
94
+
95
+# welcome message -- if a REGISTER succeeded, look if it is the first-time;
96
+# if so, initiate click-to-dial transaction to set up call to an announcement
97
+# server; edit the config values first to make it work
98
+route[3] {
99
+	if (!exec_msg('
100
+		# config: 
101
+		# --announcement server URI
102
+		ANS="sip:7170@iptel.org"
103
+		# --SIP domain
104
+		DOMAIN="192.168.2.16"
105
+		# ctd
106
+		CTD=${HOME}/sip_router/examples/ctd.sh
107
+		# ------------------------------------
108
+		# check if first time ...
109
+		SIP_UID=`echo $SIP_HF_TO | sed -e "s/^.*sip:\([a-zA-Z0-9_\.]*\)@.*$/\1/g"`
110
+		QUERY="select flag from subscriber 
111
+				where username=\"$SIP_UID\";
112
+			update subscriber set flag=\"x\" 
113
+				where username=\"$SIP_UID\" ";
114
+			mysql -Bsuser -pheslo -e "$QUERY" ser| grep "^x$" > /dev/null
115
+		# ... if so, c-t-d to announcement server
116
+		if [ "$?" -ne 0 ] ; then
117
+		# flag was not set to x yet -- first-time registration;
118
+		# initiate a call from telephone of the user to an announcement server
119
+			$CTD "sip:$SIP_UID@$DOMAIN" "$ANS" > /dev/null 2>&1
120
+		fi
121
+	')) {
122
+		log(1, "welcome exec failed\n");
123
+	}
124
+}