reSIProcate/repro  9694
RouteStore.hxx
Go to the documentation of this file.
00001 #if !defined(REPRO_ROUTESTORE_HXX)
00002 #define REPRO_ROUTESTORE_HXX
00003 
00004 #ifdef WIN32
00005 #include <pcreposix.h>
00006 #else
00007 #include <regex.h>
00008 #endif
00009 
00010 #include <set>
00011 
00012 #include "rutil/Data.hxx"
00013 #include "rutil/RWMutex.hxx"
00014 #include "resip/stack/Uri.hxx"
00015 
00016 #include "repro/AbstractDb.hxx"
00017 
00018 
00019 namespace repro
00020 {
00021 //class AbstractDb;
00022 
00023 class RouteStore
00024 {
00025    public:
00026       typedef std::vector<resip::Uri> UriList;
00027       typedef resip::Data Key;
00028       
00029       RouteStore(AbstractDb& db);
00030       ~RouteStore();
00031       
00032       bool addRoute(const resip::Data& method,
00033                     const resip::Data& event,
00034                     const resip::Data& matchingPattern,
00035                     const resip::Data& rewriteExpression,
00036                     const int order );
00037       
00038       void eraseRoute(const resip::Data& method,
00039                       const resip::Data& event,
00040                       const resip::Data& matchingPattern);
00041       void eraseRoute( const resip::Data& key );
00042 
00043       bool updateRoute( const resip::Data& originalKey,
00044                         const resip::Data& method,
00045                         const resip::Data& event,
00046                         const resip::Data& matchingPattern,
00047                         const resip::Data& rewriteExpression,
00048                         const int order );
00049       
00050       AbstractDb::RouteRecord getRouteRecord(const resip::Data& key);
00051       
00052       Key getFirstKey();// return empty if no more
00053       Key getNextKey(Key& key); // return empty if no more 
00054       
00055       UriList process(const resip::Uri& ruri, 
00056                       const resip::Data& method, 
00057                       const resip::Data& event );
00058 
00059    private:
00060       bool findKey(const Key& key); // move cursor to key
00061       
00062       Key buildKey(const resip::Data& method,
00063                    const resip::Data& event,
00064                    const resip::Data& matchingPattern ) const;
00065 
00066       AbstractDb& mDb;  
00067 
00068       class RouteOp
00069       {
00070          public:
00071             Key key;
00072             regex_t *preq;
00073             AbstractDb::RouteRecord routeRecord;
00074             bool operator<(const RouteOp&) const;
00075       };
00076       
00077       resip::RWMutex mMutex;
00078       typedef std::multiset<RouteOp> RouteOpList;
00079       RouteOpList mRouteOperators; 
00080       RouteOpList::iterator mCursor;
00081 };
00082 
00083  }
00084 #endif  
00085 
00086 /* ====================================================================
00087  * The Vovida Software License, Version 1.0 
00088  * 
00089  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00090  * 
00091  * Redistribution and use in source and binary forms, with or without
00092  * modification, are permitted provided that the following conditions
00093  * are met:
00094  * 
00095  * 1. Redistributions of source code must retain the above copyright
00096  *    notice, this list of conditions and the following disclaimer.
00097  * 
00098  * 2. Redistributions in binary form must reproduce the above copyright
00099  *    notice, this list of conditions and the following disclaimer in
00100  *    the documentation and/or other materials provided with the
00101  *    distribution.
00102  * 
00103  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00104  *    and "Vovida Open Communication Application Library (VOCAL)" must
00105  *    not be used to endorse or promote products derived from this
00106  *    software without prior written permission. For written
00107  *    permission, please contact vocal@vovida.org.
00108  *
00109  * 4. Products derived from this software may not be called "VOCAL", nor
00110  *    may "VOCAL" appear in their name, without prior written
00111  *    permission of Vovida Networks, Inc.
00112  * 
00113  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00114  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00115  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00116  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00117  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00118  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00119  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00120  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00121  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00122  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00123  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00124  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00125  * DAMAGE.
00126  * 
00127  * ====================================================================
00128  */