Browse code

Initial revision

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 13/06/2005 16:47:24
Showing 19 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+#
1
+# $Id$
2
+#
3
+# example: accounting calls to nummerical destinations
4
+#
5
+
6
+# ------------------ module loading ----------------------------------
7
+
8
+loadmodule "modules/tm/tm.so"
9
+loadmodule "modules/acc/acc.so"
10
+loadmodule "modules/sl/sl.so"
11
+loadmodule "modules/maxfwd/maxfwd.so"
12
+loadmodule "modules/rr/rr.so"
13
+
14
+# ----------------- setting module-specific parameters ---------------
15
+
16
+# -- acc params --
17
+# set the reporting log level
18
+modparam("acc", "log_level", 1)
19
+# number of flag, which will be used for accounting; if a message is
20
+# labeled with this flag, its completion status will be reported
21
+modparam("acc", "log_flag", 1 )
22
+
23
+# -------------------------  request routing logic -------------------
24
+
25
+# main routing logic
26
+
27
+route{
28
+
29
+	/* ********* ROUTINE CHECKS  ********************************** */
30
+
31
+	# filter too old messages
32
+	if (!mf_process_maxfwd_header("10")) {
33
+		log("LOG: Too many hops\n");
34
+		sl_send_reply("483","Too Many Hops");
35
+		break;
36
+	};
37
+	if (len_gt( max_len )) {
38
+		sl_send_reply("513", "Wow -- Message too large");
39
+		break;
40
+	};
41
+
42
+    #  Process record-routing
43
+    if (loose_route()) { t_relay(); break; };
44
+
45
+
46
+	# labeled all transaction for accounting
47
+	setflag(1);
48
+
49
+	# record-route INVITES to make sure BYEs will visit our server too
50
+	if (method=="INVITE") record_route();
51
+
52
+	# forward the request statefuly now; (we need *stateful* forwarding,
53
+	# because the stateful mode correlates requests with replies and
54
+	# drops retranmissions; otherwise, we would have to report on
55
+	# every single message received)
56
+	if (!t_relay()) {
57
+		sl_reply_error(); 
58
+		break; 
59
+	};
60
+
61
+}
0 62
new file mode 100644
... ...
@@ -0,0 +1,238 @@
0
+#!/bin/sh
1
+#
2
+# $Id$
3
+#
4
+# Usage: ctd.sh $FROM $TARGET
5
+# 
6
+# click-to-dial example using REFER
7
+#----------------------------------
8
+#
9
+# About:
10
+# ------
11
+# this script initiates a call from SIP user $FROM to SIP
12
+# user $TARGET; it works as follows: a dummy user invites
13
+# $FROM to a dummy "call on hold"; as soon as it is set up, the
14
+# dummy user transfers $FROM to $TARGET  (REFER transaction)
15
+# and terminates the dummy session established previously
16
+# (BYE transaction). Note: the "dummy call" is used to
17
+# make $FROM accept $REFER -- most of SIP phones do not
18
+# accept REFER if no call has not been established yet.
19
+#
20
+# Requirements: 
21
+# -------------
22
+# - SER with FIFO server turned on and TM module loaded
23
+#
24
+# Limitations: 
25
+# ------------
26
+# it only works with UAs supporting REFER; it has been tested 
27
+# with Cisco 7960, Mitel 5055, Grandstream and Pingtel; Windows 
28
+# Messenger does not support REFER. Never tested on solaris. 
29
+# Some cisco 7960 images don't work (in particular, POS30202
30
+# doesnt, POS3-03-8-21 does)
31
+#
32
+# History:
33
+# --------
34
+# 2003-03-01 bug_fix: route set reversed
35
+# 2003-02-27 dialog support completed (jiri)
36
+# 2003-04-28 dialog info precomputed in SER (jiri)
37
+
38
+#--------------------------------
39
+# config: who with whom
40
+# address of the final destination to which we want to transfer
41
+# initial CSeq and CallId
42
+if [ -z "$2" ]; then
43
+	TARGET="sip:23@192.168.2.16"
44
+	echo "destination unspecified -- taking default value $TARGET"
45
+else
46
+	TARGET="$2"
47
+fi
48
+# address of user wishing to initiate conversation
49
+if [ -z "$1" ] ; then
50
+	URI="sip:44@192.168.2.16"
51
+	echo "caller unspecified -- taking default value $URI"
52
+else
53
+	URI="$1"
54
+fi
55
+
56
+#---------------------------------
57
+# fixed config data
58
+FIFO="/tmp/ser_fifo"
59
+# address of controller
60
+FROM="<sip:controller@foo.bar>"
61
+CSEQ="1"
62
+CALLIDNR=`date '+%s'`$$
63
+CALLID="${CALLIDNR}.fifouacctd"
64
+name="ctd_fifo_$$"
65
+fifo_reply="/tmp/$name"
66
+dlg="/tmp/$CALLID.dlg"
67
+FIXED_DLG=`printf "From: $FROM;tag=$CALLIDNR\nCall-ID: $CALLID\nContact: <sip:caller@!!>"`
68
+#----------------------------------
69
+
70
+# generate parts of FIFO-request essential to forming
71
+# subsequent in-dialog reuqests
72
+# 
73
+# limitations: parsing broken if <> in display names or
74
+# line-folding used
75
+filter_fl()
76
+{
77
+
78
+awk -F ' ' '
79
+BEGIN { IGNORECASE=1; line=0; eoh=0;ret=1 }
80
+END { exit ret; }
81
+
82
+{line++; }
83
+
84
+# line 1: status code
85
+line==1 && /^2[0-9][0-9] / { ret=0;next; }
86
+line==1 && /^[3-6][0-9][0-9] / { print; print $0 > "/dev/stderr"; next; }
87
+line==1 { print "reply error"; print; next; } 
88
+
89
+# skip body
90
+/^$/ { eoh=1 }
91
+eoh==1 { next }
92
+
93
+# uri and outbound uri at line 2,3: copy and paste
94
+line==2 || line==3 { print $0; next; }
95
+# line 4: Route; empty if ".", copy and paste otherwise
96
+line==4 && /^\.$/ { next; }
97
+# if non-empty, copy and paste it
98
+line==4 { print $0; next; }
99
+# filter out to header field for use in next requests
100
+/^(To|t):/ { print $0; next; }
101
+# anything else will be ignored
102
+{next} 
103
+	' # end of awk script
104
+} # end of filter_fl
105
+
106
+#---------------------------
107
+# main
108
+
109
+# set up exit cleaner
110
+trap "rm -f $dlg $fifo_reply; exit 1" 0
111
+
112
+# set up FIFO communication
113
+
114
+if [ ! -w $FIFO ] ; then # can I write to FIFO server?
115
+	echo "Error opening ser's FIFO $FIFO"
116
+	exit 1
117
+fi
118
+mkfifo $fifo_reply # create a reply FIFO
119
+if [ $? -ne 0 ] ; then
120
+	echo "error opening reply fifo $fifo_reply"
121
+	exit 1
122
+fi
123
+chmod a+w $fifo_reply
124
+# start reader now so that it is ready for replies
125
+# immediately after a request is out
126
+cat < $fifo_reply | filter_fl > $dlg  &
127
+fifo_job="$!"
128
+
129
+# initiate dummy INVITE with pre-3261 "on-hold"
130
+# (note the dots -- they mean in order of appearance:
131
+# outbound uri, end of headers, end of body; eventualy
132
+# the FIFO request must be terminated with an empty line)
133
+cat > $FIFO <<EOF
134
+
135
+:t_uac_dlg:$name
136
+INVITE 
137
+$URI
138
+.
139
+$FIXED_DLG
140
+To: <$URI>
141
+CSeq: $CSEQ INVITE
142
+Content-Type: application/sdp
143
+.
144
+v=0
145
+o=click-to-dial 0 0 IN IP4 0.0.0.0
146
+s=session
147
+c=IN IP4 0.0.0.0
148
+b=CT:1000
149
+t=0 0
150
+m=audio 9 RTP/AVP 0
151
+a=rtpmap:0 PCMU/8000
152
+.
153
+
154
+EOF
155
+
156
+# wait for reply 
157
+wait $fifo_job # returns completion status of filter_fl
158
+if [ "$?" -ne "0" ] ; then
159
+	echo "invitation failed"
160
+	exit 1
161
+fi
162
+
163
+echo "invitation succeeded"
164
+
165
+# proceed to REFER now
166
+if [ \! -r $dlg ] ; then
167
+	echo "dialog broken"
168
+	exit 1
169
+fi
170
+CSEQ=`expr $CSEQ + 1`
171
+
172
+# start reader now so that it is ready for replies
173
+# immediately after a request is out
174
+cat < $fifo_reply | filter_fl > /dev/null  &
175
+fifo_job="$!"
176
+
177
+# dump the REFER request to FIFO server 
178
+cat > $FIFO <<EOF
179
+
180
+:t_uac_dlg:$name
181
+REFER
182
+`cat $dlg`
183
+$FIXED_DLG
184
+CSeq: $CSEQ REFER
185
+Referred-By: $FROM
186
+Refer-To: $TARGET
187
+.
188
+.
189
+
190
+EOF
191
+
192
+# report REFER status
193
+wait $fifo_job
194
+ref_ret="$?"
195
+
196
+if [ "$ref_ret" -ne "0" ] ; then
197
+	echo "refer failed"
198
+else
199
+	echo "refer succeeded"
200
+fi
201
+
202
+
203
+# well, URI is trying to call TARGET but still maintains the
204
+# dummy call we established with previous INVITE transaction:
205
+# tear it down
206
+
207
+
208
+# dump the BYE request to FIFO server 
209
+CSEQ=`expr $CSEQ + 1`
210
+cat < $fifo_reply | filter_fl > /dev/null  &
211
+fifo_job="$!"
212
+cat > $FIFO <<EOF
213
+
214
+:t_uac_dlg:$name
215
+BYE
216
+`cat $dlg`
217
+$FIXED_DLG
218
+CSeq: $CSEQ BYE
219
+.
220
+.
221
+
222
+EOF
223
+
224
+# report BYE status
225
+wait $fifo_job
226
+ret="$?"
227
+
228
+if [ "$ret" -ne "0" ] ; then
229
+	echo "bye failed"
230
+	exit 1
231
+fi
232
+echo "bye succeeded"
233
+
234
+# clean-up
235
+trap 0
236
+rm -f $dlg $fifo_reply
237
+exit $ref_ret
0 238
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=\"$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=\"$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=\"$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,100 @@
0
+#
1
+# $Id$
2
+#
3
+# simple quick-start config script
4
+#
5
+
6
+# ----------- global configuration parameters ------------------------
7
+
8
+debug=3         # debug level (cmd line: -dddddddddd)
9
+fork=yes
10
+log_stderror=no	# (cmd line: -E)
11
+
12
+fork=no
13
+log_stderror=yes
14
+
15
+check_via=no	# (cmd. line: -v)
16
+dns=no           # (cmd. line: -r)
17
+rev_dns=no      # (cmd. line: -R)
18
+children=4
19
+fifo="/tmp/ser_fifo"
20
+
21
+listen=195.37.77.100
22
+port=5068
23
+
24
+# ------------------ module loading ----------------------------------
25
+
26
+# Uncomment this if you want to use SQL database
27
+#loadmodule "/usr/local/lib/ser/modules/mysql.so"
28
+
29
+loadmodule "/usr/local/lib/ser/modules/sl.so"
30
+loadmodule "/usr/local/lib/ser/modules/tm.so"
31
+loadmodule "/usr/local/lib/ser/modules/rr.so"
32
+loadmodule "/usr/local/lib/ser/modules/maxfwd.so"
33
+loadmodule "/usr/local/lib/ser/modules/usrloc.so"
34
+loadmodule "/usr/local/lib/ser/modules/registrar.so"
35
+loadmodule "/usr/local/lib/ser/modules/textops.so"
36
+
37
+# Uncomment this if you want digest authentication
38
+# mysql.so must be loaded !
39
+#loadmodule "/usr/local/lib/ser/modules/auth.so"
40
+#loadmodule "/usr/local/lib/ser/modules/auth_db.so"
41
+
42
+# ----------------- setting module-specific parameters ---------------
43
+
44
+# -- usrloc params --
45
+
46
+modparam("usrloc", "db_mode",   0)
47
+
48
+# Uncomment this if you want to use SQL database 
49
+# for persistent storage and comment the previous line
50
+#modparam("usrloc", "db_mode", 2)
51
+
52
+# -- auth params --
53
+# Uncomment if you are using auth module
54
+#
55
+#modparam("auth_db", "calculate_ha1", yes)
56
+#
57
+# If you set "calculate_ha1" parameter to yes (which true in this config), 
58
+# uncomment also the following parameter)
59
+#
60
+#modparam("auth_db", "password_column", "password")
61
+
62
+# -- rr params --
63
+# add value to ;lr param to make some broken UAs happy
64
+modparam("rr", "enable_full_lr", 1)
65
+
66
+# -------------------------  request routing logic -------------------
67
+
68
+# main routing logic
69
+
70
+route{
71
+
72
+	setflag(1);
73
+	t_on_failure("1");
74
+	t_on_reply("1");
75
+	log(1, "message received\n");
76
+	t_relay_to_udp("siphub.org", "5060");
77
+
78
+	break;
79
+
80
+}
81
+
82
+onreply_route[1]
83
+{
84
+	if (isflagset(1)) {
85
+		log(1, "onreply: flag set\n");
86
+	} else {
87
+		log(1, "onreply: flag unset\n");
88
+	};
89
+}
90
+
91
+failure_route[1] 
92
+{
93
+	if (isflagset(1)) {
94
+		log(1, "failure: flag set\n");
95
+	} else {
96
+		log(1, "failure: flag unset\n");
97
+	};
98
+}
99
+
0 100
new file mode 100644
... ...
@@ -0,0 +1,63 @@
0
+#
1
+# $Id$
2
+#
3
+# example script showing both types of forking;
4
+# incoming message is forked in parallel to
5
+# 'nobody' and 'parallel', if no positive reply
6
+# appears with final_response timer, nonsense
7
+# is retried (serial forking); than, destination
8
+# 'foo' is given last chance
9
+
10
+# ------------------ module loading ----------------------------------
11
+
12
+loadmodule "modules/sl/sl.so"
13
+loadmodule "modules/tm/tm.so"
14
+
15
+# ----------------- setting module-specific parameters ---------------
16
+
17
+# -- tm params --
18
+# set time for which ser will be waiting for a final response;
19
+# fr_inv_timer sets value for INVITE transactions, fr_timer
20
+# for all others
21
+modparam("tm", "fr_inv_timer", 15 )
22
+modparam("tm", "fr_timer", 10 )
23
+
24
+# -------------------------  request routing logic -------------------
25
+
26
+# main routing logic
27
+
28
+route{
29
+	# for testing purposes, simply okay all REGISTERs
30
+	if (method=="REGISTER") {
31
+		log("REGISTER");
32
+		sl_send_reply("200", "ok");
33
+		break;
34
+	};
35
+	# try these two destinations first in parallel; the second
36
+	# destination is targeted to sink port -- that will make ser
37
+	# wait until timer hits
38
+	seturi("sip:nobody@siphub.net");
39
+	append_branch("sip:parallel@siphub.net:9");
40
+	# if we do not get a positive reply, continue at reply_route[1]
41
+	t_on_failure("1");
42
+	# forward the request to all destinations in destination set now 
43
+	t_relay();
44
+}
45
+
46
+failure_route[1] {
47
+	# forwarding failed -- try again at another destination 
48
+	append_branch("sip:nonsense@siphub.net");
49
+	log(1,"first redirection\n");
50
+	# if this alternative destination fails too, proceed to reply_route[2] 
51
+	t_on_failure("2");
52
+	t_relay();
53
+}
54
+
55
+failure_route[2] {
56
+	# try out the last resort destination
57
+	append_branch("sip:foo@siphub.net");
58
+	log(1, "second redirection\n");
59
+	# we no more call t_on_negative here; if this destination
60
+	# fails too, transaction will complete
61
+	t_relay();
62
+}
0 63
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+#
1
+# $Id$
2
+#
3
+# logging example
4
+#
5
+
6
+# ------------------ module loading ----------------------------------
7
+
8
+fork=no
9
+listen=192.168.2.16
10
+log_stderror=yes
11
+debug=3
12
+
13
+
14
+# -------------------------  request routing logic -------------------
15
+
16
+# main routing logic
17
+
18
+route{
19
+	# for testing purposes, simply okay all REGISTERs
20
+	if (method=="REGISTER") {
21
+		log(1, "REGISTER received\n");
22
+	} else {
23
+		log(1, "non-REGISTER received\n");
24
+	};
25
+	if (uri=~"sip:.*[@:]siphub.net") {
26
+		log(1, "request for siphub.net received\n");
27
+	} else {
28
+		log(1, "request for other domain received\n");
29
+	};
30
+}
0 31
new file mode 100644
... ...
@@ -0,0 +1,141 @@
0
+#
1
+# MSILO usage example
2
+#
3
+# $ID: daniel $
4
+#
5
+
6
+
7
+
8
+children=2
9
+check_via=no      # (cmd. line: -v)
10
+dns=off           # (cmd. line: -r)
11
+rev_dns=off       # (cmd. line: -R)
12
+
13
+
14
+# ------------------ module loading ----------------------------------
15
+
16
+loadmodule "../sip_router/modules/print/print.so"
17
+loadmodule "../sip_router/modules/textops/textops.so"
18
+
19
+loadmodule "../sip_router/modules/sl/sl.so"
20
+loadmodule "../sip_router/modules/mysql/mysql.so"
21
+loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
22
+loadmodule "../sip_router/modules/msilo/msilo.so"
23
+loadmodule "../sip_router/modules/tm/tm.so"
24
+loadmodule "../sip_router/modules/registrar/registrar.so"
25
+loadmodule "../sip_router/modules/usrloc/usrloc.so"
26
+
27
+# ----------------- setting module-specific parameters ---------------
28
+
29
+# -- registrar params --
30
+
31
+modparam("registrar", "default_expires", 120)
32
+
33
+# -- registrar params --
34
+
35
+modparam("usrloc", "db_mode", 0)
36
+
37
+# -- msilo params --
38
+
39
+modparam("msilo","db_url","mysql://user:xxx@127.0.0.1/msilo")
40
+modparam("msilo","registrar","sip:registrar@mydomain.com")
41
+
42
+# -- tm params --
43
+
44
+modparam("tm", "fr_timer", 10 )
45
+modparam("tm", "fr_inv_timer", 15 )
46
+modparam("tm", "wt_timer", 10 )
47
+
48
+
49
+route{
50
+	if ( !mf_process_maxfwd_header("10") )
51
+	{
52
+		sl_send_reply("483","To Many Hops");
53
+		drop();
54
+	};
55
+
56
+
57
+	if (uri==myself) {
58
+		# for testing purposes, simply okay all REGISTERs
59
+		if (method=="REGISTER")
60
+		{
61
+			save("location");
62
+			log("REGISTER received -> dumping messages with MSILO\n");
63
+
64
+			# MSILO - dumping user's offline messages
65
+			if (m_dump())
66
+			{
67
+				log("MSILO: offline messages dumped - if they were\n");
68
+			}else{
69
+				log("MSILO: no offline messages dumped\n");
70
+			};
71
+			break;
72
+		};
73
+
74
+		# domestic SIP destinations are handled using our USRLOC DB
75
+		
76
+		if(!lookup("location")) 
77
+		{
78
+			if (! t_newtran())
79
+   			{
80
+				sl_reply_error();
81
+				break;
82
+   			};
83
+			# we do not care about anything else but MESSAGEs
84
+			if (!method=="MESSAGE")
85
+			{
86
+				if (!t_reply("404", "Not found")) 
87
+				{
88
+					sl_reply_error();
89
+				};
90
+    			break;
91
+			};
92
+			log("MESSAGE received -> storing using MSILO\n");
93
+			# MSILO - storing as offline message
94
+			if (m_store("0"))
95
+			{
96
+				log("MSILO: offline message stored\n");
97
+				if (!t_reply("202", "Accepted")) 
98
+				{
99
+					sl_reply_error();
100
+				};
101
+			}else{
102
+				log("MSILO: offline message NOT stored\n");
103
+				if (!t_reply("503", "Service Unavailable")) 
104
+				{
105
+					sl_reply_error();
106
+				};
107
+			};
108
+			break;
109
+		};
110
+		# if the downstream UA does not support MESSAGE requests
111
+		# go to failure_route[1]
112
+		t_on_failure("1");
113
+		t_relay();
114
+		break;
115
+	};
116
+
117
+	# forward anything else
118
+	t_relay();
119
+}
120
+
121
+failure_route[1] {
122
+	# forwarding failed -- check if the request was a MESSAGE 
123
+	if (!method=="MESSAGE")
124
+	{
125
+    	break;
126
+	};
127
+	
128
+	log(1,"MSILO: the downstream UA does not support MESSAGE requests ...\n");
129
+	# we have changed the R-URI with the contact address -- ignore it now
130
+	if (m_store("1"))
131
+	{
132
+		log("MSILO: offline message stored\n");
133
+		t_reply("202", "Accepted"); 
134
+	}else{
135
+		log("MSILO: offline message NOT stored\n");
136
+		t_reply("503", "Service Unavailable");
137
+	};
138
+}
139
+
140
+
0 141
new file mode 100644
... ...
@@ -0,0 +1,227 @@
0
+#
1
+# $Id$
2
+#
3
+# simple quick-start config script including nathelper support
4
+
5
+# This default script includes nathelper support. To make it work
6
+# you will also have to install Maxim's RTP proxy. The proxy is enforced
7
+# if one of the parties is behind a NAT.
8
+#
9
+# If you have an endpoing in the public internet which is known to
10
+# support symmetric RTP (Cisco PSTN gateway or voicemail, for example),
11
+# then you don't have to force RTP proxy. If you don't want to enforce
12
+# RTP proxy for some destinations than simply use t_relay() instead of
13
+# route(1)
14
+#
15
+# Sections marked with !! Nathelper contain modifications for nathelper
16
+#
17
+# NOTE !! This config is EXPERIMENTAL !
18
+#
19
+# ----------- global configuration parameters ------------------------
20
+
21
+debug=3         # debug level (cmd line: -dddddddddd)
22
+fork=yes
23
+log_stderror=no	# (cmd line: -E)
24
+
25
+/* Uncomment these lines to enter debugging mode 
26
+fork=no
27
+log_stderror=yes
28
+*/
29
+
30
+check_via=no	# (cmd. line: -v)
31
+dns=no           # (cmd. line: -r)
32
+rev_dns=no      # (cmd. line: -R)
33
+port=5060
34
+children=4
35
+fifo="/tmp/ser_fifo"
36
+
37
+# ------------------ module loading ----------------------------------
38
+
39
+# Uncomment this if you want to use SQL database
40
+#loadmodule "/usr/local/lib/ser/modules/mysql.so"
41
+
42
+loadmodule "/usr/local/lib/ser/modules/sl.so"
43
+loadmodule "/usr/local/lib/ser/modules/tm.so"
44
+loadmodule "/usr/local/lib/ser/modules/rr.so"
45
+loadmodule "/usr/local/lib/ser/modules/maxfwd.so"
46
+loadmodule "/usr/local/lib/ser/modules/usrloc.so"
47
+loadmodule "/usr/local/lib/ser/modules/registrar.so"
48
+loadmodule "/usr/local/lib/ser/modules/textops.so"
49
+
50
+# Uncomment this if you want digest authentication
51
+# mysql.so must be loaded !
52
+#loadmodule "/usr/local/lib/ser/modules/auth.so"
53
+#loadmodule "/usr/local/lib/ser/modules/auth_db.so"
54
+
55
+# !! Nathelper
56
+loadmodule "/usr/local/lib/ser/modules/nathelper.so"
57
+
58
+# ----------------- setting module-specific parameters ---------------
59
+
60
+# -- usrloc params --
61
+
62
+modparam("usrloc", "db_mode",   0)
63
+
64
+# Uncomment this if you want to use SQL database 
65
+# for persistent storage and comment the previous line
66
+#modparam("usrloc", "db_mode", 2)
67
+
68
+# -- auth params --
69
+# Uncomment if you are using auth module
70
+#
71
+#modparam("auth_db", "calculate_ha1", yes)
72
+#
73
+# If you set "calculate_ha1" parameter to yes (which true in this config), 
74
+# uncomment also the following parameter)
75
+#
76
+#modparam("auth_db", "password_column", "password")
77
+
78
+# -- rr params --
79
+# add value to ;lr param to make some broken UAs happy
80
+modparam("rr", "enable_full_lr", 1)
81
+
82
+# !! Nathelper
83
+modparam("registrar", "nat_flag", 6)
84
+modparam("nathelper", "natping_interval", 30) # Ping interval 30 s
85
+modparam("nathelper", "ping_nated_only", 1)   # Ping only clients behind NAT
86
+
87
+# -------------------------  request routing logic -------------------
88
+
89
+# main routing logic
90
+
91
+route{
92
+
93
+	# initial sanity checks -- messages with
94
+	# max_forwards==0, or excessively long requests
95
+	if (!mf_process_maxfwd_header("10")) {
96
+		sl_send_reply("483","Too Many Hops");
97
+		break;
98
+	};
99
+	if (msg:len >=  max_len ) {
100
+		sl_send_reply("513", "Message too big");
101
+		break;
102
+	};
103
+
104
+        # !! Nathelper
105
+	# Special handling for NATed clients; first, NAT test is
106
+	# executed: it looks for via!=received and RFC1918 addresses
107
+	# in Contact (may fail if line-folding is used); also,
108
+	# the received test should, if completed, should check all
109
+	# vias for rpesence of received
110
+	if (nat_uac_test("3")) {
111
+		# Allow RR-ed requests, as these may indicate that
112
+		# a NAT-enabled proxy takes care of it; unless it is
113
+		# a REGISTER
114
+
115
+		if (method == "REGISTER" || ! search("^Record-Route:")) {
116
+		    log("LOG: Someone trying to register from private IP, rewriting\n");
117
+
118
+		    # This will work only for user agents that support symmetric
119
+		    # communication. We tested quite many of them and majority is
120
+		    # smart enough to be symmetric. In some phones it takes a configuration
121
+		    # option. With Cisco 7960, it is called NAT_Enable=Yes, with kphone it is
122
+		    # called "symmetric media" and "symmetric signalling".
123
+
124
+		    fix_nated_contact(); # Rewrite contact with source IP of signalling
125
+		    if (method == "INVITE") {
126
+		        fix_nated_sdp("1"); # Add direction=active to SDP
127
+		    };
128
+		    force_rport(); # Add rport parameter to topmost Via
129
+		    setflag(6);    # Mark as NATed
130
+		};
131
+	};
132
+
133
+	# we record-route all messages -- to make sure that
134
+	# subsequent messages will go through our proxy; that's
135
+	# particularly good if upstream and downstream entities
136
+	# use different transport protocol
137
+	if (!method=="REGISTER") record_route();	
138
+
139
+	# subsequent messages withing a dialog should take the
140
+	# path determined by record-routing
141
+	if (loose_route()) {
142
+		# mark routing logic in request
143
+		append_hf("P-hint: rr-enforced\r\n"); 
144
+		route(1);
145
+		break;
146
+	};
147
+
148
+	if (!uri==myself) {
149
+		# mark routing logic in request
150
+		append_hf("P-hint: outbound\r\n"); 
151
+		route(1);
152
+		break;
153
+	};
154
+
155
+	# if the request is for other domain use UsrLoc
156
+	# (in case, it does not work, use the following command
157
+	# with proper names and addresses in it)
158
+	if (uri==myself) {
159
+
160
+		if (method=="REGISTER") {
161
+
162
+# Uncomment this if you want to use digest authentication
163
+#			if (!www_authorize("siphub.org", "subscriber")) {
164
+#				www_challenge("siphub.org", "0");
165
+#				break;
166
+#			};
167
+
168
+			save("location");
169
+			break;
170
+		};
171
+
172
+		lookup("aliases");
173
+		if (!uri==myself) {
174
+			append_hf("P-hint: outbound alias\r\n"); 
175
+			route(1);
176
+			break;
177
+		};
178
+
179
+		# native SIP destinations are handled using our USRLOC DB
180
+		if (!lookup("location")) {
181
+			sl_send_reply("404", "Not Found");
182
+			break;
183
+		};
184
+	};
185
+	append_hf("P-hint: usrloc applied\r\n"); 
186
+	route(1);
187
+}
188
+
189
+route[1] 
190
+{
191
+	# !! Nathelper
192
+	if (uri=~"[@:](192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[0-1])\.)" && !search("^Route:")){
193
+	    sl_send_reply("479", "We don't forward to private IP addresses");
194
+	    break;
195
+        };
196
+	
197
+	# if client or server know to be behind a NAT, enable relay
198
+	if (isflagset(6)) {
199
+	    force_rtp_proxy();
200
+	};
201
+
202
+	# NAT processing of replies; apply to all transactions (for example,
203
+	# re-INVITEs from public to private UA are hard to identify as
204
+	# NATed at the moment of request processing); look at replies
205
+	t_on_reply("1");
206
+
207
+	# send it out now; use stateful forwarding as it works reliably
208
+	# even for UDP2TCP
209
+	if (!t_relay()) {
210
+		sl_reply_error();
211
+	};
212
+}
213
+
214
+# !! Nathelper
215
+onreply_route[1] {
216
+    # NATed transaction ?
217
+    if (isflagset(6) && status =~ "(183)|2[0-9][0-9]") {
218
+        fix_nated_contact();
219
+	force_rtp_proxy();
220
+    # otherwise, is it a transaction behind a NAT and we did not
221
+    # know at time of request processing ? (RFC1918 contacts)
222
+    } else if (nat_uac_test("1")) {
223
+        fix_nated_contact();
224
+    };
225
+}
226
+
0 227
new file mode 100644
... ...
@@ -0,0 +1,145 @@
0
+#
1
+# $Id$
2
+#
3
+# example: ser configured as PSTN gateway guard; PSTN gateway is located
4
+# at 192.168.0.10
5
+#
6
+
7
+# ------------------ module loading ----------------------------------
8
+
9
+loadmodule "modules/sl/sl.so"
10
+loadmodule "modules/tm/tm.so"
11
+loadmodule "modules/acc/acc.so"
12
+loadmodule "modules/rr/rr.so"
13
+loadmodule "modules/maxfwd/maxfwd.so"
14
+loadmodule "modules/mysql/mysql.so"
15
+loadmodule "modules/auth/auth.so"
16
+loadmodule "modules/auth_db/auth_db.so"
17
+loadmodule "modules/group/group.so"
18
+loadmodule "modules/uri/uri.so"
19
+
20
+# ----------------- setting module-specific parameters ---------------
21
+
22
+modparam("auth_db", "db_url","mysql://ser:heslo@localhost/ser")
23
+modparam("auth_db", "calculate_ha1", yes)
24
+modparam("auth_db", "password_column", "password")
25
+
26
+# -- acc params --
27
+modparam("acc", "log_level", 1)
28
+# that is the flag for which we will account -- don't forget to
29
+# set the same one :-)
30
+modparam("acc", "log_flag", 1 )
31
+
32
+# -------------------------  request routing logic -------------------
33
+
34
+# main routing logic
35
+
36
+route{
37
+
38
+	/* ********* ROUTINE CHECKS  ********************************** */
39
+
40
+	# filter too old messages
41
+	if (!mf_process_maxfwd_header("10")) {
42
+		log("LOG: Too many hops\n");
43
+		sl_send_reply("483","Too Many Hops");
44
+		break;
45
+	};
46
+	if (len_gt( max_len )) {
47
+		sl_send_reply("513", "Wow -- Message too large");
48
+		break;
49
+	};
50
+
51
+	/* ********* RR ********************************** */
52
+
53
+	/* grant Route routing if route headers present */
54
+	if (loose_route()) { t_relay(); break; };
55
+	
56
+	/* record-route INVITEs -- all subsequent requests must visit us */
57
+	if (method=="INVITE") {
58
+		record_route();
59
+	};
60
+
61
+	# now check if it really is a PSTN destination which should be handled
62
+	# by our gateway; if not, and the request is an invitation, drop it --
63
+	# we cannot terminate it in PSTN; relay non-INVITE requests -- it may
64
+	# be for example BYEs sent by gateway to call originator
65
+	if (!uri=~"sip:\+?[0-9]+@.*") {
66
+		if (method=="INVITE") {
67
+			sl_send_reply("403", "Call cannot be served here");
68
+		} else {
69
+			forward(uri:host, uri:port);
70
+		};
71
+		break;
72
+	}; 
73
+
74
+	# account completed transactions via syslog
75
+	setflag(1);
76
+
77
+	# free call destinations ... no authentication needed
78
+	if ( is_user_in("Request-URI", "free-pstn")  /* free destinations */
79
+			|  uri=~"sip:[79][0-9][0-9][0-9]@.*"  /* local PBX */
80
+			| uri=~"sip:98[0-9][0-9][0-9][0-9]") {
81
+		log("free call");
82
+	} else if (src_ip==192.168.0.10) {
83
+		# our gateway doesn't support digest authentication;
84
+		# verify that a request is coming from it by source
85
+		# address
86
+		log("gateway-originated request");
87
+	} else {
88
+		# in all other cases, we need to check the request against
89
+		# access control lists; first of all, verify request
90
+		# originator's identity
91
+
92
+		if (!proxy_authorize(	"gateway" /* realm */,
93
+				"subscriber" /* table name */))  {
94
+			proxy_challenge( "gateway" /* realm */, "0" /* no qop */ );
95
+			break;
96
+		};
97
+
98
+		# authorize only for INVITEs -- RR/Contact may result in weird
99
+		# things showing up in d-uri that would break our logic; our
100
+		# major concern is INVITE which causes PSTN costs 
101
+
102
+		if (method=="INVITE") {
103
+
104
+			# does the authenticated user have a permission for local
105
+			# calls (destinations beginning with a single zero)? 
106
+			# (i.e., is he in the "local" group?)
107
+			if (uri=~"sip:0[1-9][0-9]+@.*") {
108
+				if (!is_user_in("credentials", "local")) {
109
+					sl_send_reply("403", "No permission for local calls"); 
110
+					break;
111
+				};
112
+			# the same for long-distance (destinations begin with two zeros")
113
+			} else if (uri=~"sip:00[1-9][0-9]+@.*") {
114
+				if (!is_user_in("credentials", "ld")) {
115
+					sl_send_reply("403", " no permission for LD ");
116
+					break;
117
+				};
118
+			# the same for international calls (three zeros)
119
+			} else if (uri=~"sip:000[1-9][0-9]+@.*") {
120
+				if (!is_user_in("credentials", "int")) {
121
+					sl_send_reply("403", "International permissions needed");
122
+					break;
123
+				};
124
+			# everything else (e.g., interplanetary calls) is denied
125
+			} else {
126
+				sl_send_reply("403", "Forbidden");
127
+				break;
128
+			};
129
+
130
+		}; # INVITE to authorized PSTN
131
+
132
+	}; # authorized PSTN
133
+
134
+	# if you have passed through all the checks, let your call go to GW!
135
+
136
+	rewritehostport("192.168.0.10:5060");
137
+
138
+	# forward the request now
139
+	if (!t_relay()) {
140
+		sl_reply_error(); 
141
+		break; 
142
+	};
143
+
144
+}
0 145
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+#
1
+# $Id$
2
+#
3
+# this example shows use of ser as stateless redirect server
4
+#
5
+
6
+# ------------------ module loading ----------------------------------
7
+
8
+loadmodule "modules/sl/sl.so"
9
+
10
+
11
+# -------------------------  request routing logic -------------------
12
+
13
+# main routing logic
14
+
15
+route{
16
+	# for testing purposes, simply okay all REGISTERs
17
+	if (method=="REGISTER") {
18
+		log("REGISTER");
19
+		sl_send_reply("200", "ok");
20
+		break;
21
+	};
22
+	# rewrite current URI, which is always part of destination ser
23
+	rewriteuri("sip:parallel@siphub.net:9");
24
+	# append one more URI to the destination ser
25
+	append_branch("sip:redirect@siphub.net:9");
26
+	# redirect now
27
+	sl_send_reply("300", "Redirect");
28
+}
29
+
0 30
new file mode 100644
... ...
@@ -0,0 +1,73 @@
0
+#
1
+# $Id$
2
+#
3
+# demo script showing how to set-up usrloc replication
4
+#
5
+
6
+# ----------- global configuration parameters ------------------------
7
+
8
+debug=3          # debug level (cmd line: -dddddddddd)
9
+fork=no
10
+log_stderror=yes # (cmd line: -E)
11
+
12
+# ------------------ module loading ----------------------------------
13
+
14
+loadmodule "modules/mysql/mysql.so"
15
+loadmodule "modules/sl/sl.so"
16
+loadmodule "modules/tm/tm.so"
17
+loadmodule "modules/maxfwd/maxfwd.so"
18
+loadmodule "modules/usrloc/usrloc.so"
19
+loadmodule "modules/registrar/registrar.so"
20
+loadmodule "modules/auth/auth.so"
21
+loadmodule "modules/auth_db/auth_db.so"
22
+
23
+# ----------------- setting module-specific parameters ---------------
24
+
25
+# digest generation secret; use the same in backup server;
26
+# also, make sure that the backup server has sync'ed time
27
+modparam("auth", "secret", "alsdkhglaksdhfkloiwr")
28
+
29
+# -------------------------  request routing logic -------------------
30
+
31
+# main routing logic
32
+
33
+route{
34
+
35
+	# initial sanity checks -- messages with
36
+	# max_forwars==0, or excessively long requests
37
+	if (!mf_process_maxfwd_header("10")) {
38
+		sl_send_reply("483","Too Many Hops");
39
+		break;
40
+	};
41
+	if (len_gt( max_len )) {
42
+		sl_send_reply("513", "Message too big");
43
+		break;
44
+	};
45
+
46
+	# if the request is for other domain use UsrLoc
47
+	# (in case, it does not work, use the following command
48
+	# with proper names and addresses in it)
49
+	if (uri==myself) {
50
+
51
+		if (method=="REGISTER") {
52
+
53
+			# verify credentials
54
+			if (!www_authorize("foo.bar", "subscriber")) {
55
+				www_challenge("foo.bar", "0");
56
+				break;
57
+			};
58
+
59
+			# if ok, update contacts and ...
60
+			save("location");
61
+			# ... if this REGISTER is not a replica from our
62
+			# peer server, replicate to the peer server
63
+			if (!src_ip==backup.foo.bar) {
64
+				t_replicate("backup.foo.bar", "5060");
65
+			};
66
+			break;
67
+		};
68
+		# do whatever else appropriate for your domain
69
+		log("non-REGISTER\n");
70
+	};
71
+}
72
+
0 73
new file mode 100644
... ...
@@ -0,0 +1,62 @@
0
+#
1
+# $Id$
2
+#
3
+# this example shows how to use forking on failure
4
+#
5
+
6
+log_stderror=1
7
+fork=no
8
+listen=192.168.2.16
9
+debug=3
10
+# ------------------ module loading ----------------------------------
11
+
12
+# Uncomment this if you want to use SQL database
13
+loadmodule "modules/tm/tm.so"
14
+loadmodule "modules/sl/sl.so"
15
+loadmodule "modules/maxfwd/maxfwd.so"
16
+# -------------------------  request routing logic -------------------
17
+
18
+# main routing logic
19
+
20
+route{
21
+
22
+	# initial sanity checks -- messages with
23
+	# max_forwards==0, or excessively long requests
24
+	if (!mf_process_maxfwd_header("10")) {
25
+		sl_send_reply("483","Too Many Hops");
26
+		break;
27
+	};
28
+	if (len_gt( max_len )) {
29
+		sl_send_reply("513", "Message too big");
30
+		break;
31
+	};
32
+
33
+	/* skip register for testing purposes */
34
+	if (method=="REGISTER") { sl_send_reply("200", "ok"); break; };
35
+
36
+	if (!method=="ACK")
37
+		log(1, "forwarding now to primary destination\n");
38
+	if (method=="INVITE") {
39
+		rewriteuri("sip:xxx@192.168.2.16:5064");
40
+		# if transaction broken, try other an alternative
41
+		# route
42
+		t_on_failure("1");
43
+		# if a provisional came, stop alternating
44
+		t_on_reply("1");
45
+	};
46
+	t_relay();
47
+}
48
+
49
+failure_route[1] {
50
+	log(1, "trying at alternate destination\n");
51
+	append_branch("sip:yyy@192.168.2.16:5064");
52
+	t_relay();
53
+}
54
+
55
+onreply_route[1] {
56
+	log(1, "reply came in\n");
57
+	if (status=~"18[0-9]")  {
58
+		log(1, "provisional -- resetting negative failure\n");
59
+		t_on_failure("0");
60
+	};
61
+}
0 62
new file mode 100644
... ...
@@ -0,0 +1,11 @@
0
+#
1
+# $Id$
2
+#
3
+
4
+This examle illustrate how to use ser's FIFO interface
5
+to initate sending an instant message from a webpage.
6
+
7
+To enable this example, you need
8
+- web server with PHP support
9
+- install the example webpages on the server
10
+- have running ser with enabled fifo
0 11
new file mode 100644
... ...
@@ -0,0 +1,40 @@
0
+<html>
1
+<!-- $Id$ -->
2
+<header>
3
+<title>
4
+Click-To-Dial
5
+</title>
6
+</header>
7
+
8
+<body>
9
+<h1>
10
+Click-To-Dial (using REFER)
11
+</h1>
12
+
13
+<i>Unfortunately, this example does not work. The reason is use of
14
+REFER for third-party call-control has not been standardized due
15
+to resistance of proponents of B2BUA use (which is somewhat bloated
16
+and not always operational).
17
+</i>
18
+
19
+<form method=POST action=click_to_dial.php>
20
+<table>
21
+<tr>
22
+<td>
23
+Caller's SIP Address
24
+<td>
25
+<input name=caller>
26
+<tr>
27
+<td>
28
+Callee's SIP Address
29
+<td>
30
+<input name=callee>
31
+<tr>
32
+<td>Click to dial
33
+<td>
34
+<input type=submit value=now>
35
+</table>
36
+</form>
37
+
38
+
39
+</body>
0 40
new file mode 100644
... ...
@@ -0,0 +1,66 @@
0
+<html>
1
+<!-- $Id$ -->
2
+<header>
3
+<title>
4
+Click-To-Dial
5
+</title>
6
+</header>
7
+
8
+<body>
9
+<h1>
10
+Click-To-Dial
11
+</h1>
12
+
13
+<?php
14
+
15
+/* config values */
16
+$web_contact="sip:daemon@siphub.net";
17
+$fifo="/tmp/ser_fifo";
18
+$signature="web_test_0.0.0";
19
+
20
+/* open reply fifo */
21
+$myfilename="webfifo_".rand();
22
+$mypath="/tmp/".$myfilename;
23
+
24
+echo "Initiating your request...<p>";
25
+
26
+/* open fifo now */
27
+$fifo_handle=fopen( $fifo, "w" );