reSIProcate/repro  9694
GruuMonkey.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 "resip/stack/Helper.hxx"
00007 #include "repro/monkeys/GruuMonkey.hxx"
00008 #include "repro/RequestContext.hxx"
00009 #include "repro/Proxy.hxx"
00010 #include "resip/dum/RegistrationPersistence
00011 #include <ostream>
00012 
00013 #include "rutil/Logger.hxx"
00014 #define RESIPROCATE_SUBSYSTEM resip::Subsystem::REPRO
00015 
00016 using namespace resip;
00017 using namespace repro;
00018 using namespace std;
00019 
00020 GruuMonkey::GruuMonkey()
00021 {}
00022 
00023 GruuMonkey::~GruuMonkey()
00024 {}
00025 
00026 Processor::processor_action_t
00027 GruuMonkey::process(RequestContext& context)
00028 {
00029    DebugLog(<< "Monkey handling request: " << *this 
00030             << "; reqcontext = " << context);
00031 
00032    resip::SipMessage& request = context.getOriginalRequest();
00033 
00034    //    sip:alice;uuid:urn:00000-000-8....@example.com;user=gruu
00035    //
00036    // Looking for a Request URI which contains ";user=gruu"
00037    
00038    
00039    // This monkey looks for a Request URIs such as:
00040    //    sip:alice@example.com;opaque=uuid:urn:0000-000-89akkskhnasd
00041    //
00042    // Looking for a Request URI which contains an opaque parameter
00043    
00044    
00045    Uri reqUri = request.header(h_RequestLine).uri();
00046    
00047    if (reqUri.exists(p_opaque))
00048    {
00049       Uri aor = reqUri.getAor();
00050       Data instance = reqUri.param(p_opaque);
00051       
00052       // find the GRUU from the AOR and instance
00053       
00054       if (!mStore.mUserStore.aorExists(aor))
00055       {
00056          // send 404 Not Found
00057          resip::SipMessage response;
00058          InfoLog (<< *this << ": no AOR matching this GRUU found.  Gruu: <" << uri << ">, sending 404");
00059          Helper::makeResponse(response, request, 404); 
00060          context.sendResponse(response);
00061          return Processor::SkipThisChain;            
00062       }
00063       
00064       if (mStore.isContactRegistered(reqUri.getAor(), reqUri.param(p_opaque)))
00065       {
00066          // grab the grid from the Request URI
00067          Data grid;
00068          if (reqUri.exists(p_grid))
00069          {
00070             grid = reqUri.params(p_grid);
00071          }
00072       
00073          // walk through the entries that match the instance and aor
00074          RegistrationPersistenceManager::ContactList records = mStore.getRegistrationBinding(aor)->mContacts;
00075          RegistrationPersistenceManager::ContactList::const_iterator i;
00076          
00077          for (i = records.begin(); i != records.end(); ++i)
00078          {
00079             if (i->mInstance == reqUri.param(p_opaque))
00080             {
00081                NameAddr newTarget = i->mContact.uri();
00082                // strip caller prefs
00083                // strip instance and flowId
00084                // preserve q-values
00085                if (i->mContact.exists(p_q))
00086                {
00087                   newTarget.param(p_q) = i->mContact.param(p_q);
00088                }
00089                
00090                // copy the grid over from the request URI
00091                if (!grid.empty())
00092                {
00093                   newTarget.uri().param(p_grid) = grid;
00094                }
00095                
00096                // populate the targetSet with appropriate tuple (or sessionId) and URI combo
00097                // !rwm! TODO add a version of addTarget that take the server session id or the Path
00098                // and only uses sendOverExistingConnection 
00099                if (i->mSipPath.empty())
00100                {
00101                   assert(i->mServerSessionId)  // make sure there is either a Path or a sessionId
00102                   context.addTarget(newTarget, i->mServerSessionId);
00103                }
00104                else
00105                {
00106                   context.addTarget(newTarget, i->mSipPath);
00107                }
00108             }
00109 
00110             
00111             InfoLog (<< "Sending to requri: " << request.header(h_RequestLine).uri());
00112             // skip the rest of the monkeys
00113             return Processor::SkipThisChain;                
00114          }
00115          else  // nobody home with that GRUU
00116          {
00117             // send 480 Temporarily Unavailable
00118             resip::SipMessage response;
00119             InfoLog (<< *this << ": no contacts matching this GRUU found.  Gruu: <" << uri << ">, sending 480");
00120             Helper::makeResponse(response, request, 480); 
00121             context.sendResponse(response);
00122             return Processor::SkipThisChain;
00123          }
00124       }
00125    }
00126    return Processor::Continue;
00127 }
00128    
00129 
00130 void
00131 GruuMonkey::dump(std::ostream &os) const
00132 {
00133   os << "Gruu Monkey" << std::endl;
00134 }
00135 
00136 
00137 /* ====================================================================
00138  * The Vovida Software License, Version 1.0 
00139  * 
00140  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00141  * 
00142  * Redistribution and use in source and binary forms, with or without
00143  * modification, are permitted provided that the following conditions
00144  * are met:
00145  * 
00146  * 1. Redistributions of source code must retain the above copyright
00147  *    notice, this list of conditions and the following disclaimer.
00148  * 
00149  * 2. Redistributions in binary form must reproduce the above copyright
00150  *    notice, this list of conditions and the following disclaimer in
00151  *    the documentation and/or other materials provided with the
00152  *    distribution.
00153  * 
00154  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00155  *    and "Vovida Open Communication Application Library (VOCAL)" must
00156  *    not be used to endorse or promote products derived from this
00157  *    software without prior written permission. For written
00158  *    permission, please contact vocal@vovida.org.
00159  *
00160  * 4. Products derived from this software may not be called "VOCAL", nor
00161  *    may "VOCAL" appear in their name, without prior written
00162  *    permission of Vovida Networks, Inc.
00163  * 
00164  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00165  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00166  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00167  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00168  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00169  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00170  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00171  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00172  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00173  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00174  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00175  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00176  * DAMAGE.
00177  * 
00178  * ====================================================================
00179  * 
00180  * This software consists of voluntary contributions made by Vovida
00181  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00182  * Inc.  For more information on Vovida Networks, Inc., please see
00183  * <http://www.vovida.org/>.
00184  *
00185  */