[DEV] work on new URI interface
This commit is contained in:
parent
37d73e9662
commit
a38657a915
@ -1,62 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/fs/Type.hpp>
|
||||
#include <etk/String.hpp>
|
||||
|
||||
namespace etk {
|
||||
/**
|
||||
* @brief Uniform resource interface manage internal resource and nerwork resource (like URL)
|
||||
* Format is manage like : __SCHEME__://__USER__@__SERVER__:__PORT__/__PATH__?__PARAMETERS__
|
||||
*/
|
||||
class Uri {
|
||||
private:
|
||||
etk::String m_scheme; //!<
|
||||
etk::String m_user; //!<
|
||||
etk::String m_server; //!<
|
||||
uint16_t m_port; //!<
|
||||
etk::Path m_path; //!<
|
||||
etk::Vector<etk::Pair<etk::String,etk::String>> m_parameters; //!<
|
||||
public:
|
||||
ETK_CONSTRUCTOR_MOVE_DEFAULT(Uri);
|
||||
ETK_CONSTRUCTOR_COPY_DEFAULT(Uri);
|
||||
/**
|
||||
* @brief Default contructor.
|
||||
*/
|
||||
Uri();
|
||||
/**
|
||||
* @brief Contructor with basic URI.
|
||||
* @param[in] _value Element basic URI
|
||||
*/
|
||||
Uri(const etk::String& _value);
|
||||
/**
|
||||
* @brief Contructor with basic URI.
|
||||
* @param[in] _value Element basic URI
|
||||
*/
|
||||
Uri(const char * _value);
|
||||
|
||||
etk::String getScheme() const;
|
||||
void setScheme(const etk::String &_value);
|
||||
|
||||
etk::String getUser() const;
|
||||
void setUser(const etk::String &_value);
|
||||
|
||||
etk::String getServer() const;
|
||||
void setServer(const etk::String &_value);
|
||||
|
||||
uint16_t getPort() const;
|
||||
void setPort(const uint16_t &_value);
|
||||
|
||||
etk::Path getPath() const;
|
||||
void setPath(const etk::Path &_value);
|
||||
|
||||
etk::Parameters getParameters() const;
|
||||
void setParameters(const etk::Parameters &_value);
|
||||
};
|
||||
}
|
||||
|
41
etk/uri/Querry.cpp
Normal file
41
etk/uri/Querry.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/url/Query.hpp>
|
||||
|
||||
etk::uri::Query::Querry() {
|
||||
|
||||
}
|
||||
|
||||
etk::uri::Query::Querry(const etk::String& _value) {
|
||||
|
||||
}
|
||||
|
||||
void etk::uri::Query::setEncoded(const etk::String& _value) {
|
||||
|
||||
}
|
||||
|
||||
etk::String etk::uri::Query::getEncoded() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
void etk::uri::Query::set(const etk::String& _key, const etk::String& _value) {
|
||||
|
||||
}
|
||||
|
||||
bool etk::uri::Query::exist(const etk::String& _key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void etk::uri::Query::erase(const etk::String& _key) {
|
||||
|
||||
}
|
||||
|
||||
etk::String etk::uri::Query::get(const etk::String& _key) {
|
||||
return "";
|
||||
}
|
||||
|
70
etk/uri/Querry.hpp
Normal file
70
etk/uri/Querry.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/fs/Type.hpp>
|
||||
#include <etk/String.hpp>
|
||||
#include <etk/Map.hpp>
|
||||
|
||||
namespace etk {
|
||||
namespace uri {
|
||||
/**
|
||||
* @brief Querry Interface management.
|
||||
*/
|
||||
class Query {
|
||||
private:
|
||||
etk::Map<etk::String, etk::String> m_query; //!< Querry data
|
||||
public:
|
||||
ETK_CONSTRUCTOR_MOVE_DEFAULT(Query);
|
||||
ETK_CONSTRUCTOR_COPY_DEFAULT(Query);
|
||||
/**
|
||||
* @brief Default contructor.
|
||||
*/
|
||||
Querry();
|
||||
/**
|
||||
* @brief Set with a specific querry string
|
||||
* @param[in] _value querry data
|
||||
*/
|
||||
Querry(const etk::String& _value);
|
||||
/**
|
||||
* @brief Set the encoded query.
|
||||
* @param[in] _value encoded data.
|
||||
*/
|
||||
void setEncoded(const etk::String& _value);
|
||||
/**
|
||||
* @brief Get the encoded query.
|
||||
* @return encoded data.
|
||||
*/
|
||||
etk::String getEncoded() const;
|
||||
/**
|
||||
* @brief Set an element of the query.
|
||||
* @param[in] _key Key of the query.
|
||||
* @param[in] _value Associated data.
|
||||
*/
|
||||
void set(const etk::String& _key, const etk::String& _value);
|
||||
/**
|
||||
* @brief Check if the key exist.
|
||||
* @param[in] _key Key of the query.
|
||||
* @return true Key exist.
|
||||
* @return false Unknown key.
|
||||
*/
|
||||
bool exist(const etk::String& _key);
|
||||
/**
|
||||
* @brief erase a specific key.
|
||||
* @param[in] _key Key of the query.
|
||||
*/
|
||||
void erase(const etk::String& _key);
|
||||
/**
|
||||
* @brief Get value of a query element.
|
||||
* @param[in] _key Key of the query.
|
||||
* @return associated data.
|
||||
*/
|
||||
etk::String get(const etk::String& _key);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
151
etk/uri/Uri.cpp
Normal file
151
etk/uri/Uri.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/fs/Type.hpp>
|
||||
#include <etk/String.hpp>
|
||||
#include <etk/Map.hpp>
|
||||
|
||||
namespace etk {
|
||||
/**
|
||||
* @brief Uniform resource interface manage internal resource and nerwork resource (like URL)
|
||||
* Format is manage like : __SCHEME__://__USER__:__PASSWORD__@__SERVER__:__PORT__/__PATH__?__QUERY__#__FRAGMENT__
|
||||
*/
|
||||
class Uri {
|
||||
private:
|
||||
etk::String m_scheme; //!< Sheme of the uri.
|
||||
etk::String m_user; //!< user name
|
||||
etk::String m_password; //!< password (crypted/hashed)
|
||||
etk::String m_server; //!< server name
|
||||
uint16_t m_port; //!< Port of the server
|
||||
etk::Path m_path; //!< Path data
|
||||
etk::uri::Query m_query; //!< querry interface
|
||||
etk::String m_fragment; //!< fragment data
|
||||
public:
|
||||
ETK_CONSTRUCTOR_MOVE_DEFAULT(Uri);
|
||||
ETK_CONSTRUCTOR_COPY_DEFAULT(Uri);
|
||||
/**
|
||||
* @brief Default contructor.
|
||||
*/
|
||||
etk::Uri::Uri() {
|
||||
|
||||
}
|
||||
|
||||
etk::Uri::Uri(const etk::String& _value) {
|
||||
set(_value);
|
||||
}
|
||||
|
||||
etk::Uri::Uri(const char * _value) {
|
||||
set(_value);
|
||||
}
|
||||
|
||||
void etk::Uri::set(const etk::String& _value) {
|
||||
|
||||
}
|
||||
|
||||
void etk::Uri::set(const char * _value) {
|
||||
set(etk::String(_value));
|
||||
}
|
||||
|
||||
etk::String etk::Uri::get() {
|
||||
etk::String out;
|
||||
if (m_scheme != "") {
|
||||
out += m_scheme;
|
||||
out += "://";
|
||||
}
|
||||
if (m_server != "") {
|
||||
if (m_user != "") {
|
||||
out += m_user;
|
||||
if (m_password != "") {
|
||||
out += ":";
|
||||
out += m_password;
|
||||
}
|
||||
out += "@";
|
||||
}
|
||||
out += m_server;
|
||||
if (m_port != 0) {
|
||||
out += ":";
|
||||
out += etk::toString(m_port);
|
||||
}
|
||||
}
|
||||
if(m_path != "") {
|
||||
out += "/";
|
||||
out += m_path.getString();
|
||||
}
|
||||
if(m_query.size() != 0) {
|
||||
out += "?";
|
||||
out += m_query.getEncoded();
|
||||
}
|
||||
if(m_fragment != "") {
|
||||
out += "#";
|
||||
out += m_fragment;
|
||||
}
|
||||
}
|
||||
|
||||
const etk::String& etk::Uri::getScheme() const {
|
||||
return m_scheme;
|
||||
}
|
||||
|
||||
void etk::Uri::setScheme(const etk::String& _value) {
|
||||
m_scheme = _value;
|
||||
}
|
||||
|
||||
const etk::String& etk::Uri::getUser() const {
|
||||
return m_user;
|
||||
}
|
||||
|
||||
void etk::Uri::setUser(const etk::String& _value) {
|
||||
m_user = _value;
|
||||
}
|
||||
|
||||
const etk::String& etk::Uri::getPassword() const {
|
||||
return m_password;
|
||||
}
|
||||
|
||||
void etk::Uri::setPassword(const etk::String& _value) {
|
||||
m_password = _value;
|
||||
}
|
||||
|
||||
const etk::String& etk::Uri::getServer() const {
|
||||
return m_server;
|
||||
}
|
||||
|
||||
void etk::Uri::setServer(const etk::String& _value) {
|
||||
m_server = _value;
|
||||
}
|
||||
|
||||
uint16_t etk::Uri::getPort() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
void etk::Uri::setPort(uint16_t _value) {
|
||||
m_port = _value;
|
||||
}
|
||||
|
||||
const etk::Path& etk::Uri::getPath() const {
|
||||
return m_path;
|
||||
}
|
||||
|
||||
void etk::Uri::setPath(const etk::Path& _value) {
|
||||
m_path = _value;
|
||||
}
|
||||
|
||||
const etk::uri::Query& etk::Uri::getQuery() const {
|
||||
return m_query;
|
||||
}
|
||||
|
||||
void etk::Uri::setQuery(const etk::uri::Query& _value) {
|
||||
m_query = _value;
|
||||
}
|
||||
|
||||
const etk::String& etk::Uri::getFragment() const {
|
||||
return m_fragment;
|
||||
}
|
||||
|
||||
void etk::Uri::setFragment(const etk::String& _value) {
|
||||
m_fragment = _value;
|
||||
}
|
166
etk/uri/Uri.hpp
Normal file
166
etk/uri/Uri.hpp
Normal file
@ -0,0 +1,166 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/fs/Type.hpp>
|
||||
#include <etk/String.hpp>
|
||||
#include <etk/Map.hpp>
|
||||
|
||||
namespace etk {
|
||||
|
||||
class Query {
|
||||
private:
|
||||
etk::Map<etk::String, etk::String> m_query; //!< Querry data
|
||||
public:
|
||||
ETK_CONSTRUCTOR_MOVE_DEFAULT(Query);
|
||||
ETK_CONSTRUCTOR_COPY_DEFAULT(Query);
|
||||
/**
|
||||
* @brief Default contructor.
|
||||
*/
|
||||
Querry();
|
||||
/**
|
||||
* @brief Set with a specific querry string
|
||||
* @param[in] _value querry data
|
||||
*/
|
||||
Querry(const etk::String& _value);
|
||||
|
||||
void setEncoded(const etk::String& _value);
|
||||
etk::String getEncoded() const;
|
||||
|
||||
void set(const etk::String& _key, const etk::String& _value);
|
||||
bool exist(const etk::String& _key);
|
||||
etk::String get(const etk::String& _key);
|
||||
};
|
||||
/**
|
||||
* @brief Uniform resource interface manage internal resource and nerwork resource (like URL)
|
||||
* Format is manage like : __SCHEME__://__USER__:__PASSWORD__@__SERVER__:__PORT__/__PATH__?__QUERY__#__FRAGMENT__
|
||||
*/
|
||||
class Uri {
|
||||
private:
|
||||
etk::String m_scheme; //!< Sheme of the uri.
|
||||
etk::String m_user; //!< user name
|
||||
etk::String m_password; //!< password (crypted/hashed)
|
||||
etk::String m_server; //!< server name
|
||||
uint16_t m_port = 0; //!< Port of the server
|
||||
etk::Path m_path; //!< Path data
|
||||
etk::uri::Query m_query; //!< querry interface
|
||||
etk::String m_fragment; //!< fragment data
|
||||
public:
|
||||
ETK_CONSTRUCTOR_MOVE_DEFAULT(Uri);
|
||||
ETK_CONSTRUCTOR_COPY_DEFAULT(Uri);
|
||||
/**
|
||||
* @brief Default contructor.
|
||||
*/
|
||||
Uri();
|
||||
/**
|
||||
* @brief Contructor with basic URI.
|
||||
* @param[in] _value Element basic URI
|
||||
*/
|
||||
Uri(const etk::String& _value);
|
||||
/**
|
||||
* @brief Contructor with basic URI.
|
||||
* @param[in] _value Element basic URI
|
||||
*/
|
||||
Uri(const char * _value);
|
||||
/**
|
||||
* @brief Contructor with basic URI.
|
||||
* @param[in] _value Element basic URI
|
||||
*/
|
||||
void set(const etk::String& _value);
|
||||
/**
|
||||
* @brief Contructor with basic URI.
|
||||
* @param[in] _value Element basic URI
|
||||
*/
|
||||
void set(const char * _value);
|
||||
/**
|
||||
* @brief generate the URI string.
|
||||
* @return the uri correctly encoded
|
||||
*/
|
||||
etk::String get();
|
||||
/**
|
||||
* @brief Get the scheme of the URI.
|
||||
* @return Scheme value.
|
||||
*/
|
||||
const etk::String& getScheme() const;
|
||||
/**
|
||||
* @brief Get the scheme of the URI.
|
||||
* @param[in] _value New Scheme value.
|
||||
*/
|
||||
void setScheme(const etk::String& _value);
|
||||
/**
|
||||
* @brief Get the user Name (login).
|
||||
* @return User value.
|
||||
*/
|
||||
const etk::String& getUser() const;
|
||||
/**
|
||||
* @brief Set the user Name (login).
|
||||
* @param[in] _value User value
|
||||
*/
|
||||
void setUser(const etk::String& _value);
|
||||
/**
|
||||
* @brief Get the user password.
|
||||
* @return Password string (crypted/hashed)
|
||||
*/
|
||||
const etk::String& getPassword() const;
|
||||
/**
|
||||
* @brief Set the user password.
|
||||
* @param[in] _value Password string (crypted/hashed).
|
||||
*/
|
||||
void setPassword(const etk::String& _value);
|
||||
/**
|
||||
* @brief Get the server name [HOST].
|
||||
* @return Address of the server.
|
||||
*/
|
||||
const etk::String& getServer() const;
|
||||
/**
|
||||
* @brief Set the server name [HOST].
|
||||
* @param[in] _value address of the server.
|
||||
*/
|
||||
void setServer(const etk::String& _value);
|
||||
/**
|
||||
* @brief Get the server port.
|
||||
* @return port Value (0 disable).
|
||||
*/
|
||||
uint16_t getPort() const;
|
||||
/**
|
||||
* @brief Set the server port.
|
||||
* @param[in] _value new server port (0 disable).
|
||||
*/
|
||||
void setPort(uint16_t _value);
|
||||
/**
|
||||
* @brief Get the path of the URI
|
||||
* @return URI path.
|
||||
*/
|
||||
const etk::Path& getPath() const;
|
||||
/**
|
||||
* @brief Set the path.
|
||||
* @param[in] _value New path value.
|
||||
*/
|
||||
void setPath(const etk::Path& _value);
|
||||
/**
|
||||
* @brief Get the Querry.
|
||||
* @return Querry data.
|
||||
*/
|
||||
const etk::uri::Query& getQuery() const;
|
||||
/**
|
||||
* @brief Set the new querry.
|
||||
* @param[in] _value Data.
|
||||
*/
|
||||
void setQuery(const etk::uri::Query& _value);
|
||||
/**
|
||||
* @brief Get the fragment element.
|
||||
* @return frangment string.
|
||||
*/
|
||||
const etk::String& getFragment() const;
|
||||
/**
|
||||
* @brief Set the frangment property.
|
||||
* @param[in] _value New fragment
|
||||
*/
|
||||
void setFragment(const etk::String& _value);
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user