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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.26