client examples fixed
[anytun.git] / plain_tool / options.cpp
blobf8dc187b780466ffa75da397ae5290c66bc43c92
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_SEC(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 for(size_t j=0; j < strlen(argv[i+1]); ++j) \
102 argv[i+1][j] = '#'; \
103 argc--; \
104 i++; \
107 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
108 else if(str == SHORT || str == LONG) \
110 if(argc < 1 || argv[i+1][0] == '-') \
111 return false; \
112 std::stringstream tmp(argv[i+1]); \
113 while (tmp.good()) \
115 std::string tmp_line; \
116 getline(tmp,tmp_line,','); \
117 LIST.push(tmp_line); \
119 argc--; \
120 i++; \
123 bool Options::parse(int argc, char* argv[])
125 Lock lock(mutex);
127 progname_ = argv[0];
128 argc--;
129 for(int i=1; argc > 0; ++i)
131 std::string str(argv[i]);
132 argc--;
134 if(str == "-h" || str == "--help")
135 return false;
136 else
137 return false;
139 return true;
142 void Options::printUsage()
144 std::cout << "USAGE:" << std::endl;
145 std::cout << "anyrtpproxy [-h|--help] prints this..." << std::endl;
146 // std::cout << " [-K|--key] <master key> master key to use for encryption" << std::endl;
149 void Options::printOptions()
151 Lock lock(mutex);
152 std::cout << "Options:" << std::endl;
155 std::string Options::getProgname()
157 Lock lock(mutex);
158 return progname_;
162 Options& Options::setProgname(std::string p)
164 Lock lock(mutex);
165 progname_ = p;
166 return *this;