2 * Copyright 2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _B_NETWORK_COOKIE_H_
6 #define _B_NETWORK_COOKIE_H_
9 #include <Archivable.h>
16 class BNetworkCookie
: public BArchivable
{
18 BNetworkCookie(const char* name
,
19 const char* value
, const BUrl
& url
);
20 BNetworkCookie(const BString
& cookieString
,
22 BNetworkCookie(BMessage
* archive
);
24 virtual ~BNetworkCookie();
26 // Parse a "SetCookie" string
28 status_t
ParseCookieString(const BString
& string
,
31 // Modify the cookie fields
32 BNetworkCookie
& SetName(const BString
& name
);
33 BNetworkCookie
& SetValue(const BString
& value
);
34 status_t
SetDomain(const BString
& domain
);
35 status_t
SetPath(const BString
& path
);
36 BNetworkCookie
& SetMaxAge(int32 maxAge
);
37 BNetworkCookie
& SetExpirationDate(time_t expireDate
);
38 BNetworkCookie
& SetExpirationDate(BDateTime
& expireDate
);
39 BNetworkCookie
& SetSecure(bool secure
);
40 BNetworkCookie
& SetHttpOnly(bool httpOnly
);
42 // Access the cookie fields
43 const BString
& Name() const;
44 const BString
& Value() const;
45 const BString
& Domain() const;
46 const BString
& Path() const;
47 time_t ExpirationDate() const;
48 const BString
& ExpirationString() const;
50 bool HttpOnly() const;
51 const BString
& RawCookie(bool full
) const;
53 bool IsHostOnly() const;
54 bool IsSessionCookie() const;
56 bool IsValidForUrl(const BUrl
& url
) const;
57 bool IsValidForDomain(const BString
& domain
) const;
58 bool IsValidForPath(const BString
& path
) const;
60 // Test if cookie fields are defined
62 bool HasValue() const;
63 bool HasDomain() const;
65 bool HasExpirationDate() const;
67 // Test if cookie could be deleted
68 bool ShouldDeleteAtExit() const;
69 bool ShouldDeleteNow() const;
71 // BArchivable members
72 virtual status_t
Archive(BMessage
* into
,
73 bool deep
= true) const;
74 static BArchivable
* Instantiate(BMessage
* archive
);
76 // Overloaded operators
77 bool operator==(const BNetworkCookie
& other
);
78 bool operator!=(const BNetworkCookie
& other
);
81 int32
_ExtractNameValuePair(const BString
& string
,
82 BString
& name
, BString
& value
,
84 int32
_ExtractAttributeValuePair(
85 const BString
& string
, BString
& name
,
86 BString
& value
, int32 index
);
87 BString
_DefaultPathForUrl(const BUrl
& url
);
89 bool _CanBeSetFromUrl(const BUrl
& url
) const;
90 bool _CanBeSetFromDomain(const BString
& path
) const;
91 bool _CanBeSetFromPath(const BString
& path
) const;
94 mutable BString fRawCookie
;
95 mutable bool fRawCookieValid
;
96 mutable BString fRawFullCookie
;
97 mutable bool fRawFullCookieValid
;
98 mutable BString fExpirationString
;
99 mutable bool fExpirationStringValid
;
105 BDateTime fExpiration
;
106 status_t fInitStatus
;
113 #endif // _B_NETWORK_COOKIE_H_