1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2009 Michael Leupold <lemma@confuego.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef KPASSWDSERVERCLIENT_H
9#define KPASSWDSERVERCLIENT_H
10
11#include <kiocore_export.h>
12#include <qglobal.h>
13
14#include <memory>
15
16class QString;
17class OrgKdeKPasswdServerInterface;
18
19namespace KIO
20{
21class AuthInfo;
22}
23
24class KPasswdServerClientPrivate;
25
26/**
27 * @class KPasswdServerClient kpasswdserverclient.h <KPasswdServerClient>
28 *
29 * Interface class for kpasswdserver.
30 * KIO workers should not use this directly but via the WorkerBase API.
31 * @since 5.30
32 */
33class KIOCORE_EXPORT KPasswdServerClient
34{
35public:
36 /**
37 * Creates a client instance for kpasswdserver.
38 * The instance should be kept for the lifetime of the process, not created for each request.
39 */
40 KPasswdServerClient();
41 /**
42 * Destructor.
43 */
44 ~KPasswdServerClient();
45
46 KPasswdServerClient(const KPasswdServerClient &) = delete;
47 KPasswdServerClient &operator=(const KPasswdServerClient &) = delete;
48
49 /**
50 * Check if kpasswdserver has cached authentication information regarding
51 * an AuthInfo object.
52 * @param info information to check cache for
53 * @param windowId used as parent for dialogs, comes from QWidget::winId() on the toplevel widget
54 * @param usertime the X11 user time from the calling application, so that any dialog
55 * (e.g. wallet password) respects focus-prevention rules.
56 * Use KUserTimestamp::userTimestamp in the GUI application from which the request originates.
57 * @return true if kpasswdserver provided cached information, false if not
58 * @remarks info will contain the results of the check. To see if
59 * information was retrieved, check info.isModified().
60 */
61 bool checkAuthInfo(KIO::AuthInfo *info, qlonglong windowId, qlonglong usertime);
62
63 /**
64 * Let kpasswdserver ask the user for authentication information.
65 * @param info information to query the user for
66 * @param errorMsg error message that will be displayed to the user
67 * @param windowId used as parent for dialogs, comes from QWidget::winId() on the toplevel widget
68 * @param usertime the X11 user time from the calling application, so that the dialog
69 * (e.g. wallet password) respects focus-prevention rules.
70 * Use KUserTimestamp::userTimestamp in the GUI application from which the request originates.
71 * @return a KIO error code: KJob::NoError (0) on success, otherwise ERR_USER_CANCELED if the user canceled,
72 * or ERR_PASSWD_SERVER if we couldn't communicate with kpasswdserver.
73 * @remarks If NoError is returned, then @p info will contain the authentication information that was retrieved.
74 */
75 int queryAuthInfo(KIO::AuthInfo *info, const QString &errorMsg, qlonglong windowId, qlonglong usertime);
76
77 /**
78 * Manually add authentication information to kpasswdserver's cache.
79 * @param info information to add
80 * @param windowId used as parent window for dialogs, comes from QWidget::winId() on the toplevel widget
81 */
82 void addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId);
83
84 /**
85 * Manually remove authentication information from kpasswdserver's cache.
86 * @param host hostname of the information to remove
87 * @param protocol protocol to remove information for
88 * @param user username to remove information for
89 */
90 void removeAuthInfo(const QString &host, const QString &protocol, const QString &user);
91
92private:
93 OrgKdeKPasswdServerInterface *m_interface;
94 std::unique_ptr<KPasswdServerClientPrivate> d;
95};
96
97#endif
98

source code of kio/src/core/kpasswdserverclient.h