fixed issue with pid file and chrooting to early
[anytun.git] / plain_tool / options.cpp
blob1dcf8a2669e26e37215026925222fe80c4d4e377
1 /*
2 * anytun
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.
14 * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <iostream>
32 #include <queue>
33 #include <string>
34 #include <sstream>
36 #include "options.h"
38 Options* Options::inst = NULL;
39 Mutex Options::instMutex;
40 Options& gOpt = Options::instance();
42 Options& Options::instance()
44 Lock lock(instMutex);
45 static instanceCleaner c;
46 if(!inst)
47 inst = new Options();
49 return *inst;
52 Options::Options()
54 progname_ = "anyrtpproxy";
57 Options::~Options()
61 #define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \
62 else if(str == SHORT || str == LONG) \
63 VALUE = true;
65 #define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \
66 else if(str == SHORT || str == LONG) \
67 VALUE = false;
69 #define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \
70 else if(str == SHORT || str == LONG) \
71 { \
72 if(argc < 1 || argv[i+1][0] == '-') \
73 return false; \
74 std::stringstream tmp; \
75 tmp << argv[i+1]; \
76 tmp >> VALUE; \
77 argc--; \
78 i++; \
81 #define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \
82 else if(str == SHORT || str == LONG) \
83 { \
84 if(argc < 2 || \
85 argv[i+1][0] == '-' || argv[i+2][0] == '-') \
86 return false; \
87 std::stringstream tmp; \
88 tmp << argv[i+1] << " " << argv[i+2]; \
89 tmp >> VALUE1; \
90 tmp >> VALUE2; \
91 argc-=2; \
92 i+=2; \
95 #define PARSE_HEXSTRING_PARAM(SHORT, LONG, VALUE) \
96 else if(str == SHORT || str == LONG) \
97 { \
98 if(argc < 1 || argv[i+1][0] == '-') \
99 return false; \
100 VALUE = Buffer(std::string(argv[i+1])); \
101 argc--; \
102 i++; \
105 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
106 else if(str == SHORT || str == LONG) \
108 if(argc < 1 || argv[i+1][0] == '-') \
109 return false; \
110 std::stringstream tmp(argv[i+1]); \
111 while (tmp.good()) \
113 std::string tmp_line; \
114 getline(tmp,tmp_line,','); \
115 LIST.push(tmp_line); \
117 argc--; \
118 i++; \
121 bool Options::parse(int argc, char* argv[])
123 Lock lock(mutex);
125 progname_ = argv[0];
126 argc--;
127 for(int i=1; argc > 0; ++i)
129 std::string str(argv[i]);
130 argc--;
132 if(str == "-h" || str == "--help")
133 return false;
134 else
135 return false;
137 return true;
140 void Options::printUsage()
142 std::cout << "USAGE:" << std::endl;
143 std::cout << "anyrtpproxy [-h|--help] prints this..." << std::endl;
144 // std::cout << " [-K|--key] <master key> master key to use for encryption" << std::endl;
147 void Options::printOptions()
149 Lock lock(mutex);
150 std::cout << "Options:" << std::endl;
153 std::string Options::getProgname()
155 Lock lock(mutex);
156 return progname_;
160 Options& Options::setProgname(std::string p)
162 Lock lock(mutex);
163 progname_ = p;
164 return *this;