|
reSIProcate/DialogUsageManager
9694
|
00001 #include "resip/stack/SdpContents.hxx" 00002 #include "resip/stack/PlainContents.hxx" 00003 #include "resip/stack/SipMessage.hxx" 00004 #include "resip/stack/ShutdownMessage.hxx" 00005 #include "resip/stack/SipStack.hxx" 00006 #include "resip/dum/ClientAuthManager.hxx" 00007 #include "resip/dum/ClientInviteSession.hxx" 00008 #include "resip/dum/ClientRegistration.hxx" 00009 #include "resip/dum/DialogUsageManager.hxx" 00010 #include "resip/dum/DumShutdownHandler.hxx" 00011 #include "resip/dum/InviteSessionHandler.hxx" 00012 #include "resip/dum/RequestValidationHandler.hxx" 00013 #include "resip/dum/MasterProfile.hxx" 00014 #include "resip/dum/RegistrationHandler.hxx" 00015 #include "resip/dum/ServerInviteSession.hxx" 00016 #include "resip/dum/ServerOutOfDialogReq.hxx" 00017 #include "resip/dum/OutOfDialogHandler.hxx" 00018 #include "resip/dum/AppDialog.hxx" 00019 #include "resip/dum/AppDialogSet.hxx" 00020 #include "rutil/Log.hxx" 00021 #include "rutil/Logger.hxx" 00022 #include "rutil/Random.hxx" 00023 #include "rutil/WinLeakCheck.hxx" 00024 00025 #include <sstream> 00026 #include <time.h> 00027 00028 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00029 00030 using namespace resip; 00031 using namespace std; 00032 00033 class TestInviteSessionHandler : public InviteSessionHandler, public RequestValidationHandler 00034 { 00035 public: 00036 Data name; 00037 bool registered; 00038 ClientRegistrationHandle registerHandle; 00039 00040 int mInvalidMethod, mInvalidScheme, mInvalidRequiredOptions, m100RelNotSupportedByRemote, mInvalidContentType, mInvalidContentEncoding; 00041 int mInvalidContentLanguage, mInvalidAccept; 00042 00043 00044 TestInviteSessionHandler(const Data& n) : name(n), registered(false) 00045 { 00046 mInvalidMethod = 0; 00047 mInvalidScheme = 0; 00048 mInvalidRequiredOptions = 0; 00049 m100RelNotSupportedByRemote = 0; 00050 mInvalidContentType = 0; 00051 mInvalidContentEncoding = 0; 00052 mInvalidContentLanguage = 0; 00053 mInvalidAccept = 0; 00054 } 00055 00056 virtual ~TestInviteSessionHandler() 00057 { 00058 } 00059 00060 virtual void onNewSession(ClientInviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg) 00061 { 00062 cout << name << ": ClientInviteSession-onNewSession - " << msg.brief() << endl; 00063 } 00064 00065 virtual void onNewSession(ServerInviteSessionHandle, InviteSession::OfferAnswerType oat, const SipMessage& msg) 00066 { 00067 cout << name << ": ServerInviteSession-onNewSession - " << msg.brief() << endl; 00068 } 00069 00070 virtual void onFailure(ClientInviteSessionHandle, const SipMessage& msg) 00071 { 00072 cout << name << ": ClientInviteSession-onFailure - " << msg.brief() << endl; 00073 } 00074 00075 virtual void onProvisional(ClientInviteSessionHandle, const SipMessage& msg) 00076 { 00077 cout << name << ": ClientInviteSession-onProvisional - " << msg.brief() << endl; 00078 } 00079 00080 virtual void onConnected(ClientInviteSessionHandle, const SipMessage& msg) 00081 { 00082 cout << name << ": ClientInviteSession-onConnected - " << msg.brief() << endl; 00083 } 00084 00085 virtual void onStaleCallTimeout(ClientInviteSessionHandle handle) 00086 { 00087 cout << name << ": ClientInviteSession-onStaleCallTimeout" << endl; 00088 } 00089 00090 virtual void onConnected(InviteSessionHandle, const SipMessage& msg) 00091 { 00092 cout << name << ": InviteSession-onConnected - " << msg.brief() << endl; 00093 } 00094 00095 virtual void onRedirected(ClientInviteSessionHandle, const SipMessage& msg) 00096 { 00097 cout << name << ": ClientInviteSession-onRedirected - " << msg.brief() << endl; 00098 } 00099 00100 virtual void onTerminated(InviteSessionHandle, InviteSessionHandler::TerminatedReason reason, const SipMessage* msg) 00101 { 00102 cout << name << ": InviteSession-onTerminated - " << msg->brief() << endl; 00103 } 00104 00105 virtual void onAnswer(InviteSessionHandle, const SipMessage& msg, const SdpContents& sdp) 00106 { 00107 cout << name << ": InviteSession-onAnswer(SDP)" << endl; 00108 } 00109 00110 virtual void onOffer(InviteSessionHandle is, const SipMessage& msg, const SdpContents& sdp) 00111 { 00112 cout << name << ": InviteSession-onOffer(SDP)" << endl; 00113 } 00114 00115 virtual void onEarlyMedia(ClientInviteSessionHandle, const SipMessage& msg, const SdpContents& sdp) 00116 { 00117 cout << name << ": InviteSession-onEarlyMedia(SDP)" << endl; 00118 } 00119 00120 virtual void onOfferRequired(InviteSessionHandle, const SipMessage& msg) 00121 { 00122 cout << name << ": InviteSession-onOfferRequired - " << msg.brief() << endl; 00123 } 00124 00125 virtual void onOfferRejected(InviteSessionHandle, const SipMessage* msg) 00126 { 00127 cout << name << ": InviteSession-onOfferRejected" << endl; 00128 } 00129 00130 virtual void onRefer(InviteSessionHandle, ServerSubscriptionHandle, const SipMessage& msg) 00131 { 00132 cout << name << ": InviteSession-onRefer - " << msg.brief() << endl; 00133 } 00134 00135 virtual void onReferAccepted(InviteSessionHandle, ClientSubscriptionHandle, const SipMessage& msg) 00136 { 00137 cout << name << ": InviteSession-onReferAccepted - " << msg.brief() << endl; 00138 } 00139 00140 virtual void onReferRejected(InviteSessionHandle, const SipMessage& msg) 00141 { 00142 cout << name << ": InviteSession-onReferRejected - " << msg.brief() << endl; 00143 } 00144 00145 virtual void onReferNoSub(InviteSessionHandle, const SipMessage& msg) 00146 { 00147 cout << name << ": InviteSession-onReferNoSub - " << msg.brief() << endl; 00148 } 00149 00150 virtual void onInfo(InviteSessionHandle, const SipMessage& msg) 00151 { 00152 cout << name << ": InviteSession-onInfo - " << msg.brief() << endl; 00153 } 00154 00155 virtual void onInfoSuccess(InviteSessionHandle, const SipMessage& msg) 00156 { 00157 cout << name << ": InviteSession-onInfoSuccess - " << msg.brief() << endl; 00158 } 00159 00160 virtual void onInfoFailure(InviteSessionHandle, const SipMessage& msg) 00161 { 00162 cout << name << ": InviteSession-onInfoFailure - " << msg.brief() << endl; 00163 } 00164 00165 virtual void onMessage(InviteSessionHandle, const SipMessage& msg) 00166 { 00167 cout << name << ": InviteSession-onMessage - " << msg.brief() << endl; 00168 } 00169 00170 virtual void onMessageSuccess(InviteSessionHandle, const SipMessage& msg) 00171 { 00172 cout << name << ": InviteSession-onMessageSuccess - " << msg.brief() << endl; 00173 } 00174 00175 virtual void onMessageFailure(InviteSessionHandle, const SipMessage& msg) 00176 { 00177 cout << name << ": InviteSession-onMessageFailure - " << msg.brief() << endl; 00178 } 00179 00180 virtual void onForkDestroyed(ClientInviteSessionHandle) 00181 { 00182 cout << name << ": ClientInviteSession-onForkDestroyed" << endl; 00183 } 00184 00185 void onInvalidMethod(const resip::SipMessage&) 00186 { 00187 cout << name << ": onInvalidMethod" << endl; 00188 mInvalidMethod++; 00189 } 00190 00191 void onInvalidScheme(const resip::SipMessage&) 00192 { 00193 cout << name << ": onInvalidSchema" << endl; 00194 mInvalidScheme++; 00195 } 00196 00197 void onInvalidRequiredOptions(const resip::SipMessage&) 00198 { 00199 cout << name << ": onInvalidRequiredOptions" << endl; 00200 mInvalidRequiredOptions++; 00201 } 00202 00203 void on100RelNotSupportedByRemote(const resip::SipMessage&) 00204 { 00205 cout << name << ": on100RelNotSupportedByRemote" << endl; 00206 m100RelNotSupportedByRemote++; 00207 } 00208 00209 void onInvalidContentType(const resip::SipMessage&) 00210 { 00211 cout << name << ": onInvalidContentType" << endl; 00212 mInvalidContentType++; 00213 } 00214 00215 void onInvalidContentEncoding(const resip::SipMessage&) 00216 { 00217 cout << name << ": onInvalidContentEncoding" << endl; 00218 mInvalidContentEncoding++; 00219 } 00220 00221 void onInvalidContentLanguage(const resip::SipMessage&) 00222 { 00223 cout << name << ": onInvalidContentLanguage" << endl; 00224 mInvalidContentLanguage++; 00225 } 00226 00227 void onInvalidAccept(const resip::SipMessage&) 00228 { 00229 cout << name << ": onInvalidAccept" << endl; 00230 mInvalidAccept++; 00231 } 00232 00233 }; 00234 00235 int 00236 main (int argc, char** argv) 00237 { 00238 Log::initialize(Log::Cout, resip::Log::Debug, argv[0]); 00239 00240 NameAddr uacAor("sip:127.0.0.1:17298"); 00241 NameAddr uasAor("sip:127.0.0.1:17299"); 00242 00243 SdpContents* dummySdp; 00244 HeaderFieldValue* hfv; 00245 Data* txt; 00246 00247 txt = new Data("v=0\r\n" 00248 "o=1900 369696545 369696545 IN IP4 192.168.2.15\r\n" 00249 "s=X-Lite\r\n" 00250 "c=IN IP4 192.168.2.15\r\n" 00251 "t=0 0\r\n" 00252 "m=audio 8000 RTP/AVP 8 3 98 97 101\r\n" 00253 "a=rtpmap:8 pcma/8000\r\n" 00254 "a=rtpmap:3 gsm/8000\r\n" 00255 "a=rtpmap:98 iLBC\r\n" 00256 "a=rtpmap:97 speex/8000\r\n" 00257 "a=rtpmap:101 telephone-event/8000\r\n" 00258 "a=fmtp:101 0-15\r\n"); 00259 00260 hfv = new HeaderFieldValue(txt->data(), (unsigned int)txt->size()); 00261 Mime type("application", "sdp"); 00262 dummySdp = new SdpContents(*hfv, type); 00263 00264 //set up UAC 00265 SipStack stackUac; 00266 DialogUsageManager* dumUac = new DialogUsageManager(stackUac); 00267 dumUac->addTransport(UDP, 17298); 00268 dumUac->addTransport(TCP, 17298); 00269 00270 SharedPtr<MasterProfile> uacMasterProfile(new MasterProfile); 00271 auto_ptr<ClientAuthManager> uacAuth(new ClientAuthManager); 00272 dumUac->setMasterProfile(uacMasterProfile); 00273 dumUac->setClientAuthManager(uacAuth); 00274 00275 TestInviteSessionHandler uac("UAC"); 00276 dumUac->setInviteSessionHandler(&uac); 00277 dumUac->setRequestValidationHandler(&uac); 00278 00279 dumUac->getMasterProfile()->setDefaultFrom(uacAor); 00280 00281 //set up UAS 00282 SipStack stackUas; 00283 DialogUsageManager* dumUas = new DialogUsageManager(stackUas); 00284 dumUas->addTransport(UDP, 17299); 00285 dumUas->addTransport(TCP, 17299); 00286 00287 SharedPtr<MasterProfile> uasMasterProfile(new MasterProfile); 00288 std::auto_ptr<ClientAuthManager> uasAuth(new ClientAuthManager); 00289 dumUas->setMasterProfile(uasMasterProfile); 00290 dumUas->setClientAuthManager(uasAuth); 00291 00292 dumUas->getMasterProfile()->setDefaultFrom(uasAor); 00293 00294 TestInviteSessionHandler uas("UAS"); 00295 dumUas->setInviteSessionHandler(&uas); 00296 dumUas->setRequestValidationHandler(&uas); 00297 00298 // First test: invalid method 00299 dumUac->send(dumUac->makeOutOfDialogRequest(uasAor, MESSAGE)); 00300 00301 // Second test: invalid scheme 00302 SharedPtr<SipMessage> invalidSchemeMsg = dumUac->makeOutOfDialogRequest(uasAor, OPTIONS); 00303 invalidSchemeMsg->header(h_RequestLine).uri().scheme() = "tel"; 00304 dumUac->send(invalidSchemeMsg); 00305 00306 // !fjoanis! TODO: Add more tests 00307 00308 assert(uas.mInvalidMethod == 0); 00309 assert(uas.mInvalidScheme == 0); 00310 assert(uas.mInvalidRequiredOptions == 0); 00311 assert(uas.m100RelNotSupportedByRemote == 0); 00312 assert(uas.mInvalidContentType == 0); 00313 assert(uas.mInvalidContentEncoding == 0); 00314 assert(uas.mInvalidContentLanguage == 0); 00315 assert(uas.mInvalidAccept == 0); 00316 00317 assert(uac.mInvalidMethod == 0); 00318 assert(uac.mInvalidScheme == 0); 00319 assert(uac.mInvalidRequiredOptions == 0); 00320 assert(uac.m100RelNotSupportedByRemote == 0); 00321 assert(uac.mInvalidContentType == 0); 00322 assert(uac.mInvalidContentEncoding == 0); 00323 assert(uac.mInvalidContentLanguage == 0); 00324 assert(uac.mInvalidAccept == 0); 00325 00326 // Now give them some cycles 00327 for(int i=0;i<10;i++) 00328 { 00329 { 00330 stackUac.process(50); 00331 while(dumUac->process()); 00332 } 00333 { 00334 stackUas.process(50); 00335 while(dumUas->process()); 00336 } 00337 } 00338 00339 assert(uas.mInvalidMethod == 1); 00340 assert(uas.mInvalidScheme == 1); 00341 assert(uas.mInvalidRequiredOptions == 0); 00342 assert(uas.m100RelNotSupportedByRemote == 0); 00343 assert(uas.mInvalidContentType == 0); 00344 assert(uas.mInvalidContentEncoding == 0); 00345 assert(uas.mInvalidContentLanguage == 0); 00346 assert(uas.mInvalidAccept == 0); 00347 00348 assert(uac.mInvalidMethod == 0); 00349 assert(uac.mInvalidScheme == 0); 00350 assert(uac.mInvalidRequiredOptions == 0); 00351 assert(uac.m100RelNotSupportedByRemote == 0); 00352 assert(uac.mInvalidContentType == 0); 00353 assert(uac.mInvalidContentEncoding == 0); 00354 assert(uac.mInvalidContentLanguage == 0); 00355 assert(uac.mInvalidAccept == 0); 00356 00357 delete dumUac; 00358 delete dumUas; 00359 delete dummySdp; 00360 delete txt; 00361 delete hfv; 00362 00363 cout << "!!!!!!!!!!!!!!!!!! Successful !!!!!!!!!! " << endl; 00364 #if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK) 00365 } 00366 #endif 00367 00368 } 00369 00370 /* ==================================================================== 00371 * The Vovida Software License, Version 1.0 00372 * 00373 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00374 * 00375 * Redistribution and use in source and binary forms, with or without 00376 * modification, are permitted provided that the following conditions 00377 * are met: 00378 * 00379 * 1. Redistributions of source code must retain the above copyright 00380 * notice, this list of conditions and the following disclaimer. 00381 * 00382 * 2. Redistributions in binary form must reproduce the above copyright 00383 * notice, this list of conditions and the following disclaimer in 00384 * the documentation and/or other materials provided with the 00385 * distribution. 00386 * 00387 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00388 * and "Vovida Open Communication Application Library (VOCAL)" must 00389 * not be used to endorse or promote products derived from this 00390 * software without prior written permission. For written 00391 * permission, please contact vocal@vovida.org. 00392 * 00393 * 4. Products derived from this software may not be called "VOCAL", nor 00394 * may "VOCAL" appear in their name, without prior written 00395 * permission of Vovida Networks, Inc. 00396 * 00397 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00398 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00399 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00400 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00401 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00402 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00403 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00404 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00405 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00406 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00407 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00408 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00409 * DAMAGE. 00410 * 00411 * ==================================================================== 00412 * 00413 * This software consists of voluntary contributions made by Vovida 00414 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00415 * Inc. For more snformation on Vovida Networks, Inc., please see 00416 * <http://www.vovida.org/>. 00417 * 00418 */
1.7.5.1