1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
pub mod c;


use std::{
	borrow::Cow,
	error::Error,
	fmt,
	time::SystemTime
};

pub use c::*;



pub type CookieStorageCallbackFn = unsafe fn( cj: CookieJarImpl, data: *mut (), Result<(), CookieStorageError> );
pub type CookieDeleteCallbackFn = unsafe fn(cj: CookieJarImpl, data: *mut (), deleted: usize);
pub type CookieIteratorNextCallbackFn = unsafe fn(cj: CookieIteratorImpl, data: *mut (), Option<CookieImpl>);

pub trait CookieExt {
	fn new(name: &str, value: &str) -> CookieImpl;

	fn creation_time(&self) -> SystemTime;
	fn expires(&self) -> Option<SystemTime>;
	fn domain<'a>(&'a self) -> Cow<'a, str>;
	fn free(&mut self);
	fn is_http_only(&self) -> bool;
	fn name<'a>(&'a self) -> Cow<'a, str>;
	fn path<'a>(&'a self) -> Cow<'a, str>;
	fn is_secure(&self) -> bool;
	fn value<'a>(&'a self) -> Cow<'a, str>;
	
	fn make_http_only(&mut self) -> &mut Self;
	fn make_secure(&mut self) -> &mut Self;
	fn set_creation_time(&mut self, time: &SystemTime) -> &mut Self;
	fn set_expires(&mut self, time: &SystemTime) -> &mut Self;
	fn set_domain(&mut self, domain: &str) -> &mut Self;
	fn set_name(&mut self, name: &str) -> &mut Self;
	fn set_path(&mut self, path: &str) -> &mut Self;
	fn set_value(&mut self, value: &str) -> &mut Self;
}

pub trait CookieJarExt {
	fn delete(&mut self, url: &str, name: &str, complete_cb: CookieDeleteCallbackFn, cb_data: *mut ());
	fn free(&mut self);
	fn global() -> CookieJarImpl;
	fn iterator<'a>(&'a self, url: &str, include_http_only: bool) -> CookieIteratorImpl;
	fn iterator_all<'a>(&'a self) -> CookieIteratorImpl;
	fn store(&mut self, url: &str, cookie: &CookieImpl, success_cb: Option<CookieStorageCallbackFn>, cb_data: *mut ());
}

pub trait CookieIteratorExt {
	fn free(&mut self);
	fn next(&mut self, on_next: CookieIteratorNextCallbackFn, cb_data: *mut ()) -> bool;
}

#[derive(Debug)]
pub enum CookieStorageError {
	Unknown
}



impl fmt::Display for CookieStorageError {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		write!(f, "unable to set cookie (url invalid?)")
	}
}

impl Error for CookieStorageError {
	fn source(&self) -> Option<&(dyn Error + 'static)> { None }
}