reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
RedirectManager.cxx
Go to the documentation of this file.
3#include "rutil/Logger.hxx"
9
10#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
11
12using namespace resip;
13
14bool
15RedirectManager::handle(DialogSet& dSet, SipMessage& origRequest, const SipMessage& response)
16{
17 resip_assert( response.isResponse() );
18 resip_assert( origRequest.isRequest() );
19
20 //380, 305 fall through to the application
21 int code = response.header(h_StatusLine).statusCode();
22 if (code < 300 || code == 380 || code == 305)
23 {
24 return false;
25 }
26 else if (code >= 300 && code < 400)
27 {
28 RedirectHandler* handler = dSet.mDum.getRedirectHandler();
29 DialogSetId id(origRequest);
30 RedirectedRequestMap::iterator it = mRedirectedRequestMap.find(id);
31
32 if (it == mRedirectedRequestMap.end())
33 {
34 DebugLog( << "RedirectManager::handle: new TargetSet: " << id);
35 mRedirectedRequestMap[id] = new TargetSet(origRequest, mOrdering);
36 it = mRedirectedRequestMap.find(id);
37 }
38 if (handler)
39 {
40 handler->onRedirectReceived(dSet.mAppDialogSet->getHandle(), response);
41 }
42 TargetSet& tSet = *it->second;
43 tSet.addTargets(response);
44
45 while(tSet.makeNextRequest(origRequest))
46 {
47 if (handler)
48 {
49 if (handler->onTryingNextTarget(dSet.mAppDialogSet->getHandle(), origRequest))
50 {
51 return true;
52 }
53 }
54 else
55 {
56 return true;
57 }
58 }
59 delete it->second;
60 mRedirectedRequestMap.erase(it);
61 return false;
62 }
63 //5xx, 6xx different?
64 return false;
65}
66
67void
69{
70 mOrdering = order;
71}
72
73void
75{
76 if (msg.exists(h_Contacts))
77 {
78 for (NameAddrs::const_iterator it = msg.header(h_Contacts).begin(); it != msg.header(h_Contacts).end(); it++)
79 {
80 if (mTargetSet.find(*it) == mTargetSet.end())
81 {
82 DebugLog( << "RedirectManager::TargetSet::addTargets:target: " << *it);
83 mTargetSet.insert(*it);
84 mTargetQueue.push(*it);
85 }
86 }
87 }
88}
89
90bool
92{
93 request = mRequest;
94 //dispaly name, check if it's an invite, recurse if it isn't, throw if
95 //exhausted? Or make a boolean, elimnate hasTarget
96 while(!mTargetQueue.empty())
97 {
98 try
99 {
100 request.mergeUri(mTargetQueue.top().uri());
101 mTargetQueue.pop();
102 if (request.isRequest())
103 {
104 switch(request.header(h_RequestLine).method())
105 {
106 case ACK:
107 case BYE:
108 case CANCEL:
109 case PRACK:
110 break;
111 default:
112 DebugLog(<< "RedirectManager::TargetSet::makeNextRequest: " << request);
113 request.header(h_CSeq).sequence()++;
114 return true;
115 }
116 }
117 }
118 catch(BaseException&)
119 {
120 DebugLog(<< "RedirectManager::TargetSet::makeNextRequest: error generating request");
121 mTargetQueue.pop();
122 }
123 }
124 return false;
125}
126
128{
129 if (lhs.exists(p_q))
130 {
131 if (rhs.exists(p_q))
132 {
133 return lhs.param(p_q) < rhs.param(p_q);
134 }
135 else
136 {
137 return lhs.param(p_q) < 1000; // 1.0
138 }
139 }
140 else
141 {
142 // Note: if lhs is not present and treated as 1.0, it will never to less than rhs
143 return false;
144 }
145}
146
148{
149 RedirectedRequestMap::iterator it = mRedirectedRequestMap.find(id);
150
151 if (it != mRedirectedRequestMap.end())
152 {
153 delete it->second;
154 mRedirectedRequestMap.erase(it);
155 }
156}
157
158
159/* ====================================================================
160 * The Vovida Software License, Version 1.0
161 *
162 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
163 *
164 * Redistribution and use in source and binary forms, with or without
165 * modification, are permitted provided that the following conditions
166 * are met:
167 *
168 * 1. Redistributions of source code must retain the above copyright
169 * notice, this list of conditions and the following disclaimer.
170 *
171 * 2. Redistributions in binary form must reproduce the above copyright
172 * notice, this list of conditions and the following disclaimer in
173 * the documentation and/or other materials provided with the
174 * distribution.
175 *
176 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
177 * and "Vovida Open Communication Application Library (VOCAL)" must
178 * not be used to endorse or promote products derived from this
179 * software without prior written permission. For written
180 * permission, please contact vocal@vovida.org.
181 *
182 * 4. Products derived from this software may not be called "VOCAL", nor
183 * may "VOCAL" appear in their name, without prior written
184 * permission of Vovida Networks, Inc.
185 *
186 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
187 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
188 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
189 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
190 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
191 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
192 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
193 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
194 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
195 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
196 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
197 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
198 * DAMAGE.
199 *
200 * ====================================================================
201 *
202 * This software consists of voluntary contributions made by Vovida
203 * Networks, Inc. and many individuals on behalf of Vovida Networks,
204 * Inc. For more information on Vovida Networks, Inc., please see
205 * <http://www.vovida.org/>.
206 *
207 */
#define DebugLog(args_)
Definition Logger.hxx:128
#define resip_assert(x)
This file needs to work for both C and C++ code.
AppDialogSetHandle getHandle()
The abstract base-class for all exceptions thrown by resip code.
size_type find(const Data &match, size_type start=0) const
Finds a specified sequence of bytes in this Data.
Definition Data.cxx:1947
RedirectHandler * getRedirectHandler() const noexcept
Represents the "name-addr" and the "addr-spec" elements in the RFC 3261 grammar.
Definition NameAddr.hxx:19
bool exists(const Param< NameAddr > &paramType) const
Definition NameAddr.cxx:477
const Data & param(const ExtensionParameter &param) const
Const accessor for non-natively-supported parameter types.
virtual bool onTryingNextTarget(AppDialogSetHandle, const SipMessage &request)=0
virtual void onRedirectReceived(AppDialogSetHandle, const SipMessage &response)=0
virtual bool operator()(const NameAddr &lhs, const NameAddr &rhs) const
bool makeNextRequest(SipMessage &request)
void addTargets(const SipMessage &msg)
void removeDialogSet(DialogSetId id)
virtual bool handle(DialogSet &dSet, SipMessage &origRequest, const SipMessage &response)
void setOrdering(const Ordering &order)
RedirectedRequestMap mRedirectedRequestMap
MethodTypes & method()
Represents a SIP message.
bool isRequest() const
Returns true if message is a request, false otherwise.
SipMessage & mergeUri(const Uri &source)
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.
bool exists(const HeaderBase &headerType) const
Returns true if the given header field is present, false otherwise.
dcm! – add UnusedChecking(_enum) below;
StatusLineType h_StatusLine
Definition Headers.cxx:348
RequestLineType h_RequestLine
Definition Headers.cxx:347