bes  Updated for version 3.20.5
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 
42 using std::string;
43 using std::list;
44 using std::ostream;
45 
46 class BESUtil {
47 private:
48  static string rfc822_date(const time_t t);
49 
50  static string entity(char c);
51 public:
62  static void set_mime_text(ostream &strm);
63  static void set_mime_html(ostream &strm);
64 
66  static string www2id(const string &in, const string &escape = "%", const string &except = "");
67  static string unhexstring(string s);
68 
70  static string lowercase(const string &s);
71 
73  static string unescape(const string &s);
74 
76  static void check_path(const string &path, const string &root, bool follow_sym_links);
77 
79  static char * fastpidconverter(char *buf, int base);
80  static char * fastpidconverter(long val, char *buf, int base);
81 
83  static void removeLeadingAndTrailingBlanks(string &key);
84 
86  static string id2xml(string in, const string &not_allowed = "><&'\"");
87 
89  static string xml2id(string in);
90 
92  static void explode(char delim, const string &str, list<string> &values);
93 
95  static string implode(const list<string> &values, char delim);
96 
97  struct url {
98  string protocol;
99  string domain;
100  string uname;
101  string psswd;
102  string port;
103  string path;
104  };
105 
106  static void url_explode(const string &url_str, BESUtil::url &url_parts);
107  static string url_create(BESUtil::url &url_parts);
108  // static string assemblePath(const string &firstPart, const string &secondPart, bool leadingSlash = false);
109  static string assemblePath(const string &firstPart, const string &secondPart, bool leadingSlash = false, bool trailingSlash = false);
110  static string pathConcat(const string &firstPart, const string &secondPart, char separator='/');
111 
112  static bool endsWith(std::string const &fullString, std::string const &ending);
113  static void conditional_timeout_cancel();
114 
115  static void replace_all(std::string &s, std::string find_this, std::string replace_with_this);
116  static std::string normalize_path(const std::string &path, bool leading_separator, bool trailing_separator, const string separator = "/");
117  static void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = "/");
118  static string get_time(bool use_local_time = false);
119  static string get_time(time_t the_time, bool use_local_time = false);
120  static std::vector<std::string> split(const string &s, char delim='/', bool skip_empty=true);
121 
122  static BESCatalog *separateCatalogFromPath(std::string &path);
123 };
124 
125 
126 
127 
128 #endif // E_BESUtil_h
129 
static void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters="/")
Definition: BESUtil.cc:1054
static string get_time(bool use_local_time=false)
Definition: BESUtil.cc:1076
static string id2xml(string in, const string &not_allowed="><&'\"")
Definition: BESUtil.cc:502
static string pathConcat(const string &firstPart, const string &secondPart, char separator='/')
Concatenate path fragments making sure that they are separated by a single '/' character.
Definition: BESUtil.cc:769
static string lowercase(const string &s)
Definition: BESUtil.cc:197
static void conditional_timeout_cancel()
Definition: BESUtil.cc:964
static std::string normalize_path(const std::string &path, bool leading_separator, bool trailing_separator, const string separator="/")
Removes duplicate separators and provides leading and trailing separators as directed.
Definition: BESUtil.cc:1008
static string www2id(const string &in, const string &escape="%", const string &except="")
Definition: BESUtil.cc:182
static void removeLeadingAndTrailingBlanks(string &key)
Definition: BESUtil.cc:463
static string implode(const list< string > &values, char delim)
Definition: BESUtil.cc:635
static std::vector< std::string > split(const 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:1122
static string xml2id(string in)
Definition: BESUtil.cc:519
static void set_mime_html(ostream &strm)
Generate an HTTP 1.0 response header for a html document.
Definition: BESUtil.cc:99
static void explode(char delim, const string &str, list< string > &values)
Definition: BESUtil.cc:558
static void set_mime_text(ostream &strm)
Generate an HTTP 1.0 response header for a text document.
Definition: BESUtil.cc:80
static void url_explode(const string &url_str, BESUtil::url &url_parts)
Given a url, break the url into its different parts.
Definition: BESUtil.cc:675
static bool endsWith(std::string const &fullString, std::string const &ending)
Definition: BESUtil.cc:939
Catalogs provide a hierarchical organization for data.
Definition: BESCatalog.h:51
static char * fastpidconverter(char *buf, int base)
Definition: BESUtil.cc:433
static string unescape(const string &s)
Definition: BESUtil.cc:207
static void check_path(const string &path, const string &root, bool follow_sym_links)
Check if the specified path is valid.
Definition: BESUtil.cc:251
static void 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:986
static string assemblePath(const string &firstPart, const string &secondPart, bool leadingSlash=false, bool trailingSlash=false)
Assemble path fragments making sure that they are separated by a single '/' character.
Definition: BESUtil.cc:818