PdCom  5.1
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  };
104 
105  protected:
106  virtual ~SimpleLoginManager();
107 
122  bool login();
123 
126  using Sasl::logout;
129  virtual std::string getAuthname() { throw Cancel(); }
132  virtual std::string getPassword() { throw Cancel(); }
135  virtual std::string
136  getRealm(const std::vector<const char *> & /* available realms */)
137  {
138  throw Cancel();
139  }
141  virtual std::string
142  getOption(const char * /*plugin_name*/, const char * /*option*/)
143  {
144  throw Cancel();
145  }
147  virtual std::string interact(
148  unsigned long /*id*/,
149  const char * /*challenge*/,
150  const char * /*prompt*/,
151  const char * /*default result*/)
152  {
153  throw Cancel();
154  }
159  virtual void completed(LoginResult result) = 0;
160 
166  virtual void log(int level, const char *message);
167 };
168 
169 } // namespace PdCom
170 
171 #endif // PDCOM5_SIMPLELOGINMANAGER_H
SASL Interface for PdCom.
Definition: Sasl.h:42
void logout()
Logout from server.
Wrapper for Cyrus SASL library.
Definition: SimpleLoginManager.h:58
virtual std::string getOption(const char *, const char *)
SASL get option callback.
Definition: SimpleLoginManager.h:142
SimpleLoginManager(const char *remote_host, sasl_callback *additional_callbacks=nullptr)
Constructor.
virtual std::string getPassword()
Callback to get password.
Definition: SimpleLoginManager.h:132
virtual std::string getAuthname()
Callback to get login name.
Definition: SimpleLoginManager.h:129
static void InitLibrary(const char *plugin_path=nullptr)
Sasl global initialization.
LoginResult
Result of login operation.
Definition: SimpleLoginManager.h:99
virtual std::string getRealm(const std::vector< const char * > &)
Callback to get realm.
Definition: SimpleLoginManager.h:136
bool login()
Perform SASL login step.
virtual void log(int level, const char *message)
Log callback.
virtual std::string interact(unsigned long, const char *, const char *, const char *)
SASL interact callback.
Definition: SimpleLoginManager.h:147
static void FinalizeLibrary()
Sasl global finalization.
virtual void completed(LoginResult result)=0
Authentification completed callback.
library version string as "major.minor.patch"
Definition: ClientStatistics.h:31
@ Error
Error log level.
Exception for callback cancelation.
Definition: SimpleLoginManager.h:96