2010-10-27 18:03:31 +04:00
|
|
|
/*
|
2013-02-07 21:59:43 +04:00
|
|
|
* Copyright 2010-2013 Haiku Inc. All rights reserved.
|
2010-10-27 18:03:31 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _B_NETWORK_COOKIE_JAR_H_
|
|
|
|
#define _B_NETWORK_COOKIE_JAR_H_
|
|
|
|
|
2014-06-11 12:52:11 +04:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
#include <Archivable.h>
|
|
|
|
#include <Flattenable.h>
|
|
|
|
#include <Message.h>
|
|
|
|
#include <NetworkCookie.h>
|
2014-06-11 12:52:11 +04:00
|
|
|
#include <ObjectList.h>
|
2010-10-27 18:03:31 +04:00
|
|
|
#include <String.h>
|
|
|
|
#include <Url.h>
|
|
|
|
|
|
|
|
|
2014-06-11 12:52:11 +04:00
|
|
|
class BNetworkCookieList: public BObjectList<const BNetworkCookie> {
|
|
|
|
public:
|
|
|
|
BNetworkCookieList();
|
|
|
|
~BNetworkCookieList();
|
|
|
|
|
|
|
|
status_t LockForReading();
|
|
|
|
status_t LockForWriting();
|
|
|
|
status_t Unlock();
|
|
|
|
private:
|
|
|
|
pthread_rwlock_t fLock;
|
|
|
|
};
|
2010-10-27 18:03:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
class BNetworkCookieJar : public BArchivable, public BFlattenable {
|
|
|
|
public:
|
|
|
|
// Nested types
|
|
|
|
class Iterator;
|
|
|
|
class UrlIterator;
|
|
|
|
struct PrivateIterator;
|
|
|
|
struct PrivateHashMap;
|
2013-02-07 21:59:43 +04:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
public:
|
|
|
|
BNetworkCookieJar();
|
|
|
|
BNetworkCookieJar(
|
|
|
|
const BNetworkCookieJar& other);
|
|
|
|
BNetworkCookieJar(
|
|
|
|
const BNetworkCookieList& otherList);
|
|
|
|
BNetworkCookieJar(BMessage* archive);
|
|
|
|
virtual ~BNetworkCookieJar();
|
|
|
|
|
2013-02-07 21:59:43 +04:00
|
|
|
status_t AddCookie(const BNetworkCookie& cookie);
|
2013-10-09 14:08:46 +04:00
|
|
|
status_t AddCookie(const BString& cookie,
|
|
|
|
const BUrl& url);
|
2013-02-07 21:59:43 +04:00
|
|
|
status_t AddCookie(BNetworkCookie* cookie);
|
|
|
|
status_t AddCookies(const BNetworkCookieList& cookies);
|
2010-10-27 18:03:31 +04:00
|
|
|
|
|
|
|
uint32 DeleteOutdatedCookies();
|
|
|
|
uint32 PurgeForExit();
|
|
|
|
|
|
|
|
// BArchivable members
|
2013-02-07 21:59:43 +04:00
|
|
|
virtual status_t Archive(BMessage* into,
|
2010-10-27 18:03:31 +04:00
|
|
|
bool deep = true) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
|
|
|
|
|
|
|
// BFlattenable members
|
|
|
|
virtual bool IsFixedSize() const;
|
|
|
|
virtual type_code TypeCode() const;
|
|
|
|
virtual ssize_t FlattenedSize() const;
|
|
|
|
virtual status_t Flatten(void* buffer, ssize_t size)
|
|
|
|
const;
|
|
|
|
virtual bool AllowsTypeCode(type_code code) const;
|
2013-02-07 21:59:43 +04:00
|
|
|
virtual status_t Unflatten(type_code code,
|
2010-10-27 18:03:31 +04:00
|
|
|
const void* buffer, ssize_t size);
|
|
|
|
|
2013-10-25 19:14:33 +04:00
|
|
|
BNetworkCookieJar& operator=(const BNetworkCookieJar& other);
|
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
// Iterators
|
|
|
|
Iterator GetIterator() const;
|
|
|
|
UrlIterator GetUrlIterator(const BUrl& url) const;
|
2013-02-07 21:59:43 +04:00
|
|
|
|
2013-10-25 19:14:33 +04:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
private:
|
|
|
|
void _DoFlatten() const;
|
2013-02-07 21:59:43 +04:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
private:
|
|
|
|
friend class Iterator;
|
|
|
|
friend class UrlIterator;
|
2013-02-07 21:59:43 +04:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
PrivateHashMap* fCookieHashMap;
|
|
|
|
mutable BString fFlattened;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BNetworkCookieJar::Iterator {
|
|
|
|
public:
|
2014-06-11 21:27:03 +04:00
|
|
|
Iterator(const Iterator& other);
|
2010-10-27 18:03:31 +04:00
|
|
|
~Iterator();
|
|
|
|
|
2014-06-11 12:52:11 +04:00
|
|
|
Iterator& operator=(const Iterator& other);
|
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
bool HasNext() const;
|
2014-06-11 12:52:11 +04:00
|
|
|
const BNetworkCookie* Next();
|
|
|
|
const BNetworkCookie* NextDomain();
|
|
|
|
const BNetworkCookie* Remove();
|
2010-10-27 18:03:31 +04:00
|
|
|
void RemoveDomain();
|
|
|
|
|
|
|
|
private:
|
2014-06-11 21:27:03 +04:00
|
|
|
Iterator(const BNetworkCookieJar* map);
|
2010-10-27 18:03:31 +04:00
|
|
|
|
|
|
|
void _FindNext();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class BNetworkCookieJar;
|
|
|
|
|
|
|
|
BNetworkCookieJar* fCookieJar;
|
|
|
|
PrivateIterator* fIterator;
|
|
|
|
BNetworkCookieList* fLastList;
|
|
|
|
BNetworkCookieList* fList;
|
2014-06-11 12:52:11 +04:00
|
|
|
const BNetworkCookie* fElement;
|
|
|
|
const BNetworkCookie* fLastElement;
|
2010-10-27 18:03:31 +04:00
|
|
|
int32 fIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-11 12:52:11 +04:00
|
|
|
// The copy constructor and assignment operator create new iterators for the
|
|
|
|
// same cookie jar and url. Iteration will start over.
|
2010-10-27 18:03:31 +04:00
|
|
|
class BNetworkCookieJar::UrlIterator {
|
|
|
|
public:
|
|
|
|
UrlIterator(const UrlIterator& other);
|
|
|
|
~UrlIterator();
|
|
|
|
|
|
|
|
bool HasNext() const;
|
2014-06-11 12:52:11 +04:00
|
|
|
const BNetworkCookie* Next();
|
|
|
|
const BNetworkCookie* Remove();
|
2010-10-27 18:03:31 +04:00
|
|
|
UrlIterator& operator=(const UrlIterator& other);
|
|
|
|
|
|
|
|
private:
|
|
|
|
UrlIterator(const BNetworkCookieJar* map,
|
|
|
|
const BUrl& url);
|
|
|
|
|
2014-06-11 12:52:11 +04:00
|
|
|
void _Initialize();
|
2013-02-07 21:59:43 +04:00
|
|
|
bool _SuperDomain();
|
2010-10-27 18:03:31 +04:00
|
|
|
void _FindNext();
|
|
|
|
void _FindDomain();
|
|
|
|
bool _FindPath();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class BNetworkCookieJar;
|
|
|
|
|
|
|
|
BNetworkCookieJar* fCookieJar;
|
|
|
|
PrivateIterator* fIterator;
|
|
|
|
BNetworkCookieList* fList;
|
|
|
|
BNetworkCookieList* fLastList;
|
2014-06-11 12:52:11 +04:00
|
|
|
const BNetworkCookie* fElement;
|
|
|
|
const BNetworkCookie* fLastElement;
|
2013-02-07 21:59:43 +04:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
int32 fIndex;
|
|
|
|
int32 fLastIndex;
|
2013-02-07 21:59:43 +04:00
|
|
|
|
2010-10-27 18:03:31 +04:00
|
|
|
BUrl fUrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _B_NETWORK_COOKIE_JAR_
|