- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
30 class GPop::SecretsImp
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 ;
38 GAuth::Secrets m_secrets ;
39 } ;
40
41 // ===
42
43 GPop::Secrets::Secrets( const std::string & path ) :
44 m_imp( new SecretsImp(path) )
45 {
46 }
47
48 GPop::Secrets::~Secrets()
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
63 bool GPop::Secrets::valid() const
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
GPop::SecretsImp::m_secrets
GAuth::Secrets m_secrets
Definition: gpopsecrets.cpp:38
GPop::Secrets::contains
bool contains(const std::string &mechanism) const
Returns true if there is one or more secrets using the given mechanism.
Definition: gpopsecrets.cpp:73
GPop::SecretsImp::secret
std::string secret(const std::string &mechanism, const std::string &id) const
Definition: gpopsecrets.cpp:94
GAuth::Secrets::valid
virtual bool valid() const
Final override from GAuth::Valid virtual base.
Definition: gsecrets_full.cpp:47
gsecrets.h
GAuth::Secrets
A simple interface to a store of secrets as used in authentication.
Definition: gsecrets.h:44
GPop::SecretsImp::m_path
std::string m_path
Definition: gpopsecrets.cpp:37
gpopsecrets.h
GPop::Secrets::Secrets
Secrets(const std::string &storage_path=defaultPath())
Constructor.
Definition: gpopsecrets.cpp:43
GPop::SecretsImp
A private pimple-pattern implementation class used by GPop::Secrets.
Definition: gpopsecrets.cpp:30
GPop::Secrets::~Secrets
virtual ~Secrets()
Destructor.
Definition: gpopsecrets.cpp:48
gpop.h
GPop::Secrets::secret
virtual std::string secret(const std::string &mechanism, const std::string &id) const
Returns the given user's secret.
Definition: gpopsecrets.cpp:68
GPop::Secrets::valid
virtual bool valid() const
Returns true.
Definition: gpopsecrets.cpp:63
GPop::SecretsImp::SecretsImp
SecretsImp(const std::string &path)
Definition: gpopsecrets.cpp:80
GPop::Secrets::path
std::string path() const
Returns the storage path.
Definition: gpopsecrets.cpp:53
GPop::SecretsImp::contains
bool contains(const std::string &mechanism) const
Definition: gpopsecrets.cpp:99
GPop::SecretsImp::path
std::string path() const
Definition: gpopsecrets.cpp:89
GPop::Secrets::source
virtual std::string source() const
Returns the storage path, as passed in to the constructor.
Definition: gpopsecrets.cpp:58