/[resiprocate]/branches/b-directory-reorg/sip/resiprocate/MessageFilterRule.cxx
ViewVC logotype

Contents of /branches/b-directory-reorg/sip/resiprocate/MessageFilterRule.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5271 - (show annotations) (download)
Thu Aug 18 23:43:07 2005 UTC (14 years, 3 months ago) by jason
File size: 7041 byte(s)
new directory reorg proposal
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #include "resiprocate/MessageFilterRule.hxx"
6 #include "resiprocate/Helper.hxx"
7 #include "resiprocate/SipMessage.hxx"
8 #include "resiprocate/os/Logger.hxx"
9
10 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::TRANSACTION
11
12 using namespace resip;
13 using namespace std;
14
15
16 MessageFilterRule::MessageFilterRule(SchemeList schemeList,
17 HostpartTypes hostpartType,
18 MethodList methodList,
19 EventList eventList)
20 : mSchemeList(schemeList),
21 mHostpartMatches(hostpartType),
22 mMethodList(methodList),
23 mEventList(eventList)
24 {
25 }
26
27 MessageFilterRule::MessageFilterRule(SchemeList schemeList,
28 HostpartList hostpartList,
29 MethodList methodList,
30 EventList eventList)
31 : mSchemeList(schemeList),
32 mHostpartMatches(List),
33 mHostpartList(hostpartList),
34 mMethodList(methodList),
35 mEventList(eventList)
36 {
37 }
38
39 bool
40 MessageFilterRule::matches(const SipMessage &msg) const
41 {
42 DebugLog(<< "Matching rule for " << msg);
43 const Data scheme = msg.header(h_RequestLine).uri().scheme();
44
45 if (!schemeIsInList(scheme))
46 {
47 DebugLog(<< "Scheme is not in list. Rule does not match.");
48 return false;
49 }
50
51 if (msg.header(h_RequestLine).uri().scheme() != Symbols::Tel)
52 {
53 // !rwm! Should be hostport, not host
54 if (!hostIsInList( msg.header(h_RequestLine).uri().host()))
55 {
56 DebugLog(<< "Host is not in list. Rule does not match.");
57 return false;
58 }
59 }
60
61 MethodTypes method = msg.header(h_RequestLine).method();
62 if (!methodIsInList(method))
63 {
64 DebugLog(<< "Method is not in list. Rule does not match.");
65 return false;
66 }
67 else
68 {
69 switch(method)
70 {
71 case SUBSCRIBE:
72 case NOTIFY:
73 case PUBLISH:
74 if (!eventIsInList(msg.header(h_Event).value()))
75 {
76 DebugLog(<< "Event is not in list. Rule does not match.");
77 return false;
78 }
79 break;
80 default:
81 break;
82 }
83 }
84
85 return true;
86 }
87
88
89 //defaults for the constructor of a MessageFilterRule
90 /*
91 const SchemeList schemes(SIP, SIPS, TEL, IM, PRES, H323);
92 const MethodList methods(INVITE, ACK, CANCEL, BYE, REGISTER,
93 PUBLISH, SUBSCRIBE, NOTIFY, INFO, OPTIONS, REFER, UPDATE, PRACK, MESSAGE);
94 */
95 // legal values for hostpart comparison are ANY, HOSTISME, DOMAINISME, or a list of Datas
96 // legal values for events are ANY or a list of Datas
97
98
99 bool
100 MessageFilterRule::schemeIsInList(const Data& scheme) const
101 {
102 // Emtpy list means "sip or sips"
103 if (mSchemeList.empty())
104 {
105 return (scheme == "sip" || scheme == "sips");
106 }
107
108 // step through mSchemeList looking for supported schemes
109 for (SchemeList::const_iterator i = mSchemeList.begin();
110 i != mSchemeList.end(); i++)
111 {
112 if (scheme == *i)
113 {
114 return true;
115 }
116
117 }
118 return false;
119 }
120
121 bool
122 MessageFilterRule::methodIsInList(MethodTypes method) const
123 {
124 // empty list means "match all"
125 if (mMethodList.empty())
126 {
127 return true;
128 }
129
130 for (MethodList::const_iterator i = mMethodList.begin();
131 i != mMethodList.end(); i++)
132 {
133 if (method == *i)
134 {
135 return true;
136 }
137
138 }
139 return false;
140 }
141
142 bool
143 MessageFilterRule::eventIsInList(const Data& event) const
144 {
145 // empty list means "match all"
146 if (mEventList.empty())
147 {
148 return true;
149 }
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
163 bool
164 MessageFilterRule::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 // !abr! Waiting for TU support for this method.
177 // return (tu.domainIsMe(hostpart));
178 return false;
179 break;
180 case List:
181 // walk the list for specific matches
182 for (HostpartList::const_iterator i = mHostpartList.begin() ;
183 i != mHostpartList.end() ; ++i)
184 {
185 if (*i == hostpart)
186 return true;
187 }
188 break;
189 default:
190 break;
191 }
192 return false;
193 }
194
195
196 /* ====================================================================
197 * The Vovida Software License, Version 1.0
198 *
199 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
200 *
201 * Redistribution and use in source and binary forms, with or without
202 * modification, are permitted provided that the following conditions
203 * are met:
204 *
205 * 1. Redistributions of source code must retain the above copyright
206 * notice, this list of conditions and the following disclaimer.
207 *
208 * 2. Redistributions in binary form must reproduce the above copyright
209 * notice, this list of conditions and the following disclaimer in
210 * the documentation and/or other materials provided with the
211 * distribution.
212 *
213 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
214 * and "Vovida Open Communication Application Library (VOCAL)" must
215 * not be used to endorse or promote products derived from this
216 * software without prior written permission. For written
217 * permission, please contact vocal@vovida.org.
218 *
219 * 4. Products derived from this software may not be called "VOCAL", nor
220 * may "VOCAL" appear in their name, without prior written
221 * permission of Vovida Networks, Inc.
222 *
223 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
224 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
225 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
226 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
227 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
228 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
229 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
230 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
231 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
232 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
233 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
234 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
235 * DAMAGE.
236 *
237 * ====================================================================
238 *
239 * This software consists of voluntary contributions made by Vovida
240 * Networks, Inc. and many individuals on behalf of Vovida Networks,
241 * Inc. For more information on Vovida Networks, Inc., please see
242 * <http://www.vovida.org/>.
243 *
244 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27