/usr/include/davix/utils/davix_uri.hpp is in davix-dev 0.6.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | /*
* This File is part of Davix, The IO library for HTTP based protocols
* Copyright (C) CERN 2013
* Author: Adrien Devresse <adrien.devresse@cern.ch>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#pragma once
#ifndef DAVIX_DAVIXURI_HPP
#define DAVIX_DAVIXURI_HPP
#include <string>
#include <utils/davix_types.hpp>
#include <status/davixstatusrequest.hpp>
/**
@file davix_uri.hpp
@author Devresse Adrien
@brief URI utilities functions for davix
*/
#ifndef __DAVIX_INSIDE__
#error "Only davix.h or davix.hpp should be included."
#endif
namespace Davix {
struct UriPrivate;
/// @class Uri
/// @brief Uri parser
///
/// convenience class for uri parsing
///
/// @snippet example_code_snippets.cpp Uri example
class DAVIX_EXPORT Uri
{
public:
/// Construct an empty invalid Uri
Uri();
/// construct a new Davix Uri from a string URL
Uri(const std::string & uri_string);
/// Copy constructor
Uri(const Uri & uri);
///
/// \brief assignment operator
/// \param orig
/// \return
///
Uri & operator=(const Uri & orig);
virtual ~Uri();
/// append a query parameter to the uri
/// @param key : parameter key, not escaped
/// @param value : parameter value, not escaped
void addQueryParam(const std::string & key, const std::string & value);
/// append a fragment parameter to the uri
/// @param key : key
/// @param value : value
void addFragmentParam(const std::string & key, const std::string & value);
/// append a path segment to the uri
/// @param seg : the segment to add
void addPathSegment(const std::string & seg);
/// ensure that the path ends with a trailing slash
void ensureTrailingSlash();
/// remove the path's trailing slash, if it exists
void removeTrailingSlash();
/// check if the given query parameter exists
bool queryParamExists(const std::string ¶m) const;
/// check if the given fragment parameter exists
bool fragmentParamExists(const std::string ¶m) const;
/// get the value of a fragment parameter
const std::string getFragmentParam(const std::string ¶m) const;
/// get a string representation of the full uri
/// @return return the path or an empty string if error
const std::string & getString() const;
/// get the port number
/// @return return the prot number of 0 if unspecified
int getPort() const;
/// get the protocol scheme
/// @return return the protocol scheme or an empty string if error
const std::string & getProtocol() const;
/// get the host name
/// @return return the hostname or an empty string if error
const std::string & getHost() const;
/// get the path part of the Uri
/// @return return the path of the Uri or an empty string if error
const std::string & getPath()const;
// set the path part of the Uri
void setPath(const std::string & path);
// change the protocol of the Uri
void setProtocol(const std::string & protocol);
// change the protocol to either http or https, whichever is appropriate
void httpizeProtocol();
/// gextract user information from the URI
/// @return return the path of the Uri or an empty string if error
const std::string & getUserInfo() const;
/// get a concatenation of the path and the query argument of the URI
/// @return return a path + query arguments concatenation or an empty string if error
const std::string & getPathAndQuery() const;
/// get the fragment part of the uri
/// @return return the fragment part or an empty string if it does not exist
const std::string & getFragment() const;
/// get the query argument part of the uri
/// @return return the query path string or an empty string if not exist or if error
const std::string & getQuery() const;
// get the query argument part of the uri as a vector
// @return return a vector with all query parameters
ParamVec getQueryVec() const;
/// Status of the Uri
/// see StatusCode::Code
/// @return StatusCode::OK if success or StatusCode::UriParsingError if error
StatusCode::Code getStatus() const;
///
/// \brief test if two URI are equals
/// \param u1
/// \return true if equal, else false
///
bool equal(const Uri & u1) const;
///
/// \brief compare oepration
/// \param u2
/// \return true if u2 == current uri
///
bool operator==(const Uri & u2) const;
///
/// \brief Join two paths
/// \param left URL or filesystem path
// \param right Directory chunk, unescaped
/// \return The join of left and right, correctly escaped if left is a URL
// and not a filesystem path
///
static std::string join(const std::string &left, const std::string &right);
///
/// \brief Escape string
/// \param str URL to escape
/// \return encoded string
///
static std::string escapeString(const std::string & str);
///
/// \brief Unescape urI
/// \param str URL to escape
/// \return unencoded string
///
static std::string unescapeString(const std::string & str);
///
/// \brief Escape query parameter
/// \param str to escape
/// \return encoded string
static std::string queryParamEscape(const std::string & str);
///
/// \brief create a new Uri from URI and a relative associated path
/// \param uri original URI
/// \param relPath relative path
/// \return new URI from this path
///
static Uri fromRelativePath(const Uri & uri, const std::string & relPath);
private:
UriPrivate* d_ptr;
void _init();
};
///
/// check the validity of a Davix::Uri
/// @param uri : davix uri
/// @param err : Davix Error report object
/// @return true if the uri is valid, or false and setup err with a string expression
bool DAVIX_EXPORT uriCheckError(const Uri & uri, DavixError ** err);
/// return associated std port for this request
/// return default http port or default SSL port if not precised
unsigned int DAVIX_EXPORT httpUriGetPort(const Uri & uri);
std::ostream& operator<< (std::ostream& stream, const Davix::Uri & _u);
} // namespace Davix
#endif // DAVIX_DAVIXURI_HPP
|