Remove LiveTV menu.
[vuplus_xbmc] / xbmc / PasswordManager.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://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, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "utils/StdString.h"
23 #include <map>
24 #include "threads/CriticalSection.h"
25
26 class CURL;
27
28 /*!
29  \ingroup filesystem
30  \brief Password Manager class for saving authentication details
31  
32  Handles access to previously saved passwords for paths, translating normal URLs
33  into authenticated URLs if the user has details about the username and password
34  for a path previously saved. Should be accessed via CPasswordManager::GetInstance()
35  */
36 class CPasswordManager
37 {
38 public:
39  /*!
40    \brief The only way through which the global instance of the CPasswordManager should be accessed.
41    \return the global instance.
42    */
43   static CPasswordManager &GetInstance();
44
45   /*!
46    \brief Authenticate a URL by looking the URL up in the temporary and permanent caches
47    First looks up based on host and share name.  If that fails, it will try a match purely
48    on the host name (eg different shares on the same host with the same credentials)
49    \param url a CURL to authenticate
50    \return true if we have details in the cache, false otherwise.
51    \sa CURL
52    */
53   bool AuthenticateURL(CURL &url);
54
55   /*!
56    \brief Prompt for a username and password for the particular URL.
57    
58    This routine pops up a dialog, requesting the user enter a username and password
59    to access the given URL.  The user may optionally save these details.  If saved
60    we write the details into the users profile.  If not saved, the details are temporarily
61    stored so that further access no longer requires prompting for authentication.
62    
63    \param url the URL to authenticate.
64    \return true if the user entered details, false if the user cancelled the dialog.
65    \sa CURL, SaveAuthenticatedURL
66    */
67   bool PromptToAuthenticateURL(CURL &url);
68
69   /*!
70    \brief Save an authenticated URL.
71
72    This routine stores an authenticated URL in the temporary cache, and optionally
73    saves these details into the users profile.
74
75    \param url the URL to authenticate.
76    \param saveToProfile whether to save in the users profile, defaults to true.
77    \sa CURL, PromptToAuthenticateURL
78    */
79   void SaveAuthenticatedURL(const CURL &url, bool saveToProfile = true);
80
81   /*!
82    \brief Clear any previously cached passwords
83    */
84   void Clear();
85
86 private:
87   // private construction, and no assignements; use the provided singleton methods
88   CPasswordManager();
89   CPasswordManager(const CPasswordManager&);
90   CPasswordManager const & operator=(CPasswordManager const&);
91   ~CPasswordManager() {};
92
93   void Load();
94   void Save() const;
95   CStdString GetLookupPath(const CURL &url) const;
96   CStdString GetServerLookup(const CStdString &path) const;
97
98   std::map<CStdString, CStdString>  m_temporaryCache;
99   std::map<CStdString, CStdString>  m_permanentCache;
100   bool m_loaded;
101
102   CCriticalSection m_critSection;
103 };