Qt 4.8
qtransportauth_qws.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTRANSPORTAUTH_QWS_H
43 #define QTRANSPORTAUTH_QWS_H
44 
45 #include <QtCore/qglobal.h>
46 
47 #if !defined(QT_NO_SXE) || defined(SXE_INSTALLER)
48 
49 #include <QtCore/qobject.h>
50 #include <QtCore/qhash.h>
51 #include <QtCore/qstring.h>
52 #include <QtCore/qbuffer.h>
53 #include <QtCore/qpointer.h>
54 
55 #include <sys/types.h>
56 
58 
60 
61 QT_MODULE(Gui)
62 
63 class QAuthDevice;
64 class QWSClient;
65 class QIODevice;
67 class QMutex;
68 
70 {
71  Q_OBJECT
72 public:
73  static QTransportAuth *getInstance();
74 
75  enum Result {
76  // Error codes
77  Pending = 0x00,
78  TooSmall = 0x01,
79  CacheMiss = 0x02,
80  NoMagic = 0x03,
81  NoSuchKey = 0x04,
82  FailMatch = 0x05,
83  OutOfDate = 0x06,
84  // reserved for expansion
85  Success = 0x1e,
86  ErrMask = 0x1f,
87 
88  // Verification codes
89  Allow = 0x20,
90  Deny = 0x40,
91  Ask = 0x60,
92  // reserved
93  StatusMask = 0xe0
94  };
95 
96  enum Properties {
97  Trusted = 0x01,
98  Connection = 0x02,
99  UnixStreamSock = 0x04,
100  SharedMemory = 0x08,
101  MessageQueue = 0x10,
102  UDP = 0x20,
103  TCP = 0x40,
104  UserDefined = 0x80,
105  TransportType = 0xfc
106  };
107 
108  struct Data
109  {
110  Data() { processId = -1; }
111  Data( unsigned char p, int d )
112  : properties( p )
113  , descriptor( d )
114  , processId( -1 )
115  {
116  if (( properties & TransportType ) == TCP ||
117  ( properties & TransportType ) == UnixStreamSock )
118  properties |= Connection;
119  }
120 
121  unsigned char properties;
122  unsigned char progId;
123  unsigned char status;
124  unsigned int descriptor; // socket fd or shmget key
125  pid_t processId;
126 
127  bool trusted() const;
128  void setTrusted( bool );
129  bool connection() const;
130  void setConnection( bool );
131  };
132 
133  static const char *errorString( const QTransportAuth::Data & );
134 
135  QTransportAuth::Data *connectTransport( unsigned char, int );
136 
137  QAuthDevice *authBuf( QTransportAuth::Data *, QIODevice * );
138  QAuthDevice *recvBuf( QTransportAuth::Data *, QIODevice * );
139  QIODevice *passThroughByClient( QWSClient * ) const;
140 
141  void setKeyFilePath( const QString & );
142  QString keyFilePath() const;
143  const unsigned char *getClientKey( unsigned char progId );
144  void invalidateClientKeyCache();
145  QMutex *getKeyFileMutex();
146  void setLogFilePath( const QString & );
147  QString logFilePath() const;
148  void setPackageRegistry( QObject *registry );
149  bool isDiscoveryMode() const;
150  void setProcessKey( const char * );
151  void setProcessKey( const char *, const char * );
152  void registerPolicyReceiver( QObject * );
153  void unregisterPolicyReceiver( QObject * );
154 
155  bool authToMessage( QTransportAuth::Data &d, char *hdr, const char *msg, int msgLen );
156  bool authFromMessage( QTransportAuth::Data &d, const char *msg, int msgLen );
157 
158  bool authorizeRequest( QTransportAuth::Data &d, const QString &request );
159 
160 Q_SIGNALS:
161  void policyCheck( QTransportAuth::Data &, const QString & );
162  void authViolation( QTransportAuth::Data & );
163 private Q_SLOTS:
164  void bufferDestroyed( QObject * );
165 
166 private:
167  // users should never construct their own
168  QTransportAuth();
169  ~QTransportAuth();
170 
171  friend class QAuthDevice;
173 };
174 
176 {
177 public:
178  RequestAnalyzer();
179  virtual ~RequestAnalyzer();
180  QString operator()( QByteArray *data ) { return analyze( data ); }
181  bool requireMoreData() const { return moreData; }
182  qint64 bytesAnalyzed() const { return dataSize; }
183 protected:
184  virtual QString analyze( QByteArray * );
185  bool moreData;
187 };
188 
202 {
203  Q_OBJECT
204 public:
207  Send
208  };
210  ~QAuthDevice();
211  void setTarget( QIODevice *t ) { m_target = t; }
212  QIODevice *target() const { return m_target; }
213  void setClient( QObject* );
214  QObject *client() const;
215  void setRequestAnalyzer( RequestAnalyzer * );
216  bool isSequential() const;
217  bool atEnd() const;
218  qint64 bytesAvailable() const;
219  qint64 bytesToWrite() const;
220  bool seek( qint64 );
221  QByteArray & buffer();
222 
223 protected:
224  qint64 readData( char *, qint64 );
225  qint64 writeData(const char *, qint64 );
226 private Q_SLOTS:
227  void recvReadyRead();
228  void targetBytesWritten( qint64 );
229 private:
230  bool authorizeMessage();
231 
239 
241 };
242 
243 inline bool QAuthDevice::isSequential() const
244 {
245  return true;
246 }
247 
248 inline bool QAuthDevice::seek( qint64 )
249 {
250  return false;
251 }
252 
253 inline bool QAuthDevice::atEnd() const
254 {
255  return msgQueue.isEmpty();
256 }
257 
259 {
260  if ( way == Receive )
261  return m_bytesAvailable;
262  else
263  return ( m_target ? m_target->bytesAvailable() : 0 );
264 }
265 
267 {
268  return msgQueue.size();
269 }
270 
272 {
273  return msgQueue;
274 }
275 
276 
277 
278 
280 
282 
283 #endif // QT_NO_SXE
284 #endif // QTRANSPORTAUTH_QWS_H
double d
Definition: qnumeric_p.h:62
QTransportAuth::Data * d
qint64 bytesAnalyzed() const
QByteArray & buffer()
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
AuthDirection way
Pass-through QIODevice sub-class for authentication.
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setTarget(QIODevice *t)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
QIODevice * m_target
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
RequestAnalyzer * analyzer
QObject * m_client
QByteArray msgQueue
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
bool seek(qint64)
For random-access devices, this function sets the current position to pos, returning true on success...
Data(unsigned char p, int d)
#define Q_OBJECT
Definition: qobjectdefs.h:157
QIODevice * target() const
bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
QString operator()(QByteArray *data)
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
Authenticate a message transport.
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
#define QT_END_HEADER
Definition: qglobal.h:137
qint64 bytesToWrite() const
For buffered devices, this function returns the number of bytes waiting to be written.
The QWSClient class encapsulates a client process in Qt for Embedded Linux.
bool requireMoreData() const