1 /*******************************************************************************
2 
3     KHOMP generic endpoint/channel library.
4     Copyright (C) 2007-2010 Khomp Ind. & Com.
5 
6   The contents of this file are subject to the Mozilla Public License
7   Version 1.1 (the "License"); you may not use this file except in compliance
8   with the License. You may obtain a copy of the License at
9   http://www.mozilla.org/MPL/
10 
11   Software distributed under the License is distributed on an "AS IS" basis,
12   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13   the specific language governing rights and limitations under the License.
14 
15   Alternatively, the contents of this file may be used under the terms of the
16   "GNU Lesser General Public License 2.1" license (the “LGPL" License), in which
17   case the provisions of "LGPL License" are applicable instead of those above.
18 
19   If you wish to allow use of your version of this file only under the terms of
20   the LGPL License and not to allow others to use your version of this file
21   under the MPL, indicate your decision by deleting the provisions above and
22   replace them with the notice and other provisions required by the LGPL
23   License. If you do not delete the provisions above, a recipient may use your
24   version of this file under either the MPL or the LGPL License.
25 
26   The LGPL header follows below:
27 
28     This library is free software; you can redistribute it and/or
29     modify it under the terms of the GNU Lesser General Public
30     License as published by the Free Software Foundation; either
31     version 2.1 of the License, or (at your option) any later version.
32 
33     This library is distributed in the hope that it will be useful,
34     but WITHOUT ANY WARRANTY; without even the implied warranty of
35     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36     Lesser General Public License for more details.
37 
38     You should have received a copy of the GNU Lesser General Public License
39     along with this library; if not, write to the Free Software Foundation,
40     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
41 
42 *******************************************************************************/
43 
44 #ifndef _OPT_H_
45 #define _OPT_H_
46 
47 #include <string>
48 #include <map>
49 #include <vector>
50 
51 #include <config_options.hpp>
52 
53 #include "switch.h"
54 #include "utils.h"
55 
56 typedef std::map    < std::string, std::string >       OrigToDestMapType;
57 typedef std::pair   < std::string, std::string >      OrigToDestPairType;
58 typedef std::vector < std::string >                       DestVectorType;
59 
60 typedef std::map    < unsigned int, std::string >     BoardToOrigMapType;
61 typedef std::pair   < unsigned int, std::string >    BoardToOrigPairType;
62 
63 typedef std::map    < std::string, unsigned int >      OrigToNseqMapType;
64 typedef std::pair   < std::string, unsigned int >     OrigToNseqPairType;
65 
66 typedef std::pair   < unsigned int,unsigned int >           ObjectIdType;
67 typedef std::pair   < std::string, ObjectIdType > BranchToObjectPairType;
68 typedef std::map    < std::string, ObjectIdType >  BranchToObjectMapType;
69 
70 typedef std::map    < std::string, std::string >      BranchToOptMapType;
71 typedef std::pair   < std::string, std::string >     BranchToOptPairType;
72 
73 typedef std::map    < std::string, std::string >      GroupToDestMapType;
74 typedef std::pair   < std::string, std::string >     GroupToDestPairType;
75 
76 struct CadenceType
77 {
CadenceTypeCadenceType78     CadenceType(void)
79     : ring(0), ring_s(0), ring_ext(0), ring_ext_s(0) {};
80 
CadenceTypeCadenceType81     CadenceType(unsigned int _ring, unsigned int _ring_s)
82     : ring(_ring), ring_s(_ring_s), ring_ext(0), ring_ext_s(0) {};
83 
CadenceTypeCadenceType84     CadenceType(unsigned int _ring, unsigned int _ring_s, unsigned int _ring_ext, unsigned int _ring_ext_s)
85     : ring(_ring), ring_s(_ring_s), ring_ext(_ring_ext), ring_ext_s(_ring_ext_s) {};
86 
87     unsigned int ring;
88     unsigned int ring_s;
89     unsigned int ring_ext;
90     unsigned int ring_ext_s;
91 };
92 
93 typedef std::pair < std::string, CadenceType > CadencesPairType;
94 typedef std::map  < std::string, CadenceType >  CadencesMapType;
95 
96 struct Options
97 {
98     Config::Value< bool >        _debug;
99     Config::Value< std::string > _dialplan;
100     Config::Value< std::string > _context;
101 
102     Config::Value< bool > _echo_canceller;
103     Config::Value< bool > _auto_gain_control;
104     Config::Value< bool > _out_of_band_dtmfs;
105     Config::Value< bool > _suppression_delay;
106     Config::Value< bool > _pulse_forwarding;
107     Config::Value< bool > _native_bridge;
108     Config::Value< bool > _recording;
109     Config::Value< bool > _has_ctbus;
110     Config::Value< bool > _fxs_bina;
111     Config::Value< bool > _fxs_sharp_dial;
112     Config::Value< bool > _drop_collect_call;
113     Config::Value< bool > _ignore_letter_dtmfs;
114     Config::Value< bool > _optimize_audio_path;
115 
116     Config::Value< bool > _fxo_send_pre_audio;
117     Config::Value< unsigned int > _fxo_busy_disconnection;
118 
119     Config::Value< bool         > _auto_fax_adjustment;
120     Config::Value< unsigned int > _fax_adjustment_timeout;
121 
122     Config::Value< bool         > _r2_strict_behaviour;
123     Config::Value< unsigned int > _r2_preconnect_wait;
124 
125     Config::Value< unsigned int > _fxs_digit_timeout;
126     Config::Value< unsigned int > _transferdigittimeout;
127 
128     Config::Value< std::string > _flash;
129     Config::Value< std::string > _blindxfer;
130     Config::Value< std::string > _atxfer;
131 
132     Config::Value< unsigned int > _ringback_co_delay;
133     Config::Value< unsigned int > _ringback_pbx_delay;
134 
135     Config::Value< unsigned int > _disconnect_delay;
136 
137     Config::Value< int > _input_volume;
138     Config::Value< int > _output_volume;
139 
140     struct CentralOfficeDialtone : public Config::FunctionValue
141     {
142         void operator ()(const Config::StringType &);
operatorOptions::CentralOfficeDialtone143         const DestVectorType & operator()(void) const { return _value; };
clearOptions::CentralOfficeDialtone144         void clear(void)
145         {
146             _value.clear();
147         }
148 
149     protected:
150         DestVectorType _value;
151     } _fxs_co_dialtone;
152 
153     struct LogDiskOption : public Config::FunctionValue
154     {
155         void operator ()(const Config::StringType &);
156     } _log_disk_option;
157 
158     /*
159     struct CallGroupOption: public Config::FunctionValue
160     {
161         void operator ()(const Config::StringType &);
162         const std::string operator()(void) const { return _groups; };
163     protected:
164         std::string _groups;
165     } _callgroup;
166 
167     struct PickupGroupOption: public Config::FunctionValue
168     {
169         void operator ()(const Config::StringType &);
170         const std::string operator()(void) const { return _groups; };
171     protected:
172         std::string _groups;
173     } _pickupgroup; // or intercept
174     */
175 
176     struct LogConsoleOption : public Config::FunctionValue
177     {
178         void operator ()(const Config::StringType &);
179     } _log_console_option;
180 
181     struct LogTraceOption : public Config::FunctionValue
182     {
183         void operator ()(const Config::StringType &);
184     } _log_trace_option;
185 
186     struct RecordPrefixOption: public Config::FunctionValue
187     {
188         void operator ()(const Config::StringType &);
operatorOptions::RecordPrefixOption189         const std::string & operator()(void) const { return _value; };
190 
191     protected:
192         std::string _value;
193     } _record_prefix;
194 
195     Config::Value< std::string > _user_xfer_digits;
196     Config::Value< std::string > _fxs_global_orig_base;
197 
198     Config::Value< std::string > _global_mohclass;
199     Config::Value< std::string > _global_language;
200 
201     Config::Value< std::string > _context_gsm_call;
202     Config::Value< std::string > _context2_gsm_call;
203     Config::Value< std::string > _context_gsm_sms;
204     Config::Value< std::string > _context_fxo;
205     Config::Value< std::string > _context2_fxo;
206     Config::Value< std::string > _context_fxs;
207     Config::Value< std::string > _context2_fxs;
208     Config::Value< std::string > _context_digital;
209     Config::Value< std::string > _context_pr;
210 
211     Config::Value< std::string > _callgroup;
212     Config::Value< std::string > _pickupgroup; /* or intercept */
213     Config::Value< std::string > _accountcode;
214 
215     Config::Value< unsigned int > _kommuter_timeout;
216     Config::Value< std::string  > _kommuter_activation;
217 
218     Config::Value< unsigned int > _audio_packet_size;
219 };
220 
221 struct Opt
222 {
223     /* here we load [cadences] */
224     static CadencesMapType        _cadences;
225 
226     /* here we load [groups] */
227     static GroupToDestMapType     _groups;
228 
229     /* here we load [fxs-hotlines] */
230     static OrigToDestMapType      _fxs_hotline;
231 
232     /* here we load [fxs-branches] */
233     static BoardToOrigMapType     _fxs_orig_base;
234 
235     /* here we load [fxs-options] */
236     static BranchToOptMapType     _branch_options;
237 
238     /* here we load ... hannnn */
239     static BranchToObjectMapType  _fxs_branch_map;
240 
241     static Options _options;
242 
243     /* Member functions */
244     static void initialize(void);
245     static void obtain(void);
246     static void commit(void);
247 
248     //TODO: reload options at reloadxml ?
249     static void reload(void);
250 
251     protected:
252     static void loadConfiguration(const char *, const char **, bool show_errors = true);
253     static void cleanConfiguration(void);
254 
255     static switch_xml_t processSimpleXML(switch_xml_t &xml, const std::string& child_name);
256     static void processGroupXML(switch_xml_t &xml);
257     static void processCadenceXML(switch_xml_t &xml);
258     static void processFXSBranchesXML(switch_xml_t &xml);
259     static void processFXSHotlines(switch_xml_t &xml);
260     static void processFXSOptions(switch_xml_t &xml);
261 };
262 
263 
264 
265 #endif /* _OPT_H_ */
266 
267