bes  Updated for version 3.20.6
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 class BESUtil {
43 private:
44  static std::string rfc822_date(const time_t t);
45 
46  static std::string entity(char c);
47 public:
58  static void set_mime_text(std::ostream &strm);
59  static void set_mime_html(std::ostream &strm);
60 
62  static std::string www2id(const std::string &in, const std::string &escape = "%", const std::string &except = "");
63  static std::string unhexstring(std::string s);
64 
66  static std::string lowercase(const std::string &s);
67 
69  static std::string unescape(const std::string &s);
70 
72  static void check_path(const std::string &path, const std::string &root, bool follow_sym_links);
73 
75  static char * fastpidconverter(char *buf, int base);
76  static char * fastpidconverter(long val, char *buf, int base);
77 
79  static void removeLeadingAndTrailingBlanks(std::string &key);
80 
82  static std::string id2xml(std::string in, const std::string &not_allowed = "><&'\"");
83 
85  static std::string xml2id(std::string in);
86 
88  static void explode(char delim, const std::string &str, std::list<std::string> &values);
89 
91  static std::string implode(const std::list<std::string> &values, char delim);
92 
93  struct url {
94  std::string protocol;
95  std::string domain;
96  std::string uname;
97  std::string psswd;
98  std::string port;
99  std::string path;
100  };
101 
102  static void url_explode(const std::string &url_str, BESUtil::url &url_parts);
103  static std::string url_create(BESUtil::url &url_parts);
104  // static string assemblePath(const string &firstPart, const string &secondPart, bool leadingSlash = false);
105  static std::string assemblePath(const std::string &firstPart, const std::string &secondPart, bool leadingSlash = false, bool trailingSlash = false);
106  static std::string pathConcat(const std::string &firstPart, const std::string &secondPart, char separator='/');
107 
108  static bool endsWith(std::string const &fullString, std::string const &ending);
109  static void conditional_timeout_cancel();
110 
111  static void replace_all(std::string &s, std::string find_this, std::string replace_with_this);
112  static std::string normalize_path(const std::string &path, bool leading_separator, bool trailing_separator, const std::string separator = "/");
113  static void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = "/");
114  static std::string get_time(bool use_local_time = false);
115  static std::string get_time(time_t the_time, bool use_local_time = false);
116  static std::vector<std::string> split(const std::string &s, char delim='/', bool skip_empty=true);
117 
118  static BESCatalog *separateCatalogFromPath(std::string &path);
119 };
120 
121 #endif // E_BESUtil_h
BESUtil::replace_all
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:989
BESUtil::tokenize
static void tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters="/")
Definition: BESUtil.cc:1057
BESUtil
Definition: BESUtil.h:42
BESUtil::set_mime_html
static void set_mime_html(std::ostream &strm)
Generate an HTTP 1.0 response header for a html document.
Definition: BESUtil.cc:102
BESUtil::normalize_path
static std::string normalize_path(const std::string &path, bool leading_separator, bool trailing_separator, const std::string separator="/")
Removes duplicate separators and provides leading and trailing separators as directed.
Definition: BESUtil.cc:1011
BESUtil::check_path
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:254
BESUtil::conditional_timeout_cancel
static void conditional_timeout_cancel()
Definition: BESUtil.cc:967
BESUtil::www2id
static std::string www2id(const std::string &in, const std::string &escape="%", const std::string &except="")
Definition: BESUtil.cc:185
BESUtil::get_time
static std::string get_time(bool use_local_time=false)
Definition: BESUtil.cc:1079
BESUtil::assemblePath
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:821
BESUtil::set_mime_text
static void set_mime_text(std::ostream &strm)
Generate an HTTP 1.0 response header for a text document.
Definition: BESUtil.cc:83
BESUtil::fastpidconverter
static char * fastpidconverter(char *buf, int base)
Definition: BESUtil.cc:436
BESUtil::url_explode
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:678
BESUtil::endsWith
static bool endsWith(std::string const &fullString, std::string const &ending)
Definition: BESUtil.cc:942
BESUtil::url
Definition: BESUtil.h:93
BESUtil::xml2id
static std::string xml2id(std::string in)
Definition: BESUtil.cc:522
BESUtil::id2xml
static std::string id2xml(std::string in, const std::string &not_allowed="><&'\"")
Definition: BESUtil.cc:505
BESUtil::explode
static void explode(char delim, const std::string &str, std::list< std::string > &values)
Definition: BESUtil.cc:561
BESUtil::split
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:1125
BESUtil::lowercase
static std::string lowercase(const std::string &s)
Definition: BESUtil.cc:200
BESUtil::implode
static std::string implode(const std::list< std::string > &values, char delim)
Definition: BESUtil.cc:638
BESUtil::unescape
static std::string unescape(const std::string &s)
Definition: BESUtil.cc:210
BESCatalog
Catalogs provide a hierarchical organization for data.
Definition: BESCatalog.h:51
BESUtil::pathConcat
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:772
BESUtil::removeLeadingAndTrailingBlanks
static void removeLeadingAndTrailingBlanks(std::string &key)
Definition: BESUtil.cc:466