OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESContainerStorageCatalog.cc
Go to the documentation of this file.
1 // BESContainerStorageCatalog.cc
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
34 #include "BESContainer.h"
35 #include "BESCatalogUtils.h"
36 #include "BESInternalError.h"
37 #include "BESForbiddenError.h"
38 #include "BESInfo.h"
39 #include "BESServiceRegistry.h"
40 #include "GNURegex.h"
41 #include "Error.h"
42 
43 using namespace libdap ;
44 
68 {
69  _utils = BESCatalogUtils::Utils( n ) ;
70  _root_dir = _utils->get_root_dir() ;
72 }
73 
75 {
76 }
77 
106 void
108  const string &real_name,
109  const string &type )
110 {
111  // make sure that the real name passed in is not oon the exclude list
112  // for the catalog. First, remove any trailing slashes. Then find the
113  // basename of the remaining real name. The make sure it's not on the
114  // exclude list.
115  string::size_type stopat = real_name.length() - 1 ;
116  while( real_name[stopat] == '/' )
117  {
118  stopat-- ;
119  }
120  string new_name = real_name.substr( 0, stopat + 1 ) ;
121 
122  string basename ;
123  string::size_type slash = new_name.rfind( "/" ) ;
124  if( slash != string::npos )
125  {
126  basename = new_name.substr( slash+1, new_name.length() - slash ) ;
127  }
128  else
129  {
130  basename = new_name ;
131  }
132  if( !_utils->include( basename ) || _utils->exclude( basename ) )
133  {
134  string s = "Attempting to create a container with real name "
135  + real_name + " which is on the exclude list" ;
136  throw BESForbiddenError( s, __FILE__, __LINE__ ) ;
137  }
138 
139  // If the type is specified, then just pass that on. If not, then match
140  // it against the types in the type list.
141  string new_type = type ;
142  if( new_type == "" )
143  {
146  bool done = false ;
147  for( ; i != ie && !done; i++ )
148  {
149  BESCatalogUtils::type_reg match = (*i) ;
150  try
151  {
152  Regex reg_expr( match.reg.c_str() ) ;
153  if( reg_expr.match( real_name.c_str(), real_name.length() ) ==
154  static_cast<int>(real_name.length()) )
155  {
156  new_type = match.type ;
157  done = true ;
158  }
159  }
160  catch( Error &e )
161  {
162  string serr = (string)"Unable to match data type, "
163  + "malformed Catalog TypeMatch parameter "
164  + "in bes configuration file around "
165  + match.reg + ": " + e.get_error_message() ;
166  throw BESInternalError( serr, __FILE__, __LINE__ ) ;
167  }
168  }
169  }
170  BESContainerStorageVolatile::add_container( sym_name, real_name, new_type );
171 }
172 
182 bool
183 BESContainerStorageCatalog::isData( const string &inQuestion,
184  list<string> &provides )
185 {
186  string node_type = "" ;
189  bool done = false ;
190  for( ; i != ie && !done; i++ )
191  {
192  BESCatalogUtils::type_reg match = (*i) ;
193  try
194  {
195  Regex reg_expr( match.reg.c_str() ) ;
196  if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
197  static_cast<int>(inQuestion.length()) )
198  {
199  node_type = match.type ;
200  done = true ;
201  }
202  }
203  catch( Error &e )
204  {
205  string serr = (string)"Unable to determine data products (is data), "
206  + "malformed Catalog TypeMatch parameter "
207  + "in bes configuration file around "
208  + match.reg + ": " + e.get_error_message() ;
209  throw BESInternalError( serr, __FILE__, __LINE__ ) ;
210  }
211  }
212 
213  BESServiceRegistry::TheRegistry()->services_handled( node_type, provides ) ;
214 
215  return done ;
216 }
217 
225 void
226 BESContainerStorageCatalog::dump( ostream &strm ) const
227 {
228  strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - ("
229  << (void *)this << ")" << endl ;
231  strm << BESIndent::LMarg << "name: " << get_name() << endl ;
232  strm << BESIndent::LMarg << "utils: " << get_name() << endl ;
234  _utils->dump( strm ) ;
237 }
238 
static const BESCatalogUtils * Utils(const string &name)
exception thrown if inernal error encountered
BESContainerStorageCatalog(const string &n)
create an instance of this persistent store with the given name.
implementation of BESContainerStorage that stores containers in memory for the duration of this proce...
BESCatalogUtils::match_citer match_list_end() const
static void Indent()
Definition: BESIndent.cc:38
virtual void add_container(BESContainer *c)
add the passed container to the list of containers in volatile storage
vector< type_reg >::const_iterator match_citer
bool isData(const string &inQuestion, list< string > &provides)
is the specified node in question served by a request handler
virtual void add_container(const string &sym_name, const string &real_name, const string &type)
adds a container with the provided information
static BESServiceRegistry * TheRegistry()
const string & get_root_dir() const
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual void dump(ostream &strm) const
dumps information about this object
virtual bool include(const string &inQuestion) const
error thrown if the BES is not allowed to access the resource requested
virtual bool exclude(const string &inQuestion) const
BESCatalogUtils::match_citer match_list_begin() const
static void UnIndent()
Definition: BESIndent.cc:44
virtual const string & get_name() const
retrieve the name of this persistent store
bool follow_sym_links() const
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question