/[resiprocate]/main/sip/resiprocate/dum/test/testIdentity.cxx
ViewVC logotype

Annotation of /main/sip/resiprocate/dum/test/testIdentity.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (hide annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 6 months ago) by derek
Original Path: branches/b-identity-0505/dum/test/testIdentity.cxx
File size: 8546 byte(s)
set svn:eol-style to LF
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    
141     InfoLog(<< "user: " << userAor << ", passwd: " << passwd << "\n");
142    
143     Security* security = new Security("certs");
144    
145     try
146     {
147     assert(security != 0);
148     security->preload();
149     }
150     catch( ... )
151     {
152     ErrLog( << "Got a exception loading certificates" );
153     }
154    
155     assert( security );
156    
157     SipStack clientStack(security);
158     DialogUsageManager clientDum(clientStack);
159 greg 4578 clientDum.addTransport(UDP, 10000 + rand()&0x7fff);
160 greg 4564
161     MasterProfile clientProfile;
162     auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
163     TestIdentityHandler clientHandler;
164    
165     clientDum.setMasterProfile(&clientProfile);
166     clientDum.setClientAuthManager(clientAuth);
167     clientDum.setClientRegistrationHandler(&clientHandler);
168     clientDum.setClientPagerMessageHandler(&clientHandler);
169     clientDum.setServerPagerMessageHandler(&clientHandler);
170     clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
171     clientDum.getMasterProfile()->addSupportedMethod(MESSAGE);
172     clientDum.getMasterProfile()->addSupportedMimeType(MESSAGE, Mime("text", "plain"));
173    
174     clientProfile.setDefaultFrom(userAor);
175    
176     InfoLog( << userAor.uri().host() << " " << userAor.uri().user()
177     << " " << passwd );
178    
179     clientProfile.setDigestCredential(userAor.uri().host(),
180     userAor.uri().user(),
181     passwd);
182    
183     SipMessage & regMessage = clientDum.makeRegistration(userAor);
184    
185     InfoLog( << regMessage << "Generated register: " << endl << regMessage );
186     clientDum.send( regMessage );
187    
188     while (!clientHandler.isEnded() || !clientHandler.isRcvd() )
189     {
190     FdSet fdset;
191    
192     // Should these be buildFdSet on the DUM?
193     clientStack.buildFdSet(fdset);
194     int err = fdset.selectMilliSeconds(100);
195     assert ( err != -1 );
196    
197     clientStack.process(fdset);
198     while(clientDum.process());
199     //if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
200    
201     if (first && clientHandler.isRegistered()) {
202     first = false;
203     InfoLog( << "client registered!!\n" );
204     InfoLog( << "Sending MESSAGE\n" );
205     ClientPagerMessageHandle cpmh = clientDum.makePagerMessage(userAor);
206     auto_ptr<Contents> content(new PlainContents(Data("message")));
207     cpmh.get()->page(content);
208     }
209     }
210    
211     return 0;
212     }
213    
214     /* ====================================================================
215     * The Vovida Software License, Version 1.0
216     *
217     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
218     *
219     * Redistribution and use in source and binary forms, with or without
220     * modification, are permitted provided that the following conditions
221     * are met:
222     *
223     * 1. Redistributions of source code must retain the above copyright
224     * notice, this list of conditions and the following disclaimer.
225     *
226     * 2. Redistributions in binary form must reproduce the above copyright
227     * notice, this list of conditions and the following disclaimer in
228     * the documentation and/or other materials provided with the
229     * distribution.
230     *
231     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
232     * and "Vovida Open Communication Application Library (VOCAL)" must
233     * not be used to endorse or promote products derived from this
234     * software without prior written permission. For written
235     * permission, please contact vocal@vovida.org.
236     *
237     * 4. Products derived from this software may not be called "VOCAL", nor
238     * may "VOCAL" appear in their name, without prior written
239     * permission of Vovida Networks, Inc.
240     *
241     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
242     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
243     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
244     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
245     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
246     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
247     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
248     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
249     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
250     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
252     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
253     * DAMAGE.
254     *
255     * ====================================================================
256     *
257     * This software consists of voluntary contributions made by Vovida
258     * Networks, Inc. and many individuals on behalf of Vovida Networks,
259     * Inc. For more information on Vovida Networks, Inc., please see
260     * <http://www.vovida.org/>.
261     *
262     */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27