Browse code

new exec examples introduced

Jiri Kuthan authored on 05/01/2003 20:37:51
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,23 @@
0
+#
1
+# $Id$
2
+#
3
+# send a notificiation if a request for user jiri arrives
4
+# ------------------ module loading ----------------------------------
5
+
6
+loadmodule "modules/exec/exec.so"
7
+loadmodule "modules/sl/sl.so"
8
+
9
+# -------------------------  request routing logic -------------------
10
+
11
+# main routing logic
12
+
13
+route{
14
+	# send email if a request for jiri arrives
15
+	if (uri=~"^sip:jiri@") {
16
+		exec_msg("(egrep -i '^(From|f):'; 
17
+			echo 'request received')|
18
+			mail -s 'request for you' jiri");
19
+	};
20
+
21
+}
22
+
0 23
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+#
1
+# $Id$
2
+#
3
+# email notification to email address from mysql database
4
+#
5
+
6
+# ------------------ module loading ----------------------------------
7
+
8
+loadmodule "modules/exec/exec.so"
9
+loadmodule "modules/sl/sl.so"
10
+
11
+# send email if a request arrives
12
+route[0] {
13
+     if (!exec_msg('
14
+	QUERY="select email_address from subscriber 
15
+		where user_id=\"$SIP_OUSER\"";
16
+	EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
17
+	if [ -z "$EMAIL" ] ; then exit 1; fi ;
18
+	echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
19
+	mail -s "request for you" $EMAIL ')) {
20
+		# exec returned error ... user does not exist
21
+		sl_send_reply("404", "User does not exist");
22
+	} else {
23
+		sl_send_reply("600", "No messages for this user");
24
+	};
25
+		
26
+}
0 27
new file mode 100644
... ...
@@ -0,0 +1,39 @@
0
+#
1
+# $Id$
2
+#
3
+# email notification to email address from mysql database
4
+#
5
+
6
+fork=no
7
+
8
+# ------------------ module loading ----------------------------------
9
+
10
+loadmodule "modules/exec/exec.so"
11
+loadmodule "modules/sl/sl.so"
12
+loadmodule "modules/tm/tm.so"
13
+
14
+# send email if a request arrives; process statefully
15
+# to avoid multiple execution on request retransmissions
16
+route[0] {
17
+	# stop script processing if transaction exists
18
+	if ( !t_newtran()) {
19
+		sl_reply_error();
20
+		break;
21
+	};
22
+
23
+     	if (!exec_msg('
24
+		QUERY="select email_address from subscriber 
25
+			where user_id=\"$SIP_OUSER\"";
26
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
27
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
28
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
29
+		mail -s "request for you" $EMAIL ')) 
30
+	{
31
+		# exec returned error ... user does not exist
32
+		# send a stateful reply
33
+		t_reply("404", "User does not exist");
34
+	} else {
35
+		t_reply("600", "No messages for this user");
36
+	};
37
+		
38
+}
0 39
new file mode 100644
... ...
@@ -0,0 +1,65 @@
0
+#
1
+# $Id$
2
+#
3
+# simple quick-start config script
4
+#
5
+fork=no
6
+log_stderror=yes
7
+# ----------- global configuration parameters ------------------------
8
+
9
+loadmodule "modules/sl/sl.so"
10
+loadmodule "modules/tm/tm.so"
11
+loadmodule "modules/usrloc/usrloc.so"
12
+loadmodule "modules/registrar/registrar.so"
13
+loadmodule "modules/exec/exec.so"
14
+
15
+# ----------------- setting module-specific parameters ---------------
16
+
17
+route{
18
+	# uri for my domain ?
19
+	if (uri==myself) {
20
+
21
+		if (method=="REGISTER") {
22
+			save("location");
23
+			break;
24
+		};
25
+
26
+		# native SIP destinations are handled using our USRLOC DB
27
+		if (!lookup("location")) {
28
+			# proceed to email notification
29
+			if (method=="INVITE") route(1)
30
+			else sl_send_reply("404", "Not Found");
31
+			break;
32
+		};
33
+	};
34
+	# user found, forward to his current uri now
35
+	if (!t_relay()) {
36
+		sl_reply_error();
37
+	};
38
+}
39
+
40
+/* handling of missed calls */
41
+route[1] {
42
+	# don't continue if it is a retransmission
43
+	if ( !t_newtran()) {
44
+		sl_reply_error();
45
+		break;
46
+	};
47
+	# external script: lookup user, if user exists, send 
48
+	# an email notification to him
49
+     	if (!exec_msg('
50
+		QUERY="select email_address from subscriber 
51
+			where user_id=\"$SIP_OUSER\"";
52
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
53
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
54
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
55
+		mail -s "request for you" $EMAIL ')) 
56
+	{
57
+		# exec returned error ... user does not exist
58
+		# send a stateful reply
59
+		t_reply("404", "User does not exist");
60
+	} else {
61
+		t_reply("600", "No messages for this user");
62
+	};
63
+	break;
64
+}
0 65
new file mode 100644
... ...
@@ -0,0 +1,79 @@
0
+#
1
+# $Id$
2
+#
3
+# simple quick-start config script
4
+#
5
+fork=no
6
+log_stderror=yes
7
+# ----------- global configuration parameters ------------------------
8
+
9
+loadmodule "modules/sl/sl.so"
10
+loadmodule "modules/tm/tm.so"
11
+loadmodule "modules/usrloc/usrloc.so"
12
+loadmodule "modules/registrar/registrar.so"
13
+loadmodule "modules/exec/exec.so"
14
+
15
+# ----------------- setting module-specific parameters ---------------
16
+
17
+route{
18
+	# uri for my domain ?
19
+	if (uri==myself) {
20
+
21
+		if (method=="REGISTER") {
22
+			save("location");
23
+			break;
24
+		};
25
+
26
+		# native SIP destinations are handled using our USRLOC DB
27
+		if (!lookup("location")) {
28
+			# proceed to email notification
29
+			if (method=="INVITE") route(1)
30
+			else sl_send_reply("404", "Not Found");
31
+			break;
32
+		};
33
+	};
34
+	# user found, forward to his current uri now; if any 
35
+	# forwarding error occurs (e.g., busy or cancelled recevied
36
+	# from downstream), proceed to reply_route[1]
37
+	t_on_negative("1");
38
+	if (!t_relay()) {
39
+		sl_reply_error();
40
+	};
41
+}
42
+
43
+/* handling of missed calls */
44
+route[1] {
45
+	# don't continue if it is a retransmission
46
+	if ( !t_newtran()) {
47
+		sl_reply_error();
48
+		break;
49
+	};
50
+	# external script: lookup user, if user exists, send 
51
+	# an email notification to him
52
+     	if (!exec_msg('
53
+		QUERY="select email_address from subscriber 
54
+			where user_id=\"$SIP_OUSER\"";
55
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
56
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
57
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
58
+		mail -s "request for you" $EMAIL ')) 
59
+	{
60
+		# exec returned error ... user does not exist
61
+		# send a stateful reply
62
+		t_reply("404", "User does not exist");
63
+	} else {
64
+		t_reply("600", "No messages for this user");
65
+	};
66
+	break;
67
+}
68
+
69
+reply_route[1] {
70
+	# just call exec, that's it
71
+     	exec_msg('
72
+		QUERY="select email_address from subscriber 
73
+			where user_id=\"$SIP_OUSER\"";
74
+		EMAIL=`mysql  -Bsuser -pheslo -e "$QUERY" ser`;
75
+		if [ -z "$EMAIL" ] ; then exit 1; fi ;
76
+		echo "SIP request received from $SIP_HF_FROM for $SIP_OUSER" |
77
+		mail -s "request for you" $EMAIL ') ;
78
+}