bes Updated for version 3.20.10
BESUtil Class Reference
Collaboration diagram for BESUtil:
Collaboration graph

Classes

struct  url
 

Static Public Member Functions

MIME utility functions

These functions are used to create the MIME headers for a message from a server to a client.

NB: These functions actually write both the response status line and the header.

See also
libdap::escaping.cc
libdap::mime_util.cc
static void set_mime_text (std::ostream &strm)
 Generate an HTTP 1.0 response header for a text document. More...
 
static void set_mime_html (std::ostream &strm)
 Generate an HTTP 1.0 response header for a html document. More...
 
static std::string www2id (const std::string &in, const std::string &escape="%", const std::string &except="")
 
static std::string unhexstring (const std::string &s)
 
static std::string lowercase (const std::string &s)
 
static std::string unescape (const std::string &s)
 
static void check_path (const std::string &path, const std::string &root, bool follow_sym_links)
 Check if the specified path is valid. More...
 
static char * fastpidconverter (char *buf, int base)
 
static char * fastpidconverter (long val, char *buf, int base)
 
static void removeLeadingAndTrailingBlanks (std::string &key)
 
static std::string id2xml (std::string in, const std::string &not_allowed="><&'\"")
 
static std::string xml2id (std::string in)
 
static void explode (char delim, const std::string &str, std::list< std::string > &values)
 
static std::string implode (const std::list< std::string > &values, char delim)
 
static void url_explode (const std::string &url_str, BESUtil::url &url_parts)
 Given a url, break the url into its different parts. More...
 
static std::string url_create (BESUtil::url &url_parts)
 
static std::string assemblePath (const std::string &firstPart, const std::string &secondPart, bool leadingSlash=false, bool trailingSlash=false)
 Assemble path fragments making sure that they are separated by a single '/' character. More...
 
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. More...
 
static bool endsWith (std::string const &fullString, std::string const &ending)
 
static void conditional_timeout_cancel ()
 Checks if the timeout alarm should be canceled based on the value of the BES key BES.CancelTimeoutOnSend. More...
 
static unsigned int replace_all (std::string &s, std::string find_this, std::string replace_with_this)
 Operates on the string 's' to replaces every occurrence of the value of the string 'find_this' with the value of the string 'replace_with_this'. More...
 
static std::string normalize_path (const std::string &path, bool leading_separator, bool trailing_separator, std::string separator="/")
 Removes duplicate separators and provides leading and trailing separators as directed. More...
 
static void tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters="/")
 
static std::string get_time (bool use_local_time=false)
 
static std::string get_time (time_t the_time, bool use_local_time=false)
 Returns the time represented by 'the_time' as an ISO8601 string. More...
 
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 values as instructed by skip_empty. More...
 
static BESCatalogseparateCatalogFromPath (std::string &path)
 
static void file_to_stream (const std::string &file_name, std::ostream &o_strm)
 Copies the contents of the file identified by file_name to the stream o_strm. More...
 
static uint64_t file_to_stream_helper (const std::string &file_name, std::ostream &o_strm, uint64_t byteCount)
 
static uint64_t file_to_stream_task (const std::string &file_name, std::atomic< bool > &file_write_done, std::ostream &o_strm)
 

Detailed Description

Definition at line 43 of file BESUtil.h.

Member Function Documentation

◆ assemblePath()

string BESUtil::assemblePath ( const std::string &  firstPart,
const std::string &  secondPart,
bool  leadingSlash = false,
bool  trailingSlash = false 
)
static

Assemble path fragments making sure that they are separated by a single '/' character.

If the parameter ensureLeadingSlash is true then the returned string will begin with a single '/' character followed by the string firstPart, a single '/' character, and the string secondPart.

Note
I replaced the code here with a simpler version that assumes the two string arguments do not contain multiple consecutive slashes - I don't think the original version will work in cases where the string is only slashes because it will dereference the return value of begin()
Parameters
firstPartThe first string to concatenate.
secondPartThe second string to concatenate.
leadingSlashIf this bool value is true then the returned string will have a leading slash. If the value of leadingSlash is false then the first character of the returned string will be the first character of the passed firstPart.
trailingSlashIf this bool is true then the returned string will end it a slash. If trailingSlash is false, then the returned string will not end with a slash. If trailing slash(es) need to be removed to accomplish this, then they will be removed.

Definition at line 840 of file BESUtil.cc.

◆ check_path()

void BESUtil::check_path ( const std::string &  path,
const std::string &  root,
bool  follow_sym_links 
)
static

Check if the specified path is valid.

Check if the specified path is valid

Checks to see if the specified path is a valid path or not. The root directory specified is assumed to be valid, so we don't check that part of the path. The path parameter is relative to the root directory.

If follow_sym_links is false, then if any part of the specified path is a symbolic link, this function will return false, set the passed has_sym_link parameter. No error message is specified.

If there is a problem accessing the specified path then the error string will be filled with whatever system error message is provided.

param path path to check param root root directory path, assumed to be valid param follow_sym_links specifies whether allowed to follow symbolic links throws BESForbiddenError if the user is not allowed to traverse the path throws BESNotFoundError if there is a problem accessing the path or the path does not exist.

Definition at line 260 of file BESUtil.cc.

◆ conditional_timeout_cancel()

void BESUtil::conditional_timeout_cancel ( )
static

Checks if the timeout alarm should be canceled based on the value of the BES key BES.CancelTimeoutOnSend.

If the value of the BES Key BES.CancelTimeoutOnSend is false || no, then do not cancel the timeout alarm. The intent of this is to stop the timeout counter once the BES starts sending data back since, the network link used by a remote client may be low-bandwidth and data providers might want to ensure those users get their data (and don't submit second, third, ..., requests when/if the first one fails). The timeout is initiated in the BES framework when it first processes the request.

Default: If the BES key BES.CancelTimeoutOnSend is not set, or if it is set to true || yes then the timeout alrm will be canceled.

Note
The BES timeout is set/controlled in bes/dispatch/BESInterface in the 'int BESInterface::execute_request(const string &from)' method.
See also
See the send_data(BESResponseObject *obj, BESDataHandlerInterface &dhi) methods of the children of BESTransmitter

Definition at line 992 of file BESUtil.cc.

◆ endsWith()

bool BESUtil::endsWith ( std::string const &  fullString,
std::string const &  ending 
)
static

Returns true if (the value of) 'fullString' ends with (the value of) 'ending', false otherwise.

Definition at line 961 of file BESUtil.cc.

◆ explode()

void BESUtil::explode ( char  delim,
const std::string &  str,
std::list< std::string > &  values 
)
static

explode a string into an array given a delimiter

Given a string of values separated by a delimiter, break out the values and store in the list.

Quoted values must be escaped.

If values contain the delimiter then the value must be wrapped in quotes.

Parameters
delimdelimiter separating the values
strthe original string
valueslist of the delimited values returned to caller
Exceptions
BESInternalErrorif missing ending quote or delimiter does not follow end quote

Definition at line 580 of file BESUtil.cc.

◆ fastpidconverter() [1/2]

char * BESUtil::fastpidconverter ( char *  buf,
int  base 
)
static

convert pid and place in provided buffer

Definition at line 455 of file BESUtil.cc.

◆ fastpidconverter() [2/2]

char * BESUtil::fastpidconverter ( long  val,
char *  buf,
int  base 
)
static

Definition at line 461 of file BESUtil.cc.

◆ file_to_stream()

void BESUtil::file_to_stream ( const std::string &  file_name,
std::ostream &  o_strm 
)
static

Copies the contents of the file identified by file_name to the stream o_strm.

Thanks to O'Reilly: https://www.oreilly.com/library/view/c-cookbook/0596007612/ch10s08.html

Parameters
file_name
o_strm

Definition at line 1226 of file BESUtil.cc.

◆ file_to_stream_helper()

uint64_t BESUtil::file_to_stream_helper ( const std::string &  file_name,
std::ostream &  o_strm,
uint64_t  byteCount 
)
static

Definition at line 1304 of file BESUtil.cc.

◆ file_to_stream_task()

uint64_t BESUtil::file_to_stream_task ( const std::string &  file_name,
std::atomic< bool > &  file_write_done,
std::ostream &  o_strm 
)
static

*brief child thread/task to stream a netCDF file as it is built

Parameters
file_name
o_strm

Definition at line 1399 of file BESUtil.cc.

◆ get_time() [1/2]

string BESUtil::get_time ( bool  use_local_time = false)
static

Returns the current time as an ISO8601 string.

Parameters
use_local_timeTrue to use the local time, false (default) to use GMT
Returns
The time, either local or GMT/UTC as an ISO8601 string

Definition at line 1108 of file BESUtil.cc.

◆ get_time() [2/2]

string BESUtil::get_time ( time_t  the_time,
bool  use_local_time = false 
)
static

Returns the time represented by 'the_time' as an ISO8601 string.

Parameters
the_timeA time_t value
use_local_timeTrue to use the local time, false (default) to use GMT
Returns
The time, either local or GMT/UTC as an ISO8601 string

Definition at line 1120 of file BESUtil.cc.

◆ id2xml()

string BESUtil::id2xml ( std::string  in,
const std::string &  not_allowed = "><&'\"" 
)
static

convert characters not allowed in xml to escaped characters

Replace characters that are not allowed in XML

Parameters
inThe string in which to replace characters.
not_allowedThe set of characters that are not allowed in XML. default: ><&'(single quote)"(double quote)
Returns
The modified identifier.

Definition at line 524 of file BESUtil.cc.

◆ implode()

string BESUtil::implode ( const std::list< std::string > &  values,
char  delim 
)
static

implode a list of values into a single string delimited by delim

Given a list of string values create a single string of values delimited by delim

If the delimiter exists in a value in the list then that value must be enclosed in quotes

Parameters
valueslist of string values to implode
delimthe delimiter to use in creating the resulting string
Returns
the delim delimited string of values

Definition at line 657 of file BESUtil.cc.

◆ lowercase()

string BESUtil::lowercase ( const std::string &  s)
static

Convert a string to all lower case

Definition at line 206 of file BESUtil.cc.

◆ normalize_path()

string BESUtil::normalize_path ( const std::string &  path,
bool  leading_separator,
bool  trailing_separator,
std::string  separator = "/" 
)
static

Removes duplicate separators and provides leading and trailing separators as directed.

Parameters
raw_pathThe string to normalize
leading_separatorif true then the result will begin with a single separator character. If false the result will not begin with a separator character.
trailing_separatorIf true the result will end with a single separator character. If false the result will not end with a separator character.
separatorA string, of length one, containing the separator character for the path. This parameter is optional and its value defaults to the slash '/' character.

Definition at line 1040 of file BESUtil.cc.

◆ pathConcat()

string BESUtil::pathConcat ( const std::string &  firstPart,
const std::string &  secondPart,
char  separator = '/' 
)
static

Concatenate path fragments making sure that they are separated by a single '/' character.

Returns a new string made from appending secondPart to firstPart while ensuring that a single separator appears between the two parts.

Parameters
firstPartThe first string to concatenate.
secondPartThe second string to concatenate.
separatorThe separator character to use between the two concatenated strings. Default: '/'

Definition at line 791 of file BESUtil.cc.

◆ removeLeadingAndTrailingBlanks()

void BESUtil::removeLeadingAndTrailingBlanks ( std::string &  key)
static

remove leading and trailing blanks from a string

Definition at line 485 of file BESUtil.cc.

◆ replace_all()

unsigned int BESUtil::replace_all ( std::string &  s,
std::string  find_this,
std::string  replace_with_this 
)
static

Operates on the string 's' to replaces every occurrence of the value of the string 'find_this' with the value of the string 'replace_with_this'.

Convert a string to all lower case

Parameters

Definition at line 1015 of file BESUtil.cc.

◆ separateCatalogFromPath()

BESCatalog * BESUtil::separateCatalogFromPath ( std::string &  path)
static

Definition at line 1176 of file BESUtil.cc.

◆ set_mime_html()

void BESUtil::set_mime_html ( std::ostream &  strm)
static

Generate an HTTP 1.0 response header for a html document.

Parameters
strmWrite the MIME header to this ostream.

Definition at line 107 of file BESUtil.cc.

◆ set_mime_text()

void BESUtil::set_mime_text ( std::ostream &  strm)
static

Generate an HTTP 1.0 response header for a text document.

Parameters
strmWrite the MIME header to this ostream.

Definition at line 88 of file BESUtil.cc.

◆ split()

vector< string > BESUtil::split ( const std::string &  s,
char  delim = '/',
bool  skip_empty = true 
)
static

Splits the string s into the return vector of tokens using the delimiter delim and skipping empty values as instructed by skip_empty.

Parameters
sThe string to tokenize.
delimThe character delimiter to utilize during tokenization. default: '/'
skip_emptyA boolean flag which controls if empty tokens are returned.
Returns
A vector of strings each of which is a token in the string read left to right.
See also
BESUtil::tokenize() is probably faster

Definition at line 1159 of file BESUtil.cc.

◆ tokenize()

void BESUtil::tokenize ( const std::string &  str,
std::vector< std::string > &  tokens,
const std::string &  delimiters = "/" 
)
static

A call out thanks to: http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html for the tokenizer.

Definition at line 1086 of file BESUtil.cc.

◆ unescape()

string BESUtil::unescape ( const std::string &  s)
static

Unescape characters with backslash before them

Definition at line 216 of file BESUtil.cc.

◆ unhexstring()

string BESUtil::unhexstring ( const std::string &  s)
static

Definition at line 178 of file BESUtil.cc.

◆ url_create()

string BESUtil::url_create ( BESUtil::url url_parts)
static

Definition at line 765 of file BESUtil.cc.

◆ url_explode()

void BESUtil::url_explode ( const std::string &  url_str,
BESUtil::url url_parts 
)
static

Given a url, break the url into its different parts.

The different parts are the protocol, the domain name, a username if specified, a password if specified, a port if specified, and a path if specified.

struct url { string protocol ; string domain ; string uname ; string psswd ; string port ; string path ; } ;

Parameters
urlstring representation of the URL

Definition at line 697 of file BESUtil.cc.

◆ www2id()

string BESUtil::www2id ( const std::string &  in,
const std::string &  escape = "%",
const std::string &  except = "" 
)
static

This functions are used to unescape hex characters from strings

Definition at line 191 of file BESUtil.cc.

◆ xml2id()

string BESUtil::xml2id ( std::string  in)
static

unescape xml escaped characters

Given a string that contains XML escape sequences (i.e., entities), translate those back into ASCII characters. Return the modified string.

Parameters
inThe string to modify.
Returns
The modified string.

Definition at line 541 of file BESUtil.cc.


The documentation for this class was generated from the following files: