2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/UrlOptions.h"
15 #include <string_view>
18 #undef SetPort // WIN32INCLUDES this is defined as SetPortA in WinSpool.h which is being included _somewhere_
24 explicit CURL(std::string strURL
) { Parse(std::move(strURL
)); }
29 // explicit equals operator for std::string comparison
30 bool operator==(const std::string
&url
) const { return Get() == url
; }
33 void Parse(std::string strURL
);
34 void SetFileName(std::string strFileName
);
35 void SetHostName(std::string strHostName
) { m_strHostName
= std::move(strHostName
); }
37 void SetUserName(std::string strUserName
) { m_strUserName
= std::move(strUserName
); }
39 void SetDomain(std::string strDomain
) { m_strDomain
= std::move(strDomain
); }
41 void SetPassword(std::string strPassword
) { m_strPassword
= std::move(strPassword
); }
43 void SetProtocol(std::string strProtocol
);
44 void SetOptions(std::string strOptions
);
45 void SetProtocolOptions(std::string strOptions
);
46 void SetPort(int port
)
53 return (m_iPort
!= 0);
61 const std::string
& GetHostName() const
66 const std::string
& GetDomain() const
71 const std::string
& GetUserName() const
76 const std::string
& GetPassWord() const
81 const std::string
& GetFileName() const
86 const std::string
& GetProtocol() const
91 std::string
GetTranslatedProtocol() const;
93 const std::string
& GetFileType() const
98 const std::string
& GetShareName() const
100 return m_strShareName
;
103 const std::string
& GetOptions() const
108 const std::string
& GetProtocolOptions() const
110 return m_strProtocolOptions
;
113 std::string
GetFileNameWithoutPath() const; /* return the filename excluding path */
115 char GetDirectorySeparator() const;
117 std::string
Get() const;
118 std::string
GetWithoutOptions() const;
119 std::string
GetWithoutUserDetails(bool redact
= false) const;
120 std::string
GetWithoutFilename() const;
121 std::string
GetRedacted() const;
122 static std::string
GetRedacted(std::string path
);
123 bool IsLocal() const;
124 bool IsLocalHost() const;
125 static bool IsFileOnly(const std::string
&url
); ///< return true if there are no directories in the url.
126 static bool IsFullPath(const std::string
&url
); ///< return true if the url includes the full path
127 static std::string
Decode(std::string_view strURLData
);
128 static std::string
Encode(std::string_view strURLData
);
130 /*! \brief Check whether a URL is a given URL scheme.
131 Comparison is case-insensitive as per RFC1738
132 \param type a lower-case scheme name, e.g. "smb".
133 \return true if the url is of the given scheme, false otherwise.
135 bool IsProtocol(const char *type
) const
137 return IsProtocolEqual(m_strProtocol
, type
);
140 /*! \brief Check whether a URL protocol is a given URL scheme.
141 Both parameters MUST be lower-case. Typically this would be called using
142 the result of TranslateProtocol() which enforces this for protocol.
143 \param protocol a lower-case scheme name, e.g. "ftp"
144 \param type a lower-case scheme name, e.g. "smb".
145 \return true if the url is of the given scheme, false otherwise.
147 static bool IsProtocolEqual(const std::string
& protocol
, const char *type
);
149 /*! \brief Check whether a URL is a given filetype.
150 Comparison is effectively case-insensitive as both the parameter
151 and m_strFileType are lower-case.
152 \param type a lower-case filetype, e.g. "mp3".
153 \return true if the url is of the given filetype, false otherwise.
155 bool IsFileType(const char *type
) const
157 return m_strFileType
== type
;
160 void GetOptions(std::map
<std::string
, std::string
> &options
) const;
161 bool HasOption(const std::string
&key
) const;
162 bool GetOption(const std::string
&key
, std::string
&value
) const;
163 std::string
GetOption(const std::string
&key
) const;
164 void SetOption(const std::string
&key
, const std::string
&value
);
165 void RemoveOption(const std::string
&key
);
167 void GetProtocolOptions(std::map
<std::string
, std::string
> &options
) const;
168 bool HasProtocolOption(const std::string
&key
) const;
169 bool GetProtocolOption(const std::string
&key
, std::string
&value
) const;
170 std::string
GetProtocolOption(const std::string
&key
) const;
171 void SetProtocolOption(const std::string
&key
, const std::string
&value
);
172 void RemoveProtocolOption(const std::string
&key
);
176 std::string m_strHostName
;
177 std::string m_strShareName
;
178 std::string m_strDomain
;
179 std::string m_strUserName
;
180 std::string m_strPassword
;
181 std::string m_strFileName
;
182 std::string m_strProtocol
;
183 std::string m_strFileType
;
184 std::string m_strOptions
;
185 std::string m_strProtocolOptions
;
186 CUrlOptions m_options
;
187 CUrlOptions m_protocolOptions
;