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"
17 #undef SetPort // WIN32INCLUDES this is defined as SetPortA in WinSpool.h which is being included _somewhere_
23 explicit CURL(const std::string
& strURL
)
31 // explicit equals operator for std::string comparison
32 bool operator==(const std::string
&url
) const { return Get() == url
; }
35 void Parse(const std::string
& strURL
);
36 void SetFileName(const std::string
& strFileName
);
37 void SetHostName(const std::string
& strHostName
)
39 m_strHostName
= strHostName
;
42 void SetUserName(const std::string
& strUserName
)
44 m_strUserName
= strUserName
;
47 void SetDomain(const std::string
& strDomain
)
49 m_strDomain
= strDomain
;
52 void SetPassword(const std::string
& strPassword
)
54 m_strPassword
= strPassword
;
57 void SetProtocol(const std::string
& strProtocol
);
58 void SetOptions(const std::string
& strOptions
);
59 void SetProtocolOptions(const std::string
& strOptions
);
60 void SetPort(int port
)
67 return (m_iPort
!= 0);
75 const std::string
& GetHostName() const
80 const std::string
& GetDomain() const
85 const std::string
& GetUserName() const
90 const std::string
& GetPassWord() const
95 const std::string
& GetFileName() const
100 const std::string
& GetProtocol() const
102 return m_strProtocol
;
105 const std::string
GetTranslatedProtocol() const;
107 const std::string
& GetFileType() const
109 return m_strFileType
;
112 const std::string
& GetShareName() const
114 return m_strShareName
;
117 const std::string
& GetOptions() const
122 const std::string
& GetProtocolOptions() const
124 return m_strProtocolOptions
;
127 const std::string
GetFileNameWithoutPath() const; /* return the filename excluding path */
129 char GetDirectorySeparator() const;
131 std::string
Get() const;
132 std::string
GetWithoutOptions() const;
133 std::string
GetWithoutUserDetails(bool redact
= false) const;
134 std::string
GetWithoutFilename() const;
135 std::string
GetRedacted() const;
136 static std::string
GetRedacted(const std::string
& path
);
137 bool IsLocal() const;
138 bool IsLocalHost() const;
139 static bool IsFileOnly(const std::string
&url
); ///< return true if there are no directories in the url.
140 static bool IsFullPath(const std::string
&url
); ///< return true if the url includes the full path
141 static std::string
Decode(const std::string
& strURLData
);
142 static std::string
Encode(const std::string
& strURLData
);
144 /*! \brief Check whether a URL is a given URL scheme.
145 Comparison is case-insensitive as per RFC1738
146 \param type a lower-case scheme name, e.g. "smb".
147 \return true if the url is of the given scheme, false otherwise.
149 bool IsProtocol(const char *type
) const
151 return IsProtocolEqual(m_strProtocol
, type
);
154 /*! \brief Check whether a URL protocol is a given URL scheme.
155 Both parameters MUST be lower-case. Typically this would be called using
156 the result of TranslateProtocol() which enforces this for protocol.
157 \param protocol a lower-case scheme name, e.g. "ftp"
158 \param type a lower-case scheme name, e.g. "smb".
159 \return true if the url is of the given scheme, false otherwise.
161 static bool IsProtocolEqual(const std::string
& protocol
, const char *type
);
163 /*! \brief Check whether a URL is a given filetype.
164 Comparison is effectively case-insensitive as both the parameter
165 and m_strFileType are lower-case.
166 \param type a lower-case filetype, e.g. "mp3".
167 \return true if the url is of the given filetype, false otherwise.
169 bool IsFileType(const char *type
) const
171 return m_strFileType
== type
;
174 void GetOptions(std::map
<std::string
, std::string
> &options
) const;
175 bool HasOption(const std::string
&key
) const;
176 bool GetOption(const std::string
&key
, std::string
&value
) const;
177 std::string
GetOption(const std::string
&key
) const;
178 void SetOption(const std::string
&key
, const std::string
&value
);
179 void RemoveOption(const std::string
&key
);
181 void GetProtocolOptions(std::map
<std::string
, std::string
> &options
) const;
182 bool HasProtocolOption(const std::string
&key
) const;
183 bool GetProtocolOption(const std::string
&key
, std::string
&value
) const;
184 std::string
GetProtocolOption(const std::string
&key
) const;
185 void SetProtocolOption(const std::string
&key
, const std::string
&value
);
186 void RemoveProtocolOption(const std::string
&key
);
190 std::string m_strHostName
;
191 std::string m_strShareName
;
192 std::string m_strDomain
;
193 std::string m_strUserName
;
194 std::string m_strPassword
;
195 std::string m_strFileName
;
196 std::string m_strProtocol
;
197 std::string m_strFileType
;
198 std::string m_strOptions
;
199 std::string m_strProtocolOptions
;
200 CUrlOptions m_options
;
201 CUrlOptions m_protocolOptions
;