bes  Updated for version 3.20.5
BESFileContainerStorage.cc
1 // BESFileContainerStorage.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 
33 #include "config.h"
34 
35 #include "BESFileContainerStorage.h"
36 #include "BESContainer.h"
37 
38 #include "BESCatalogList.h"
39 #include "BESCatalog.h"
40 
41 #include "BESCatalogUtils.h"
42 #include "BESInfo.h"
43 #include "BESServiceRegistry.h"
44 #include "BESRegex.h"
45 #include "BESInternalError.h"
46 #include "BESForbiddenError.h"
47 
48 #include "BESDebug.h"
49 
50 
76 {
77  BESCatalog *catalog = BESCatalogList::TheCatalogList()->find_catalog(n);
78 
79  _utils = catalog->get_catalog_utils();
80 
81  _root_dir = _utils->get_root_dir();
82  _follow_sym_links = _utils->follow_sym_links();
83 }
84 
85 BESFileContainerStorage::~BESFileContainerStorage()
86 {
87 }
88 
118 void BESFileContainerStorage::add_container(const string &sym_name, const string &real_name, const string &type)
119 {
120  // make sure that the real name passed in is not on the exclude list
121  // for the catalog. First, remove any trailing slashes. Then find the
122  // basename of the remaining real name. The make sure it's not on the
123  // exclude list.
124  BESDEBUG( "bes", "BESFileContainerStorage::add_container: "
125  << "adding container with name \"" << sym_name << "\", real name \""
126  << real_name << "\", type \"" << type << "\"" << endl);
127 
128  string::size_type stopat = real_name.length() - 1;
129  while (real_name[stopat] == '/') {
130  stopat--;
131  }
132  string new_name = real_name.substr(0, stopat + 1);
133 
134  string basename;
135  string::size_type slash = new_name.rfind("/");
136  if (slash != string::npos) {
137  basename = new_name.substr(slash + 1, new_name.length() - slash);
138  }
139  else {
140  basename = new_name;
141  }
142 
143  // BESCatalogUtils::include method already calls exclude, so just call include
144  if (!_utils->include(basename)) {
145  string s = "Attempting to create a container with real name '" + real_name + "' which is excluded from the server's catalog.";
146  throw BESForbiddenError(s, __FILE__, __LINE__);
147  }
148 
149  // If the type is specified, then just pass that on. If not, then match
150  // it against the types in the type list.
151  string new_type = type;
152  if (new_type == "") {
153  new_type = _utils->get_handler_name(real_name);
154  }
155 
156  BESContainerStorageVolatile::add_container(sym_name, real_name, new_type);
157 }
158 
168 bool BESFileContainerStorage::isData(const string &inQuestion, list<string> &provides)
169 {
170  string node_type = _utils->get_handler_name(inQuestion);
171 
172  BESServiceRegistry::TheRegistry()->services_handled(node_type, provides);
173 
174  return !node_type.empty(); // Return false if node_type is empty, true if a match is found.
175 }
176 
184 void BESFileContainerStorage::dump(ostream &strm) const
185 {
186  strm << BESIndent::LMarg << "BESFileContainerStorage::dump - (" << (void *) this << ")" << endl;
187  BESIndent::Indent();
188  strm << BESIndent::LMarg << "name: " << get_name() << endl;
189  strm << BESIndent::LMarg << "utils: " << get_name() << endl;
190  BESIndent::Indent();
191  _utils->dump(strm);
192  BESIndent::UnIndent();
193  BESIndent::UnIndent();
194 }
195 
BESCatalogUtils::include
virtual bool include(const std::string &inQuestion) const
Should this file/directory be included in the catalog?
Definition: BESCatalogUtils.cc:183
BESCatalogUtils::dump
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
Definition: BESCatalogUtils.cc:506
BESContainerStorageVolatile::add_container
virtual void add_container(BESContainer *c)
add the passed container to the list of containers in volatile storage
Definition: BESContainerStorageVolatile.cc:177
BESFileContainerStorage::isData
virtual bool isData(const std::string &inQuestion, std::list< std::string > &provides)
is the specified node in question served by a request handler
Definition: BESFileContainerStorage.cc:168
BESFileContainerStorage::BESFileContainerStorage
BESFileContainerStorage(const std::string &n)
create an instance of this persistent store with the given name.
Definition: BESFileContainerStorage.cc:74
BESContainerStorageVolatile
implementation of BESContainerStorage that stores containers in memory for the duration of this proce...
Definition: BESContainerStorageVolatile.h:62
BESContainerStorage::get_name
virtual const std::string & get_name() const
retrieve the name of this persistent store
Definition: BESContainerStorage.h:96
BESCatalogList::TheCatalogList
static BESCatalogList * TheCatalogList()
Get the singleton BESCatalogList instance.
Definition: BESCatalogList.cc:81
BESCatalogUtils::get_handler_name
std::string get_handler_name(const std::string &item) const
Find the handler name that will process.
Definition: BESCatalogUtils.cc:422
BESFileContainerStorage::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESFileContainerStorage.cc:184
BESForbiddenError
error thrown if the BES is not allowed to access the resource requested
Definition: BESForbiddenError.h:40
BESCatalog::get_catalog_utils
virtual BESCatalogUtils * get_catalog_utils() const
Get a pointer to the utilities, customized for this catalog.
Definition: BESCatalog.h:113
BESCatalogUtils::get_root_dir
const std::string & get_root_dir() const
Get the root directory of the catalog.
Definition: BESCatalogUtils.h:102
BESCatalog
Catalogs provide a hierarchical organization for data.
Definition: BESCatalog.h:51
BESFileContainerStorage::add_container
virtual void add_container(const std::string &sym_name, const std::string &real_name, const std::string &type)
adds a container with the provided information
Definition: BESFileContainerStorage.cc:118
BESServiceRegistry::services_handled
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question
Definition: BESServiceRegistry.cc:328