29 #include <sys/types.h>
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("() - ")
72 namespace httpd_catalog {
84 HttpdCatalog::HttpdCatalog(
const string &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__);
96 vector<string>::iterator it;
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.length()>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);
170 map<string, string>::const_iterator it = d_httpd_catalogs.begin();
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);
185 node->set_lmt(time_now);
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);
208 map<string,string>::const_iterator it = d_httpd_catalogs.find(collection);
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);
228 map<string,string>::const_iterator it = d_httpd_catalogs.find(collection);
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.length()+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();