1debug=3         # debug level (cmd line: -dddddddddd)
2#memdbg=100
3#fork=yes
4#log_stderror=no	# (cmd line: -E)
5#memlog=5 # memory debug log level
6#log_facility=LOG_LOCAL0 # sets the facility used for logging (see syslog(3))
7
8check_via=no	# (cmd. line: -v)
9dns=no           # (cmd. line: -r)
10rev_dns=no      # (cmd. line: -R)
11port=5060
12children=2
13alias="example.com"
14alias="t-online.de"
15
16#user=ser
17#group=ser
18#open_fd_limit=1024 # sets the open file descriptors limit
19mhomed=yes  # usefull for multihomed hosts, small performance penalty
20
21#disable_tcp=yes
22tcp_accept_aliases=yes # accepts the tcp alias via option (see NEWS)
23#tcp_poll_method="sigio_rt"
24
25tcp_send_timeout=1
26tcp_children=32
27tcp_connect_timeout=1
28tcp_connection_lifetime=600
29tcp_max_connections=50000
30
31# ------------------ module loading ----------------------------------
32
33# Uncomment this if you want to use SQL database
34loadmodule "/usr/lib/ser/modules/xcap.so"
35loadmodule "/usr/lib/ser/modules/sl.so"
36loadmodule "/usr/lib/ser/modules/avp.so"
37loadmodule "/usr/lib/ser/modules/avpops.so"
38loadmodule "/usr/lib/ser/modules/tm.so"
39loadmodule "/usr/lib/ser/modules/rr.so"
40loadmodule "/usr/lib/ser/modules/maxfwd.so"
41loadmodule "/usr/lib/ser/modules/usrloc.so"
42loadmodule "/usr/lib/ser/modules/registrar.so"
43loadmodule "/usr/lib/ser/modules/textops.so"
44loadmodule "/usr/lib/ser/modules/mysql.so"
45loadmodule "/usr/lib/ser/modules/dialog.so"
46loadmodule "/usr/lib/ser/modules/rls.so"
47loadmodule "/usr/lib/ser/modules/pa.so"
48loadmodule "/usr/lib/ser/modules/presence_b2b.so"
49loadmodule "/usr/lib/ser/modules/uri.so"
50loadmodule "/usr/lib/ser/modules/uri_db.so"
51loadmodule "/usr/lib/ser/modules/domain.so"
52loadmodule "/usr/lib/ser/modules/fifo.so"
53loadmodule "/usr/lib/ser/modules/xmlrpc.so"
54loadmodule "/usr/lib/ser/modules/xlog.so"
55#loadmodule "/usr/lib/ser/modules/unixsock.so"
56
57# binrpc
58loadmodule "/usr/lib/ser/modules/ctl.so"
59
60# Uncomment this if you want digest authentication
61# mysql.so must be loaded !
62loadmodule "/usr/lib/ser/modules/auth.so"
63loadmodule "/usr/lib/ser/modules/auth_db.so"
64loadmodule "/usr/lib/ser/modules/msilo.so"
65
66# ----------------- setting module-specific parameters ---------------
67
68# modparam("msilo","registrar","sip:registrar@example.com")
69modparam("msilo","use_contact",0)
70modparam("msilo","expire_time",7200)
71
72# -- usrloc params --
73
74# -- auth params --
75# Uncomment if you are using auth module
76#
77modparam("auth_db", "calculate_ha1", yes)
78#
79# If you set "calculate_ha1" parameter to yes (which true in this config),
80# uncomment also the following parameter)
81#
82modparam("auth_db", "password_column", "password")
83
84# -- rr params --
85# add value to ;lr param to make some broken UAs happy
86modparam("rr", "enable_full_lr", 1)
87
88modparam("rls", "min_expiration", 300)
89modparam("rls", "max_expiration", 300)
90modparam("rls", "default_expiration", 300)
91modparam("rls", "expiration_timer_period", 30)
92modparam("rls", "auth", "none")
93modparam("rls", "reduce_xcap_needs", 1)
94modparam("rls", "db_mode", 1)
95modparam("rls", "timer_interval", 10)
96modparam("rls", "max_notifications_at_once", 100);
97modparam("rls", "max_list_nesting_level", 4);
98
99modparam("pa", "use_db", 1)
100# allow storing authorization requests for offline users into database
101modparam("pa", "use_offline_winfo", 1)
102# how often try to remove old stored authorization requests
103modparam("pa", "offline_winfo_timer", 600)
104# how long stored authorization requests live
105modparam("pa", "offline_winfo_expiration", 600)
106# mode of PA authorization: none, implicit or xcap
107modparam("pa", "auth", "xcap")
108# do not authorize watcherinfo subscriptions
109modparam("pa", "winfo_auth", "none")
110# use only published information if set to 0
111modparam("pa", "use_callbacks", 1)
112# don't accept internal subscriptions from RLS, ...
113modparam("pa", "accept_internal_subscriptions", 0)
114# maximum value of Expires for subscriptions
115modparam("pa", "max_subscription_expiration", 300)
116# maximum value of Expires for publications
117modparam("pa", "max_publish_expiration", 300)
118# how often test if something changes and send NOTIFY
119modparam("pa", "timer_interval", 1)
120modparam("pa", "async_auth_queries", 0)
121modparam("pa", "auth_rules_refresh_time", 60)
122modparam("pa", "max_auth_requests_per_tick", 1000)
123modparam("pa", "ignore_408_on_notify", 1)
124#modparam("pa", "pres_rules_file", "presence-rules.xml")
125#experimental:
126#modparam("pa", "subscribe_to_users", 1);
127#modparam("pa", "pa_subscription_uri", "sip:presence-server@example.com");
128
129
130# route for generated SUBSCRIBE requests for presence
131#modparam("presence_b2b", "presence_route", "<sip:127.0.0.1;transport=tcp;lr>")
132modparam("presence_b2b", "presence_outbound_proxy", "sip:127.0.0.1;transport=tcp")
133#modparam("presence_b2b", "presence_outbound_proxy", "sip:127.0.0.1")
134# waiting time from error to new attepmt about SUBSCRIBE
135modparam("presence_b2b", "on_error_retry_time", 60)
136# how long wait for NOTIFY with Subscription-Status=terminated after unsubscribe
137modparam("presence_b2b", "wait_for_term_notify", 33)
138# how long before expiration send renewal SUBSCRIBE request
139modparam("presence_b2b", "resubscribe_delta", 30)
140# minimal time to send renewal SUBSCRIBE request from receiving previous response
141modparam("presence_b2b", "min_resubscribe_time", 60)
142# default expiration timeout
143modparam("presence_b2b", "default_expiration", 3600)
144# process internal subscriptions to presence events
145modparam("presence_b2b", "handle_presence_subscriptions", 1)
146#additional headers for presence
147#modparam("presence_b2b", "additional_presence_headers", "P-Generated: yes\r\nP-Regenreated: no\r\n")
148# randomized SUBSCRIBE requests?
149modparam("presence_b2b", "max_subscribe_delay", 10)
150
151#modparam("usrloc", "reg_avp_flag", "regavps")
152modparam("usrloc", "db_mode", 0)
153
154modparam("domain", "db_mode", 1)
155modparam("domain", "load_domain_attrs", 1)
156#modparam("domain|uri_db|acc|auth_db|usrloc|msilo|rls|pa", "db_url", "mysql://ser:heslo@spsdb:3306/ser")
157modparam("domain|uri_db|acc|auth_db|usrloc|msilo|rls|pa", "db_url", "mysql://ser:heslo@127.0.0.1:3306/ser")
158
159modparam("fifo", "fifo_file", "/tmp/ser_fifo")
160
161#modparam("xcap", "xcap_root", "http://pulpuk/xcap")
162modparam("xcap", "xcap_root", "http://localhost/xcap")
163
164# -------------------------  request routing logic -------------------
165
166# main routing logic
167
168avpflags regavps;
169
170route{
171	# XML RPC
172	if (method == "POST" ||  method == "GET") {
173		dispatch_rpc();
174		break;
175	}
176
177	# initial sanity checks -- messages with
178	# max_forwards==0, or excessively long requests
179	if (!mf_process_maxfwd_header("10")) {
180		sl_send_reply("483","Too Many Hops");
181		break;
182	};
183	if (msg:len >=  max_len ) {
184		sl_send_reply("513", "Message too big");
185		break;
186	};
187
188	# we record-route all messages -- to make sure that
189	# subsequent messages will go through our proxy; that's
190	# particularly good if upstream and downstream entities
191	# use different transport protocol
192	if (!method=="REGISTER") record_route();
193
194	# subsequent messages withing a dialog should take the
195	# path determined by record-routing
196	if (loose_route()) {
197		# mark routing logic in request
198		append_hf("P-hint: rr-enforced\r\n");
199		route(1);
200		break;
201	};
202
203
204#	lookup_domain("To");
205#	lookup_user("To");
206#
207#	xlog("L_ERR", "Dispatch request %rm to: %tu from: %fu\n");
208#	ds_select_new("1", "3");  /* request uri */
209#	sl_send_reply("302", "Moved temporarily");
210#	break;
211
212	if (!lookup_domain("$td", "@to.uri.host")) {
213		xlog("L_ERR", "Unknown domain to: %tu from: %fu\n");
214		route(1);
215		break;
216	}
217
218#	xlog("L_INFO", "xcap_root: %$t.xcap_root\n");
219
220	if (method=="SUBSCRIBE") {
221#		if ((@msg.supported=~"eventlist")) {
222#			xlog("L_ERR","!!! Support for event lists: %@msg.supported\n");
223#		}
224#		else {
225#			xlog("L_ERR","!!! NON-Support for event lists: %@msg.supported\n");
226#		}
227
228		if (search("^(From|f):.*sip:presence-server@test-domain")) {
229			log(1,"subscription from PA!\n");
230			# subscriptions from PA to user !!!
231			if (!lookup("location")) {
232				sl_send_reply("404", "Not Found");
233				break;
234			};
235		#	append_hf("P-hint: usrloc applied\r\n");
236			route(1);
237			drop;
238		};
239
240		if (!t_newtran()) {
241			sl_reply_error();
242			break;
243		};
244
245		if (@to.tag=="") {
246			# only for new subscriptions (with empty to tag)
247
248			if (lookup_user("$tu.uid", "@to.uri")) {
249				# existing user -> it is subscription to PA
250
251				# xcap parameters
252#					set_xcap_root("hTTp://localhost/xcap");
253#					set_xcap_filename("pres.xml");
254#					xlog("L_INFO", "Hopla\n");
255
256				$xcap_root = "pokus";
257#				set_xcap_root("http://nekde.nic.cz");
258				set_xcap_filename("pre.xml");
259
260				xlog("L_ERR", "XCAP_ROOT before: %$xcap_root\n");
261				if (handle_subscription("registrar")) {
262					xlog("L_ERR", "XCAP_ROOT after: %$xcap_root\n");
263					break;
264
265					if ((@msg.event=~"presence\.winfo")) {
266						# new watcher info subscription
267						# sends one watcher info NOTIFY message with all saved authorization requests
268						#xlog("L_ERR", "dumping stored winfo to %fu\n");
269						dump_stored_winfo("registrar", "presence");
270					}
271					else {
272						# new presence subscription
273						#if ((@msg.event=~"presence") && check_subscription_status("pending")) {
274						if ((@msg.event=~"presence")) {
275							# if offline user and new pending subscription
276							if (!target_online("registrar")) {
277								#xlog("L_ERR", "storing 'pending' winfo to: %tu, from: %fu\n");
278								store_winfo("registrar");
279							}
280						}
281					}
282				}
283				break;
284			}
285
286			if ((@msg.supported=~"eventlist")) {
287				# such user doesn't exist and Supported header field
288				#    -> probably RLS subscription
289
290				#set_xcap_root("HttP://LOCALhost/xcap");
291
292				if (lookup_domain("$fd", "@from.uri.host")) {
293					if (lookup_user("$fu.uid","@from.uri")) {
294						if (is_simple_rls_target("$uid-list")) {
295						# if (is_simple_rls_target("contact-list")) {
296							# log(1, "it is simple subscription!\n");
297							# takes From UID and makes XCAP query for user's
298							# list named "default"
299							if (!query_resource_list("default")) {
300								t_reply("404", "No such user list");
301								break;
302							}
303						}
304						else {
305							if (is_simple_rls_target("contact-list")) {
306								if (!query_resource_list("testing")) {
307									t_reply("404", "No such user contact list");
308									break;
309								}
310							}
311						}
312					}
313				}
314
315				if (!have_flat_list()) {
316					# query_resource_list failed or was not called
317					# do standard RLS query acording to To/AOR
318					if (!query_rls_services()) {
319						log(1, "XCAP query failed\n");
320						t_reply("404", "No such list URI");
321						break;
322					}
323				}
324
325				# uncomment this if you want to authenticate first SUBSCRIBE request to resource list
326#					if (!proxy_authenticate("example.com", "credentials")) {
327#						proxy_challenge( "example.com", "0");
328#						break;
329#					};
330
331				handle_rls_subscription("1");
332			}
333			else {
334				# not resource list subscription -> invalid user
335				#xlog("L_ERR", "subscription to invalid user %tu\n");
336				t_reply("404", "User not found");
337			}
338
339			break;
340		}
341		else {
342			# renewal subscriptions - try to handle it as RLS and if failed, handle it as PA subscription
343			# FIXME: better will be test like existing_rls_subscription()
344			#        and existing_subscription("registrar")
345			if (!handle_rls_subscription("0")) {
346				lookup_user("$tu.uid", "@to.uri"); # needed to get correct UID (internal call converts it to lowercase!)
347				handle_subscription("registrar");
348			}
349			break;
350		}
351	};
352
353	if (method=="NOTIFY") {
354		if (search("^(To|t):.*sip:presence-server@test-domain")) {
355			log(1,"notify to PA!\n");
356			# notification to PA from user !!!
357			if (!t_newtran()) {
358			   log(1, "newtran error\n");
359			   sl_reply_error();
360			   break;
361			};
362			# handle notification sent in internal subscriptions (presence_b2b)
363			if (!handle_notify()) {
364				t_reply("481", "Unable to handle notification for PA");
365			}
366			break;
367		}
368	};
369
370	# get user (common for all other messages than SUBSCRIBE)
371	if (!lookup_user("$tu.uid", "@to.uri")) {
372		xlog("L_ERR", "Unknown user, To: %tu?");
373		# break;
374		#append_hf("P-hint: unknown user\r\n");
375		sl_send_reply("404", "Unknown user");
376		#route(1);
377		break;
378	}
379
380	if (method=="PUBLISH") {
381		if (!t_newtran()) {
382#			   log(1, "newtran error\n");
383		   sl_reply_error();
384		   break;
385		};
386		handle_publish("registrar");
387
388		# deliver messages to online user
389		# TODO: only if user goes from offline to online?
390		if (target_online("registrar")) {
391			# log(1, "Dumping stored messages\n");
392			# dump stored messages - route it through myself (otherwise routed via DNS!)
393			if (m_dump("sip:127.0.0.1")) {
394				#xlog("L_ERR", "MSILO: offline messages for %fu dumped\n");
395				break;
396			}
397		}
398
399		break;
400	};
401
402	if (method=="NOTIFY") {
403		if (!t_newtran()) {
404		   log(1, "newtran error\n");
405		   sl_reply_error();
406		   break;
407		};
408		# handle notification sent in internal subscriptions (presence_b2b)
409		if (!handle_notify()) {
410			t_reply("481", "Unable to handle notification");
411		}
412		break;
413	};
414
415	if (method=="MESSAGE") {
416
417		if (authorize_message("im-rules.xml")) {
418
419			# use usrloc for delivery
420			if (lookup("location")) {
421
422				#log(1, "Delivering MESSAGE using usrloc\n");
423				t_on_failure("1");
424				if (!t_relay()) {
425					sl_reply_error();
426				}
427
428				break;
429			}
430			else {
431				# store messages for offline user
432				#xlog("L_ERR", "MSILO: storing MESSAGE for %tu\n");
433
434				if (!t_newtran()) {
435				   log(1, "newtran error\n");
436				   sl_reply_error();
437				   break;
438				};
439
440				# store only text messages NOT isComposing... !
441				if (search("^(Content-Type|c):.*application/im-iscomposing\+xml.*")) {
442					#log(1, "it is only isComposing message - ignored\n");
443					t_reply("202", "Ignored");
444					break;
445				}
446
447				if (m_store("0", "sip:127.0.0.1")) {
448#	                #log(1, "MSILO: offline message stored\n");
449					if (!t_reply("202", "Accepted")) {
450						sl_reply_error();
451					};
452				} else {
453					log(1, "MSILO: error storing offline message\n");
454					if (!t_reply("503", "Service Unavailable")) {
455						sl_reply_error();
456					};
457				};
458				break;
459			}
460			break;
461		}
462		else {
463			# log(1, "unauthorized message\n");
464			sl_reply("403", "Forbidden");
465		}
466		break;
467	}
468
469	if (method=="REGISTER") {
470		# uncomment this if you want to authenticate REGISTER request
471#			if (!www_authenticate("example.com", "credentials")) {
472#				www_challenge( "example.com", "0");
473#				break;
474#			};
475
476		$t.a = @msg.cseq;
477		setavpflag("$t.a","regavps");
478		save("location");
479
480		# dump stored messages - route it through myself (otherwise routed via DNS!)
481		if (m_dump("sip:127.0.0.1")) {
482			#xlog("L_ERR", "MSILO: offline messages for %fu dumped\n");
483			break;
484		}
485		break;
486	};
487
488	# native SIP destinations are handled using our USRLOC DB
489	t_on_branch("1");
490	if (!lookup("location")) {
491		sl_send_reply("404", "Not Found");
492		break;
493	};
494#	append_hf("P-hint: usrloc applied\r\n");
495	route(1);
496}
497
498branch_route[1]
499{
500#	xlog("L_ERR", "on_branch: to: %tu, from: %fu\n");
501#	xlog("L_ERR", "ruri: %ru uid: %$t.uid\n");
502	read_reg_avps("location", "$t.uid");
503	xlog("L_ERR", "$t.a = %$t.a");
504}
505route[1]
506{
507	# send it out now; use stateful forwarding as it works reliably
508	# even for UDP2TCP
509	if (!t_relay()) {
510		sl_reply_error();
511	};
512}
513
514
515failure_route[1] {
516	# forwarding failed -- check if the request was a MESSAGE
517	if (!method=="MESSAGE") { break; };
518	#log(1, "MSILO: MESSAGE forward failed - storing it\n");
519
520    # we have changed the R-URI with the contact address, ignore it now
521	if (m_store("0", "")) {
522		t_reply("202", "Accepted");
523	} else {
524		log(1, "MSILO: offline message NOT stored\n");
525		t_reply("503", "Service Unavailable");
526	};
527}
528