/[resiprocate]/main/resip/stack/test/UAS.cxx
ViewVC logotype

Contents of /main/resip/stack/test/UAS.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9485 - (show annotations) (download)
Sat Apr 7 00:34:03 2012 UTC (7 years, 8 months ago) by dpocock
File size: 5892 byte(s)
Switch over to autotools build system from dpocock-autotools branch
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 <sys/types.h>
14 #include <iostream>
15 #include <signal.h>
16 #include <memory>
17
18 #include "rutil/DnsUtil.hxx"
19 #include "rutil/Inserter.hxx"
20 #include "rutil/Logger.hxx"
21 #include "resip/stack/DeprecatedDialog.hxx"
22 #include "resip/stack/Helper.hxx"
23 #include "resip/stack/SipMessage.hxx"
24 #include "resip/stack/SipStack.hxx"
25 #include "resip/stack/Uri.hxx"
26
27 using namespace resip;
28 using namespace std;
29
30 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
31
32 static bool finished = false;
33
34 static void
35 signalHandler(int signo)
36 {
37 std::cerr << "Shutting down" << endl;
38 finished = true;
39 }
40
41 int
42 main(int argc, char* argv[])
43 {
44
45 #ifndef _WIN32
46 if ( signal( SIGPIPE, SIG_IGN) == SIG_ERR)
47 {
48 cerr << "Couldn't install signal handler for SIGPIPE" << endl;
49 exit(-1);
50 }
51 #endif
52
53 if ( signal( SIGINT, signalHandler ) == SIG_ERR )
54 {
55 cerr << "Couldn't install signal handler for SIGINT" << endl;
56 exit( -1 );
57 }
58
59 if ( signal( SIGTERM, signalHandler ) == SIG_ERR )
60 {
61 cerr << "Couldn't install signal handler for SIGTERM" << endl;
62 exit( -1 );
63 }
64
65 const char* logType = "cout";
66 const char* logLevel = "ALERT";
67 const char* proto = "tcp";
68 const char* bindAddr = "";
69
70 int seltime = 0;
71
72 #if defined(HAVE_POPT_H)
73 struct poptOption table[] = {
74 {"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
75 {"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
76 { "select-time", 's', POPT_ARG_INT, &seltime, 0, "number of runs in test", 0},
77 {"protocol", 'p', POPT_ARG_STRING, &proto, 0, "protocol to use (tcp | udp)", 0},
78 {"bind", 'b', POPT_ARG_STRING, &bindAddr, 0, "interface address to bind to",0},
79 POPT_AUTOHELP
80 { NULL, 0, 0, NULL, 0 }
81 };
82
83 poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
84 poptGetNextOpt(context);
85 #endif
86 Log::initialize(logType, logLevel, argv[0]);
87
88 SipStack receiver;
89
90 int port = 5060;
91 receiver.addTransport(UDP, port, V4);
92 receiver.addTransport(TCP, port, V4);
93
94
95 NameAddr contact;
96 contact.uri().scheme() = "sip";
97 contact.uri().user() = "fluffy";
98 contact.uri().host() = bindAddr;
99
100 while (!finished)
101 {
102
103 try
104 {
105 receiver.process(seltime);
106 }
107 catch(BaseException& e)
108 {
109 CritLog(<< "Uncaught Exception: " << e);
110 assert(0);
111 }
112
113 SipMessage* request = receiver.receive();
114 static NameAddr contact;
115
116 if (request)
117 {
118 if(request->isRequest())
119 {
120 SipMessage response;
121 try
122 {
123 switch (request->header(h_RequestLine).getMethod())
124 {
125 case ACK:
126 break;
127 default:
128 Helper::makeResponse(response,*request,200,contact);
129 receiver.send(response);
130 break;
131 }
132 }
133 catch(BaseException& e)
134 {
135 CritLog(<< "Uncaught Exception: " << e );
136 assert(0);
137 }
138 }
139 delete request;
140 }
141 }
142
143 #if defined(HAVE_POPT_H)
144 poptFreeContext(context);
145 #endif
146 return 0;
147 }
148 /* ====================================================================
149 * The Vovida Software License, Version 1.0
150 *
151 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
152 *
153 * Redistribution and use in source and binary forms, with or without
154 * modification, are permitted provided that the following conditions
155 * are met:
156 *
157 * 1. Redistributions of source code must retain the above copyright
158 * notice, this list of conditions and the following disclaimer.
159 *
160 * 2. Redistributions in binary form must reproduce the above copyright
161 * notice, this list of conditions and the following disclaimer in
162 * the documentation and/or other materials provided with the
163 * distribution.
164 *
165 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
166 * and "Vovida Open Communication Application Library (VOCAL)" must
167 * not be used to endorse or promote products derived from this
168 * software without prior written permission. For written
169 * permission, please contact vocal@vovida.org.
170 *
171 * 4. Products derived from this software may not be called "VOCAL", nor
172 * may "VOCAL" appear in their name, without prior written
173 * permission of Vovida Networks, Inc.
174 *
175 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
176 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
177 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
178 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
179 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
180 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
181 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
182 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
183 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
184 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
185 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
186 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
187 * DAMAGE.
188 *
189 * ====================================================================
190 *
191 * This software consists of voluntary contributions made by Vovida
192 * Networks, Inc. and many individuals on behalf of Vovida Networks,
193 * Inc. For more information on Vovida Networks, Inc., please see
194 * <http://www.vovida.org/>.
195 *
196 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27