|
reSIProcate/stack
9694
|
00001 #include "resip/stack/TransactionUser.hxx" 00002 #include "resip/stack/MessageFilterRule.hxx" 00003 #include "rutil/Logger.hxx" 00004 #include "rutil/WinLeakCheck.hxx" 00005 00006 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::TRANSACTION 00007 00008 using namespace resip; 00009 00010 TransactionUser::TransactionUser(TransactionTermination t, 00011 ConnectionTermination c, 00012 KeepAlivePongs k) : 00013 mFifo(0, 0), 00014 mCongestionManager(0), 00015 mRuleList(), 00016 mDomainList(), 00017 mRegisteredForTransactionTermination(t == RegisterForTransactionTermination), 00018 mRegisteredForConnectionTermination(c == RegisterForConnectionTermination), 00019 mRegisteredForKeepAlivePongs(k == RegisterForKeepAlivePongs) 00020 { 00021 // This creates a default message filter rule, which 00022 // handles all sip:, sips:, and tel: requests. 00023 mRuleList.push_back(MessageFilterRule()); 00024 00025 // Set a default Fifo description - should be modified by override class to be 00026 // more desriptive 00027 mFifo.setDescription("TransactionUser::mFifo"); 00028 } 00029 00030 TransactionUser::TransactionUser(MessageFilterRuleList &mfrl, 00031 TransactionTermination t, 00032 ConnectionTermination c, 00033 KeepAlivePongs k) : 00034 mFifo(0, 0), 00035 mCongestionManager(0), 00036 mRuleList(mfrl), 00037 mDomainList(), 00038 mRegisteredForTransactionTermination(t == RegisterForTransactionTermination), 00039 mRegisteredForConnectionTermination(c == RegisterForConnectionTermination), 00040 mRegisteredForKeepAlivePongs(k == RegisterForKeepAlivePongs) 00041 { 00042 // Set a default Fifo description - should be modified by override class to be 00043 // more desriptive 00044 mFifo.setDescription("TransactionUser::mFifo"); 00045 } 00046 00047 TransactionUser::~TransactionUser() 00048 { 00049 } 00050 00051 void 00052 TransactionUser::post(Message* msg) 00053 { 00054 mFifo.add(msg, TimeLimitFifo<Message>::InternalElement); 00055 } 00056 00057 void 00058 TransactionUser::postToTransactionUser(Message* msg, TimeLimitFifo<Message>::DepthUsage usage) 00059 { 00060 mFifo.add(msg, usage); 00061 //DebugLog (<< "TransactionUser::postToTransactionUser " << msg->brief() << " &=" << &mFifo << " size=" << mFifo.size()); 00062 } 00063 00064 unsigned int 00065 TransactionUser::size() const 00066 { 00067 return mFifo.size(); 00068 } 00069 00070 bool 00071 TransactionUser::wouldAccept(TimeLimitFifo<Message>::DepthUsage usage) const 00072 { 00073 return mFifo.wouldAccept(usage); 00074 } 00075 00076 bool 00077 TransactionUser::isForMe(const SipMessage& msg) const 00078 { 00079 DebugLog (<< "Checking if " << msg.brief() << " is for me"); 00080 // do this for each MessageFilterRule 00081 for (MessageFilterRuleList::const_iterator i = mRuleList.begin() ; 00082 i != mRuleList.end() ; ++i) 00083 { 00084 DebugLog (<< "Checking rule..."); 00085 if (i->matches(msg)) 00086 { 00087 DebugLog (<< "Match!"); 00088 return true; 00089 } 00090 } 00091 DebugLog (<< "No matching rule found"); 00092 return false; 00093 } 00094 00095 bool 00096 TransactionUser::isMyDomain(const Data& domain) const 00097 { 00098 // Domain search should be case insensitive - search in lowercase only 00099 return mDomainList.count(Data(domain).lowercase()) > 0; 00100 } 00101 00102 void TransactionUser::addDomain(const Data& domain) 00103 { 00104 // Domain search should be case insensitive - store in lowercase only 00105 mDomainList.insert(Data(domain).lowercase()); 00106 } 00107 00108 EncodeStream& 00109 TransactionUser::encode(EncodeStream& strm) const 00110 { 00111 strm << "TU: " << name() << " size=" << mFifo.size(); 00112 return strm; 00113 } 00114 00115 void 00116 TransactionUser::setMessageFilterRuleList(MessageFilterRuleList &rules) 00117 { 00118 mRuleList = rules; 00119 MessageFilterRuleList::iterator it = mRuleList.begin(); 00120 for(;it!=mRuleList.end();it++) 00121 { 00122 it->setTransactionUser(this); 00123 } 00124 } 00125 00126 bool 00127 TransactionUser::isRegisteredForTransactionTermination() const 00128 { 00129 return mRegisteredForTransactionTermination; 00130 } 00131 00132 bool 00133 TransactionUser::isRegisteredForConnectionTermination() const 00134 { 00135 return mRegisteredForConnectionTermination; 00136 } 00137 00138 bool 00139 TransactionUser::isRegisteredForKeepAlivePongs() const 00140 { 00141 return mRegisteredForKeepAlivePongs; 00142 } 00143 00144 EncodeStream& 00145 resip::operator<<(EncodeStream& strm, const resip::TransactionUser& tu) 00146 { 00147 tu.encode(strm); 00148 return strm; 00149 } 00150 00151 /* ==================================================================== 00152 * The Vovida Software License, Version 1.0 00153 * 00154 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00155 * 00156 * Redistribution and use in source and binary forms, with or without 00157 * modification, are permitted provided that the following conditions 00158 * are met: 00159 * 00160 * 1. Redistributions of source code must retain the above copyright 00161 * notice, this list of conditions and the following disclaimer. 00162 * 00163 * 2. Redistributions in binary form must reproduce the above copyright 00164 * notice, this list of conditions and the following disclaimer in 00165 * the documentation and/or other materials provided with the 00166 * distribution. 00167 * 00168 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00169 * and "Vovida Open Communication Application Library (VOCAL)" must 00170 * not be used to endorse or promote products derived from this 00171 * software without prior written permission. For written 00172 * permission, please contact vocal@vovida.org. 00173 * 00174 * 4. Products derived from this software may not be called "VOCAL", nor 00175 * may "VOCAL" appear in their name, without prior written 00176 * permission of Vovida Networks, Inc. 00177 * 00178 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00179 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00180 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00181 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00182 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00183 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00184 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00185 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00186 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00187 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00188 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00189 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00190 * DAMAGE. 00191 * 00192 * ==================================================================== 00193 * 00194 * This software consists of voluntary contributions made by Vovida 00195 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00196 * Inc. For more information on Vovida Networks, Inc., please see 00197 * <http://www.vovida.org/>. 00198 * 00199 */
1.7.5.1