/[resiprocate]/main/resip/stack/test/dumpTls.cxx
ViewVC logotype

Contents of /main/resip/stack/test/dumpTls.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9485 - (show annotations) (download)
Sat Apr 7 00:34:03 2012 UTC (7 years, 7 months ago) by dpocock
File size: 7933 byte(s)
Switch over to autotools build system from dpocock-autotools branch
1 #if defined(HAVE_CONFIG_H)
2 #include "config.h"
3 #endif
4
5 #if defined (HAVE_POPT_H)
6 #include <popt.h>
7 #else
8 #ifndef WIN32
9 #warning "will not work very well without libpopt"
10 #endif
11 #endif
12
13 #include <sys/types.h>
14 #include <unistd.h> // for sleep
15 #include <iostream>
16 #include <memory>
17 #include <sys/ioctl.h>
18 #include <signal.h>
19
20 #ifdef __MINGW32__
21 #define sleep(x) Sleep((x)*1000)
22 #endif
23
24 #include "rutil/DnsUtil.hxx"
25 #include "rutil/Inserter.hxx"
26 #include "rutil/Logger.hxx"
27 #include "resip/stack/Helper.hxx"
28 #include "resip/stack/SipMessage.hxx"
29 #include "resip/stack/SipStack.hxx"
30 #include "resip/stack/Uri.hxx"
31 #include "resip/stack/ShutdownMessage.hxx"
32
33 #include "resip/stack/ssl/Security.hxx"
34
35 using namespace resip;
36 using namespace std;
37
38 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
39
40 int
41 main(int argc, char* argv[])
42 {
43 #ifdef USE_SSL
44 const char *logType = "cerr";
45 const char *logLevel = "DEBUG";
46 const char *certPath = ".";
47 int clientPort = 15001;
48 int serverPort = 5061;
49 const char *clientDomain = "example.net";
50 const char *serverDomain = "example.com";
51
52 #if defined(HAVE_POPT_H)
53 struct poptOption table[] = {
54 {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
55 {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
56 {"cert-path", 'p', POPT_ARG_STRING, &certPath, 0, "path to the server certificates", "."},
57 {"client-port", 'f', POPT_ARG_INT, &clientPort, 0, "client port (send request from)", "15001"},
58 {"server-port", 't', POPT_ARG_INT, &serverPort, 0, "server port (send request to)", "5061"},
59 {"client-domain",'c', POPT_ARG_STRING, &clientDomain, 0, "client domain", "example.net"},
60 {"server-domain",'s', POPT_ARG_STRING, &serverDomain, 0, "server domain", "example.com"},
61 POPT_AUTOHELP
62 { NULL, 0, 0, NULL, 0 }
63 };
64
65 poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
66 poptGetNextOpt(context);
67 #endif
68
69 Log::initialize(logType, logLevel, argv[0]);
70
71 DebugLog(<< "Logs initialized");
72 DebugLog(<< "logLevel = " << logLevel);
73 DebugLog(<< "certPath = " << certPath);
74
75 DebugLog(<< "Starting ssldump");
76
77 int dumpPid = fork();
78
79 if (dumpPid==-1)
80 {
81 DebugLog(<< "Can't fork to run ssldump"); exit(-1);
82 }
83
84 if (dumpPid==0)
85 {
86 // todo - make this something that can come on the command line
87 const char *args[] = { "ssldump","-A","-i","lo0",NULL };
88 // .kw. execvp takes a 'char* const *' -- for some reason it doesn't
89 // promise to not modify the strings. Thus shouldn't use static string
90 // initializers above!
91 int ret = execvp("ssldump",const_cast<char**>(args));
92 ErrLog(<< "Can't execvp: return is " << ret <<" errno is " << errno);
93 exit(-1);
94 }
95
96 DebugLog(<< "ssldump's pid is " << dumpPid);
97
98 IpVersion version = V4;
99 Data bindInterface;
100 //bindInterface = Data( "127.0.0.1" );
101
102 SipStack* clientStack;
103 SipStack* serverStack;
104
105 Security* clientSecurity = new Security(certPath);
106 Security* serverSecurity = new Security(certPath);
107 clientStack = new SipStack(clientSecurity);
108 serverStack = new SipStack(serverSecurity);
109
110 clientStack->addTransport(TLS, clientPort, version, StunDisabled, bindInterface, clientDomain);
111 serverStack->addTransport(TLS, serverPort, version, StunDisabled, bindInterface, serverDomain);
112
113 NameAddr target;
114 target.uri().scheme() = "sip";
115 target.uri().user() = "fluffy";
116 target.uri().host() = serverDomain;
117 target.uri().port() = serverPort;
118 target.uri().param(p_transport) = "tls";
119
120 NameAddr contact;
121 contact.uri().scheme() = "sip";
122 contact.uri().user() = "fluffy";
123 contact.uri().host() = clientDomain;
124 contact.uri().port() = clientPort;
125
126 NameAddr from = target;
127 from.uri().port() = clientPort;
128
129 InfoLog (<< "Starting" );
130
131 SipMessage* msg = Helper::makeRegister( target, from, contact);
132 clientStack->send(*msg);
133 delete msg;
134
135 bool done=false;
136 int rundown = 0;
137 while ( (!done) || (rundown-- > 0) )
138 {
139
140 FdSet fdset;
141
142 clientStack->buildFdSet(fdset);
143 serverStack->buildFdSet(fdset);
144
145 fdset.selectMilliSeconds(100);
146
147
148 serverStack->process(fdset);
149 SipMessage *msg = serverStack->receive();
150 if ( !msg )
151 {
152 clientStack->process(fdset);
153 msg = clientStack->receive();
154 }
155
156 if ( msg )
157 {
158 if ( msg->isRequest() )
159 {
160 assert(msg->isRequest());
161 assert(msg->header(h_RequestLine).getMethod() == REGISTER);
162
163 SipMessage* response = Helper::makeResponse(*msg, 200);
164 serverStack->send(*response);
165 delete response;
166 delete msg;
167 }
168 else
169 {
170 assert(msg->isResponse());
171 assert(msg->header(h_CSeq).method() == REGISTER);
172 if (msg->header(h_StatusLine).statusCode() < 200)
173 {
174 DebugLog(<<"Provisional response to a REGISTER - you're kidding me, right?");
175 }
176 else
177 {
178 done = true;
179 rundown = 100;
180 }
181 delete msg;
182 }
183 }
184 }
185 InfoLog (<< "Finished " );
186
187 #if defined(HAVE_POPT_H)
188 poptFreeContext(context);
189 #endif
190 sleep(2);
191 delete serverStack; //btw - this deletes the security object
192 delete clientStack;
193 sleep(5);
194
195 if (dumpPid>0)
196
197 {
198 DebugLog( << "Trying to kill process id " << dumpPid);
199 int ret = kill(dumpPid, SIGINT); // ssldump catches INT and does an fflush
200 DebugLog( << "Kill returned: " << ret);
201 }
202
203
204 #endif
205 return 0;
206 }
207 /* ====================================================================
208 * The Vovida Software License, Version 1.0
209 *
210 * Copyright (c) 2008 Robert Sparks. All rights reserved.
211 *
212 * Redistribution and use in source and binary forms, with or without
213 * modification, are permitted provided that the following conditions
214 * are met:
215 *
216 * 1. Redistributions of source code must retain the above copyright
217 * notice, this list of conditions and the following disclaimer.
218 *
219 * 2. Redistributions in binary form must reproduce the above copyright
220 * notice, this list of conditions and the following disclaimer in
221 * the documentation and/or other materials provided with the
222 * distribution.
223 *
224 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
225 * and "Vovida Open Communication Application Library (VOCAL)" must
226 * not be used to endorse or promote products derived from this
227 * software without prior written permission. For written
228 * permission, please contact vocal@vovida.org.
229 *
230 * 4. Products derived from this software may not be called "VOCAL", nor
231 * may "VOCAL" appear in their name, without prior written
232 * permission of Vovida Networks, Inc.
233 *
234 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
235 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
236 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
237 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
238 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
239 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
240 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
241 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
242 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
243 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
244 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
245 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
246 * DAMAGE.
247 *
248 * ====================================================================
249 *
250 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27