full_ps.cfg 15 KB

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