44#include <BESCatalogUtils.h>
45#include <BESCatalogEntry.h>
47#include <CatalogNode.h>
48#include <CatalogItem.h>
51#include <BESContainerStorageList.h>
52#include <BESFileContainerStorage.h>
55#include <BESInternalError.h>
56#include <BESForbiddenError.h>
57#include <BESNotFoundError.h>
58#include <BESSyntaxUserError.h>
60#include <TheBESKeys.h>
63#include "HttpdCatalogNames.h"
64#include "HttpdCatalog.h"
65#include "HttpdDirScraper.h"
70#define prolog std::string("HttpdCatalog::").append(__func__).append("() - ")
72namespace httpd_catalog {
85 BESCatalog(catalog_name) {
87 vector<string> httpd_catalogs;
92 string(
"The httpd_catalog module must define at least one catalog name using the key; '")
93 + HTTPD_CATALOG_COLLECTIONS +
"'", __FILE__, __LINE__);
97 for (it = httpd_catalogs.begin(); it != httpd_catalogs.end(); it++) {
98 string catalog_entry = *it;
99 int index = catalog_entry.find(
":");
101 string name = catalog_entry.substr(0, index);
102 string url = catalog_entry.substr(index + 1);
104 prolog <<
"name: '" << name <<
"' url: " << url << endl);
105 d_httpd_catalogs.insert(pair<string, string>(name, url));
108 string(
"The configuration entry for the ")
109 + HTTPD_CATALOG_COLLECTIONS
110 +
" was incorrectly formatted. entry: "
111 + catalog_entry, __FILE__, __LINE__);
116 string default_type_match_key =
"BES.Catalog.catalog.TypeMatch";
117 string catalog_type_match_key =
"BES.Catalog."+catalog_name+
".TypeMatch";
118 string type_match_key = catalog_type_match_key;
119 vector<string> type_match_v;
122 type_match_key = default_type_match_key;
125 throw BESInternalError(
"ERROR: Failed to located either the '"+catalog_type_match_key+
126 "' or the '"+default_type_match_key+
"' BES keys." , __FILE__, __LINE__);
130 for(it=type_match_v.begin(); it!=type_match_v.end(); it++) {
131 string typeMatch_entry = *it;
132 int index = typeMatch_entry.find(
":");
134 string name = typeMatch_entry.substr(0,index);
135 string regex = typeMatch_entry.substr(index+1);
136 BESDEBUG(MODULE, prolog <<
"name: '" << name <<
"' regex: " << regex << endl);
137 d_typematch.insert( pair<string,string>(name,regex));
140 throw BESInternalError(
string(
"The configuration entry for the ") + type_match_key +
141 " was incorrectly formatted. entry: "+typeMatch_entry, __FILE__,__LINE__);
163 while(path.size()>0 && path[0]==
'/')
164 path = path.substr(1);
166 if(path.empty() || path==
"/"){
168 node->set_lmt(time_now);
169 node->set_catalog_name(HTTPD_CATALOG_NAME);
172 while(it!=d_httpd_catalogs.end()){
175 collection->
set_type(CatalogItem::node);
176 node->add_node(collection);
184 node = hds.get_node(remote_target_url,path);
186 node->set_catalog_name(HTTPD_CATALOG_NAME);
204 string path = (p.find(
'/') == 0) ? p.substr(1): p;
205 string::size_type i = path.find(
'/');
206 string collection = path.substr(0, i);
209 if (it == d_httpd_catalogs.end())
210 throw BESNotFoundError(
"The httpd_catalog does not contain a collection named '" + collection +
"'", __FILE__, __LINE__);
213 string remote_relative_path = (i == string::npos) ?
"": path.substr(i);
215 if(remote_relative_path ==
"/" || remote_relative_path.empty())
222 BESDEBUG(MODULE, prolog <<
"path_elements.size(): " << path_elements.size() <<
" path: '" << path <<
"'"<< endl);
224 string collection = path_elements[0];
225 BESDEBUG(MODULE, prolog <<
"Checking for collection: " << collection <<
" d_httpd_catalogs.size(): "
226 << d_httpd_catalogs.size() << endl);
229 if(it == d_httpd_catalogs.end()) {
230 throw BESNotFoundError(
"The httpd_catalog does not contain a collection named '"+collection+
"'",__FILE__,__LINE__);
232 BESDEBUG(MODULE, prolog <<
"The httpd_catalog collection " << collection <<
" is valid." << endl);
234 string url = it->second;
236 string remote_relative_path = path.substr(collection.size()+1);
237 BESDEBUG(MODULE, prolog <<
"remote_relative_path: " << remote_relative_path << endl);
240 if(remote_relative_path ==
"/" || remote_relative_path.empty())
245 BESDEBUG(MODULE, prolog <<
"remote_target_url: " << access_url << endl);
261 strm << BESIndent::LMarg << prolog <<
"(" << (
void *)
this <<
")" << endl;
264 strm << BESIndent::LMarg <<
"catalog utilities: " << endl;
267 BESIndent::UnIndent();
268 BESIndent::UnIndent();
virtual void dump(std::ostream &strm) const
dump the contents of this object to the specified ostream
virtual BESCatalogUtils * get_catalog_utils() const
Get a pointer to the utilities, customized for this catalog.
exception thrown if internal error encountered
error thrown if the resource requested cannot be found
static std::vector< std::string > split(const std::string &s, char delim='/', bool skip_empty=true)
Splits the string s into the return vector of tokens using the delimiter delim and skipping empty val...
static std::string pathConcat(const std::string &firstPart, const std::string &secondPart, char separator='/')
Concatenate path fragments making sure that they are separated by a single '/' character.
static std::string get_time(bool use_local_time=false)
static TheBESKeys * TheKeys()
Access to the singleton.
void get_values(const std::string &s, std::vector< std::string > &vals, bool &found)
Retrieve the values of a given key, if set.
void set_type(item_type t)
Set the type for this item.
void set_name(const std::string &n)
Set the name of the item.
void set_lmt(std::string lmt)
Set the LMT for this node.
virtual bes::CatalogNode * get_node(const std::string &path) const
Produces the bes::CatalogNode for the string ppath.
HttpdCatalog(const std::string &catalog_name=HTTPD_CATALOG_NAME)
A catalog based on scraping the directory pages produced by httpd .
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual std::string path_to_access_url(const std::string &path) const
Takes a path which begins with the name of an HttpdCatalog collection and returns the associated acce...
This class builds a BES CatalogNode response from an httpd-generated directory page.