Qt Cryptographic Architecture
qca_support.h
Go to the documentation of this file.
1 /*
2  * qca_support.h - Qt Cryptographic Architecture
3  * Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
4  * Copyright (C) 2004,2005, 2007 Brad Hards <bradh@frogmouth.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22 
36 #ifndef QCA_SUPPORT_H
37 #define QCA_SUPPORT_H
38 
39 #include "qca_export.h"
40 #include "qca_tools.h"
41 #include <QByteArray>
42 #include <QList>
43 #include <QMetaObject>
44 #include <QObject>
45 #include <QString>
46 #include <QStringList>
47 #include <QThread>
48 #include <QVariant>
49 #include <QVariantList>
50 
51 namespace QCA {
52 
101 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
102 QCA_EXPORT int methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> &argTypes);
103 #else
104 QCA_EXPORT QByteArray methodReturnType(const QMetaObject * obj,
105  const QByteArray & method,
106  const QList<QByteArray> argTypes);
107 #endif
108 
150 QCA_EXPORT bool invokeMethodWithVariants(QObject * obj,
151  const QByteArray & method,
152  const QVariantList &args,
153  QVariant * ret,
154  Qt::ConnectionType type = Qt::AutoConnection);
155 
279 class QCA_EXPORT SyncThread : public QThread
280 {
281  Q_OBJECT
282 public:
288  SyncThread(QObject *parent = nullptr);
289 
295  ~SyncThread() override;
296 
302  void start();
303 
309  void stop();
310 
329  QVariant
330  call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = nullptr);
331 
332 protected:
336  virtual void atStart() = 0;
337 
341  virtual void atEnd() = 0;
342 
346  void run() override;
347 
348 private:
349  Q_DISABLE_COPY(SyncThread)
350 
351  class Private;
352  friend class Private;
353  Private *d;
354 };
355 
361 class QCA_EXPORT Synchronizer : public QObject
362 {
363  Q_OBJECT
364 public:
370  Synchronizer(QObject *parent);
371  ~Synchronizer() override;
372 
380  bool waitForCondition(int msecs = -1);
381 
385  void conditionMet();
386 
387 private:
388  Q_DISABLE_COPY(Synchronizer)
389 
390  class Private;
391  Private *d;
392 };
393 
409 class QCA_EXPORT DirWatch : public QObject
410 {
411  Q_OBJECT
412 public:
420  explicit DirWatch(const QString &dir = QString(), QObject *parent = nullptr);
421  ~DirWatch() override;
422 
426  QString dirName() const;
427 
433  void setDirName(const QString &dir);
434 
435 Q_SIGNALS:
442  void changed();
443 
444 private:
445  Q_DISABLE_COPY(DirWatch)
446 
447  class Private;
448  friend class Private;
449  Private *d;
450 };
451 
467 class QCA_EXPORT FileWatch : public QObject
468 {
469  Q_OBJECT
470 public:
478  explicit FileWatch(const QString &file = QString(), QObject *parent = nullptr);
479  ~FileWatch() override;
480 
484  QString fileName() const;
485 
491  void setFileName(const QString &file);
492 
493 Q_SIGNALS:
498  void changed();
499 
500 private:
501  Q_DISABLE_COPY(FileWatch)
502 
503  class Private;
504  friend class Private;
505  Private *d;
506 };
507 
508 class ConsolePrivate;
509 class ConsoleReferencePrivate;
510 class ConsoleReference;
511 
560 class QCA_EXPORT Console : public QObject
561 {
562  Q_OBJECT
563 public:
567  enum Type
568  {
569  Tty,
570  Stdio
571  };
576  {
578  ReadWrite
579  };
580 
585  {
587  Interactive
588  };
589 
607  Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = nullptr);
608  ~Console() override;
609 
613  Type type() const;
614 
618  ChannelMode channelMode() const;
619 
623  TerminalMode terminalMode() const;
624 
630  static bool isStdinRedirected();
631 
637  static bool isStdoutRedirected();
638 
645  static Console *ttyInstance();
646 
653  static Console *stdioInstance();
654 
660  void release();
661 
666  QByteArray bytesLeftToRead();
667 
672  QByteArray bytesLeftToWrite();
673 
674 private:
675  Q_DISABLE_COPY(Console)
676 
677  friend class ConsolePrivate;
678  ConsolePrivate *d;
679 
680  friend class ConsoleReference;
681 };
682 
692 class QCA_EXPORT ConsoleReference : public QObject
693 {
694  Q_OBJECT
695 public:
700  {
701  SecurityDisabled,
702  SecurityEnabled
703  };
704 
710  ConsoleReference(QObject *parent = nullptr);
711  ~ConsoleReference() override;
712 
726  bool start(Console *console, SecurityMode mode = SecurityDisabled);
727 
731  void stop();
732 
738  Console *console() const;
739 
746  SecurityMode securityMode() const;
747 
757  QByteArray read(int bytes = -1);
758 
767  void write(const QByteArray &a);
768 
777  SecureArray readSecure(int bytes = -1);
778 
786  void writeSecure(const SecureArray &a);
787 
794  void closeOutput();
795 
800  int bytesAvailable() const;
801 
806  int bytesToWrite() const;
807 
808 Q_SIGNALS:
813  void readyRead();
814 
822  void bytesWritten(int bytes);
823 
827  void inputClosed();
828 
832  void outputClosed();
833 
834 private:
835  Q_DISABLE_COPY(ConsoleReference)
836 
837  friend class ConsoleReferencePrivate;
838  ConsoleReferencePrivate *d;
839 
840  friend class Console;
841 };
842 
863 class QCA_EXPORT ConsolePrompt : public QObject
864 {
865  Q_OBJECT
866 public:
872  ConsolePrompt(QObject *parent = nullptr);
873  ~ConsolePrompt() override;
874 
884  void getHidden(const QString &promptStr);
885 
891  void getChar();
892 
899  void waitForFinished();
900 
908  SecureArray result() const;
909 
917  QChar resultChar() const;
918 
919 Q_SIGNALS:
929  void finished();
930 
931 private:
932  Q_DISABLE_COPY(ConsolePrompt)
933 
934  class Private;
935  friend class Private;
936  Private *d;
937 };
938 
939 class AbstractLogDevice;
940 
962 class QCA_EXPORT Logger : public QObject
963 {
964  Q_OBJECT
965 public:
972  enum Severity
973  {
974  Quiet = 0,
975  Emergency = 1,
976  Alert = 2,
977  Critical = 3,
978  Error = 4,
979  Warning = 5,
980  Notice = 6,
981  Information = 7,
982  Debug = 8
983  };
984 
990  inline Severity level() const
991  {
992  return m_logLevel;
993  }
994 
1002  void setLevel(Severity level);
1003 
1009  void logTextMessage(const QString &message, Severity = Information);
1010 
1020  void logBinaryMessage(const QByteArray &blob, Severity = Information);
1021 
1027  void registerLogDevice(AbstractLogDevice *logger);
1028 
1036  void unregisterLogDevice(const QString &loggerName);
1037 
1041  QStringList currentLogDevices() const;
1042 
1043 private:
1044  Q_DISABLE_COPY(Logger)
1045 
1046  friend class Global;
1047 
1051  Logger();
1052 
1053  ~Logger() override;
1054 
1055  QStringList m_loggerNames;
1056  QList<AbstractLogDevice *> m_loggers;
1057  Severity m_logLevel;
1058 };
1059 
1067 class QCA_EXPORT AbstractLogDevice : public QObject
1068 {
1069  Q_OBJECT
1070 public:
1074  QString name() const;
1075 
1086  virtual void logTextMessage(const QString &message, Logger::Severity severity);
1087 
1098  virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
1099 
1100 protected:
1107  explicit AbstractLogDevice(const QString &name, QObject *parent = nullptr);
1108 
1109  ~AbstractLogDevice() override = 0;
1110 
1111 private:
1112  Q_DISABLE_COPY(AbstractLogDevice)
1113 
1114  class Private;
1115  Private *d;
1116 
1117  QString m_name;
1118 };
1119 
1120 }
1121 
1122 #endif
QCA::Logger
Definition: qca_support.h:962
QObject
QCA::Console::ChannelMode
ChannelMode
The type of I/O to use with the console object.
Definition: qca_support.h:575
QCA::Console::TerminalMode
TerminalMode
The nature of the console operation.
Definition: qca_support.h:584
QCA::Console::Type
Type
The type of console object.
Definition: qca_support.h:567
QCA::Logger::Severity
Severity
The severity of the message.
Definition: qca_support.h:972
QCA::ConsoleReference
Definition: qca_support.h:692
QCA
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
QCA::Logger::level
Severity level() const
Get the current logging level.
Definition: qca_support.h:990
QList
qca_export.h
QCA::ConsolePrompt
Definition: qca_support.h:863
QCA::Console::Read
@ Read
Read only (equivalent to stdin)
Definition: qca_support.h:577
QCA::Console::Tty
@ Tty
physical console
Definition: qca_support.h:569
QCA::DirWatch
Definition: qca_support.h:409
QCA::logger
QCA_EXPORT Logger * logger()
Return a reference to the QCA Logger, which is used for diagnostics and error recording.
QCA::SecureArray
Definition: qca_tools.h:316
QCA::SyncThread
Definition: qca_support.h:279
QCA::Synchronizer
Definition: qca_support.h:361
QCA::AbstractLogDevice
Definition: qca_support.h:1067
QCA::Console::Default
@ Default
use default terminal settings
Definition: qca_support.h:586
QCA::FileWatch
Definition: qca_support.h:467
QThread
QCA::Console
Definition: qca_support.h:560
qca_tools.h
QCA::ConsoleReference::SecurityMode
SecurityMode
The security setting to use for the Console being managed.
Definition: qca_support.h:699