2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-07-19 12:26:25 +08:00
|
|
|
Copyright (c) Bytedance Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-07-19 12:26:25 +08:00
|
|
|
https://adxe.org
|
2019-11-23 20:27:39 +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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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
|
|
|
|
/// @cond DO_NOT_SHOW
|
|
|
|
|
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>
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-07-19 12:26:25 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
namespace network
|
|
|
|
{
|
|
|
|
|
|
|
|
class Uri;
|
2019-11-23 20:27:39 +08:00
|
|
|
struct CookiesInfo
|
|
|
|
{
|
2021-07-19 12:26:25 +08:00
|
|
|
CookiesInfo() = default;
|
|
|
|
CookiesInfo(const CookiesInfo&) = default;
|
|
|
|
CookiesInfo(CookiesInfo&& rhs)
|
|
|
|
: 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)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CookiesInfo& operator=(CookiesInfo&& rhs)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSame(const CookiesInfo& rhs) { return name == rhs.name && domain == rhs.domain; }
|
|
|
|
|
|
|
|
void updateValue(const CookiesInfo& rhs)
|
|
|
|
{
|
|
|
|
value = rhs.value;
|
|
|
|
expires = rhs.expires;
|
|
|
|
path = rhs.path;
|
|
|
|
}
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string domain;
|
2021-07-19 12:26:25 +08:00
|
|
|
bool tailmatch = true;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string path;
|
2021-07-19 12:26:25 +08:00
|
|
|
bool secure = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string name;
|
|
|
|
std::string value;
|
2021-07-19 12:26:25 +08:00
|
|
|
time_t expires = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class HttpCookie
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void readFile();
|
|
|
|
|
|
|
|
void writeFile();
|
|
|
|
void setCookieFileName(const std::string& fileName);
|
|
|
|
|
2021-07-19 12:26:25 +08:00
|
|
|
const std::vector<CookiesInfo>* getCookies() const;
|
|
|
|
const CookiesInfo* getMatchCookie(const Uri& uri) const;
|
2019-11-23 20:27:39 +08:00
|
|
|
void updateOrAddCookie(CookiesInfo* cookie);
|
|
|
|
|
2021-07-19 12:26:25 +08:00
|
|
|
// Check match cookies for http request
|
|
|
|
std::string checkAndGetFormatedMatchCookies(const Uri& uri);
|
|
|
|
bool updateOrAddCookie(const std::string& cookie, const Uri& uri);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
std::string _cookieFileName;
|
|
|
|
std::vector<CookiesInfo> _cookies;
|
|
|
|
};
|
2021-07-19 12:26:25 +08:00
|
|
|
} // namespace network
|
|
|
|
|
|
|
|
NS_CC_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/// @endcond
|
|
|
|
#endif /* HTTP_COOKIE_H */
|