|
reSIProcate/stack
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #include "resip/stack/MessageFilterRule.hxx" 00006 #include "resip/stack/Helper.hxx" 00007 #include "resip/stack/SipMessage.hxx" 00008 #include "resip/stack/TransactionUser.hxx" 00009 #include "rutil/Logger.hxx" 00010 00011 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::TRANSACTION 00012 00013 using namespace resip; 00014 using namespace std; 00015 00016 00017 MessageFilterRule::MessageFilterRule(SchemeList schemeList, 00018 HostpartTypes hostpartType, 00019 MethodList methodList, 00020 EventList eventList) 00021 : mSchemeList(schemeList), 00022 mHostpartMatches(hostpartType), 00023 mMethodList(methodList), 00024 mEventList(eventList), 00025 mTransactionUser(0) 00026 { 00027 } 00028 00029 MessageFilterRule::MessageFilterRule(SchemeList schemeList, 00030 HostpartList hostpartList, 00031 MethodList methodList, 00032 EventList eventList) 00033 : mSchemeList(schemeList), 00034 mHostpartMatches(List), 00035 mHostpartList(hostpartList), 00036 mMethodList(methodList), 00037 mEventList(eventList), 00038 mTransactionUser(0) 00039 { 00040 } 00041 00042 bool 00043 MessageFilterRule::matches(const SipMessage &msg) const 00044 { 00045 DebugLog(<< "Matching rule for: " << std::endl << std::endl << msg); 00046 const Data scheme = msg.header(h_RequestLine).uri().scheme(); 00047 00048 if (!schemeIsInList(scheme)) 00049 { 00050 DebugLog(<< "Scheme is not in list. Rule does not match."); 00051 return false; 00052 } 00053 00054 if (msg.header(h_RequestLine).uri().scheme() != Symbols::Tel) 00055 { 00056 // !rwm! Should be hostport, not host 00057 if (!hostIsInList( msg.header(h_RequestLine).uri().host())) 00058 { 00059 DebugLog(<< "Host is not in list. Rule does not match."); 00060 return false; 00061 } 00062 } 00063 00064 MethodTypes method = msg.header(h_RequestLine).method(); 00065 if (!methodIsInList(method)) 00066 { 00067 DebugLog(<< "Method is not in list. Rule does not match."); 00068 return false; 00069 } 00070 else 00071 { 00072 switch(method) 00073 { 00074 case SUBSCRIBE: 00075 case NOTIFY: 00076 case PUBLISH: 00077 if (!eventIsInList(msg)) 00078 { 00079 DebugLog(<< "Event is not in list. Rule does not match."); 00080 return false; 00081 } 00082 break; 00083 default: 00084 break; 00085 } 00086 } 00087 00088 return true; 00089 } 00090 00091 bool 00092 MessageFilterRule::schemeIsInList(const Data& scheme) const 00093 { 00094 // Emtpy list means "sip or sips" 00095 if (mSchemeList.empty()) 00096 { 00097 return (scheme == Symbols::Sip || scheme == Symbols::Sips || scheme == Symbols::Tel); 00098 } 00099 00100 // step through mSchemeList looking for supported schemes 00101 for (SchemeList::const_iterator i = mSchemeList.begin(); 00102 i != mSchemeList.end(); i++) 00103 { 00104 if (scheme == *i) 00105 { 00106 return true; 00107 } 00108 00109 } 00110 return false; 00111 } 00112 00113 bool 00114 MessageFilterRule::methodIsInList(MethodTypes method) const 00115 { 00116 // empty list means "match all" 00117 if (mMethodList.empty()) 00118 { 00119 return true; 00120 } 00121 00122 for (MethodList::const_iterator i = mMethodList.begin(); 00123 i != mMethodList.end(); i++) 00124 { 00125 if (method == *i) 00126 { 00127 return true; 00128 } 00129 00130 } 00131 return false; 00132 } 00133 00134 bool 00135 MessageFilterRule::eventIsInList(const SipMessage& msg) const 00136 { 00137 // empty list means "match all" 00138 if (mEventList.empty()) 00139 { 00140 return true; 00141 } 00142 00143 if (!msg.exists(h_Event)) 00144 { 00145 return false; 00146 } 00147 00148 Data event = msg.header(h_Event).value(); 00149 00150 for (EventList::const_iterator i = mEventList.begin(); 00151 i != mEventList.end(); i++) 00152 { 00153 if (event == *i) 00154 { 00155 return true; 00156 } 00157 00158 } 00159 return false; 00160 } 00161 00162 bool 00163 MessageFilterRule::hostIsInList(const Data& hostpart) const 00164 { 00165 switch(mHostpartMatches) 00166 { 00167 case Any: 00168 return true; 00169 case HostIsMe: 00170 // !abr! Waiting for TU support for this method. 00171 // return (tu.hostIsMe(hostpart)); 00172 return false; 00173 break; 00174 case DomainIsMe: 00175 if(mTransactionUser) 00176 { 00177 return mTransactionUser->isMyDomain(hostpart); 00178 } 00179 return false; 00180 break; 00181 case List: 00182 // walk the list for specific matches 00183 for (HostpartList::const_iterator i = mHostpartList.begin() ; 00184 i != mHostpartList.end() ; ++i) 00185 { 00186 if (isEqualNoCase(*i, hostpart)) 00187 return true; 00188 } 00189 break; 00190 default: 00191 break; 00192 } 00193 return false; 00194 } 00195 00196 00197 /* ==================================================================== 00198 * The Vovida Software License, Version 1.0 00199 * 00200 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00201 * 00202 * Redistribution and use in source and binary forms, with or without 00203 * modification, are permitted provided that the following conditions 00204 * are met: 00205 * 00206 * 1. Redistributions of source code must retain the above copyright 00207 * notice, this list of conditions and the following disclaimer. 00208 * 00209 * 2. Redistributions in binary form must reproduce the above copyright 00210 * notice, this list of conditions and the following disclaimer in 00211 * the documentation and/or other materials provided with the 00212 * distribution. 00213 * 00214 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00215 * and "Vovida Open Communication Application Library (VOCAL)" must 00216 * not be used to endorse or promote products derived from this 00217 * software without prior written permission. For written 00218 * permission, please contact vocal@vovida.org. 00219 * 00220 * 4. Products derived from this software may not be called "VOCAL", nor 00221 * may "VOCAL" appear in their name, without prior written 00222 * permission of Vovida Networks, Inc. 00223 * 00224 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00225 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00226 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00227 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00228 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00229 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00230 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00231 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00232 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00233 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00234 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00235 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00236 * DAMAGE. 00237 * 00238 * ==================================================================== 00239 * 00240 * This software consists of voluntary contributions made by Vovida 00241 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00242 * Inc. For more information on Vovida Networks, Inc., please see 00243 * <http://www.vovida.org/>. 00244 * 00245 */
1.7.5.1