|
reSIProcate/DialogUsageManager
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #if defined (HAVE_POPT_H) 00006 #include <popt.h> 00007 #endif 00008 00009 #include "basicClientCmdLineParser.hxx" 00010 #include <rutil/Logger.hxx> 00011 #include <rutil/DnsUtil.hxx> 00012 #include <rutil/ParseException.hxx> 00013 00014 using namespace resip; 00015 using namespace std; 00016 00017 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00018 00019 BasicClientCmdLineParser::BasicClientCmdLineParser(int argc, char** argv) 00020 { 00021 const char* logType = "cout"; 00022 const char* logLevel = "INFO"; 00023 char* tlsDomain = 0; 00024 char* certPath = 0; 00025 00026 int udpPort = 5160; 00027 int tcpPort = 5160; 00028 int tlsPort = 5161; 00029 int dtlsPort = 5161; 00030 00031 mRegisterDuration = 3600; 00032 int noV4 = false; 00033 int enableV6 = false; 00034 int hostFileLookupOnlyDnsMode = false; 00035 00036 char* inputAor = 0; 00037 const char* password = ""; 00038 00039 char* inputOutboundProxy = 0; 00040 char* inputContact = 0; 00041 Data basePath(getenv("HOME")); 00042 00043 int outboundEnabled = false; 00044 00045 char* subscribeTarget = 0; 00046 char* callTarget = 0; 00047 00048 #if defined(HAVE_POPT_H) 00049 struct poptOption table[] = { 00050 {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"}, 00051 {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"}, 00052 #if defined(USE_SSL) 00053 {"tls-domain", 't', POPT_ARG_STRING, &tlsDomain, 0, "act as a TLS server for specified domain", "example.com"}, 00054 {"cert-path", 0, POPT_ARG_STRING, &certPath, 0, "path for certificates (default ~/.sipCerts)", 0}, 00055 #endif 00056 00057 {"udp", 0, POPT_ARG_INT, &udpPort, 0, "add UDP transport on specified port", "5160"}, 00058 {"tcp", 0, POPT_ARG_INT, &tcpPort, 0, "add TCP transport on specified port", "5160"}, 00059 #if defined(USE_SSL) 00060 {"tls", 0, POPT_ARG_INT, &tlsPort, 0, "add TLS transport on specified port", "5161"}, 00061 #endif 00062 #if defined(USE_DTLS) 00063 {"dtls", 0, POPT_ARG_INT, &dtlsPort, 0, "add DTLS transport on specified port", "5161"}, 00064 #endif 00065 00066 {"register-duration",'r', POPT_ARG_INT, &mRegisterDuration, 0, "expires for register (0 for no reg)", "3600"}, 00067 {"enable-v6", 0, POPT_ARG_NONE, &enableV6, 0, "enable IPV6", 0}, 00068 {"disable-v4", 0, POPT_ARG_NONE, &noV4, 0, "disable IPV4", 0}, 00069 {"enable-hostfileonly",0, POPT_ARG_NONE, &hostFileLookupOnlyDnsMode,0, "enable hostfile only dns lookup mode", 0}, 00070 00071 {"aor", 'a', POPT_ARG_STRING, &inputAor, 0, "specify address of record", "sip:alice@example.com"}, 00072 {"password", 'p', POPT_ARG_STRING, &password, 0, "specify password for address of record", "password"}, 00073 {"outbound-proxy", 'o', POPT_ARG_STRING, &inputOutboundProxy, 0, "specify uri for outbound proxy (if none present, don't use)", "sip:outbound.example.com"}, 00074 {"contact", 'c', POPT_ARG_STRING, &inputContact, 0, "override default contact", "sip:alice@contact.example.com"}, 00075 {"enable-outbound", 'b', POPT_ARG_NONE, &outboundEnabled, 0, "enable RFC 5626 outbound support", 0}, 00076 00077 {"subtarget", 0, POPT_ARG_STRING, &subscribeTarget, 0, "specify a SIP URI to subscribe to", "sip:bob@example.com"}, 00078 {"calltarget", 0, POPT_ARG_STRING, &callTarget, 0, "specify a SIP URI to call", "sip:carol@example.com"}, 00079 POPT_AUTOHELP 00080 { NULL, 0, 0, NULL, 0 } 00081 }; 00082 00083 poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0); 00084 poptGetNextOpt(context); 00085 #endif 00086 00087 mLogType = logType; 00088 mLogLevel = logLevel; 00089 if (tlsDomain) mTlsDomain = tlsDomain; 00090 if (certPath) mCertPath = certPath; 00091 else mCertPath = basePath + "/.sipCerts"; 00092 00093 mUdpPort = udpPort; 00094 mTcpPort = tcpPort; 00095 mTlsPort = tlsPort; 00096 mDtlsPort = dtlsPort; 00097 mNoV4 = noV4 != 0; 00098 mEnableV6 = enableV6 != 0; 00099 mHostFileLookupOnlyDnsMode = hostFileLookupOnlyDnsMode != 0; 00100 if (inputAor) 00101 { 00102 mAor = toUri(inputAor, "aor"); 00103 } 00104 else 00105 { 00106 mAor.user() = "test"; 00107 mAor.host() = DnsUtil::getLocalHostName(); 00108 } 00109 00110 mPassword = password; 00111 mOutboundProxy = toUri(inputOutboundProxy, "outbound proxy"); 00112 mContact = toUri(inputContact, "contact"); 00113 00114 mOutboundEnabled = outboundEnabled != 0; 00115 00116 if(subscribeTarget) 00117 { 00118 mSubscribeTarget = toUri(subscribeTarget, "subscribe target"); 00119 } 00120 00121 if(callTarget) 00122 { 00123 mCallTarget = toUri(callTarget, "call target"); 00124 } 00125 00126 // Free the option parsing context. 00127 #if defined(HAVE_POPT_H) 00128 poptFreeContext(context); 00129 #endif 00130 } 00131 00132 resip::Uri 00133 BasicClientCmdLineParser::toUri(const char* input, const char* description) 00134 { 00135 resip::Uri uri; 00136 try 00137 { 00138 if (input) 00139 { 00140 uri = Uri(input); 00141 } 00142 else 00143 { 00144 //WarningLog (<< "No " << description << " specified"); 00145 } 00146 } 00147 catch (ParseException& e) 00148 { 00149 InfoLog (<< "Caught: " << e); 00150 WarningLog (<< "Can't parse " << description << " : " << input); 00151 exit(-1); 00152 } 00153 return uri; 00154 } 00155 00156 00157 /* ==================================================================== 00158 00159 Copyright (c) 2011, SIP Spectrum, Inc. 00160 All rights reserved. 00161 00162 Redistribution and use in source and binary forms, with or without 00163 modification, are permitted provided that the following conditions are 00164 met: 00165 00166 1. Redistributions of source code must retain the above copyright 00167 notice, this list of conditions and the following disclaimer. 00168 00169 2. Redistributions in binary form must reproduce the above copyright 00170 notice, this list of conditions and the following disclaimer in the 00171 documentation and/or other materials provided with the distribution. 00172 00173 3. Neither the name of SIP Spectrum nor the names of its contributors 00174 may be used to endorse or promote products derived from this 00175 software without specific prior written permission. 00176 00177 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00178 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00179 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00180 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00181 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00182 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00183 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00184 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00185 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00186 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00187 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00188 00189 ==================================================================== */
1.7.5.1