2021-04-11 10:43:54 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <AK/Vector.h>
|
2021-04-11 23:40:49 -04:00
|
|
|
#include <LibCore/DateTime.h>
|
2021-04-11 10:43:54 -04:00
|
|
|
|
|
|
|
namespace Browser {
|
|
|
|
|
|
|
|
struct Cookie {
|
|
|
|
String name;
|
|
|
|
String value;
|
2021-04-11 23:40:49 -04:00
|
|
|
Core::DateTime expiry_time {};
|
2021-04-11 23:47:43 -04:00
|
|
|
String domain {};
|
2021-04-11 23:48:59 -04:00
|
|
|
String path {};
|
2021-04-11 23:49:33 -04:00
|
|
|
bool secure { false };
|
|
|
|
bool http_only { false };
|
2021-04-11 10:43:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class CookieJar {
|
|
|
|
public:
|
|
|
|
String get_cookie(const URL& url) const;
|
|
|
|
void set_cookie(const URL& url, const String& cookie);
|
2021-04-12 12:12:13 -04:00
|
|
|
void dump_cookies() const;
|
2021-04-11 10:43:54 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
static Optional<String> canonicalize_domain(const URL& url);
|
2021-04-11 23:48:59 -04:00
|
|
|
static String default_path(const URL& url);
|
|
|
|
static Optional<Cookie> parse_cookie(const String& cookie_string, String default_domain, String default_path);
|
2021-04-11 14:24:07 -04:00
|
|
|
static void parse_attributes(Cookie& cookie, StringView unparsed_attributes);
|
|
|
|
static void process_attribute(Cookie& cookie, StringView attribute_name, StringView attribute_value);
|
|
|
|
static void on_expires_attribute(Cookie& cookie, StringView attribute_value);
|
|
|
|
static void on_max_age_attribute(Cookie& cookie, StringView attribute_value);
|
|
|
|
static void on_domain_attribute(Cookie& cookie, StringView attribute_value);
|
|
|
|
static void on_path_attribute(Cookie& cookie, StringView attribute_value);
|
2021-04-11 23:49:33 -04:00
|
|
|
static void on_secure_attribute(Cookie& cookie);
|
|
|
|
static void on_http_only_attribute(Cookie& cookie);
|
2021-04-12 11:38:48 -04:00
|
|
|
static Optional<Core::DateTime> parse_date_time(StringView date_string);
|
2021-04-11 10:43:54 -04:00
|
|
|
|
|
|
|
HashMap<String, Vector<Cookie>> m_cookies;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|