1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #ifndef URL_H 4 #define URL_H 5 6 #include "remote/i2-remote.hpp" 7 #include "base/object.hpp" 8 #include "base/string.hpp" 9 #include "base/array.hpp" 10 #include "base/value.hpp" 11 #include <map> 12 #include <utility> 13 #include <vector> 14 15 namespace icinga 16 { 17 18 /** 19 * A url class to use with the API 20 * 21 * @ingroup base 22 */ 23 class Url final : public Object 24 { 25 public: 26 DECLARE_PTR_TYPEDEFS(Url); 27 28 Url() = default; 29 Url(const String& url); 30 31 String Format(bool onlyPathAndQuery = false, bool printCredentials = false) const; 32 33 String GetScheme() const; 34 String GetAuthority() const; 35 String GetUsername() const; 36 String GetPassword() const; 37 String GetHost() const; 38 String GetPort() const; 39 const std::vector<String>& GetPath() const; 40 const std::vector<std::pair<String, String>>& GetQuery() const; 41 String GetFragment() const; 42 43 void SetScheme(const String& scheme); 44 void SetUsername(const String& username); 45 void SetPassword(const String& password); 46 void SetHost(const String& host); 47 void SetPort(const String& port); 48 void SetPath(const std::vector<String>& path); 49 void SetQuery(const std::vector<std::pair<String, String>>& query); 50 void SetArrayFormatUseBrackets(bool useBrackets = true); 51 52 void AddQueryElement(const String& name, const String& query); 53 void SetFragment(const String& fragment); 54 55 private: 56 String m_Scheme; 57 String m_Username; 58 String m_Password; 59 String m_Host; 60 String m_Port; 61 std::vector<String> m_Path; 62 std::vector<std::pair<String, String>> m_Query; 63 bool m_ArrayFormatUseBrackets; 64 String m_Fragment; 65 66 bool ParseScheme(const String& scheme); 67 bool ParseAuthority(const String& authority); 68 bool ParseUserinfo(const String& userinfo); 69 bool ParsePort(const String& port); 70 bool ParsePath(const String& path); 71 bool ParseQuery(const String& query); 72 bool ParseFragment(const String& fragment); 73 74 static bool ValidateToken(const String& token, const String& symbols); 75 }; 76 77 } 78 #endif /* URL_H */ 79