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

Contents of /main/sip/resiprocate/dum/test/basicMessage.cxx

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27