PdCom  5.0
Process data communication client
Loading...
Searching...
No Matches
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
37extern "C" struct sasl_callback;
38
39namespace PdCom {
40namespace impl {
41class SimpleLoginManager;
42} // namespace impl
43
57class 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
98 protected:
99 virtual ~SimpleLoginManager();
100
115 bool login();
116
119 using Sasl::logout;
122 virtual std::string getAuthname() { throw Cancel(); }
125 virtual std::string getPassword() { throw Cancel(); }
128 virtual std::string
129 getRealm(const std::vector<const char *> & /* available realms */)
130 {
131 throw Cancel();
132 }
134 virtual std::string
135 getOption(const char * /*plugin_name*/, const char * /*option*/)
136 {
137 throw Cancel();
138 }
140 virtual std::string interact(
141 unsigned long /*id*/,
142 const char * /*challenge*/,
143 const char * /*prompt*/,
144 const char * /*default result*/)
145 {
146 throw Cancel();
147 }
152 virtual void completed(bool success) = 0;
153
159 virtual void log(int level, const char *message);
160};
161
162} // namespace PdCom
163
164#endif // PDCOM5_SIMPLELOGINMANAGER_H
SASL Interface for PdCom.
Definition: Sasl.h:42
Wrapper for Cyrus SASL library.
Definition: SimpleLoginManager.h:58
virtual std::string getOption(const char *, const char *)
SASL get option callback.
Definition: SimpleLoginManager.h:135
SimpleLoginManager(const char *remote_host, sasl_callback *additional_callbacks=nullptr)
Constructor.
virtual std::string getPassword()
Callback to get password.
Definition: SimpleLoginManager.h:125
virtual std::string getAuthname()
Callback to get login name.
Definition: SimpleLoginManager.h:122
static void InitLibrary(const char *plugin_path=nullptr)
Sasl global initialization.
virtual std::string getRealm(const std::vector< const char * > &)
Callback to get realm.
Definition: SimpleLoginManager.h:129
bool login()
Perform SASL login step.
virtual void completed(bool success)=0
Authentification completed callback.
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:140
static void FinalizeLibrary()
Sasl global finalization.
library version string as "major.minor.patch"
Definition: ClientStatistics.h:31
Exception for callback cancelation.
Definition: SimpleLoginManager.h:96