bes Updated for version 3.20.10
BESUtil.h
1// BESUtil.h
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#ifndef E_BESUtil_h
34#define E_BESUtil_h 1
35
36#include <string>
37#include <list>
38#include <iostream>
39#include <vector>
40#include <BESCatalog.h>
41#include <atomic>
42
43class BESUtil {
44private:
45 static std::string rfc822_date(const time_t t);
46
47 static std::string entity(char c);
48
49public:
60 static void set_mime_text(std::ostream &strm);
61 static void set_mime_html(std::ostream &strm);
62
64 static std::string www2id(const std::string &in, const std::string &escape = "%", const std::string &except = "");
65 static std::string unhexstring(const std::string& s);
66
68 static std::string lowercase(const std::string &s);
69
71 static std::string unescape(const std::string &s);
72
74 static void check_path(const std::string &path, const std::string &root, bool follow_sym_links);
75
77 static char * fastpidconverter(char *buf, int base);
78 static char * fastpidconverter(long val, char *buf, int base);
79
81 static void removeLeadingAndTrailingBlanks(std::string &key);
82
84 static std::string id2xml(std::string in, const std::string &not_allowed = "><&'\"");
85
87 static std::string xml2id(std::string in);
88
90 static void explode(char delim, const std::string &str, std::list<std::string> &values);
91
93 static std::string implode(const std::list<std::string> &values, char delim);
94
95 struct url {
96 std::string protocol;
97 std::string domain;
98 std::string uname;
99 std::string psswd;
100 std::string port;
101 std::string path;
102 };
103
104 static void url_explode(const std::string &url_str, BESUtil::url &url_parts);
105 static std::string url_create(BESUtil::url &url_parts);
106 // static string assemblePath(const string &firstPart, const string &secondPart, bool leadingSlash = false);
107 static std::string assemblePath(const std::string &firstPart, const std::string &secondPart, bool leadingSlash = false, bool trailingSlash = false);
108 static std::string pathConcat(const std::string &firstPart, const std::string &secondPart, char separator='/');
109
110 static bool endsWith(std::string const &fullString, std::string const &ending);
111 static void conditional_timeout_cancel();
112
114 static unsigned int replace_all(std::string &s, std::string find_this, std::string replace_with_this);
115 static std::string normalize_path(const std::string &path, bool leading_separator, bool trailing_separator, std::string separator = "/");
116 static void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = "/");
117 static std::string get_time(bool use_local_time = false);
118 static std::string get_time(time_t the_time, bool use_local_time = false);
119 static std::vector<std::string> split(const std::string &s, char delim='/', bool skip_empty=true);
120
121 static BESCatalog *separateCatalogFromPath(std::string &path);
122
123 static void file_to_stream(const std::string &file_name, std::ostream &o_strm);
124 static uint64_t file_to_stream_helper(const std::string &file_name, std::ostream &o_strm, uint64_t byteCount);
125 static uint64_t file_to_stream_task(const std::string &file_name, std::atomic<bool> &file_write_done,
126 std::ostream &o_strm);
127#if 0
128 // Added jhrg 11/9/21
129 static void split(const std::string &s, const std::string &delimiter, std::vector<uint64_t> &res);
130 static void split(const std::string &s, const std::string &delimiter, std::vector<std::string> &res);
131#endif
132};
133
134#endif // E_BESUtil_h
Catalogs provide a hierarchical organization for data.
Definition: BESCatalog.h:51
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...
Definition: BESUtil.cc:1159
static uint64_t file_to_stream_task(const std::string &file_name, std::atomic< bool > &file_write_done, std::ostream &o_strm)
Definition: BESUtil.cc:1399
static void explode(char delim, const std::string &str, std::list< std::string > &values)
Definition: BESUtil.cc:580
static void url_explode(const std::string &url_str, BESUtil::url &url_parts)
Given a url, break the url into its different parts.
Definition: BESUtil.cc:697
static bool endsWith(std::string const &fullString, std::string const &ending)
Definition: BESUtil.cc:961
static void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters="/")
Definition: BESUtil.cc:1086
static void set_mime_text(std::ostream &strm)
Generate an HTTP 1.0 response header for a text document.
Definition: BESUtil.cc:88
static std::string id2xml(std::string in, const std::string &not_allowed="><&'\"")
Definition: BESUtil.cc:524
static void conditional_timeout_cancel()
Checks if the timeout alarm should be canceled based on the value of the BES key BES....
Definition: BESUtil.cc:992
static void check_path(const std::string &path, const std::string &root, bool follow_sym_links)
Check if the specified path is valid.
Definition: BESUtil.cc:260
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 t...
Definition: BESUtil.cc:1015
static void set_mime_html(std::ostream &strm)
Generate an HTTP 1.0 response header for a html document.
Definition: BESUtil.cc:107
static std::string lowercase(const std::string &s)
Definition: BESUtil.cc:206
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.
Definition: BESUtil.cc:791
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.
Definition: BESUtil.cc:840
static std::string www2id(const std::string &in, const std::string &escape="%", const std::string &except="")
Definition: BESUtil.cc:191
static std::string implode(const std::list< std::string > &values, char delim)
Definition: BESUtil.cc:657
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.
Definition: BESUtil.cc:1226
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.
Definition: BESUtil.cc:1040
static std::string xml2id(std::string in)
Definition: BESUtil.cc:541
static std::string unescape(const std::string &s)
Definition: BESUtil.cc:216
static char * fastpidconverter(char *buf, int base)
Definition: BESUtil.cc:455
static void removeLeadingAndTrailingBlanks(std::string &key)
Definition: BESUtil.cc:485
static std::string get_time(bool use_local_time=false)
Definition: BESUtil.cc:1108