GCC Code Coverage Report


Directory: ./
File: qtpdcom/QtPdCom1/LoginManager.h
Date: 2025-06-29 04:10:41
Exec Total Coverage
Lines: 2 3 66.7%
Branches: 0 0 -%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2009-2023 Bjarne von Horn <vh@igh.de>
4 *
5 * This file is part of the QtPdCom library.
6 *
7 * The QtPdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The QtPdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #ifndef QTPDCOM_LOGINMANAGER_H
23 #define QTPDCOM_LOGINMANAGER_H
24
25 #include "Export.h"
26
27 #include <QObject>
28 #include <QScopedPointer>
29 #include <QString>
30
31 namespace QtPdCom {
32
33 class LoginManagerPrivate;
34 class Process;
35
36 /**
37 * Class to handle the Authentication process.
38 *
39 * Prior to using an instance of this class,
40 * InitLibrary() has to be called.
41 *
42 * In Qt6 QML, simply create an \c SaslInitializer instance
43 * before connecting to a process.
44 *
45 */
46 4 class QTPDCOM_PUBLIC LoginManager: public QObject
47 {
48 Q_OBJECT
49
50 public:
51 explicit LoginManager(QString server_name = QString(), QObject *parent = nullptr);
52 ~LoginManager();
53
54 /**
55 * Set Login Name.
56 *
57 * \param name Login name.
58 */
59 Q_INVOKABLE void setAuthName(QString name);
60 /**
61 * Set Password.
62 *
63 * \param password Password.
64 */
65 Q_INVOKABLE void setPassword(QString password);
66
67 /**
68 * Clear stored credentials.
69 *
70 */
71 Q_INVOKABLE void clearCredentials();
72
73 /**
74 * Start the login process.
75 *
76 * If possible, please call setAuthName() and
77 * setPassword() in advance.
78 * Do not call login() from whithin any Authentification-related
79 * callback (i.e. slots connected to any of our signals which are not
80 * queued connections) as use-after-free can happen as a new session is
81 * started.
82 */
83 Q_INVOKABLE void login();
84 /**
85 * logout.
86 */
87 Q_INVOKABLE void logout();
88
89 /* Retrieve reason for login failure.
90 */
91 Q_INVOKABLE QString getErrorMessage();
92
93 /** Sasl global initialization.
94 *
95 * Call this at startup of your application to initialize the underlying
96 * sasl library.
97 *
98 * \param plugin_path Path to SASL.
99 * \throws PdCom::Exception Initialization failed.
100 */
101 static void InitLibrary(const char *plugin_path = nullptr);
102 /** Sasl global finalization
103 */
104 static void FinalizeLibrary();
105
106 signals:
107
108 /**
109 * Username and/or password has not been set.
110 */
111 void needCredentials();
112 /**
113 * Authentification was successful.
114 */
115 void loginSuccessful();
116 /**
117 * Authentification was not successful.
118 * See getErrorMessage().
119 */
120 void loginFailed();
121
122 private:
123 13 Q_DECLARE_PRIVATE(LoginManager);
124 Q_DISABLE_COPY(LoginManager);
125 LoginManager& operator=(LoginManager&&) = delete;
126 LoginManager(LoginManager&&) = delete;
127
128 QScopedPointer<LoginManagerPrivate> d_ptr;
129 friend Process;
130 };
131
132 } // namespace QtPdCom
133
134 #endif // QTPDCOM_LOGINMANAGER_H
135