| Line |
Branch |
Exec |
Source |
| 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 |
|
|
|
| 25 |
|
|
#ifndef PDCOM5_SIMPLELOGINMANAGER_IMPL_H |
| 26 |
|
|
#define PDCOM5_SIMPLELOGINMANAGER_IMPL_H |
| 27 |
|
|
|
| 28 |
|
|
extern "C" { |
| 29 |
|
|
struct sasl_conn; |
| 30 |
|
|
struct sasl_interact; |
| 31 |
|
|
struct sasl_callback; |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
|
#include <forward_list> |
| 35 |
|
|
#include <memory> |
| 36 |
|
|
#include <string> |
| 37 |
|
|
|
| 38 |
|
|
namespace PdCom { |
| 39 |
|
|
class SimpleLoginManager; |
| 40 |
|
|
|
| 41 |
|
|
namespace impl { |
| 42 |
|
|
|
| 43 |
|
29 |
class SimpleLoginManager |
| 44 |
|
|
{ |
| 45 |
|
|
public: |
| 46 |
|
|
enum class State { |
| 47 |
|
|
Init, |
| 48 |
|
|
MechRecieved, |
| 49 |
|
|
Pending, |
| 50 |
|
|
Completed, |
| 51 |
|
|
Error, |
| 52 |
|
|
Canceled, |
| 53 |
|
|
}; |
| 54 |
|
|
|
| 55 |
|
|
SimpleLoginManager( |
| 56 |
|
|
PdCom::SimpleLoginManager *This, |
| 57 |
|
|
const char *host, |
| 58 |
|
|
sasl_callback *additional_callbacks); |
| 59 |
|
|
void loginReply(const char *mechlist, const char *serverData, int finished); |
| 60 |
|
|
|
| 61 |
|
|
private: |
| 62 |
|
|
void doInteract(sasl_interact *); |
| 63 |
|
|
void startNewSession(); |
| 64 |
|
|
|
| 65 |
|
|
struct SaslContextDeleter |
| 66 |
|
|
{ |
| 67 |
|
|
void operator()(sasl_conn *) const; |
| 68 |
|
|
}; |
| 69 |
|
|
|
| 70 |
|
|
struct CallbackManager; |
| 71 |
|
|
|
| 72 |
|
|
friend PdCom::SimpleLoginManager; |
| 73 |
|
|
PdCom::SimpleLoginManager *This_; |
| 74 |
|
|
const std::string host_; |
| 75 |
|
|
const std::unique_ptr<sasl_callback[]> callbacks_; |
| 76 |
|
|
std::unique_ptr<sasl_conn, SaslContextDeleter> sasl_ctx_; |
| 77 |
|
|
// pointers to strings need to stay valid on resize, so not using a vector |
| 78 |
|
|
// here |
| 79 |
|
|
std::forward_list<std::string> cached_userdata_; |
| 80 |
|
|
std::unique_ptr<char[]> cached_password_; |
| 81 |
|
|
State state_ = State::Init; |
| 82 |
|
|
}; |
| 83 |
|
|
|
| 84 |
|
|
} // namespace impl |
| 85 |
|
|
} // namespace PdCom |
| 86 |
|
|
|
| 87 |
|
|
#endif // PDCOM5_SIMPLELOGINMANAGER_IMPL_H |
| 88 |
|
|
|