parser: some more const-correctness for the other functions in msg_parser.[c,h]
[sip-router] / etc / im_gw.cfg
1 ### ----- IM Gateway [SMS+Jabber] config file for 'bat.iptel.org' ----  
2
3 # ----------- global configuration parameters ------------------------
4
5 debug=9          # debug level (cmd line: -dddddddddd)
6 #fork=yes
7 #fork=no
8 #log_stderror=no     # (cmd line: -E)
9 log_stderror=yes   # (cmd line: -E)
10 check_via=yes       # (cmd. line: -v)
11 dns=on              # (cmd. line: -r)
12 rev_dns=yes         # (cmd. line: -R)
13 port=5070
14 children=2
15
16 # advertise IP address in Via (as opposed to advertising DNS name
17 # which is annoying for downstream servers and some phones can
18 # not handle DNS at all)
19 listen=195.37.77.100
20
21 # ------------------ module loading ----------------------------------
22
23 loadmodule "../sip_router/modules/sl/sl.so"
24 loadmodule "../sip_router/modules/print/print.so"
25 loadmodule "../sip_router/modules/tm/tm_mod.so"
26 loadmodule "../sip_router/modules/maxfwd/maxfwd.so"
27 loadmodule "../sip_router/modules/sms/sms.so"
28 loadmodule "../sip_router/modules/textops/textops.so"
29 loadmodule "../sip_router/modules/mysql/mysql.so"
30 loadmodule "../sip_router/modules/jabber/jabber.so"
31 loadmodule "../sip_router/modules/pike/pike.so"
32
33 # ----------------- setting module-specific parameters ---------------
34
35 # -- sms params --
36 modparam("sms","modems","Falcom [d=/dev/ttyS0;b=9600;p=9254;m=new;l=10;r=2]")
37 modparam("sms","networks","D1[c=491710765000;m=10]")
38 modparam("sms","links","Falcom[D1]")
39 modparam("sms","domain","iptel.org")
40 modparam("sms","max_sms_parts",3)
41 modparam("sms","use_contact",1)
42
43 # -- tm params --
44 modparam("tm", "fr_timer", 10 )
45 modparam("tm", "fr_inv_timer", 10 )
46 modparam("tm", "wt_timer", 10 )
47
48 # -- pike params --
49 # no more than minimum 5 or maximum 5*3 msg per 10 secs - only for sms
50 modparam("pike","sampling_time_unit",60)
51 modparam("pike","reqs_density_per_unit",5)
52 modparam("pike","removel_latency",30)
53
54 # -- jabber params --
55 modparam("jabber","db_url","mysql://s2jgw:47s2jgw11@127.0.0.1/sip_jab")
56 modparam("jabber","jaddress","bat.iptel.org")
57 modparam("jabber","jport",5222)
58 modparam("jabber","workers",2)
59 modparam("jabber","max_jobs",10)
60 modparam("jabber","delay_time",17)
61 modparam("jabber","cache_time",1800)
62
63 # -------------------------  request routing logic -------------------
64
65 # main routing logic
66
67 route{
68
69         # filter too old messages
70         log("LOG: Checking maxfwd\n");
71         if (!mf_process_maxfwd_header("10")) {
72                 log("LOG: Too many hops\n");
73                 sl_send_reply("483","Too Many Hops");
74                 break;
75         };
76
77         # messages too large are denied
78         if (len_gt( max_len )) {
79                 sl_send_reply("513", "Riesengross -- Message too large");
80                 break;
81         };
82  
83         # accept only req coming from iptel.org
84         if (!src_ip==195.37.77.101 |
85         !( uri=~"iptel.org" | uri=~"195\.37\.77\.100" ))
86         {
87                 sl_send_reply("403","Forbidden");
88                 log("SER:Forbidden request: wrong src_ip or req_uri\n");
89                 break;
90         };
91
92         # we are not interested in non-MESSAGE requests
93         if (!method=="MESSAGE")
94         {
95                 sl_send_reply("501","Not Implemented");
96                 break;
97         };
98
99         # error occured ...
100         if (! t_newtran())
101         {
102                 sl_reply_error();
103                 break;
104         };
105
106         # do what you want to do -  first, it's for SMS or JABBER ?
107         if ( search("To:.*@icq\.iptel\.org")
108                         | search("To:.*@msn\.iptel\.org")
109                         | search("To:.*@aim\.iptel\.org")
110                         | search("To:.*@yahoo\.iptel\.org") )
111         {
112                 ### ----- JABBER GATEWAY ------
113                 log("MESSAGE received -> sending as JABBER\n");
114                 if (jab_send_message())
115                 {
116                         if (!t_reply("202","Accepted"))
117                         {
118                                 # if replying failed, retry statelessly
119                                 sl_reply_error();
120                         };
121                 }else{
122                         if (!t_reply("502","Bad gateway - IM error"))
123                         {
124                                 # if replying failed, retry statelessly
125                                 sl_reply_error();
126                         };
127                 };
128                 break; # End of Jabber
129         };
130
131         ### ------ SMS GATEWAY --------
132         # let's block ips that send a lot of request!!
133         if (!pike_check_req() )
134         {
135                 break;
136         };
137         # SMS expects only the numbers as follows +<int> <area> <nr>
138         if (!(uri=~"sip:+[^0][0-9]{3}"))
139         {
140                 log("SER: invalid number format!!\n");
141                 if (!t_reply("502","Bad gateway - invalid number"))
142                 {
143                         # if replying failed, retry statelessly
144                         sl_reply_error();
145                 };
146                 break;
147         };
148         if (sms_send_msg_to_net("D1"))
149         {
150                 # for sending replies, we woun't use the statefull
151                 # function because it is not able to add the Contact
152                 # header (in fact to add any rpl_lump :-( )
153                 # things went well, send ok upstream
154                 if (!t_reply("202", "yes sir, SMS sent over"))
155                 {
156                         # if replying failed, retry statelessly
157                         sl_reply_error();
158                 };
159         } else {
160                 if (!t_reply("502", "Bad gateway - SMS error"))
161                 {
162                         # if replying failed, retry statelessly
163                         sl_reply_error();
164                 };
165                 break;
166         };
167 }