| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_COOKIES_PARSED_COOKIE_H_ | 5 #ifndef NET_COOKIES_PARSED_COOKIE_H_ |
| 6 #define NET_COOKIES_PARSED_COOKIE_H_ | 6 #define NET_COOKIES_PARSED_COOKIE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/cookies/cookie_constants.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 class NET_EXPORT ParsedCookie { | 17 class NET_EXPORT ParsedCookie { |
| 17 public: | 18 public: |
| 18 typedef std::pair<std::string, std::string> TokenValuePair; | 19 typedef std::pair<std::string, std::string> TokenValuePair; |
| 19 typedef std::vector<TokenValuePair> PairList; | 20 typedef std::vector<TokenValuePair> PairList; |
| 20 | 21 |
| 21 // The maximum length of a cookie string we will try to parse | 22 // The maximum length of a cookie string we will try to parse |
| 22 static const size_t kMaxCookieSize = 4096; | 23 static const size_t kMaxCookieSize = 4096; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 bool HasPath() const { return path_index_ != 0; } | 39 bool HasPath() const { return path_index_ != 0; } |
| 39 const std::string& Path() const { return pairs_[path_index_].second; } | 40 const std::string& Path() const { return pairs_[path_index_].second; } |
| 40 bool HasDomain() const { return domain_index_ != 0; } | 41 bool HasDomain() const { return domain_index_ != 0; } |
| 41 const std::string& Domain() const { return pairs_[domain_index_].second; } | 42 const std::string& Domain() const { return pairs_[domain_index_].second; } |
| 42 bool HasExpires() const { return expires_index_ != 0; } | 43 bool HasExpires() const { return expires_index_ != 0; } |
| 43 const std::string& Expires() const { return pairs_[expires_index_].second; } | 44 const std::string& Expires() const { return pairs_[expires_index_].second; } |
| 44 bool HasMaxAge() const { return maxage_index_ != 0; } | 45 bool HasMaxAge() const { return maxage_index_ != 0; } |
| 45 const std::string& MaxAge() const { return pairs_[maxage_index_].second; } | 46 const std::string& MaxAge() const { return pairs_[maxage_index_].second; } |
| 46 bool IsSecure() const { return secure_index_ != 0; } | 47 bool IsSecure() const { return secure_index_ != 0; } |
| 47 bool IsHttpOnly() const { return httponly_index_ != 0; } | 48 bool IsHttpOnly() const { return httponly_index_ != 0; } |
| 49 CookiePriority Priority() const; |
| 48 | 50 |
| 49 // Returns the number of attributes, for example, returning 2 for: | 51 // Returns the number of attributes, for example, returning 2 for: |
| 50 // "BLAH=hah; path=/; domain=.google.com" | 52 // "BLAH=hah; path=/; domain=.google.com" |
| 51 size_t NumberOfAttributes() const { return pairs_.size() - 1; } | 53 size_t NumberOfAttributes() const { return pairs_.size() - 1; } |
| 52 | 54 |
| 53 // These functions set the respective properties of the cookie. If the | 55 // These functions set the respective properties of the cookie. If the |
| 54 // parameters are empty, the respective properties are cleared. | 56 // parameters are empty, the respective properties are cleared. |
| 55 // The functions return false in case an error occurred. | 57 // The functions return false in case an error occurred. |
| 56 // The cookie needs to be assigned a name/value before setting the other | 58 // The cookie needs to be assigned a name/value before setting the other |
| 57 // attributes. | 59 // attributes. |
| 58 bool SetName(const std::string& name); | 60 bool SetName(const std::string& name); |
| 59 bool SetValue(const std::string& value); | 61 bool SetValue(const std::string& value); |
| 60 bool SetPath(const std::string& path); | 62 bool SetPath(const std::string& path); |
| 61 bool SetDomain(const std::string& domain); | 63 bool SetDomain(const std::string& domain); |
| 62 bool SetExpires(const std::string& expires); | 64 bool SetExpires(const std::string& expires); |
| 63 bool SetMaxAge(const std::string& maxage); | 65 bool SetMaxAge(const std::string& maxage); |
| 64 bool SetIsSecure(bool is_secure); | 66 bool SetIsSecure(bool is_secure); |
| 65 bool SetIsHttpOnly(bool is_http_only); | 67 bool SetIsHttpOnly(bool is_http_only); |
| 68 bool SetPriority(const std::string& priority); |
| 66 | 69 |
| 67 // Returns the cookie description as it appears in a HTML response header. | 70 // Returns the cookie description as it appears in a HTML response header. |
| 68 std::string ToCookieLine() const; | 71 std::string ToCookieLine() const; |
| 69 | 72 |
| 70 // Returns an iterator pointing to the first terminator character found in | 73 // Returns an iterator pointing to the first terminator character found in |
| 71 // the given string. | 74 // the given string. |
| 72 static std::string::const_iterator FindFirstTerminator(const std::string& s); | 75 static std::string::const_iterator FindFirstTerminator(const std::string& s); |
| 73 | 76 |
| 74 // Given iterators pointing to the beginning and end of a string segment, | 77 // Given iterators pointing to the beginning and end of a string segment, |
| 75 // returns as output arguments token_start and token_end to the start and end | 78 // returns as output arguments token_start and token_end to the start and end |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // These will default to 0, but that should never be valid since the | 130 // These will default to 0, but that should never be valid since the |
| 128 // 0th index is the user supplied token/value, not an attribute. | 131 // 0th index is the user supplied token/value, not an attribute. |
| 129 // We're really never going to have more than like 8 attributes, so we | 132 // We're really never going to have more than like 8 attributes, so we |
| 130 // could fit these into 3 bits each if we're worried about size... | 133 // could fit these into 3 bits each if we're worried about size... |
| 131 size_t path_index_; | 134 size_t path_index_; |
| 132 size_t domain_index_; | 135 size_t domain_index_; |
| 133 size_t expires_index_; | 136 size_t expires_index_; |
| 134 size_t maxage_index_; | 137 size_t maxage_index_; |
| 135 size_t secure_index_; | 138 size_t secure_index_; |
| 136 size_t httponly_index_; | 139 size_t httponly_index_; |
| 140 size_t priority_index_; |
| 137 | 141 |
| 138 DISALLOW_COPY_AND_ASSIGN(ParsedCookie); | 142 DISALLOW_COPY_AND_ASSIGN(ParsedCookie); |
| 139 }; | 143 }; |
| 140 | 144 |
| 141 } // namespace net | 145 } // namespace net |
| 142 | 146 |
| 143 #endif // NET_COOKIES_COOKIE_MONSTER_H_ | 147 #endif // NET_COOKIES_COOKIE_MONSTER_H_ |
| OLD | NEW |