bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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
50using std::endl;
51using std::string;
52using std::list;
53using std::ostream;
54
55
81{
82 BESCatalog *catalog = BESCatalogList::TheCatalogList()->find_catalog(n);
83
84 _utils = catalog->get_catalog_utils();
85
86 _root_dir = _utils->get_root_dir();
87 _follow_sym_links = _utils->follow_sym_links();
88}
89
90BESFileContainerStorage::~BESFileContainerStorage()
91{
92}
93
123void BESFileContainerStorage::add_container(const string &sym_name, const string &real_name, const string &type)
124{
125 // make sure that the real name passed in is not on the exclude list
126 // for the catalog. First, remove any trailing slashes. Then find the
127 // basename of the remaining real name. The make sure it's not on the
128 // exclude list.
129 BESDEBUG( "bes", "BESFileContainerStorage::add_container: "
130 << "adding container with name \"" << sym_name << "\", real name \""
131 << real_name << "\", type \"" << type << "\"" << endl);
132
133 string::size_type stopat = real_name.size() - 1;
134 while (real_name[stopat] == '/') {
135 stopat--;
136 }
137 string new_name = real_name.substr(0, stopat + 1);
138
139 string basename;
140 string::size_type slash = new_name.rfind("/");
141 if (slash != string::npos) {
142 basename = new_name.substr(slash + 1, new_name.size() - slash);
143 }
144 else {
145 basename = new_name;
146 }
147
148 // BESCatalogUtils::include method already calls exclude, so just call include
149 if (!_utils->include(basename)) {
150 string s = "Attempting to create a container with real name '" + real_name + "' which is excluded from the server's catalog.";
151 throw BESForbiddenError(s, __FILE__, __LINE__);
152 }
153
154 // If the type is specified, then just pass that on. If not, then match
155 // it against the types in the type list.
156 string new_type = type;
157 if (new_type == "") {
158 new_type = _utils->get_handler_name(real_name);
159 }
160
161 BESContainerStorageVolatile::add_container(sym_name, real_name, new_type);
162}
163
173bool BESFileContainerStorage::isData(const string &inQuestion, list<string> &provides)
174{
175 string node_type = _utils->get_handler_name(inQuestion);
176
177 BESServiceRegistry::TheRegistry()->services_handled(node_type, provides);
178
179 return !node_type.empty(); // Return false if node_type is empty, true if a match is found.
180}
181
189void BESFileContainerStorage::dump(ostream &strm) const
190{
191 strm << BESIndent::LMarg << "BESFileContainerStorage::dump - (" << (void *) this << ")" << endl;
192 BESIndent::Indent();
193 strm << BESIndent::LMarg << "name: " << get_name() << endl;
194 strm << BESIndent::LMarg << "utils: " << get_name() << endl;
195 BESIndent::Indent();
196 _utils->dump(strm);
197 BESIndent::UnIndent();
198 BESIndent::UnIndent();
199}
200
const std::string & get_root_dir() const
Get the root directory of the catalog.
Catalogs provide a hierarchical organization for data.
Definition BESCatalog.h:51
virtual BESCatalogUtils * get_catalog_utils() const
Get a pointer to the utilities, customized for this catalog.
Definition BESCatalog.h:112
BESContainerStorageVolatile(const std::string &n)
create an instance of this persistent store with the given name.
virtual void add_container(BESContainer *c)
add the passed container to the list of containers in volatile storage
virtual const std::string & get_name() const
retrieve the name of this persistent store
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
BESFileContainerStorage(const std::string &n)
create an instance of this persistent store with the given name.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual bool isData(const std::string &inQuestion, std::list< std::string > &provides)
is the specified node in question served by a request handler
error thrown if the BES is not allowed to access the resource requested