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

Contents of /main/resip/dum/test/basicClientCmdLineParser.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9493 - (show annotations) (download)
Sat Apr 7 10:56:50 2012 UTC (7 years, 2 months ago) by dpocock
File MIME type: text/plain
File size: 6860 byte(s)
Include config.h from even more places where it may be needed
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #if defined (HAVE_POPT_H)
6 #include <popt.h>
7 #endif
8
9 #include "basicClientCmdLineParser.hxx"
10 #include <rutil/Logger.hxx>
11 #include <rutil/DnsUtil.hxx>
12 #include <rutil/ParseException.hxx>
13
14 using namespace resip;
15 using namespace std;
16
17 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
18
19 BasicClientCmdLineParser::BasicClientCmdLineParser(int argc, char** argv)
20 {
21 const char* logType = "cout";
22 const char* logLevel = "INFO";
23 char* tlsDomain = 0;
24 char* certPath = 0;
25
26 int udpPort = 5160;
27 int tcpPort = 5160;
28 int tlsPort = 5161;
29 int dtlsPort = 5161;
30
31 mRegisterDuration = 3600;
32 int noV4 = false;
33 int enableV6 = false;
34 int hostFileLookupOnlyDnsMode = false;
35
36 char* inputAor = 0;
37 const char* password = "";
38
39 char* inputOutboundProxy = 0;
40 char* inputContact = 0;
41 Data basePath(getenv("HOME"));
42
43 int outboundEnabled = false;
44
45 char* subscribeTarget = 0;
46 char* callTarget = 0;
47
48 #if defined(HAVE_POPT_H)
49 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 #if defined(USE_SSL)
53 {"tls-domain", 't', POPT_ARG_STRING, &tlsDomain, 0, "act as a TLS server for specified domain", "example.com"},
54 {"cert-path", 0, POPT_ARG_STRING, &certPath, 0, "path for certificates (default ~/.sipCerts)", 0},
55 #endif
56
57 {"udp", 0, POPT_ARG_INT, &udpPort, 0, "add UDP transport on specified port", "5160"},
58 {"tcp", 0, POPT_ARG_INT, &tcpPort, 0, "add TCP transport on specified port", "5160"},
59 #if defined(USE_SSL)
60 {"tls", 0, POPT_ARG_INT, &tlsPort, 0, "add TLS transport on specified port", "5161"},
61 #endif
62 #if defined(USE_DTLS)
63 {"dtls", 0, POPT_ARG_INT, &dtlsPort, 0, "add DTLS transport on specified port", "5161"},
64 #endif
65
66 {"register-duration",'r', POPT_ARG_INT, &mRegisterDuration, 0, "expires for register (0 for no reg)", "3600"},
67 {"enable-v6", 0, POPT_ARG_NONE, &enableV6, 0, "enable IPV6", 0},
68 {"disable-v4", 0, POPT_ARG_NONE, &noV4, 0, "disable IPV4", 0},
69 {"enable-hostfileonly",0, POPT_ARG_NONE, &hostFileLookupOnlyDnsMode,0, "enable hostfile only dns lookup mode", 0},
70
71 {"aor", 'a', POPT_ARG_STRING, &inputAor, 0, "specify address of record", "sip:alice@example.com"},
72 {"password", 'p', POPT_ARG_STRING, &password, 0, "specify password for address of record", "password"},
73 {"outbound-proxy", 'o', POPT_ARG_STRING, &inputOutboundProxy, 0, "specify uri for outbound proxy (if none present, don't use)", "sip:outbound.example.com"},
74 {"contact", 'c', POPT_ARG_STRING, &inputContact, 0, "override default contact", "sip:alice@contact.example.com"},
75 {"enable-outbound", 'b', POPT_ARG_NONE, &outboundEnabled, 0, "enable RFC 5626 outbound support", 0},
76
77 {"subtarget", 0, POPT_ARG_STRING, &subscribeTarget, 0, "specify a SIP URI to subscribe to", "sip:bob@example.com"},
78 {"calltarget", 0, POPT_ARG_STRING, &callTarget, 0, "specify a SIP URI to call", "sip:carol@example.com"},
79 POPT_AUTOHELP
80 { NULL, 0, 0, NULL, 0 }
81 };
82
83 poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
84 poptGetNextOpt(context);
85 #endif
86
87 mLogType = logType;
88 mLogLevel = logLevel;
89 if (tlsDomain) mTlsDomain = tlsDomain;
90 if (certPath) mCertPath = certPath;
91 else mCertPath = basePath + "/.sipCerts";
92
93 mUdpPort = udpPort;
94 mTcpPort = tcpPort;
95 mTlsPort = tlsPort;
96 mDtlsPort = dtlsPort;
97 mNoV4 = noV4 != 0;
98 mEnableV6 = enableV6 != 0;
99 mHostFileLookupOnlyDnsMode = hostFileLookupOnlyDnsMode != 0;
100 if (inputAor)
101 {
102 mAor = toUri(inputAor, "aor");
103 }
104 else
105 {
106 mAor.user() = "test";
107 mAor.host() = DnsUtil::getLocalHostName();
108 }
109
110 mPassword = password;
111 mOutboundProxy = toUri(inputOutboundProxy, "outbound proxy");
112 mContact = toUri(inputContact, "contact");
113
114 mOutboundEnabled = outboundEnabled != 0;
115
116 if(subscribeTarget)
117 {
118 mSubscribeTarget = toUri(subscribeTarget, "subscribe target");
119 }
120
121 if(callTarget)
122 {
123 mCallTarget = toUri(callTarget, "call target");
124 }
125
126 // Free the option parsing context.
127 #if defined(HAVE_POPT_H)
128 poptFreeContext(context);
129 #endif
130 }
131
132 resip::Uri
133 BasicClientCmdLineParser::toUri(const char* input, const char* description)
134 {
135 resip::Uri uri;
136 try
137 {
138 if (input)
139 {
140 uri = Uri(input);
141 }
142 else
143 {
144 //WarningLog (<< "No " << description << " specified");
145 }
146 }
147 catch (ParseException& e)
148 {
149 InfoLog (<< "Caught: " << e);
150 WarningLog (<< "Can't parse " << description << " : " << input);
151 exit(-1);
152 }
153 return uri;
154 }
155
156
157 /* ====================================================================
158
159 Copyright (c) 2011, SIP Spectrum, Inc.
160 All rights reserved.
161
162 Redistribution and use in source and binary forms, with or without
163 modification, are permitted provided that the following conditions are
164 met:
165
166 1. Redistributions of source code must retain the above copyright
167 notice, this list of conditions and the following disclaimer.
168
169 2. Redistributions in binary form must reproduce the above copyright
170 notice, this list of conditions and the following disclaimer in the
171 documentation and/or other materials provided with the distribution.
172
173 3. Neither the name of SIP Spectrum nor the names of its contributors
174 may be used to endorse or promote products derived from this
175 software without specific prior written permission.
176
177 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
179 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
180 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
181 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
182 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
183 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
184 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
185 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
186 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
187 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
188
189 ==================================================================== */

Properties

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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.26