• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef NET_FTP_FTP_AUTH_CACHE_H_
6 #define NET_FTP_FTP_AUTH_CACHE_H_
7 #pragma once
8 
9 #include <list>
10 
11 #include "base/string16.h"
12 #include "googleurl/src/gurl.h"
13 
14 namespace net {
15 
16 // The FtpAuthCache class is a simple cache structure to store authentication
17 // information for ftp. Provides lookup, insertion, and deletion of entries.
18 // The parameter for doing lookups, insertions, and deletions is a GURL of the
19 // server's address (not a full URL with path, since FTP auth isn't per path).
20 // For example:
21 //   GURL("ftp://myserver") -- OK (implied port of 21)
22 //   GURL("ftp://myserver:21") -- OK
23 //   GURL("ftp://myserver/PATH") -- WRONG, paths not allowed
24 class FtpAuthCache {
25  public:
26   // Maximum number of entries we allow in the cache.
27   static const size_t kMaxEntries;
28 
29   struct Entry {
30     Entry(const GURL& origin, const string16& username,
31           const string16& password);
32     ~Entry();
33 
34     const GURL origin;
35     string16 username;
36     string16 password;
37   };
38 
39   FtpAuthCache();
40   ~FtpAuthCache();
41 
42   // Return Entry corresponding to given |origin| or NULL if not found.
43   Entry* Lookup(const GURL& origin);
44 
45   // Add an entry for |origin| to the cache (consisting of |username| and
46   // |password|). If there is already an entry for |origin|, it will be
47   // overwritten.
48   void Add(const GURL& origin, const string16& username,
49            const string16& password);
50 
51   // Remove the entry for |origin| from the cache, if one exists and matches
52   // |username| and |password|.
53   void Remove(const GURL& origin, const string16& username,
54               const string16& password);
55 
56  private:
57   typedef std::list<Entry> EntryList;
58 
59   // Internal representation of cache, an STL list. This makes lookups O(n),
60   // but we expect n to be very low.
61   EntryList entries_;
62 };
63 
64 }  // namespace net
65 
66 #endif  // NET_FTP_FTP_AUTH_CACHE_H_
67