/[resiprocate]/branches/b-directory-reorg/resip/dum/test/testIdentity.cxx
ViewVC logotype

Annotation of /branches/b-directory-reorg/resip/dum/test/testIdentity.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5283 - (hide annotations) (download)
Fri Aug 19 01:27:14 2005 UTC (14 years, 4 months ago) by derek
File size: 8840 byte(s)
finished resip/sip -> resip/stack rename
1 jason 5276 #include "resip/dum/ClientAuthManager.hxx"
2     #include "resip/dum/ClientRegistration.hxx"
3     #include "resip/dum/DialogUsageManager.hxx"
4     #include "resip/dum/MasterProfile.hxx"
5     #include "resip/dum/Profile.hxx"
6     #include "resip/dum/UserProfile.hxx"
7     #include "resip/dum/RegistrationHandler.hxx"
8     #include "resip/dum/ClientPagerMessage.hxx"
9     #include "resip/dum/ServerPagerMessage.hxx"
10 greg 4564
11 jason 5276 #include "resip/dum/DialogUsageManager.hxx"
12     #include "resip/dum/AppDialogSet.hxx"
13     #include "resip/dum/AppDialog.hxx"
14     #include "resip/dum/RegistrationHandler.hxx"
15     #include "resip/dum/PagerMessageHandler.hxx"
16 derek 5283 #include "resip/stack/PlainContents.hxx"
17 greg 4564
18 derek 5283 #include "resip/stack/external/HttpGetMessage.hxx"
19 greg 4564 #include "curlHttp/CurlHttpProvider.hxx"
20    
21 jason 5276 #include "rutil/Log.hxx"
22     #include "rutil/Logger.hxx"
23     #include "rutil/Subsystem.hxx"
24 greg 4564
25 daniel 4740 #ifdef WIN32
26 derek 5283 #include "resip/stack/WinSecurity.hxx"
27 daniel 4740 #endif
28    
29 greg 4564 #include <iostream>
30     #include <string>
31     #include <sstream>
32    
33     using namespace std;
34     using namespace resip;
35    
36     #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
37    
38     class TestIdentityHandler : public ClientPagerMessageHandler,
39     public ServerPagerMessageHandler,
40     public ClientRegistrationHandler
41     {
42     public:
43     TestIdentityHandler() : _registered(false), _ended(false), _rcvd(false)
44     {};
45    
46     bool isRegistered()
47     {
48     return _registered;
49     };
50    
51     bool isEnded()
52     {
53     return _ended;
54     };
55    
56     bool isRcvd()
57     {
58     return _rcvd;
59     };
60    
61     virtual void onMessageArrived(ServerPagerMessageHandle handle,
62     const SipMessage& message)
63     {
64    
65     SipMessage ok = handle->accept();
66     handle->send(ok);
67    
68     Contents *body = message.getContents();
69    
70     InfoLog( << "ServerPagerMessageHandler::onMessageArrived: "
71     << *body << "\n" );
72 greg 4633
73     const SecurityAttributes *attr = message.getSecurityAttributes();
74     InfoLog( << *attr );
75 greg 4564
76     _rcvd = true;
77     }
78    
79     virtual void onSuccess(ClientPagerMessageHandle,
80     const SipMessage& status)
81     {
82     InfoLog( << "ClientMessageHandler::onSuccess\n" );
83     _ended = true;
84     }
85    
86     virtual void onFailure(ClientPagerMessageHandle,
87     const SipMessage& status,
88     std::auto_ptr<Contents> contents)
89     {
90     InfoLog( << "ClientMessageHandler::onFailure\n" );
91     _ended = true;
92     }
93    
94     virtual void onSuccess(ClientRegistrationHandle,
95     const SipMessage& response)
96     {
97     InfoLog( << "ClientRegistrationHandler::onSuccess\n" );
98     _registered = true;
99     }
100    
101     virtual void onRemoved(ClientRegistrationHandle)
102     {
103     InfoLog( << "ClientRegistrationHander::onRemoved\n" );
104     exit(-1);
105     }
106    
107     virtual void onFailure(ClientRegistrationHandle,
108     const SipMessage& response)
109     {
110     InfoLog( << "ClientRegistrationHandler::onFailure\n" );
111     exit(-1);
112     }
113    
114     virtual int onRequestRetry(ClientRegistrationHandle,
115     int retrySeconds, const SipMessage& response)
116     {
117     InfoLog( << "ClientRegistrationHandler::onRequestRetry\n" );
118     exit(-1);
119     }
120    
121     protected:
122     bool _registered;
123     bool _ended;
124     bool _rcvd;
125    
126     };
127    
128    
129     /*****************************************************************************/
130    
131     int main(int argc, char *argv[])
132     {
133    
134     if ( argc < 3 ) {
135     cout << "usage: " << argv[0] << " sip:user passwd\n";
136     return 0;
137     }
138    
139     Log::initialize(Log::Cout, Log::Debug, argv[0]);
140    
141     HttpProvider::setFactory(
142     std::auto_ptr<HttpProviderFactory>(new CurlHttpProviderFactory()));
143    
144     bool first = true;
145     NameAddr userAor(argv[1]);
146     Data passwd(argv[2]);
147    
148     InfoLog(<< "user: " << userAor << ", passwd: " << passwd << "\n");
149    
150 daniel 4740 #ifdef WIN32
151     WinSecurity* security = new WinSecurity;
152     #else
153     Security* security = new Security;
154     #endif
155 greg 4564
156     assert( security );
157    
158     SipStack clientStack(security);
159     DialogUsageManager clientDum(clientStack);
160 daniel 4740 clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V4);
161     clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V4);
162     clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V4);
163     // clientDum.addTransport(UDP, 10000 + rand()&0x7fff, V6);
164     // clientDum.addTransport(TCP, 10000 + rand()&0x7fff, V6);
165     // clientDum.addTransport(TLS, 10000 + rand()&0x7fff, V6);
166 greg 4564
167 sgodin 4781 SharedPtr<MasterProfile> clientProfile(new MasterProfile);
168 greg 4564 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
169     TestIdentityHandler clientHandler;
170    
171 sgodin 4781 clientDum.setMasterProfile(clientProfile);
172 greg 4564 clientDum.setClientAuthManager(clientAuth);
173     clientDum.setClientRegistrationHandler(&clientHandler);
174     clientDum.setClientPagerMessageHandler(&clientHandler);
175     clientDum.setServerPagerMessageHandler(&clientHandler);
176     clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
177     clientDum.getMasterProfile()->addSupportedMethod(MESSAGE);
178     clientDum.getMasterProfile()->addSupportedMimeType(MESSAGE, Mime("text", "plain"));
179    
180 sgodin 4781 clientProfile->setDefaultFrom(userAor);
181 greg 4564
182     InfoLog( << userAor.uri().host() << " " << userAor.uri().user()
183     << " " << passwd );
184    
185 sgodin 4781 clientProfile->setDigestCredential(userAor.uri().host(),
186 greg 4564 userAor.uri().user(),
187     passwd);
188    
189     SipMessage & regMessage = clientDum.makeRegistration(userAor);
190    
191     InfoLog( << regMessage << "Generated register: " << endl << regMessage );
192     clientDum.send( regMessage );
193    
194     while (!clientHandler.isEnded() || !clientHandler.isRcvd() )
195     {
196     FdSet fdset;
197    
198     // Should these be buildFdSet on the DUM?
199     clientStack.buildFdSet(fdset);
200     int err = fdset.selectMilliSeconds(100);
201     assert ( err != -1 );
202    
203     clientStack.process(fdset);
204     while(clientDum.process());
205     //if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
206    
207     if (first && clientHandler.isRegistered()) {
208     first = false;
209     InfoLog( << "client registered!!\n" );
210     InfoLog( << "Sending MESSAGE\n" );
211     ClientPagerMessageHandle cpmh = clientDum.makePagerMessage(userAor);
212     auto_ptr<Contents> content(new PlainContents(Data("message")));
213     cpmh.get()->page(content);
214     }
215 greg 4633 }
216 greg 4564
217     return 0;
218     }
219    
220     /* ====================================================================
221     * The Vovida Software License, Version 1.0
222     *
223     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
224     *
225     * Redistribution and use in source and binary forms, with or without
226     * modification, are permitted provided that the following conditions
227     * are met:
228     *
229     * 1. Redistributions of source code must retain the above copyright
230     * notice, this list of conditions and the following disclaimer.
231     *
232     * 2. Redistributions in binary form must reproduce the above copyright
233     * notice, this list of conditions and the following disclaimer in
234     * the documentation and/or other materials provided with the
235     * distribution.
236     *
237     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
238     * and "Vovida Open Communication Application Library (VOCAL)" must
239     * not be used to endorse or promote products derived from this
240     * software without prior written permission. For written
241     * permission, please contact vocal@vovida.org.
242     *
243     * 4. Products derived from this software may not be called "VOCAL", nor
244     * may "VOCAL" appear in their name, without prior written
245     * permission of Vovida Networks, Inc.
246     *
247     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
248     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
249     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
250     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
251     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
252     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
253     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
254     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
255     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
256     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
258     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
259     * DAMAGE.
260     *
261     * ====================================================================
262     *
263     * This software consists of voluntary contributions made by Vovida
264     * Networks, Inc. and many individuals on behalf of Vovida Networks,
265     * Inc. For more information on Vovida Networks, Inc., please see
266     * <http://www.vovida.org/>.
267     *
268     */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27