Qt 4.8
Public Types | Public Functions | Protected Functions | Private Slots | Private Functions | Properties | List of all members
QAuthDevice Class Reference

Pass-through QIODevice sub-class for authentication. More...

#include <qtransportauth_qws.h>

Inheritance diagram for QAuthDevice:
QIODevice QObject

Public Types

enum  AuthDirection { Receive, Send }
 
- Public Types inherited from QIODevice
enum  OpenModeFlag {
  NotOpen = 0x0000, ReadOnly = 0x0001, WriteOnly = 0x0002, ReadWrite = ReadOnly | WriteOnly,
  Append = 0x0004, Truncate = 0x0008, Text = 0x0010, Unbuffered = 0x0020
}
 This enum is used with open() to describe the mode in which a device is opened. More...
 

Public Functions

bool atEnd () const
 Returns true if the current read and write position is at the end of the device (i.e. More...
 
QByteArraybuffer ()
 
qint64 bytesAvailable () const
 Returns the number of bytes that are available for reading. More...
 
qint64 bytesToWrite () const
 For buffered devices, this function returns the number of bytes waiting to be written. More...
 
QObjectclient () const
 
bool isSequential () const
 Returns true if this device is sequential; otherwise returns false. More...
 
 QAuthDevice (QIODevice *, QTransportAuth::Data *, AuthDirection)
 Constructs a new auth device for the transport data and I/O device parent. More...
 
bool seek (qint64)
 For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred. More...
 
void setClient (QObject *)
 
void setRequestAnalyzer (RequestAnalyzer *)
 
void setTarget (QIODevice *t)
 
QIODevicetarget () const
 
 ~QAuthDevice ()
 
- Public Functions inherited from QIODevice
virtual bool canReadLine () const
 Returns true if a complete line of data can be read from the device; otherwise returns false. More...
 
virtual void close ()
 First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. More...
 
QString errorString () const
 Returns a human-readable description of the last device error that occurred. More...
 
bool getChar (char *c)
 Reads one character from the device and stores it in c. More...
 
bool isOpen () const
 Returns true if the device is open; otherwise returns false. More...
 
bool isReadable () const
 Returns true if data can be read from the device; otherwise returns false. More...
 
bool isTextModeEnabled () const
 Returns true if the Text flag is enabled; otherwise returns false. More...
 
bool isWritable () const
 Returns true if data can be written to the device; otherwise returns false. More...
 
virtual bool open (OpenMode mode)
 Opens the device and sets its OpenMode to mode. More...
 
OpenMode openMode () const
 Returns the mode in which the device has been opened; i.e. More...
 
qint64 peek (char *data, qint64 maxlen)
 Reads at most maxSize bytes from the device into data, without side effects (i. More...
 
QByteArray peek (qint64 maxlen)
 Peeks at most maxSize bytes from the device, returning the data peeked as a QByteArray. More...
 
virtual qint64 pos () const
 For random-access devices, this function returns the position that data is written to or read from. More...
 
bool putChar (char c)
 Writes the character c to the device. More...
 
 QIODevice ()
 Constructs a QIODevice object. More...
 
 QIODevice (QObject *parent)
 Constructs a QIODevice object with the given parent. More...
 
qint64 read (char *data, qint64 maxlen)
 Reads at most maxSize bytes from the device into data, and returns the number of bytes read. More...
 
QByteArray read (qint64 maxlen)
 Reads at most maxSize bytes from the device, and returns the data read as a QByteArray. More...
 
QByteArray readAll ()
 Reads all available data from the device, and returns it as a QByteArray. More...
 
qint64 readLine (char *data, qint64 maxlen)
 This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes, stores the characters in data, and returns the number of bytes read. More...
 
QByteArray readLine (qint64 maxlen=0)
 Reads a line from the device, but no more than maxSize characters, and returns the result as a QByteArray. More...
 
virtual bool reset ()
 Seeks to the start of input for random-access devices. More...
 
void setTextModeEnabled (bool enabled)
 If enabled is true, this function sets the Text flag on the device; otherwise the Text flag is removed. More...
 
virtual qint64 size () const
 For open random-access devices, this function returns the size of the device. More...
 
void ungetChar (char c)
 Puts the character c back into the device, and decrements the current position unless the position is 0. More...
 
virtual bool waitForBytesWritten (int msecs)
 For buffered devices, this function waits until a payload of buffered written data has been written to the device and the bytesWritten() signal has been emitted, or until msecs milliseconds have passed. More...
 
virtual bool waitForReadyRead (int msecs)
 Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. More...
 
qint64 write (const char *data, qint64 len)
 Writes at most maxSize bytes of data from data to the device. More...
 
qint64 write (const char *data)
 Writes data from a zero-terminated string of 8-bit characters to the device. More...
 
qint64 write (const QByteArray &data)
 Writes the content of byteArray to the device. More...
 
virtual ~QIODevice ()
 The destructor is virtual, and QIODevice is an abstract base class. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

qint64 readData (char *, qint64)
 Reimplement from QIODevice. More...
 
qint64 writeData (const char *, qint64)
 Reimplement QIODevice writeData method. More...
 
- Protected Functions inherited from QIODevice
 QIODevice (QIODevicePrivate &dd, QObject *parent=0)
 
virtual qint64 readLineData (char *data, qint64 maxlen)
 Reads up to maxSize characters into data and returns the number of characters read. More...
 
void setErrorString (const QString &errorString)
 Sets the human readable description of the last device error that occurred to str. More...
 
void setOpenMode (OpenMode openMode)
 Sets the OpenMode of the device to openMode. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Slots

void recvReadyRead ()
 Receive readyRead signal from the target recv device. More...
 
void targetBytesWritten (qint64)
 

Private Functions

bool authorizeMessage ()
 

Properties

RequestAnalyzeranalyzer
 
QTransportAuth::Datad
 
qint64 m_bytesAvailable
 
QObjectm_client
 
qint64 m_skipWritten
 
QIODevicem_target
 
QByteArray msgQueue
 
AuthDirection way
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QIODevice
void aboutToClose ()
 This signal is emitted when the device is about to close. More...
 
void bytesWritten (qint64 bytes)
 This signal is emitted every time a payload of data has been written to the device. More...
 
void readChannelFinished ()
 This signal is emitted when the input (reading) stream is closed in this device. More...
 
void readyRead ()
 This signal is emitted once every time new data is available for reading from the device. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Pass-through QIODevice sub-class for authentication.

Warning
This function is not part of the public interface.

Use this class to forward on or receive forwarded data over a real device for authentication.

Definition at line 201 of file qtransportauth_qws.h.

Enumerations

◆ AuthDirection

Enumerator
Receive 
Send 

Definition at line 205 of file qtransportauth_qws.h.

Constructors and Destructors

◆ QAuthDevice()

QAuthDevice::QAuthDevice ( QIODevice parent,
QTransportAuth::Data data,
AuthDirection  dir 
)

Constructs a new auth device for the transport data and I/O device parent.

Incoming or outgoing data will be authenticated according to the auth direction dir.

The auth device will take ownership of the transport data and delete it when the device is destroyed.

Definition at line 877 of file qtransportauth_qws.cpp.

878  : QIODevice( parent )
879  , d( data )
880  , way( dir )
881  , m_target( parent )
882  , m_client( 0 )
883  , m_bytesAvailable( 0 )
884  , m_skipWritten( 0 )
885  , analyzer( 0 )
886 {
887  if ( dir == Receive ) // server side
888  {
890  this, SLOT(recvReadyRead()));
891  } else {
893  this, SIGNAL(readyRead()));
894  }
896  this, SLOT(targetBytesWritten(qint64)) );
898 }
QTransportAuth::Data * d
#define SLOT(a)
Definition: qobjectdefs.h:226
AuthDirection way
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device.
void targetBytesWritten(qint64)
QIODevice * m_target
#define SIGNAL(a)
Definition: qobjectdefs.h:227
RequestAnalyzer * analyzer
QObject * m_client
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
__int64 qint64
Definition: qglobal.h:942
void recvReadyRead()
Receive readyRead signal from the target recv device.
QIODevice()
Constructs a QIODevice object.
Definition: qiodevice.cpp:390
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
void readyRead()
This signal is emitted once every time new data is available for reading from the device...

◆ ~QAuthDevice()

QAuthDevice::~QAuthDevice ( )

Definition at line 900 of file qtransportauth_qws.cpp.

901 {
902  if ( analyzer )
903  delete analyzer;
904  delete d;
905 }
QTransportAuth::Data * d
RequestAnalyzer * analyzer

Functions

◆ atEnd()

bool QAuthDevice::atEnd ( ) const
inlinevirtual

Returns true if the current read and write position is at the end of the device (i.e.

there is no more data available for reading on the device); otherwise returns false.

For some devices, atEnd() can return true even though there is more data to read. This special case only applies to devices that generate data in direct response to you calling read() (e.g., /dev or /proc files on Unix and Mac OS X, or console input / stdin on all platforms).

See also
bytesAvailable(), read(), isSequential()

Reimplemented from QIODevice.

Definition at line 253 of file qtransportauth_qws.h.

254 {
255  return msgQueue.isEmpty();
256 }
QByteArray msgQueue
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ authorizeMessage()

bool QAuthDevice::authorizeMessage ( )
private
Warning
This function is not part of the public interface. Pre-process the message to determine what QWS command it is. This information is used as the "request" for the purposes of authorization.

The request and other data on the connection (id, PID, etc.) are forwarded to all policy listeners by emitting a signal.

The signal must be processed synchronously because on return the allow/deny status is used immediately to either drop or continue processing the message.

Definition at line 1140 of file qtransportauth_qws.cpp.

Referenced by recvReadyRead().

1141 {
1142  if ( analyzer == NULL )
1143  analyzer = new RequestAnalyzer();
1144  QString request = (*analyzer)( &msgQueue );
1145  if ( analyzer->requireMoreData() )
1146  return false;
1147  bool isAuthorized = true;
1148 
1149  if ( !request.isEmpty() && request != QLatin1String("Unknown") )
1150  {
1151  isAuthorized = QTransportAuth::getInstance()->authorizeRequest( *d, request );
1152  }
1153 
1154  bool moreToProcess = ( msgQueue.size() - analyzer->bytesAnalyzed() ) > (int)sizeof(int);
1155  if ( isAuthorized )
1156  {
1157 #ifdef QTRANSPORTAUTH_DEBUG
1158  qDebug() << getpid() << "SERVER authorized: releasing" << analyzer->bytesAnalyzed() << "byte command" << request;
1159 #endif
1162  return moreToProcess;
1163  }
1164  else
1165  {
1167  }
1168 
1169  return true;
1170 }
QTransportAuth::Data * d
qint64 bytesAnalyzed() const
bool authorizeRequest(QTransportAuth::Data &d, const QString &request)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
RequestAnalyzer * analyzer
QByteArray msgQueue
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
void readyRead()
This signal is emitted once every time new data is available for reading from the device...
static QTransportAuth * getInstance()
Return a pointer to the instance of this process&#39;s QTransportAuth object.
bool requireMoreData() const

◆ buffer()

QByteArray & QAuthDevice::buffer ( )
inline

Definition at line 271 of file qtransportauth_qws.h.

272 {
273  return msgQueue;
274 }
QByteArray msgQueue

◆ bytesAvailable()

qint64 QAuthDevice::bytesAvailable ( ) const
inlinevirtual

Returns the number of bytes that are available for reading.

This function is commonly used with sequential devices to determine the number of bytes to allocate in a buffer before reading.

Subclasses that reimplement this function must call the base implementation in order to include the size of QIODevices' buffer. Example:

qint64 CustomDevice::bytesAvailable() const
{
}
See also
bytesToWrite(), readyRead(), isSequential()

Reimplemented from QIODevice.

Definition at line 258 of file qtransportauth_qws.h.

259 {
260  if ( way == Receive )
261  return m_bytesAvailable;
262  else
263  return ( m_target ? m_target->bytesAvailable() : 0 );
264 }
AuthDirection way
QIODevice * m_target
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752

◆ bytesToWrite()

qint64 QAuthDevice::bytesToWrite ( ) const
inlinevirtual

For buffered devices, this function returns the number of bytes waiting to be written.

For devices with no buffer, this function returns 0.

See also
bytesAvailable(), bytesWritten(), isSequential()

Reimplemented from QIODevice.

Definition at line 266 of file qtransportauth_qws.h.

267 {
268  return msgQueue.size();
269 }
QByteArray msgQueue
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ client()

QObject * QAuthDevice::client ( ) const

Definition at line 922 of file qtransportauth_qws.cpp.

Referenced by QWSServerPrivate::_q_doClient().

923 {
924  return m_client;
925 }
QObject * m_client

◆ isSequential()

bool QAuthDevice::isSequential ( ) const
inlinevirtual

Returns true if this device is sequential; otherwise returns false.

Sequential devices, as opposed to a random-access devices, have no concept of a start, an end, a size, or a current position, and they do not support seeking. You can only read from the device when it reports that data is available. The most common example of a sequential device is a network socket. On Unix, special files such as /dev/zero and fifo pipes are sequential.

Regular files, on the other hand, do support random access. They have both a size and a current position, and they also support seeking backwards and forwards in the data stream. Regular files are non-sequential.

The QIODevice implementation returns false.

See also
bytesAvailable()

Reimplemented from QIODevice.

Definition at line 243 of file qtransportauth_qws.h.

244 {
245  return true;
246 }

◆ readData()

qint64 QAuthDevice::readData ( char *  data,
qint64  maxSize 
)
protectedvirtual

Reimplement from QIODevice.

Read data out of the internal message queue, reduce the queue by the amount read. Note that the amount available is only ever the size of a command (although a command can be very big) since we need to check at command boundaries for new authentication headers.

Implements QIODevice.

Definition at line 1013 of file qtransportauth_qws.cpp.

1014 {
1015  if ( way == Send ) // client
1016  return m_target->read( data, maxSize );
1017  if ( msgQueue.size() == 0 )
1018  return 0;
1019 #ifdef QTRANSPORTAUTH_DEBUG
1020  char displaybuf[1024];
1021  hexstring( displaybuf, reinterpret_cast<const unsigned char *>(msgQueue.constData()),
1022  msgQueue.size() > 500 ? 500 : msgQueue.size() );
1023  qDebug() << getpid() << "QAuthDevice::readData() buffered/requested/avail"
1024  << msgQueue.size() << maxSize << m_bytesAvailable << displaybuf;
1025 #endif
1027  qint64 bytes = ( maxSize > m_bytesAvailable ) ? m_bytesAvailable : maxSize;
1028  ::memcpy( data, msgQueue.constData(), bytes );
1029  msgQueue = msgQueue.mid( bytes );
1030  m_bytesAvailable -= bytes;
1031  return bytes;
1032 }
AuthDirection way
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QIODevice * m_target
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
Q_CORE_EXPORT void qDebug(const char *,...)
QByteArray msgQueue
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ recvReadyRead

void QAuthDevice::recvReadyRead ( )
privateslot

Receive readyRead signal from the target recv device.

Warning
This function is not part of the public interface. In response authorize the data, and write results out to the recvBuf() device for processing by the application. Trigger the readyRead signal.

Authorizing involves first checking the transport is valid, ie the handshake has either already been done and is cached on a trusted transport, or was valid with this message; then second passing the string representation of the service request up to any policyReceivers

If either of these fail, the message is denied. In discovery mode denied messages are allowed, but the message is logged.

Definition at line 1051 of file qtransportauth_qws.cpp.

Referenced by QAuthDevice().

1052 {
1053  qint64 bytes = m_target->bytesAvailable();
1054  if ( bytes <= 0 ) return;
1056  QUnixSocket *usock = static_cast<QUnixSocket*>(m_target);
1057  QUnixSocketMessage msg = usock->read();
1058  msgQueue.append( msg.bytes() );
1059  d->processId = msg.processId();
1060  // if "fragmented" packet 1/2 way through start of a command, ie
1061  // in the QWS msg type, cant do anything, come back later when
1062  // there's more of the packet
1063  if ( msgQueue.size() < (int)sizeof(int) )
1064  {
1065  // qDebug() << "returning: msg size too small" << msgQueue.size();
1066  return;
1067  }
1068 #ifdef QTRANSPORTAUTH_DEBUG
1069  char displaybuf[1024];
1070  hexstring( displaybuf, reinterpret_cast<const unsigned char *>(msgQueue.constData()),
1071  msgQueue.size() > 500 ? 500 : msgQueue.size() );
1072  qDebug( "%d ***** SERVER read %lli bytes - msg %s", getpid(), bytes, displaybuf );
1073 #endif
1074 
1075  bool bufHasMessages = msgQueue.size() >= (int)sizeof(int);
1076  while ( bufHasMessages )
1077  {
1078  unsigned char saveStatus = d->status;
1080  {
1082  break;
1083  }
1084  if ( !QTransportAuth::getInstance()->authFromMessage( *d, msgQueue, msgQueue.size() ))
1085  {
1086  // not all arrived yet? come back later
1088  {
1089  d->status = saveStatus;
1090  return;
1091  }
1092  }
1094  {
1095  // no msg auth header, don't change the success status for connections
1096  if ( d->connection() )
1097  d->status = saveStatus;
1098  }
1099  else
1100  {
1101  // msg auth header detected and auth determined, remove hdr
1103  }
1104  if ( !authorizeMessage() )
1105  break;
1106  bufHasMessages = msgQueue.size() >= (int)sizeof(int);
1107  }
1108 }
QTransportAuth::Data * d
bool authorizeRequest(QTransportAuth::Data &d, const QString &request)
The QUnixSocket class provides a Unix domain socket.
qint64 read(char *data, qint64 maxSize)
QByteArray & append(char c)
Appends the character ch to this byte array.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QIODevice * m_target
Q_CORE_EXPORT void qDebug(const char *,...)
QByteArray msgQueue
__int64 qint64
Definition: qglobal.h:942
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
pid_t processId() const
Returns the process id credential associated with this message.
#define QSXE_HEADER_LEN
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
bool connection() const
Is the transport connection oriented.
const QByteArray & bytes() const
Return the data portion of the message.
The QUnixSocketMessage class encapsulates a message sent or received through the QUnixSocket class...
Definition: qunixsocket_p.h:92
static QTransportAuth * getInstance()
Return a pointer to the instance of this process&#39;s QTransportAuth object.

◆ seek()

bool QAuthDevice::seek ( qint64  pos)
inlinevirtual

For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred.

For sequential devices, the default behavior is to do nothing and return false.

When subclassing QIODevice, you must call QIODevice::seek() at the start of your function to ensure integrity with QIODevice's built-in buffer. The base implementation always returns true.

See also
pos(), isSequential()

Reimplemented from QIODevice.

Definition at line 248 of file qtransportauth_qws.h.

249 {
250  return false;
251 }

◆ setClient()

void QAuthDevice::setClient ( QObject cli)
Warning
This function is not part of the public interface. Store a pointer to the related device or instance which this authorizer is proxying for

Definition at line 912 of file qtransportauth_qws.cpp.

Referenced by QWSServerPrivate::_q_newConnection(), QWSDisplay::Data::init(), and QWSDisplay::Data::reinit().

913 {
914  m_client = cli;
915  QTransportAuth::getInstance()->d_func()->buffersByClient[cli] = this;
917  QTransportAuth::getInstance(), SLOT(bufferDestroyed(QObject*)) );
918  // qDebug( "@@@@@@@@@@@@ client set %p @@@@@@@@@", cli );
919  // qDebug( " client count %d", QTransportAuth::getInstance()->d_func()->buffersByClient.count() );
920 }
#define SLOT(a)
Definition: qobjectdefs.h:226
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
QObject * m_client
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
static QTransportAuth * getInstance()
Return a pointer to the instance of this process&#39;s QTransportAuth object.

◆ setRequestAnalyzer()

void QAuthDevice::setRequestAnalyzer ( RequestAnalyzer ra)

Definition at line 1172 of file qtransportauth_qws.cpp.

1173 {
1174  Q_ASSERT( ra );
1175  if ( analyzer )
1176  delete analyzer;
1177  analyzer = ra;
1178 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
RequestAnalyzer * analyzer

◆ setTarget()

void QAuthDevice::setTarget ( QIODevice t)
inline

Definition at line 211 of file qtransportauth_qws.h.

211 { m_target = t; }
QIODevice * m_target

◆ target()

QIODevice* QAuthDevice::target ( ) const
inline

Definition at line 212 of file qtransportauth_qws.h.

212 { return m_target; }
QIODevice * m_target

◆ targetBytesWritten

void QAuthDevice::targetBytesWritten ( qint64  bytes)
privateslot
Warning
This function is not part of the public interface. Handle bytesWritten signals from the underlying target device. We adjust the target's value for bytes that are part of auth packets.

Definition at line 1115 of file qtransportauth_qws.cpp.

Referenced by QAuthDevice().

1116 {
1117  if ( m_skipWritten >= bytes ) {
1118  m_skipWritten -= bytes;
1119  bytes = 0;
1120  } else if ( m_skipWritten > 0 ) {
1121  bytes -= m_skipWritten;
1122  m_skipWritten = 0;
1123  }
1124  if ( bytes > 0 ) {
1125  emit bytesWritten( bytes );
1126  }
1127 }
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device.
#define emit
Definition: qobjectdefs.h:76

◆ writeData()

qint64 QAuthDevice::writeData ( const char *  data,
qint64  len 
)
protectedvirtual

Reimplement QIODevice writeData method.

Warning
This function is not part of the public interface.

For client end, when the device is written to the incoming data is processed and an authentication header calculated. This is pushed into the target device, followed by the actual incoming data (the payload).

For server end, it is a fatal error to write to the device.

Implements QIODevice.

Definition at line 966 of file qtransportauth_qws.cpp.

967 {
968  if ( way == Receive ) // server
969  return m_target->write( data, len );
970  // client
971 #ifdef QTRANSPORTAUTH_DEBUG
972  char displaybuf[1024];
973 #endif
974  char header[QSXE_HEADER_LEN];
975  ::memset( header, 0, QSXE_HEADER_LEN );
976  qint64 bytes = 0;
977  if ( QTransportAuth::getInstance()->authToMessage( *d, header, data, len ))
978  {
979  m_target->write( header, QSXE_HEADER_LEN );
980 #ifdef QTRANSPORTAUTH_DEBUG
981  hexstring( displaybuf, (const unsigned char *)header, QSXE_HEADER_LEN );
982  qDebug( "%d QAuthDevice::writeData - CLIENT: Header written: %s", getpid(), displaybuf );
983 #endif
985  }
986  m_target->write( data, len );
987  bytes += len;
988 #ifdef QTRANSPORTAUTH_DEBUG
989  int bytesToDisplay = bytes;
990  const unsigned char *dataptr = (const unsigned char *)data;
991  while ( bytesToDisplay > 0 )
992  {
993  int amt = bytes < 500 ? bytes : 500;
994  hexstring( displaybuf, dataptr, amt );
995  qDebug( "%d QAuthDevice::writeData - CLIENT: %s", getpid(), bytes > 0 ? displaybuf : "(null)" );
996  dataptr += 500;
997  bytesToDisplay -= 500;
998  }
999 #endif
1000  if ( m_target->inherits( "QAbstractSocket" ))
1001  static_cast<QAbstractSocket*>(m_target)->flush();
1002  return bytes;
1003 }
QTransportAuth::Data * d
AuthDirection way
QIODevice * m_target
Q_CORE_EXPORT void qDebug(const char *,...)
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
#define QSXE_HEADER_LEN
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
static QTransportAuth * getInstance()
Return a pointer to the instance of this process&#39;s QTransportAuth object.

Properties

◆ analyzer

RequestAnalyzer* QAuthDevice::analyzer
private

Definition at line 240 of file qtransportauth_qws.h.

Referenced by authorizeMessage(), setRequestAnalyzer(), and ~QAuthDevice().

◆ d

QTransportAuth::Data* QAuthDevice::d
private

Definition at line 232 of file qtransportauth_qws.h.

Referenced by authorizeMessage(), recvReadyRead(), writeData(), and ~QAuthDevice().

◆ m_bytesAvailable

qint64 QAuthDevice::m_bytesAvailable
private

Definition at line 237 of file qtransportauth_qws.h.

Referenced by authorizeMessage(), and readData().

◆ m_client

QObject* QAuthDevice::m_client
private

Definition at line 235 of file qtransportauth_qws.h.

Referenced by client(), and setClient().

◆ m_skipWritten

qint64 QAuthDevice::m_skipWritten
private

Definition at line 238 of file qtransportauth_qws.h.

Referenced by targetBytesWritten(), and writeData().

◆ m_target

QIODevice* QAuthDevice::m_target
private

Definition at line 234 of file qtransportauth_qws.h.

Referenced by QAuthDevice(), readData(), recvReadyRead(), and writeData().

◆ msgQueue

QByteArray QAuthDevice::msgQueue
private

Definition at line 236 of file qtransportauth_qws.h.

Referenced by authorizeMessage(), readData(), and recvReadyRead().

◆ way

AuthDirection QAuthDevice::way
private

Definition at line 233 of file qtransportauth_qws.h.

Referenced by readData(), and writeData().


The documentation for this class was generated from the following files: