2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2015-06-26 15:37:47 +02:00
|
|
|
|
|
|
|
#ifndef URL_H
|
|
|
|
#define URL_H
|
|
|
|
|
2015-07-20 17:21:27 +02:00
|
|
|
#include "remote/i2-remote.hpp"
|
2015-06-26 15:37:47 +02:00
|
|
|
#include "base/object.hpp"
|
|
|
|
#include "base/string.hpp"
|
2015-07-29 13:09:42 +02:00
|
|
|
#include "base/array.hpp"
|
2015-06-26 15:37:47 +02:00
|
|
|
#include "base/value.hpp"
|
|
|
|
#include <map>
|
2018-12-21 11:52:37 +01:00
|
|
|
#include <utility>
|
2015-06-26 15:37:47 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A url class to use with the API
|
|
|
|
*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class Url final : public Object
|
2015-06-26 15:37:47 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
DECLARE_PTR_TYPEDEFS(Url);
|
|
|
|
|
2018-01-04 09:43:49 +01:00
|
|
|
Url() = default;
|
2015-06-26 15:37:47 +02:00
|
|
|
Url(const String& url);
|
|
|
|
|
2017-09-06 16:01:02 +02:00
|
|
|
String Format(bool onlyPathAndQuery = false, bool printCredentials = false) const;
|
2015-06-26 15:37:47 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String GetScheme() const;
|
|
|
|
String GetAuthority() const;
|
|
|
|
String GetUsername() const;
|
|
|
|
String GetPassword() const;
|
|
|
|
String GetHost() const;
|
|
|
|
String GetPort() const;
|
|
|
|
const std::vector<String>& GetPath() const;
|
2018-12-21 11:52:37 +01:00
|
|
|
const std::vector<std::pair<String, String>>& GetQuery() const;
|
2018-01-04 04:25:35 +01:00
|
|
|
String GetFragment() const;
|
2015-06-26 15:37:47 +02:00
|
|
|
|
2015-09-01 11:11:45 +02:00
|
|
|
void SetScheme(const String& scheme);
|
2015-11-02 16:35:21 +01:00
|
|
|
void SetUsername(const String& username);
|
|
|
|
void SetPassword(const String& password);
|
2015-09-30 14:02:18 +02:00
|
|
|
void SetHost(const String& host);
|
|
|
|
void SetPort(const String& port);
|
2015-09-01 11:11:45 +02:00
|
|
|
void SetPath(const std::vector<String>& path);
|
2018-12-21 11:52:37 +01:00
|
|
|
void SetQuery(const std::vector<std::pair<String, String>>& query);
|
2018-04-06 14:49:15 +02:00
|
|
|
void SetArrayFormatUseBrackets(bool useBrackets = true);
|
2015-11-02 16:35:21 +01:00
|
|
|
|
2015-09-01 11:11:45 +02:00
|
|
|
void AddQueryElement(const String& name, const String& query);
|
|
|
|
void SetFragment(const String& fragment);
|
|
|
|
|
2015-06-26 15:37:47 +02:00
|
|
|
private:
|
|
|
|
String m_Scheme;
|
2015-09-01 11:11:45 +02:00
|
|
|
String m_Username;
|
|
|
|
String m_Password;
|
|
|
|
String m_Host;
|
|
|
|
String m_Port;
|
2015-06-26 15:37:47 +02:00
|
|
|
std::vector<String> m_Path;
|
2018-12-21 11:52:37 +01:00
|
|
|
std::vector<std::pair<String, String>> m_Query;
|
2018-04-06 14:49:15 +02:00
|
|
|
bool m_ArrayFormatUseBrackets;
|
2015-06-26 15:37:47 +02:00
|
|
|
String m_Fragment;
|
|
|
|
|
|
|
|
bool ParseScheme(const String& scheme);
|
|
|
|
bool ParseAuthority(const String& authority);
|
2015-09-01 11:11:45 +02:00
|
|
|
bool ParseUserinfo(const String& userinfo);
|
|
|
|
bool ParsePort(const String& port);
|
2015-06-26 15:37:47 +02:00
|
|
|
bool ParsePath(const String& path);
|
|
|
|
bool ParseQuery(const String& query);
|
|
|
|
bool ParseFragment(const String& fragment);
|
|
|
|
|
|
|
|
static bool ValidateToken(const String& token, const String& symbols);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* URL_H */
|