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 QCA_EXPORT QByteArray methodReturnType(const QMetaObject * obj,
102  const QByteArray & method,
103  const QList<QByteArray> argTypes);
104 
146 QCA_EXPORT bool invokeMethodWithVariants(QObject * obj,
147  const QByteArray & method,
148  const QVariantList &args,
149  QVariant * ret,
150  Qt::ConnectionType type = Qt::AutoConnection);
151 
278 class QCA_EXPORT SyncThread : public QThread
279 {
280  Q_OBJECT
281 public:
287  SyncThread(QObject *parent = nullptr);
288 
294  ~SyncThread() override;
295 
301  void start();
302 
308  void stop();
309 
328  QVariant
329  call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = nullptr);
330 
331 protected:
335  virtual void atStart() = 0;
336 
340  virtual void atEnd() = 0;
341 
345  void run() override;
346 
347 private:
348  Q_DISABLE_COPY(SyncThread)
349 
350  class Private;
351  friend class Private;
352  Private *d;
353 };
354 
360 class QCA_EXPORT Synchronizer : public QObject
361 {
362  Q_OBJECT
363 public:
369  Synchronizer(QObject *parent);
370  ~Synchronizer() override;
371 
379  bool waitForCondition(int msecs = -1);
380 
384  void conditionMet();
385 
386 private:
387  Q_DISABLE_COPY(Synchronizer)
388 
389  class Private;
390  Private *d;
391 };
392 
408 class QCA_EXPORT DirWatch : public QObject
409 {
410  Q_OBJECT
411 public:
419  explicit DirWatch(const QString &dir = QString(), QObject *parent = nullptr);
420  ~DirWatch() override;
421 
425  QString dirName() const;
426 
432  void setDirName(const QString &dir);
433 
434 Q_SIGNALS:
441  void changed();
442 
443 private:
444  Q_DISABLE_COPY(DirWatch)
445 
446  class Private;
447  friend class Private;
448  Private *d;
449 };
450 
466 class QCA_EXPORT FileWatch : public QObject
467 {
468  Q_OBJECT
469 public:
477  explicit FileWatch(const QString &file = QString(), QObject *parent = nullptr);
478  ~FileWatch() override;
479 
483  QString fileName() const;
484 
490  void setFileName(const QString &file);
491 
492 Q_SIGNALS:
497  void changed();
498 
499 private:
500  Q_DISABLE_COPY(FileWatch)
501 
502  class Private;
503  friend class Private;
504  Private *d;
505 };
506 
507 class ConsolePrivate;
508 class ConsoleReferencePrivate;
509 class ConsoleReference;
510 
559 class QCA_EXPORT Console : public QObject
560 {
561  Q_OBJECT
562 public:
566  enum Type
567  {
568  Tty,
569  Stdio
570  };
575  {
577  ReadWrite
578  };
579 
584  {
586  Interactive
587  };
588 
606  Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = nullptr);
607  ~Console() override;
608 
612  Type type() const;
613 
617  ChannelMode channelMode() const;
618 
622  TerminalMode terminalMode() const;
623 
629  static bool isStdinRedirected();
630 
636  static bool isStdoutRedirected();
637 
644  static Console *ttyInstance();
645 
652  static Console *stdioInstance();
653 
659  void release();
660 
665  QByteArray bytesLeftToRead();
666 
671  QByteArray bytesLeftToWrite();
672 
673 private:
674  Q_DISABLE_COPY(Console)
675 
676  friend class ConsolePrivate;
677  ConsolePrivate *d;
678 
679  friend class ConsoleReference;
680 };
681 
691 class QCA_EXPORT ConsoleReference : public QObject
692 {
693  Q_OBJECT
694 public:
699  {
700  SecurityDisabled,
701  SecurityEnabled
702  };
703 
709  ConsoleReference(QObject *parent = nullptr);
710  ~ConsoleReference() override;
711 
725  bool start(Console *console, SecurityMode mode = SecurityDisabled);
726 
730  void stop();
731 
737  Console *console() const;
738 
745  SecurityMode securityMode() const;
746 
756  QByteArray read(int bytes = -1);
757 
766  void write(const QByteArray &a);
767 
776  SecureArray readSecure(int bytes = -1);
777 
785  void writeSecure(const SecureArray &a);
786 
793  void closeOutput();
794 
799  int bytesAvailable() const;
800 
805  int bytesToWrite() const;
806 
807 Q_SIGNALS:
812  void readyRead();
813 
821  void bytesWritten(int bytes);
822 
826  void inputClosed();
827 
831  void outputClosed();
832 
833 private:
834  Q_DISABLE_COPY(ConsoleReference)
835 
836  friend class ConsoleReferencePrivate;
837  ConsoleReferencePrivate *d;
838 
839  friend class Console;
840 };
841 
862 class QCA_EXPORT ConsolePrompt : public QObject
863 {
864  Q_OBJECT
865 public:
871  ConsolePrompt(QObject *parent = nullptr);
872  ~ConsolePrompt() override;
873 
883  void getHidden(const QString &promptStr);
884 
890  void getChar();
891 
898  void waitForFinished();
899 
907  SecureArray result() const;
908 
916  QChar resultChar() const;
917 
918 Q_SIGNALS:
928  void finished();
929 
930 private:
931  Q_DISABLE_COPY(ConsolePrompt)
932 
933  class Private;
934  friend class Private;
935  Private *d;
936 };
937 
938 class AbstractLogDevice;
939 
961 class QCA_EXPORT Logger : public QObject
962 {
963  Q_OBJECT
964 public:
971  enum Severity
972  {
973  Quiet = 0,
974  Emergency = 1,
975  Alert = 2,
976  Critical = 3,
977  Error = 4,
978  Warning = 5,
979  Notice = 6,
980  Information = 7,
981  Debug = 8
982  };
983 
989  inline Severity level() const
990  {
991  return m_logLevel;
992  }
993 
1001  void setLevel(Severity level);
1002 
1008  void logTextMessage(const QString &message, Severity = Information);
1009 
1019  void logBinaryMessage(const QByteArray &blob, Severity = Information);
1020 
1026  void registerLogDevice(AbstractLogDevice *logger);
1027 
1035  void unregisterLogDevice(const QString &loggerName);
1036 
1040  QStringList currentLogDevices() const;
1041 
1042 private:
1043  Q_DISABLE_COPY(Logger)
1044 
1045  friend class Global;
1046 
1050  Logger();
1051 
1052  ~Logger() override;
1053 
1054  QStringList m_loggerNames;
1055  QList<AbstractLogDevice *> m_loggers;
1056  Severity m_logLevel;
1057 };
1058 
1066 class QCA_EXPORT AbstractLogDevice : public QObject
1067 {
1068  Q_OBJECT
1069 public:
1073  QString name() const;
1074 
1085  virtual void logTextMessage(const QString &message, Logger::Severity severity);
1086 
1097  virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
1098 
1099 protected:
1106  explicit AbstractLogDevice(const QString &name, QObject *parent = nullptr);
1107 
1108  ~AbstractLogDevice() override = 0;
1109 
1110 private:
1111  Q_DISABLE_COPY(AbstractLogDevice)
1112 
1113  class Private;
1114  Private *d;
1115 
1116  QString m_name;
1117 };
1118 
1119 }
1120 
1121 #endif
QCA_EXPORT Logger * logger()
Return a reference to the QCA Logger, which is used for diagnostics and error recording.
Console prompt handler.
Definition: qca_support.h:862
Convenience class to run a thread and interact with it synchronously.
Definition: qca_support.h:278
A simple logging system.
Definition: qca_support.h:961
TerminalMode
The nature of the console operation.
Definition: qca_support.h:583
Type
The type of console object.
Definition: qca_support.h:566
QCA Console system
Definition: qca_support.h:559
Support class to monitor a file for activity.
Definition: qca_support.h:466
physical console
Definition: qca_support.h:568
Severity level() const
Get the current logging level.
Definition: qca_support.h:989
Support class to monitor a directory for activity.
Definition: qca_support.h:408
Preprocessor magic to allow export of library symbols.
Read only (equivalent to stdin)
Definition: qca_support.h:576
Manager for a Console.
Definition: qca_support.h:691
use default terminal settings
Definition: qca_support.h:585
QCA - the Qt Cryptographic Architecture.
Definition: qca_basic.h:41
Enable synchronization between two threads.
Definition: qca_support.h:360
An abstract log device.
Definition: qca_support.h:1066
Secure array of bytes.
Definition: qca_tools.h:316
ChannelMode
The type of I/O to use with the console object.
Definition: qca_support.h:574
Severity
The severity of the message.
Definition: qca_support.h:971
Header file for "tool" classes used in QCA.
SecurityMode
The security setting to use for the Console being managed.
Definition: qca_support.h:698