BESContainerStorageCatalog.cc

Go to the documentation of this file.
00001 // BESContainerStorageCatalog.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include "BESContainerStorageCatalog.h"
00034 #include "BESContainer.h"
00035 #include "BESCatalogUtils.h"
00036 #include "BESInternalError.h"
00037 #include "BESForbiddenError.h"
00038 #include "BESInfo.h"
00039 #include "GNURegex.h"
00040 #include "Error.h"
00041 
00042 using namespace libdap ;
00043 
00065 BESContainerStorageCatalog::BESContainerStorageCatalog( const string &n )
00066     : BESContainerStorageVolatile( n )
00067 {
00068     _utils = BESCatalogUtils::Utils( n ) ;
00069     _root_dir = _utils->get_root_dir() ;
00070     _follow_sym_links = _utils->follow_sym_links() ;
00071 }
00072 
00073 BESContainerStorageCatalog::~BESContainerStorageCatalog()
00074 { 
00075 }
00076 
00105 void
00106 BESContainerStorageCatalog::add_container( const string &sym_name,
00107                                            const string &real_name,
00108                                            const string &type )
00109 {
00110     // make sure that the real name passed in is not oon the exclude list
00111     // for the catalog. First, remove any trailing slashes. Then find the
00112     // basename of the remaining real name. The make sure it's not on the
00113     // exclude list.
00114     string::size_type stopat = real_name.length() - 1 ;
00115     while( real_name[stopat] == '/' )
00116     {
00117         stopat-- ;
00118     }
00119     string new_name = real_name.substr( 0, stopat + 1 ) ;
00120 
00121     string basename ;
00122     string::size_type slash = new_name.rfind( "/" ) ;
00123     if( slash != string::npos )
00124     {
00125         basename = new_name.substr( slash+1, new_name.length() - slash ) ;
00126     }
00127     else
00128     {
00129         basename = new_name ;
00130     }
00131     if( !_utils->include( basename ) || _utils->exclude( basename ) )
00132     {
00133         string s = "Attempting to create a container with real name "
00134                    + real_name + " which is on the exclude list" ;
00135         throw BESForbiddenError( s, __FILE__, __LINE__ ) ;
00136     }
00137 
00138     // If the type is specified, then just pass that on. If not, then match
00139     // it against the types in the type list.
00140     string new_type = type ;
00141     if( new_type == "" )
00142     {
00143         BESCatalogUtils::match_citer i = _utils->match_list_begin() ;
00144         BESCatalogUtils::match_citer ie = _utils->match_list_end() ;
00145         bool done = false ;
00146         for( ; i != ie && !done; i++ )
00147         {
00148             BESCatalogUtils::type_reg match = (*i) ;
00149             try
00150             {
00151                 Regex reg_expr( match.reg.c_str() ) ;
00152                 if( reg_expr.match( real_name.c_str(), real_name.length() ) == real_name.length() )
00153                 {
00154                     new_type = match.type ;
00155                     done = true ;
00156                 }
00157             }
00158             catch( Error &e )
00159             {
00160                 string serr = (string)"Unable to match data type, "
00161                               + "malformed Catalog TypeMatch parameter " 
00162                               + "in bes configuration file around " 
00163                               + match.reg + ": " + e.get_error_message() ;
00164                 throw BESInternalError( serr, __FILE__, __LINE__ ) ;
00165             }
00166         }
00167     }
00168     BESContainerStorageVolatile::add_container( sym_name, real_name, new_type );
00169 }
00170 
00180 bool
00181 BESContainerStorageCatalog::isData( const string &inQuestion,
00182                                     list<string> &provides )
00183 {
00184     string node_type = "" ;
00185     BESCatalogUtils::match_citer i = _utils->match_list_begin() ;
00186     BESCatalogUtils::match_citer ie = _utils->match_list_end() ;
00187     bool done = false ;
00188     for( ; i != ie && !done; i++ )
00189     {
00190         BESCatalogUtils::type_reg match = (*i) ;
00191         // FIXME: Should we create the Regex and put it in the type_reg
00192         // structure list instead of compiling it each time? Could this
00193         // improve performance? pcw 09/08/06
00194         try
00195         {
00196             Regex reg_expr( match.reg.c_str() ) ;
00197             if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) == inQuestion.length() )
00198             {
00199                 node_type = match.type ;
00200                 done = true ;
00201             }
00202         }
00203         catch( Error &e )
00204         {
00205             string serr = (string)"Unable to determine data products (is data), "
00206                           + "malformed Catalog TypeMatch parameter " 
00207                           + "in bes configuration file around " 
00208                           + match.reg + ": " + e.get_error_message() ;
00209             throw BESInternalError( serr, __FILE__, __LINE__ ) ;
00210         }
00211     }
00212     // TODO: Now that we have the type, go find the request handler and ask
00213     // what it provides (das, dds, ddx, data, etc...)
00214     return done ;
00215 }
00216 
00224 void
00225 BESContainerStorageCatalog::dump( ostream &strm ) const
00226 {
00227     strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - ("
00228                              << (void *)this << ")" << endl ;
00229     BESIndent::Indent() ;
00230     strm << BESIndent::LMarg << "name: " << get_name() << endl ;
00231     strm << BESIndent::LMarg << "utils: " << get_name() << endl ;
00232     BESIndent::Indent() ;
00233     _utils->dump( strm ) ;
00234     BESIndent::UnIndent() ;
00235     BESIndent::UnIndent() ;
00236 }
00237 

Generated on Tue Mar 4 23:13:33 2008 for OPeNDAP Back End Server (BES) by  doxygen 1.5.1