1 |
#if defined(HAVE_CONFIG_H) |
2 |
#include "config.h" |
3 |
#endif |
4 |
|
5 |
#if defined (HAVE_POPT_H) |
6 |
#include <popt.h> |
7 |
#else |
8 |
#ifndef WIN32 |
9 |
#warning "will not work very well without libpopt" |
10 |
#endif |
11 |
#endif |
12 |
|
13 |
#include <iostream> |
14 |
|
15 |
#include "resip/stack/SipStack.hxx" |
16 |
#include "resip/stack/Helper.hxx" |
17 |
#include "resip/stack/SipMessage.hxx" |
18 |
#include "resip/stack/Uri.hxx" |
19 |
#include "rutil/Data.hxx" |
20 |
#include "rutil/DnsUtil.hxx" |
21 |
#include "rutil/Logger.hxx" |
22 |
#include "rutil/DataStream.hxx" |
23 |
|
24 |
using namespace resip; |
25 |
using namespace std; |
26 |
|
27 |
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP |
28 |
|
29 |
int |
30 |
main(int argc, char* argv[]) |
31 |
{ |
32 |
const char* logType = "cout"; |
33 |
const char* logLevel = "DEBUG"; |
34 |
int optLoop = 0; |
35 |
int optPort = 0; |
36 |
int optTcp = 0; |
37 |
int optUdp = 0; |
38 |
char *optBindAddr = 0; |
39 |
char *optBindTcpAddr = 0; |
40 |
char *optBindUdpAddr = 0; |
41 |
|
42 |
#if defined(HAVE_POPT_H) |
43 |
struct poptOption table[] = { |
44 |
{"log-type", 'l', POPT_ARG_STRING, &logType, 0, |
45 |
"where to send logging messages", "syslog|cerr|cout"}, |
46 |
{"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, |
47 |
"specify the default log level", "DEBUG|INFO|WARNING|ALERT"}, |
48 |
{"loop", 'l', POPT_ARG_NONE, &optLoop, 0, "loop endlessly", 0 }, |
49 |
{"port", 'p', POPT_ARG_INT, &optPort, 0, "port to listen on", 0}, |
50 |
{"tcp", 't', POPT_ARG_NONE, &optTcp, 0, "do not use TCP", 0}, |
51 |
{"udp", 'u', POPT_ARG_NONE, &optUdp, 0, "do not use UDP", 0}, |
52 |
{"bind", 'b', POPT_ARG_STRING, &optBindAddr, 0, "bind to this address globally", 0}, |
53 |
{"bind-tcp", 0, POPT_ARG_STRING, &optBindTcpAddr, 0, "bind TCP Transport to this address", 0}, |
54 |
{"bind-udp", 0, POPT_ARG_STRING, &optBindUdpAddr, 0, "bind UDP Transport to this address", 0}, |
55 |
POPT_AUTOHELP |
56 |
{ 0 } |
57 |
}; |
58 |
|
59 |
poptContext context = poptGetContext(0, argc, const_cast<const char**>(argv), table, 0); |
60 |
poptGetNextOpt(context); |
61 |
#endif |
62 |
|
63 |
Log::initialize(logType, logLevel, argv[0]); |
64 |
|
65 |
optUdp = !optUdp; |
66 |
optTcp = !optTcp; |
67 |
if (!optPort) optPort = 5060; |
68 |
|
69 |
|
70 |
|
71 |
auto_ptr<SipStack> stack(new SipStack()); |
72 |
if (optBindAddr) |
73 |
{ |
74 |
const char *addr = optBindUdpAddr?optBindUdpAddr:optBindAddr; |
75 |
stack->addTransport(UDP, optPort, DnsUtil::isIpV6Address(addr)?V6:V4, StunDisabled, addr); |
76 |
addr = optBindTcpAddr?optBindTcpAddr:optBindAddr; |
77 |
stack->addTransport(TCP, optPort, DnsUtil::isIpV6Address(addr)?V6:V4, StunDisabled, addr); |
78 |
} |
79 |
else |
80 |
{ |
81 |
stack->addTransport(UDP, optPort); |
82 |
stack->addTransport(TCP, optPort); |
83 |
} |
84 |
|
85 |
int count=1; |
86 |
bool needToProcessSend = false; |
87 |
while (optLoop || count > 0 || needToProcessSend) |
88 |
{ |
89 |
FdSet fdset; |
90 |
stack->buildFdSet(fdset); |
91 |
|
92 |
stack->process(fdset); |
93 |
needToProcessSend = false; |
94 |
|
95 |
Message* msg = stack->receive(); |
96 |
|
97 |
if (msg) |
98 |
{ |
99 |
SipMessage* received = dynamic_cast<SipMessage*>(msg); |
100 |
if (received) |
101 |
{ |
102 |
--count; |
103 |
received->encode(resipCout); |
104 |
if (received->isRequest()) |
105 |
{ |
106 |
SipMessage* resp = Helper::makeResponse(*received, 606); |
107 |
WarningCategory warn; |
108 |
warn.text() = "Simple test reply from "__FILE__" driver."; |
109 |
resp->header(h_Warnings).push_back(warn); |
110 |
stack->send(*resp); |
111 |
needToProcessSend = true; |
112 |
} |
113 |
} |
114 |
} |
115 |
} |
116 |
|
117 |
return 0; |
118 |
} |
119 |
/* ==================================================================== |
120 |
* The Vovida Software License, Version 1.0 |
121 |
* |
122 |
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. |
123 |
* |
124 |
* Redistribution and use in source and binary forms, with or without |
125 |
* modification, are permitted provided that the following conditions |
126 |
* are met: |
127 |
* |
128 |
* 1. Redistributions of source code must retain the above copyright |
129 |
* notice, this list of conditions and the following disclaimer. |
130 |
* |
131 |
* 2. Redistributions in binary form must reproduce the above copyright |
132 |
* notice, this list of conditions and the following disclaimer in |
133 |
* the documentation and/or other materials provided with the |
134 |
* distribution. |
135 |
* |
136 |
* 3. The names "VOCAL", "Vovida Open Communication Application Library", |
137 |
* and "Vovida Open Communication Application Library (VOCAL)" must |
138 |
* not be used to endorse or promote products derived from this |
139 |
* software without prior written permission. For written |
140 |
* permission, please contact vocal@vovida.org. |
141 |
* |
142 |
* 4. Products derived from this software may not be called "VOCAL", nor |
143 |
* may "VOCAL" appear in their name, without prior written |
144 |
* permission of Vovida Networks, Inc. |
145 |
* |
146 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
147 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
148 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
149 |
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA |
150 |
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES |
151 |
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, |
152 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
153 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
154 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
155 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
156 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
157 |
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
158 |
* DAMAGE. |
159 |
* |
160 |
* ==================================================================== |
161 |
* |
162 |
* This software consists of voluntary contributions made by Vovida |
163 |
* Networks, Inc. and many individuals on behalf of Vovida Networks, |
164 |
* Inc. For more information on Vovida Networks, Inc., please see |
165 |
* <http://www.vovida.org/>. |
166 |
* |
167 |
*/ |