1 /*
2  * Copyright (C) 2002-2003 Fhg Fokus
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version. This program is released under
10  * the GPL with the additional exemption that compiling, linking,
11  * and/or using OpenSSL is allowed.
12  *
13  * For a license to use the SEMS software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * SEMS is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27 /** @file AmConfig.h */
28 #ifndef _AmConfig_h_
29 #define _AmConfig_h_
30 
31 #include "AmSdp.h"
32 #include "AmDtmfDetector.h"
33 #include "AmSipDialog.h"
34 #include "AmUtils.h"
35 #include "AmAudio.h"
36 
37 #include <string>
38 using std::string;
39 #include <map>
40 using std::map;
41 using std::multimap;
42 #include <utility>
43 
44 /**
45  * \brief holds the current configuration.
46  *
47  * This Structure holds the current configuration.
48  */
49 struct AmConfig
50 {
51   /** Name of the main configuration file. */
52   static string ConfigurationFile;
53   /** Path to the plug-in configuration files. */
54   static string ModConfigPath;
55   /** Path where the plug-ins are. */
56   static string PlugInPath;
57   /** semicolon separated list of plugins to load */
58   static string LoadPlugins;
59   /** semicolon separated list of plugins to exclude from loading */
60   static string ExcludePlugins;
61   /** semicolon separated list of payloads to exclude from loading */
62   static string ExcludePayloads;
63   //static unsigned int MaxRecordTime;
64   /** log level */
65   static int LogLevel;
66   /** log to stderr */
67   static bool LogStderr;
68 
69 #ifndef DISABLE_DAEMON_MODE
70   /** run the program in daemon mode? */
71   static bool DaemonMode;
72   /** PID file when in daemon mode */
73   static string DaemonPidFile;
74   /** set UID when in daemon mode */
75   static string DaemonUid;
76   /** set GID when in daemon mode */
77   static string DaemonGid;
78 #endif
79 
80   static unsigned int MaxShutdownTime;
81 
82   static unsigned int RtpMuxPort;
83   static string RtpMuxIP;
84   static string RtpMuxOutInterface;
85   static unsigned int RtpMuxMTUThreshold;
86   static unsigned int RtpMuxMaxFrameAgeMs;
87 
88   struct IP_interface {
89 
90     string name;
91 
92     /** Used for binding socket */
93     string       LocalIP;
94 
95     /** Used in Contact-HF */
96     string PublicIP;
97 
98     /** Network interface name and index */
99     string       NetIf;
100     unsigned int NetIfIdx;
101 
102     IP_interface();
103 
getIPAmConfig::IP_interface104     string getIP() {
105       return PublicIP.empty() ?	LocalIP : PublicIP;
106     }
107   };
108 
109   struct SIP_interface : public IP_interface {
110 
111     /** Used for binding SIP socket */
112     unsigned int LocalPort;
113 
114     /** options for the signaling socket
115      * (@see trsp_socket::socket_options)
116      */
117     unsigned int SigSockOpts;
118 
119     unsigned int tcp_connect_timeout;
120     unsigned int tcp_idle_timeout;
121 
122     /** RTP interface index */
123     int RtpInterface;
124 
125     SIP_interface();
126   };
127 
128   struct RTP_interface : public IP_interface {
129 
130     /** Lowest local RTP port */
131     int RtpLowPort;
132     /** Highest local RTP port */
133     int RtpHighPort;
134 
135     RTP_interface();
136 
137     int getNextRtpPort();
138 
139   private:
140     int next_rtp_port;
141     AmMutex next_rtp_port_mut;
142   };
143 
144   static vector<SIP_interface>      SIP_Ifs;
145   static vector<RTP_interface>      RTP_Ifs;
146   static map<string,unsigned short> SIP_If_names;
147   static map<string,unsigned short> RTP_If_names;
148   static map<string,unsigned short> LocalSIPIP2If;
149 
150   struct IPAddr {
151     string addr;
152     short  family;
153 
IPAddrAmConfig::IPAddr154     IPAddr(const string& addr, const short family)
155       : addr(addr), family(family) {}
156 
IPAddrAmConfig::IPAddr157     IPAddr(const IPAddr& ip)
158       : addr(ip.addr), family(ip.family) {}
159   };
160 
161   struct SysIntf {
162     string       name;
163     list<IPAddr> addrs;
164     // identical to those returned by SIOCGIFFLAGS
165     unsigned int flags;
166     unsigned int mtu;
167   };
168 
169   static vector<SysIntf> SysIfs;
170 
171   static int insert_SIP_interface(const SIP_interface& intf);
172   static int insert_SIP_interface_mapping(const SIP_interface& intf);
173   static int insert_RTP_interface(const RTP_interface& intf);
174   static int finalizeIPConfig();
175 
176   static void dump_Ifs();
177 
178   /** number of session (signaling/application) processor threads */
179   static int SessionProcessorThreads;
180   /** number of media processor threads */
181   static int MediaProcessorThreads;
182   /** number of RTP receiver threads */
183   static int RTPReceiverThreads;
184   /** number of SIP server threads */
185   static int SIPServerThreads;
186   /** Outbound Proxy (optional, outgoing calls only) */
187   static string OutboundProxy;
188   /** force Outbound Proxy to be used for in dialog requests */
189   static bool ForceOutboundProxy;
190   /** force next hop IP[:port] */
191   static string NextHop;
192   /** use next hop only on 1st request within a dialog */
193   static bool NextHop1stReq;
194   /** update ruri-host to previously resolved IP:port on SIP auth */
195   static bool ProxyStickyAuth;
196   /** force the outbound network interface / short-circuit the routing table */
197   static bool ForceOutboundIf;
198   /** force comedia style remote address learning */
199   static bool ForceSymmetricRtp;
200   /** turn on SIP NAT handling (remote signaling address learning) */
201   static bool SipNATHandling;
202   /** use raw socket to send UDP packets (root permission required) */
203   static bool UseRawSockets;
204   /** Ignore Low CSeq on NOTIFY  - for RFC 3265 instead of 5057 */
205   static bool IgnoreNotifyLowerCSeq;
206   /** Server/User-Agent header (optional) */
207   static string Signature;
208   /** Value of Max-Forward header field for new requests */
209   static unsigned int MaxForwards;
210   /** If 200 OK reply should be limited to preferred codec only */
211   static bool SingleCodecInOK;
212   static vector <string> CodecOrder;
213 
214   enum ApplicationSelector {
215     App_RURIUSER,
216     App_RURIPARAM,
217     App_APPHDR,
218     App_MAPPING,
219     App_SPECIFIED
220   };
221 
222   /** "application" config value */
223   static string Application;
224   /** type of application selection (parsed from Application) */
225   static ApplicationSelector AppSelect;
226 
227   /* this is regex->application mapping is used if  App_MAPPING */
228   static RegexMappingVector AppMapping;
229 
230 #ifdef WITH_ZRTP
231   static bool enable_zrtp;
232   static bool enable_zrtp_debuglog;
233 #endif
234 
235   static unsigned int SessionLimit;
236   static unsigned int SessionLimitErrCode;
237   static string SessionLimitErrReason;
238 
239   static unsigned int OptionsSessionLimit;
240   static unsigned int OptionsSessionLimitErrCode;
241   static string OptionsSessionLimitErrReason;
242 
243   static unsigned int CPSLimitErrCode;
244   static string CPSLimitErrReason;
245 
246   static bool AcceptForkedDialogs;
247 
248   static bool ShutdownMode;
249   static unsigned int ShutdownModeErrCode;
250   static string ShutdownModeErrReason;
251 
252   /** header containing the transcoder's outgoing codec statistics which should
253    * be present in replies to OPTIONS requests */
254   static string OptionsTranscoderOutStatsHdr;
255   /** header containing the transcoder's incoming codec statistics which should
256    * be present in replies to OPTIONS requests */
257   static string OptionsTranscoderInStatsHdr;
258   /** header containing the transcoder's outgoing codec statistics which should
259    * be present in every message leaving server */
260   static string TranscoderOutStatsHdr;
261   /** header containing the transcoder's incoming codec statistics which should
262    * be present in every message leaving server */
263   static string TranscoderInStatsHdr;
264 
265   static bool DumpConferenceStreams;
266   static string DumpConferencePath;
267 
268   static Am100rel::State rel100;
269 
270   /** Time of no RTP after which Session is regarded as dead, 0 for no Timeout */
271   static unsigned int DeadRtpTime;
272 
273   /** Ignore RTP Extension headers? */
274   static bool IgnoreRTPXHdrs;
275 
276   static Dtmf::InbandDetectorType DefaultDTMFDetector;
277 
278   static bool IgnoreSIGCHLD;
279 
280   static bool IgnoreSIGPIPE;
281 
282   static bool LogSessions;
283 
284   static bool LogEvents;
285 
286   static int UnhandledReplyLoglevel;
287 
288   static AmAudio::ResamplingImplementationType ResamplingImplementationType;
289 
290   /** Read global configuration file and insert values. Maybe overwritten by
291    * command line arguments */
292   static int readConfiguration();
293 
294   /* following setters are used to fill config from config file */
295 
296   /** Setter for SIP Port, returns 0 on invalid value */
297   static int setSIPPort(const string& port);
298   /** Setter for SmtpServer Port, returns 0 on invalid value */
299   static int setSmtpPort(const string& port);
300   /** Setter for RtpLowPort, returns 0 on invalid value */
301   static int setRtpLowPort(const string& port);
302   /** Setter for RtpHighPort, returns 0 on invalid value */
303   static int setRtpHighPort(const string& port);
304   /** Setter for Loglevel, returns 0 on invalid value */
305   static int setLogLevel(const string& level, bool apply=true);
306   /** Setter for parameter stderr, returns 0 on invalid value */
307   static int setLogStderr(const string& s, bool apply=true);
308 
309 #ifndef DISABLE_DAEMON_MODE
310   /** Setter for parameter DaemonMode, returns 0 on invalid value */
311   static int setDaemonMode(const string& fork);
312 #endif
313 
314   /** Setter for parameter SessionProcessorThreads, returns 0 on invalid value */
315   static int setSessionProcessorThreads(const string& th);
316   /** Setter for parameter MediaProcessorThreads, returns 0 on invalid value */
317   static int setMediaProcessorThreads(const string& th);
318   /** Setter for parameter RTPReceiverThreads, returns 0 on invalid value */
319   static int setRTPReceiverThreads(const string& th);
320   /** Setter for parameter SIPServerThreads, returns 0 on invalid value */
321   static int setSIPServerThreads(const string& th);
322   /** Setter for parameter DeadRtpTime, returns 0 on invalid value */
323   static int setDeadRtpTime(const string& drt);
324 
325 };
326 
327 /** Get the PF_INET address associated with the network interface */
328 string fixIface2IP(const string& dev_name, bool v6_for_sip = false);
329 
330 #endif
331 
332 // Local Variables:
333 // mode:C++
334 // End:
335