PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/xbmc/PasswordManager.h

http://github.com/xbmc/xbmc
C Header | 105 lines | 29 code | 14 blank | 62 comment | 0 complexity | d85e45e32abfb09688ebd63b95fd2395 MD5 | raw file
  1/*
  2 *  Copyright (C) 2005-2018 Team Kodi
  3 *  This file is part of Kodi - https://kodi.tv
  4 *
  5 *  SPDX-License-Identifier: GPL-2.0-or-later
  6 *  See LICENSES/README.md for more information.
  7 */
  8
  9#pragma once
 10
 11#include "threads/CriticalSection.h"
 12
 13#include <map>
 14#include <stdint.h>
 15#include <string>
 16
 17class CURL;
 18
 19/*!
 20 \ingroup filesystem
 21 \brief Password Manager class for saving authentication details
 22
 23 Handles access to previously saved passwords for paths, translating normal URLs
 24 into authenticated URLs if the user has details about the username and password
 25 for a path previously saved. Should be accessed via CPasswordManager::GetInstance()
 26 */
 27class CPasswordManager
 28{
 29public:
 30 /*!
 31   \brief The only way through which the global instance of the CPasswordManager should be accessed.
 32   \return the global instance.
 33   */
 34  static CPasswordManager &GetInstance();
 35
 36  /*!
 37   \brief Authenticate a URL by looking the URL up in the temporary and permanent caches
 38   First looks up based on host and share name.  If that fails, it will try a match purely
 39   on the host name (eg different shares on the same host with the same credentials)
 40   \param url a CURL to authenticate
 41   \return true if we have details in the cache, false otherwise.
 42   \sa CURL
 43   */
 44  bool AuthenticateURL(CURL &url);
 45
 46  /*!
 47   \brief Prompt for a username and password for the particular URL.
 48
 49   This routine pops up a dialog, requesting the user enter a username and password
 50   to access the given URL.  The user may optionally save these details.  If saved
 51   we write the details into the users profile.  If not saved, the details are temporarily
 52   stored so that further access no longer requires prompting for authentication.
 53
 54   \param url the URL to authenticate.
 55   \return true if the user entered details, false if the user cancelled the dialog.
 56   \sa CURL, SaveAuthenticatedURL
 57   */
 58  bool PromptToAuthenticateURL(CURL &url);
 59
 60  /*!
 61   \brief Save an authenticated URL.
 62
 63   This routine stores an authenticated URL in the temporary cache, and optionally
 64   saves these details into the users profile.
 65
 66   \param url the URL to authenticate.
 67   \param saveToProfile whether to save in the users profile, defaults to true.
 68   \sa CURL, PromptToAuthenticateURL
 69   */
 70  void SaveAuthenticatedURL(const CURL &url, bool saveToProfile = true);
 71
 72  /*!
 73   \brief Is an URL is supported (by the manager)
 74
 75   This routine checks that an URL is supported by the manager
 76
 77   \param url the URL to check.
 78   \return true if the URL is supported
 79   \sa CURL, IsURLSupported
 80   */
 81  bool IsURLSupported(const CURL &url);
 82
 83  /*!
 84   \brief Clear any previously cached passwords
 85   */
 86  void Clear();
 87
 88private:
 89  // private construction, and no assignments; use the provided singleton methods
 90  CPasswordManager();
 91  CPasswordManager(const CPasswordManager&) = delete;
 92  CPasswordManager& operator=(CPasswordManager const&) = delete;
 93  ~CPasswordManager() = default;
 94
 95  void Load();
 96  void Save() const;
 97  std::string GetLookupPath(const CURL &url) const;
 98  std::string GetServerLookup(const std::string &path) const;
 99
100  std::map<std::string, std::string>  m_temporaryCache;
101  std::map<std::string, std::string>  m_permanentCache;
102  bool m_loaded;
103
104  CCriticalSection m_critSection;
105};