reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
StatelessHandler.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#ifndef WIN32
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <arpa/inet.h>
9#ifndef __CYGWIN__
10# include <netinet/in.h>
11# include <arpa/nameser.h>
12# include <resolv.h>
13#endif
14#include <netdb.h>
15#include <netinet/in.h>
16#else
17#include <Winsock2.h>
18#include <svcguid.h>
19#ifdef USE_IPV6
20#include <ws2tcpip.h>
21#endif
22#endif
23
24#include "rutil/Logger.hxx"
25#include "rutil/DnsUtil.hxx"
26
34
35
36
37using namespace resip;
38
39#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSACTION
40
44
45void
47{
48 Message* msg = mController.mStateMacFifo.getNext();
49 resip_assert(msg);
50
51 SipMessage* sip = dynamic_cast<SipMessage*>(msg);
52 TransportFailure* transport = dynamic_cast<TransportFailure*>(msg);
53
54 if (sip)
55 {
56 if (sip->const_header(h_Vias).empty())
57 {
58 InfoLog(<< "TransactionState::process dropping message with no Via: " << sip->brief());
59 delete sip;
60 return;
61 }
62 else
63 {
64 if (sip->isExternal())
65 {
66 DebugLog (<< "Processing sip from wire: " << msg->brief());
67 Via& via = sip->header(h_Vias).front();
68 // this is here so that we will reuse the tcp connection
69 via.param(p_rport).port() = sip->getSource().getPort();
70 mController.mTuSelector.add(sip, TimeLimitFifo<Message>::InternalElement);
71 }
72 else if (sip->isRequest())
73 {
74 if (sip->getDestination().mFlowKey)
75 {
76 DebugLog (<< "Processing request from TU : " << msg->brief());
77 mController.mTransportSelector.transmit(sip, sip->getDestination()); // results not used
78 }
79 else
80 {
81 DebugLog (<< "Processing request from TU : " << msg->brief());
82 StatelessMessage* stateless = new StatelessMessage(mController.mTransportSelector, sip);
83 DnsResult* dnsRes = mController.mTransportSelector.createDnsResult(stateless);
84 mController.mTransportSelector.dnsResolve(dnsRes, sip);
85 }
86 }
87 else // no dns for sip responses
88 {
90 DebugLog (<< "Processing response from TU: " << msg->brief());
91 const Via& via = sip->const_header(h_Vias).front();
92 int port = via.sentPort();
93 if (sip->hasForceTarget())
94 {
95 resip_assert( /*Unimplemented*/ 0 );
96 }
97 else
98 {
99 if (via.exists(p_rport) && via.param(p_rport).hasValue())
100 {
101 port = via.param(p_rport).port();
102 }
103 Tuple destination(via.param(p_received), port, Tuple::toTransport(via.transport()));
104 mController.mTransportSelector.transmit(sip, destination); // results not used
105 }
106 }
107 }
108 }
109 else if (transport)
110 {
111 DebugLog (<< "Processing Transport result: " << msg->brief());
112 InfoLog (<< "Not yet supported");
113 }
114 else
115 {
116 DebugLog (<< "Dropping: " << msg->brief());
117 }
118}
119
120
121StatelessMessage::StatelessMessage(TransportSelector& selector, SipMessage* msg) : mSelector(selector), mMsg(msg)
122{
123}
124
125void
127{
128 resip_assert(mMsg->isRequest());
129 if (mMsg->const_header(h_RequestLine).uri() != rewrite)
130 {
131 InfoLog (<< "Rewriting request-uri to " << rewrite);
132 mMsg->header(h_RequestLine).uri() = rewrite;
133 }
134}
135
136
137void
139{
140 if (result->available() == DnsResult::Available)
141 {
142 Tuple next = result->next();
143 mSelector.transmit(mMsg, next);
144 }
145
146 delete this;
147 result->destroy();
148}
149/* ====================================================================
150 * The Vovida Software License, Version 1.0
151 *
152 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
153 *
154 * Redistribution and use in source and binary forms, with or without
155 * modification, are permitted provided that the following conditions
156 * are met:
157 *
158 * 1. Redistributions of source code must retain the above copyright
159 * notice, this list of conditions and the following disclaimer.
160 *
161 * 2. Redistributions in binary form must reproduce the above copyright
162 * notice, this list of conditions and the following disclaimer in
163 * the documentation and/or other materials provided with the
164 * distribution.
165 *
166 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
167 * and "Vovida Open Communication Application Library (VOCAL)" must
168 * not be used to endorse or promote products derived from this
169 * software without prior written permission. For written
170 * permission, please contact vocal@vovida.org.
171 *
172 * 4. Products derived from this software may not be called "VOCAL", nor
173 * may "VOCAL" appear in their name, without prior written
174 * permission of Vovida Networks, Inc.
175 *
176 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
177 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
178 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
179 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
180 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
181 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
182 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
183 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
184 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
185 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
186 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
187 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
188 * DAMAGE.
189 *
190 * ====================================================================
191 *
192 * This software consists of voluntary contributions made by Vovida
193 * Networks, Inc. and many individuals on behalf of Vovida Networks,
194 * Inc. For more information on Vovida Networks, Inc., please see
195 * <http://www.vovida.org/>.
196 *
197 */
#define DebugLog(args_)
Definition Logger.hxx:128
#define InfoLog(args_)
Definition Logger.hxx:131
#define resip_assert(x)
This file needs to work for both C and C++ code.
The base-class used for message-passing.
Definition Message.hxx:21
virtual Brief brief() const
return a facet for brief encoding of message
Definition Message.cxx:16
const Uri & uri() const
Represents a SIP message.
Tuple & getDestination()
bool isRequest() const
Returns true if message is a request, false otherwise.
bool hasForceTarget() const
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
bool isResponse() const
Returns true if message is a response, false otherwise.
const RequestLine & const_header(const RequestLineType &l) const
const Tuple & getSource() const
Returns the source tuple that the message was received from only makes sense for messages received fr...
bool isExternal() const
Check if SipMessage is to be treated as it came off the wire.
StatelessHandler(TransactionController &c)
StatelessMessage(TransportSelector &selector, SipMessage *msg)
void rewriteRequest(const Uri &rewrite)
void handle(DnsResult *result)
This message is used to indicate that the TransportSelector has sent a sip message using either relia...
DnsResult * createDnsResult(DnsHandler *handler)
DNS Resolution.
TransmitState transmit(SipMessage *msg, Tuple &target, SendData *sendData=0)
void dnsResolve(DnsResult *result, SipMessage *msg)
void add(Message *msg, TimeLimitFifo< Message >::DepthUsage usage)
Represents a network address.
Definition Tuple.hxx:59
FlowKey mFlowKey
This is a (largely) opaque key that subclasses of Transport will use to help record/find flows.
Definition Tuple.hxx:189
int getPort() const
Definition Tuple.cxx:466
static TransportType toTransport(const Data &)
Converts a string representation of transport type, i.e.
Definition Tuple.cxx:921
Represents the "SIP-URI" and "SIPS-URI" elements in the RFC 3261 grammar.
Definition Uri.hxx:22
Represents the "via-parm" element in the RFC 3261 grammar.
Definition Via.hxx:18
Data & transport()
Definition Via.cxx:121
bool exists(const Param< Via > &paramType) const
Definition Via.cxx:266
int & sentPort()
Definition Via.cxx:149
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
dcm! – add UnusedChecking(_enum) below;
RequestLineType h_RequestLine
Definition Headers.cxx:347