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 "BESRegex.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  // BESCatalogUtils::include method already calls exclude, so just
133  // need to call include
134  if( !_utils->include( basename ) )
135  {
136  string s = "Attempting to create a container with real name "
137  + real_name + " which is on the exclude list" ;
138  throw BESForbiddenError( s, __FILE__, __LINE__ ) ;
139  }
140 
141  // If the type is specified, then just pass that on. If not, then match
142  // it against the types in the type list.
143  string new_type = type ;
144  if( new_type == "" )
145  {
148  bool done = false ;
149  for( ; i != ie && !done; i++ )
150  {
151  BESCatalogUtils::type_reg match = (*i) ;
152  try
153  {
154  BESRegex reg_expr( match.reg.c_str() ) ;
155  if( reg_expr.match( real_name.c_str(), real_name.length() ) ==
156  static_cast<int>(real_name.length()) )
157  {
158  new_type = match.type ;
159  done = true ;
160  }
161  }
162  catch( Error &e )
163  {
164  string serr = (string)"Unable to match data type, "
165  + "malformed Catalog TypeMatch parameter "
166  + "in bes configuration file around "
167  + match.reg + ": " + e.get_error_message() ;
168  throw BESInternalError( serr, __FILE__, __LINE__ ) ;
169  }
170  }
171  }
172  BESContainerStorageVolatile::add_container( sym_name, real_name, new_type );
173 }
174 
184 bool
185 BESContainerStorageCatalog::isData( const string &inQuestion,
186  list<string> &provides )
187 {
188  string node_type = "" ;
191  bool done = false ;
192  for( ; i != ie && !done; i++ )
193  {
194  BESCatalogUtils::type_reg match = (*i) ;
195  try
196  {
197  BESRegex reg_expr( match.reg.c_str() ) ;
198  if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
199  static_cast<int>(inQuestion.length()) )
200  {
201  node_type = match.type ;
202  done = true ;
203  }
204  }
205  catch( Error &e )
206  {
207  string serr = (string)"Unable to determine data products (is data), "
208  + "malformed Catalog TypeMatch parameter "
209  + "in bes configuration file around "
210  + match.reg + ": " + e.get_error_message() ;
211  throw BESInternalError( serr, __FILE__, __LINE__ ) ;
212  }
213  }
214 
215  BESServiceRegistry::TheRegistry()->services_handled( node_type, provides ) ;
216 
217  return done ;
218 }
219 
227 void
228 BESContainerStorageCatalog::dump( ostream &strm ) const
229 {
230  strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - ("
231  << (void *)this << ")" << endl ;
233  strm << BESIndent::LMarg << "name: " << get_name() << endl ;
234  strm << BESIndent::LMarg << "utils: " << get_name() << endl ;
236  _utils->dump( strm ) ;
239 }
240