full-no-failover.cfg 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. debug=3 # debug level (cmd line: -dddddddddd)
  2. #fork=yes
  3. #log_stderror=no # (cmd line: -E)
  4. #memlog=5 # memory debug log level
  5. #log_facility=LOG_LOCAL0 # sets the facility used for logging (see syslog(3))
  6. check_via=no # (cmd. line: -v)
  7. dns=no # (cmd. line: -r)
  8. rev_dns=no # (cmd. line: -R)
  9. port=5060
  10. children=2
  11. alias="test-domain.com"
  12. #user=ser
  13. #group=ser
  14. #open_fd_limit=1024 # sets the open file descriptors limit
  15. mhomed=yes # usefull for multihomed hosts, small performance penalty
  16. #disable_tcp=yes
  17. #tcp_accept_aliases=yes # accepts the tcp alias via option (see NEWS)
  18. #tcp_poll_method="sigio_rt"
  19. # ------------------ module loading ----------------------------------
  20. # Uncomment this if you want to use SQL database
  21. loadmodule "/usr/lib/ser/modules/sl.so"
  22. loadmodule "/usr/lib/ser/modules/avp.so"
  23. loadmodule "/usr/lib/ser/modules/avpops.so"
  24. loadmodule "/usr/lib/ser/modules/tm.so"
  25. loadmodule "/usr/lib/ser/modules/rr.so"
  26. loadmodule "/usr/lib/ser/modules/maxfwd.so"
  27. loadmodule "/usr/lib/ser/modules/usrloc.so"
  28. loadmodule "/usr/lib/ser/modules/registrar.so"
  29. loadmodule "/usr/lib/ser/modules/textops.so"
  30. loadmodule "/usr/lib/ser/modules/mysql.so"
  31. loadmodule "/usr/lib/ser/modules/dialog.so"
  32. loadmodule "/usr/lib/ser/modules/rls.so"
  33. loadmodule "/usr/lib/ser/modules/pa.so"
  34. loadmodule "/usr/lib/ser/modules/presence_b2b.so"
  35. loadmodule "/usr/lib/ser/modules/uri.so"
  36. loadmodule "/usr/lib/ser/modules/uri_db.so"
  37. loadmodule "/usr/lib/ser/modules/domain.so"
  38. loadmodule "/usr/lib/ser/modules/fifo.so"
  39. loadmodule "/usr/lib/ser/modules/xmlrpc.so"
  40. loadmodule "/usr/lib/ser/modules/xlog.so"
  41. #loadmodule "/usr/lib/ser/modules/unixsock.so"
  42. # Uncomment this if you want digest authentication
  43. # mysql.so must be loaded !
  44. loadmodule "/usr/lib/ser/modules/auth.so"
  45. loadmodule "/usr/lib/ser/modules/auth_db.so"
  46. loadmodule "/usr/lib/ser/modules/msilo.so"
  47. # ----------------- setting module-specific parameters ---------------
  48. # modparam("msilo","registrar","sip:[email protected]")
  49. modparam("msilo","use_contact",0)
  50. modparam("msilo","expire_time",7200)
  51. # -- usrloc params --
  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", "plain_password_column", "password")
  61. # -- rr params --
  62. # add value to ;lr param to make some broken UAs happy
  63. modparam("rr", "enable_full_lr", 1)
  64. modparam("rls", "min_expiration", 200)
  65. modparam("rls", "max_expiration", 300)
  66. modparam("rls", "default_expiration", 300)
  67. modparam("rls", "auth", "none")
  68. modparam("rls", "xcap_root", "http://localhost/xcap")
  69. modparam("rls", "reduce_xcap_needs", 1)
  70. modparam("rls", "db_mode", 0)
  71. modparam("rls", "db_url", "mysql://ser:heslo@localhost:3306/ser")
  72. modparam("pa", "use_db", 0)
  73. # allow storing authorization requests for offline users into database
  74. modparam("pa", "use_offline_winfo", 1)
  75. # how often try to remove old stored authorization requests
  76. modparam("pa", "offline_winfo_timer", 600)
  77. # how long stored authorization requests live
  78. modparam("pa", "offline_winfo_expiration", 600)
  79. modparam("pa", "db_url", "mysql://ser:heslo@localhost:3306/ser")
  80. # mode of PA authorization: none, implicit or xcap
  81. modparam("pa", "auth", "xcap")
  82. modparam("pa", "auth_xcap_root", "http://localhost/xcap")
  83. # do not authorize watcherinfo subscriptions
  84. modparam("pa", "winfo_auth", "none")
  85. # use only published information if set to 0
  86. modparam("pa", "use_callbacks", 1)
  87. # don't accept internal subscriptions from RLS, ...
  88. modparam("pa", "accept_internal_subscriptions", 0)
  89. # maximum value of Expires for subscriptions
  90. modparam("pa", "max_subscription_expiration", 600)
  91. # maximum value of Expires for publications
  92. modparam("pa", "max_publish_expiration", 120)
  93. # how often test if something changes and send NOTIFY
  94. modparam("pa", "timer_interval", 10)
  95. # route for generated SUBSCRIBE requests for presence
  96. modparam("presence_b2b", "presence_route", "<sip:127.0.0.1;transport=tcp;lr>")
  97. # waiting time from error to new attepmt about SUBSCRIBE
  98. modparam("presence_b2b", "on_error_retry_time", 60)
  99. # how long wait for NOTIFY with Subscription-Status=terminated after unsubscribe
  100. modparam("presence_b2b", "wait_for_term_notify", 33)
  101. # how long before expiration send renewal SUBSCRIBE request
  102. modparam("presence_b2b", "resubscribe_delta", 30)
  103. # minimal time to send renewal SUBSCRIBE request from receiving previous response
  104. modparam("presence_b2b", "min_resubscribe_time", 60)
  105. # default expiration timeout
  106. modparam("presence_b2b", "default_expiration", 3600)
  107. # process internal subscriptions to presence events
  108. modparam("presence_b2b", "handle_presence_subscriptions", 1)
  109. modparam("usrloc", "db_mode", 0)
  110. modparam("domain", "db_mode", 1)
  111. modparam("domain|uri_db|acc|auth_db|usrloc|msilo", "db_url", "mysql://ser:heslo@localhost:3306/ser")
  112. modparam("fifo", "fifo_file", "/tmp/ser_fifo")
  113. # ------------------------- request routing logic -------------------
  114. # main routing logic
  115. route{
  116. # XML RPC
  117. if (method == "POST" || method == "GET") {
  118. create_via();
  119. dispatch_rpc();
  120. break;
  121. }
  122. # initial sanity checks -- messages with
  123. # max_forwards==0, or excessively long requests
  124. if (!mf_process_maxfwd_header("10")) {
  125. sl_send_reply("483","Too Many Hops");
  126. break;
  127. };
  128. if (msg:len >= max_len ) {
  129. sl_send_reply("513", "Message too big");
  130. break;
  131. };
  132. # we record-route all messages -- to make sure that
  133. # subsequent messages will go through our proxy; that's
  134. # particularly good if upstream and downstream entities
  135. # use different transport protocol
  136. if (!method=="REGISTER") record_route();
  137. # subsequent messages withing a dialog should take the
  138. # path determined by record-routing
  139. if (loose_route()) {
  140. # mark routing logic in request
  141. append_hf("P-hint: rr-enforced\r\n");
  142. route(1);
  143. break;
  144. };
  145. # if the request is for other domain use UsrLoc
  146. # (in case, it does not work, use the following command
  147. # with proper names and addresses in it)
  148. if (uri==myself) {
  149. if (!lookup_domain("To")) {
  150. xlog("L_ERR", "Unknown domain to: %tu from: %fu\n");
  151. route(1);
  152. break;
  153. }
  154. if (method=="SUBSCRIBE") {
  155. if (!t_newtran()) {
  156. sl_reply_error();
  157. break;
  158. };
  159. if (@to.tag=="") {
  160. # only for new subscriptions (with empty to tag)
  161. if (lookup_user("To")) {
  162. # existing user -> it is subscription to PA
  163. if (handle_subscription("registrar")) {
  164. if ((@msg.event=~"presence\.winfo")) {
  165. # new watcher info subscription
  166. # sends one watcher info NOTIFY message with all saved authorization requests
  167. xlog("L_ERR", "dumping stored winfo to %fu\n");
  168. dump_stored_winfo("registrar", "presence");
  169. }
  170. else {
  171. # new presence subscription
  172. if ((@msg.event=~"presence") && (%subscription_status=="pending")) {
  173. # if offline user and new pending subscription
  174. if (!target_online("registrar")) {
  175. #%subscription_status="waiting"; # store it as waiting subscription
  176. xlog("L_ERR", "storing 'pending' winfo to: %tu, from: %fu\n");
  177. store_winfo("registrar");
  178. }
  179. }
  180. }
  181. }
  182. break;
  183. }
  184. if ((@msg.supported=~"eventlist")) {
  185. # such user doesn't exist and Supported header field
  186. # -> probably RLS subscription
  187. if (lookup_domain("From")) {
  188. if (lookup_user("From")) {
  189. if (is_simple_rls_target("$uid-list")) {
  190. # log(1, "it is simple subscription!\n");
  191. # takes From UID and makes XCAP query for user's
  192. # list named "default"
  193. if (!query_resource_list("default")) {
  194. t_reply("404", "No such user list");
  195. break;
  196. }
  197. }
  198. }
  199. }
  200. if (!have_flat_list()) {
  201. # query_resource_list failed or was not called
  202. # do standard RLS query acording to To/AOR
  203. if (!query_rls_services()) {
  204. log(1, "XCAP query failed\n");
  205. t_reply("404", "No such list URI");
  206. break;
  207. }
  208. }
  209. # uncomment this if you want to authenticate first SUBSCRIBE request to resource list
  210. # if (!proxy_authenticate("test-domain.com", "credentials")) {
  211. # proxy_challenge( "test-domain.com", "0");
  212. # break;
  213. # };
  214. handle_rls_subscription("1");
  215. }
  216. else {
  217. # not resource list subscription -> invalid user
  218. xlog("L_ERR", "subscription to invalid user %tu\n");
  219. t_reply("404", "User not found");
  220. }
  221. break;
  222. }
  223. else {
  224. # renewal subscriptions - try to handle it as RLS and if failed, handle it as PA subscription
  225. # FIXME: better will be test like existing_rls_subscription()
  226. # and existing_subscription("registrar")
  227. if (!handle_rls_subscription("0")) {
  228. handle_subscription("registrar");
  229. }
  230. break;
  231. }
  232. };
  233. # get user (common for all other messages than SUBSCRIBE)
  234. if (!lookup_user("To")) {
  235. # log(1, "Unknown user - message should be forwarded?");
  236. # # break;
  237. append_hf("P-hint: unknown user\r\n");
  238. route(1);
  239. break;
  240. }
  241. if (method=="PUBLISH") {
  242. if (!t_newtran()) {
  243. # log(1, "newtran error\n");
  244. sl_reply_error();
  245. break;
  246. };
  247. handle_publish("registrar");
  248. # deliver messages to online user
  249. # TODO: only if user goes from offline to online?
  250. if (target_online("registrar")) {
  251. # log(1, "Dumping stored messages\n");
  252. # dump stored messages - route it through myself (otherwise routed via DNS!)
  253. if (m_dump("sip:127.0.0.1")) {
  254. xlog("L_ERR", "MSILO: offline messages for %fu dumped\n");
  255. }
  256. }
  257. break;
  258. };
  259. if (method=="NOTIFY") {
  260. if (!t_newtran()) {
  261. log(1, "newtran error\n");
  262. sl_reply_error();
  263. break;
  264. };
  265. # handle notification sent in internal subscriptions (presence_b2b)
  266. if (!handle_notify()) {
  267. t_reply("481", "Unable to handle notification");
  268. }
  269. break;
  270. };
  271. if (method=="MESSAGE") {
  272. if (authorize_message("http://localhost/xcap")) {
  273. # use usrloc for delivery
  274. if (lookup("location")) {
  275. log(1, "Delivering MESSAGE using usrloc\n");
  276. t_on_failure("1");
  277. if (!t_relay()) {
  278. sl_reply_error();
  279. }
  280. break;
  281. }
  282. else {
  283. # store messages for offline user
  284. xlog("L_ERR", "MSILO: storing MESSAGE for %tu\n");
  285. if (!t_newtran()) {
  286. log(1, "newtran error\n");
  287. sl_reply_error();
  288. break;
  289. };
  290. # store only text messages NOT isComposing... !
  291. if (search("^(Content-Type|c):.*application/im-iscomposing\+xml.*")) {
  292. log(1, "it is only isComposing message - ignored\n");
  293. t_reply("202", "Ignored");
  294. break;
  295. }
  296. if (m_store("0", "sip:127.0.0.1")) {
  297. # log(1, "MSILO: offline message stored\n");
  298. if (!t_reply("202", "Accepted")) {
  299. sl_reply_error();
  300. };
  301. } else {
  302. log(1, "MSILO: error storing offline message\n");
  303. if (!t_reply("503", "Service Unavailable")) {
  304. sl_reply_error();
  305. };
  306. };
  307. break;
  308. }
  309. break;
  310. }
  311. else {
  312. # log(1, "unauthorized message\n");
  313. sl_reply("403", "Forbidden");
  314. }
  315. break;
  316. }
  317. if (method=="REGISTER") {
  318. # uncomment this if you want to authenticate REGISTER request
  319. # if (!www_authenticate("test-domain.com", "credentials")) {
  320. # www_challenge( "test-domain.com", "0");
  321. # break;
  322. # };
  323. save("location");
  324. # dump stored messages - route it through myself (otherwise routed via DNS!)
  325. if (m_dump("sip:127.0.0.1")) {
  326. xlog("L_ERR", "MSILO: offline messages for %fu dumped\n");
  327. }
  328. break;
  329. };
  330. # native SIP destinations are handled using our USRLOC DB
  331. if (!lookup("location")) {
  332. sl_send_reply("404", "Not Found");
  333. break;
  334. };
  335. };
  336. # append_hf("P-hint: usrloc applied\r\n");
  337. route(1);
  338. }
  339. route[1]
  340. {
  341. # send it out now; use stateful forwarding as it works reliably
  342. # even for UDP2TCP
  343. if (!t_relay()) {
  344. sl_reply_error();
  345. };
  346. }
  347. failure_route[1] {
  348. # forwarding failed -- check if the request was a MESSAGE
  349. if (!method=="MESSAGE") { break; };
  350. log(1, "MSILO: MESSAGE forward failed - storing it\n");
  351. # we have changed the R-URI with the contact address, ignore it now
  352. if (m_store("0", "")) {
  353. t_reply("202", "Accepted");
  354. } else {
  355. log(1, "MSILO: offline message NOT stored\n");
  356. t_reply("503", "Service Unavailable");
  357. };
  358. }