/[resiprocate]/main/resip/dum/test/CommandLineParser.cxx
ViewVC logotype

Annotation of /main/resip/dum/test/CommandLineParser.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9807 - (hide annotations) (download)
Thu Aug 2 16:36:30 2012 UTC (7 years, 4 months ago) by sgodin
File MIME type: text/plain
File size: 8018 byte(s)
-added missing Config.h include - was not building properly with popt enabled
1 sgodin 9807 #if defined(HAVE_CONFIG_H)
2     #include "config.h"
3     #endif
4    
5 sgodin 8547 #if defined (HAVE_POPT_H)
6 jason 4076 #include <popt.h>
7 sgodin 8547 #endif
8 jason 4076
9     #include "CommandLineParser.hxx"
10 jason 5276 #include "rutil/Logger.hxx"
11     #include "rutil/DnsUtil.hxx"
12 bcampen 7268 #include "rutil/ParseException.hxx"
13 jason 4076
14     using namespace resip;
15     using namespace std;
16    
17     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
18    
19     CommandLineParser::CommandLineParser(int argc, char** argv)
20     {
21 adam 8430 const char* logType = "cout";
22     const char* logLevel = "INFO";
23 jason 4076 int encrypt=false;
24     int sign=false;
25     int genUserCert = false;
26     char* tlsDomain = 0;
27    
28 jason 4383 int udpPort = 5160;
29     int tcpPort = 5160;
30     int tlsPort = 5161;
31     int dtlsPort = 5161;
32 jason 4076
33     mRegisterDuration = 3600;
34     int noV4 = false;
35     int noV6 = false;
36    
37     char* inputAor = 0;
38 adam 8430 const char* password = "";
39 jason 4076
40     char* inputOutboundProxy = 0;
41     char* inputContact = 0;
42     char* inputBuddies = 0;
43     char* inputTarget = 0;
44     char* passPhrase = 0;
45 jason 4383 char* certPath = 0;
46     Data basePath(getenv("HOME"));
47 jason 4076
48 sgodin 8547 #if defined(HAVE_POPT_H)
49 jason 4076 struct poptOption table[] = {
50     {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
51     {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
52     {"encrypt", 'e', POPT_ARG_NONE, &encrypt, 0, "whether to encrypt or not", 0},
53     {"sign", 's', POPT_ARG_NONE, &sign, 0, "signs messages you send", 0},
54     {"gen-user-cert",'u', POPT_ARG_NONE, &genUserCert, 0, "generate a new user certificate", 0},
55     {"tls-domain", 't', POPT_ARG_STRING, &tlsDomain, 0, "act as a TLS server for specified domain", "example.com"},
56    
57     {"udp", 0, POPT_ARG_INT, &udpPort, 0, "add UDP transport on specified port", "5060"},
58     {"tcp", 0, POPT_ARG_INT, &tcpPort, 0, "add TCP transport on specified port", "5060"},
59     {"tls", 0, POPT_ARG_INT, &tlsPort, 0, "add TLS transport on specified port", "5061"},
60     {"dtls", 0, POPT_ARG_INT, &dtlsPort, 0, "add DTLS transport on specified port", "5061"},
61    
62     {"register-duration", 0, POPT_ARG_INT, &mRegisterDuration, 0, "expires for register (0 for no reg)", "3600"},
63     {"disable-v6", 0, POPT_ARG_NONE, &noV6, 0, "disable IPV6", 0},
64     {"disable-v4", 0, POPT_ARG_NONE, &noV4, 0, "disable IPV4", 0},
65     // may want to be able to specify that PUBLISH will occur
66    
67     {"aor", 'a', POPT_ARG_STRING, &inputAor, 0, "specify address of record", "sip:alice@example.com"},
68     {"password", 'p', POPT_ARG_STRING, &password, 0, "specify password for address of record", "password"},
69     {"outbound-proxy",'o', POPT_ARG_STRING, &inputOutboundProxy, 0, "specify uri for outbound proxy (if none present, don't use)", "sip:outbound.example.com"},
70     {"contact", 'c', POPT_ARG_STRING, &inputContact, 0, "override default contact", "sip:alice@contact.example.com"},
71     {"to", 't', POPT_ARG_STRING, &inputTarget, 0, "specify target aor", "sip:jane@example.com"},
72     {"buddies", 'b', POPT_ARG_STRING, &inputBuddies, 0, "list of buddy aors", "sip:b1@example.com,sip:b2@example.com"},
73    
74     {"pass-phrase", 'k', POPT_ARG_STRING, &passPhrase, 0, "pass phrase for private key", 0},
75     {"cert-path", 0, POPT_ARG_STRING, &certPath, 0, "path for certificates (default ~/.sipCerts)", 0},
76    
77     POPT_AUTOHELP
78     { NULL, 0, 0, NULL, 0 }
79     };
80    
81     poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
82     poptGetNextOpt(context);
83 sgodin 8547 #endif
84 jason 4076
85     mLogType = logType;
86     mLogLevel = logLevel;
87     mEncrypt = encrypt;
88     mSign = sign;
89     mGenUserCert = genUserCert;
90     if (tlsDomain) mTlsDomain = tlsDomain;
91     mUdpPort = udpPort;
92     mTcpPort = tcpPort;
93     mTlsPort = tlsPort;
94     mDtlsPort = dtlsPort;
95     mNoV4 = noV4;
96     mNoV6 = noV6;
97     if (inputAor)
98     {
99     mAor = toUri(inputAor, "aor");
100     }
101     else
102     {
103 jason 4383 mAor.user() = "test";
104 jason 4076 mAor.host() = DnsUtil::getLocalHostName();
105     }
106    
107     mPassword = password;
108     mOutboundProxy = toUri(inputOutboundProxy, "outbound proxy");
109     mContact = toUri(inputContact, "contact");
110     mBuddies = toUriVector(inputBuddies, "buddies"); // was addList
111     mTarget = toUri(inputTarget, "target"); // was dest
112     if (passPhrase) mPassPhrase = passPhrase;
113 jason 4383 if (certPath) mCertPath = certPath;
114     else mCertPath = basePath + "/.sipCerts";
115 jason 4076
116     // pubList for publish targets
117 dworley 5971
118     // Free the option parsing context.
119 sgodin 8547 #if defined(HAVE_POPT_H)
120 dworley 5971 poptFreeContext(context);
121 sgodin 8547 #endif
122 jason 4076 }
123    
124     resip::Uri
125     CommandLineParser::toUri(const char* input, const char* description)
126     {
127     resip::Uri uri;
128     try
129     {
130     if (input)
131     {
132     uri = Uri(input);
133     }
134     else
135     {
136 jason 6091 //WarningLog (<< "No " << description << " specified");
137 jason 4076 }
138     }
139     catch (ParseException& e)
140     {
141     InfoLog (<< "Caught: " << e);
142     WarningLog (<< "Can't parse " << description << " : " << input);
143     exit(-1);
144     }
145     return uri;
146     }
147    
148     std::vector<resip::Uri>
149     CommandLineParser::toUriVector(const char* input, const char* description)
150     {
151     std::vector<Uri> uris;
152     if (input)
153     {
154 jason 4383 char buffer[2048];
155     strcpy(buffer, input);
156    
157 jason 4076 for (char* token = strtok(buffer, ","); token != 0; token = strtok(0, ","))
158     {
159     try
160     {
161     uris.push_back(Uri(token));
162     }
163     catch (ParseException& e)
164     {
165     InfoLog (<< "Caught: " << e);
166     WarningLog (<< "Can't parse " << description << " : " << token);
167     exit(-1);
168     }
169     }
170     }
171     return uris;
172     }
173    
174 derek 4602
175     /* ====================================================================
176     * The Vovida Software License, Version 1.0
177     *
178     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
179     *
180     * Redistribution and use in source and binary forms, with or without
181     * modification, are permitted provided that the following conditions
182     * are met:
183     *
184     * 1. Redistributions of source code must retain the above copyright
185     * notice, this list of conditions and the following disclaimer.
186     *
187     * 2. Redistributions in binary form must reproduce the above copyright
188     * notice, this list of conditions and the following disclaimer in
189     * the documentation and/or other materials provided with the
190     * distribution.
191     *
192     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
193     * and "Vovida Open Communication Application Library (VOCAL)" must
194     * not be used to endorse or promote products derived from this
195     * software without prior written permission. For written
196     * permission, please contact vocal@vovida.org.
197     *
198     * 4. Products derived from this software may not be called "VOCAL", nor
199     * may "VOCAL" appear in their name, without prior written
200     * permission of Vovida Networks, Inc.
201     *
202     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
203     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
204     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
205     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
206     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
207     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
208     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
209     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
210     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
211     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
212     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
213     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
214     * DAMAGE.
215     *
216     * ====================================================================
217     *
218     * This software consists of voluntary contributions made by Vovida
219     * Networks, Inc. and many individuals on behalf of Vovida Networks,
220     * Inc. For more information on Vovida Networks, Inc., please see
221     * <http://www.vovida.org/>.
222     *
223     */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27