|
reSIProcate/stack
9694
|
00001 #ifndef WIN32 00002 #include <sys/time.h> 00003 #include <unistd.h> 00004 #include <sys/socket.h> 00005 #include <netinet/in.h> 00006 #include <arpa/inet.h> 00007 #endif 00008 00009 #include <sys/types.h> 00010 #include <iostream> 00011 #include <memory> 00012 00013 #include "resip/stack/Helper.hxx" 00014 #include "resip/stack/SipMessage.hxx" 00015 #include "resip/stack/Uri.hxx" 00016 #include "resip/stack/SipStack.hxx" 00017 #include "resip/stack/DeprecatedDialog.hxx" 00018 #include "rutil/Logger.hxx" 00019 #include "rutil/ThreadIf.hxx" 00020 00021 using namespace resip; 00022 using namespace std; 00023 00024 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00025 00026 class Client 00027 { 00028 public: 00029 Client(TransportType transport, const NameAddr& contact, const NameAddr& target) 00030 : mStack(), 00031 mContact(contact), 00032 mTarget(target), 00033 mWaitingForBye200(false) 00034 { 00035 mStack.addTransport(transport, contact.uri().port()); 00036 auto_ptr<SipMessage> message(Helper::makeInvite( target, mContact, mContact)); 00037 mStack.send(*message); 00038 } 00039 00040 void process(unsigned int timeoutMs) 00041 { 00042 mStack.process(timeoutMs); 00043 00044 SipMessage* received = mStack.receive(); 00045 if (received) 00046 { 00047 InfoLog (<< "Client received: " << received->brief()); 00048 00049 auto_ptr<SipMessage> forDel(received); 00050 if ( (received->isResponse()) ) 00051 { 00052 if ( received->header(h_StatusLine).responseCode() == 200 ) 00053 { 00054 if (!mWaitingForBye200) 00055 { 00056 ErrLog(<< "Creating dialog."); 00057 DeprecatedDialog dlog(mContact); 00058 00059 DebugLog(<< "Creating dialog as UAC."); 00060 dlog.createDialogAsUAC(*received); 00061 00062 DebugLog(<< "making ack."); 00063 auto_ptr<SipMessage> ack(dlog.makeAck(*received) ); 00064 DebugLog(<< *ack); 00065 00066 DebugLog(<< "making bye."); 00067 auto_ptr<SipMessage> bye(dlog.makeBye()); 00068 00069 DebugLog(<< "Sending ack: << " << endl << *ack); 00070 mStack.send(*ack); 00071 00072 DebugLog(<< "Sending bye: << " << endl << *bye); 00073 mStack.send(*bye); 00074 mWaitingForBye200 = true; 00075 } 00076 else 00077 { 00078 auto_ptr<SipMessage> message(Helper::makeInvite( mTarget, mContact, mContact)); 00079 mStack.send(*message); 00080 mWaitingForBye200 = false; 00081 } 00082 } 00083 } 00084 } 00085 } 00086 private: 00087 SipStack mStack; 00088 NameAddr mContact; 00089 NameAddr mTarget; 00090 bool mWaitingForBye200; 00091 }; 00092 00093 int 00094 main(int argc, char* argv[]) 00095 { 00096 if (argc != 3) 00097 { 00098 cerr << argv[0] << " LOG_LEVEL TARGET_URI" << endl; 00099 exit(-1); 00100 } 00101 Log::initialize(Log::Cout, Log::toLevel(argv[1]), argv[0]); 00102 00103 NameAddr target(argv[2]); 00104 00105 NameAddr contact; 00106 contact.uri().host() = SipStack::getHostname(); 00107 contact.uri().port() = 5080; 00108 contact.uri().user() = "yffulf"; 00109 00110 TransportType protocol; 00111 if (isEqualNoCase(target.uri().param(p_transport), "UDP")) 00112 { 00113 protocol = UDP; 00114 } 00115 else if (isEqualNoCase(target.uri().param(p_transport), "TCP")) 00116 { 00117 protocol = TCP; 00118 } 00119 else 00120 { 00121 cerr << argv[0] << " LOG_LEVEL TARGET_URI(must include transport parameter)" << endl; 00122 exit(-1); 00123 } 00124 00125 Client c(protocol, contact, target); 00126 00127 while (true) 00128 { 00129 c.process(0); 00130 } 00131 } 00132 /* ==================================================================== 00133 * The Vovida Software License, Version 1.0 00134 * 00135 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00136 * 00137 * Redistribution and use in source and binary forms, with or without 00138 * modification, are permitted provided that the following conditions 00139 * are met: 00140 * 00141 * 1. Redistributions of source code must retain the above copyright 00142 * notice, this list of conditions and the following disclaimer. 00143 * 00144 * 2. Redistributions in binary form must reproduce the above copyright 00145 * notice, this list of conditions and the following disclaimer in 00146 * the documentation and/or other materials provided with the 00147 * distribution. 00148 * 00149 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00150 * and "Vovida Open Communication Application Library (VOCAL)" must 00151 * not be used to endorse or promote products derived from this 00152 * software without prior written permission. For written 00153 * permission, please contact vocal@vovida.org. 00154 * 00155 * 4. Products derived from this software may not be called "VOCAL", nor 00156 * may "VOCAL" appear in their name, without prior written 00157 * permission of Vovida Networks, Inc. 00158 * 00159 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00160 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00161 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00162 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00163 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00164 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00165 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00166 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00167 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00168 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00169 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00170 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00171 * DAMAGE. 00172 * 00173 * ==================================================================== 00174 * 00175 * This software consists of voluntary contributions made by Vovida 00176 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00177 * Inc. For more information on Vovida Networks, Inc., please see 00178 * <http://www.vovida.org/>. 00179 * 00180 */
1.7.5.1