Qt Cryptographic Architecture
include
QtCrypto
qpipe.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2003-2007 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
17
* 02110-1301 USA
18
*
19
*/
20
31
#ifndef QPIPE_H
32
#define QPIPE_H
33
34
#ifndef DOXYGEN_SHOULD_SKIP_THIS
35
36
#ifndef QPIPE_NO_SECURE
37
#define QPIPE_SECURE
38
#endif
39
40
#ifdef QPIPE_SECURE
41
#include "QtCrypto"
42
#else
43
#define QCA_EXPORT
44
#endif
45
46
// defs adapted qprocess_p.h
47
#ifdef Q_OS_WIN
48
#include <windows.h>
49
typedef
HANDLE Q_PIPE_ID;
50
#define INVALID_Q_PIPE_ID INVALID_HANDLE_VALUE
51
#else
52
typedef
int
Q_PIPE_ID;
53
#define INVALID_Q_PIPE_ID -1
54
#endif
55
56
#endif
57
58
// Note: for Windows console, I/O must be in UTF-8. Reads are guaranteed to
59
// to completely decode (no partial characters). Likewise, writes must
60
// not contain partial characters.
61
62
namespace
QCA
{
63
74
class
QCA_EXPORT
QPipeDevice
:
public
QObject
75
{
76
Q_OBJECT
77
public
:
81
enum
Type
82
{
83
Read
,
84
Write
85
};
86
92
QPipeDevice
(
QObject
*parent =
nullptr
);
93
~
QPipeDevice
()
override
;
94
98
Type type()
const
;
99
103
bool
isValid()
const
;
104
114
Q_PIPE_ID id()
const
;
115
123
int
idAsInt()
const
;
124
131
void
take(Q_PIPE_ID
id
, Type t);
132
136
void
enable();
137
141
void
close();
142
146
void
release();
147
155
bool
setInheritable(
bool
enabled);
156
160
int
bytesAvailable()
const
;
161
170
int
read(
char
*data,
int
maxsize);
171
182
int
write(
const
char
*data,
int
size);
183
192
int
writeResult(
int
*written)
const
;
193
194
Q_SIGNALS:
198
void
notify();
199
200
private
:
201
Q_DISABLE_COPY(
QPipeDevice
)
202
203
class
Private;
204
friend
class
Private;
205
Private *d;
206
};
207
217
class
QCA_EXPORT
QPipeEnd
:
public
QObject
218
{
219
Q_OBJECT
220
public
:
224
enum
Error
225
{
226
ErrorEOF
,
227
ErrorBroken
228
};
229
235
QPipeEnd
(
QObject
*parent =
nullptr
);
236
237
~
QPipeEnd
()
override
;
238
242
void
reset();
243
247
QPipeDevice::Type
type()
const
;
248
255
bool
isValid()
const
;
256
260
Q_PIPE_ID id()
const
;
261
265
int
idAsInt()
const
;
266
273
void
take(Q_PIPE_ID
id
,
QPipeDevice::Type
t);
274
275
#ifdef QPIPE_SECURE
276
284
void
setSecurityEnabled(
bool
secure);
285
#endif
286
293
void
enable();
294
300
void
close();
301
308
void
release();
309
318
bool
setInheritable(
bool
enabled);
319
323
void
finalize();
324
328
void
finalizeAndRelease();
329
338
int
bytesAvailable()
const
;
339
348
int
bytesToWrite()
const
;
349
360
QByteArray read(
int
bytes = -1);
361
371
void
write(
const
QByteArray &a);
372
373
#ifdef QPIPE_SECURE
374
384
SecureArray
readSecure(
int
bytes = -1);
385
395
void
writeSecure(
const
SecureArray
&a);
396
#endif
397
404
QByteArray takeBytesToWrite();
405
406
#ifdef QPIPE_SECURE
407
413
SecureArray
takeBytesToWriteSecure();
414
#endif
415
416
Q_SIGNALS:
423
void
readyRead();
424
431
void
bytesWritten(
int
bytes);
432
444
void
closed();
445
452
void
error(
QCA::QPipeEnd::Error
e);
453
454
private
:
455
Q_DISABLE_COPY(
QPipeEnd
)
456
457
class
Private;
458
friend
class
Private;
459
Private *d;
460
};
461
478
class
QCA_EXPORT
QPipe
479
{
480
public
:
488
QPipe
(
QObject
*parent =
nullptr
);
489
490
~
QPipe
();
491
498
void
reset();
499
500
#ifdef QPIPE_SECURE
501
506
bool
create(
bool
secure =
false
);
507
#else
508
511
bool
create();
512
#endif
513
517
QPipeEnd
&
readEnd
()
518
{
519
return
i;
520
}
521
525
QPipeEnd
&
writeEnd
()
526
{
527
return
o;
528
}
529
530
private
:
531
Q_DISABLE_COPY(
QPipe
)
532
533
QPipeEnd
i, o;
534
};
535
536
}
537
538
#endif
QObject
QCA::QPipeDevice
Definition:
qpipe.h:74
QCA::QPipeDevice::Type
Type
The type of device.
Definition:
qpipe.h:81
QCA::QPipe
Definition:
qpipe.h:478
QCA
QCA - the Qt Cryptographic Architecture.
Definition:
qca_basic.h:41
QCA::QPipeEnd::ErrorEOF
@ ErrorEOF
End of file error.
Definition:
qpipe.h:226
QCA::QPipe::readEnd
QPipeEnd & readEnd()
The read end of the pipe.
Definition:
qpipe.h:517
QCA::QPipeEnd
Definition:
qpipe.h:217
QCA::SecureArray
Definition:
qca_tools.h:316
QCA::QPipeDevice::Read
@ Read
The pipe end can be read from.
Definition:
qpipe.h:83
QCA::QPipe::writeEnd
QPipeEnd & writeEnd()
The write end of the pipe.
Definition:
qpipe.h:525
QCA::QPipeEnd::Error
Error
The type of error.
Definition:
qpipe.h:224
Generated by
1.8.17