Merge pull request #1143 from bossanova808/master
[vuplus_xbmc] / xbmc / PasswordManager.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2008 Team XBMC
4  *      http://www.xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, write to
18  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *  http://www.gnu.org/copyleft/gpl.html
20  *
21  */
22
23 #include "utils/StdString.h"
24 #include <map>
25 #include "threads/CriticalSection.h"
26
27 class CURL;
28
29 /*!
30  \ingroup filesystem
31  \brief Password Manager class for saving authentication details
32  
33  Handles access to previously saved passwords for paths, translating normal URLs
34  into authenticated URLs if the user has details about the username and password
35  for a path previously saved. Should be accessed via CPasswordManager::GetInstance()
36  */
37 class CPasswordManager
38 {
39 public:
40  /*!
41    \brief The only way through which the global instance of the CPasswordManager should be accessed.
42    \return the global instance.
43    */
44   static CPasswordManager &GetInstance();
45
46   /*!
47    \brief Authenticate a URL by looking the URL up in the temporary and permanent caches
48    First looks up based on host and share name.  If that fails, it will try a match purely
49    on the host name (eg different shares on the same host with the same credentials)
50    \param url a CURL to authenticate
51    \return true if we have details in the cache, false otherwise.
52    \sa CURL
53    */
54   bool AuthenticateURL(CURL &url);
55
56   /*!
57    \brief Prompt for a username and password for the particular URL.
58    
59    This routine pops up a dialog, requesting the user enter a username and password
60    to access the given URL.  The user may optionally save these details.  If saved
61    we write the details into the users profile.  If not saved, the details are temporarily
62    stored so that further access no longer requires prompting for authentication.
63    
64    \param url the URL to authenticate.
65    \return true if the user entered details, false if the user cancelled the dialog.
66    \sa CURL
67    */
68   bool PromptToAuthenticateURL(CURL &url);
69
70   /*!
71    \brief Clear any previously cached passwords
72    */
73   void Clear();
74
75 private:
76   // private construction, and no assignements; use the provided singleton methods
77   CPasswordManager();
78   CPasswordManager(const CPasswordManager&);
79   CPasswordManager const & operator=(CPasswordManager const&);
80   ~CPasswordManager() {};
81
82   void Load();
83   void Save() const;
84   CStdString GetLookupPath(const CURL &url) const;
85   CStdString GetServerLookup(const CStdString &path) const;
86
87   std::map<CStdString, CStdString>  m_temporaryCache;
88   std::map<CStdString, CStdString>  m_permanentCache;
89   bool m_loaded;
90
91   CCriticalSection m_critSection;
92 };