icinga2/lib/remote/url.hpp

79 lines
1.9 KiB
C++
Raw Normal View History

/* 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);
Url() = default;
2015-06-26 15:37:47 +02:00
Url(const String& url);
String Format(bool onlyPathAndQuery = false, bool printCredentials = false) const;
2015-06-26 15:37:47 +02: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;
String GetFragment() const;
2015-06-26 15:37:47 +02:00
2015-09-01 11:11:45 +02:00
void SetScheme(const String& scheme);
void SetUsername(const String& username);
void SetPassword(const String& password);
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);
void SetArrayFormatUseBrackets(bool useBrackets = true);
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;
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 */