2 * Copyright 2010-2013 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _B_NETWORK_COOKIE_JAR_H_
6 #define _B_NETWORK_COOKIE_JAR_H_
10 #include <Archivable.h>
11 #include <Flattenable.h>
13 #include <NetworkCookie.h>
14 #include <ObjectList.h>
19 class BNetworkCookieList
: public BObjectList
<const BNetworkCookie
> {
22 ~BNetworkCookieList();
24 status_t
LockForReading();
25 status_t
LockForWriting();
28 pthread_rwlock_t fLock
;
32 class BNetworkCookieJar
: public BArchivable
, public BFlattenable
{
37 struct PrivateIterator
;
38 struct PrivateHashMap
;
43 const BNetworkCookieJar
& other
);
45 const BNetworkCookieList
& otherList
);
46 BNetworkCookieJar(BMessage
* archive
);
47 virtual ~BNetworkCookieJar();
49 status_t
AddCookie(const BNetworkCookie
& cookie
);
50 status_t
AddCookie(const BString
& cookie
,
52 status_t
AddCookie(BNetworkCookie
* cookie
);
53 status_t
AddCookies(const BNetworkCookieList
& cookies
);
55 uint32
DeleteOutdatedCookies();
56 uint32
PurgeForExit();
58 // BArchivable members
59 virtual status_t
Archive(BMessage
* into
,
60 bool deep
= true) const;
61 static BArchivable
* Instantiate(BMessage
* archive
);
63 // BFlattenable members
64 virtual bool IsFixedSize() const;
65 virtual type_code
TypeCode() const;
66 virtual ssize_t
FlattenedSize() const;
67 virtual status_t
Flatten(void* buffer
, ssize_t size
)
69 virtual bool AllowsTypeCode(type_code code
) const;
70 virtual status_t
Unflatten(type_code code
,
71 const void* buffer
, ssize_t size
);
73 BNetworkCookieJar
& operator=(const BNetworkCookieJar
& other
);
76 Iterator
GetIterator() const;
77 UrlIterator
GetUrlIterator(const BUrl
& url
) const;
81 void _DoFlatten() const;
84 friend class Iterator
;
85 friend class UrlIterator
;
87 PrivateHashMap
* fCookieHashMap
;
88 mutable BString fFlattened
;
92 class BNetworkCookieJar::Iterator
{
94 Iterator(const Iterator
& other
);
97 Iterator
& operator=(const Iterator
& other
);
100 const BNetworkCookie
* Next();
101 const BNetworkCookie
* NextDomain();
102 const BNetworkCookie
* Remove();
106 Iterator(const BNetworkCookieJar
* map
);
111 friend class BNetworkCookieJar
;
113 BNetworkCookieJar
* fCookieJar
;
114 PrivateIterator
* fIterator
;
115 BNetworkCookieList
* fLastList
;
116 BNetworkCookieList
* fList
;
117 const BNetworkCookie
* fElement
;
118 const BNetworkCookie
* fLastElement
;
123 // The copy constructor and assignment operator create new iterators for the
124 // same cookie jar and url. Iteration will start over.
125 class BNetworkCookieJar::UrlIterator
{
127 UrlIterator(const UrlIterator
& other
);
130 bool HasNext() const;
131 const BNetworkCookie
* Next();
132 const BNetworkCookie
* Remove();
133 UrlIterator
& operator=(const UrlIterator
& other
);
136 UrlIterator(const BNetworkCookieJar
* map
,
146 friend class BNetworkCookieJar
;
148 BNetworkCookieJar
* fCookieJar
;
149 PrivateIterator
* fIterator
;
150 BNetworkCookieList
* fList
;
151 BNetworkCookieList
* fLastList
;
152 const BNetworkCookie
* fElement
;
153 const BNetworkCookie
* fLastElement
;
161 #endif // _B_NETWORK_COOKIE_JAR_