PdCom  5.3
Process data communication client
SimpleLoginManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vim:tw=78
3  *
4  * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5  * Florian Pose (fp at igh dot de),
6  * Bjarne von Horn (vh at igh dot de).
7  *
8  * This file is part of the PdCom library.
9  *
10  * The PdCom library is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or (at your
13  * option) any later version.
14  *
15  * The PdCom library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  *****************************************************************************/
24 
27 #ifndef PDCOM5_SIMPLELOGINMANAGER_H
28 #define PDCOM5_SIMPLELOGINMANAGER_H
29 
30 #include "pdcom5-sasl_export.h"
31 
32 #include <memory>
33 #include <pdcom5/Sasl.h>
34 #include <stdexcept>
35 #include <vector>
36 
37 extern "C" struct sasl_callback;
38 
39 namespace PdCom {
40 namespace impl {
41 class SimpleLoginManager;
42 } // namespace impl
43 
57 class PDCOM5_SASL_EXPORT SimpleLoginManager : public Sasl
58 {
59  friend class impl::SimpleLoginManager;
60  std::unique_ptr<impl::SimpleLoginManager> impl_;
61  void loginReply(const char *mechlist, const char *serverData, int finished)
62  override;
63 
64  public:
72  static void InitLibrary(const char *plugin_path = nullptr);
75  static void FinalizeLibrary();
76 
84  const char *remote_host,
85  sasl_callback *additional_callbacks = nullptr);
87  SimpleLoginManager &operator=(SimpleLoginManager &&) noexcept;
88 
89 
95  struct Cancel : std::exception
96  {};
97 
99  enum class LoginResult {
100  Success,
101  Error,
102  Canceled,
103  NoSaslMechanism,
105  };
106 
107  protected:
108  virtual ~SimpleLoginManager();
109 
124  bool login();
125 
128  using Sasl::logout;
131  virtual std::string getAuthname() { throw Cancel(); }
134  virtual std::string getPassword() { throw Cancel(); }
137  virtual std::string
138  getRealm(const std::vector<const char *> & /* available realms */)
139  {
140  throw Cancel();
141  }
143  virtual std::string
144  getOption(const char * /*plugin_name*/, const char * /*option*/)
145  {
146  throw Cancel();
147  }
149  virtual std::string interact(
150  unsigned long /*id*/,
151  const char * /*challenge*/,
152  const char * /*prompt*/,
153  const char * /*default result*/)
154  {
155  throw Cancel();
156  }
161  virtual void completed(LoginResult result) = 0;
162 
168  virtual void log(int level, const char *message);
169 };
170 
171 } // namespace PdCom
172 
173 #endif // PDCOM5_SIMPLELOGINMANAGER_H
virtual std::string getPassword()
Callback to get password.
Definition: SimpleLoginManager.h:134
virtual std::string getAuthname()
Callback to get login name.
Definition: SimpleLoginManager.h:131
virtual std::string interact(unsigned long, const char *, const char *, const char *)
SASL interact callback.
Definition: SimpleLoginManager.h:149
LoginResult
Result of login operation.
Definition: SimpleLoginManager.h:99
Exception for callback cancelation.
Definition: SimpleLoginManager.h:95
virtual std::string getOption(const char *, const char *)
SASL get option callback.
Definition: SimpleLoginManager.h:144
virtual std::string getRealm(const std::vector< const char *> &)
Callback to get realm.
Definition: SimpleLoginManager.h:138
Wrapper for Cyrus SASL library.
Definition: SimpleLoginManager.h:57
SASL Interface for PdCom.
Definition: Sasl.h:41
void logout()
Logout from server.
Definition: ClientStatistics.h:31