Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1173)

Side by Side Diff: net/cookies/parsed_cookie.h

Issue 10697035: Add a mutable version of CookieMonster::ParsedCookie (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/cookies/parsed_cookie.cc » ('j') | net/cookies/parsed_cookie.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 const std::string& Expires() const { return pairs_[expires_index_].second; } 48 const std::string& Expires() const { return pairs_[expires_index_].second; }
49 bool HasMaxAge() const { return maxage_index_ != 0; } 49 bool HasMaxAge() const { return maxage_index_ != 0; }
50 const std::string& MaxAge() const { return pairs_[maxage_index_].second; } 50 const std::string& MaxAge() const { return pairs_[maxage_index_].second; }
51 bool IsSecure() const { return secure_index_ != 0; } 51 bool IsSecure() const { return secure_index_ != 0; }
52 bool IsHttpOnly() const { return httponly_index_ != 0; } 52 bool IsHttpOnly() const { return httponly_index_ != 0; }
53 53
54 // Returns the number of attributes, for example, returning 2 for: 54 // Returns the number of attributes, for example, returning 2 for:
55 // "BLAH=hah; path=/; domain=.google.com" 55 // "BLAH=hah; path=/; domain=.google.com"
56 size_t NumberOfAttributes() const { return pairs_.size() - 1; } 56 size_t NumberOfAttributes() const { return pairs_.size() - 1; }
57 57
58 // For debugging only! 58 // These functions set the respective properties of the cookie. If the
59 std::string DebugString() const; 59 // parameters are empty, the respective properties are cleared.
60 // The functions return false in case an error occurred.
61 bool SetName(const std::string& name);
62 bool SetValue(const std::string& value);
63 bool SetPath(const std::string& path);
64 bool SetDomain(const std::string& domain);
65 bool SetMACKey(const std::string& mac_key);
66 bool SetMACAlgorithm(const std::string& mac_algorithm);
67 bool SetExpires(const std::string& expires);
68 bool SetMaxAge(const std::string& maxage);
69 bool SetIsSecure(bool is_secure);
70 bool SetIsHttpOnly(bool is_http_only);
71
72 // Returns the cookie description as it appears in a HTML response header.
73 // ToCookieLine() is the new DebugString();
erikwright (departed) 2012/07/12 15:50:57 Remove the "new DebugString()" note.
battre 2012/07/12 18:03:10 Done.
74 std::string ToCookieLine() const;
60 75
61 // Returns an iterator pointing to the first terminator character found in 76 // Returns an iterator pointing to the first terminator character found in
62 // the given string. 77 // the given string.
63 static std::string::const_iterator FindFirstTerminator(const std::string& s); 78 static std::string::const_iterator FindFirstTerminator(const std::string& s);
64 79
65 // Given iterators pointing to the beginning and end of a string segment, 80 // Given iterators pointing to the beginning and end of a string segment,
66 // returns as output arguments token_start and token_end to the start and end 81 // returns as output arguments token_start and token_end to the start and end
67 // positions of a cookie attribute token name parsed from the segment, and 82 // positions of a cookie attribute token name parsed from the segment, and
68 // updates the segment iterator to point to the next segment to be parsed. 83 // updates the segment iterator to point to the next segment to be parsed.
69 // If no token is found, the function returns false. 84 // If no token is found, the function returns false.
(...skipping 10 matching lines...) Expand all
80 const std::string::const_iterator& end, 95 const std::string::const_iterator& end,
81 std::string::const_iterator* value_start, 96 std::string::const_iterator* value_start,
82 std::string::const_iterator* value_end); 97 std::string::const_iterator* value_end);
83 98
84 // Same as the above functions, except the input is assumed to contain the 99 // Same as the above functions, except the input is assumed to contain the
85 // desired token/value and nothing else. 100 // desired token/value and nothing else.
86 static std::string ParseTokenString(const std::string& token); 101 static std::string ParseTokenString(const std::string& token);
87 static std::string ParseValueString(const std::string& value); 102 static std::string ParseValueString(const std::string& value);
88 103
89 private: 104 private:
90 static const char kTerminator[];
91 static const int kTerminatorLen;
92 static const char kWhitespace[];
93 static const char kValueSeparator[];
94 static const char kTokenSeparator[];
95
96 void ParseTokenValuePairs(const std::string& cookie_line); 105 void ParseTokenValuePairs(const std::string& cookie_line);
97 void SetupAttributes(); 106 void SetupAttributes();
98 107
108 // Sets a key/value pair for a cookie. |index| has to point to one of the
109 // |*_index_| fields in ParsedCookie and is updated to the position where
110 // the key/value pair is set in |pairs_|. Accordingly, |key| has to correspond
111 // to the token matching |index|. If |value| contains invalid characters, the
112 // cookie parameter is not changed and the function returns false.
113 bool SetAttributePair(size_t* index,
114 const std::string& key,
115 const std::string& value);
116
117 // Removes the key/value pair from a cookie that is identified by |index|.
118 // |index| refers to a position in |pairs_|.
119 // Returns false in case an error occurred.
120 bool ClearAttributePair(size_t index);
121
99 PairList pairs_; 122 PairList pairs_;
100 bool is_valid_; 123 bool is_valid_;
101 // These will default to 0, but that should never be valid since the 124 // These will default to 0, but that should never be valid since the
102 // 0th index is the user supplied token/value, not an attribute. 125 // 0th index is the user supplied token/value, not an attribute.
103 // We're really never going to have more than like 8 attributes, so we 126 // We're really never going to have more than like 8 attributes, so we
104 // could fit these into 3 bits each if we're worried about size... 127 // could fit these into 3 bits each if we're worried about size...
105 size_t path_index_; 128 size_t path_index_;
106 size_t domain_index_; 129 size_t domain_index_;
107 size_t mac_key_index_; 130 size_t mac_key_index_;
108 size_t mac_algorithm_index_; 131 size_t mac_algorithm_index_;
109 size_t expires_index_; 132 size_t expires_index_;
110 size_t maxage_index_; 133 size_t maxage_index_;
111 size_t secure_index_; 134 size_t secure_index_;
112 size_t httponly_index_; 135 size_t httponly_index_;
113 136
114 DISALLOW_COPY_AND_ASSIGN(ParsedCookie); 137 DISALLOW_COPY_AND_ASSIGN(ParsedCookie);
115 }; 138 };
116 139
117 } // namespace net 140 } // namespace net
118 141
119 #endif // NET_COOKIES_COOKIE_MONSTER_H_ 142 #endif // NET_COOKIES_COOKIE_MONSTER_H_
OLDNEW
« no previous file with comments | « no previous file | net/cookies/parsed_cookie.cc » ('j') | net/cookies/parsed_cookie.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698