|
reSIProcate/DialogUsageManager
9694
|
00001 #ifdef HAVE_CONFIG_H 00002 #include "config.h" 00003 #endif 00004 00005 #include "resip/stack/SipStack.hxx" 00006 #include "resip/dum/ClientAuthManager.hxx" 00007 #include "resip/dum/ClientRegistration.hxx" 00008 #include "resip/dum/DialogUsageManager.hxx" 00009 #include "resip/dum/MasterProfile.hxx" 00010 #include "resip/dum/RegistrationHandler.hxx" 00011 #include "rutil/Log.hxx" 00012 #include "rutil/Logger.hxx" 00013 #include "rutil/Subsystem.hxx" 00014 #include "resip/dum/KeepAliveManager.hxx" 00015 00016 #if defined (USE_SSL) 00017 #if defined(WIN32) 00018 #include "resip/stack/ssl/WinSecurity.hxx" 00019 #else 00020 #include "resip/stack/ssl/Security.hxx" 00021 #endif 00022 #endif 00023 00024 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00025 00026 using namespace resip; 00027 using namespace std; 00028 00029 class ClientHandler : public ClientRegistrationHandler 00030 { 00031 public: 00032 ClientHandler() : done(false) {} 00033 00034 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response) 00035 { 00036 InfoLog( << "ClientHandler::onSuccess: " << endl ); 00037 00038 resipCerr << "Pausing before unregister" << endl; 00039 00040 #ifdef WIN32 00041 Sleep(2000); 00042 #else 00043 sleep(5); 00044 #endif 00045 h->removeAll(); 00046 } 00047 00048 virtual void onRemoved(ClientRegistrationHandle, const SipMessage& response) 00049 { 00050 InfoLog ( << "ClientHandler::onRemoved "); 00051 done = true; 00052 } 00053 00054 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response) 00055 { 00056 InfoLog ( << "ClientHandler::onFailure: " << response ); 00057 } 00058 00059 virtual int onRequestRetry(ClientRegistrationHandle, int retrySeconds, const SipMessage& response) 00060 { 00061 InfoLog ( << "ClientHandler:onRequestRetry"); 00062 return -1; 00063 } 00064 00065 bool done; 00066 }; 00067 00068 00069 00070 int 00071 main (int argc, char** argv) 00072 { 00073 00074 if ( argc < 3 ) { 00075 resipCout << "usage: " << argv[0] << " sip:user passwd\n"; 00076 return 0; 00077 } 00078 00079 Log::initialize(Log::Cout, Log::Stack, argv[0]); 00080 00081 NameAddr userAor(argv[1]); 00082 Data passwd(argv[2]); 00083 00084 #ifdef USE_SSL 00085 #ifdef WIN32 00086 Security* security = new WinSecurity; 00087 #else 00088 Security* security = new Security; 00089 #endif 00090 SipStack stack(security); 00091 #else 00092 SipStack stack; 00093 #endif 00094 00095 DialogUsageManager clientDum(stack); 00096 SharedPtr<MasterProfile> profile(new MasterProfile); 00097 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager); 00098 ClientHandler clientHandler; 00099 00100 clientDum.addTransport(UDP, 0, V4); 00101 // clientDum.addTransport(UDP, 0, V6); 00102 clientDum.addTransport(TCP, 0, V4); 00103 // clientDum.addTransport(TCP, 0, V6); 00104 #ifdef USE_SSL 00105 clientDum.addTransport(TLS, 0, V4); 00106 // clientDum.addTransport(TLS, 0, V6); 00107 #endif 00108 clientDum.setMasterProfile(profile); 00109 clientDum.setClientRegistrationHandler(&clientHandler); 00110 clientDum.setClientAuthManager(clientAuth); 00111 clientDum.getMasterProfile()->setDefaultRegistrationTime(70); 00112 00113 // keep alive test. 00114 auto_ptr<KeepAliveManager> keepAlive(new KeepAliveManager); 00115 clientDum.setKeepAliveManager(keepAlive); 00116 00117 clientDum.getMasterProfile()->setDefaultFrom(userAor); 00118 profile->setDigestCredential(userAor.uri().host(), 00119 userAor.uri().user(), 00120 passwd); 00121 00122 SharedPtr<SipMessage> regMessage = clientDum.makeRegistration(userAor); 00123 NameAddr contact; 00124 00125 clientDum.send( regMessage ); 00126 00127 int n = 0; 00128 while ( !clientHandler.done ) 00129 { 00130 stack.process(100); 00131 while(clientDum.process()); 00132 00133 if (n == 1000) clientHandler.done = true; 00134 00135 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b'; 00136 } 00137 return 0; 00138 } 00139 00140 /* ==================================================================== 00141 * The Vovida Software License, Version 1.0 00142 * 00143 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00144 * 00145 * Redistribution and use in source and binary forms, with or without 00146 * modification, are permitted provided that the following conditions 00147 * are met: 00148 * 00149 * 1. Redistributions of source code must retain the above copyright 00150 * notice, this list of conditions and the following disclaimer. 00151 * 00152 * 2. Redistributions in binary form must reproduce the above copyright 00153 * notice, this list of conditions and the following disclaimer in 00154 * the documentation and/or other materials provided with the 00155 * distribution. 00156 * 00157 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00158 * and "Vovida Open Communication Application Library (VOCAL)" must 00159 * not be used to endorse or promote products derived from this 00160 * software without prior written permission. For written 00161 * permission, please contact vocal@vovida.org. 00162 * 00163 * 4. Products derived from this software may not be called "VOCAL", nor 00164 * may "VOCAL" appear in their name, without prior written 00165 * permission of Vovida Networks, Inc. 00166 * 00167 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00168 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00169 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00170 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00171 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00172 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00173 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00174 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00175 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00176 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00177 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00178 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00179 * DAMAGE. 00180 * 00181 * ==================================================================== 00182 * 00183 * This software consists of voluntary contributions made by Vovida 00184 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00185 * Inc. For more information on Vovida Networks, Inc., please see 00186 * <http://www.vovida.org/>. 00187 * 00188 */
1.7.5.1