/[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 4602 - (hide annotations) (download)
Thu May 12 01:27:52 2005 UTC (14 years, 8 months ago) by derek
Original Path: main/sip/resiprocate/dum/test/basicRegister.cxx
File size: 6474 byte(s)
added missing vocal licences
1 jason 2941 #include "resiprocate/SipStack.hxx"
2     #include "resiprocate/dum/ClientAuthManager.hxx"
3     #include "resiprocate/dum/ClientRegistration.hxx"
4     #include "resiprocate/dum/DialogUsageManager.hxx"
5 derek 2850 #include "resiprocate/dum/InviteSessionHandler.hxx"
6 jason 4010 #include "resiprocate/dum/MasterProfile.hxx"
7 derek 2850 #include "resiprocate/dum/RegistrationHandler.hxx"
8 alan 2861 #include "resiprocate/os/Log.hxx"
9 alan 2906 #include "resiprocate/os/Logger.hxx"
10     #include "resiprocate/os/Subsystem.hxx"
11 derek 2955 #include "resiprocate/dum/AppDialogSet.hxx"
12     #include "resiprocate/dum/AppDialog.hxx"
13 derek 2850
14 derek 2955
15 alan 2906 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
16    
17 derek 2850 using namespace resip;
18 jason 4010 using namespace std;
19 derek 2850
20 derek 2955 class RegisterAppDialogSet : public AppDialogSet
21     {
22     public:
23     RegisterAppDialogSet(DialogUsageManager& dum) : AppDialogSet(dum)
24     {}
25     };
26    
27    
28    
29 derek 2850 class Client : public ClientRegistrationHandler
30     {
31     public:
32 derek 2984 Client() : done(false), removing(true) {}
33 derek 2850
34 jason 2941 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
35 derek 2850 {
36 jason 4335 InfoLog( << "Client::Success: " << endl << response );
37     if (removing)
38     {
39     removing = false;
40 derek 2929 #ifdef WIN32
41 jason 4335 Sleep(2000);
42 derek 2929 #else
43 jason 4335 sleep(5);
44 derek 2929 #endif
45 jason 4335 //ClientRegistration* foo = h.get();
46     h->removeAll();
47     }
48     else
49     {
50     done = true;
51     }
52 derek 2850 }
53    
54 sgodin 3458 virtual void onRemoved(ClientRegistrationHandle)
55     {
56 jason 4335 InfoLog ( << "Client::onRemoved ");
57 sgodin 3458 }
58    
59 jason 2941 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
60 derek 2850 {
61 jason 4335 InfoLog ( << "Client::onFailure: " << response );
62     done = true;
63 derek 2850 }
64 alan 2906
65 jason 4335 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response)
66     {
67     return 0;
68     }
69    
70    
71 derek 2850 bool done;
72 derek 2984 bool removing;
73 derek 2850 };
74    
75     /*
76 jason 4335 class RegistrationServer : public ServerRegistrationHandler
77     {
78     public:
79     RegistrationServer() : done(false) {}
80     virtual void onRefresh(ServerRegistrationHandle, const SipMessage& reg)=0;
81 derek 2850
82 jason 4335 /// called when one of the contacts is removed
83     virtual void onRemoveOne(ServerRegistrationHandle, const SipMessage& reg)=0;
84 derek 2850
85 jason 4335 /// Called when all the contacts are removed
86     virtual void onRemoveAll(ServerRegistrationHandle, const SipMessage& reg)=0;
87 derek 2850
88 jason 4335 /// Called when a new contact is added. This is after authentication has
89     /// all sucseeded
90     virtual void onAdd(ServerRegistrationHandle, const SipMessage& reg)=0;
91 derek 2850
92 jason 4335 /// Called when an registration expires
93     virtual void onExpired(ServerRegistrationHandle, const NameAddr& contact)=0;
94    
95     private:
96     bool done;
97     };
98 derek 2850 */
99    
100     int
101     main (int argc, char** argv)
102     {
103 derek 4601 int level=(int)Log::Debug;
104 sgodin 3458 if (argc >1 ) level = atoi(argv[1]);
105 alan 2877
106 sgodin 3458 Log::initialize(Log::Cout, (resip::Log::Level)level, argv[0]);
107 alan 2877
108 derek 2850 Client client;
109 jason 4010 MasterProfile profile;
110     auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager);
111 derek 2929
112 jason 4335 SipStack stack;
113     DialogUsageManager clientDum(stack);
114 derek 4601 clientDum.addTransport(UDP, 15066);
115 jason 4010 clientDum.setMasterProfile(&profile);
116 alan 2895
117 derek 2850 clientDum.setClientRegistrationHandler(&client);
118 sgodin 3458 clientDum.setClientAuthManager(clientAuth);
119 jason 4010 clientDum.getMasterProfile()->setDefaultRegistrationTime(70);
120 derek 2991
121 derek 4601 NameAddr from("sip:derek@foo.net");
122 jason 4010 clientDum.getMasterProfile()->setDefaultFrom(from);
123 alan 2877
124 derek 2991
125 derek 4601 profile.setDigestCredential( "foo.net", "derek", "derek");
126    
127 fluffy 2882
128 jason 3150 SipMessage & regMessage = clientDum.makeRegistration(from, new RegisterAppDialogSet(clientDum));
129 derek 2984 NameAddr contact;
130 derek 2991 // contact.uri().user() = "13015604286";
131     // regMessage.header(h_Contacts).push_back(contact);
132 alan 2877
133 alan 2906 InfoLog( << regMessage << "Generated register: " << endl << regMessage );
134 fluffy 2870 clientDum.send( regMessage );
135 alan 2877
136     int n = 0;
137     while ( !client.done )
138    
139 derek 2850 {
140 jason 4335 FdSet fdset;
141 fluffy 2870
142 sgodin 4342 stack.buildFdSet(fdset);
143 jason 4335 int err = fdset.selectMilliSeconds(100);
144     assert ( err != -1 );
145 alan 2877
146 sgodin 4342 stack.process(fdset);
147     while(clientDum.process());
148    
149 jason 4335 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
150 derek 2850 }
151 derek 2984 return 0;
152 derek 2850 }
153 derek 4602
154     /* ====================================================================
155     * The Vovida Software License, Version 1.0
156     *
157     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
158     *
159     * Redistribution and use in source and binary forms, with or without
160     * modification, are permitted provided that the following conditions
161     * are met:
162     *
163     * 1. Redistributions of source code must retain the above copyright
164     * notice, this list of conditions and the following disclaimer.
165     *
166     * 2. Redistributions in binary form must reproduce the above copyright
167     * notice, this list of conditions and the following disclaimer in
168     * the documentation and/or other materials provided with the
169     * distribution.
170     *
171     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
172     * and "Vovida Open Communication Application Library (VOCAL)" must
173     * not be used to endorse or promote products derived from this
174     * software without prior written permission. For written
175     * permission, please contact vocal@vovida.org.
176     *
177     * 4. Products derived from this software may not be called "VOCAL", nor
178     * may "VOCAL" appear in their name, without prior written
179     * permission of Vovida Networks, Inc.
180     *
181     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
182     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
183     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
184     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
185     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
186     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
187     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
188     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
189     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
190     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
191     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
192     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
193     * DAMAGE.
194     *
195     * ====================================================================
196     *
197     * This software consists of voluntary contributions made by Vovida
198     * Networks, Inc. and many individuals on behalf of Vovida Networks,
199     * Inc. For more information on Vovida Networks, Inc., please see
200     * <http://www.vovida.org/>.
201     *
202     */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27