Project

General

Profile

RE: Certified - Softphone » kamailiocfg.txt

Danielle Coelho, 07/01/2019 03:46 PM

 
1
#!KAMAILIO
2
#
3
#!define WITH_MYSQL
4
#!define WITH_AUTH
5
#!define WITH_USRLOCDB
6
#!define WITH_NAT
7
#!define WITH_ANTIFLOOD
8
#
9
#
10
# Kamailio (OpenSER) SIP Server v5.0 - default configuration script
11
#     - web: http://www.kamailio.org
12
#     - git: http://sip-router.org
13
#
14
# Direct your questions about this file to: <sr-users@lists.sip-router.org>
15
#
16
# Refer to the Core CookBook at http://www.kamailio.org/wiki/
17
# for an explanation of possible statements, functions and parameters.
18
#
19
# Several features can be enabled using '#!define WITH_FEATURE' directives:
20
#
21
# *** To run in debug mode: 
22
#     - define WITH_DEBUG
23
#
24
# *** To enable mysql: 
25
#     - define WITH_MYSQL
26
#
27
# *** To enable authentication execute:
28
#     - enable mysql
29
#     - define WITH_AUTH
30
#     - add users using 'kamctl'
31
#
32
# *** To enable IP authentication execute:
33
#     - enable mysql
34
#     - enable authentication
35
#     - define WITH_IPAUTH
36
#     - add IP addresses with group id '1' to 'address' table
37
#
38
# *** To enable persistent user location execute:
39
#     - enable mysql
40
#     - define WITH_USRLOCDB
41
#
42
# *** To enable presence server execute:
43
#     - enable mysql
44
#     - define WITH_PRESENCE
45
#
46
# *** To enable nat traversal execute:
47
#     - define WITH_NAT
48
#     - install RTPProxy: http://www.rtpproxy.org
49
#     - start RTPProxy:
50
#        rtpproxy -l _your_public_ip_ -s udp:localhost:7722
51
#     - option for NAT SIP OPTIONS keepalives: WITH_NATSIPPING
52
#
53
# *** To enable PSTN gateway routing execute:
54
#     - define WITH_PSTN
55
#     - set the value of pstn.gw_ip
56
#     - check route[PSTN] for regexp routing condition
57
#
58
# *** To enable database aliases lookup execute:
59
#     - enable mysql
60
#     - define WITH_ALIASDB
61
#
62
# *** To enable speed dial lookup execute:
63
#     - enable mysql
64
#     - define WITH_SPEEDDIAL
65
#
66
# *** To enable multi-domain support execute:
67
#     - enable mysql
68
#     - define WITH_MULTIDOMAIN
69
#
70
# *** To enable TLS support execute:
71
#     - adjust CFGDIR/tls.cfg as needed
72
#     - define WITH_TLS
73
#
74
# *** To enable XMLRPC support execute:
75
#     - define WITH_XMLRPC
76
#     - adjust route[XMLRPC] for access policy
77
#
78
# *** To enable anti-flood detection execute:
79
#     - adjust pike and htable=>ipban settings as needed (default is
80
#       block if more than 16 requests in 2 seconds and ban for 300 seconds)
81
#     - define WITH_ANTIFLOOD
82
#
83
# *** To block 3XX redirect replies execute:
84
#     - define WITH_BLOCK3XX
85
#
86
# *** To enable VoiceMail routing execute:
87
#     - define WITH_VOICEMAIL
88
#     - set the value of voicemail.srv_ip
89
#     - adjust the value of voicemail.srv_port
90
#
91
# *** To enhance accounting execute:
92
#     - enable mysql
93
#     - define WITH_ACCDB
94
#     - add following columns to database
95
#!ifdef ACCDB_COMMENT
96
  ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
97
  ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
98
  ALTER TABLE acc ADD COLUMN src_ip varchar(64) NOT NULL default '';
99
  ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
100
  ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
101
  ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
102
  ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT '';
103
  ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT '';
104
  ALTER TABLE missed_calls ADD COLUMN src_ip varchar(64) NOT NULL default '';
105
  ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT '';
106
  ALTER TABLE missed_calls ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT '';
107
  ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT '';
108
#!endif
109

    
110
####### Include Local Config If Exists #########
111
import_file "kamailio-local.cfg"
112

    
113
####### Defined Values #########
114

    
115
# *** Value defines - IDs used later in config
116
#!ifdef WITH_MYSQL
117
# - database URL - used to connect to database server by modules such
118
#       as: auth_db, acc, usrloc, a.s.o.
119
#!ifndef DBURL
120
#!define DBURL "mysql://kamailiou:kamailiou1234@localhost/kamailio"
121
#!endif
122
#!endif
123
#!ifdef WITH_MULTIDOMAIN
124
# - the value for 'use_domain' parameters
125
#!define MULTIDOMAIN 1
126
#!else
127
#!define MULTIDOMAIN 0
128
#!endif
129

    
130
# - flags
131
#   FLT_ - per transaction (message) flags
132
#	FLB_ - per branch flags
133
#!define FLT_ACC 1
134
#!define FLT_ACCMISSED 2
135
#!define FLT_ACCFAILED 3
136
#!define FLT_NATS 5
137

    
138
#!define FLB_NATB 6
139
#!define FLB_NATSIPPING 7
140

    
141
#!substdef "!MY_IP_ADDR!172.31.1.239!g"
142
#!substdef "!MY_DOMAIN!gsvoip.solutionsvoip.com.br!g"
143
#!substdef "!MY_WS_PORT!8080!g"
144
#!substdef "!MY_WSS_PORT!4443!g"
145
#!substdef "!MY_MSRP_PORT!9080!g"
146
#!substdef "!MY_WS_ADDR!tcp:MY_IP_ADDR:MY_WS_PORT!g"
147
#!substdef "!MY_WSS_ADDR!tls:MY_IP_ADDR:MY_WSS_PORT!g"
148
#!substdef "!MY_MSRP_ADDR!tls:MY_IP_ADDR:MY_MSRP_PORT!g"
149
#!substdef "!MSRP_MIN_EXPIRES!1800!g"
150
#!substdef "!MSRP_MAX_EXPIRES!3600!g"
151

    
152
#!define WITH_TLS
153
#!define WITH_WEBSOCKETS
154
#!define WITH_MSRP
155

    
156
####### Global Parameters #########
157

    
158
### LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
159
#!ifdef WITH_DEBUG
160
debug=4
161
log_stderror=no
162
#!else
163
debug=2
164
log_stderror=no
165
#!endif
166

    
167
memdbg=5
168
memlog=5
169

    
170
log_facility=LOG_LOCAL0
171

    
172
fork=yes
173
children=4
174

    
175
/* uncomment the next line to disable TCP (default on) */
176
#disable_tcp=yes
177

    
178
/* uncomment the next line to disable the auto discovery of local aliases
179
   based on reverse DNS on IPs (default on) */
180
#auto_aliases=no
181

    
182
/* add local domain aliases */
183
alias="172.31.1.239"
184
alias="gsvoip.solutionsvoip.com.br"
185

    
186
/* uncomment and configure the following line if you want Kamailio to 
187
   bind on a specific interface/port/proto (default bind on all available) */
188
listen=udp:127.0.0.1:5060
189
listen=udp:172.31.1.239:5060
190

    
191
/* port to listen to
192
 * - can be specified more than once if needed to listen on many ports */
193
#port=5060
194

    
195
#!ifdef WITH_TLS
196
enable_tls=yes
197
#!endif
198

    
199
listen=MY_IP_ADDR
200
#!ifdef WITH_WEBSOCKETS
201
listen=MY_WS_ADDR
202
#!ifdef WITH_TLS
203
listen=MY_WSS_ADDR
204
#!endif
205
#!endif
206
#!ifdef WITH_MSRP
207
listen=MY_MSRP_ADDR
208
#!endif
209

    
210
tcp_connection_lifetime=3604
211
tcp_accept_no_cl=yes
212
tcp_rd_buf_size=16384
213

    
214
# life time of TCP connection when there is no traffic
215
# - a bit higher than registration expires to cope with UA behind NAT
216
#tcp_connection_lifetime=3605
217

    
218
####### Custom Parameters #########
219

    
220
# These parameters can be modified runtime via RPC interface
221
# - see the documentation of 'cfg_rpc' module.
222
#
223
# Format: group.id = value 'desc' description
224
# Access: $sel(cfg_get.group.id) or @cfg_get.group.id
225
#
226

    
227
#!ifdef WITH_PSTN
228
# PSTN GW Routing
229
#
230
# - pstn.gw_ip: valid IP or hostname as string value, example:
231
# pstn.gw_ip = "10.0.0.101" desc "My PSTN GW Address"
232
#
233
# - by default is empty to avoid misrouting
234
pstn.gw_ip = "" desc "tos.cloud.goautodial.com GW Address"
235
pstn.gw_port = "" desc "PSTN GW Port"
236
#!endif
237

    
238
#!ifdef WITH_VOICEMAIL
239
# VoiceMail Routing on offline, busy or no answer
240
#
241
# - by default Voicemail server IP is empty to avoid misrouting
242
voicemail.srv_ip = "" desc "VoiceMail IP Address"
243
voicemail.srv_port = "5060" desc "VoiceMail Port"
244
#!endif
245

    
246
# don't advertise server headers
247
server_signature=no
248
sip_warning=0
249

    
250
####### Modules Section ########
251

    
252
# set paths to location of modules (to sources or installation folders)
253
#!ifdef WITH_SRCPATH
254
mpath="modules/"
255
#!else
256
mpath="/usr/lib64/kamailio/modules/"
257
#mpath="/usr/lib/x86_64-linux-gnu/kamailio/modules/"
258
#!endif
259

    
260
#!ifdef WITH_MYSQL
261
loadmodule "db_mysql.so"
262
#!endif
263

    
264
#loadmodule "topoh.so"
265
#loadmodule "mi_fifo.so"
266
loadmodule "jsonrpcs.so"
267
loadmodule "kex.so"
268
loadmodule "corex.so"
269
loadmodule "tm.so"
270
loadmodule "tmx.so"
271
loadmodule "sl.so"
272
loadmodule "rr.so"
273
loadmodule "pv.so"
274
loadmodule "maxfwd.so"
275
loadmodule "usrloc.so"
276
loadmodule "registrar.so"
277
loadmodule "textops.so"
278
loadmodule "siputils.so"
279
loadmodule "xlog.so"
280
loadmodule "sanity.so"
281
loadmodule "ctl.so"
282
loadmodule "cfg_rpc.so"
283
loadmodule "acc.so"
284

    
285
#!ifdef WITH_AUTH
286
loadmodule "auth.so"
287
loadmodule "auth_db.so"
288
#!ifdef WITH_IPAUTH
289
loadmodule "permissions.so"
290
#!endif
291
#!endif
292

    
293
#!ifdef WITH_ALIASDB
294
loadmodule "alias_db.so"
295
#!endif
296

    
297
#!ifdef WITH_SPEEDDIAL
298
loadmodule "speeddial.so"
299
#!endif
300

    
301
#!ifdef WITH_MULTIDOMAIN
302
loadmodule "domain.so"
303
#!endif
304

    
305
#!ifdef WITH_PRESENCE
306
loadmodule "presence.so"
307
loadmodule "presence_xml.so"
308
#!endif
309

    
310
#!ifdef WITH_NAT
311
loadmodule "nathelper.so"
312
loadmodule "rtpengine.so"
313
#loadmodule "rtpproxy.so"
314
#!endif
315

    
316
#!ifdef WITH_TLS
317
loadmodule "tls.so"
318
#!endif
319
 
320
#!ifdef WITH_MSRP
321
loadmodule "msrp.so"
322
#loadmodule "htable.so"
323
loadmodule "cfgutils.so"
324
#!endif
325
 
326
#!ifdef WITH_WEBSOCKETS
327
loadmodule "xhttp.so"
328
loadmodule "websocket.so"
329
loadmodule "sdpops.so"
330
loadmodule "textopsx.so"
331
loadmodule "dialog.so"
332
loadmodule "sst.so"
333
#!endif
334

    
335
#!ifdef WITH_ANTIFLOOD
336
loadmodule "htable.so"
337
loadmodule "pike.so"
338
#!endif
339

    
340
#!ifdef WITH_XMLRPC
341
loadmodule "xmlrpc.so"
342
#!endif
343

    
344
#!ifdef WITH_DEBUG
345
loadmodule "debugger.so"
346
#!endif
347

    
348
# ----------------- setting module-specific parameters ---------------
349

    
350
# ---- topoh params -----
351
#modparam("topoh", "mask_key", "Gu3ssWh@T1tS2016")
352
#modparam("topoh", "mask_ip", "10.0.0.1")
353
#modparam("topoh", "mask_callid", 1)
354

    
355
# ----- mi_fifo params -----
356
#modparam("mi_fifo", "fifo_name", "/var/run/kamailio/kamailio_fifo")
357

    
358
# ----- jsonrpcs params -----
359
modparam("jsonrpcs", "pretty_format", 1)
360
/* set the path to RPC fifo control file */
361
modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
362
/* set the path to RPC unix socket control file */
363
modparam("jsonrpcs", "dgram_socket", "/var/run/kamailio/kamailio_rpc.sock")
364

    
365
# ----- tm params -----
366
# auto-discard branches from previous serial forking leg
367
modparam("tm", "failure_reply_mode", 3)
368
# default retransmission timeout: 30sec
369
modparam("tm", "fr_timer", 30000)
370
# default invite retransmission timeout after 1xx: 120sec
371
modparam("tm", "fr_inv_timer", 120000)
372

    
373

    
374
# ----- rr params -----
375
# set next param to 1 to add value to ;lr param (helps with some UAs)
376
modparam("rr", "enable_full_lr", 0)
377
# do not append from tag to the RR (no need for this script)
378
modparam("rr", "append_fromtag", 0)
379

    
380

    
381
# ----- registrar params -----
382
modparam("registrar", "method_filtering", 1)
383
/* uncomment the next line to disable parallel forking via location */
384
modparam("registrar", "append_branches", 0)
385
/* uncomment the next line not to allow more than 100 contacts per AOR */
386
modparam("registrar", "max_contacts", 100)
387
# max value for expires of registrations
388
modparam("registrar", "max_expires", 3600)
389
# set it to 1 to enable GRUU
390
modparam("registrar", "gruu_enabled", 0)
391

    
392

    
393
# ----- acc params -----
394
/* what special events should be accounted ? */
395
modparam("acc", "early_media", 0)
396
modparam("acc", "report_ack", 0)
397
modparam("acc", "report_cancels", 0)
398
/* by default ww do not adjust the direct of the sequential requests.
399
   if you enable this parameter, be sure the enable "append_fromtag"
400
   in "rr" module */
401
modparam("acc", "detect_direction", 0)
402
/* account triggers (flags) */
403
modparam("acc", "log_flag", FLT_ACC)
404
modparam("acc", "log_missed_flag", FLT_ACCMISSED)
405
modparam("acc", "log_extra", 
406
	"src_user=$fU;src_domain=$fd;src_ip=$si;"
407
	"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
408
modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
409
/* enhanced DB accounting */
410
#!ifdef WITH_ACCDB
411
modparam("acc", "db_flag", FLT_ACC)
412
modparam("acc", "db_missed_flag", FLT_ACCMISSED)
413
modparam("acc", "db_url", DBURL)
414
modparam("acc", "db_extra",
415
	"src_user=$fU;src_domain=$fd;src_ip=$si;"
416
	"dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
417
#!endif
418

    
419

    
420
# ----- usrloc params -----
421
/* enable DB persistency for location entries */
422
#!ifdef WITH_USRLOCDB
423
modparam("usrloc", "db_url", DBURL)
424
modparam("usrloc", "db_mode", 1)
425
modparam("usrloc", "use_domain", MULTIDOMAIN)
426
modparam("usrloc", "timer_interval", 60)
427
modparam("usrloc", "timer_procs", 4)
428
#!endif
429

    
430

    
431
# ----- auth_db params -----
432
#!ifdef WITH_AUTH
433
modparam("auth_db", "db_url", DBURL)
434
modparam("auth_db", "calculate_ha1", 0)
435
modparam("auth_db", "password_column", "ha1")
436
modparam("auth_db", "load_credentials", "")
437
modparam("auth_db", "use_domain", MULTIDOMAIN)
438

    
439
modparam("auth", "nonce_count", 1) # enable nonce_count support
440
modparam("auth", "qop", "auth")    # enable qop=auth
441
modparam("auth", "nonce_expire", 60)
442
modparam("auth", "nonce_auth_max_drift", 2)
443

    
444
# For REGISTER requests we hash the Request-URI, Call-ID, and source IP of the
445
# request into the nonce string. This ensures that the generated credentials
446
# cannot be used with another registrar, user agent with another source IP
447
# address or Call-ID. Note that user agents that change Call-ID with every
448
# REGISTER message will not be able to register if you enable this.
449
modparam("auth", "auth_checks_register", 11)
450

    
451
# For dialog-establishing requests (such as the original INVITE, OPTIONS, etc)
452
# we hash the Request-URI and source IP. Hashing Call-ID and From tags takes
453
# some extra precaution, because these checks could render some UA unusable.
454
modparam("auth", "auth_checks_no_dlg", 9)
455

    
456
# For mid-dialog requests, such as re-INVITE, we can hash source IP and
457
# Request-URI just like in the previous case. In addition to that we can hash
458
# Call-ID and From tag because these are fixed within a dialog and are
459
# guaranteed not to change. This settings effectively restrict the usage of
460
# generated credentials to a single user agent within a single dialog.
461
modparam("auth", "auth_checks_in_dlg", 15)
462

    
463
# ----- permissions params -----
464
#!ifdef WITH_IPAUTH
465
modparam("permissions", "db_url", DBURL)
466
modparam("permissions", "db_mode", 1)
467
#!endif
468

    
469
#!endif
470

    
471

    
472
# ----- alias_db params -----
473
#!ifdef WITH_ALIASDB
474
modparam("alias_db", "db_url", DBURL)
475
modparam("alias_db", "use_domain", MULTIDOMAIN)
476
#!endif
477

    
478

    
479
# ----- speeddial params -----
480
#!ifdef WITH_SPEEDDIAL
481
modparam("speeddial", "db_url", DBURL)
482
modparam("speeddial", "use_domain", MULTIDOMAIN)
483
#!endif
484

    
485

    
486
# ----- domain params -----
487
#!ifdef WITH_MULTIDOMAIN
488
modparam("domain", "db_url", DBURL)
489
# register callback to match myself condition with domains list
490
modparam("domain", "register_myself", 1)
491
#!endif
492

    
493

    
494
#!ifdef WITH_PRESENCE
495
# ----- presence params -----
496
modparam("presence", "db_url", DBURL)
497

    
498
# ----- presence_xml params -----
499
modparam("presence_xml", "db_url", DBURL)
500
modparam("presence_xml", "force_active", 1)
501
#!endif
502

    
503

    
504
#!ifdef WITH_NAT
505
# ----- rtpengine params -----
506
modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:5066")
507
modparam("rtpengine", "rtpengine_disable_tout", 20)
508
#modparam("rtpengine", "db_url", DBURL)
509

    
510
# ----- nathelper params -----
511
modparam("nathelper", "natping_interval", 30)
512
modparam("nathelper", "ping_nated_only", 1)
513
modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
514
modparam("nathelper", "sipping_from", "sip:pinger@kamailio.org")
515

    
516
# params needed for NAT traversal in other modules
517
modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
518
modparam("usrloc", "nat_bflag", FLB_NATB)
519
#!endif
520

    
521

    
522
#!ifdef WITH_TLS
523
# ----- tls params -----
524
modparam("tls", "config", "/etc/kamailio/tls.cfg")
525
#modparam("tls", "private_key", "/etc/httpd/certs/essentialSSL/wildcard.goautodial.com.key")
526
#modparam("tls", "certificate", "/etc/httpd/certs/essentialSSL/wildcard.goautodial.com.crt")
527
#modparam("tls", "ca_list", "/etc/httpd/certs/essentialSSL/wildcard.goautodial.com.ca-bundle")
528
#!endif
529
 
530
#!ifdef WITH_WEBSOCKETS
531
# ----- nathelper params -----
532
modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")
533
# Note: leaving NAT pings turned off here as nathelper is _only_ being used for
534
#       WebSocket connections.  NAT pings are not needed as WebSockets have
535
#       their own keep-alives.
536
modparam("dialog", "dlg_flag", 10)
537
modparam("dialog", "track_cseq_updates", 0)
538
modparam("dialog", "dlg_match_mode", 2)
539

    
540
modparam("dialog", "timeout_avp", "$avp(i:10)")
541
# Set the sst modules timeout_avp to be the same value
542
modparam("sst", "timeout_avp", "$avp(i:10)")
543
modparam("sst", "sst_flag", 11)
544
#!endif
545
 
546
#!ifdef WITH_MSRP
547
# ----- htable params -----
548
modparam("htable", "htable", "msrp=>size=8;autoexpire=MSRP_MAX_EXPIRES;")
549
#!endif
550

    
551
#!ifdef WITH_ANTIFLOOD
552
# ----- pike params -----
553
modparam("pike", "sampling_time_unit", 2)
554
modparam("pike", "reqs_density_per_unit", 32)
555
modparam("pike", "remove_latency", 4)
556

    
557
# ----- htable params -----
558
# ip ban htable with autoexpire after 5 minutes
559
# modparam("htable", "htable", "ipban=>size=8;autoexpire=300;")
560
#!endif
561

    
562
#!ifdef WITH_XMLRPC
563
# ----- xmlrpc params -----
564
modparam("xmlrpc", "route", "XMLRPC");
565
modparam("xmlrpc", "url_match", "^/RPC")
566
#!endif
567

    
568
#!ifdef WITH_DEBUG
569
# ----- debugger params -----
570
modparam("debugger", "cfgtrace", 1)
571
modparam("debugger", "log_level_name", "exec")
572
#!endif
573

    
574
####### Routing Logic ########
575

    
576

    
577
# Main SIP request routing logic
578
# - processing of any incoming SIP request starts with this route
579
# - note: this is the same as route { ... }
580
request_route {
581

    
582
	# per request initial checks
583
	route(REQINIT);
584

    
585
#!ifdef WITH_WEBSOCKETS
586
	if (nat_uac_test(64)) {
587
		# Do NAT traversal stuff for requests from a WebSocket
588
		# connection - even if it is not behind a NAT!
589
		# This won't be needed in the future if Kamailio and the
590
		# WebSocket client support Outbound and Path.
591
		force_rport();
592
		if (is_method("REGISTER")) {
593
			fix_nated_register();
594
		} else {
595
			if (!add_contact_alias()) {
596
				xlog("L_ERR", "Error aliasing contact <$ct>\n");
597
				sl_send_reply("400", "Bad Request");
598
				exit;
599
			}
600
		}
601
	}
602
#!endif
603

    
604
	# NAT detection
605
	route(NATDETECT);
606

    
607
	# CANCEL processing
608
	if (is_method("CANCEL")) {
609
		if (t_check_trans()) {
610
			route(RELAY);
611
		}
612
		exit;
613
	}
614

    
615
	# handle requests within SIP dialogs
616
	route(WITHINDLG);
617

    
618
	### only initial requests (no To tag)
619

    
620
	# handle retransmissions
621
	if(t_precheck_trans()) {
622
		t_check_trans();
623
		exit;
624
	}
625
	t_check_trans();
626

    
627
	# authentication
628
	route(AUTH);
629

    
630
	# record routing for dialog forming requests (in case they are routed)
631
	# - remove preloaded route headers
632
	remove_hf("Route");
633
	if (is_method("INVITE|SUBSCRIBE"))
634
		record_route();
635

    
636
	# account only INVITEs
637
	if (is_method("INVITE")) {
638
		setflag(FLT_ACC); # do accounting
639
		setflag(10); # set the dialog flag
640
		setflag(11); # Set the sst flag
641
	}
642

    
643
	if (is_method("UPDATE")) {
644
		setflag(FLT_ACC); # do accounting
645
		setflag(10); # set the dialog flag
646
		setflag(11); # Set the sst flag
647
	}
648

    
649
	# dispatch requests to foreign domains
650
	route(SIPOUT);
651

    
652
	### requests for my local domains
653

    
654
	# handle presence related requests
655
	route(PRESENCE);
656

    
657
	# handle registrations
658
	route(REGISTRAR);
659

    
660
	if ($rU==$null) {
661
		# request with no Username in RURI
662
		sl_send_reply("484","Address Incomplete");
663
		exit;
664
	}
665

    
666
	# dispatch destinations to PSTN
667
	route(PSTN);
668

    
669
	# user location service
670
	route(LOCATION);
671
	route(RELAY);
672
}
673

    
674
# Wrapper for relaying requests
675
route[RELAY] {
676
	# enable additional event routes for forwarded requests
677
	# - serial forking, RTP relaying handling, a.s.o.
678
	if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
679
		if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
680
	}
681
	if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
682
		if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
683
	}
684
	if (is_method("INVITE")) {
685
		dlg_manage();
686
		route(SETUP_BY_TRANSPORT);
687
		if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
688
	}
689
	if (!t_relay()) {
690
		sl_reply_error();
691
	}
692
	exit;
693
}
694

    
695
route[SETUP_BY_TRANSPORT] {
696
	if ($ru =~ "transport=ws") {
697
		xlog("L_INFO", "Request going to WS");
698
		if(sdp_with_transport("RTP/SAVPF")) {
699
			xlog("L_INFO", "RTP/SAVPF detected");
700
			rtpengine_manage("force trust-address replace-origin replace-session-connection ICE=force");
701
			t_on_reply("REPLY_WS_TO_WS");
702
			return;
703
		}
704
		rtpengine_manage("trust-address replace-origin replace-session-connection ICE=force RTP/SAVPF rtcp-mux-offer rtcp-mux-accept SDES-off");
705
		t_on_reply("REPLY_FROM_WS");
706
	}
707
	else if ($proto =~ "ws") {
708
		xlog("L_INFO", "Request coming from WS");
709
		rtpengine_manage("RTP/AVP");
710
		t_on_reply("REPLY_TO_WS");
711
	}
712
	else {
713
		xlog("L_INFO", "This is a classic phone call");
714
		rtpengine_manage("trust-address replace-origin replace-session-connection RTP/AVP");
715
		t_on_reply("MANAGE_CLASSIC_REPLY");
716
	}
717
}
718

    
719
onreply_route[REPLY_WS_TO_WS] {
720
	xlog("L_INFO", "WS to WS");
721
	if(status=~"[12][0-9][0-9]") {
722
		rtpengine_manage("force trust-address replace-origin replace-session-connection ICE=force");
723
		route(NATMANAGE);
724
	}
725
}
726

    
727
onreply_route[REPLY_FROM_WS] {
728
	xlog("L_INFO", "Reply from webrtc client: $rs");
729
	if(status=~"[12][0-9][0-9]") {
730
		rtpengine_manage("trust-address replace-origin replace-session-connection ICE=remove RTP/AVP rtcp-mux-offer rtcp-mux-accept SDES-off");
731
		route(NATMANAGE);
732
	}
733
}
734

    
735
onreply_route[REPLY_TO_WS] {
736
	xlog("L_INFO", "Reply from softphone: $rs");
737
	
738
	if (t_check_status("183")) {
739
		change_reply_status("180", "Ringing");
740
		remove_body();
741
		exit;
742
	}
743

    
744
	if(!(status=~"[12][0-9][0-9]"))
745
		return;
746

    
747
	rtpengine_manage("froc+SP");
748
	route(NATMANAGE);
749
}
750

    
751
onreply_route[MANAGE_CLASSIC_REPLY] {
752
	xlog("L_INFO", "Boring reply from softphone: $rs");
753

    
754
	if(status=~"[12][0-9][0-9]") {
755
		xlog("L_INFO", "rtpengine_manage - trust-address replace-origin replace-session-connection RTP/AVP");
756
		rtpengine_manage("trust-address replace-origin replace-session-connection RTP/AVP");	
757
                route(NATMANAGE);
758
	}
759
}
760

    
761
# Per SIP request initial checks
762
route[REQINIT] {
763
#!ifdef WITH_ANTIFLOOD
764
	# flood dection from same IP and traffic ban for a while
765
	# be sure you exclude checking trusted peers, such as pstn gateways
766
	# - local host excluded (e.g., loop to self)
767
	if(src_ip!=myself) {
768
		if($sht(ipban=>$si)!=$null) {
769
			# ip is already blocked
770
			xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
771
			exit;
772
		}
773
		if (!pike_check_req()) {
774
			xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
775
			$sht(ipban=>$si) = 1;
776
			exit;
777
		}
778
	}
779
	if($ua =~ "friendly-scanner") {
780
		sl_send_reply("200", "OK");
781
		exit;
782
	}
783
#!endif
784

    
785
	if (!mf_process_maxfwd_header("10")) {
786
		sl_send_reply("483","Too Many Hops");
787
		exit;
788
	}
789

    
790
	if(is_method("OPTIONS") && uri==myself && $rU==$null) {
791
		sl_send_reply("200","Keepalive");
792
		exit;
793
	}
794

    
795
	if(!sanity_check("1511", "7")) {
796
		xlog("Malformed SIP message from $si:$sp\n");
797
		exit;
798
	}
799
}
800

    
801
# Handle requests within SIP dialogs
802
route[WITHINDLG] {
803
	if (!has_totag()) return;
804

    
805
	# sequential request withing a dialog should
806
	# take the path determined by record-routing
807
	if (loose_route()) {
808
#!ifdef WITH_WEBSOCKETS
809
		if ($du == "") {
810
			if (!handle_ruri_alias()) {
811
				xlog("L_ERR", "Bad alias <$ru>\n");
812
				sl_send_reply("400", "Bad Request");
813
				exit;
814
			}
815
		}
816
#!endif
817
		route(DLGURI);
818
		if (is_method("BYE")) {
819
			setflag(FLT_ACC); # do accounting ...
820
			setflag(FLT_ACCFAILED); # ... even if the transaction fails
821
		}
822
		else if ( is_method("ACK") ) {
823
			# ACK is forwarded statelessy
824
			route(NATMANAGE);
825
		}
826
		else if ( is_method("NOTIFY") ) {
827
			# Add Record-Route for in-dialog NOTIFY as per RFC 6665.
828
			record_route();
829
		}
830
		route(RELAY);
831
		exit;
832
	}
833

    
834
	if (is_method("SUBSCRIBE") && uri == myself) {
835
		# in-dialog subscribe requests
836
		route(PRESENCE);
837
		exit;
838
	}
839
	if ( is_method("ACK") ) {
840
		if ( t_check_trans() ) {
841
			# no loose-route, but stateful ACK;
842
			# must be an ACK after a 487
843
			# or e.g. 404 from upstream server
844
			route(RELAY);
845
			exit;
846
		} else {
847
			# ACK without matching transaction ... ignore and discard
848
			exit;
849
		}
850
	}
851
	sl_send_reply("404","Not here");
852
	exit;
853
}
854

    
855
# Handle SIP registrations
856
route[REGISTRAR] {
857
	if (!is_method("REGISTER")) return;
858

    
859
	if(isflagset(FLT_NATS)) {
860
		setbflag(FLB_NATB);
861
#!ifdef WITH_NATSIPPING
862
		# do SIP NAT pinging
863
		setbflag(FLB_NATSIPPING);
864
#!endif
865
	}
866
	if (!save("location", "0x04"))
867
		sl_reply_error();
868
	exit;
869
}
870

    
871
# User location service
872
route[LOCATION] {
873

    
874
#!ifdef WITH_SPEEDDIAL
875
	# search for short dialing - 2-digit extension
876
	if($rU=~"^[0-9][0-9]$")
877
		if(sd_lookup("speed_dial"))
878
			route(SIPOUT);
879
#!endif
880

    
881
#!ifdef WITH_ALIASDB
882
	# search in DB-based aliases
883
	if(alias_db_lookup("dbaliases"))
884
		route(SIPOUT);
885
#!endif
886

    
887
	$avp(oexten) = $rU;
888
	if (!lookup("location")) {
889
		$var(rc) = $rc;
890
		route(TOVOICEMAIL);
891
		t_newtran();
892
		switch ($var(rc)) {
893
			case -1:
894
			case -3:
895
				send_reply("404", "Not Found");
896
				exit;
897
			case -2:
898
				send_reply("405", "Method Not Allowed");
899
				exit;
900
		}
901
	}
902

    
903
	# when routing via usrloc, log the missed calls also
904
	if (is_method("INVITE")) {
905
		setflag(FLT_ACCMISSED);
906
	}
907

    
908
	# t_on_failure("UA_FAILURE");
909
	route(RELAY);
910
	exit;
911
}
912

    
913
# Presence server processing
914
route[PRESENCE] {
915
	if(!is_method("PUBLISH|SUBSCRIBE"))
916
		return;
917

    
918
	if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {
919
		route(TOVOICEMAIL);
920
		# returns here if no voicemail server is configured
921
		sl_send_reply("404", "No voicemail service");
922
		exit;
923
	}
924

    
925
#!ifdef WITH_PRESENCE
926
	if (!t_newtran()) {
927
		sl_reply_error();
928
		exit;
929
	}
930

    
931
	if(is_method("PUBLISH")) {
932
		handle_publish();
933
		t_release();
934
	} else if(is_method("SUBSCRIBE")) {
935
		handle_subscribe();
936
		t_release();
937
	}
938
	exit;
939
#!endif
940
	
941
	# if presence enabled, this part will not be executed
942
	if (is_method("PUBLISH") || $rU==$null) {
943
		sl_send_reply("404", "Not here");
944
		exit;
945
	}
946
	return;
947
}
948

    
949
# IP authorization and user uthentication
950
route[AUTH] {
951
#!ifdef WITH_AUTH
952

    
953
#!ifdef WITH_IPAUTH
954
	if((!is_method("REGISTER")) && allow_source_address()) {
955
		# source IP allowed
956
		return;
957
	}
958
#!endif
959

    
960
	if (is_method("REGISTER") || from_uri==myself)
961
	{
962
		# authenticate requests
963
		if (!auth_check("$fd", "subscriber", "1")) {
964
			auth_challenge("$fd", "0");
965
			exit;
966
		}		
967
		# user authenticated - remove auth header
968
		if(!is_method("REGISTER|PUBLISH"))
969
			consume_credentials();
970
	}
971
	# if caller is not local subscriber, then check if it calls
972
	# a local destination, otherwise deny, not an open relay here
973
	if (from_uri!=myself && uri!=myself) {
974
		sl_send_reply("403","Not relaying");
975
		exit;
976
	}
977

    
978
#!endif
979
	return;
980
}
981

    
982
# Caller NAT detection
983
route[NATDETECT] {
984
#!ifdef WITH_NAT
985
	force_rport();
986
	if (nat_uac_test("19")) {
987
		if (is_method("REGISTER")) {
988
			fix_nated_register();
989
		} else {
990
			if(is_first_hop())
991
				set_contact_alias();
992
		}
993
		setflag(FLT_NATS);
994
	}
995
#!endif
996
	return;
997
}
998

    
999
# RTPengine control and singaling updates for NAT traversal
1000
route[NATMANAGE] {
1001
#!ifdef WITH_NAT
1002
	if (is_request()) {
1003
		if(has_totag()) {
1004
			if(check_route_param("nat=yes")) {
1005
				setbflag(FLB_NATB);
1006
			}
1007
		}
1008
	}
1009
	if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB)))
1010
		return;
1011
	
1012
	if (is_request()) {
1013
		if (!has_totag()) {
1014
			if(t_is_branch_route()) {
1015
				add_rr_param(";nat=yes");
1016
			}
1017
		}
1018
	}
1019
	if (is_reply()) {
1020
		if(isbflagset(FLB_NATB)) {
1021
			if(is_first_hop())
1022
				set_contact_alias();
1023
		}
1024
	}
1025
#!endif
1026
	return;
1027
}
1028

    
1029
# URI update for dialog requests
1030
route[DLGURI] {
1031
#!ifdef WITH_NAT
1032
	if(!isdsturiset()) {
1033
		handle_ruri_alias();
1034
	}
1035
#!endif
1036
	return;
1037
}
1038

    
1039
# Routing to foreign domains
1040
route[SIPOUT] {
1041
	if (uri==myself) return;
1042

    
1043
	append_hf("P-hint: outbound\r\n");
1044
	route(RELAY);
1045
	exit;
1046
}
1047

    
1048
# PSTN GW routing
1049
route[PSTN] {
1050
#!ifdef WITH_PSTN
1051
	# check if PSTN GW IP is defined
1052
	if (strempty($sel(cfg_get.pstn.gw_ip))) {
1053
		xlog("SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n");
1054
		return;
1055
	}
1056

    
1057
	# route to PSTN dialed numbers starting with '+' or '00'
1058
	#     (international format)
1059
	# - update the condition to match your dialing rules for PSTN routing
1060
	if(!($rU=~"^(\+|00)[1-9][0-9]{3,20}$"))
1061
		return;
1062

    
1063
	# only local users allowed to call
1064
	if(from_uri!=myself) {
1065
		sl_send_reply("403", "Not Allowed");
1066
		exit;
1067
	}
1068

    
1069
	if (strempty($sel(cfg_get.pstn.gw_port))) {
1070
		$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip);
1071
	} else {
1072
		$ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip) + ":"
1073
					+ $sel(cfg_get.pstn.gw_port);
1074
	}
1075

    
1076
	route(RELAY);
1077
	exit;
1078
#!endif
1079

    
1080
	return;
1081
}
1082

    
1083
# XMLRPC routing
1084
#!ifdef WITH_XMLRPC
1085
route[XMLRPC] {
1086
	# allow XMLRPC from localhost
1087
	if ((method=="POST" || method=="GET")
1088
			&& (src_ip==127.0.0.1)) {
1089
		# close connection only for xmlrpclib user agents (there is a bug in
1090
		# xmlrpclib: it waits for EOF before interpreting the response).
1091
		if ($hdr(User-Agent) =~ "xmlrpclib")
1092
			set_reply_close();
1093
		set_reply_no_connect();
1094
		dispatch_rpc();
1095
		exit;
1096
	}
1097
	send_reply("403", "Forbidden");
1098
	exit;
1099
}
1100
#!endif
1101

    
1102
# Routing to voicemail server
1103
route[TOVOICEMAIL] {
1104
#!ifdef WITH_VOICEMAIL
1105
	if(!is_method("INVITE|SUBSCRIBE"))
1106
		return;
1107

    
1108
	# check if VoiceMail server IP is defined
1109
	if (strempty($sel(cfg_get.voicemail.srv_ip))) {
1110
		xlog("SCRIPT: VoiceMail rotuing enabled but IP not defined\n");
1111
		return;
1112
	}
1113
	if(is_method("INVITE")) {
1114
		if($avp(oexten)==$null)
1115
			return;
1116
		$ru = "sip:" + $avp(oexten) + "@" + $sel(cfg_get.voicemail.srv_ip)
1117
				+ ":" + $sel(cfg_get.voicemail.srv_port);
1118
	} else {
1119
		if($rU==$null)
1120
			return;
1121
		$ru = "sip:" + $rU + "@" + $sel(cfg_get.voicemail.srv_ip)
1122
				+ ":" + $sel(cfg_get.voicemail.srv_port);
1123
	}
1124
	route(RELAY);
1125
	exit;
1126
#!endif
1127

    
1128
	return;
1129
}
1130

    
1131
# Manage outgoing branches
1132
branch_route[MANAGE_BRANCH] {
1133
	xdbg("new branch [$T_branch_idx] to $ru\n");
1134
	route(NATMANAGE);
1135
}
1136

    
1137
# Manage incoming replies
1138
onreply_route[MANAGE_REPLY] {
1139
	xdbg("incoming reply\n");
1140
	if(status=~"[12][0-9][0-9]")
1141
		route(NATMANAGE);
1142
}
1143

    
1144
# Manage failure routing cases
1145
failure_route[MANAGE_FAILURE] {
1146
	route(NATMANAGE);
1147

    
1148
	if (t_is_canceled()) {
1149
		exit;
1150
	}
1151

    
1152
#!ifdef WITH_BLOCK3XX
1153
	# block call redirect based on 3xx replies.
1154
	if (t_check_status("3[0-9][0-9]")) {
1155
		t_reply("404","Not found");
1156
		exit;
1157
	}
1158
#!endif
1159

    
1160
#!ifdef WITH_VOICEMAIL
1161
	# serial forking
1162
	# - route to voicemail on busy or no answer (timeout)
1163
	if (t_check_status("486|408")) {
1164
		$du = $null;
1165
		route(TOVOICEMAIL);
1166
		exit;
1167
	}
1168
#!endif
1169
}
1170

    
1171
#!ifdef WITH_WEBSOCKETS
1172
onreply_route {
1173
	if ((($Rp == MY_WS_PORT || $Rp == MY_WSS_PORT)
1174
		&& !(proto == WS || proto == WSS)) || $Rp == MY_MSRP_PORT) {
1175
		xlog("L_WARN", "SIP response received on $Rp\n");
1176
		drop;
1177
		exit;
1178
	}
1179
 
1180
	if (nat_uac_test(64)) {
1181
		# Do NAT traversal stuff for replies to a WebSocket connection
1182
		# - even if it is not behind a NAT!
1183
		# This won't be needed in the future if Kamailio and the
1184
		# WebSocket client support Outbound and Path.
1185
		add_contact_alias();
1186
	}
1187
}
1188
 
1189
event_route[xhttp:request] {
1190
	set_reply_close();
1191
	set_reply_no_connect();
1192
	
1193
	if ($Rp != MY_WS_PORT
1194
#!ifdef WITH_TLS
1195
	    && $Rp != MY_WSS_PORT
1196
#!endif
1197
	) {
1198
		xlog("L_WARN", "HTTP request received on $Rp\n");
1199
		xhttp_reply("403", "Forbidden", "", "");
1200
		exit;
1201
	}
1202
 
1203
	xlog("L_DBG", "HTTP Request Received\n");
1204
 
1205
	if ($hdr(Upgrade)=~"websocket"
1206
			&& $hdr(Connection)=~"Upgrade"
1207
			&& $rm=~"GET") {
1208
 
1209
		# Validate Host - make sure the client is using the correct
1210
		# alias for WebSockets
1211
		# Sasa: commented out, see http://sip-router.1086192.n5.nabble.com/Testing-the-Websocket-module-with-sipml5-org-td65069.html
1212
		#if ($hdr(Host) == $null || !is_myself("sip:" + $hdr(Host))) {
1213
		#	xlog("L_WARN", "Bad host $hdr(Host)\n");
1214
		#	xhttp_reply("403", "Forbidden", "", "");
1215
		#	exit;
1216
		#}
1217
 
1218
		# Optional... validate Origin - make sure the client is from an
1219
		# authorised website.  For example,
1220
		#
1221
		# if ($hdr(Origin) != "http://communicator.MY_DOMAIN"
1222
		#     && $hdr(Origin) != "https://communicator.MY_DOMAIN") {
1223
		#	xlog("L_WARN", "Unauthorised client $hdr(Origin)\n");
1224
		#	xhttp_reply("403", "Forbidden", "", "");
1225
		#	exit;
1226
		# }
1227
 
1228
		# Optional... perform HTTP authentication
1229
 
1230
		# ws_handle_handshake() exits (no further configuration file
1231
		# processing of the request) when complete.
1232
		if (ws_handle_handshake())
1233
		{
1234
			# Optional... cache some information about the
1235
			# successful connection
1236
			exit;
1237
		}
1238
	}
1239
 
1240
	xhttp_reply("404", "Not Found", "", "");
1241
}
1242
 
1243
event_route[websocket:closed] {
1244
	xlog("L_INFO", "WebSocket connection from $si:$sp has closed\n");
1245
}
1246

    
1247
failure_route[UA_FAILURE] {
1248
	xlog("L_INFO", "Triggered UA_FAILURE\n");
1249
	if (t_check_status("488") && sdp_content()) {
1250
		if (sdp_get_line_startswith("$avp(mline)", "m=")) {
1251
			if ($avp(mline) =~ "SAVPF") {
1252
				$avp(rtpengine_offer_flags) = "froc-sp";
1253
				$avp(rtpengine_answer_flags) = "froc+SP";
1254
			} else {
1255
				$avp(rtpengine_offer_flags) = "froc+SP";
1256
				$avp(rtpengine_answer_flags) = "froc-sp";
1257
			}
1258
		}
1259
		append_branch();
1260
		rtpengine_offer($avp(rtpengine_offer_flags));
1261
		t_on_reply("RTPPROXY_REPLY");
1262
		route(RELAY);
1263
	}
1264
}
1265

    
1266
onreply_route[RTPPROXY_REPLY] {
1267
	xlog("L_INFO", "Triggered RTPPROXY_REPLY\n");
1268
	if (status =~ "18[03]") {
1269
		change_reply_status(180, "Ringing");
1270
		remove_body();
1271
	} else if (status =~ "2[0-9][0-9]" && sdp_content()) {
1272
		rtpengine_answer($avp(rtpengine_answer_flags));
1273
	}
1274
}
1275
#!endif
1276
 
1277
#!ifdef WITH_MSRP
1278
event_route[msrp:frame-in] {
1279
	msrp_reply_flags("1");
1280
 
1281
	if ((($Rp == MY_WS_PORT || $Rp == MY_WSS_PORT)
1282
		&& !(proto == WS || proto == WSS)) && $Rp != MY_MSRP_PORT) {
1283
		xlog("L_WARN", "MSRP request received on $Rp\n");
1284
		msrp_reply("403", "Action-not-allowed");
1285
		exit;
1286
	}
1287
 
1288
	if (msrp_is_reply()) {
1289
		msrp_relay();
1290
	} else if($msrp(method)=="AUTH") {
1291
		if($msrp(nexthops)>0) {
1292
			msrp_relay();
1293
			exit;
1294
		}
1295
 
1296
		if (!www_authenticate("MY_DOMAIN", "subscriber",
1297
					"$msrp(method)")) {
1298
			if (auth_get_www_authenticate("MY_DOMAIN", "1",
1299
							"$var(wauth)")) {
1300
				msrp_reply("401", "Unauthorized",
1301
							"$var(wauth)");
1302
			} else {
1303
				msrp_reply("500", "Server Error");
1304
			}
1305
			exit;
1306
		}
1307
 
1308
		if ($hdr(Expires) != $null) {
1309
			$var(expires) = (int) $hdr(Expires);
1310
			if ($var(expires) < MSRP_MIN_EXPIRES) {
1311
				msrp_reply("423", "Interval Out-of-Bounds",
1312
					"Min-Expires: MSRP_MIN_EXPIRES\r\n");
1313
				exit;
1314
			} else if ($var(expires) > MSRP_MAX_EXPIRES) {
1315
				msrp_reply("423", "Interval Out-of-Bounds",
1316
					"Max-Expires: MSRP_MAX_EXPIRES\r\n");
1317
				exit;
1318
			}
1319
		} else {
1320
			$var(expires) = MSRP_MAX_EXPIRES;
1321
		}
1322
 
1323
		$var(cnt) = $var(cnt) + 1;
1324
		pv_printf("$var(sessid)", "s.$(pp).$(var(cnt)).$(RANDOM)");
1325
		$sht(msrp=>$var(sessid)::srcaddr) = $msrp(srcaddr);
1326
		$sht(msrp=>$var(sessid)::srcsock) = $msrp(srcsock);
1327
		$shtex(msrp=>$var(sessid)) = $var(expires) + 5;
1328
		# - Use-Path: the MSRP address for server + session id
1329
		$var(hdrs) = "Use-Path: msrps://MY_IP_ADDR:MY_MSRP_PORT/"
1330
					+ $var(sessid) + ";tcp\r\n"
1331
					+ "Expires: " + $var(expires) + "\r\n";
1332
		msrp_reply("200", "OK", "$var(hdrs)");
1333
	} else if ($msrp(method)=="SEND" || $msrp(method)=="REPORT") {
1334
		if ($msrp(nexthops)>1) {
1335
			if ($msrp(method)!="REPORT") {
1336
				msrp_reply("200", "OK");
1337
			}
1338
			msrp_relay();
1339
			exit;
1340
		}
1341
		$var(sessid) = $msrp(sessid);
1342
		if ($sht(msrp=>$var(sessid)::srcaddr) == $null) {
1343
			# one more hop, but we don't have address in htable
1344
			msrp_reply("481", "Session-does-not-exist");
1345
			exit;
1346
		} else if ($msrp(method)!="REPORT") {
1347
			msrp_reply("200", "OK");
1348
		}
1349
		msrp_relay_flags("1");
1350
		msrp_set_dst("$sht(msrp=>$var(sessid)::srcaddr)",
1351
				"$sht(msrp=>$var(sessid)::srcsock)");
1352
		msrp_relay();
1353
	} else {
1354
		msrp_reply("501", "Request-method-not-understood");
1355
	}
1356
}
1357
#!endif
(5-5/5) Go to top