/[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 7077 - (hide annotations) (download)
Mon Apr 16 10:07:24 2007 UTC (12 years, 9 months ago) by nash
File MIME type: text/plain
File size: 14765 byte(s)
inside resip/stack/Transaction::process method contains complex 
logics and message ptr can be easily leaked if it's not maintained by 
original coder, therefore I changed to SharedPtr usage and made a bunch 
of code changed to make it compile.

Also another place worth mention as TimeLimitFifo::add method could 
result memory leak usage, and it's fixed on the way for above changes.

The tests under rutil/stack/dum has passed as well.

resip/stack/Security add to allow disable server authentication check



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

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