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