/[resiprocate]/branches/b-identity-0505/dum/test/testIdentity.cxx
ViewVC logotype

Annotation of /branches/b-identity-0505/dum/test/testIdentity.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4564 - (hide annotations) (download)
Mon May 9 23:57:12 2005 UTC (14 years, 6 months ago) by greg
File size: 8566 byte(s)
Identity test - moved curlHttp

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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27