1use crate::{ffi, SameSitePolicy};
7use glib::translate::*;
8
9glib::wrapper! {
10 #[derive(Debug, PartialOrd, Ord, Hash)]
11 pub struct Cookie(Boxed<ffi::SoupCookie>);
12
13 match fn {
14 copy => |ptr| ffi::soup_cookie_copy(mut_override(ptr)),
15 free => |ptr| ffi::soup_cookie_free(ptr),
16 type_ => || ffi::soup_cookie_get_type(),
17 }
18}
19
20impl Cookie {
21 #[doc(alias = "soup_cookie_new")]
22 pub fn new(name: &str, value: &str, domain: &str, path: &str, max_age: i32) -> Cookie {
23 assert_initialized_main_thread!();
24 unsafe {
25 from_glib_full(ffi::soup_cookie_new(
26 name.to_glib_none().0,
27 value.to_glib_none().0,
28 domain.to_glib_none().0,
29 path.to_glib_none().0,
30 max_age,
31 ))
32 }
33 }
34
35 #[doc(alias = "soup_cookie_applies_to_uri")]
36 pub fn applies_to_uri(&mut self, uri: &glib::Uri) -> bool {
37 unsafe {
38 from_glib(ffi::soup_cookie_applies_to_uri(
39 self.to_glib_none_mut().0,
40 uri.to_glib_none().0,
41 ))
42 }
43 }
44
45 #[doc(alias = "soup_cookie_domain_matches")]
46 pub fn domain_matches(&mut self, host: &str) -> bool {
47 unsafe {
48 from_glib(ffi::soup_cookie_domain_matches(
49 self.to_glib_none_mut().0,
50 host.to_glib_none().0,
51 ))
52 }
53 }
54
55 #[doc(alias = "soup_cookie_equal")]
56 fn equal(&self, cookie2: &Cookie) -> bool {
57 unsafe {
58 from_glib(ffi::soup_cookie_equal(
59 mut_override(self.to_glib_none().0),
60 mut_override(cookie2.to_glib_none().0),
61 ))
62 }
63 }
64
65 #[doc(alias = "soup_cookie_get_domain")]
66 #[doc(alias = "get_domain")]
67 pub fn domain(&mut self) -> Option<glib::GString> {
68 unsafe { from_glib_none(ffi::soup_cookie_get_domain(self.to_glib_none_mut().0)) }
69 }
70
71 #[doc(alias = "soup_cookie_get_expires")]
72 #[doc(alias = "get_expires")]
73 pub fn expires(&mut self) -> Option<glib::DateTime> {
74 unsafe { from_glib_none(ffi::soup_cookie_get_expires(self.to_glib_none_mut().0)) }
75 }
76
77 #[doc(alias = "soup_cookie_get_http_only")]
78 #[doc(alias = "get_http_only")]
79 pub fn is_http_only(&mut self) -> bool {
80 unsafe { from_glib(ffi::soup_cookie_get_http_only(self.to_glib_none_mut().0)) }
81 }
82
83 #[doc(alias = "soup_cookie_get_name")]
84 #[doc(alias = "get_name")]
85 pub fn name(&mut self) -> Option<glib::GString> {
86 unsafe { from_glib_none(ffi::soup_cookie_get_name(self.to_glib_none_mut().0)) }
87 }
88
89 #[doc(alias = "soup_cookie_get_path")]
90 #[doc(alias = "get_path")]
91 pub fn path(&mut self) -> Option<glib::GString> {
92 unsafe { from_glib_none(ffi::soup_cookie_get_path(self.to_glib_none_mut().0)) }
93 }
94
95 #[doc(alias = "soup_cookie_get_same_site_policy")]
96 #[doc(alias = "get_same_site_policy")]
97 pub fn same_site_policy(&mut self) -> SameSitePolicy {
98 unsafe {
99 from_glib(ffi::soup_cookie_get_same_site_policy(
100 self.to_glib_none_mut().0,
101 ))
102 }
103 }
104
105 #[doc(alias = "soup_cookie_get_secure")]
106 #[doc(alias = "get_secure")]
107 pub fn is_secure(&mut self) -> bool {
108 unsafe { from_glib(ffi::soup_cookie_get_secure(self.to_glib_none_mut().0)) }
109 }
110
111 #[doc(alias = "soup_cookie_get_value")]
112 #[doc(alias = "get_value")]
113 pub fn value(&mut self) -> Option<glib::GString> {
114 unsafe { from_glib_none(ffi::soup_cookie_get_value(self.to_glib_none_mut().0)) }
115 }
116
117 #[doc(alias = "soup_cookie_set_domain")]
118 pub fn set_domain(&mut self, domain: &str) {
119 unsafe {
120 ffi::soup_cookie_set_domain(self.to_glib_none_mut().0, domain.to_glib_none().0);
121 }
122 }
123
124 #[doc(alias = "soup_cookie_set_expires")]
125 pub fn set_expires(&mut self, expires: &glib::DateTime) {
126 unsafe {
127 ffi::soup_cookie_set_expires(self.to_glib_none_mut().0, expires.to_glib_none().0);
128 }
129 }
130
131 #[doc(alias = "soup_cookie_set_http_only")]
132 pub fn set_http_only(&mut self, http_only: bool) {
133 unsafe {
134 ffi::soup_cookie_set_http_only(self.to_glib_none_mut().0, http_only.into_glib());
135 }
136 }
137
138 #[doc(alias = "soup_cookie_set_max_age")]
139 pub fn set_max_age(&mut self, max_age: i32) {
140 unsafe {
141 ffi::soup_cookie_set_max_age(self.to_glib_none_mut().0, max_age);
142 }
143 }
144
145 #[doc(alias = "soup_cookie_set_name")]
146 pub fn set_name(&mut self, name: &str) {
147 unsafe {
148 ffi::soup_cookie_set_name(self.to_glib_none_mut().0, name.to_glib_none().0);
149 }
150 }
151
152 #[doc(alias = "soup_cookie_set_path")]
153 pub fn set_path(&mut self, path: &str) {
154 unsafe {
155 ffi::soup_cookie_set_path(self.to_glib_none_mut().0, path.to_glib_none().0);
156 }
157 }
158
159 #[doc(alias = "soup_cookie_set_same_site_policy")]
160 pub fn set_same_site_policy(&mut self, policy: SameSitePolicy) {
161 unsafe {
162 ffi::soup_cookie_set_same_site_policy(self.to_glib_none_mut().0, policy.into_glib());
163 }
164 }
165
166 #[doc(alias = "soup_cookie_set_secure")]
167 pub fn set_secure(&mut self, secure: bool) {
168 unsafe {
169 ffi::soup_cookie_set_secure(self.to_glib_none_mut().0, secure.into_glib());
170 }
171 }
172
173 #[doc(alias = "soup_cookie_set_value")]
174 pub fn set_value(&mut self, value: &str) {
175 unsafe {
176 ffi::soup_cookie_set_value(self.to_glib_none_mut().0, value.to_glib_none().0);
177 }
178 }
179
180 #[doc(alias = "soup_cookie_to_cookie_header")]
181 pub fn to_cookie_header(&mut self) -> Option<glib::GString> {
182 unsafe { from_glib_full(ffi::soup_cookie_to_cookie_header(self.to_glib_none_mut().0)) }
183 }
184
185 #[doc(alias = "soup_cookie_to_set_cookie_header")]
186 pub fn to_set_cookie_header(&mut self) -> Option<glib::GString> {
187 unsafe {
188 from_glib_full(ffi::soup_cookie_to_set_cookie_header(
189 self.to_glib_none_mut().0,
190 ))
191 }
192 }
193
194 #[doc(alias = "soup_cookie_parse")]
195 pub fn parse(header: &str, origin: Option<&glib::Uri>) -> Option<Cookie> {
196 assert_initialized_main_thread!();
197 unsafe {
198 from_glib_full(ffi::soup_cookie_parse(
199 header.to_glib_none().0,
200 origin.to_glib_none().0,
201 ))
202 }
203 }
204}
205
206impl PartialEq for Cookie {
207 #[inline]
208 fn eq(&self, other: &Self) -> bool {
209 self.equal(other)
210 }
211}
212
213impl Eq for Cookie {}