Imported Upstream version 0.3
[anytun.git] / src / anyrtpproxy / options.h
1 /*
2  *  anytun
3  *
4  *  The secure anycast tunneling protocol (satp) defines a protocol used
5  *  for communication between any combination of unicast and anycast
6  *  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
7  *  mode and allows tunneling of every ETHER TYPE protocol (e.g.
8  *  ethernet, ip, arp ...). satp directly includes cryptography and
9  *  message authentication based on the methodes used by SRTP.  It is
10  *  intended to deliver a generic, scaleable and secure solution for
11  *  tunneling and relaying of packets of any protocol.
12  *
13  *
14  *  Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl, 
15  *                          Christian Pointner <satp@wirdorange.org>
16  *
17  *  This file is part of Anytun.
18  *
19  *  Anytun is free software: you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License version 3 as
21  *  published by the Free Software Foundation.
22  *
23  *  Anytun is distributed in the hope that it will be useful,
24  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *  GNU General Public License for more details.
27  *
28  *  You should have received a copy of the GNU General Public License
29  *  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 #ifndef _OPTIONS_H_
33 #define _OPTIONS_H_
34
35 #include "../threadUtils.hpp"
36 #include <list>
37 #include <sstream>
38
39 typedef struct OptionConnectTo
40 {
41   std::string host;
42   std::string port;
43 };
44
45 typedef std::list<OptionConnectTo>  ConnectToList;
46
47 class Host
48 {
49 public:
50   Host(std::string addr, std::string port) : addr_(addr), port_(port) {}
51   Host(std::string addr_port) {
52     splitAndSetAddrPort(addr_port);
53   } 
54   std::string toString() const
55   {
56     std::ostringstream oss;
57     oss << addr_ << ":" << port_;
58     return oss.str();
59   }
60   
61   std::string addr_;
62         std::string port_;
63
64 protected:
65   void splitAndSetAddrPort(std::string addr_port);
66 };
67
68 typedef std::list<Host> HostList;
69
70 class Options
71 {
72 public:
73   static Options& instance();
74
75   bool parse(int argc, char* argv[]);
76   void printUsage();
77   void printOptions();
78
79   std::string getProgname();
80   bool getChroot();
81   bool getNat();
82   bool getNoNatOnce();
83   std::string getUsername();
84   std::string getChrootDir();
85   std::string getPidFile();
86   bool getDaemonize();
87   Host getControlInterface();
88   std::string getLocalAddr();
89   Options& setLocalAddr(std::string l);
90   std::string getLocalSyncAddr();
91         Options& setLocalSyncAddr(std::string l);
92   std::string getLocalSyncPort();
93         Options& setLocalSyncPort(std::string l);
94   u_int16_t getRtpStartPort();
95         Options& setRtpStartPort(u_int16_t l);
96   u_int16_t getRtpEndPort();
97         Options& setRtpEndPort(u_int16_t l);
98   ConnectToList getConnectTo();
99
100 private:
101   Options();
102   ~Options();
103   Options(const Options &l);
104   void operator=(const Options &l);
105   bool sanityCheck();
106
107   static Options* inst;
108   static ::Mutex instMutex;
109   class instanceCleaner {
110     public: ~instanceCleaner() {
111       if(Options::inst != 0)
112         delete Options::inst;
113     }
114   };
115   friend class instanceCleaner;
116
117   ::Mutex mutex;
118
119   std::string progname_;
120   bool chroot_;
121   bool nat_;
122   bool no_nat_once_;
123   std::string username_;
124   std::string chroot_dir_;
125   std::string pid_file_;
126   bool daemonize_;
127         std::string local_sync_addr_;
128         std::string local_sync_port_;
129   std::string local_addr_;
130         u_int16_t rtp_start_port_;
131         u_int16_t rtp_end_port_;
132         ConnectToList connect_to_;
133   Host control_interface_;
134 };
135
136 extern Options& gOpt;
137
138 #endif