Go to
the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QTRANSPORTAUTH_QWS_H
00043 #define QTRANSPORTAUTH_QWS_H
00044
00045 #include <QtCore/qglobal.h>
00046
00047 #if !defined(QT_NO_SXE) || defined(SXE_INSTALLER)
00048
00049 #include <QtCore/qobject.h>
00050 #include <QtCore/qhash.h>
00051 #include <QtCore/qstring.h>
00052 #include <QtCore/qbuffer.h>
00053 #include <QtCore/qpointer.h>
00054
00055 #include <sys/types.h>
00056
00057 QT_BEGIN_HEADER
00058
00059 QT_BEGIN_NAMESPACE
00060
00061 QT_MODULE(Gui)
00062
00063 class QAuthDevice;
00064 class QWSClient;
00065 class QIODevice;
00066 class QTransportAuthPrivate;
00067 class QMutex;
00068
00069 class Q_GUI_EXPORT QTransportAuth : public QObject
00070 {
00071 Q_OBJECT
00072 public:
00073 static QTransportAuth *getInstance();
00074
00075 enum Result {
00076
00077 Pending = 0x00,
00078 TooSmall = 0x01,
00079 CacheMiss = 0x02,
00080 NoMagic = 0x03,
00081 NoSuchKey = 0x04,
00082 FailMatch = 0x05,
00083 OutOfDate = 0x06,
00084
00085 Success = 0x1e,
00086 ErrMask = 0x1f,
00087
00088
00089 Allow = 0x20,
00090 Deny = 0x40,
00091 Ask = 0x60,
00092
00093 StatusMask = 0xe0
00094 };
00095
00096 enum Properties {
00097 Trusted = 0x01,
00098 Connection = 0x02,
00099 UnixStreamSock = 0x04,
00100 SharedMemory = 0x08,
00101 MessageQueue = 0x10,
00102 UDP = 0x20,
00103 TCP = 0x40,
00104 UserDefined = 0x80,
00105 TransportType = 0xfc
00106 };
00107
00108 struct Data
00109 {
00110 Data() { processId = -1; }
00111 Data( unsigned char p, int d )
00112 : properties( p )
00113 , descriptor( d )
00114 , processId( -1 )
00115 {
00116 if (( properties & TransportType ) == TCP ||
00117 ( properties & TransportType ) == UnixStreamSock )
00118 properties |= Connection;
00119 }
00120
00121 unsigned char properties;
00122 unsigned char progId;
00123 unsigned char status;
00124 unsigned int descriptor;
00125 pid_t processId;
00126
00127 bool trusted() const;
00128 void setTrusted( bool );
00129 bool connection() const;
00130 void setConnection( bool );
00131 };
00132
00133 static const char *errorString( const QTransportAuth::Data & );
00134
00135 QTransportAuth::Data *connectTransport( unsigned char, int );
00136
00137 QAuthDevice *authBuf( QTransportAuth::Data *, QIODevice * );
00138 QAuthDevice *recvBuf( QTransportAuth::Data *, QIODevice * );
00139 QIODevice *passThroughByClient( QWSClient * ) const;
00140
00141 void setKeyFilePath( const QString & );
00142 QString keyFilePath() const;
00143 const unsigned char *getClientKey( unsigned char progId );
00144 void invalidateClientKeyCache();
00145 QMutex *getKeyFileMutex();
00146 void setLogFilePath( const QString & );
00147 QString logFilePath() const;
00148 void setPackageRegistry( QObject *registry );
00149 bool isDiscoveryMode() const;
00150 void setProcessKey( const char * );
00151 void setProcessKey( const char *, const char * );
00152 void registerPolicyReceiver( QObject * );
00153 void unregisterPolicyReceiver( QObject * );
00154
00155 bool authToMessage( QTransportAuth::Data &d, char *hdr, const char *msg, int msgLen );
00156 bool authFromMessage( QTransportAuth::Data &d, const char *msg, int msgLen );
00157
00158 bool authorizeRequest( QTransportAuth::Data &d, const QString &request );
00159
00160 Q_SIGNALS:
00161 void policyCheck( QTransportAuth::Data &, const QString & );
00162 void authViolation( QTransportAuth::Data & );
00163 private Q_SLOTS:
00164 void bufferDestroyed( QObject * );
00165
00166 private:
00167
00168 QTransportAuth();
00169 ~QTransportAuth();
00170
00171 friend class QAuthDevice;
00172 Q_DECLARE_PRIVATE(QTransportAuth)
00173 };
00174
00175 class Q_GUI_EXPORT RequestAnalyzer
00176 {
00177 public:
00178 RequestAnalyzer();
00179 virtual ~RequestAnalyzer();
00180 QString operator()( QByteArray *data ) { return analyze( data ); }
00181 bool requireMoreData() const { return moreData; }
00182 qint64 bytesAnalyzed() const { return dataSize; }
00183 protected:
00184 virtual QString analyze( QByteArray * );
00185 bool moreData;
00186 qint64 dataSize;
00187 };
00188
00198 class Q_GUI_EXPORT QAuthDevice : public QIODevice
00199 {
00200 Q_OBJECT
00201 public:
00202 enum AuthDirection {
00203 Receive,
00204 Send
00205 };
00206 QAuthDevice( QIODevice *, QTransportAuth::Data *, AuthDirection );
00207 ~QAuthDevice();
00208 void setTarget( QIODevice *t ) { m_target = t; }
00209 QIODevice *target() const { return m_target; }
00210 void setClient( QObject* );
00211 QObject *client() const;
00212 void setRequestAnalyzer( RequestAnalyzer * );
00213 bool isSequential() const;
00214 bool atEnd() const;
00215 qint64 bytesAvailable() const;
00216 qint64 bytesToWrite() const;
00217 bool seek( qint64 );
00218 QByteArray & buffer();
00219
00220 protected:
00221 qint64 readData( char *, qint64 );
00222 qint64 writeData(const char *, qint64 );
00223 private Q_SLOTS:
00224 void recvReadyRead();
00225 void targetBytesWritten( qint64 );
00226 private:
00227 bool authorizeMessage();
00228
00229 QTransportAuth::Data *d;
00230 AuthDirection way;
00231 QIODevice *m_target;
00232 QObject *m_client;
00233 QByteArray msgQueue;
00234 qint64 m_bytesAvailable;
00235 qint64 m_skipWritten;
00236
00237 RequestAnalyzer *analyzer;
00238 };
00239
00240 inline bool QAuthDevice::isSequential() const
00241 {
00242 return true;
00243 }
00244
00245 inline bool QAuthDevice::seek( qint64 )
00246 {
00247 return false;
00248 }
00249
00250 inline bool QAuthDevice::atEnd() const
00251 {
00252 return msgQueue.isEmpty();
00253 }
00254
00255 inline qint64 QAuthDevice::bytesAvailable() const
00256 {
00257 if ( way == Receive )
00258 return m_bytesAvailable;
00259 else
00260 return ( m_target ? m_target->bytesAvailable() : 0 );
00261 }
00262
00263 inline qint64 QAuthDevice::bytesToWrite() const
00264 {
00265 return msgQueue.size();
00266 }
00267
00268 inline QByteArray &QAuthDevice::buffer()
00269 {
00270 return msgQueue;
00271 }
00272
00273
00274
00275
00276 QT_END_NAMESPACE
00277
00278 QT_END_HEADER
00279
00280 #endif // QT_NO_SXE
00281 #endif // QTRANSPORTAUTH_QWS_H