Imported Upstream version 0.3.4
[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-2009 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 as published by
21  *  the Free Software Foundation, either version 3 of the License, or
22  *  any later version.
23  *
24  *  Anytun is distributed in the hope that it will be useful,
25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *  GNU General Public License for more details.
28  *
29  *  You should have received a copy of the GNU General Public License
30  *  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
31  */
32
33 #ifndef _OPTIONS_H_
34 #define _OPTIONS_H_
35
36 #include "../threadUtils.hpp"
37 #include <list>
38 #include <sstream>
39
40 typedef struct OptionConnectTo {
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     std::ostringstream oss;
56     oss << addr_ << ":" << port_;
57     return oss.str();
58   }
59
60   std::string addr_;
61   std::string port_;
62
63 protected:
64   void splitAndSetAddrPort(std::string addr_port);
65 };
66
67 typedef std::list<Host> HostList;
68
69 class Options
70 {
71 public:
72   static Options& instance();
73
74   bool parse(int argc, char* argv[]);
75   void printUsage();
76   void printOptions();
77
78   std::string getProgname();
79   bool getChroot();
80   bool getNat();
81   bool getNoNatOnce();
82   std::string getUsername();
83   std::string getChrootDir();
84   std::string getPidFile();
85   bool getDaemonize();
86   Host getControlInterface();
87   std::string getLocalAddr();
88   Options& setLocalAddr(std::string l);
89   std::string getLocalSyncAddr();
90   Options& setLocalSyncAddr(std::string l);
91   std::string getLocalSyncPort();
92   Options& setLocalSyncPort(std::string l);
93   uint16_t getRtpStartPort();
94   Options& setRtpStartPort(uint16_t l);
95   uint16_t getRtpEndPort();
96   Options& setRtpEndPort(uint16_t l);
97   ConnectToList getConnectTo();
98
99 private:
100   Options();
101   ~Options();
102   Options(const Options& l);
103   void operator=(const Options& l);
104   bool sanityCheck();
105
106   static Options* inst;
107   static ::Mutex instMutex;
108   class instanceCleaner
109   {
110   public:
111     ~instanceCleaner() {
112       if(Options::inst != 0) {
113         delete Options::inst;
114       }
115     }
116   };
117   friend class instanceCleaner;
118
119   ::Mutex mutex;
120
121   std::string progname_;
122   bool chroot_;
123   bool nat_;
124   bool no_nat_once_;
125   std::string username_;
126   std::string chroot_dir_;
127   std::string pid_file_;
128   bool daemonize_;
129   std::string local_sync_addr_;
130   std::string local_sync_port_;
131   std::string local_addr_;
132   uint16_t rtp_start_port_;
133   uint16_t rtp_end_port_;
134   ConnectToList connect_to_;
135   Host control_interface_;
136 };
137
138 extern Options& gOpt;
139
140 #endif