|
reSIProcate/stack
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #if defined (HAVE_POPT_H) 00006 #include <popt.h> 00007 #else 00008 #ifndef WIN32 00009 #warning "will not work very well without libpopt" 00010 #endif 00011 #endif 00012 00013 #include <iostream> 00014 00015 #include "resip/stack/SipStack.hxx" 00016 #include "resip/stack/Helper.hxx" 00017 #include "resip/stack/SipMessage.hxx" 00018 #include "resip/stack/Uri.hxx" 00019 #include "rutil/Data.hxx" 00020 #include "rutil/DnsUtil.hxx" 00021 #include "rutil/Logger.hxx" 00022 #include "rutil/DataStream.hxx" 00023 00024 using namespace resip; 00025 using namespace std; 00026 00027 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP 00028 00029 int 00030 main(int argc, char* argv[]) 00031 { 00032 const char* logType = "cout"; 00033 const char* logLevel = "DEBUG"; 00034 int optLoop = 0; 00035 int optPort = 0; 00036 int optTcp = 0; 00037 int optUdp = 0; 00038 char *optBindAddr = 0; 00039 char *optBindTcpAddr = 0; 00040 char *optBindUdpAddr = 0; 00041 00042 #if defined(HAVE_POPT_H) 00043 struct poptOption table[] = { 00044 {"log-type", 'l', POPT_ARG_STRING, &logType, 0, 00045 "where to send logging messages", "syslog|cerr|cout"}, 00046 {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, 00047 "specify the default log level", "DEBUG|INFO|WARNING|ALERT"}, 00048 {"loop", 'l', POPT_ARG_NONE, &optLoop, 0, "loop endlessly", 0 }, 00049 {"port", 'p', POPT_ARG_INT, &optPort, 0, "port to listen on", 0}, 00050 {"tcp", 't', POPT_ARG_NONE, &optTcp, 0, "do not use TCP", 0}, 00051 {"udp", 'u', POPT_ARG_NONE, &optUdp, 0, "do not use UDP", 0}, 00052 {"bind", 'b', POPT_ARG_STRING, &optBindAddr, 0, "bind to this address globally", 0}, 00053 {"bind-tcp", 0, POPT_ARG_STRING, &optBindTcpAddr, 0, "bind TCP Transport to this address", 0}, 00054 {"bind-udp", 0, POPT_ARG_STRING, &optBindUdpAddr, 0, "bind UDP Transport to this address", 0}, 00055 POPT_AUTOHELP 00056 { 0 } 00057 }; 00058 00059 poptContext context = poptGetContext(0, argc, const_cast<const char**>(argv), table, 0); 00060 poptGetNextOpt(context); 00061 #endif 00062 00063 Log::initialize(logType, logLevel, argv[0]); 00064 00065 optUdp = !optUdp; 00066 optTcp = !optTcp; 00067 if (!optPort) optPort = 5060; 00068 00069 00070 00071 auto_ptr<SipStack> stack(new SipStack()); 00072 if (optBindAddr) 00073 { 00074 const char *addr = optBindUdpAddr?optBindUdpAddr:optBindAddr; 00075 stack->addTransport(UDP, optPort, DnsUtil::isIpV6Address(addr)?V6:V4, StunDisabled, addr); 00076 addr = optBindTcpAddr?optBindTcpAddr:optBindAddr; 00077 stack->addTransport(TCP, optPort, DnsUtil::isIpV6Address(addr)?V6:V4, StunDisabled, addr); 00078 } 00079 else 00080 { 00081 stack->addTransport(UDP, optPort); 00082 stack->addTransport(TCP, optPort); 00083 } 00084 00085 int count=1; 00086 bool needToProcessSend = false; 00087 while (optLoop || count > 0 || needToProcessSend) 00088 { 00089 FdSet fdset; 00090 stack->buildFdSet(fdset); 00091 00092 stack->process(fdset); 00093 needToProcessSend = false; 00094 00095 Message* msg = stack->receive(); 00096 00097 if (msg) 00098 { 00099 SipMessage* received = dynamic_cast<SipMessage*>(msg); 00100 if (received) 00101 { 00102 --count; 00103 received->encode(resipCout); 00104 if (received->isRequest()) 00105 { 00106 SipMessage* resp = Helper::makeResponse(*received, 606); 00107 WarningCategory warn; 00108 warn.text() = "Simple test reply from "__FILE__" driver."; 00109 resp->header(h_Warnings).push_back(warn); 00110 stack->send(*resp); 00111 needToProcessSend = true; 00112 } 00113 } 00114 } 00115 } 00116 00117 return 0; 00118 } 00119 /* ==================================================================== 00120 * The Vovida Software License, Version 1.0 00121 * 00122 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00123 * 00124 * Redistribution and use in source and binary forms, with or without 00125 * modification, are permitted provided that the following conditions 00126 * are met: 00127 * 00128 * 1. Redistributions of source code must retain the above copyright 00129 * notice, this list of conditions and the following disclaimer. 00130 * 00131 * 2. Redistributions in binary form must reproduce the above copyright 00132 * notice, this list of conditions and the following disclaimer in 00133 * the documentation and/or other materials provided with the 00134 * distribution. 00135 * 00136 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00137 * and "Vovida Open Communication Application Library (VOCAL)" must 00138 * not be used to endorse or promote products derived from this 00139 * software without prior written permission. For written 00140 * permission, please contact vocal@vovida.org. 00141 * 00142 * 4. Products derived from this software may not be called "VOCAL", nor 00143 * may "VOCAL" appear in their name, without prior written 00144 * permission of Vovida Networks, Inc. 00145 * 00146 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00147 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00148 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00149 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00150 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00151 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00152 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00153 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00154 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00155 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00156 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00157 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00158 * DAMAGE. 00159 * 00160 * ==================================================================== 00161 * 00162 * This software consists of voluntary contributions made by Vovida 00163 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00164 * Inc. For more information on Vovida Networks, Inc., please see 00165 * <http://www.vovida.org/>. 00166 * 00167 */
1.7.5.1