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

Annotation of /main/resip/dum/test/basicRegister.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: 6073 byte(s)
DUM test driver fixes, as proposed by Chris Brody

1 derek 5283 #include "resip/stack/SipStack.hxx"
2 jason 5276 #include "resip/dum/ClientAuthManager.hxx"
3     #include "resip/dum/ClientRegistration.hxx"
4     #include "resip/dum/DialogUsageManager.hxx"
5     #include "resip/dum/MasterProfile.hxx"
6     #include "resip/dum/RegistrationHandler.hxx"
7     #include "rutil/Log.hxx"
8     #include "rutil/Logger.hxx"
9     #include "rutil/Subsystem.hxx"
10     #include "resip/dum/KeepAliveManager.hxx"
11 derek 2850
12 adam 8415 #if defined (USE_SSL)
13     #if defined(WIN32)
14 bcampen 8228 #include "resip/stack/ssl/WinSecurity.hxx"
15 adam 8415 #else
16     #include "resip/stack/ssl/Security.hxx"
17 daniel 4740 #endif
18 adam 8415 #endif
19 derek 2955
20 alan 2906 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
21    
22 derek 2850 using namespace resip;
23 jason 4010 using namespace std;
24 derek 2850
25 daniel 4740 class ClientHandler : public ClientRegistrationHandler
26 derek 2955 {
27     public:
28 daniel 4740 ClientHandler() : done(false) {}
29 derek 2955
30 jason 2941 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
31 derek 2850 {
32 daniel 4740 InfoLog( << "ClientHandler::onSuccess: " << endl );
33    
34 sgodin 8215 resipCerr << "Pausing before unregister" << endl;
35 daniel 4740
36 derek 2929 #ifdef WIN32
37 daniel 4740 Sleep(2000);
38 derek 2929 #else
39 daniel 4740 sleep(5);
40 derek 2929 #endif
41 daniel 4740 h->removeAll();
42 derek 2850 }
43    
44 sgodin 5758 virtual void onRemoved(ClientRegistrationHandle, const SipMessage& response)
45 sgodin 3458 {
46 daniel 4740 InfoLog ( << "ClientHandler::onRemoved ");
47     done = true;
48 sgodin 3458 }
49    
50 jason 2941 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
51 derek 2850 {
52 daniel 4740 InfoLog ( << "ClientHandler::onFailure: " << response );
53 derek 2850 }
54 alan 2906
55 jason 4335 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
56     {
57 daniel 4740 InfoLog ( << "ClientHandler:onRequestRetry");
58     return -1;
59 jason 4335 }
60    
61 derek 2850 bool done;
62     };
63    
64    
65    
66     int
67     main (int argc, char** argv)
68     {
69 alan 2877
70 daniel 4740 if ( argc < 3 ) {
71 sgodin 8215 resipCout << "usage: " << argv[0] << " sip:user passwd\n";
72 daniel 4740 return 0;
73     }
74 alan 2877
75 daniel 4740 Log::initialize(Log::Cout, Log::Stack, argv[0]);
76    
77     NameAddr userAor(argv[1]);
78     Data passwd(argv[2]);
79    
80 greg 4796 #ifdef USE_SSL
81 daniel 4740 #ifdef WIN32
82 greg 4796 Security* security = new WinSecurity;
83 daniel 4740 #else
84     Security* security = new Security;
85 greg 4796 #endif
86 daniel 4740 SipStack stack(security);
87     #else
88     SipStack stack;
89     #endif
90    
91     DialogUsageManager clientDum(stack);
92 sgodin 4781 SharedPtr<MasterProfile> profile(new MasterProfile);
93 jason 4010 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
94 daniel 4740 ClientHandler clientHandler;
95 derek 2929
96 daniel 4740 clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
97     // clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
98     clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
99     // clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
100 greg 4796 #ifdef USE_SSL
101 daniel 4740 clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
102     // clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
103 greg 4796 #endif
104 sgodin 4781 clientDum.setMasterProfile(profile);
105 daniel 4740 clientDum.setClientRegistrationHandler(&clientHandler);
106 sgodin 3458 clientDum.setClientAuthManager(clientAuth);
107 jason 4010 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
108 derek 2991
109 daniel 4740 // keep alive test.
110     auto_ptr<KeepAliveManager> keepAlive(new KeepAliveManager);
111     clientDum.setKeepAliveManager(keepAlive);
112 alan 2877
113 daniel 4740 clientDum.getMasterProfile()->setDefaultFrom(userAor);
114 sgodin 4781 profile->setDigestCredential(userAor.uri().host(),
115 daniel 4740 userAor.uri().user(),
116     passwd);
117 derek 2991
118 sgodin 5758 SharedPtr<SipMessage> regMessage = clientDum.makeRegistration(userAor);
119 derek 2984 NameAddr contact;
120 alan 2877
121 fluffy 2870 clientDum.send( regMessage );
122 alan 2877
123     int n = 0;
124 daniel 4740 while ( !clientHandler.done )
125 derek 2850 {
126 jason 4335 FdSet fdset;
127 fluffy 2870
128 sgodin 4342 stack.buildFdSet(fdset);
129 jason 4335 int err = fdset.selectMilliSeconds(100);
130     assert ( err != -1 );
131 alan 2877
132 sgodin 4342 stack.process(fdset);
133     while(clientDum.process());
134    
135 daniel 4740 if (n == 1000) clientHandler.done = true;
136    
137 jason 4335 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
138 derek 2850 }
139 derek 2984 return 0;
140 derek 2850 }
141 derek 4602
142     /* ====================================================================
143     * The Vovida Software License, Version 1.0
144     *
145     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
146     *
147     * Redistribution and use in source and binary forms, with or without
148     * modification, are permitted provided that the following conditions
149     * are met:
150     *
151     * 1. Redistributions of source code must retain the above copyright
152     * notice, this list of conditions and the following disclaimer.
153     *
154     * 2. Redistributions in binary form must reproduce the above copyright
155     * notice, this list of conditions and the following disclaimer in
156     * the documentation and/or other materials provided with the
157     * distribution.
158     *
159     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
160     * and "Vovida Open Communication Application Library (VOCAL)" must
161     * not be used to endorse or promote products derived from this
162     * software without prior written permission. For written
163     * permission, please contact vocal@vovida.org.
164     *
165     * 4. Products derived from this software may not be called "VOCAL", nor
166     * may "VOCAL" appear in their name, without prior written
167     * permission of Vovida Networks, Inc.
168     *
169     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
170     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
172     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
173     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
174     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
175     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
176     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
177     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
178     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
179     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
180     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
181     * DAMAGE.
182     *
183     * ====================================================================
184     *
185     * This software consists of voluntary contributions made by Vovida
186     * Networks, Inc. and many individuals on behalf of Vovida Networks,
187     * Inc. For more information on Vovida Networks, Inc., please see
188     * <http://www.vovida.org/>.
189     *
190     */

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