|
reSIProcate/repro
9694
|
00001 #if defined(HAVE_CONFIG_H) 00002 #include "config.h" 00003 #endif 00004 00005 #include "resip/stack/SipMessage.hxx" 00006 #include "resip/stack/Helper.hxx" 00007 #include "repro/monkeys/StaticRoute.hxx" 00008 #include "repro/monkeys/IsTrustedNode.hxx" 00009 #include "repro/RequestContext.hxx" 00010 #include "repro/QValueTarget.hxx" 00011 00012 #include "rutil/Logger.hxx" 00013 #include "repro/RouteStore.hxx" 00014 00015 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO 00016 00017 using namespace resip; 00018 using namespace repro; 00019 using namespace std; 00020 00021 StaticRoute::StaticRoute(ProxyConfig& config) : 00022 Processor("StaticRoute"), 00023 mRouteStore(config.getDataStore()->mRouteStore), 00024 mNoChallenge(config.getConfigBool("DisableAuth", false)), 00025 mParallelForkStaticRoutes(config.getConfigBool("ParallelForkStaticRoutes", false)), 00026 mContinueProcessingAfterRoutesFound(config.getConfigBool("ContinueProcessingAfterRoutesFound", false)), 00027 mUseAuthInt(!config.getConfigBool("DisableAuthInt", false)) 00028 {} 00029 00030 StaticRoute::~StaticRoute() 00031 {} 00032 00033 Processor::processor_action_t 00034 StaticRoute::process(RequestContext& context) 00035 { 00036 DebugLog(<< "Monkey handling request: " << *this 00037 << "; reqcontext = " << context); 00038 00039 SipMessage& msg = context.getOriginalRequest(); 00040 00041 Uri ruri(msg.header(h_RequestLine).uri()); 00042 Data method(getMethodName(msg.header(h_RequestLine).method())); 00043 Data event; 00044 if ( msg.exists(h_Event) && msg.header(h_Event).isWellFormed()) 00045 { 00046 event = msg.header(h_Event).value() ; 00047 } 00048 00049 RouteStore::UriList targets(mRouteStore.process( ruri, 00050 method, 00051 event)); 00052 bool requireAuth = false; 00053 if(!context.getKeyValueStore().getBoolValue(IsTrustedNode::mFromTrustedNodeKey) && 00054 msg.method() != ACK && // Don't challenge ACK and BYE requests 00055 msg.method() != BYE) 00056 { 00057 requireAuth = !mNoChallenge; 00058 //for ( RouteStore::UriList::const_iterator i = targets.begin(); 00059 // i != targets.end(); i++ ) 00060 //{ 00061 // !rwm! TODO would be useful to check if these targets require authentication 00062 // but for know we will just fail safe and assume that all routes require auth 00063 // if the sender is not trusted 00064 // requireAuth |= !mNoChallenge; 00065 //} 00066 } 00067 00068 if (requireAuth && context.getDigestIdentity().empty()) 00069 { 00070 // !rwm! TODO do we need anything more sophisticated to figure out the realm? 00071 Data realm = msg.header(h_RequestLine).uri().host(); 00072 00073 challengeRequest(context, realm); 00074 return Processor::SkipAllChains; 00075 } 00076 else 00077 { 00078 TargetPtrList parallelBatch; 00079 for (RouteStore::UriList::const_iterator i = targets.begin(); 00080 i != targets.end(); i++ ) 00081 { 00082 //Targets are only added after authentication 00083 InfoLog(<< "Adding target " << *i ); 00084 00085 if(mParallelForkStaticRoutes) 00086 { 00087 Target* target = new Target(*i); 00088 parallelBatch.push_back(target); 00089 } 00090 else 00091 { 00092 // Add Simple Target 00093 context.getResponseContext().addTarget(NameAddr(*i)); 00094 } 00095 } 00096 if(parallelBatch.size() > 0) 00097 { 00098 context.getResponseContext().addTargetBatch(parallelBatch, false /* highPriority */); 00099 } 00100 00101 if(!targets.empty() && !mContinueProcessingAfterRoutesFound) 00102 { 00103 return Processor::SkipThisChain; 00104 } 00105 } 00106 00107 return Processor::Continue; 00108 } 00109 00110 void 00111 StaticRoute::challengeRequest(repro::RequestContext &rc, resip::Data &realm) 00112 { 00113 Message *message = rc.getCurrentEvent(); 00114 SipMessage *sipMessage = dynamic_cast<SipMessage*>(message); 00115 assert(sipMessage); 00116 00117 SipMessage *challenge = Helper::makeProxyChallenge(*sipMessage, realm, mUseAuthInt /*auth-int*/, false /*stale*/); 00118 rc.sendResponse(*challenge); 00119 00120 delete challenge; 00121 } 00122 00123 00124 /* ==================================================================== 00125 * The Vovida Software License, Version 1.0 00126 * 00127 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00128 * 00129 * Redistribution and use in source and binary forms, with or without 00130 * modification, are permitted provided that the following conditions 00131 * are met: 00132 * 00133 * 1. Redistributions of source code must retain the above copyright 00134 * notice, this list of conditions and the following disclaimer. 00135 * 00136 * 2. Redistributions in binary form must reproduce the above copyright 00137 * notice, this list of conditions and the following disclaimer in 00138 * the documentation and/or other materials provided with the 00139 * distribution. 00140 * 00141 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00142 * and "Vovida Open Communication Application Library (VOCAL)" must 00143 * not be used to endorse or promote products derived from this 00144 * software without prior written permission. For written 00145 * permission, please contact vocal@vovida.org. 00146 * 00147 * 4. Products derived from this software may not be called "VOCAL", nor 00148 * may "VOCAL" appear in their name, without prior written 00149 * permission of Vovida Networks, Inc. 00150 * 00151 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00152 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00153 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00154 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00155 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00156 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00157 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00158 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00159 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00160 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00161 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00162 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00163 * DAMAGE. 00164 * 00165 * ==================================================================== 00166 */
1.7.5.1