| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_HTTP_HTTP_AUTH_CACHE_H_ | 5 #ifndef NET_HTTP_HTTP_AUTH_CACHE_H_ |
| 6 #define NET_HTTP_HTTP_AUTH_CACHE_H_ | 6 #define NET_HTTP_HTTP_AUTH_CACHE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // HttpAuthCache::Entry, which holds: | 21 // HttpAuthCache::Entry, which holds: |
| 22 // - the origin server {protocol scheme, host, port} | 22 // - the origin server {protocol scheme, host, port} |
| 23 // - the last identity used (username/password) | 23 // - the last identity used (username/password) |
| 24 // - the last auth handler used (contains realm and authentication scheme) | 24 // - the last auth handler used (contains realm and authentication scheme) |
| 25 // - the list of paths which used this realm | 25 // - the list of paths which used this realm |
| 26 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). | 26 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). |
| 27 class HttpAuthCache { | 27 class HttpAuthCache { |
| 28 public: | 28 public: |
| 29 class Entry; | 29 class Entry; |
| 30 | 30 |
| 31 // Prevent unbounded memory growth. These are safeguards for abuse; it is |
| 32 // not expected that the limits will be reached in ordinary usage. |
| 33 // This also defines the worst-case lookup times (which grow linearly |
| 34 // with number of elements in the cache). |
| 35 enum { kMaxNumPathsPerRealmEntry = 10 }; |
| 36 enum { kMaxNumRealmEntries = 10 }; |
| 37 |
| 31 HttpAuthCache(); | 38 HttpAuthCache(); |
| 32 ~HttpAuthCache(); | 39 ~HttpAuthCache(); |
| 33 | 40 |
| 34 // Find the realm entry on server |origin| for realm |realm| and | 41 // Find the realm entry on server |origin| for realm |realm| and |
| 35 // scheme |scheme|. | 42 // scheme |scheme|. |
| 36 // |origin| - the {scheme, host, port} of the server. | 43 // |origin| - the {scheme, host, port} of the server. |
| 37 // |realm| - case sensitive realm string. | 44 // |realm| - case sensitive realm string. |
| 38 // |scheme| - case sensitive authentication scheme, should be lower-case. | 45 // |scheme| - case sensitive authentication scheme, should be lower-case. |
| 39 // returns - the matched entry or NULL. | 46 // returns - the matched entry or NULL. |
| 40 Entry* Lookup(const GURL& origin, const std::string& realm, | 47 Entry* Lookup(const GURL& origin, const std::string& realm, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Updates a stale digest entry on server |origin| for realm |realm| and | 93 // Updates a stale digest entry on server |origin| for realm |realm| and |
| 87 // scheme |scheme|. The cached auth challenge is replaced with | 94 // scheme |scheme|. The cached auth challenge is replaced with |
| 88 // |auth_challenge| and the nonce count is reset. | 95 // |auth_challenge| and the nonce count is reset. |
| 89 // |UpdateStaleChallenge()| returns true if a matching entry exists in the | 96 // |UpdateStaleChallenge()| returns true if a matching entry exists in the |
| 90 // cache, false otherwise. | 97 // cache, false otherwise. |
| 91 bool UpdateStaleChallenge(const GURL& origin, | 98 bool UpdateStaleChallenge(const GURL& origin, |
| 92 const std::string& realm, | 99 const std::string& realm, |
| 93 const std::string& scheme, | 100 const std::string& scheme, |
| 94 const std::string& auth_challenge); | 101 const std::string& auth_challenge); |
| 95 | 102 |
| 96 // Prevent unbounded memory growth. These are safeguards for abuse; it is | |
| 97 // not expected that the limits will be reached in ordinary usage. | |
| 98 // This also defines the worst-case lookup times (which grow linearly | |
| 99 // with number of elements in the cache). | |
| 100 enum { kMaxNumPathsPerRealmEntry = 10 }; | |
| 101 enum { kMaxNumRealmEntries = 10 }; | |
| 102 | |
| 103 private: | 103 private: |
| 104 typedef std::list<Entry> EntryList; | 104 typedef std::list<Entry> EntryList; |
| 105 EntryList entries_; | 105 EntryList entries_; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 // An authentication realm entry. | 108 // An authentication realm entry. |
| 109 class HttpAuthCache::Entry { | 109 class HttpAuthCache::Entry { |
| 110 public: | 110 public: |
| 111 ~Entry(); |
| 112 |
| 111 const GURL& origin() const { | 113 const GURL& origin() const { |
| 112 return origin_; | 114 return origin_; |
| 113 } | 115 } |
| 114 | 116 |
| 115 // The case-sensitive realm string of the challenge. | 117 // The case-sensitive realm string of the challenge. |
| 116 const std::string realm() const { | 118 const std::string realm() const { |
| 117 return realm_; | 119 return realm_; |
| 118 } | 120 } |
| 119 | 121 |
| 120 // The authentication scheme string of the challenge | 122 // The authentication scheme string of the challenge |
| (...skipping 15 matching lines...) Expand all Loading... |
| 136 const string16 password() const { | 138 const string16 password() const { |
| 137 return password_; | 139 return password_; |
| 138 } | 140 } |
| 139 | 141 |
| 140 int IncrementNonceCount() { | 142 int IncrementNonceCount() { |
| 141 return ++nonce_count_; | 143 return ++nonce_count_; |
| 142 } | 144 } |
| 143 | 145 |
| 144 void UpdateStaleChallenge(const std::string& auth_challenge); | 146 void UpdateStaleChallenge(const std::string& auth_challenge); |
| 145 | 147 |
| 146 ~Entry(); | |
| 147 | |
| 148 private: | 148 private: |
| 149 friend class HttpAuthCache; | 149 friend class HttpAuthCache; |
| 150 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddPath); | 150 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddPath); |
| 151 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddToExistingEntry); | 151 FRIEND_TEST_ALL_PREFIXES(HttpAuthCacheTest, AddToExistingEntry); |
| 152 | 152 |
| 153 typedef std::list<std::string> PathList; |
| 154 |
| 153 Entry(); | 155 Entry(); |
| 154 | 156 |
| 155 // Adds a path defining the realm's protection space. If the path is | 157 // Adds a path defining the realm's protection space. If the path is |
| 156 // already contained in the protection space, is a no-op. | 158 // already contained in the protection space, is a no-op. |
| 157 void AddPath(const std::string& path); | 159 void AddPath(const std::string& path); |
| 158 | 160 |
| 159 // Returns true if |dir| is contained within the realm's protection space. | 161 // Returns true if |dir| is contained within the realm's protection space. |
| 160 bool HasEnclosingPath(const std::string& dir); | 162 bool HasEnclosingPath(const std::string& dir); |
| 161 | 163 |
| 162 // |origin_| contains the {scheme, host, port} of the server. | 164 // |origin_| contains the {scheme, host, port} of the server. |
| 163 GURL origin_; | 165 GURL origin_; |
| 164 std::string realm_; | 166 std::string realm_; |
| 165 std::string scheme_; | 167 std::string scheme_; |
| 166 | 168 |
| 167 // Identity. | 169 // Identity. |
| 168 std::string auth_challenge_; | 170 std::string auth_challenge_; |
| 169 string16 username_; | 171 string16 username_; |
| 170 string16 password_; | 172 string16 password_; |
| 171 | 173 |
| 172 int nonce_count_; | 174 int nonce_count_; |
| 173 | 175 |
| 174 // List of paths that define the realm's protection space. | 176 // List of paths that define the realm's protection space. |
| 175 typedef std::list<std::string> PathList; | |
| 176 PathList paths_; | 177 PathList paths_; |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 } // namespace net | 180 } // namespace net |
| 180 | 181 |
| 181 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ | 182 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ |
| OLD | NEW |