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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8415 - (hide annotations) (download)
Wed Feb 18 16:35:08 2009 UTC (10 years, 11 months ago) by adam
File MIME type: text/plain
File size: 14744 byte(s)
DUM test driver fixes, as proposed by Chris Brody

1 jason 5276 #include "resip/dum/DialogUsageManager.hxx"
2     #include "resip/dum/ClientRegistration.hxx"
3     #include "resip/dum/ClientInviteSession.hxx"
4     #include "resip/dum/ServerInviteSession.hxx"
5     #include "resip/dum/ClientAuthManager.hxx"
6 greg 5016
7 jason 5276 #include "resip/dum/RegistrationHandler.hxx"
8     #include "resip/dum/InviteSessionHandler.hxx"
9     #include "resip/dum/DumShutdownHandler.hxx"
10 greg 5016
11 jason 5276 #include "resip/dum/MasterProfile.hxx"
12 derek 5283 #include "resip/stack/ShutdownMessage.hxx"
13 greg 5016
14 derek 5283 #include "resip/stack/SdpContents.hxx"
15     #include "resip/stack/Pkcs7Contents.hxx"
16     #include "resip/stack/MultipartSignedContents.hxx"
17     #include "resip/stack/MultipartAlternativeContents.hxx"
18     #include "resip/stack/Mime.hxx"
19 greg 5016
20 derek 5283 #include "resip/stack/SecurityAttributes.hxx"
21     #include "resip/stack/Helper.hxx"
22 greg 5016
23 jason 5276 #include "rutil/Log.hxx"
24     #include "rutil/Logger.hxx"
25 greg 5016
26     #ifdef WIN32
27 bcampen 8228 #include "resip/stack/ssl/WinSecurity.hxx"
28 adam 8415 #else
29     #include "resip/stack/ssl/Security.hxx"
30 greg 5016 #endif
31    
32     #include "TestDumHandlers.hxx"
33    
34     #include <time.h>
35     #include <sstream>
36    
37     using namespace std;
38     using namespace resip;
39    
40     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
41    
42    
43     class TestSMIMEInviteHandler : public TestClientRegistrationHandler,
44     public TestInviteSessionHandler,
45     public TestDumShutdownHandler
46     {
47     public:
48    
49     TestSMIMEInviteHandler(Security *sec) : handles(0), security(sec), registered(0), done(0), dumShutDown(0), connected(0), callFailed(false)
50     {
51     }
52    
53     virtual ~TestSMIMEInviteHandler()
54     {
55     }
56    
57     void resetRegistered(void)
58     {
59     registered = 0;
60     }
61    
62     bool isConnected(void)
63     {
64     return (connected == 2);
65     }
66    
67     bool isDumShutDown(void)
68     {
69     return (dumShutDown == 2);
70     }
71    
72     bool isRegistered(void)
73     {
74     return (registered == 2);
75     }
76    
77     bool isDone(void)
78     {
79     return (done == 2);
80    
81     }
82    
83     bool isCallFailed(void)
84     {
85     return callFailed;
86     }
87    
88     SdpContents* generateBody()
89     {
90     HeaderFieldValue* hfv;
91     Data* txt = new Data("v=0\r\n"
92     "o=1900 369696545 369696545 IN IP4 192.168.2.15\r\n"
93     "s=X-Lite\r\n"
94     "c=IN IP4 192.168.2.15\r\n"
95     "t=0 0\r\n"
96     "m=audio 8000 RTP/AVP 8 3 101\r\n"
97     "a=rtpmap:8 pcma/8000\r\n"
98     "a=rtpmap:3 gsm/8000\r\n"
99     "a=rtpmap:101 telephone-event/8000\r\n"
100     "a=fmtp:101 0-15\r\n");
101    
102     hfv = new HeaderFieldValue(txt->data(), txt->size());
103     SdpContents *sdp = new SdpContents(hfv, Mime("application", "sdp"));
104     return sdp;
105     }
106    
107    
108     virtual void onSuccess(ClientRegistrationHandle r,
109     const SipMessage& response)
110     {
111     InfoLog( << "ClientRegistrationHandler::onSuccess" );
112     handles.push_back(r);
113     registered++;
114     }
115    
116     virtual void onConnected(ClientInviteSessionHandle,
117     const SipMessage& msg)
118     {
119     InfoLog( << "ClientInviteSessionHandler::onConnected" );
120     connected++;
121     }
122    
123     virtual void onFailure(ClientInviteSessionHandle,
124     const SipMessage& msg)
125     {
126     InfoLog( << "TestInviteSessionHander::onFailure" );
127     callFailed = true;
128     }
129    
130     virtual void onNewSession(ServerInviteSessionHandle is,
131     InviteSession::OfferAnswerType oat,
132     const SipMessage& msg)
133     {
134     InfoLog( << "ServerInviteSessionHandler::onNewSession" );
135     sis = is;
136     is->provisional(180);
137     }
138    
139     virtual void onConnected(InviteSessionHandle,
140     const SipMessage& msg)
141     {
142     InfoLog( << "InviteSessionHandler::onConnected()" );
143     connected++;
144     }
145    
146     virtual void onTerminated(InviteSessionHandle,
147     InviteSessionHandler::TerminatedReason reason,
148     const SipMessage* msg)
149     {
150     InfoLog( << "InviteSessionHandler::onTerminated");
151     done++;
152     }
153    
154     virtual void onOffer(InviteSessionHandle is,
155     const SipMessage& msg,
156     const SdpContents& sdp)
157     {
158     InfoLog( << "InviteSessionHandler::onOffer" );
159     InfoLog( << "Server received SDP: " << sdp );
160    
161     const SecurityAttributes *attr = msg.getSecurityAttributes();
162     if (attr)
163     {
164     InfoLog( << *attr );
165     }
166     else
167     {
168     InfoLog( << "no Security Attributes" );
169     }
170    
171     if (sis.isValid())
172     {
173     NameAddr fromAor(msg.header(h_From).uri());
174     NameAddr toAor(msg.header(h_To).uri());
175     is->provideAnswer(*generateBody());
176     sis->accept();
177     }
178     }
179    
180     virtual void onAnswer(InviteSessionHandle,
181     const SipMessage& msg,
182 bcampen 7081 const SdpContents& sdp)
183 greg 5016 {
184     InfoLog( << "InviteSessionHandler::onAnswer");
185     InfoLog( << "Client received SDP: " << sdp );
186    
187     const SecurityAttributes *attr = msg.getSecurityAttributes();
188     if (attr)
189     {
190     InfoLog( << *attr );
191     }
192     else
193     {
194     InfoLog( << "no Security Attributes" );
195     }
196    
197     }
198    
199     virtual void onDumCanBeDeleted()
200     {
201     InfoLog( << "DumShutDownHandler::onDumCanBeDeleted" );
202     dumShutDown++;
203     }
204    
205 jozsef 5888 virtual void onReferNoSub(InviteSessionHandle, const SipMessage& msg)
206     {
207     InfoLog(<< "InviteSessionHandler::onReferNoSub(): " << msg.brief());
208     }
209    
210 greg 5016 public:
211     std::vector<ClientRegistrationHandle> handles;
212     ServerInviteSessionHandle sis;
213    
214     private:
215     Security *security;
216     int registered;
217 greg 5308 int done;
218 greg 5016 int dumShutDown;
219     int connected;
220     bool callFailed;
221    
222     };
223    
224    
225     int
226     main (int argc, char** argv)
227     {
228     if ( argc < 5 ) {
229     cout << "usage: " << argv[0] << " sip:user1 passwd1 sip:user2 passwd2" << endl;
230 greg 5308 return 1;
231 greg 5016 }
232    
233     Log::initialize(Log::Cout, Log::Debug, argv[0]);
234    
235     NameAddr clientAor(argv[1]);
236     Data clientPasswd(argv[2]);
237     NameAddr serverAor(argv[3]);
238     Data serverPasswd(argv[4]);
239    
240     #ifdef WIN32
241     Security* security = new WinSecurity;
242     #else
243     Security* security = new Security;
244     #endif
245    
246     TestSMIMEInviteHandler handler(security);
247    
248     // set up UAC
249     SipStack clientStack(security);
250     DialogUsageManager clientDum(clientStack);
251     srand(time(NULL));
252     clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
253     clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
254     clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
255     #ifdef USE_IPV6
256     clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
257     clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
258     clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
259     #endif
260    
261     SharedPtr<MasterProfile> clientProfile(new MasterProfile);
262     auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
263    
264     clientDum.setClientAuthManager(clientAuth);
265     clientDum.setClientRegistrationHandler(&handler);
266     clientDum.setInviteSessionHandler(&handler);
267    
268     clientProfile->setDefaultFrom(clientAor);
269     clientProfile->setDigestCredential(clientAor.uri().host(),clientAor.uri().user(),clientPasswd);
270     clientProfile->setDefaultRegistrationTime(60);
271     clientProfile->addSupportedMethod(INVITE);
272     clientProfile->addSupportedMimeType(INVITE, Mime("application", "pkcs7-mime"));
273     clientProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
274     clientProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
275     clientDum.setMasterProfile(clientProfile);
276    
277     //set up UAS
278     SipStack serverStack(security);
279     DialogUsageManager serverDum(serverStack);
280     //serverDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
281     serverDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
282     //serverDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
283    
284     SharedPtr<MasterProfile> serverProfile(new MasterProfile);
285     std::auto_ptr<ClientAuthManager> serverAuth(new ClientAuthManager);
286    
287     serverDum.setClientAuthManager(serverAuth);
288     serverDum.setClientRegistrationHandler(&handler);
289     serverDum.setInviteSessionHandler(&handler);
290    
291     serverProfile->setDefaultFrom(serverAor);
292     serverProfile->setDigestCredential(serverAor.uri().host(),serverAor.uri().user(),serverPasswd);
293     serverProfile->setDefaultRegistrationTime(60);
294     serverProfile->addSupportedMethod(INVITE);
295     serverProfile->addSupportedMimeType(INVITE, Mime("application", "pkcs7-mime"));
296     serverProfile->addSupportedMimeType(INVITE, Mime("multipart", "signed"));
297     serverProfile->addSupportedMimeType(INVITE, Mime("multipart", "alternative"));
298     serverDum.setMasterProfile(serverProfile);
299    
300     enum
301     {
302     Registering,
303     Inviting,
304     Waiting,
305     HangingUp,
306     Unregistering,
307     ShuttingDown,
308     Finished
309     } state;
310     time_t endTime;
311    
312     // register client and server
313 daniel 5759 SharedPtr<SipMessage> clientRegMessage = clientDum.makeRegistration(clientAor);
314 greg 5016 clientDum.send(clientRegMessage);
315 daniel 5759 SharedPtr<SipMessage> serverRegMessage = serverDum.makeRegistration(serverAor);
316 greg 5016 serverDum.send(serverRegMessage);
317     state = Registering;
318    
319     while (state != Finished)
320     {
321     FdSet fdset;
322    
323     clientStack.buildFdSet(fdset);
324     serverStack.buildFdSet(fdset);
325    
326     int err = fdset.selectMilliSeconds(resipMin((int)clientStack.getTimeTillNextProcessMS(), 50));
327     assert ( err != -1 );
328    
329     clientStack.process(fdset);
330     serverStack.process(fdset);
331     while(clientDum.process() || serverDum.process());
332    
333     switch (state)
334     {
335     case Registering:
336     {
337     if (handler.isRegistered())
338     {
339     InfoLog( << "Sending INVITE request" );
340     clientDum.send(clientDum.makeInviteSession(serverAor,
341     handler.generateBody()));
342     state = Inviting;
343     }
344     break;
345     }
346    
347     case Inviting:
348     {
349     if (handler.isConnected())
350     {
351     InfoLog( << "Starting timer, waiting for 5 seconds" );
352     endTime = time(NULL) + 5;
353     state = Waiting;
354     }
355     break;
356     }
357    
358     case Waiting:
359     {
360     if (handler.isCallFailed())
361     {
362     InfoLog( << "Call Failed" );
363     for (std::vector<ClientRegistrationHandle>::iterator it = handler.handles.begin();
364     it != handler.handles.end(); it++)
365     {
366     (*it)->end();
367     }
368     state = Unregistering;
369     }
370    
371     if (time(NULL) > endTime)
372     {
373     InfoLog( << "Timer expired, hanging up" );
374     handler.sis->end();
375     state = HangingUp;
376     }
377     break;
378     }
379    
380     case HangingUp:
381     {
382     if (handler.isDone())
383     {
384     for (std::vector<ClientRegistrationHandle>::iterator it = handler.handles.begin();
385     it != handler.handles.end(); it++)
386     {
387     (*it)->end();
388     }
389     state = Unregistering;
390     }
391     break;
392     }
393    
394     case Unregistering:
395     {
396     if (handler.isRegistered())
397     {
398     InfoLog( << "Shutting down" );
399     serverDum.shutdown(&handler);
400     clientDum.shutdown(&handler);
401     state = ShuttingDown;
402     }
403     break;
404     }
405    
406     case ShuttingDown:
407     {
408     if (handler.isDumShutDown())
409     {
410     InfoLog( << "Finished" );
411     state = Finished;
412     }
413    
414     break;
415     }
416    
417     default:
418     {
419     InfoLog( << "Unrecognised state" );
420     assert(0);
421     }
422     }
423    
424     }
425    
426 greg 5308 return 0;
427    
428 greg 5016 }
429    
430     /* ====================================================================
431     * The Vovida Software License, Version 1.0
432     *
433     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
434     *
435     * Redistribution and use in source and binary forms, with or without
436     * modification, are permitted provided that the following conditions
437     * are met:
438     *
439     * 1. Redistributions of source code must retain the above copyright
440     * notice, this list of conditions and the following disclaimer.
441     *
442     * 2. Redistributions in binary form must reproduce the above copyright
443     * notice, this list of conditions and the following disclaimer in
444     * the documentation and/or other materials provided with the
445     * distribution.
446     *
447     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
448     * and "Vovida Open Communication Application Library (VOCAL)" must
449     * not be used to endorse or promote products derived from this
450     * software without prior written permission. For written
451     * permission, please contact vocal@vovida.org.
452     *
453     * 4. Products derived from this software may not be called "VOCAL", nor
454     * may "VOCAL" appear in their name, without prior written
455     * permission of Vovida Networks, Inc.
456     *
457     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
458     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
459     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
460     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
461     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
462     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
463     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
464     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
465     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
466     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
467     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
468     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
469     * DAMAGE.
470     *
471     * ====================================================================
472     *
473     * This software consists of voluntary contributions made by Vovida
474     * Networks, Inc. and many individuals on behalf of Vovida Networks,
475     * Inc. For more information on Vovida Networks, Inc., please see
476     * <http://www.vovida.org/>.
477     *
478     */

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