reSIProcate/repro  9694
StrictRouteFixup.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_H)
00002 #include "config.h"
00003 #endif
00004 
00005 #include "resip/stack/SipMessage.hxx"
00006 #include "repro/monkeys/StrictRouteFixup.hxx"
00007 #include "repro/RequestContext.hxx"
00008 #include "repro/Proxy.hxx"
00009 
00010 #include "resip/stack/Helper.hxx"
00011 
00012 #include "rutil/Logger.hxx"
00013 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
00014 
00015 using namespace resip;
00016 using namespace repro;
00017 using namespace std;
00018 
00019 
00020 StrictRouteFixup::StrictRouteFixup() :
00021    Processor("StrictRouteFixup")
00022 {}
00023 
00024 StrictRouteFixup::~StrictRouteFixup()
00025 {}
00026 
00027 /** @brief This monkey looks to see if the request has
00028  *        a Route header (the RequestContext has already
00029  *        done preprocessing, and has removed any topmost
00030  *        route that was self). If there is, the previous
00031  *        hop was a strict routing proxy and the candidate
00032  *        set is exactly the RURI of the received request
00033  *        (after the above preprocessing).
00034  */
00035 Processor::processor_action_t
00036 StrictRouteFixup::process(RequestContext& context)
00037 {
00038    DebugLog(<< "Monkey handling request: " << *this 
00039             << "; reqcontext = " << context);
00040 
00041    resip::SipMessage& request = context.getOriginalRequest();
00042 
00043    if (request.exists(h_Routes) &&
00044        !request.header(h_Routes).empty())
00045    {
00046       if(!request.header(h_Routes).front().isWellFormed())
00047       {
00048          // Garbage topmost Route, reject
00049          SipMessage resp;
00050          resip::Helper::makeResponse(resp, request, 400, "Garbage Route Header.");
00051          context.sendResponse(resp);
00052          return SkipAllChains;
00053       }
00054 
00055       //Will cancel any active transactions (ideally there should be none)
00056       //and terminate any pending transactions.
00057       context.getResponseContext().cancelAllClientTransactions();
00058       std::auto_ptr<Target> target(new Target(request.header(h_RequestLine).uri()));
00059       if(!context.getTopRoute().uri().user().empty())
00060       {
00061          resip::Tuple source(Tuple::makeTupleFromBinaryToken(context.getTopRoute().uri().user().base64decode(), Proxy::FlowTokenSalt));
00062          if(!(source==resip::Tuple()))
00063          {
00064             // valid flow token
00065             target->rec().mReceivedFrom = source;
00066             target->rec().mUseFlowRouting = true;
00067          }
00068       }
00069       context.getResponseContext().addTarget(target);
00070       return Processor::SkipThisChain;
00071    }
00072   
00073    return Processor::Continue;
00074 }
00075 
00076 
00077 /* ====================================================================
00078  * The Vovida Software License, Version 1.0 
00079  * 
00080  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00081  * 
00082  * Redistribution and use in source and binary forms, with or without
00083  * modification, are permitted provided that the following conditions
00084  * are met:
00085  * 
00086  * 1. Redistributions of source code must retain the above copyright
00087  *    notice, this list of conditions and the following disclaimer.
00088  * 
00089  * 2. Redistributions in binary form must reproduce the above copyright
00090  *    notice, this list of conditions and the following disclaimer in
00091  *    the documentation and/or other materials provided with the
00092  *    distribution.
00093  * 
00094  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00095  *    and "Vovida Open Communication Application Library (VOCAL)" must
00096  *    not be used to endorse or promote products derived from this
00097  *    software without prior written permission. For written
00098  *    permission, please contact vocal@vovida.org.
00099  *
00100  * 4. Products derived from this software may not be called "VOCAL", nor
00101  *    may "VOCAL" appear in their name, without prior written
00102  *    permission of Vovida Networks, Inc.
00103  * 
00104  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00105  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00106  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00107  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00108  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00109  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00110  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00111  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00112  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00113  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00114  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00115  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00116  * DAMAGE.
00117  * 
00118  * ====================================================================
00119  * 
00120  * This software consists of voluntary contributions made by Vovida
00121  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00122  * Inc.  For more information on Vovida Networks, Inc., please see
00123  * <http://www.vovida.org/>.
00124  *
00125  */