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

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