Merge branch 'master' into sam460ex
This commit is contained in:
@@ -17,109 +17,96 @@ class BNetworkCookie : public BArchivable {
|
|||||||
public:
|
public:
|
||||||
BNetworkCookie(const char* name,
|
BNetworkCookie(const char* name,
|
||||||
const char* value);
|
const char* value);
|
||||||
BNetworkCookie(const BNetworkCookie& other);
|
|
||||||
BNetworkCookie(const BString& cookieString);
|
BNetworkCookie(const BString& cookieString);
|
||||||
BNetworkCookie(const BString& cookieString,
|
BNetworkCookie(const BString& cookieString,
|
||||||
const BUrl& url);
|
const BUrl& url);
|
||||||
BNetworkCookie(BMessage* archive);
|
BNetworkCookie(BMessage* archive);
|
||||||
BNetworkCookie();
|
BNetworkCookie();
|
||||||
virtual ~BNetworkCookie();
|
virtual ~BNetworkCookie();
|
||||||
|
|
||||||
// Parse a "SetCookie" string, or "name=value"
|
// Parse a "SetCookie" string
|
||||||
|
|
||||||
BNetworkCookie& ParseCookieStringFromUrl(const BString& string,
|
BNetworkCookie& ParseCookieStringFromUrl(const BString& string,
|
||||||
const BUrl& url);
|
const BUrl& url);
|
||||||
BNetworkCookie& ParseCookieString(const BString& cookieString);
|
BNetworkCookie& ParseCookieString(const BString& cookieString);
|
||||||
|
|
||||||
// Modify the cookie fields
|
// Modify the cookie fields
|
||||||
BNetworkCookie& SetComment(const BString& comment);
|
BNetworkCookie& SetName(const BString& name);
|
||||||
BNetworkCookie& SetCommentUrl(const BString& commentUrl);
|
BNetworkCookie& SetValue(const BString& value);
|
||||||
BNetworkCookie& SetDiscard(bool discard);
|
|
||||||
BNetworkCookie& SetDomain(const BString& domain);
|
BNetworkCookie& SetDomain(const BString& domain);
|
||||||
|
BNetworkCookie& SetPath(const BString& path);
|
||||||
BNetworkCookie& SetMaxAge(int32 maxAge);
|
BNetworkCookie& SetMaxAge(int32 maxAge);
|
||||||
BNetworkCookie& SetExpirationDate(time_t expireDate);
|
BNetworkCookie& SetExpirationDate(time_t expireDate);
|
||||||
BNetworkCookie& SetExpirationDate(BDateTime& expireDate);
|
BNetworkCookie& SetExpirationDate(BDateTime& expireDate);
|
||||||
BNetworkCookie& SetPath(const BString& path);
|
|
||||||
BNetworkCookie& SetSecure(bool secure);
|
BNetworkCookie& SetSecure(bool secure);
|
||||||
BNetworkCookie& SetVersion(int8 version);
|
BNetworkCookie& SetHttpOnly(bool httpOnly);
|
||||||
BNetworkCookie& SetName(const BString& name);
|
|
||||||
BNetworkCookie& SetValue(const BString& value);
|
|
||||||
|
|
||||||
// Access the cookie fields
|
// Access the cookie fields
|
||||||
const BString& CommentUrl() const;
|
|
||||||
const BString& Comment() const;
|
|
||||||
bool Discard() const;
|
|
||||||
const BString& Domain() const;
|
|
||||||
int32 MaxAge() const;
|
|
||||||
time_t ExpirationDate() const;
|
|
||||||
const BString& ExpirationString() const;
|
|
||||||
const BString& Path() const;
|
|
||||||
bool Secure() const;
|
|
||||||
int8 Version() const;
|
|
||||||
const BString& Name() const;
|
const BString& Name() const;
|
||||||
const BString& Value() const;
|
const BString& Value() const;
|
||||||
|
const BString& Domain() const;
|
||||||
|
const BString& Path() const;
|
||||||
|
time_t ExpirationDate() const;
|
||||||
|
const BString& ExpirationString() const;
|
||||||
|
bool Secure() const;
|
||||||
|
bool HttpOnly() const;
|
||||||
const BString& RawCookie(bool full) const;
|
const BString& RawCookie(bool full) const;
|
||||||
|
|
||||||
|
bool IsHostOnly() const;
|
||||||
bool IsSessionCookie() const;
|
bool IsSessionCookie() const;
|
||||||
bool IsValid(bool strict = false) const;
|
bool IsValid() const;
|
||||||
bool IsValidForUrl(const BUrl& url) const;
|
bool IsValidForUrl(const BUrl& url) const;
|
||||||
bool IsValidForDomain(const BString& domain) const;
|
bool IsValidForDomain(const BString& domain) const;
|
||||||
bool IsValidForPath(const BString& path) const;
|
bool IsValidForPath(const BString& path) const;
|
||||||
|
|
||||||
// Test if cookie fields are defined
|
// Test if cookie fields are defined
|
||||||
bool HasCommentUrl() const;
|
|
||||||
bool HasComment() const;
|
|
||||||
bool HasDiscard() const;
|
|
||||||
bool HasDomain() const;
|
|
||||||
bool HasMaxAge() const;
|
|
||||||
bool HasExpirationDate() const;
|
|
||||||
bool HasPath() const;
|
|
||||||
bool HasVersion() const;
|
|
||||||
bool HasName() const;
|
bool HasName() const;
|
||||||
bool HasValue() const;
|
bool HasValue() const;
|
||||||
|
bool HasDomain() const;
|
||||||
|
bool HasPath() const;
|
||||||
|
bool HasExpirationDate() const;
|
||||||
|
|
||||||
// Test if cookie could be deleted
|
// Test if cookie could be deleted
|
||||||
bool ShouldDeleteAtExit() const;
|
bool ShouldDeleteAtExit() const;
|
||||||
bool ShouldDeleteNow() const;
|
bool ShouldDeleteNow() const;
|
||||||
|
|
||||||
// BArchivable members
|
// BArchivable members
|
||||||
virtual status_t Archive(BMessage* into,
|
virtual status_t Archive(BMessage* into,
|
||||||
bool deep = true) const;
|
bool deep = true) const;
|
||||||
static BArchivable* Instantiate(BMessage* archive);
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
|
|
||||||
// Overloaded operators
|
// Overloaded operators
|
||||||
BNetworkCookie& operator=(const BNetworkCookie& other);
|
|
||||||
BNetworkCookie& operator=(const char* string);
|
BNetworkCookie& operator=(const char* string);
|
||||||
bool operator==(const BNetworkCookie& other);
|
bool operator==(const BNetworkCookie& other);
|
||||||
bool operator!=(const BNetworkCookie& other);
|
bool operator!=(const BNetworkCookie& other);
|
||||||
private:
|
private:
|
||||||
void _Reset();
|
void _Reset();
|
||||||
void _ExtractNameValuePair(
|
int32 _ExtractNameValuePair(const BString& string,
|
||||||
const BString& cookieString, int16* index,
|
BString& name, BString& value,
|
||||||
bool parseField = false);
|
int32 index);
|
||||||
|
int32 _ExtractAttributeValuePair(
|
||||||
|
const BString& string, BString& name,
|
||||||
|
BString& value, int32 index);
|
||||||
|
BString _DefaultPathForUrl(const BUrl& url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable BString fRawCookie;
|
mutable BString fRawCookie;
|
||||||
mutable bool fRawCookieValid;
|
mutable bool fRawCookieValid;
|
||||||
mutable BString fRawFullCookie;
|
mutable BString fRawFullCookie;
|
||||||
mutable bool fRawFullCookieValid;
|
mutable bool fRawFullCookieValid;
|
||||||
|
|
||||||
BString fComment;
|
|
||||||
BString fCommentUrl;
|
|
||||||
bool fDiscard;
|
|
||||||
BString fDomain;
|
|
||||||
BDateTime fExpiration;
|
|
||||||
mutable BString fExpirationString;
|
mutable BString fExpirationString;
|
||||||
mutable bool fExpirationStringValid;
|
mutable bool fExpirationStringValid;
|
||||||
BString fPath;
|
|
||||||
bool fSecure;
|
|
||||||
int8 fVersion;
|
|
||||||
BString fName;
|
BString fName;
|
||||||
BString fValue;
|
BString fValue;
|
||||||
|
BString fDomain;
|
||||||
bool fHasDiscard;
|
BString fPath;
|
||||||
bool fHasExpirationDate;
|
BDateTime fExpiration;
|
||||||
|
bool fSecure;
|
||||||
|
bool fHttpOnly;
|
||||||
|
|
||||||
|
bool fHostOnly;
|
||||||
bool fSessionCookie;
|
bool fSessionCookie;
|
||||||
bool fHasVersion;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _B_NETWORK_COOKIE_H_
|
#endif // _B_NETWORK_COOKIE_H_
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
* Copyright 2010-2013 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _B_NETWORK_COOKIE_JAR_H_
|
#ifndef _B_NETWORK_COOKIE_JAR_H_
|
||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
class UrlIterator;
|
class UrlIterator;
|
||||||
struct PrivateIterator;
|
struct PrivateIterator;
|
||||||
struct PrivateHashMap;
|
struct PrivateHashMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BNetworkCookieJar();
|
BNetworkCookieJar();
|
||||||
BNetworkCookieJar(
|
BNetworkCookieJar(
|
||||||
@@ -34,16 +34,15 @@ public:
|
|||||||
BNetworkCookieJar(BMessage* archive);
|
BNetworkCookieJar(BMessage* archive);
|
||||||
virtual ~BNetworkCookieJar();
|
virtual ~BNetworkCookieJar();
|
||||||
|
|
||||||
bool AddCookie(const BNetworkCookie& cookie);
|
status_t AddCookie(const BNetworkCookie& cookie);
|
||||||
bool AddCookie(BNetworkCookie* cookie);
|
status_t AddCookie(BNetworkCookie* cookie);
|
||||||
bool AddCookies(
|
status_t AddCookies(const BNetworkCookieList& cookies);
|
||||||
const BNetworkCookieList& cookies);
|
|
||||||
|
|
||||||
uint32 DeleteOutdatedCookies();
|
uint32 DeleteOutdatedCookies();
|
||||||
uint32 PurgeForExit();
|
uint32 PurgeForExit();
|
||||||
|
|
||||||
// BArchivable members
|
// BArchivable members
|
||||||
virtual status_t Archive(BMessage* into,
|
virtual status_t Archive(BMessage* into,
|
||||||
bool deep = true) const;
|
bool deep = true) const;
|
||||||
static BArchivable* Instantiate(BMessage* archive);
|
static BArchivable* Instantiate(BMessage* archive);
|
||||||
|
|
||||||
@@ -54,20 +53,20 @@ public:
|
|||||||
virtual status_t Flatten(void* buffer, ssize_t size)
|
virtual status_t Flatten(void* buffer, ssize_t size)
|
||||||
const;
|
const;
|
||||||
virtual bool AllowsTypeCode(type_code code) const;
|
virtual bool AllowsTypeCode(type_code code) const;
|
||||||
virtual status_t Unflatten(type_code code,
|
virtual status_t Unflatten(type_code code,
|
||||||
const void* buffer, ssize_t size);
|
const void* buffer, ssize_t size);
|
||||||
|
|
||||||
// Iterators
|
// Iterators
|
||||||
Iterator GetIterator() const;
|
Iterator GetIterator() const;
|
||||||
UrlIterator GetUrlIterator(const BUrl& url) const;
|
UrlIterator GetUrlIterator(const BUrl& url) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _DoFlatten() const;
|
void _DoFlatten() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class Iterator;
|
friend class Iterator;
|
||||||
friend class UrlIterator;
|
friend class UrlIterator;
|
||||||
|
|
||||||
PrivateHashMap* fCookieHashMap;
|
PrivateHashMap* fCookieHashMap;
|
||||||
mutable BString fFlattened;
|
mutable BString fFlattened;
|
||||||
};
|
};
|
||||||
@@ -117,7 +116,7 @@ private:
|
|||||||
UrlIterator(const BNetworkCookieJar* map,
|
UrlIterator(const BNetworkCookieJar* map,
|
||||||
const BUrl& url);
|
const BUrl& url);
|
||||||
|
|
||||||
bool _SupDomain();
|
bool _SuperDomain();
|
||||||
void _FindNext();
|
void _FindNext();
|
||||||
void _FindDomain();
|
void _FindDomain();
|
||||||
bool _FindPath();
|
bool _FindPath();
|
||||||
@@ -131,10 +130,10 @@ private:
|
|||||||
BNetworkCookieList* fLastList;
|
BNetworkCookieList* fLastList;
|
||||||
BNetworkCookie* fElement;
|
BNetworkCookie* fElement;
|
||||||
BNetworkCookie* fLastElement;
|
BNetworkCookie* fLastElement;
|
||||||
|
|
||||||
int32 fIndex;
|
int32 fIndex;
|
||||||
int32 fLastIndex;
|
int32 fLastIndex;
|
||||||
|
|
||||||
BUrl fUrl;
|
BUrl fUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ AppearancePrefView::AppearancePrefView(const char* name,
|
|||||||
fTerminalMessenger(messenger)
|
fTerminalMessenger(messenger)
|
||||||
{
|
{
|
||||||
const char* kColorTable[] = {
|
const char* kColorTable[] = {
|
||||||
B_TRANSLATE("Text"),
|
B_TRANSLATE_MARK("Text"),
|
||||||
B_TRANSLATE("Background"),
|
B_TRANSLATE_MARK("Background"),
|
||||||
B_TRANSLATE("Cursor"),
|
B_TRANSLATE_MARK("Cursor"),
|
||||||
B_TRANSLATE("Text under cursor"),
|
B_TRANSLATE_MARK("Text under cursor"),
|
||||||
B_TRANSLATE("Selected text"),
|
B_TRANSLATE_MARK("Selected text"),
|
||||||
B_TRANSLATE("Selected background"),
|
B_TRANSLATE_MARK("Selected background"),
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -272,11 +272,14 @@ AppearancePrefView::MessageReceived(BMessage* msg)
|
|||||||
|
|
||||||
case MSG_COLOR_CHANGED:
|
case MSG_COLOR_CHANGED:
|
||||||
{
|
{
|
||||||
rgb_color oldColor = PrefHandler::Default()->getRGB(
|
const BMessage* itemMessage
|
||||||
fColorField->Menu()->FindMarked()->Label());
|
= fColorField->Menu()->FindMarked()->Message();
|
||||||
|
const char* label = NULL;
|
||||||
|
if (itemMessage->FindString("label", &label) != B_OK)
|
||||||
|
break;
|
||||||
|
rgb_color oldColor = PrefHandler::Default()->getRGB(label);
|
||||||
if (oldColor != fColorControl->ValueAsColor()) {
|
if (oldColor != fColorControl->ValueAsColor()) {
|
||||||
PrefHandler::Default()->setRGB(
|
PrefHandler::Default()->setRGB(label,
|
||||||
fColorField->Menu()->FindMarked()->Label(),
|
|
||||||
fColorControl->ValueAsColor());
|
fColorControl->ValueAsColor());
|
||||||
modified = true;
|
modified = true;
|
||||||
}
|
}
|
||||||
@@ -300,9 +303,12 @@ AppearancePrefView::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case MSG_COLOR_FIELD_CHANGED:
|
case MSG_COLOR_FIELD_CHANGED:
|
||||||
fColorControl->SetValue(PrefHandler::Default()->getRGB(
|
{
|
||||||
fColorField->Menu()->FindMarked()->Label()));
|
const char* label = NULL;
|
||||||
|
if (msg->FindString("label", &label) == B_OK)
|
||||||
|
fColorControl->SetValue(PrefHandler::Default()->getRGB(label));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MSG_BLINK_CURSOR_CHANGED:
|
case MSG_BLINK_CURSOR_CHANGED:
|
||||||
if (PrefHandler::Default()->getBool(PREF_BLINK_CURSOR)
|
if (PrefHandler::Default()->getBool(PREF_BLINK_CURSOR)
|
||||||
@@ -514,23 +520,21 @@ AppearancePrefView::_MakeMenu(uint32 msg, const char** items,
|
|||||||
{
|
{
|
||||||
BPopUpMenu* menu = new BPopUpMenu("");
|
BPopUpMenu* menu = new BPopUpMenu("");
|
||||||
|
|
||||||
int32 i = 0;
|
|
||||||
while (*items) {
|
while (*items) {
|
||||||
if (strcmp((*items), "") == 0)
|
if (strcmp((*items), "") == 0)
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
else {
|
else {
|
||||||
BMessage* message = new BMessage(msg);
|
BMessage* message = new BMessage(msg);
|
||||||
menu->AddItem(new BMenuItem((*items), message));
|
message->AddString("label", *items);
|
||||||
|
BMenuItem* item = new BMenuItem(B_TRANSLATE(*items), message);
|
||||||
|
menu->AddItem(item);
|
||||||
|
if (strcmp(*items, defaultItemName) == 0)
|
||||||
|
item->SetMarked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
items++;
|
items++;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BMenuItem* defaultItem = menu->FindItem(defaultItemName);
|
|
||||||
if (defaultItem)
|
|
||||||
defaultItem->SetMarked(true);
|
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,63 +1,68 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
* Copyright 2010-2013 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Christophe Huriaux, c.huriaux@gmail.com
|
* Christophe Huriaux, c.huriaux@gmail.com
|
||||||
|
* Hamish Morrison, hamishm53@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <new>
|
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <HashString.h>
|
#include <HashString.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <NetworkCookieJar.h>
|
#include <NetworkCookieJar.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#include "NetworkCookieJarPrivate.h"
|
#include "NetworkCookieJarPrivate.h"
|
||||||
|
|
||||||
const char* kArchivedCookieMessageName = "be:cookie";
|
|
||||||
|
const char* kArchivedCookieMessageName = "be:cookie";
|
||||||
|
|
||||||
|
|
||||||
BNetworkCookieJar::BNetworkCookieJar()
|
BNetworkCookieJar::BNetworkCookieJar()
|
||||||
:
|
:
|
||||||
fCookieHashMap(new PrivateHashMap)
|
fCookieHashMap(new PrivateHashMap())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BNetworkCookieJar::BNetworkCookieJar(const BNetworkCookieJar&)
|
BNetworkCookieJar::BNetworkCookieJar(const BNetworkCookieJar&)
|
||||||
:
|
:
|
||||||
BArchivable(),
|
fCookieHashMap(new PrivateHashMap())
|
||||||
fCookieHashMap(new PrivateHashMap)
|
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BNetworkCookieJar::BNetworkCookieJar(const BNetworkCookieList& otherList)
|
BNetworkCookieJar::BNetworkCookieJar(const BNetworkCookieList& otherList)
|
||||||
:
|
:
|
||||||
fCookieHashMap(new PrivateHashMap)
|
fCookieHashMap(new PrivateHashMap())
|
||||||
{
|
{
|
||||||
AddCookies(otherList);
|
AddCookies(otherList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BNetworkCookieJar::BNetworkCookieJar(BMessage* archive)
|
BNetworkCookieJar::BNetworkCookieJar(BMessage* archive)
|
||||||
:
|
:
|
||||||
fCookieHashMap(new PrivateHashMap)
|
fCookieHashMap(new PrivateHashMap())
|
||||||
{
|
{
|
||||||
BMessage extractedCookie;
|
BMessage extractedCookie;
|
||||||
|
|
||||||
for (int32 i = 0;
|
for (int32 i = 0; archive->FindMessage(kArchivedCookieMessageName, i,
|
||||||
archive->FindMessage(kArchivedCookieMessageName, i, &extractedCookie)
|
&extractedCookie) == B_OK; i++) {
|
||||||
== B_OK;
|
BNetworkCookie* heapCookie
|
||||||
i++) {
|
|
||||||
BNetworkCookie* heapCookie
|
|
||||||
= new(std::nothrow) BNetworkCookie(&extractedCookie);
|
= new(std::nothrow) BNetworkCookie(&extractedCookie);
|
||||||
|
|
||||||
if (heapCookie == NULL || !AddCookie(heapCookie))
|
if (heapCookie == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (!AddCookie(heapCookie)) {
|
||||||
|
delete heapCookie;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +70,8 @@ BNetworkCookieJar::BNetworkCookieJar(BMessage* archive)
|
|||||||
BNetworkCookieJar::~BNetworkCookieJar()
|
BNetworkCookieJar::~BNetworkCookieJar()
|
||||||
{
|
{
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); )
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;)
|
||||||
delete it.Remove();
|
delete it.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,64 +79,72 @@ BNetworkCookieJar::~BNetworkCookieJar()
|
|||||||
// #pragma mark Add cookie to cookie jar
|
// #pragma mark Add cookie to cookie jar
|
||||||
|
|
||||||
|
|
||||||
bool
|
status_t
|
||||||
BNetworkCookieJar::AddCookie(const BNetworkCookie& cookie)
|
BNetworkCookieJar::AddCookie(const BNetworkCookie& cookie)
|
||||||
{
|
{
|
||||||
BNetworkCookie* heapCookie = new(std::nothrow) BNetworkCookie(cookie);
|
BNetworkCookie* heapCookie = new(std::nothrow) BNetworkCookie(cookie);
|
||||||
|
if (heapCookie == NULL)
|
||||||
if (!AddCookie(heapCookie)) {
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
status_t result = AddCookie(heapCookie);
|
||||||
|
if (result != B_OK) {
|
||||||
delete heapCookie;
|
delete heapCookie;
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
status_t
|
||||||
BNetworkCookieJar::AddCookie(BNetworkCookie* cookie)
|
BNetworkCookieJar::AddCookie(BNetworkCookie* cookie)
|
||||||
{
|
{
|
||||||
if (cookie != NULL) {
|
if (cookie == NULL)
|
||||||
HashString key(cookie->Domain());
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (!fCookieHashMap->fHashMap.ContainsKey(key))
|
HashString key(cookie->Domain());
|
||||||
fCookieHashMap->fHashMap.Put(key, new BList);
|
|
||||||
|
BNetworkCookieList* list = fCookieHashMap->fHashMap.Get(key);
|
||||||
BNetworkCookieList* list = fCookieHashMap->fHashMap.Get(key);
|
if (list == NULL) {
|
||||||
|
list = new(std::nothrow) BNetworkCookieList();
|
||||||
for (int32 i = 0; i < list->CountItems(); i++) {
|
if (list == NULL || fCookieHashMap->fHashMap.Put(key, list) != B_OK)
|
||||||
BNetworkCookie* c
|
return B_NO_MEMORY;
|
||||||
= reinterpret_cast<BNetworkCookie*>(list->ItemAt(i));
|
|
||||||
|
|
||||||
if (c->Name() == cookie->Name()) {
|
|
||||||
list->RemoveItem(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discard the cookie if it's to be deleted
|
|
||||||
if (!cookie->ShouldDeleteNow())
|
|
||||||
list->AddItem(cookie);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
for (int32 i = 0; i < list->CountItems(); i++) {
|
||||||
|
BNetworkCookie* c
|
||||||
|
= reinterpret_cast<BNetworkCookie*>(list->ItemAt(i));
|
||||||
|
|
||||||
|
if (c->Name() == cookie->Name() && c->Path() == cookie->Path()) {
|
||||||
|
list->RemoveItem(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cookie->ShouldDeleteNow())
|
||||||
|
delete cookie;
|
||||||
|
else
|
||||||
|
list->AddItem(cookie);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
status_t
|
||||||
BNetworkCookieJar::AddCookies(const BNetworkCookieList& cookies)
|
BNetworkCookieJar::AddCookies(const BNetworkCookieList& cookies)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < cookies.CountItems(); i++) {
|
for (int32 i = 0; i < cookies.CountItems(); i++) {
|
||||||
BNetworkCookie* cookiePtr
|
BNetworkCookie* cookiePtr
|
||||||
= reinterpret_cast<BNetworkCookie*>(cookies.ItemAt(i));
|
= reinterpret_cast<BNetworkCookie*>(cookies.ItemAt(i));
|
||||||
|
|
||||||
// Using AddCookie by reference in order to avoid multiple
|
// Using AddCookie by reference in order to avoid multiple
|
||||||
// cookie jar share the same cookie pointers
|
// cookie jar share the same cookie pointers
|
||||||
if (!AddCookie(*cookiePtr))
|
status_t result = AddCookie(*cookiePtr);
|
||||||
return false;
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,8 +156,8 @@ BNetworkCookieJar::DeleteOutdatedCookies()
|
|||||||
{
|
{
|
||||||
int32 deleteCount = 0;
|
int32 deleteCount = 0;
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
if (cookiePtr->ShouldDeleteNow()) {
|
if (cookiePtr->ShouldDeleteNow()) {
|
||||||
delete it.Remove();
|
delete it.Remove();
|
||||||
deleteCount++;
|
deleteCount++;
|
||||||
@@ -160,8 +173,8 @@ BNetworkCookieJar::PurgeForExit()
|
|||||||
{
|
{
|
||||||
int32 deleteCount = 0;
|
int32 deleteCount = 0;
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
if (cookiePtr->ShouldDeleteAtExit()) {
|
if (cookiePtr->ShouldDeleteAtExit()) {
|
||||||
delete it.Remove();
|
delete it.Remove();
|
||||||
deleteCount++;
|
deleteCount++;
|
||||||
@@ -182,10 +195,10 @@ BNetworkCookieJar::Archive(BMessage* into, bool deep) const
|
|||||||
|
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
|
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
BMessage subArchive;
|
BMessage subArchive;
|
||||||
|
|
||||||
error = cookiePtr->Archive(&subArchive, deep);
|
error = cookiePtr->Archive(&subArchive, deep);
|
||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
@@ -205,7 +218,7 @@ BNetworkCookieJar::Instantiate(BMessage* archive)
|
|||||||
{
|
{
|
||||||
if (archive->HasMessage(kArchivedCookieMessageName))
|
if (archive->HasMessage(kArchivedCookieMessageName))
|
||||||
return new(std::nothrow) BNetworkCookieJar(archive);
|
return new(std::nothrow) BNetworkCookieJar(archive);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,11 +255,11 @@ BNetworkCookieJar::Flatten(void* buffer, ssize_t size) const
|
|||||||
{
|
{
|
||||||
if (FlattenedSize() > size)
|
if (FlattenedSize() > size)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
fFlattened.CopyInto(reinterpret_cast<char*>(buffer), 0,
|
fFlattened.CopyInto(reinterpret_cast<char*>(buffer), 0,
|
||||||
fFlattened.Length());
|
fFlattened.Length());
|
||||||
reinterpret_cast<char*>(buffer)[fFlattened.Length()] = 0;
|
reinterpret_cast<char*>(buffer)[fFlattened.Length()] = 0;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,13 +275,13 @@ BNetworkCookieJar::AllowsTypeCode(type_code) const
|
|||||||
status_t
|
status_t
|
||||||
BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
|
BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
BString flattenedCookies;
|
BString flattenedCookies;
|
||||||
flattenedCookies.SetTo(reinterpret_cast<const char*>(buffer), size);
|
flattenedCookies.SetTo(reinterpret_cast<const char*>(buffer), size);
|
||||||
|
|
||||||
while (flattenedCookies.Length() > 0) {
|
while (flattenedCookies.Length() > 0) {
|
||||||
BNetworkCookie tempCookie;
|
BNetworkCookie tempCookie;
|
||||||
BString tempCookieLine;
|
BString tempCookieLine;
|
||||||
|
|
||||||
int32 endOfLine = flattenedCookies.FindFirst('\n', 0);
|
int32 endOfLine = flattenedCookies.FindFirst('\n', 0);
|
||||||
if (endOfLine == -1)
|
if (endOfLine == -1)
|
||||||
tempCookieLine = flattenedCookies;
|
tempCookieLine = flattenedCookies;
|
||||||
@@ -276,11 +289,11 @@ BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
|
|||||||
flattenedCookies.MoveInto(tempCookieLine, 0, endOfLine);
|
flattenedCookies.MoveInto(tempCookieLine, 0, endOfLine);
|
||||||
flattenedCookies.Remove(0, 1);
|
flattenedCookies.Remove(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempCookieLine.Length() != 0 && tempCookieLine[0] != '#') {
|
if (tempCookieLine.Length() != 0 && tempCookieLine[0] != '#') {
|
||||||
for (int32 field = 0; field < 7; field++) {
|
for (int32 field = 0; field < 7; field++) {
|
||||||
BString tempString;
|
BString tempString;
|
||||||
|
|
||||||
int32 endOfField = tempCookieLine.FindFirst('\t', 0);
|
int32 endOfField = tempCookieLine.FindFirst('\t', 0);
|
||||||
if (endOfField == -1)
|
if (endOfField == -1)
|
||||||
tempString = tempCookieLine;
|
tempString = tempCookieLine;
|
||||||
@@ -288,42 +301,42 @@ BNetworkCookieJar::Unflatten(type_code, const void* buffer, ssize_t size)
|
|||||||
tempCookieLine.MoveInto(tempString, 0, endOfField);
|
tempCookieLine.MoveInto(tempString, 0, endOfField);
|
||||||
tempCookieLine.Remove(0, 1);
|
tempCookieLine.Remove(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 0:
|
case 0:
|
||||||
tempCookie.SetDomain(tempString);
|
tempCookie.SetDomain(tempString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// TODO: Useless field ATM
|
// TODO: Useless field ATM
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
tempCookie.SetPath(tempString);
|
tempCookie.SetPath(tempString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
tempCookie.SetSecure(tempString == "TRUE");
|
tempCookie.SetSecure(tempString == "TRUE");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
tempCookie.SetExpirationDate(atoi(tempString));
|
tempCookie.SetExpirationDate(atoi(tempString));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
tempCookie.SetName(tempString);
|
tempCookie.SetName(tempString);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
tempCookie.SetValue(tempString);
|
tempCookie.SetValue(tempString);
|
||||||
break;
|
break;
|
||||||
} // switch
|
} // switch
|
||||||
} // for loop
|
} // for loop
|
||||||
|
|
||||||
AddCookie(tempCookie);
|
AddCookie(tempCookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,7 +359,7 @@ BNetworkCookieJar::GetUrlIterator(const BUrl& url) const
|
|||||||
copy.SetPath("/");
|
copy.SetPath("/");
|
||||||
return BNetworkCookieJar::UrlIterator(this, copy);
|
return BNetworkCookieJar::UrlIterator(this, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BNetworkCookieJar::UrlIterator(this, url);
|
return BNetworkCookieJar::UrlIterator(this, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,10 +370,10 @@ BNetworkCookieJar::_DoFlatten() const
|
|||||||
fFlattened.Truncate(0);
|
fFlattened.Truncate(0);
|
||||||
|
|
||||||
BNetworkCookie* cookiePtr;
|
BNetworkCookie* cookiePtr;
|
||||||
for (Iterator it(GetIterator()); (cookiePtr = it.Next()); ) {
|
for (Iterator it = GetIterator(); (cookiePtr = it.Next()) != NULL;) {
|
||||||
fFlattened << cookiePtr->Domain() << '\t' << "TRUE" << '\t'
|
fFlattened << cookiePtr->Domain() << '\t' << "TRUE" << '\t'
|
||||||
<< cookiePtr->Path() << '\t'
|
<< cookiePtr->Path() << '\t'
|
||||||
<< (cookiePtr->Secure()?"TRUE":"FALSE") << '\t'
|
<< (cookiePtr->Secure()?"TRUE":"FALSE") << '\t'
|
||||||
<< (int32)cookiePtr->ExpirationDate() << '\t'
|
<< (int32)cookiePtr->ExpirationDate() << '\t'
|
||||||
<< cookiePtr->Name() << '\t' << cookiePtr->Value() << '\n';
|
<< cookiePtr->Name() << '\t' << cookiePtr->Value() << '\n';
|
||||||
}
|
}
|
||||||
@@ -395,7 +408,7 @@ BNetworkCookieJar::Iterator::Iterator(const BNetworkCookieJar* cookieJar)
|
|||||||
{
|
{
|
||||||
fIterator = new(std::nothrow) PrivateIterator(
|
fIterator = new(std::nothrow) PrivateIterator(
|
||||||
fCookieJar->fCookieHashMap->fHashMap.GetIterator());
|
fCookieJar->fCookieHashMap->fHashMap.GetIterator());
|
||||||
|
|
||||||
// Locate first cookie
|
// Locate first cookie
|
||||||
_FindNext();
|
_FindNext();
|
||||||
}
|
}
|
||||||
@@ -419,7 +432,7 @@ BNetworkCookieJar::Iterator::Next()
|
|||||||
{
|
{
|
||||||
if (!fElement)
|
if (!fElement)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BNetworkCookie* result = fElement;
|
BNetworkCookie* result = fElement;
|
||||||
_FindNext();
|
_FindNext();
|
||||||
return result;
|
return result;
|
||||||
@@ -431,18 +444,18 @@ BNetworkCookieJar::Iterator::NextDomain()
|
|||||||
{
|
{
|
||||||
if (!fElement)
|
if (!fElement)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BNetworkCookie* result = fElement;
|
BNetworkCookie* result = fElement;
|
||||||
|
|
||||||
if (!fIterator->fCookieMapIterator.HasNext()) {
|
if (!fIterator->fCookieMapIterator.HasNext()) {
|
||||||
fElement = NULL;
|
fElement = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fList = *(fIterator->fCookieMapIterator.NextValue());
|
fList = *fIterator->fCookieMapIterator.NextValue();
|
||||||
fIndex = 0;
|
fIndex = 0;
|
||||||
fElement = reinterpret_cast<BNetworkCookie*>(fList->ItemAt(fIndex));
|
fElement = reinterpret_cast<BNetworkCookie*>(fList->ItemAt(fIndex));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +465,7 @@ BNetworkCookieJar::Iterator::Remove()
|
|||||||
{
|
{
|
||||||
if (!fLastElement)
|
if (!fLastElement)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BNetworkCookie* result = fLastElement;
|
BNetworkCookie* result = fLastElement;
|
||||||
|
|
||||||
if (fIndex == 0) {
|
if (fIndex == 0) {
|
||||||
@@ -463,10 +476,10 @@ BNetworkCookieJar::Iterator::Remove()
|
|||||||
else
|
else
|
||||||
fLastList->RemoveItem(fLastList->CountItems() - 1);
|
fLastList->RemoveItem(fLastList->CountItems() - 1);
|
||||||
} else {
|
} else {
|
||||||
fList->RemoveItem(fIndex-1);
|
|
||||||
fIndex--;
|
fIndex--;
|
||||||
|
fList->RemoveItem(fIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
fLastElement = NULL;
|
fLastElement = NULL;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -476,12 +489,18 @@ BNetworkCookieJar::Iterator&
|
|||||||
BNetworkCookieJar::Iterator::operator=(const BNetworkCookieJar::Iterator& other)
|
BNetworkCookieJar::Iterator::operator=(const BNetworkCookieJar::Iterator& other)
|
||||||
{
|
{
|
||||||
fCookieJar = other.fCookieJar;
|
fCookieJar = other.fCookieJar;
|
||||||
fIterator = other.fIterator;
|
|
||||||
fLastList = other.fLastList;
|
fLastList = other.fLastList;
|
||||||
fList = other.fList;
|
fList = other.fList;
|
||||||
fElement = other.fElement;
|
fElement = other.fElement;
|
||||||
fLastElement = other.fLastElement;
|
fLastElement = other.fLastElement;
|
||||||
fIndex = other.fIndex;
|
fIndex = other.fIndex;
|
||||||
|
|
||||||
|
fIterator = new(std::nothrow) PrivateIterator(*other.fIterator);
|
||||||
|
if (fIterator == NULL) {
|
||||||
|
// Make the iterator unusable.
|
||||||
|
fElement = NULL;
|
||||||
|
fLastElement = NULL;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,18 +509,18 @@ void
|
|||||||
BNetworkCookieJar::Iterator::_FindNext()
|
BNetworkCookieJar::Iterator::_FindNext()
|
||||||
{
|
{
|
||||||
fLastElement = fElement;
|
fLastElement = fElement;
|
||||||
|
|
||||||
fIndex++;
|
fIndex++;
|
||||||
if (fList && fIndex < fList->CountItems()) {
|
if (fList && fIndex < fList->CountItems()) {
|
||||||
fElement = reinterpret_cast<BNetworkCookie*>(fList->ItemAt(fIndex));
|
fElement = reinterpret_cast<BNetworkCookie*>(fList->ItemAt(fIndex));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fIterator->fCookieMapIterator.HasNext()) {
|
if (!fIterator->fCookieMapIterator.HasNext()) {
|
||||||
fElement = NULL;
|
fElement = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fLastList = fList;
|
fLastList = fList;
|
||||||
fList = *(fIterator->fCookieMapIterator.NextValue());
|
fList = *(fIterator->fCookieMapIterator.NextValue());
|
||||||
fIndex = 0;
|
fIndex = 0;
|
||||||
@@ -529,25 +548,22 @@ BNetworkCookieJar::UrlIterator::UrlIterator(const BNetworkCookieJar* cookieJar,
|
|||||||
fLastElement(NULL),
|
fLastElement(NULL),
|
||||||
fIndex(0),
|
fIndex(0),
|
||||||
fLastIndex(0),
|
fLastIndex(0),
|
||||||
fUrl(const_cast<BUrl&>(url))
|
fUrl(url)
|
||||||
{
|
{
|
||||||
BString domain(url.Host());
|
BString domain = url.Host();
|
||||||
|
|
||||||
if (!domain.Length())
|
if (!domain.Length())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (domain[0] != '.')
|
|
||||||
domain.Prepend(".");
|
|
||||||
|
|
||||||
// Prepending another dot since _FindNext is going to
|
|
||||||
// call _SupDomain()
|
|
||||||
domain.Prepend(".");
|
|
||||||
|
|
||||||
fIterator = new(std::nothrow) PrivateIterator(
|
fIterator = new(std::nothrow) PrivateIterator(
|
||||||
fCookieJar->fCookieHashMap->fHashMap.GetIterator());
|
fCookieJar->fCookieHashMap->fHashMap.GetIterator());
|
||||||
fIterator->fKey.SetTo(domain, domain.Length());
|
|
||||||
|
|
||||||
_FindNext();
|
if (fIterator != NULL) {
|
||||||
|
// Prepending a dot since _FindNext is going to call _SupDomain()
|
||||||
|
domain.Prepend(".");
|
||||||
|
fIterator->fKey.SetTo(domain, domain.Length());
|
||||||
|
_FindNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -569,7 +585,7 @@ BNetworkCookieJar::UrlIterator::Next()
|
|||||||
{
|
{
|
||||||
if (!fElement)
|
if (!fElement)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BNetworkCookie* result = fElement;
|
BNetworkCookie* result = fElement;
|
||||||
_FindNext();
|
_FindNext();
|
||||||
return result;
|
return result;
|
||||||
@@ -581,15 +597,15 @@ BNetworkCookieJar::UrlIterator::Remove()
|
|||||||
{
|
{
|
||||||
if (!fLastElement)
|
if (!fLastElement)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BNetworkCookie* result = fLastElement;
|
BNetworkCookie* result = fLastElement;
|
||||||
|
|
||||||
fLastList->RemoveItem(fLastIndex);
|
fLastList->RemoveItem(fLastIndex);
|
||||||
|
|
||||||
if (fLastList->CountItems() == 0) {
|
if (fLastList->CountItems() == 0) {
|
||||||
HashString lastKey(fLastElement->Domain(),
|
HashString lastKey(fLastElement->Domain(),
|
||||||
fLastElement->Domain().Length());
|
fLastElement->Domain().Length());
|
||||||
|
|
||||||
delete fCookieJar->fCookieHashMap->fHashMap.Remove(lastKey);
|
delete fCookieJar->fCookieHashMap->fHashMap.Remove(lastKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,23 +625,28 @@ BNetworkCookieJar::UrlIterator::operator=(
|
|||||||
fLastElement = other.fLastElement;
|
fLastElement = other.fLastElement;
|
||||||
fIndex = other.fIndex;
|
fIndex = other.fIndex;
|
||||||
fLastIndex = other.fLastIndex;
|
fLastIndex = other.fLastIndex;
|
||||||
fUrl = other.fUrl;
|
|
||||||
fIterator = other.fIterator;
|
fIterator = new(std::nothrow) PrivateIterator(*other.fIterator);
|
||||||
|
if (fIterator == NULL) {
|
||||||
|
// Make the iterator unusable.
|
||||||
|
fElement = NULL;
|
||||||
|
fLastElement = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BNetworkCookieJar::UrlIterator::_SupDomain()
|
BNetworkCookieJar::UrlIterator::_SuperDomain()
|
||||||
{
|
{
|
||||||
BString domain(fIterator->fKey.GetString());
|
const char* domain = fIterator->fKey.GetString();
|
||||||
int32 nextDot = domain.FindFirst('.', 1);
|
const char* nextDot = strchr(domain, '.');
|
||||||
|
|
||||||
if (nextDot == -1)
|
if (nextDot == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
domain.Remove(0, nextDot);
|
fIterator->fKey.SetTo(nextDot + 1);
|
||||||
fIterator->fKey.SetTo(domain.String(), domain.Length());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,19 +656,16 @@ BNetworkCookieJar::UrlIterator::_FindNext()
|
|||||||
{
|
{
|
||||||
fLastIndex = fIndex;
|
fLastIndex = fIndex;
|
||||||
fLastElement = fElement;
|
fLastElement = fElement;
|
||||||
|
|
||||||
if (_FindPath())
|
|
||||||
return;
|
|
||||||
|
|
||||||
fLastList = fList;
|
fLastList = fList;
|
||||||
do {
|
|
||||||
if (!_SupDomain()) {
|
while (!_FindPath()) {
|
||||||
|
if (!_SuperDomain()) {
|
||||||
fElement = NULL;
|
fElement = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_FindDomain();
|
_FindDomain();
|
||||||
} while (!_FindPath());
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -655,10 +673,10 @@ void
|
|||||||
BNetworkCookieJar::UrlIterator::_FindDomain()
|
BNetworkCookieJar::UrlIterator::_FindDomain()
|
||||||
{
|
{
|
||||||
fList = fCookieJar->fCookieHashMap->fHashMap.Get(fIterator->fKey);
|
fList = fCookieJar->fCookieHashMap->fHashMap.Get(fIterator->fKey);
|
||||||
|
|
||||||
if (fList == NULL)
|
if (fList == NULL)
|
||||||
fElement = NULL;
|
fElement = NULL;
|
||||||
|
|
||||||
fIndex = -1;
|
fIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,17 +685,14 @@ bool
|
|||||||
BNetworkCookieJar::UrlIterator::_FindPath()
|
BNetworkCookieJar::UrlIterator::_FindPath()
|
||||||
{
|
{
|
||||||
fIndex++;
|
fIndex++;
|
||||||
if (fList && fIndex < fList->CountItems()) {
|
while (fList && fIndex < fList->CountItems()) {
|
||||||
do {
|
fElement = reinterpret_cast<BNetworkCookie*>(fList->ItemAt(fIndex));
|
||||||
fElement
|
|
||||||
= reinterpret_cast<BNetworkCookie*>(fList->ItemAt(fIndex));
|
if (fElement->IsValidForPath(fUrl.Path()))
|
||||||
|
return true;
|
||||||
if (fElement->IsValidForPath(fUrl.Path()))
|
|
||||||
return true;
|
fIndex++;
|
||||||
|
|
||||||
fIndex++;
|
|
||||||
} while (fList && fIndex < fList->CountItems());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ const uint32 kUpdateVolumeSpaceBar = 'UpSB';
|
|||||||
const uint32 kShowVolumeSpaceBar = 'ShSB';
|
const uint32 kShowVolumeSpaceBar = 'ShSB';
|
||||||
const uint32 kSpaceBarColorChanged = 'SBcc';
|
const uint32 kSpaceBarColorChanged = 'SBcc';
|
||||||
|
|
||||||
const uint32 kMoveFilesToTrashChanged = 'STdm';
|
const uint32 kDontMoveFilesToTrashChanged = 'STdm';
|
||||||
const uint32 kAskBeforeDeleteFileChanged = 'STad';
|
const uint32 kAskBeforeDeleteFileChanged = 'STad';
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -604,7 +604,7 @@ BContainerWindow::BContainerWindow(LockingList<BWindow>* list,
|
|||||||
app->StartWatching(this, kWindowsShowFullPathChanged);
|
app->StartWatching(this, kWindowsShowFullPathChanged);
|
||||||
app->StartWatching(this, kSingleWindowBrowseChanged);
|
app->StartWatching(this, kSingleWindowBrowseChanged);
|
||||||
app->StartWatching(this, kShowNavigatorChanged);
|
app->StartWatching(this, kShowNavigatorChanged);
|
||||||
app->StartWatching(this, kMoveFilesToTrashChanged);
|
app->StartWatching(this, kDontMoveFilesToTrashChanged);
|
||||||
app->Unlock();
|
app->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,7 +625,7 @@ BContainerWindow::~BContainerWindow()
|
|||||||
app->StopWatching(this, kWindowsShowFullPathChanged);
|
app->StopWatching(this, kWindowsShowFullPathChanged);
|
||||||
app->StopWatching(this, kSingleWindowBrowseChanged);
|
app->StopWatching(this, kSingleWindowBrowseChanged);
|
||||||
app->StopWatching(this, kShowNavigatorChanged);
|
app->StopWatching(this, kShowNavigatorChanged);
|
||||||
app->StopWatching(this, kMoveFilesToTrashChanged);
|
app->StopWatching(this, kDontMoveFilesToTrashChanged);
|
||||||
app->Unlock();
|
app->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1687,10 +1687,10 @@ BContainerWindow::MessageReceived(BMessage* message)
|
|||||||
settings.SingleWindowBrowse());
|
settings.SingleWindowBrowse());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMoveFilesToTrashChanged:
|
case kDontMoveFilesToTrashChanged:
|
||||||
{
|
{
|
||||||
bool dontMoveToTrash
|
bool dontMoveToTrash
|
||||||
= settings.MoveFilesToTrash();
|
= settings.DontMoveFilesToTrash();
|
||||||
|
|
||||||
BMenuItem* item
|
BMenuItem* item
|
||||||
= fFileContextMenu->FindItem(kMoveToTrash);
|
= fFileContextMenu->FindItem(kMoveToTrash);
|
||||||
@@ -1934,8 +1934,8 @@ BContainerWindow::AddFileMenu(BMenu* menu)
|
|||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Duplicate"),
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Duplicate"),
|
||||||
new BMessage(kDuplicateSelection), 'D'));
|
new BMessage(kDuplicateSelection), 'D'));
|
||||||
|
|
||||||
menu->AddItem(new BMenuItem(TrackerSettings().MoveFilesToTrash()
|
menu->AddItem(new BMenuItem(TrackerSettings().DontMoveFilesToTrash()
|
||||||
? B_TRANSLATE("Move to Trash") : B_TRANSLATE("Delete"),
|
? B_TRANSLATE("Delete") : B_TRANSLATE("Move to Trash"),
|
||||||
new BMessage(kMoveToTrash), 'T'));
|
new BMessage(kMoveToTrash), 'T'));
|
||||||
|
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
@@ -2758,8 +2758,8 @@ BContainerWindow::AddFileContextMenus(BMenu* menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!IsTrash() && !InTrash()) {
|
if (!IsTrash() && !InTrash()) {
|
||||||
menu->AddItem(new BMenuItem(TrackerSettings().MoveFilesToTrash()
|
menu->AddItem(new BMenuItem(TrackerSettings().DontMoveFilesToTrash()
|
||||||
? B_TRANSLATE("Move to Trash") : B_TRANSLATE("Delete"),
|
? B_TRANSLATE("Delete") : B_TRANSLATE("Move to Trash"),
|
||||||
new BMessage(kMoveToTrash), 'T'));
|
new BMessage(kMoveToTrash), 'T'));
|
||||||
|
|
||||||
// add separator for copy to/move to items (navigation items)
|
// add separator for copy to/move to items (navigation items)
|
||||||
|
|||||||
@@ -2842,9 +2842,9 @@ status_t
|
|||||||
_DeleteTask(BObjectList<entry_ref>* list, bool confirm)
|
_DeleteTask(BObjectList<entry_ref>* list, bool confirm)
|
||||||
{
|
{
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
bool MoveToTrash = TrackerSettings().MoveFilesToTrash();
|
bool dontMoveToTrash = TrackerSettings().DontMoveFilesToTrash();
|
||||||
|
|
||||||
if (MoveToTrash) {
|
if (!dontMoveToTrash) {
|
||||||
BAlert* alert = new BAlert("",
|
BAlert* alert = new BAlert("",
|
||||||
B_TRANSLATE_NOCOLLECT(kDeleteConfirmationStr),
|
B_TRANSLATE_NOCOLLECT(kDeleteConfirmationStr),
|
||||||
B_TRANSLATE("Cancel"), B_TRANSLATE("Move to Trash"),
|
B_TRANSLATE("Cancel"), B_TRANSLATE("Move to Trash"),
|
||||||
|
|||||||
@@ -885,9 +885,9 @@ TFilePanel::AddFileContextMenus(BMenu* menu)
|
|||||||
new BMessage(kGetInfo), 'I'));
|
new BMessage(kGetInfo), 'I'));
|
||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
|
||||||
new BMessage(kEditItem), 'E'));
|
new BMessage(kEditItem), 'E'));
|
||||||
menu->AddItem(new BMenuItem(TrackerSettings().MoveFilesToTrash()
|
menu->AddItem(new BMenuItem(TrackerSettings().DontMoveFilesToTrash()
|
||||||
? B_TRANSLATE("Move to Trash")
|
? B_TRANSLATE("Delete")
|
||||||
: B_TRANSLATE("Delete"),
|
: B_TRANSLATE("Move to Trash"),
|
||||||
new BMessage(kMoveToTrash), 'T'));
|
new BMessage(kMoveToTrash), 'T'));
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
menu->AddItem(new BMenuItem(B_TRANSLATE("Cut"),
|
menu->AddItem(new BMenuItem(B_TRANSLATE("Cut"),
|
||||||
|
|||||||
@@ -2323,7 +2323,7 @@ BPoseView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
TrackerSettings settings;
|
TrackerSettings settings;
|
||||||
|
|
||||||
if ((modifiers() & B_SHIFT_KEY) != 0 || !settings.MoveFilesToTrash())
|
if ((modifiers() & B_SHIFT_KEY) != 0 || settings.DontMoveFilesToTrash())
|
||||||
DeleteSelection(true, settings.AskBeforeDeleteFile());
|
DeleteSelection(true, settings.AskBeforeDeleteFile());
|
||||||
else
|
else
|
||||||
MoveSelectionToTrash();
|
MoveSelectionToTrash();
|
||||||
@@ -6461,7 +6461,7 @@ BPoseView::KeyDown(const char* bytes, int32 count)
|
|||||||
} else {
|
} else {
|
||||||
TrackerSettings settings;
|
TrackerSettings settings;
|
||||||
|
|
||||||
if ((modifiers() & B_SHIFT_KEY) != 0 || !settings.MoveFilesToTrash())
|
if ((modifiers() & B_SHIFT_KEY) != 0 || settings.DontMoveFilesToTrash())
|
||||||
DeleteSelection(true, settings.AskBeforeDeleteFile());
|
DeleteSelection(true, settings.AskBeforeDeleteFile());
|
||||||
else
|
else
|
||||||
MoveSelectionToTrash();
|
MoveSelectionToTrash();
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ BPoseView::DeleteProperty(BMessage* _SCRIPTING_ONLY(specifier),
|
|||||||
|
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
TrackerSettings settings;
|
TrackerSettings settings;
|
||||||
if (settings.MoveFilesToTrash()) {
|
if (!settings.DontMoveFilesToTrash()) {
|
||||||
// move the list we build into trash, don't make the
|
// move the list we build into trash, don't make the
|
||||||
// trashing task select the next item
|
// trashing task select the next item
|
||||||
MoveListToTrash(entryList, false, false);
|
MoveListToTrash(entryList, false, false);
|
||||||
|
|||||||
@@ -947,151 +947,3 @@ SpaceBarSettingsView::IsRevertable() const
|
|||||||
|| fFreeSpaceColor != settings.FreeSpaceColor()
|
|| fFreeSpaceColor != settings.FreeSpaceColor()
|
||||||
|| fWarningSpaceColor != settings.WarningSpaceColor();
|
|| fWarningSpaceColor != settings.WarningSpaceColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
TrashSettingsView::TrashSettingsView()
|
|
||||||
:
|
|
||||||
SettingsView("TrashSettingsView")
|
|
||||||
{
|
|
||||||
fMoveFilesToTrashCheckBox = new BCheckBox("",
|
|
||||||
B_TRANSLATE("Move deleted files to Trash first"),
|
|
||||||
new BMessage(kMoveFilesToTrashChanged));
|
|
||||||
|
|
||||||
fAskBeforeDeleteFileCheckBox = new BCheckBox("",
|
|
||||||
B_TRANSLATE("Ask before deleting for good"),
|
|
||||||
new BMessage(kAskBeforeDeleteFileChanged));
|
|
||||||
|
|
||||||
const float spacing = be_control_look->DefaultItemSpacing();
|
|
||||||
|
|
||||||
BGroupLayout* layout = GroupLayout();
|
|
||||||
layout->SetOrientation(B_VERTICAL);
|
|
||||||
layout->SetSpacing(0);
|
|
||||||
BGroupLayoutBuilder(layout)
|
|
||||||
.Add(fMoveFilesToTrashCheckBox)
|
|
||||||
.Add(fAskBeforeDeleteFileCheckBox)
|
|
||||||
.AddGlue()
|
|
||||||
.SetInsets(spacing, spacing, spacing, spacing);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::AttachedToWindow()
|
|
||||||
{
|
|
||||||
fMoveFilesToTrashCheckBox->SetTarget(this);
|
|
||||||
fAskBeforeDeleteFileCheckBox->SetTarget(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::MessageReceived(BMessage* message)
|
|
||||||
{
|
|
||||||
TTracker* tracker = dynamic_cast<TTracker*>(be_app);
|
|
||||||
if (!tracker)
|
|
||||||
return;
|
|
||||||
TrackerSettings settings;
|
|
||||||
|
|
||||||
switch (message->what) {
|
|
||||||
case kMoveFilesToTrashChanged:
|
|
||||||
settings.SetMoveFilesToTrash(
|
|
||||||
fMoveFilesToTrashCheckBox->Value() == 1);
|
|
||||||
|
|
||||||
tracker->SendNotices(kMoveFilesToTrashChanged);
|
|
||||||
Window()->PostMessage(kSettingsContentsModified);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kAskBeforeDeleteFileChanged:
|
|
||||||
settings.SetAskBeforeDeleteFile(
|
|
||||||
fAskBeforeDeleteFileCheckBox->Value() == 1);
|
|
||||||
|
|
||||||
tracker->SendNotices(kAskBeforeDeleteFileChanged);
|
|
||||||
Window()->PostMessage(kSettingsContentsModified);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
_inherited::MessageReceived(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::SetDefaults()
|
|
||||||
{
|
|
||||||
TrackerSettings settings;
|
|
||||||
|
|
||||||
settings.SetMoveFilesToTrash(true);
|
|
||||||
settings.SetAskBeforeDeleteFile(true);
|
|
||||||
|
|
||||||
ShowCurrentSettings();
|
|
||||||
_SendNotices();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
TrashSettingsView::IsDefaultable() const
|
|
||||||
{
|
|
||||||
TrackerSettings settings;
|
|
||||||
|
|
||||||
return settings.MoveFilesToTrash() != true
|
|
||||||
|| settings.AskBeforeDeleteFile() != true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::Revert()
|
|
||||||
{
|
|
||||||
TrackerSettings settings;
|
|
||||||
|
|
||||||
settings.SetMoveFilesToTrash(fMoveFilesToTrash);
|
|
||||||
settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFile);
|
|
||||||
|
|
||||||
ShowCurrentSettings();
|
|
||||||
_SendNotices();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::_SendNotices()
|
|
||||||
{
|
|
||||||
TTracker* tracker = dynamic_cast<TTracker*>(be_app);
|
|
||||||
if (!tracker)
|
|
||||||
return;
|
|
||||||
|
|
||||||
tracker->SendNotices(kMoveFilesToTrashChanged);
|
|
||||||
tracker->SendNotices(kAskBeforeDeleteFileChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::ShowCurrentSettings()
|
|
||||||
{
|
|
||||||
TrackerSettings settings;
|
|
||||||
|
|
||||||
fMoveFilesToTrashCheckBox->SetValue(settings.MoveFilesToTrash());
|
|
||||||
fAskBeforeDeleteFileCheckBox->SetValue(settings.AskBeforeDeleteFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
TrashSettingsView::RecordRevertSettings()
|
|
||||||
{
|
|
||||||
TrackerSettings settings;
|
|
||||||
|
|
||||||
fMoveFilesToTrash = settings.MoveFilesToTrash();
|
|
||||||
fAskBeforeDeleteFile = settings.AskBeforeDeleteFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
TrashSettingsView::IsRevertable() const
|
|
||||||
{
|
|
||||||
return fMoveFilesToTrash
|
|
||||||
!= (fMoveFilesToTrashCheckBox->Value() > 0)
|
|
||||||
|| fAskBeforeDeleteFile
|
|
||||||
!= (fAskBeforeDeleteFileCheckBox->Value() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,33 +163,6 @@ class SpaceBarSettingsView : public SettingsView {
|
|||||||
typedef SettingsView _inherited;
|
typedef SettingsView _inherited;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class TrashSettingsView : public SettingsView {
|
|
||||||
public:
|
|
||||||
TrashSettingsView();
|
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
|
||||||
virtual void AttachedToWindow();
|
|
||||||
|
|
||||||
virtual void SetDefaults();
|
|
||||||
virtual bool IsDefaultable() const;
|
|
||||||
virtual void Revert();
|
|
||||||
virtual void ShowCurrentSettings();
|
|
||||||
virtual void RecordRevertSettings();
|
|
||||||
virtual bool IsRevertable() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void _SendNotices();
|
|
||||||
|
|
||||||
BCheckBox* fMoveFilesToTrashCheckBox;
|
|
||||||
BCheckBox* fAskBeforeDeleteFileCheckBox;
|
|
||||||
|
|
||||||
bool fMoveFilesToTrash;
|
|
||||||
bool fAskBeforeDeleteFile;
|
|
||||||
|
|
||||||
typedef SettingsView _inherited;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class TTrackerState : public Settings {
|
|||||||
HexScalarValueSetting* fFreeSpaceColor;
|
HexScalarValueSetting* fFreeSpaceColor;
|
||||||
HexScalarValueSetting* fWarningSpaceColor;
|
HexScalarValueSetting* fWarningSpaceColor;
|
||||||
|
|
||||||
BooleanValueSetting* fMoveFilesToTrash;
|
BooleanValueSetting* fDontMoveFilesToTrash;
|
||||||
BooleanValueSetting* fAskBeforeDeleteFile;
|
BooleanValueSetting* fAskBeforeDeleteFile;
|
||||||
|
|
||||||
Benaphore fInitLock;
|
Benaphore fInitLock;
|
||||||
@@ -202,8 +202,8 @@ TTrackerState::LoadSettingsIfNeeded()
|
|||||||
Add(fWarningSpaceColor
|
Add(fWarningSpaceColor
|
||||||
= new HexScalarValueSetting("WarningSpaceColor", 0xc0cb0000, "", ""));
|
= new HexScalarValueSetting("WarningSpaceColor", 0xc0cb0000, "", ""));
|
||||||
|
|
||||||
Add(fMoveFilesToTrash
|
Add(fDontMoveFilesToTrash
|
||||||
= new BooleanValueSetting("MoveFilesToTrash", true));
|
= new BooleanValueSetting("DontMoveFilesToTrash", false));
|
||||||
Add(fAskBeforeDeleteFile
|
Add(fAskBeforeDeleteFile
|
||||||
= new BooleanValueSetting("AskBeforeDeleteFile", true));
|
= new BooleanValueSetting("AskBeforeDeleteFile", true));
|
||||||
|
|
||||||
@@ -509,16 +509,16 @@ TrackerSettings::SetRecentFoldersCount(int32 count)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TrackerSettings::MoveFilesToTrash()
|
TrackerSettings::DontMoveFilesToTrash()
|
||||||
{
|
{
|
||||||
return gTrackerState.fMoveFilesToTrash->Value();
|
return gTrackerState.fDontMoveFilesToTrash->Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TrackerSettings::SetMoveFilesToTrash(bool enabled)
|
TrackerSettings::SetDontMoveFilesToTrash(bool enabled)
|
||||||
{
|
{
|
||||||
gTrackerState.fMoveFilesToTrash->SetValue(enabled);
|
gTrackerState.fDontMoveFilesToTrash->SetValue(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ class TrackerSettings {
|
|||||||
bool ClockIs24Hr();
|
bool ClockIs24Hr();
|
||||||
void SetClockTo24Hr(bool);
|
void SetClockTo24Hr(bool);
|
||||||
|
|
||||||
bool MoveFilesToTrash();
|
bool DontMoveFilesToTrash();
|
||||||
void SetMoveFilesToTrash(bool);
|
void SetDontMoveFilesToTrash(bool);
|
||||||
bool AskBeforeDeleteFile();
|
bool AskBeforeDeleteFile();
|
||||||
void SetAskBeforeDeleteFile(bool);
|
void SetAskBeforeDeleteFile(bool);
|
||||||
|
|
||||||
|
|||||||
@@ -114,8 +114,6 @@ TrackerSettingsWindow::TrackerSettingsWindow()
|
|||||||
new DesktopSettingsView()));
|
new DesktopSettingsView()));
|
||||||
fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Windows"),
|
fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Windows"),
|
||||||
new WindowsSettingsView()));
|
new WindowsSettingsView()));
|
||||||
fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Trash"),
|
|
||||||
new TrashSettingsView()));
|
|
||||||
fSettingsTypeListView->AddItem(new SettingsItem(
|
fSettingsTypeListView->AddItem(new SettingsItem(
|
||||||
B_TRANSLATE("Volume icons"), new SpaceBarSettingsView()));
|
B_TRANSLATE("Volume icons"), new SpaceBarSettingsView()));
|
||||||
|
|
||||||
|
|||||||
@@ -20,58 +20,81 @@ using std::cout;
|
|||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
const char* cookieString;
|
const char* cookieString;
|
||||||
|
const char* url;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
bool valid;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* value;
|
const char* value;
|
||||||
const char* domain;
|
const char* domain;
|
||||||
const char* path;
|
const char* path;
|
||||||
bool secure;
|
bool secure;
|
||||||
bool discard;
|
bool httponly;
|
||||||
bool session;
|
bool session;
|
||||||
int32 maxAge;
|
BDateTime expire;
|
||||||
} expected;
|
} expected;
|
||||||
} ExplodeTest;
|
} ExplodeTest;
|
||||||
|
|
||||||
const ExplodeTest kTestExplode[] =
|
|
||||||
// Cookie string
|
ExplodeTest kTestExplode[] =
|
||||||
// Name Value Domain Path Secure Discard Session maxAge
|
// Cookie string URL
|
||||||
// -------- --------- --------- --------- ------ ------- -------- -------
|
// ------------- -------------
|
||||||
|
// Valid Name Value Domain Path Secure HttpOnly Session Expiration
|
||||||
|
// --------- -------- --------- ----------------- --------- -------- -------- ------- ----------
|
||||||
{
|
{
|
||||||
{ "name=value",
|
// Normal cookies
|
||||||
{ "name", "value", "", "", false, false, true, 0 } },
|
{ "name=value", "http://www.example.com/path/path",
|
||||||
{ "name=value;secure=true",
|
{ true, "name", "value", "www.example.com", "/path", false, false, true, BDateTime() } },
|
||||||
{ "name", "value", "", "", true, false, true, 0 } },
|
{ "name=value; domain=example.com; path=/; secure", "http://www.example.com/path/path",
|
||||||
{ "name=value;secure=false;maxage=5",
|
{ true, "name", "value", "example.com", "/" , true, false, true, BDateTime() } },
|
||||||
{ "name", "value", "", "", false, false, false, 5 } },
|
{ "name=value; httponly; secure", "http://www.example.com/path/path",
|
||||||
{ "name=value;discard=true",
|
{ true, "name", "value", "www.example.com", "/path", true, true, true, BDateTime() } },
|
||||||
{ "name", "value", "", "", false, true, true, 0 } },
|
{ "name=value; expires=Wed, 20 Feb 2013 20:00:00 UTC", "http://www.example.com/path/path",
|
||||||
|
{ true, "name", "value", "www.example.com", "/path", false, false, false,
|
||||||
|
BDateTime(BDate(2012, 2, 20), BTime(20, 0, 0, 0)) } },
|
||||||
|
// Valid cookie with bad form
|
||||||
|
{ "name= ; domain =example.com ;path=/; secure = yup ; blahblah ;)", "http://www.example.com/path/path",
|
||||||
|
{ true, "name", "", "example.com", "/" , true, false, true, BDateTime() } },
|
||||||
|
// Invalid path, default path should be used instead
|
||||||
|
{ "name=value; path=invalid", "http://www.example.com/path/path",
|
||||||
|
{ true, "name", "value", "www.example.com", "/path", false, false, true, BDateTime() } },
|
||||||
|
// Setting for other subdomain (invalid)
|
||||||
|
{ "name=value; domain=subdomain.example.com", "http://www.example.com/path/path",
|
||||||
|
{ false, "name", "value", "www.example.com", "/path", false, false, true, BDateTime() } },
|
||||||
|
// Various invalid cookies
|
||||||
|
{ "name", "http://www.example.com/path/path",
|
||||||
|
{ false, "name", "value", "www.example.com", "/path", false, false, true, BDateTime() } },
|
||||||
|
{ "; domain=example.com", "http://www.example.com/path/path",
|
||||||
|
{ false, "name", "value", "www.example.com", "/path", false, false, true, BDateTime() } }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void explodeImplodeTest()
|
void explodeImplodeTest()
|
||||||
{
|
{
|
||||||
uint8 testIndex;
|
uint32 testIndex;
|
||||||
BNetworkCookie cookie;
|
BNetworkCookie cookie;
|
||||||
|
|
||||||
for (testIndex = 0; testIndex < (sizeof(kTestExplode) / sizeof(ExplodeTest)); testIndex++)
|
for (testIndex = 0; testIndex < (sizeof(kTestExplode) / sizeof(ExplodeTest)); testIndex++)
|
||||||
{
|
{
|
||||||
cookie.ParseCookieString(kTestExplode[testIndex].cookieString);
|
BUrl url(kTestExplode[testIndex].url);
|
||||||
|
cookie.ParseCookieStringFromUrl(kTestExplode[testIndex].cookieString, url);
|
||||||
|
|
||||||
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.name) == BString(cookie.Name()));
|
ASSERT(testIndex, kTestExplode[testIndex].expected.valid == cookie.IsValid());
|
||||||
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.value) == BString(cookie.Value()));
|
|
||||||
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.domain) == BString(cookie.Domain()));
|
|
||||||
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.path) == BString(cookie.Path()));
|
|
||||||
ASSERT(testIndex, kTestExplode[testIndex].expected.secure == cookie.Secure());
|
|
||||||
ASSERT(testIndex, kTestExplode[testIndex].expected.discard == cookie.Discard());
|
|
||||||
ASSERT(testIndex, kTestExplode[testIndex].expected.session == cookie.IsSessionCookie());
|
|
||||||
|
|
||||||
if (!cookie.IsSessionCookie())
|
if (kTestExplode[testIndex].expected.valid) {
|
||||||
ASSERT(testIndex, kTestExplode[testIndex].expected.maxAge == cookie.MaxAge());
|
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.name) == cookie.Name());
|
||||||
|
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.value) == cookie.Value());
|
||||||
|
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.domain) == cookie.Domain());
|
||||||
|
ASSERT(testIndex, BString(kTestExplode[testIndex].expected.path) == cookie.Path());
|
||||||
|
ASSERT(testIndex, kTestExplode[testIndex].expected.secure == cookie.Secure());
|
||||||
|
ASSERT(testIndex, kTestExplode[testIndex].expected.httponly == cookie.HttpOnly());
|
||||||
|
ASSERT(testIndex, kTestExplode[testIndex].expected.session == cookie.IsSessionCookie());
|
||||||
|
|
||||||
|
if (!cookie.IsSessionCookie())
|
||||||
|
ASSERT(testIndex, kTestExplode[testIndex].expected.expire.Time_t() == cookie.ExpirationDate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,27 +102,27 @@ void explodeImplodeTest()
|
|||||||
void stressTest(int32 domainNumber, int32 totalCookies, char** flat, ssize_t* size)
|
void stressTest(int32 domainNumber, int32 totalCookies, char** flat, ssize_t* size)
|
||||||
{
|
{
|
||||||
char **domains = new char*[domainNumber];
|
char **domains = new char*[domainNumber];
|
||||||
|
|
||||||
cout << "Creating random domains" << endl;
|
cout << "Creating random domains" << endl;
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
for (int32 i = 0; i < domainNumber; i++) {
|
for (int32 i = 0; i < domainNumber; i++) {
|
||||||
int16 charNum = (rand() % 16) + 1;
|
int16 charNum = (rand() % 16) + 1;
|
||||||
|
|
||||||
domains[i] = new char[charNum + 5];
|
domains[i] = new char[charNum + 5];
|
||||||
|
|
||||||
// Random domain
|
// Random domain
|
||||||
for (int32 c = 0; c < charNum; c++)
|
for (int32 c = 0; c < charNum; c++)
|
||||||
domains[i][c] = (rand() % 26) + 'a';
|
domains[i][c] = (rand() % 26) + 'a';
|
||||||
|
|
||||||
domains[i][charNum] = '.';
|
domains[i][charNum] = '.';
|
||||||
|
|
||||||
// Random tld
|
// Random tld
|
||||||
for (int32 c = 0; c < 3; c++)
|
for (int32 c = 0; c < 3; c++)
|
||||||
domains[i][charNum+1+c] = (rand() % 26) + 'a';
|
domains[i][charNum+1+c] = (rand() % 26) + 'a';
|
||||||
|
|
||||||
domains[i][charNum+4] = 0;
|
domains[i][charNum+4] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BNetworkCookieJar j;
|
BNetworkCookieJar j;
|
||||||
BStopWatch* watch = new BStopWatch("Cookie insertion");
|
BStopWatch* watch = new BStopWatch("Cookie insertion");
|
||||||
for (int32 i = 0; i < totalCookies; i++) {
|
for (int32 i = 0; i < totalCookies; i++) {
|
||||||
@@ -107,21 +130,21 @@ void stressTest(int32 domainNumber, int32 totalCookies, char** flat, ssize_t* si
|
|||||||
int16 domain = (rand() % domainNumber);
|
int16 domain = (rand() % domainNumber);
|
||||||
BString name("Foo");
|
BString name("Foo");
|
||||||
name << i;
|
name << i;
|
||||||
|
|
||||||
c.SetName(name);
|
c.SetName(name);
|
||||||
c.SetValue("Bar");
|
c.SetValue("Bar");
|
||||||
c.SetDomain(domains[domain]);
|
c.SetDomain(domains[domain]);
|
||||||
c.SetPath("/");
|
c.SetPath("/");
|
||||||
|
|
||||||
j.AddCookie(c);
|
j.AddCookie(c);
|
||||||
}
|
}
|
||||||
delete watch;
|
delete watch;
|
||||||
|
|
||||||
BNetworkCookie* c;
|
BNetworkCookie* c;
|
||||||
int16 domain = (rand() % domainNumber);
|
int16 domain = (rand() % domainNumber);
|
||||||
BString host("http://");
|
BString host("http://");
|
||||||
host << domains[domain] << "/";
|
host << domains[domain] << "/";
|
||||||
|
|
||||||
watch = new BStopWatch("Cookie filtering");
|
watch = new BStopWatch("Cookie filtering");
|
||||||
BUrl url(host);
|
BUrl url(host);
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
@@ -131,17 +154,17 @@ void stressTest(int32 domainNumber, int32 totalCookies, char** flat, ssize_t* si
|
|||||||
}
|
}
|
||||||
delete watch;
|
delete watch;
|
||||||
cout << "Count for " << host << ": " << count << endl;
|
cout << "Count for " << host << ": " << count << endl;
|
||||||
|
|
||||||
|
|
||||||
cout << "Flat view of cookie jar is " << j.FlattenedSize() << " bytes large." << endl;
|
cout << "Flat view of cookie jar is " << j.FlattenedSize() << " bytes large." << endl;
|
||||||
*flat = new char[j.FlattenedSize()];
|
*flat = new char[j.FlattenedSize()];
|
||||||
*size = j.FlattenedSize();
|
*size = j.FlattenedSize();
|
||||||
|
|
||||||
if (j.Flatten(*flat, j.FlattenedSize()) == B_OK)
|
if (j.Flatten(*flat, j.FlattenedSize()) == B_OK)
|
||||||
cout << "Flatten() success!" << endl;
|
cout << "Flatten() success!" << endl;
|
||||||
else
|
else
|
||||||
cout << "Flatten() error!" << endl;
|
cout << "Flatten() error!" << endl;
|
||||||
|
|
||||||
delete[] domains;
|
delete[] domains;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,22 +175,22 @@ main(int, char**)
|
|||||||
cout << "Running explodeImplodeTest:" << endl;
|
cout << "Running explodeImplodeTest:" << endl;
|
||||||
explodeImplodeTest();
|
explodeImplodeTest();
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
|
|
||||||
cout << "Running stressTest:" << endl;
|
cout << "Running stressTest:" << endl;
|
||||||
char* flatJar;
|
char* flatJar;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
stressTest(10000, 40000, &flatJar, &size);
|
stressTest(10000, 40000, &flatJar, &size);
|
||||||
|
|
||||||
BNetworkCookieJar j;
|
BNetworkCookieJar j;
|
||||||
j.Unflatten(B_ANY_TYPE, flatJar, size);
|
j.Unflatten(B_ANY_TYPE, flatJar, size);
|
||||||
|
|
||||||
int32 count = 0;
|
int32 count = 0;
|
||||||
BNetworkCookie* c;
|
BNetworkCookie* c;
|
||||||
for (BNetworkCookieJar::Iterator it(j.GetIterator()); (c = it.Next()); )
|
for (BNetworkCookieJar::Iterator it(j.GetIterator()); (c = it.Next()); )
|
||||||
count++;
|
count++;
|
||||||
cout << "Count : " << count << endl;
|
cout << "Count : " << count << endl;
|
||||||
|
|
||||||
delete[] flatJar;
|
delete[] flatJar;
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user