| 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 | |
| 16 | class QString; |
| 17 | class OrgKdeKPasswdServerInterface; |
| 18 | |
| 19 | namespace KIO |
| 20 | { |
| 21 | class AuthInfo; |
| 22 | } |
| 23 | |
| 24 | class KPasswdServerClientPrivate; |
| 25 | |
| 26 | /*! |
| 27 | * \class KPasswdServerClient |
| 28 | * \inmodule KIOCore |
| 29 | * |
| 30 | * \brief Interface class for kpasswdserver. |
| 31 | * |
| 32 | * KIO workers should not use this directly but via the WorkerBase API. |
| 33 | * \since 5.30 |
| 34 | */ |
| 35 | class KIOCORE_EXPORT KPasswdServerClient |
| 36 | { |
| 37 | public: |
| 38 | /*! |
| 39 | * Creates a client instance for kpasswdserver. |
| 40 | * The instance should be kept for the lifetime of the process, not created for each request. |
| 41 | */ |
| 42 | KPasswdServerClient(); |
| 43 | ~KPasswdServerClient(); |
| 44 | |
| 45 | KPasswdServerClient(const KPasswdServerClient &) = delete; |
| 46 | KPasswdServerClient &operator=(const KPasswdServerClient &) = delete; |
| 47 | |
| 48 | /*! |
| 49 | * Check if kpasswdserver has cached authentication information regarding |
| 50 | * an AuthInfo object. |
| 51 | * |
| 52 | * \a info information to check cache for |
| 53 | * |
| 54 | * \a windowId used as parent for dialogs, comes from QWidget::winId() on the toplevel widget |
| 55 | * |
| 56 | * \a usertime the X11 user time from the calling application, so that any dialog |
| 57 | * (e.g. wallet password) respects focus-prevention rules. |
| 58 | * Use KUserTimestamp::userTimestamp in the GUI application from which the request originates. |
| 59 | * |
| 60 | * Returns \c true if kpasswdserver provided cached information, false if not |
| 61 | * |
| 62 | * Info will contain the results of the check. To see if |
| 63 | * information was retrieved, check info.isModified(). |
| 64 | */ |
| 65 | bool checkAuthInfo(KIO::AuthInfo *info, qlonglong windowId, qlonglong usertime); |
| 66 | |
| 67 | /*! |
| 68 | * Let kpasswdserver ask the user for authentication information. |
| 69 | * |
| 70 | * \a info information to query the user for |
| 71 | * |
| 72 | * \a errorMsg error message that will be displayed to the user |
| 73 | * |
| 74 | * \a windowId used as parent for dialogs, comes from QWidget::winId() on the toplevel widget |
| 75 | * |
| 76 | * \a usertime the X11 user time from the calling application, so that the dialog |
| 77 | * (e.g. wallet password) respects focus-prevention rules. |
| 78 | * Use KUserTimestamp::userTimestamp in the GUI application from which the request originates. |
| 79 | * |
| 80 | * Returns a KIO error code: KJob::NoError (0) on success, otherwise ERR_USER_CANCELED if the user canceled, |
| 81 | * or ERR_PASSWD_SERVER if we couldn't communicate with kpasswdserver. |
| 82 | * |
| 83 | * If NoError is returned, then \a info will contain the authentication information that was retrieved. |
| 84 | */ |
| 85 | int queryAuthInfo(KIO::AuthInfo *info, const QString &errorMsg, qlonglong windowId, qlonglong usertime); |
| 86 | |
| 87 | /*! |
| 88 | * Manually add authentication information to kpasswdserver's cache. |
| 89 | * |
| 90 | * \a info information to add |
| 91 | * |
| 92 | * \a windowId used as parent window for dialogs, comes from QWidget::winId() on the toplevel widget |
| 93 | */ |
| 94 | void addAuthInfo(const KIO::AuthInfo &info, qlonglong windowId); |
| 95 | |
| 96 | /*! |
| 97 | * Manually remove authentication information from kpasswdserver's cache. |
| 98 | * |
| 99 | * \a host hostname of the information to remove |
| 100 | * |
| 101 | * \a protocol protocol to remove information for |
| 102 | * |
| 103 | * \a user username to remove information for |
| 104 | */ |
| 105 | void removeAuthInfo(const QString &host, const QString &protocol, const QString &user); |
| 106 | |
| 107 | private: |
| 108 | OrgKdeKPasswdServerInterface *m_interface; |
| 109 | std::unique_ptr<KPasswdServerClientPrivate> d; |
| 110 | }; |
| 111 | |
| 112 | #endif |
| 113 | |