3 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
25 #include "threads/CriticalSection.h"
31 \brief Password Manager class for saving authentication details
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()
37 class CPasswordManager
41 \brief The only way through which the global instance of the CPasswordManager should be accessed.
42 \return the global instance.
44 static CPasswordManager
&GetInstance();
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.
54 bool AuthenticateURL(CURL
&url
);
57 \brief Prompt for a username and password for the particular URL.
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.
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, SaveAuthenticatedURL
68 bool PromptToAuthenticateURL(CURL
&url
);
71 \brief Save an authenticated URL.
73 This routine stores an authenticated URL in the temporary cache, and optionally
74 saves these details into the users profile.
76 \param url the URL to authenticate.
77 \param saveToProfile whether to save in the users profile, defaults to true.
78 \sa CURL, PromptToAuthenticateURL
80 void SaveAuthenticatedURL(const CURL
&url
, bool saveToProfile
= true);
83 \brief Clear any previously cached passwords
88 // private construction, and no assignements; use the provided singleton methods
90 CPasswordManager(const CPasswordManager
&);
91 CPasswordManager
const & operator=(CPasswordManager
const&);
92 ~CPasswordManager() {};
96 std::string
GetLookupPath(const CURL
&url
) const;
97 std::string
GetServerLookup(const std::string
&path
) const;
99 std::map
<std::string
, std::string
> m_temporaryCache
;
100 std::map
<std::string
, std::string
> m_permanentCache
;
103 CCriticalSection m_critSection
;