00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00111
00112
00113
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
00139
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
00192
00193
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
00213
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