Fix FreeBSD build.
[haiku.git] / headers / os / net / NetworkCookieJar.h
blob6efba2642faf2edeaa0eec42fc2721578c454cea
1 /*
2 * Copyright 2010-2013 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _B_NETWORK_COOKIE_JAR_H_
6 #define _B_NETWORK_COOKIE_JAR_H_
8 #include <pthread.h>
10 #include <Archivable.h>
11 #include <Flattenable.h>
12 #include <Message.h>
13 #include <NetworkCookie.h>
14 #include <ObjectList.h>
15 #include <String.h>
16 #include <Url.h>
19 class BNetworkCookieList: public BObjectList<const BNetworkCookie> {
20 public:
21 BNetworkCookieList();
22 ~BNetworkCookieList();
24 status_t LockForReading();
25 status_t LockForWriting();
26 status_t Unlock();
27 private:
28 pthread_rwlock_t fLock;
32 class BNetworkCookieJar : public BArchivable, public BFlattenable {
33 public:
34 // Nested types
35 class Iterator;
36 class UrlIterator;
37 struct PrivateIterator;
38 struct PrivateHashMap;
40 public:
41 BNetworkCookieJar();
42 BNetworkCookieJar(
43 const BNetworkCookieJar& other);
44 BNetworkCookieJar(
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,
51 const BUrl& url);
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)
68 const;
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);
75 // Iterators
76 Iterator GetIterator() const;
77 UrlIterator GetUrlIterator(const BUrl& url) const;
80 private:
81 void _DoFlatten() const;
83 private:
84 friend class Iterator;
85 friend class UrlIterator;
87 PrivateHashMap* fCookieHashMap;
88 mutable BString fFlattened;
92 class BNetworkCookieJar::Iterator {
93 public:
94 Iterator(const Iterator& other);
95 ~Iterator();
97 Iterator& operator=(const Iterator& other);
99 bool HasNext() const;
100 const BNetworkCookie* Next();
101 const BNetworkCookie* NextDomain();
102 const BNetworkCookie* Remove();
103 void RemoveDomain();
105 private:
106 Iterator(const BNetworkCookieJar* map);
108 void _FindNext();
110 private:
111 friend class BNetworkCookieJar;
113 BNetworkCookieJar* fCookieJar;
114 PrivateIterator* fIterator;
115 BNetworkCookieList* fLastList;
116 BNetworkCookieList* fList;
117 const BNetworkCookie* fElement;
118 const BNetworkCookie* fLastElement;
119 int32 fIndex;
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 {
126 public:
127 UrlIterator(const UrlIterator& other);
128 ~UrlIterator();
130 bool HasNext() const;
131 const BNetworkCookie* Next();
132 const BNetworkCookie* Remove();
133 UrlIterator& operator=(const UrlIterator& other);
135 private:
136 UrlIterator(const BNetworkCookieJar* map,
137 const BUrl& url);
139 void _Initialize();
140 bool _SuperDomain();
141 void _FindNext();
142 void _FindDomain();
143 bool _FindPath();
145 private:
146 friend class BNetworkCookieJar;
148 BNetworkCookieJar* fCookieJar;
149 PrivateIterator* fIterator;
150 BNetworkCookieList* fList;
151 BNetworkCookieList* fLastList;
152 const BNetworkCookie* fElement;
153 const BNetworkCookie* fLastElement;
155 int32 fIndex;
156 int32 fLastIndex;
158 BUrl fUrl;
161 #endif // _B_NETWORK_COOKIE_JAR_