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 "BESDebug.h"
42 #include "Error.h"
43 
44 using namespace libdap ;
45 
69 {
70  _utils = BESCatalogUtils::Utils( n ) ;
71  _root_dir = _utils->get_root_dir() ;
73 }
74 
76 {
77 }
78 
107 void
109  const string &real_name,
110  const string &type )
111 {
112  // make sure that the real name passed in is not oon the exclude list
113  // for the catalog. First, remove any trailing slashes. Then find the
114  // basename of the remaining real name. The make sure it's not on the
115  // exclude list.
116  BESDEBUG( "bes", "BESContainerStorageCatalog::add_container: "
117  << "adding container with name \"" << sym_name
118  << "\", real name \"" << real_name
119  << "\", type \"" << type << "\"" << endl ) ;
120  string::size_type stopat = real_name.length() - 1 ;
121  while( real_name[stopat] == '/' )
122  {
123  stopat-- ;
124  }
125  string new_name = real_name.substr( 0, stopat + 1 ) ;
126 
127  string basename ;
128  string::size_type slash = new_name.rfind( "/" ) ;
129  if( slash != string::npos )
130  {
131  basename = new_name.substr( slash+1, new_name.length() - slash ) ;
132  }
133  else
134  {
135  basename = new_name ;
136  }
137  // BESCatalogUtils::include method already calls exclude, so just
138  // need to call include
139  if( !_utils->include( basename ) )
140  {
141  string s = "Attempting to create a container with real name "
142  + real_name + " which is on the exclude list" ;
143  throw BESForbiddenError( s, __FILE__, __LINE__ ) ;
144  }
145 
146  // If the type is specified, then just pass that on. If not, then match
147  // it against the types in the type list.
148  string new_type = type ;
149  if( new_type == "" )
150  {
153  bool done = false ;
154  for( ; i != ie && !done; i++ )
155  {
156  BESCatalogUtils::type_reg match = (*i) ;
157  try
158  {
159  BESRegex reg_expr( match.reg.c_str() ) ;
160  if( reg_expr.match( real_name.c_str(), real_name.length() ) ==
161  static_cast<int>(real_name.length()) )
162  {
163  new_type = match.type ;
164  done = true ;
165  }
166  }
167  catch( Error &e )
168  {
169  string serr = (string)"Unable to match data type, "
170  + "malformed Catalog TypeMatch parameter "
171  + "in bes configuration file around "
172  + match.reg + ": " + e.get_error_message() ;
173  throw BESInternalError( serr, __FILE__, __LINE__ ) ;
174  }
175  }
176  }
177  BESContainerStorageVolatile::add_container( sym_name, real_name, new_type );
178 }
179 
189 bool
190 BESContainerStorageCatalog::isData( const string &inQuestion,
191  list<string> &provides )
192 {
193  string node_type = "" ;
196  bool done = false ;
197  for( ; i != ie && !done; i++ )
198  {
199  BESCatalogUtils::type_reg match = (*i) ;
200  try
201  {
202  BESRegex reg_expr( match.reg.c_str() ) ;
203  if( reg_expr.match( inQuestion.c_str(), inQuestion.length() ) ==
204  static_cast<int>(inQuestion.length()) )
205  {
206  node_type = match.type ;
207  done = true ;
208  }
209  }
210  catch( Error &e )
211  {
212  string serr = (string)"Unable to determine data products (is data), "
213  + "malformed Catalog TypeMatch parameter "
214  + "in bes configuration file around "
215  + match.reg + ": " + e.get_error_message() ;
216  throw BESInternalError( serr, __FILE__, __LINE__ ) ;
217  }
218  }
219 
220  BESServiceRegistry::TheRegistry()->services_handled( node_type, provides ) ;
221 
222  return done ;
223 }
224 
232 void
233 BESContainerStorageCatalog::dump( ostream &strm ) const
234 {
235  strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - ("
236  << (void *)this << ")" << endl ;
238  strm << BESIndent::LMarg << "name: " << get_name() << endl ;
239  strm << BESIndent::LMarg << "utils: " << get_name() << endl ;
241  _utils->dump( strm ) ;
244 }
245