bes  Updated for version 3.17.4
BESContainerStorageCatalog.cc
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., 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 "BESContainerStorageCatalog.h"
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 
66 {
67  _utils = BESCatalogUtils::Utils(n);
68  _root_dir = _utils->get_root_dir();
69  _follow_sym_links = _utils->follow_sym_links();
70 }
71 
72 BESContainerStorageCatalog::~BESContainerStorageCatalog()
73 {
74 }
75 
104 void BESContainerStorageCatalog::add_container(const string &sym_name, const string &real_name, const string &type)
105 {
106  // make sure that the real name passed in is not oon the exclude list
107  // for the catalog. First, remove any trailing slashes. Then find the
108  // basename of the remaining real name. The make sure it's not on the
109  // exclude list.
110  BESDEBUG( "bes", "BESContainerStorageCatalog::add_container: "
111  << "adding container with name \"" << sym_name << "\", real name \""
112  << real_name << "\", type \"" << type << "\"" << endl);
113 
114  string::size_type stopat = real_name.length() - 1;
115  while (real_name[stopat] == '/') {
116  stopat--;
117  }
118  string new_name = real_name.substr(0, stopat + 1);
119 
120  string basename;
121  string::size_type slash = new_name.rfind("/");
122  if (slash != string::npos) {
123  basename = new_name.substr(slash + 1, new_name.length() - slash);
124  }
125  else {
126  basename = new_name;
127  }
128  // BESCatalogUtils::include method already calls exclude, so just
129  // need to call include
130  if (!_utils->include(basename)) {
131  string s = "Attempting to create a container with real name " + real_name + " which is on the exclude list";
132  throw BESForbiddenError(s, __FILE__, __LINE__);
133  }
134 
135  // If the type is specified, then just pass that on. If not, then match
136  // it against the types in the type list.
137  string new_type = type;
138  if (new_type == "") {
139  BESCatalogUtils::match_citer i = _utils->match_list_begin();
140  BESCatalogUtils::match_citer ie = _utils->match_list_end();
141  bool done = false;
142  for (; i != ie && !done; i++) {
143  BESCatalogUtils::type_reg match = (*i);
144  BESRegex reg_expr(match.reg.c_str());
145  if (reg_expr.match(real_name.c_str(), real_name.length()) == static_cast<int>(real_name.length())) {
146  new_type = match.type;
147  done = true;
148  }
149 
150  }
151  }
152 
153  BESContainerStorageVolatile::add_container(sym_name, real_name, new_type);
154 }
155 
165 bool BESContainerStorageCatalog::isData(const string &inQuestion, list<string> &provides)
166 {
167  string node_type = "";
168  BESCatalogUtils::match_citer i = _utils->match_list_begin();
169  BESCatalogUtils::match_citer ie = _utils->match_list_end();
170  bool done = false;
171  for (; i != ie && !done; i++) {
172  BESCatalogUtils::type_reg match = (*i);
173  BESRegex reg_expr(match.reg.c_str());
174  if (reg_expr.match(inQuestion.c_str(), inQuestion.length()) == static_cast<int>(inQuestion.length())) {
175  node_type = match.type;
176  done = true;
177  }
178  }
179 
180  BESServiceRegistry::TheRegistry()->services_handled(node_type, provides);
181 
182  return done;
183 }
184 
192 void BESContainerStorageCatalog::dump(ostream &strm) const
193 {
194  strm << BESIndent::LMarg << "BESContainerStorageCatalog::dump - (" << (void *) this << ")" << endl;
195  BESIndent::Indent();
196  strm << BESIndent::LMarg << "name: " << get_name() << endl;
197  strm << BESIndent::LMarg << "utils: " << get_name() << endl;
198  BESIndent::Indent();
199  _utils->dump(strm);
200  BESIndent::UnIndent();
201  BESIndent::UnIndent();
202 }
203 
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...
virtual void add_container(BESContainer *c)
add the passed container to the list of containers in volatile storage
virtual 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
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
virtual void dump(ostream &strm) const
dumps information about this object
error thrown if the BES is not allowed to access the resource requested
virtual const string & get_name() const
retrieve the name of this persistent store
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question