Browse code

examples ported from stable to devel

Jiri Kuthan authored on 10/10/2003 06:27:18
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,50 @@
1
+#
2
+# $Id$
3
+#
4
+# Example for distributing load accross multiple devices
5
+#
6
+fork=no
7
+log_stderror=yes
8
+listen=192.168.2.16
9
+# ----------- global configuration parameters ------------------------
10
+
11
+loadmodule "modules/exec/exec.so"
12
+loadmodule "modules/sl/sl.so"
13
+loadmodule "modules/tm/tm.so"
14
+
15
+# ----------------- setting module-specific parameters ---------------
16
+
17
+route{
18
+	# uri for my domain ?
19
+	if (!(uri==myself)) {
20
+		sl_send_reply("500", "example serves only my domain");
21
+		break;
22
+	};
23
+	if (method=="REGISTER") {
24
+		sl_send_reply("200", "silly example -- pretend registrar");
25
+		break;
26
+	};
27
+   	exec_dset('
28
+# calculate a characteristic value for this call
29
+CHAR=`echo $SIP_HF_CALLID | sum  | awk " { print \\\$1 } "`
30
+# normalize the value
31
+NC=`expr $CHAR % 100`
32
+
33
+# distribute now
34
+
35
+# gateway 192.168.2.35 @ 10 %
36
+if [ "$NC" -lt 10 ] ; then
37
+	printf "sip:00$SIP_USER@192.168.2.35"
38
+	exit
39
+fi
40
+
41
+# anything else at 90 %
42
+printf "sip:11$SIP_USER@192.168.2.34"  
43
+exit
44
+
45
+# SER adds command-line parameters -- trash them here
46
+echo > dev/null
47
+');
48
+
49
+	t_relay();
50
+}
0 51
new file mode 100644
... ...
@@ -0,0 +1,100 @@
1
+#
2
+# $Id$
3
+#
4
+# this script is configured for use as voicemail UAS; it processes
5
+# INVITEs and BYEs and asks SEMS to record media via "vm"; in this
6
+# script, all record-routing and other constructs known from proxy
7
+# scripts are not present  -- it is a simple UAS 
8
+#
9
+
10
+# ----------- global configuration parameters ------------------------
11
+
12
+#debug=		        # debug level (cmd line: -dddddddddd)
13
+#fork=no
14
+#log_stderror=yes 	# (cmd line: -E)
15
+
16
+
17
+check_via=no		# (cmd. line: -v)
18
+dns=no			# (cmd. line: -r)
19
+rev_dns=no		# (cmd. line: -R)
20
+port=5090
21
+children=4
22
+fifo="/tmp/vm_ser_fifo"
23
+
24
+# ------------------ module loading ----------------------------------
25
+
26
+loadmodule "/home/srouter/sip_router/modules/sl/sl.so"
27
+loadmodule "/home/srouter/sip_router/modules/tm/tm.so"
28
+loadmodule "/home/srouter/sip_router/modules/maxfwd/maxfwd.so"
29
+loadmodule "/home/srouter/sip_router/modules/mysql/mysql.so"
30
+loadmodule "/home/srouter/sip_router/modules/vm/vm.so"
31
+	    
32
+# ----------------- setting module-specific parameters ---------------
33
+
34
+modparam("voicemail", "db_url","sql://ser:heslo@dbhost/ser")
35
+
36
+# -------------------------  request routing logic -------------------
37
+
38
+# main routing logic
39
+
40
+route{
41
+
42
+
43
+	# initial sanity checks -- messages with
44
+	# max_forwars==0, or excessively long requests
45
+	if (!mf_process_maxfwd_header("10")) {
46
+		sl_send_reply("483","Too Many Hops");
47
+		break;
48
+	};
49
+	if (len_gt( max_len )) {
50
+		sl_send_reply("513", "Message too big");
51
+		break;
52
+	};
53
+
54
+	if (!uri==myself) {
55
+		sl_send_reply("404", "not reponsible for host in r-uri");
56
+		break;
57
+	};
58
+
59
+
60
+	# Voicemail specific configuration - begin
61
+
62
+	if(method=="ACK" || method=="INVITE" || method=="BYE"){
63
+
64
+		if (!t_newtran()) {
65
+			log("could not create new transaction\n");
66
+			sl_send_reply("500","could not create new transaction");
67
+			break;
68
+		};
69
+
70
+		t_reply("100","Trying -- just wait a minute !");
71
+		if(method=="INVITE"){
72
+			log("**************** vm start - begin ******************\n");
73
+			if (uri=~"sip:as_welcome@.*" || uri=~"sip:as_nomoney@.*") {
74
+	               		if (!vm("/tmp/am_fifo", "announcement")) {
75
+			        	log("couldn't contact announcement server\n");
76
+					t_reply("500", "couldn not contact announcement server");
77
+				};
78
+			} else {
79
+				if(!vm("/tmp/am_fifo","voicemail")){
80
+					log("could not contact the answer machine\n");
81
+					t_reply("500","could not contact the answer machine");
82
+				};
83
+			};
84
+			log("**************** vm start - end ******************\n");
85
+		} else if(method=="BYE"){
86
+			log("**************** vm end - begin ******************\n");
87
+			if(!vm("/tmp/am_fifo","bye")){
88
+				log("could not contact the answer machine\n");
89
+				t_reply("500","could not contact the answer machine");
90
+			};
91
+			log("**************** vm end - end ******************\n");
92
+		};
93
+		break;
94
+	};
95
+	if (method=="CANCEL") {
96
+		sl_send_reply("200", "cancels are junked here");
97
+		break;
98
+	};
99
+	sl_send_reply("501", "method not understood here");
100
+}