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

Side by Side Diff: net/http/http_auth_cache.h

Issue 6191001: Cleanup: Use AUTH_SCHEME enum instead of a string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Merge with trunk Created 9 years, 11 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 | « net/http/http_auth.cc ('k') | net/http/http_auth_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
16 #include "net/http/http_auth.h"
16 17
17 namespace net { 18 namespace net {
18 19
19 // HttpAuthCache stores HTTP authentication identities and challenge info. 20 // HttpAuthCache stores HTTP authentication identities and challenge info.
20 // For each (origin, realm, scheme) triple the cache stores a 21 // For each (origin, realm, scheme) triple the cache stores a
21 // HttpAuthCache::Entry, which holds: 22 // HttpAuthCache::Entry, which holds:
22 // - the origin server {protocol scheme, host, port} 23 // - the origin server {protocol scheme, host, port}
23 // - the last identity used (username/password) 24 // - the last identity used (username/password)
24 // - the last auth handler used (contains realm and authentication scheme) 25 // - the last auth handler used (contains realm and authentication scheme)
25 // - the list of paths which used this realm 26 // - the list of paths which used this realm
26 // Entries can be looked up by either (origin, realm, scheme) or (origin, path). 27 // Entries can be looked up by either (origin, realm, scheme) or (origin, path).
27 class HttpAuthCache { 28 class HttpAuthCache {
28 public: 29 public:
29 class Entry; 30 class Entry;
30 31
31 // Prevent unbounded memory growth. These are safeguards for abuse; it is 32 // Prevent unbounded memory growth. These are safeguards for abuse; it is
32 // not expected that the limits will be reached in ordinary usage. 33 // not expected that the limits will be reached in ordinary usage.
33 // This also defines the worst-case lookup times (which grow linearly 34 // This also defines the worst-case lookup times (which grow linearly
34 // with number of elements in the cache). 35 // with number of elements in the cache).
35 enum { kMaxNumPathsPerRealmEntry = 10 }; 36 enum { kMaxNumPathsPerRealmEntry = 10 };
36 enum { kMaxNumRealmEntries = 10 }; 37 enum { kMaxNumRealmEntries = 10 };
37 38
38 HttpAuthCache(); 39 HttpAuthCache();
39 ~HttpAuthCache(); 40 ~HttpAuthCache();
40 41
41 // Find the realm entry on server |origin| for realm |realm| and 42 // Find the realm entry on server |origin| for realm |realm| and
42 // scheme |scheme|. 43 // scheme |scheme|.
43 // |origin| - the {scheme, host, port} of the server. 44 // |origin| - the {scheme, host, port} of the server.
44 // |realm| - case sensitive realm string. 45 // |realm| - case sensitive realm string.
45 // |scheme| - case sensitive authentication scheme, should be lower-case. 46 // |scheme| - the authentication scheme (i.e. basic, negotiate).
46 // returns - the matched entry or NULL. 47 // returns - the matched entry or NULL.
47 Entry* Lookup(const GURL& origin, const std::string& realm, 48 Entry* Lookup(const GURL& origin,
48 const std::string& scheme); 49 const std::string& realm,
50 HttpAuth::Scheme scheme);
49 51
50 // Find the entry on server |origin| whose protection space includes 52 // Find the entry on server |origin| whose protection space includes
51 // |path|. This uses the assumption in RFC 2617 section 2 that deeper 53 // |path|. This uses the assumption in RFC 2617 section 2 that deeper
52 // paths lie in the same protection space. 54 // paths lie in the same protection space.
53 // |origin| - the {scheme, host, port} of the server. 55 // |origin| - the {scheme, host, port} of the server.
54 // |path| - absolute path of the resource, or empty string in case of 56 // |path| - absolute path of the resource, or empty string in case of
55 // proxy auth (which does not use the concept of paths). 57 // proxy auth (which does not use the concept of paths).
56 // returns - the matched entry or NULL. 58 // returns - the matched entry or NULL.
57 Entry* LookupByPath(const GURL& origin, const std::string& path); 59 Entry* LookupByPath(const GURL& origin, const std::string& path);
58 60
59 // Add an entry on server |origin| for realm |handler->realm()| and 61 // Add an entry on server |origin| for realm |handler->realm()| and
60 // scheme |handler->scheme()|. If an entry for this (realm,scheme) 62 // scheme |handler->scheme()|. If an entry for this (realm,scheme)
61 // already exists, update it rather than replace it -- this preserves the 63 // already exists, update it rather than replace it -- this preserves the
62 // paths list. 64 // paths list.
63 // |origin| - the {scheme, host, port} of the server. 65 // |origin| - the {scheme, host, port} of the server.
64 // |realm| - the auth realm for the challenge. 66 // |realm| - the auth realm for the challenge.
65 // |scheme| - the authentication scheme for the challenge. 67 // |scheme| - the authentication scheme (i.e. basic, negotiate).
66 // |username| - login information for the realm. 68 // |username| - login information for the realm.
67 // |password| - login information for the realm. 69 // |password| - login information for the realm.
68 // |path| - absolute path for a resource contained in the protection 70 // |path| - absolute path for a resource contained in the protection
69 // space; this will be added to the list of known paths. 71 // space; this will be added to the list of known paths.
70 // returns - the entry that was just added/updated. 72 // returns - the entry that was just added/updated.
71 Entry* Add(const GURL& origin, 73 Entry* Add(const GURL& origin,
72 const std::string& realm, 74 const std::string& realm,
73 const std::string& scheme, 75 HttpAuth::Scheme scheme,
74 const std::string& auth_challenge, 76 const std::string& auth_challenge,
75 const string16& username, 77 const string16& username,
76 const string16& password, 78 const string16& password,
77 const std::string& path); 79 const std::string& path);
78 80
79 // Remove entry on server |origin| for realm |realm| and scheme |scheme| 81 // Remove entry on server |origin| for realm |realm| and scheme |scheme|
80 // if one exists AND if the cached identity matches (|username|, |password|). 82 // if one exists AND if the cached identity matches (|username|, |password|).
81 // |origin| - the {scheme, host, port} of the server. 83 // |origin| - the {scheme, host, port} of the server.
82 // |realm| - case sensitive realm string. 84 // |realm| - case sensitive realm string.
83 // |scheme| - authentication scheme 85 // |scheme| - the authentication scheme (i.e. basic, negotiate).
84 // |username| - condition to match. 86 // |username| - condition to match.
85 // |password| - condition to match. 87 // |password| - condition to match.
86 // returns - true if an entry was removed. 88 // returns - true if an entry was removed.
87 bool Remove(const GURL& origin, 89 bool Remove(const GURL& origin,
88 const std::string& realm, 90 const std::string& realm,
89 const std::string& scheme, 91 HttpAuth::Scheme scheme,
90 const string16& username, 92 const string16& username,
91 const string16& password); 93 const string16& password);
92 94
93 // Updates a stale digest entry on server |origin| for realm |realm| and 95 // Updates a stale digest entry on server |origin| for realm |realm| and
94 // scheme |scheme|. The cached auth challenge is replaced with 96 // scheme |scheme|. The cached auth challenge is replaced with
95 // |auth_challenge| and the nonce count is reset. 97 // |auth_challenge| and the nonce count is reset.
96 // |UpdateStaleChallenge()| returns true if a matching entry exists in the 98 // |UpdateStaleChallenge()| returns true if a matching entry exists in the
97 // cache, false otherwise. 99 // cache, false otherwise.
98 bool UpdateStaleChallenge(const GURL& origin, 100 bool UpdateStaleChallenge(const GURL& origin,
99 const std::string& realm, 101 const std::string& realm,
100 const std::string& scheme, 102 HttpAuth::Scheme scheme,
101 const std::string& auth_challenge); 103 const std::string& auth_challenge);
102 104
103 private: 105 private:
104 typedef std::list<Entry> EntryList; 106 typedef std::list<Entry> EntryList;
105 EntryList entries_; 107 EntryList entries_;
106 }; 108 };
107 109
108 // An authentication realm entry. 110 // An authentication realm entry.
109 class HttpAuthCache::Entry { 111 class HttpAuthCache::Entry {
110 public: 112 public:
111 ~Entry(); 113 ~Entry();
112 114
113 const GURL& origin() const { 115 const GURL& origin() const {
114 return origin_; 116 return origin_;
115 } 117 }
116 118
117 // The case-sensitive realm string of the challenge. 119 // The case-sensitive realm string of the challenge.
118 const std::string realm() const { 120 const std::string realm() const {
119 return realm_; 121 return realm_;
120 } 122 }
121 123
122 // The authentication scheme string of the challenge 124 // The authentication scheme of the challenge.
123 const std::string scheme() const { 125 const HttpAuth::Scheme scheme() const {
124 return scheme_; 126 return scheme_;
125 } 127 }
126 128
127 // The authentication challenge. 129 // The authentication challenge.
128 const std::string auth_challenge() const { 130 const std::string auth_challenge() const {
129 return auth_challenge_; 131 return auth_challenge_;
130 } 132 }
131 133
132 // The login username. 134 // The login username.
133 const string16 username() const { 135 const string16 username() const {
(...skipping 20 matching lines...) Expand all
154 156
155 Entry(); 157 Entry();
156 158
157 // Adds a path defining the realm's protection space. If the path is 159 // Adds a path defining the realm's protection space. If the path is
158 // already contained in the protection space, is a no-op. 160 // already contained in the protection space, is a no-op.
159 void AddPath(const std::string& path); 161 void AddPath(const std::string& path);
160 162
161 // Returns true if |dir| is contained within the realm's protection space. 163 // Returns true if |dir| is contained within the realm's protection space.
162 bool HasEnclosingPath(const std::string& dir); 164 bool HasEnclosingPath(const std::string& dir);
163 165
164 // |origin_| contains the {scheme, host, port} of the server. 166 // |origin_| contains the {protocol, host, port} of the server.
165 GURL origin_; 167 GURL origin_;
166 std::string realm_; 168 std::string realm_;
167 std::string scheme_; 169 HttpAuth::Scheme scheme_;
168 170
169 // Identity. 171 // Identity.
170 std::string auth_challenge_; 172 std::string auth_challenge_;
171 string16 username_; 173 string16 username_;
172 string16 password_; 174 string16 password_;
173 175
174 int nonce_count_; 176 int nonce_count_;
175 177
176 // List of paths that define the realm's protection space. 178 // List of paths that define the realm's protection space.
177 PathList paths_; 179 PathList paths_;
178 }; 180 };
179 181
180 } // namespace net 182 } // namespace net
181 183
182 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ 184 #endif // NET_HTTP_HTTP_AUTH_CACHE_H_
OLDNEW
« no previous file with comments | « net/http/http_auth.cc ('k') | net/http/http_auth_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698