31 #include <sys/types.h>
48 #include <Constructor.h>
51 using std::istringstream;
70 const string &w10nResourceId,
71 const string &catalogRoot,
72 const bool follow_sym_links,
85 int (*ye_old_stat_function)(
const char *pathname,
struct stat *buf);
88 ye_old_stat_function = &stat;
91 BESDEBUG(
W10N_DEBUG_KEY,
"eval_resource_path() - Using 'lstat' function (follow_sym_links = false)" << endl);
92 ye_old_stat_function = &lstat;
98 if (w10nResourceId ==
""){
108 string::size_type dotdot = w10nResourceId.find(
"..");
109 if (dotdot != string::npos) {
110 BESDEBUG(
W10N_DEBUG_KEY,
"eval_resource_path() - ERROR: w10n resourceID '" << w10nResourceId <<
"' contains the substring '..' This is Forbidden." << endl);
111 string s = (string)
"Invalid node name '" + w10nResourceId +
"' ACCESS IS FORBIDDEN";
121 string rem = w10nResourceId;
126 rem = rem.substr(1, rem.length() - 1);
129 if (rem[rem.length() - 1] ==
'/')
130 rem = rem.substr(0, rem.length() - 1);
133 string fullpath = catalogRoot;
135 if (fullpath[fullpath.length() - 1] ==
'/') {
136 fullpath = fullpath.substr(0, fullpath.length() - 1);
149 size_t slash = rem.find(
'/');
150 if (slash == string::npos) {
152 fullpath = fullpath +
"/" + rem;
153 checking = validPath +
"/" + rem;
157 fullpath = fullpath +
"/" + rem.substr(0, slash);
158 checking = validPath +
"/" + rem.substr(0, slash);
159 rem = rem.substr(slash + 1, rem.length() - slash);
167 int statret = ye_old_stat_function(fullpath.c_str(), &sb);
174 char *s_err = strerror(errsv);
175 string error =
"Unable to access node " + checking +
": ";
177 error = error + s_err;
179 error = error +
"unknown access error";
185 if (errsv == ENOENT || errsv == ENOTDIR) {
193 validPath = checking;
196 if (S_ISREG(sb.st_mode)) {
201 else if (S_ISDIR(sb.st_mode)) {
206 else if (S_ISLNK(sb.st_mode)) {
208 string error =
"Service not configured to traverse symbolic links as embodied by the node '"
209 + checking +
"' ACCESS IS FORBIDDEN";
223 std::stringstream ss;
224 for (
size_t i = 0; i < input.length(); ++i) {
225 if (
unsigned(input[i]) <
'\x20' || input[i] ==
'\\' || input[i] ==
'"') {
226 ss <<
"\\u" << std::setfill(
'0') << std::setw(4) << std::hex << unsigned(input[i]);
248 std::ostringstream ss;
251 for (std::string::const_iterator iter = input.begin(); iter != input.end(); iter++) {
253 case '\\': ss <<
"\\\\";
break;
254 case '"': ss <<
"\\\"";
break;
255 case '/': ss <<
"\\/";
break;
256 case '\b': ss <<
"\\b";
break;
257 case '\f': ss <<
"\\f";
break;
258 case '\n': ss <<
"\\n";
break;
259 case '\r': ss <<
"\\r";
break;
260 case '\t': ss <<
"\\t";
break;
261 default: ss << *iter;
break;
281 std::string backslash_escape(std::string source,
char char_to_escape){
282 std::string escaped_result = source;
283 if(source.find(char_to_escape) != string::npos ){
285 for(
size_t i=0; i< source.length() ; i++){
286 if(source[i] == char_to_escape){
287 escaped_result.insert( i + found++,
"\\");
291 return escaped_result;
299 libdap::Array::Dim_iter dIt;
304 unsigned int dimSize = 1;
308 BESDEBUG(
W10N_DEBUG_KEY,
"w10n::computeConstrainedShape() - Array has " << a->dimensions(
true) <<
" dimensions."<< endl);
312 for(dIt = a->dim_begin() ; dIt!=a->dim_end() ;dIt++){
313 BESDEBUG(
W10N_DEBUG_KEY,
"w10n::computeConstrainedShape() - Processing dimension '" << a->dimension_name(dIt)<<
"'. (dim# "<< dimNum <<
")"<< endl);
314 start = a->dimension_start(dIt,
true);
315 stride = a->dimension_stride(dIt,
true);
316 stop = a->dimension_stop(dIt,
true);
317 BESDEBUG(
W10N_DEBUG_KEY,
"w10n::computeConstrainedShape() - start: " << start <<
" stride: " << stride <<
" stop: "<<stop<< endl);
319 dimSize = 1 + ( (stop - start) / stride);
322 (*shape)[dimNum++] = dimSize;
323 totalSize *= dimSize;
338 for (libdap::DDS::Vars_iter i = dds->var_begin(); i != dds->var_end(); i++) {
339 libdap::BaseType *bt = (*i);
341 if(bt->is_constructor_type()){
344 else if (bt->is_vector_type()){
345 if(bt->var()->is_constructor_type()){
346 string msg =
"Arrays of ";
347 msg += bt->type_name() +
" are not supported by the w10n service.";
355 if(markedCount > 1) {
356 string msg =
"More than one variable in the dataset is projected and that's a no-no for w10n data responses.";
368 for (libdap::Constructor::Vars_iter i = constructor->var_begin(); i != constructor->var_end(); i++) {
369 libdap::BaseType *bt = (*i);
372 if(bt->is_constructor_type()){
375 else if (bt->is_vector_type()){
376 if(bt->var()->is_constructor_type()){
377 string msg =
"Arrays of ";
378 msg += bt->type_name() +
" are not supported by the w10n service.";
389 if(markedCount > 1) {
391 if(markedCount == constructor->element_count())
392 msg =
"The w10n protocol does not support data responses from nodes. The variable " + constructor->name()+
" is a node variable.";
394 msg =
"More than one child variable of the node variable "+ constructor->name() +
" is projected and that's a no-no for w10n data responses.";
407 bool allMarked =
true;
409 libdap::DDS::Vars_iter vi = dds->var_begin();
410 libdap::DDS::Vars_iter ve = dds->var_end();
411 for (; vi != ve; vi++) {
412 libdap::BaseType *v = *vi;
414 if(v->is_constructor_type()){
417 else if(v->is_vector_type() && v->var()->is_constructor_type()){
421 allMarked = allMarked &&
true;
425 allMarked = allMarked &&
false;
434 bool allMarked =
true;
436 libdap::Constructor::Vars_iter vi = ctor->var_begin();
437 libdap::Constructor::Vars_iter ve = ctor->var_end();
438 for (; vi != ve; vi++) {
439 libdap::BaseType *v = *vi;
441 if(v->is_constructor_type()){
444 else if(v->is_vector_type() && v->var()->is_constructor_type()){
448 allMarked = allMarked &&
true;
452 allMarked = allMarked &&
false;
void checkConstrainedDDSForW10nDataCompatibility(libdap::DDS *dds)
std::string escape_for_json(const std::string &input)
void checkConstructorForW10nDataCompatibility(libdap::Constructor *constructor)
error thrown if there is a user syntax error in the request or any other user error ...
bool allVariablesMarkedToSend(libdap::DDS *dds)
void eval_resource_path(const string &w10nResourceId, const string &catalogRoot, const bool follow_sym_links, string &validPath, bool &isFile, bool &isDir, string &remainder)
Check if the specified path is valid.
error thrown if the BES is not allowed to access the resource requested
long computeConstrainedShape(libdap::Array *a, std::vector< unsigned int > *shape)
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream