1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 /* 3 * Copyright 2007, 2008 Red Hat, Inc. 4 */ 5 6 #ifndef __SOUP_COOKIE_H__ 7 #define __SOUP_COOKIE_H__ 1 8 9 #include <libsoup/soup-types.h> 10 11 G_BEGIN_DECLS 12 13 /** 14 * SoupSameSitePolicy: 15 * @SOUP_SAME_SITE_POLICY_NONE: The cookie is exposed with both cross-site and same-site requests 16 * @SOUP_SAME_SITE_POLICY_LAX: The cookie is withheld on cross-site requests but exposed on cross-site navigations 17 * @SOUP_SAME_SITE_POLICY_STRICT: The cookie is only exposed for same-site requests 18 * 19 * Since: 2.70 20 */ 21 typedef enum { 22 SOUP_SAME_SITE_POLICY_NONE, 23 SOUP_SAME_SITE_POLICY_LAX, 24 SOUP_SAME_SITE_POLICY_STRICT, 25 } SoupSameSitePolicy; 26 27 struct _SoupCookie { 28 char *name; 29 char *value; 30 char *domain; 31 char *path; 32 SoupDate *expires; 33 gboolean secure; 34 gboolean http_only; 35 }; 36 37 SOUP_AVAILABLE_IN_2_24 38 GType soup_cookie_get_type (void); 39 #define SOUP_TYPE_COOKIE (soup_cookie_get_type()) 40 41 #define SOUP_COOKIE_MAX_AGE_ONE_HOUR (60 * 60) 42 #define SOUP_COOKIE_MAX_AGE_ONE_DAY (SOUP_COOKIE_MAX_AGE_ONE_HOUR * 24) 43 #define SOUP_COOKIE_MAX_AGE_ONE_WEEK (SOUP_COOKIE_MAX_AGE_ONE_DAY * 7) 44 #define SOUP_COOKIE_MAX_AGE_ONE_YEAR (SOUP_COOKIE_MAX_AGE_ONE_DAY * 365.2422) 45 46 SOUP_AVAILABLE_IN_2_24 47 SoupCookie *soup_cookie_new (const char *name, 48 const char *value, 49 const char *domain, 50 const char *path, 51 int max_age); 52 SOUP_AVAILABLE_IN_2_24 53 SoupCookie *soup_cookie_parse (const char *header, 54 SoupURI *origin); 55 SOUP_AVAILABLE_IN_2_24 56 SoupCookie *soup_cookie_copy (SoupCookie *cookie); 57 58 SOUP_AVAILABLE_IN_2_32 59 const char *soup_cookie_get_name (SoupCookie *cookie); 60 SOUP_AVAILABLE_IN_2_24 61 void soup_cookie_set_name (SoupCookie *cookie, 62 const char *name); 63 SOUP_AVAILABLE_IN_2_32 64 const char *soup_cookie_get_value (SoupCookie *cookie); 65 SOUP_AVAILABLE_IN_2_24 66 void soup_cookie_set_value (SoupCookie *cookie, 67 const char *value); 68 SOUP_AVAILABLE_IN_2_32 69 const char *soup_cookie_get_domain (SoupCookie *cookie); 70 SOUP_AVAILABLE_IN_2_24 71 void soup_cookie_set_domain (SoupCookie *cookie, 72 const char *domain); 73 SOUP_AVAILABLE_IN_2_32 74 const char *soup_cookie_get_path (SoupCookie *cookie); 75 SOUP_AVAILABLE_IN_2_24 76 void soup_cookie_set_path (SoupCookie *cookie, 77 const char *path); 78 SOUP_AVAILABLE_IN_2_24 79 void soup_cookie_set_max_age (SoupCookie *cookie, 80 int max_age); 81 SOUP_AVAILABLE_IN_2_32 82 SoupDate *soup_cookie_get_expires (SoupCookie *cookie); 83 SOUP_AVAILABLE_IN_2_24 84 void soup_cookie_set_expires (SoupCookie *cookie, 85 SoupDate *expires); 86 SOUP_AVAILABLE_IN_2_32 87 gboolean soup_cookie_get_secure (SoupCookie *cookie); 88 SOUP_AVAILABLE_IN_2_24 89 void soup_cookie_set_secure (SoupCookie *cookie, 90 gboolean secure); 91 SOUP_AVAILABLE_IN_2_32 92 gboolean soup_cookie_get_http_only (SoupCookie *cookie); 93 SOUP_AVAILABLE_IN_2_24 94 void soup_cookie_set_http_only (SoupCookie *cookie, 95 gboolean http_only); 96 97 SOUP_AVAILABLE_IN_2_70 98 void soup_cookie_set_same_site_policy (SoupCookie *cookie, 99 SoupSameSitePolicy policy); 100 SOUP_AVAILABLE_IN_2_70 101 SoupSameSitePolicy soup_cookie_get_same_site_policy (SoupCookie *cookie); 102 103 SOUP_AVAILABLE_IN_2_24 104 char *soup_cookie_to_set_cookie_header (SoupCookie *cookie); 105 SOUP_AVAILABLE_IN_2_24 106 char *soup_cookie_to_cookie_header (SoupCookie *cookie); 107 108 SOUP_AVAILABLE_IN_2_24 109 gboolean soup_cookie_applies_to_uri (SoupCookie *cookie, 110 SoupURI *uri); 111 SOUP_AVAILABLE_IN_2_24 112 gboolean soup_cookie_equal (SoupCookie *cookie1, 113 SoupCookie *cookie2); 114 115 SOUP_AVAILABLE_IN_2_24 116 void soup_cookie_free (SoupCookie *cookie); 117 118 SOUP_AVAILABLE_IN_2_24 119 GSList *soup_cookies_from_response (SoupMessage *msg); 120 SOUP_AVAILABLE_IN_2_24 121 GSList *soup_cookies_from_request (SoupMessage *msg); 122 123 SOUP_AVAILABLE_IN_2_24 124 void soup_cookies_to_response (GSList *cookies, 125 SoupMessage *msg); 126 SOUP_AVAILABLE_IN_2_24 127 void soup_cookies_to_request (GSList *cookies, 128 SoupMessage *msg); 129 130 SOUP_AVAILABLE_IN_2_24 131 void soup_cookies_free (GSList *cookies); 132 133 SOUP_AVAILABLE_IN_2_24 134 char *soup_cookies_to_cookie_header (GSList *cookies); 135 136 SOUP_AVAILABLE_IN_2_30 137 gboolean soup_cookie_domain_matches (SoupCookie *cookie, 138 const char *host); 139 140 G_END_DECLS 141 142 #endif /* __SOUP_COOKIE_H__ */ 143