reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
MessageFilterRule.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
9#include "rutil/Logger.hxx"
10
11#define RESIPROCATE_SUBSYSTEM resip::Subsystem::TRANSACTION
12
13using namespace resip;
14using namespace std;
15
16
18 HostpartTypes hostpartType,
19 MethodList methodList,
20 EventList eventList)
21 : mSchemeList(schemeList),
22 mHostpartMatches(hostpartType),
23 mMethodList(methodList),
24 mEventList(eventList),
25 mTransactionUser(0)
26{
27}
28
30 HostpartList hostpartList,
31 MethodList methodList,
32 EventList eventList)
33 : mSchemeList(schemeList),
34 mHostpartMatches(List),
35 mHostpartList(hostpartList),
36 mMethodList(methodList),
37 mEventList(eventList),
38 mTransactionUser(0)
39{
40}
41
42bool
44{
45 const Data scheme = msg.header(h_RequestLine).uri().scheme();
46
47 if (!schemeIsInList(scheme))
48 {
49 DebugLog(<< " MessageFilterRule::matches: Scheme is not in list. Rule does not match.");
50 return false;
51 }
52
53 if (msg.header(h_RequestLine).uri().scheme() != Symbols::Tel &&
55 {
56 // !rwm! Should be hostport, not host
57 if (!hostIsInList( msg.header(h_RequestLine).uri().host()))
58 {
59 DebugLog(<< " MessageFilterRule::matches: Host is not in list. Rule does not match.");
60 return false;
61 }
62 }
63
64 MethodTypes method = msg.header(h_RequestLine).method();
65 if (!methodIsInList(method))
66 {
67 DebugLog(<< " MessageFilterRule::matches: Method is not in list. Rule does not match.");
68 return false;
69 }
70 else
71 {
72 switch(method)
73 {
74 case SUBSCRIBE:
75 case NOTIFY:
76 case PUBLISH:
77 if (!eventIsInList(msg))
78 {
79 DebugLog(<< " MessageFilterRule::matches: Event is not in list. Rule does not match.");
80 return false;
81 }
82 break;
83 default:
84 break;
85 }
86 }
87
88 return true;
89}
90
91bool
92MessageFilterRule::schemeIsInList(const Data& scheme) const
93{
94 // Emtpy list means "sip or sips"
95 if (mSchemeList.empty())
96 {
97 return (scheme == Symbols::Sip || scheme == Symbols::Sips ||
98 scheme == Symbols::Tel || scheme == Symbols::Urn);
99 }
100
101 // step through mSchemeList looking for supported schemes
102 for (SchemeList::const_iterator i = mSchemeList.begin();
103 i != mSchemeList.end(); i++)
104 {
105 if (scheme == *i)
106 {
107 return true;
108 }
109
110 }
111 return false;
112}
113
114bool
115MessageFilterRule::methodIsInList(MethodTypes method) const
116{
117 // empty list means "match all"
118 if (mMethodList.empty())
119 {
120 return true;
121 }
122
123 for (MethodList::const_iterator i = mMethodList.begin();
124 i != mMethodList.end(); i++)
125 {
126 if (method == *i)
127 {
128 return true;
129 }
130
131 }
132 return false;
133}
134
135bool
136MessageFilterRule::eventIsInList(const SipMessage& msg) const
137{
138 // empty list means "match all"
139 if (mEventList.empty())
140 {
141 return true;
142 }
143
144 if (!msg.exists(h_Event))
145 {
146 return false;
147 }
148
149 Data event = msg.header(h_Event).value();
150
151 for (EventList::const_iterator i = mEventList.begin();
152 i != mEventList.end(); i++)
153 {
154 if (event == *i)
155 {
156 return true;
157 }
158
159 }
160 return false;
161}
162
163bool
164MessageFilterRule::hostIsInList(const Data& hostpart) const
165{
166 switch(mHostpartMatches)
167 {
168 case Any:
169 return true;
170 case HostIsMe:
171 // !abr! Waiting for TU support for this method.
172 // return (tu.hostIsMe(hostpart));
173 return false;
174 break;
175 case DomainIsMe:
176 if(mTransactionUser)
177 {
178 return mTransactionUser->isMyDomain(hostpart);
179 }
180 return false;
181 break;
182 case List:
183 // walk the list for specific matches
184 for (HostpartList::const_iterator i = mHostpartList.begin() ;
185 i != mHostpartList.end() ; ++i)
186 {
187 if (isEqualNoCase(*i, hostpart))
188 return true;
189 }
190 break;
191 default:
192 break;
193 }
194 return false;
195}
196
197
198/* ====================================================================
199 * The Vovida Software License, Version 1.0
200 *
201 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
202 *
203 * Redistribution and use in source and binary forms, with or without
204 * modification, are permitted provided that the following conditions
205 * are met:
206 *
207 * 1. Redistributions of source code must retain the above copyright
208 * notice, this list of conditions and the following disclaimer.
209 *
210 * 2. Redistributions in binary form must reproduce the above copyright
211 * notice, this list of conditions and the following disclaimer in
212 * the documentation and/or other materials provided with the
213 * distribution.
214 *
215 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
216 * and "Vovida Open Communication Application Library (VOCAL)" must
217 * not be used to endorse or promote products derived from this
218 * software without prior written permission. For written
219 * permission, please contact vocal@vovida.org.
220 *
221 * 4. Products derived from this software may not be called "VOCAL", nor
222 * may "VOCAL" appear in their name, without prior written
223 * permission of Vovida Networks, Inc.
224 *
225 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
226 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
227 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
228 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
229 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
230 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
231 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
232 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
233 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
234 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
236 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
237 * DAMAGE.
238 *
239 * ====================================================================
240 *
241 * This software consists of voluntary contributions made by Vovida
242 * Networks, Inc. and many individuals on behalf of Vovida Networks,
243 * Inc. For more information on Vovida Networks, Inc., please see
244 * <http://www.vovida.org/>.
245 *
246 */
#define DebugLog(args_)
Definition Logger.hxx:128
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
std::vector< Data > EventList
std::vector< MethodTypes > MethodList
std::vector< Data > HostpartList
MessageFilterRule(SchemeList schemeList=SchemeList(), HostpartTypes hostpartType=Any, MethodList methodList=MethodList(), EventList eventTypeList=EventList())
bool matches(const SipMessage &) const
std::vector< Data > SchemeList
const Uri & uri() const
MethodTypes & method()
Represents a SIP message.
const RequestLine & header(const RequestLineType &l) const
Returns the RequestLine. This is only valid for request messages.
bool exists(const HeaderBase &headerType) const
Returns true if the given header field is present, false otherwise.
static const char * Tel
Definition Symbols.hxx:64
static const char * Sips
Definition Symbols.hxx:63
static const char * Urn
Definition Symbols.hxx:65
static const char * Sip
Definition Symbols.hxx:62
bool isMyDomain(const Data &domain) const
Returns true iff domain matches one of the domains that this TransactionUser is responsible for.
Data & scheme()
Definition Uri.hxx:143
Data & host()
Definition Uri.hxx:40
dcm! – add UnusedChecking(_enum) below;
bool isEqualNoCase(const Data &left, const Data &right)
Definition Data.hxx:1116
RequestLineType h_RequestLine
Definition Headers.cxx:347