From b7617ddd68d4b2b95d8394edad08f2954e859bf5 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 25 Oct 2013 17:14:33 +0200 Subject: [PATCH] Network Cookie Jar: implement assignment operator. This change is needed for implementing cookie persistence in Web+ using the network kit backend. The current implementation requires the user to unarchive the cookie jar, then hand it over to the BUrlContext which will copy it to its own field. This makes the code simpler, but maybe doing a complete copy (with all the cookies) is an heavy operation and could be avoided. --- headers/os/net/NetworkCookieJar.h | 3 +++ .../network/libnetapi/NetworkCookieJar.cpp | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/headers/os/net/NetworkCookieJar.h b/headers/os/net/NetworkCookieJar.h index 0bf070f30f..58364a6a97 100644 --- a/headers/os/net/NetworkCookieJar.h +++ b/headers/os/net/NetworkCookieJar.h @@ -58,10 +58,13 @@ public: virtual status_t Unflatten(type_code code, const void* buffer, ssize_t size); + BNetworkCookieJar& operator=(const BNetworkCookieJar& other); + // Iterators Iterator GetIterator() const; UrlIterator GetUrlIterator(const BUrl& url) const; + private: void _DoFlatten() const; diff --git a/src/kits/network/libnetapi/NetworkCookieJar.cpp b/src/kits/network/libnetapi/NetworkCookieJar.cpp index 03c894cc1b..ee0c4de437 100644 --- a/src/kits/network/libnetapi/NetworkCookieJar.cpp +++ b/src/kits/network/libnetapi/NetworkCookieJar.cpp @@ -71,6 +71,8 @@ BNetworkCookieJar::~BNetworkCookieJar() { for (Iterator it = GetIterator(); it.Next() != NULL;) delete it.Remove(); + + delete fCookieHashMap; } @@ -356,6 +358,30 @@ BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size) } +BNetworkCookieJar& +BNetworkCookieJar::operator=(const BNetworkCookieJar& other) +{ + if(&other == this) + return *this; + + BArchivable::operator=(other); + BFlattenable::operator=(other); + + fFlattened = other.fFlattened; + + delete fCookieHashMap; + fCookieHashMap = new PrivateHashMap(); + + for (Iterator it = other.GetIterator(); it.HasNext();) + { + BNetworkCookie* cookie = it.Next(); + AddCookie(*cookie); // Pass by reference so the cookie is copied. + } + + return *this; +} + + // #pragma mark Iterators