/[resiprocate]/main/resip/dum/test/basicPublication.cxx
ViewVC logotype

Contents of /main/resip/dum/test/basicPublication.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8816 - (show annotations) (download)
Wed Sep 22 23:24:09 2010 UTC (9 years, 2 months ago) by arosenberg
File size: 7300 byte(s)
Add a new test for simple PUBLISH handling.
1 // made by Aron Rosenberg
2 // Will do an initial PUBLICATION of pidf presence
3 // then do 2 in-dialog updates, then quit
4 // If you define PUB_REALLY_FAST then overlapping
5 // or queued PUBLISH'es will be created.
6
7 #include "rutil/Log.hxx"
8 #include "rutil/Logger.hxx"
9 #include "rutil/Subsystem.hxx"
10 #include "resip/dum/ClientAuthManager.hxx"
11 #include "resip/dum/DialogUsageManager.hxx"
12 #include "resip/dum/InviteSessionHandler.hxx"
13 #include "resip/dum/MasterProfile.hxx"
14 #include "resip/dum/Profile.hxx"
15 #include "resip/dum/UserProfile.hxx"
16 #include "resip/dum/PublicationHandler.hxx"
17 #include "resip/dum/ClientPublication.hxx"
18
19 #include "resip/dum/AppDialogSet.hxx"
20 #include "resip/dum/AppDialog.hxx"
21 #include "resip/stack/PlainContents.hxx"
22 #include "resip/stack/Pidf.hxx"
23 #include "rutil/Random.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 //#define PUB_REALLY_FAST 1// Will create overlapping PUBLISH'es
35
36 int transCount = 0;
37
38 class ClientPubHandler : public ClientPublicationHandler {
39 public:
40 ClientPubHandler() {}
41 virtual void onSuccess(ClientPublicationHandle cph, const SipMessage& status)
42 {
43 handle = cph;
44 InfoLog(<<"ClientPubHandler::onSuccess\n");
45 transCount--;
46 }
47 virtual void onRemove(ClientPublicationHandle cph, const SipMessage& status)
48 {
49 InfoLog(<<"ClientPubHandler::onRemove\n");
50 handle = ClientPublicationHandle();
51 transCount--;
52 }
53 virtual int onRequestRetry(ClientPublicationHandle cph, int retrySeconds, const SipMessage& status)
54 {
55 handle = cph;
56 InfoLog(<<"ClientPubHandler::onRequestRetry\n");
57 return 30;
58 }
59 virtual void onFailure(ClientPublicationHandle cph, const SipMessage& status)
60 {
61 InfoLog(<<"ClientPubHandler::onFailure\n");
62 handle = ClientPublicationHandle();
63 transCount--;
64 }
65 ClientPublicationHandle handle;
66 };
67
68
69 /*****************************************************************************/
70
71 int main(int argc, char *argv[])
72 {
73 if( (argc < 5) || (argc > 6) ) {
74 cout << "usage: " << argv[0] << " sip:aor user passwd realm [port]\n";
75 return 0;
76 }
77
78 Log::initialize(Log::VSDebugWindow, Log::Debug, argv[0]);
79
80 bool first = true;
81 string aor(argv[1]);
82 string user(argv[2]);
83 string passwd(argv[3]);
84 string realm(argv[4]);
85 int port = 5060;
86 if(argc == 6) {
87 string temp(argv[5]);
88 istringstream src(temp);
89 src >> port;
90 }
91 Data eventName("presence");
92
93 InfoLog(<< "log: aor: " << aor << ", port: " << port << "\n");
94 InfoLog(<< "user: " << user << ", passwd: " << passwd << ", realm: " << realm << "\n");
95
96 // sip logic
97 SharedPtr<MasterProfile> profile(new MasterProfile);
98 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager());
99
100 SipStack clientStack;
101 DialogUsageManager clientDum(clientStack);
102 clientDum.addTransport(UDP, port);
103 clientDum.setMasterProfile(profile);
104
105 clientDum.setClientAuthManager(clientAuth);
106 clientDum.getMasterProfile()->addSupportedMethod(PUBLISH);
107 clientDum.getMasterProfile()->addSupportedMimeType(PUBLISH,Pidf::getStaticType());
108
109 ClientPubHandler cph;
110 clientDum.addClientPublicationHandler(eventName,&cph);
111
112 /////
113 NameAddr naAor(aor.c_str());
114 profile->setDefaultFrom(naAor);
115 profile->setDigestCredential(realm.c_str(), user.c_str(), passwd.c_str());
116
117 Pidf pidf;
118 pidf.setSimpleStatus(true);
119 pidf.setEntity(naAor.uri());
120 pidf.setSimpleId(Random::getRandomHex(3));
121
122 {
123 SharedPtr<SipMessage> pubMessage = clientDum.makePublication(naAor, profile,pidf,eventName,120);
124 InfoLog( << "Generated publish: " << endl << *pubMessage );
125 transCount++;
126 clientDum.send( pubMessage );
127 }
128
129 int nAttempts = 0;
130 bool bKeepGoing = true;
131 while(bKeepGoing)
132 {
133 FdSet fdset;
134
135 // Should these be buildFdSet on the DUM?
136 clientStack.buildFdSet(fdset);
137 int err = fdset.selectMilliSeconds(100);
138 assert ( err != -1 );
139
140 clientStack.process(fdset);
141 while(clientDum.process());
142 //if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
143
144 if(transCount == 0) // No pending transactions.
145 {
146 nAttempts++;
147 if(nAttempts > 2)
148 bKeepGoing = false;
149 else
150 {
151 int nLoops = 1;
152 #ifdef PUB_REALLY_FAST
153 nLoops = 2;
154 #endif
155 for(int i = 0; i < nLoops; i++)
156 {
157 pidf.setSimpleStatus(!pidf.getSimpleStatus()); //toggle status
158 transCount++;
159 cph.handle->update(&pidf);
160 }
161 }
162 }
163 }
164
165 return 0;
166 }
167
168 /* ====================================================================
169 * The Vovida Software License, Version 1.0
170 *
171 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
172 *
173 * Redistribution and use in source and binary forms, with or without
174 * modification, are permitted provided that the following conditions
175 * are met:
176 *
177 * 1. Redistributions of source code must retain the above copyright
178 * notice, this list of conditions and the following disclaimer.
179 *
180 * 2. Redistributions in binary form must reproduce the above copyright
181 * notice, this list of conditions and the following disclaimer in
182 * the documentation and/or other materials provided with the
183 * distribution.
184 *
185 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
186 * and "Vovida Open Communication Application Library (VOCAL)" must
187 * not be used to endorse or promote products derived from this
188 * software without prior written permission. For written
189 * permission, please contact vocal@vovida.org.
190 *
191 * 4. Products derived from this software may not be called "VOCAL", nor
192 * may "VOCAL" appear in their name, without prior written
193 * permission of Vovida Networks, Inc.
194 *
195 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
196 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
197 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
198 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
199 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
200 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
201 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
202 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
203 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
204 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
205 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
206 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
207 * DAMAGE.
208 *
209 * ====================================================================
210 *
211 * This software consists of voluntary contributions made by Vovida
212 * Networks, Inc. and many individuals on behalf of Vovida Networks,
213 * Inc. For more information on Vovida Networks, Inc., please see
214 * <http://www.vovida.org/>.
215 *
216 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27