1 | /* |
2 | * Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2.1 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
17 | * |
18 | */ |
19 | |
20 | #ifndef GPGPROC_H |
21 | #define GPGPROC_H |
22 | |
23 | #include "qpipe.h" |
24 | |
25 | namespace gpgQCAPlugin { |
26 | |
27 | // GPGProc - executes gpg and provides access to all 6 channels. NormalMode |
28 | // enables stdout, stderr, and stdin. ExtendedMode has those 3 plus status |
29 | // aux, and command. The aux channel is connected to the '-&?' argument. |
30 | // The debug() signal, as well as stderr, can be used for diagnostic text. |
31 | class GPGProc : public QObject |
32 | { |
33 | Q_OBJECT |
34 | public: |
35 | enum Error |
36 | { |
37 | FailedToStart, |
38 | UnexpectedExit, |
39 | ErrorWrite |
40 | }; |
41 | enum Mode |
42 | { |
43 | NormalMode, |
44 | ExtendedMode |
45 | }; |
46 | GPGProc(QObject *parent = nullptr); |
47 | ~GPGProc() override; |
48 | |
49 | void reset(); |
50 | |
51 | bool isActive() const; |
52 | void start(const QString &bin, const QStringList &args, Mode m = ExtendedMode); |
53 | |
54 | QByteArray readStdout(); |
55 | QByteArray readStderr(); |
56 | QStringList readStatusLines(); |
57 | void writeStdin(const QByteArray &a); |
58 | void writeAux(const QByteArray &a); |
59 | #ifdef QPIPE_SECURE |
60 | void writeCommand(const QCA::SecureArray &a); |
61 | #else |
62 | void writeCommand(const QByteArray &a); |
63 | #endif |
64 | void closeStdin(); |
65 | void closeAux(); |
66 | void closeCommand(); |
67 | |
68 | Q_SIGNALS: |
69 | void error(gpgQCAPlugin::GPGProc::Error error); |
70 | void finished(int exitCode); |
71 | void readyReadStdout(); |
72 | void readyReadStderr(); |
73 | void readyReadStatusLines(); |
74 | void bytesWrittenStdin(int bytes); |
75 | void bytesWrittenAux(int bytes); |
76 | void bytesWrittenCommand(int bytes); |
77 | void debug(const QString &str); // not signal-safe |
78 | |
79 | private: |
80 | class Private; |
81 | friend class Private; |
82 | Private *d; |
83 | }; |
84 | |
85 | } |
86 | |
87 | #endif |
88 | |