File indexing completed on 2024-12-01 08:10:14

0001 /*
0002     SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef OPENCONNECTAUTHWORKERTHREAD_H
0008 #define OPENCONNECTAUTHWORKERTHREAD_H
0009 
0010 extern "C" {
0011 #include <openconnect.h>
0012 }
0013 
0014 #if OPENCONNECT_CHECK_VER(3, 0)
0015 #define NEWGROUP_SUPPORTED 1
0016 #define AUTHGROUP_OPT(form) (void *)(form)->authgroup_opt
0017 #define AUTHGROUP_SELECTION(form) (form)->authgroup_selection
0018 #define FORMCHOICE(sopt, i) ((sopt)->choices[i])
0019 #define IGNORE_OPT(opt) ((opt)->flags & OC_FORM_OPT_IGNORE)
0020 #else
0021 #define NEWGROUP_SUPPORTED 0
0022 #define AUTHGROUP_OPT(form) nullptr
0023 #define AUTHGROUP_SELECTION(form) 0
0024 #define FORMCHOICE(sopt, i) (&(sopt)->choices[i])
0025 #define IGNORE_OPT(opt) 0
0026 
0027 #define OC_FORM_RESULT_ERR -1
0028 #define OC_FORM_RESULT_OK 0
0029 #define OC_FORM_RESULT_CANCELLED 1
0030 #define OC_FORM_RESULT_NEWGROUP 2
0031 #endif
0032 
0033 #if OPENCONNECT_CHECK_VER(4, 0)
0034 #define OC3DUP(x) (x)
0035 #else
0036 #define openconnect_set_option_value(opt, val)                                                                                                                 \
0037     do {                                                                                                                                                       \
0038         struct oc_form_opt *_o = (opt);                                                                                                                        \
0039         free(_o->value);                                                                                                                                       \
0040         _o->value = strdup(val);                                                                                                                               \
0041     } while (0)
0042 #define openconnect_free_cert_info(v, x) ::free(x)
0043 #define OC3DUP(x) strdup(x)
0044 #endif
0045 
0046 #include <QThread>
0047 
0048 class QMutex;
0049 class QSemaphore;
0050 class QWaitCondition;
0051 struct openconnect_info;
0052 
0053 class OpenconnectAuthWorkerThread : public QThread
0054 {
0055     Q_OBJECT
0056     friend class OpenconnectAuthStaticWrapper;
0057 
0058 public:
0059     OpenconnectAuthWorkerThread(QMutex *, QWaitCondition *, bool *, bool *, int);
0060     ~OpenconnectAuthWorkerThread() override;
0061     struct openconnect_info *getOpenconnectInfo();
0062 
0063 Q_SIGNALS:
0064     void validatePeerCert(const QString &, const QString &, const QString &, bool *);
0065     void processAuthForm(struct oc_auth_form *);
0066     void updateLog(const QString &, const int &);
0067     void writeNewConfig(const QString &);
0068     void cookieObtained(const int &);
0069     void initTokens();
0070     void openWebEngine(const char *, QSemaphore *);
0071 
0072 protected:
0073     void run() override;
0074 
0075 private:
0076     int writeNewConfig(const char *, int);
0077     int validatePeerCert(void *, const char *);
0078     int processAuthFormP(struct oc_auth_form *);
0079     void writeProgress(int level, const char *, va_list);
0080     int openWebEngineP(struct openconnect_info *, const char *, void *);
0081     int openUri(struct openconnect_info *, const char *, void *);
0082 
0083     QMutex *m_mutex;
0084     QWaitCondition *m_waitForUserInput;
0085     bool *m_userDecidedToQuit;
0086     bool *m_formGroupChanged;
0087     struct openconnect_info *m_openconnectInfo;
0088 };
0089 
0090 #endif