gpopsecrets.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // gpopsecrets.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gpop.h"
23 #include "gpopsecrets.h"
24 #include "gsecrets.h" // gsmtp
25 
31 {
32 public:
33  explicit SecretsImp( const std::string & path ) ;
34  std::string path() const ;
35  std::string secret( const std::string & mechanism , const std::string & id ) const ;
36  bool contains( const std::string & mechanism ) const ;
37  std::string m_path ;
39 } ;
40 
41 // ===
42 
43 GPop::Secrets::Secrets( const std::string & path ) :
44  m_imp( new SecretsImp(path) )
45 {
46 }
47 
49 {
50  delete m_imp ;
51 }
52 
53 std::string GPop::Secrets::path() const
54 {
55  return m_imp->path() ;
56 }
57 
58 std::string GPop::Secrets::source() const
59 {
60  return m_imp->path() ;
61 }
62 
64 {
65  return true ;
66 }
67 
68 std::string GPop::Secrets::secret( const std::string & mechanism , const std::string & id ) const
69 {
70  return m_imp->secret( mechanism , id ) ;
71 }
72 
73 bool GPop::Secrets::contains( const std::string & mechanism ) const
74 {
75  return m_imp->contains( mechanism ) ;
76 }
77 
78 // ===
79 
80 GPop::SecretsImp::SecretsImp( const std::string & path ) :
81  m_path(path) ,
82  m_secrets( path , "pop-server" ) // throws on error
83 {
84  // throw if an empty path
85  if( !m_secrets.valid() )
86  throw GPop::Secrets::OpenError(path) ;
87 }
88 
89 std::string GPop::SecretsImp::path() const
90 {
91  return m_path ;
92 }
93 
94 std::string GPop::SecretsImp::secret( const std::string & mechanism , const std::string & id ) const
95 {
96  return m_secrets.secret( mechanism , id ) ;
97 }
98 
99 bool GPop::SecretsImp::contains( const std::string & mechanism ) const
100 {
101  return m_secrets.contains( mechanism ) ;
102 }
103 
GAuth::Secrets m_secrets
Definition: gpopsecrets.cpp:38
bool contains(const std::string &mechanism) const
Returns true if there is one or more secrets using the given mechanism.
Definition: gpopsecrets.cpp:73
std::string secret(const std::string &mechanism, const std::string &id) const
Definition: gpopsecrets.cpp:94
virtual bool valid() const
Final override from GAuth::Valid virtual base.
A simple interface to a store of secrets as used in authentication.
Definition: gsecrets.h:44
std::string m_path
Definition: gpopsecrets.cpp:37
Secrets(const std::string &storage_path=defaultPath())
Constructor.
Definition: gpopsecrets.cpp:43
A private pimple-pattern implementation class used by GPop::Secrets.
Definition: gpopsecrets.cpp:30
virtual ~Secrets()
Destructor.
Definition: gpopsecrets.cpp:48
virtual std::string secret(const std::string &mechanism, const std::string &id) const
Returns the given user's secret.
Definition: gpopsecrets.cpp:68
virtual bool valid() const
Returns true.
Definition: gpopsecrets.cpp:63
SecretsImp(const std::string &path)
Definition: gpopsecrets.cpp:80
std::string path() const
Returns the storage path.
Definition: gpopsecrets.cpp:53
bool contains(const std::string &mechanism) const
Definition: gpopsecrets.cpp:99
std::string path() const
Definition: gpopsecrets.cpp:89
virtual std::string source() const
Returns the storage path, as passed in to the constructor.
Definition: gpopsecrets.cpp:58