2014-12-31 10:02:14 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-07-19 17:58:13 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
https://axys1.github.io/
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2014-12-31 10:02:14 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2014-12-31 10:02:14 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2014-12-31 10:02:14 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef HTTP_COOKIE_H
|
|
|
|
#define HTTP_COOKIE_H
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @cond DO_NOT_SHOW
|
2014-12-31 10:02:14 +08:00
|
|
|
|
2021-07-19 12:40:22 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2021-07-19 12:26:25 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-06-21 19:50:00 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2021-07-19 12:26:25 +08:00
|
|
|
|
|
|
|
namespace network
|
|
|
|
{
|
|
|
|
|
|
|
|
class Uri;
|
2021-07-19 17:58:13 +08:00
|
|
|
struct CookieInfo
|
2014-12-31 10:02:14 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
CookieInfo() = default;
|
2021-07-19 17:58:13 +08:00
|
|
|
CookieInfo(const CookieInfo&) = default;
|
|
|
|
CookieInfo(CookieInfo&& rhs)
|
2021-07-19 12:26:25 +08:00
|
|
|
: domain(std::move(rhs.domain))
|
|
|
|
, tailmatch(rhs.tailmatch)
|
|
|
|
, path(std::move(rhs.path))
|
|
|
|
, secure(rhs.secure)
|
|
|
|
, name(std::move(rhs.name))
|
|
|
|
, value(std::move(rhs.value))
|
|
|
|
, expires(rhs.expires)
|
|
|
|
{}
|
|
|
|
|
2021-07-19 17:58:13 +08:00
|
|
|
CookieInfo& operator=(CookieInfo&& rhs)
|
2021-07-19 12:26:25 +08:00
|
|
|
{
|
|
|
|
domain = std::move(rhs.domain);
|
|
|
|
tailmatch = rhs.tailmatch;
|
|
|
|
path = std::move(rhs.path);
|
|
|
|
secure = rhs.secure;
|
|
|
|
name = std::move(rhs.name);
|
|
|
|
value = std::move(rhs.value);
|
|
|
|
expires = rhs.expires;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-07-19 17:58:13 +08:00
|
|
|
bool isSame(const CookieInfo& rhs) { return name == rhs.name && domain == rhs.domain; }
|
2021-07-19 12:26:25 +08:00
|
|
|
|
2021-07-19 17:58:13 +08:00
|
|
|
void updateValue(const CookieInfo& rhs)
|
2021-07-19 12:26:25 +08:00
|
|
|
{
|
|
|
|
value = rhs.value;
|
|
|
|
expires = rhs.expires;
|
|
|
|
path = rhs.path;
|
|
|
|
}
|
|
|
|
|
2014-12-31 10:02:14 +08:00
|
|
|
std::string domain;
|
2021-07-19 12:26:25 +08:00
|
|
|
bool tailmatch = true;
|
2014-12-31 10:02:14 +08:00
|
|
|
std::string path;
|
2021-07-19 12:26:25 +08:00
|
|
|
bool secure = false;
|
2014-12-31 10:02:14 +08:00
|
|
|
std::string name;
|
|
|
|
std::string value;
|
2021-07-19 12:26:25 +08:00
|
|
|
time_t expires = 0;
|
2014-12-31 10:02:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class HttpCookie
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void readFile();
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2014-12-31 10:02:14 +08:00
|
|
|
void writeFile();
|
2021-12-26 23:26:34 +08:00
|
|
|
void setCookieFileName(std::string_view fileName);
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2021-07-19 17:58:13 +08:00
|
|
|
const std::vector<CookieInfo>* getCookies() const;
|
|
|
|
const CookieInfo* getMatchCookie(const Uri& uri) const;
|
|
|
|
void updateOrAddCookie(CookieInfo* cookie);
|
2016-05-18 12:54:16 +08:00
|
|
|
|
2021-07-19 12:26:25 +08:00
|
|
|
// Check match cookies for http request
|
|
|
|
std::string checkAndGetFormatedMatchCookies(const Uri& uri);
|
2021-12-26 23:26:34 +08:00
|
|
|
bool updateOrAddCookie(std::string_view cookie, const Uri& uri);
|
2021-07-19 12:26:25 +08:00
|
|
|
|
2014-12-31 10:02:14 +08:00
|
|
|
private:
|
|
|
|
std::string _cookieFileName;
|
2021-07-19 17:58:13 +08:00
|
|
|
std::vector<CookieInfo> _cookies;
|
2014-12-31 10:02:14 +08:00
|
|
|
};
|
2021-07-19 12:26:25 +08:00
|
|
|
} // namespace network
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-12-31 10:02:14 +08:00
|
|
|
|
2015-03-24 20:23:51 +08:00
|
|
|
/// @endcond
|
2014-12-31 10:02:14 +08:00
|
|
|
#endif /* HTTP_COOKIE_H */
|