Imported Upstream version 0.3.2
[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 {
42   std::string host;
43   std::string port;
44 };
45
46 typedef std::list<OptionConnectTo>  ConnectToList;
47
48 class Host
49 {
50 public:
51   Host(std::string addr, std::string port) : addr_(addr), port_(port) {}
52   Host(std::string addr_port) {
53     splitAndSetAddrPort(addr_port);
54   } 
55   std::string toString() const
56   {
57     std::ostringstream oss;
58     oss << addr_ << ":" << port_;
59     return oss.str();
60   }
61   
62   std::string addr_;
63         std::string port_;
64
65 protected:
66   void splitAndSetAddrPort(std::string addr_port);
67 };
68
69 typedef std::list<Host> HostList;
70
71 class Options
72 {
73 public:
74   static Options& instance();
75
76   bool parse(int argc, char* argv[]);
77   void printUsage();
78   void printOptions();
79
80   std::string getProgname();
81   bool getChroot();
82   bool getNat();
83   bool getNoNatOnce();
84   std::string getUsername();
85   std::string getChrootDir();
86   std::string getPidFile();
87   bool getDaemonize();
88   Host getControlInterface();
89   std::string getLocalAddr();
90   Options& setLocalAddr(std::string l);
91   std::string getLocalSyncAddr();
92         Options& setLocalSyncAddr(std::string l);
93   std::string getLocalSyncPort();
94         Options& setLocalSyncPort(std::string l);
95   u_int16_t getRtpStartPort();
96         Options& setRtpStartPort(u_int16_t l);
97   u_int16_t getRtpEndPort();
98         Options& setRtpEndPort(u_int16_t l);
99   ConnectToList getConnectTo();
100
101 private:
102   Options();
103   ~Options();
104   Options(const Options &l);
105   void operator=(const Options &l);
106   bool sanityCheck();
107
108   static Options* inst;
109   static ::Mutex instMutex;
110   class instanceCleaner {
111     public: ~instanceCleaner() {
112       if(Options::inst != 0)
113         delete Options::inst;
114     }
115   };
116   friend class instanceCleaner;
117
118   ::Mutex mutex;
119
120   std::string progname_;
121   bool chroot_;
122   bool nat_;
123   bool no_nat_once_;
124   std::string username_;
125   std::string chroot_dir_;
126   std::string pid_file_;
127   bool daemonize_;
128         std::string local_sync_addr_;
129         std::string local_sync_port_;
130   std::string local_addr_;
131         u_int16_t rtp_start_port_;
132         u_int16_t rtp_end_port_;
133         ConnectToList connect_to_;
134   Host control_interface_;
135 };
136
137 extern Options& gOpt;
138
139 #endif