/usr/include/QtCrypto/qpipe.h is in libqca2-dev 2.0.3-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | /*
* Copyright (C) 2003-2007 Justin Karneges <justin@affinix.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**
\file qpipe.h
Header file for the QPipe FIFO class
\note You should not use this header directly from an
application. You should just use <tt> \#include \<QtCrypto>
</tt> instead.
*/
#ifndef QPIPE_H
#define QPIPE_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef QPIPE_NO_SECURE
# define QPIPE_SECURE
#endif
#ifdef QPIPE_SECURE
# include "QtCrypto"
#else
# define QCA_EXPORT
#endif
// defs adapted qprocess_p.h
#ifdef Q_OS_WIN
#include <windows.h>
typedef HANDLE Q_PIPE_ID;
#define INVALID_Q_PIPE_ID INVALID_HANDLE_VALUE
#else
typedef int Q_PIPE_ID;
#define INVALID_Q_PIPE_ID -1
#endif
#endif
// Note: for Windows console, I/O must be in UTF-8. Reads are guaranteed to
// to completely decode (no partial characters). Likewise, writes must
// not contain partial characters.
namespace QCA {
/**
\class QPipeDevice qpipe.h QtCrypto
Unbuffered direct pipe.
This class is not usually required except for very low level operations.
You should use QPipe and QPipeEnd for most applications.
\ingroup UserAPI
*/
class QCA_EXPORT QPipeDevice : public QObject
{
Q_OBJECT
public:
/**
The type of device
*/
enum Type
{
Read, ///< The pipe end can be read from
Write ///< The pipe end can be written to
};
/**
Standard constructor
\param parent the parent object to this object
*/
QPipeDevice(QObject *parent = 0);
~QPipeDevice();
/**
The Type of the pipe device (that is, read or write)
*/
Type type() const;
/**
Test whether this object corresponds to a valid pipe
*/
bool isValid() const;
/**
The low level identification for this pipe.
On Windows, this is a HANDLE. On Unix, this is a file descriptor (i.e. integer).
Code using this method should be carefully tested for portability.
\sa idAsInt
*/
Q_PIPE_ID id() const;
/**
The low level identification for this pipe, returned as an integer.
Code using this method should be carefully tested for portability.
\sa id().
*/
int idAsInt() const;
/**
Take over an existing pipe id, closing the old pipe if any.
\param id the identification of the pipe end to take over.
\param t the type of pipe end (read or write).
*/
void take(Q_PIPE_ID id, Type t);
/**
Enable the pipe for reading or writing (depending on Type)
*/
void enable();
/**
Close the pipe end.
*/
void close();
/**
Release the pipe end, but do not close it.
*/
void release();
/**
Set the pipe end to be inheritable
\note On Windows, this operation changes the pipe end id value.
\param enabled whether the pipe is inheritable (true) or not (false)
*/
bool setInheritable(bool enabled);
/**
Obtain the number of bytes available to be read.
*/
int bytesAvailable() const;
/**
Read from the pipe end
\param data where to put the data that has been read
\param maxsize the maximum number of bytes to be read.
\return the actual number of bytes read, 0 on end-of-file, or -1 on error.
*/
int read(char *data, int maxsize);
/**
Write to the pipe end.
\param data the source of the data to be written
\param size the number of bytes in the data to be written
\note the data source must remain valid
\return the number of bytes written, or -1 on error.
*/
int write(const char *data, int size);
/**
The result of a write operation
\param written if not null, this will be set to the number of
bytes written in the last operation.
\return 0 on success (all data written), or -1 on error
*/
int writeResult(int *written) const;
Q_SIGNALS:
/**
Emitted when the pipe end can be read from or written to (depending on its Type).
*/
void notify();
private:
Q_DISABLE_COPY(QPipeDevice)
class Private;
friend class Private;
Private *d;
};
/**
\class QPipeEnd qpipe.h QtCrypto
A buffered higher-level pipe end
This is either the read end or write end of a QPipe.
\ingroup UserAPI
*/
class QCA_EXPORT QPipeEnd : public QObject
{
Q_OBJECT
public:
/**
The type of error
*/
enum Error
{
ErrorEOF, ///< End of file error
ErrorBroken ///< Broken pipe error
};
/**
Standard constructor
\param parent the parent object for this object
*/
QPipeEnd(QObject *parent = 0);
~QPipeEnd();
/**
Reset the pipe end to an inactive state
*/
void reset();
/**
The type of pipe end (either read or write)
*/
QPipeDevice::Type type() const;
/**
Determine whether the pipe end is valid.
\note This does not mean the pipe is ready to be used - you
may need to call enable() first
*/
bool isValid() const;
/**
Pipe identification
*/
Q_PIPE_ID id() const;
/**
Pipe identification
*/
int idAsInt() const;
/**
Take over an existing pipe handle
\param id the pipe handle
\param t the type of the pipe (read or write)
*/
void take(Q_PIPE_ID id, QPipeDevice::Type t);
#ifdef QPIPE_SECURE
/**
Sets whether the pipe uses secure memory for read/write
Enabling this may reduce performance, and it should only be used if
sensitive data is being transmitted (such as a passphrase).
\param secure whether the pipe uses secure memory (true) or not (false).
*/
void setSecurityEnabled(bool secure);
#endif
/**
Enable the endpoint for the pipe
When an endpoint is created, it is not
able to be used until it is enabled.
*/
void enable();
/**
Close the end of the pipe
\sa closed()
*/
void close();
/**
Let go of the active pipe handle, but don't close it
Use this before destructing QPipeEnd, if you don't want the pipe
to automatically close.
*/
void release();
/**
Sets whether the pipe should be inheritable to child processes
Returns true if inheritability was successfully changed, otherwise
false.
\param enabled whether the pipe is inheritable (true) or not (false).
*/
bool setInheritable(bool enabled);
/**
Clear the contents of the pipe, and invalidate the pipe
*/
void finalize();
/**
Clear the contents of the pipe, and release the pipe
*/
void finalizeAndRelease();
/**
Determine how many bytes are available to be read.
This only makes sense at the read end of the pipe
\sa readyRead() for a signal that can be used to determine
when there are bytes available to read.
*/
int bytesAvailable() const;
/**
Returns the number of bytes pending to write
This only makes sense at the write end of the pipe
\sa bytesWritten() for a signal that can be used to determine
when bytes have been written
*/
int bytesToWrite() const;
/**
Read bytes from the pipe.
You can only call this on the read end of the pipe
If the pipe is using secure memory, you should use readSecure()
\param bytes the number of bytes to read (-1 for all
content).
*/
QByteArray read(int bytes = -1);
/**
Write bytes to the pipe.
You can only call this on the write end of the pipe.
If the pipe is using secure memory, you should use writeSecure().
\param a the array to write to the pipe
*/
void write(const QByteArray &a);
#ifdef QPIPE_SECURE
/**
Read bytes from the pipe.
You can only call this on the read end of the pipe
If the pipe is using insecure memory, you should use read()
\param bytes the number of bytes to read (-1 for all
content).
*/
SecureArray readSecure(int bytes = -1);
/**
Write bytes to the pipe.
You can only call this on the write end of the pipe.
If the pipe is using insecure memory, you should use write().
\param a the array to write to the pipe
*/
void writeSecure(const SecureArray &a);
#endif
/**
Returns any unsent bytes queued for writing
If the pipe is using secure memory, you should use
takeBytesToWriteSecure().
*/
QByteArray takeBytesToWrite();
#ifdef QPIPE_SECURE
/**
Returns any unsent bytes queued for writing
If the pipe is using insecure memory, you should use
takeBytesToWrite().
*/
SecureArray takeBytesToWriteSecure();
#endif
Q_SIGNALS:
/**
Emitted when there are bytes available to be read
from the read end of the pipe.
\sa bytesAvailable()
*/
void readyRead();
/**
Emitted when bytes have been written to the
write end of the pipe.
\param bytes the number of bytes written
*/
void bytesWritten(int bytes);
/**
Emitted when this end of the pipe is closed as a result of calling
close()
If this is the write end of the pipe and there is data still
pending to write, this signal will be emitted once all of the data
has been written.
To be notified if the other end of the pipe has been closed, see
error().
*/
void closed();
/**
Emitted when the pipe encounters an error trying to read or write,
or if the other end of the pipe has been closed
\param e the reason for error
*/
void error(QCA::QPipeEnd::Error e);
private:
Q_DISABLE_COPY(QPipeEnd)
class Private;
friend class Private;
Private *d;
};
/**
\class QPipe qpipe.h QtCrypto
A FIFO buffer (named pipe) abstraction
This class creates a full buffer, consisting of two ends
(QPipeEnd). You can obtain each end (after calling create()) using
readEnd() and writeEnd(), however you must call enable() on each end
before using the pipe.
By default, the pipe ends are not inheritable by child processes. On
Windows, the pipe is created with inheritability disabled. On Unix, the
FD_CLOEXEC flag is set on each end's file descriptor.
\ingroup UserAPI
*/
class QCA_EXPORT QPipe
{
public:
/**
Standard constructor
\note You must call create() before using the pipe ends.
\param parent the parent object for this object
*/
QPipe(QObject *parent = 0);
~QPipe();
/**
Reset the pipe.
At this point, the readEnd() and writeEnd() calls
will no longer be valid.
*/
void reset();
#ifdef QPIPE_SECURE
/**
Create the pipe
\param secure whether to use secure memory (true) or not (false)
*/
bool create(bool secure = false);
#else
/**
Create the pipe
*/
bool create();
#endif
/**
The read end of the pipe.
*/
QPipeEnd & readEnd() { return i; }
/**
The write end of the pipe.
*/
QPipeEnd & writeEnd() { return o; }
private:
Q_DISABLE_COPY(QPipe)
QPipeEnd i, o;
};
}
#endif
|