Qt 4.8
qhttpsocketengine.cpp
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 QtNetwork 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 #include "qhttpsocketengine_p.h"
43 #include "qtcpsocket.h"
44 #include "qhostaddress.h"
45 #include "qurl.h"
46 #include "qhttp.h"
47 #include "qelapsedtimer.h"
48 #include "qnetworkinterface.h"
49 
50 #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP)
51 #include <qdebug.h>
52 
54 
55 #define DEBUG
56 
59 {
60 }
61 
63 {
64 }
65 
67 {
69  if (type != QAbstractSocket::TcpSocket)
70  return false;
71 
72  setProtocol(protocol);
73  setSocketType(type);
74  d->socket = new QTcpSocket(this);
75 #ifndef QT_NO_BEARERMANAGEMENT
76  d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
77 #endif
78 
79  // Explicitly disable proxying on the proxy socket itself to avoid
80  // unwanted recursion.
81  d->socket->setProxy(QNetworkProxy::NoProxy);
82 
83  // Intercept all the signals.
84  connect(d->socket, SIGNAL(connected()),
85  this, SLOT(slotSocketConnected()),
87  connect(d->socket, SIGNAL(disconnected()),
90  connect(d->socket, SIGNAL(readyRead()),
93  connect(d->socket, SIGNAL(bytesWritten(qint64)),
99  connect(d->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
102 
103  return true;
104 }
105 
107 {
108  return false;
109 }
110 
112 {
114  d->proxy = proxy;
115  QString user = proxy.user();
116  if (!user.isEmpty())
117  d->authenticator.setUser(user);
118  QString password = proxy.password();
119  if (!password.isEmpty())
120  d->authenticator.setPassword(password);
121 }
122 
124 {
125  Q_D(const QHttpSocketEngine);
126  return d->socket ? d->socket->socketDescriptor() : 0;
127 }
128 
130 {
131  Q_D(const QHttpSocketEngine);
132  return d->socket;
133 }
134 
136 {
138 
139  d->credentialsSent = false;
140 
141  // If the handshake is done, enter ConnectedState state and return true.
142  if (d->state == Connected) {
143  qWarning("QHttpSocketEngine::connectToHost: called when already connected");
145  return true;
146  }
147 
148  if (d->state == ConnectSent && d->socketState != QAbstractSocket::ConnectedState)
150 
151  // Handshake isn't done. If unconnected, start connecting.
152  if (d->state == None && d->socket->state() == QAbstractSocket::UnconnectedState) {
154  //limit buffer in internal socket, data is buffered in the external socket under application control
155  d->socket->setReadBufferSize(65536);
156  d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
157  }
158 
159  // If connected (might happen right away, at least for localhost services
160  // on some BSD systems), there might already be bytes available.
161  if (bytesAvailable())
163 
164  return d->socketState == QAbstractSocket::ConnectedState;
165 }
166 
168 {
170 
171  setPeerAddress(address);
172  setPeerPort(port);
173  d->peerName.clear();
174 
175  return connectInternal();
176 }
177 
179 {
181 
183  setPeerPort(port);
184  d->peerName = hostname;
185 
186  return connectInternal();
187 }
188 
190 {
191  return false;
192 }
193 
195 {
196  return false;
197 }
198 
200 {
201  return 0;
202 }
203 
205 {
207  if (d->socket) {
208  d->socket->close();
209  delete d->socket;
210  d->socket = 0;
211  }
212 }
213 
215 {
216  Q_D(const QHttpSocketEngine);
217  return d->readBuffer.size() + (d->socket ? d->socket->bytesAvailable() : 0);
218 }
219 
221 {
223  qint64 bytesRead = d->socket->read(data, maxlen);
224 
225  if (d->socket->state() == QAbstractSocket::UnconnectedState
226  && d->socket->bytesAvailable() == 0) {
228  }
229 
230  if (bytesRead == -1) {
231  // If nothing has been read so far, and the direct socket read
232  // failed, return the socket's error. Otherwise, fall through and
233  // return as much as we read so far.
234  close();
236  QLatin1String("Remote host closed"));
238  return -1;
239  }
240  return bytesRead;
241 }
242 
244 {
246  return d->socket->write(data, len);
247 }
248 
249 #ifndef QT_NO_UDPSOCKET
250 #ifndef QT_NO_NETWORKINTERFACE
252  const QNetworkInterface &)
253 {
255  QLatin1String("Operation on socket is not supported"));
256  return false;
257 }
258 
260  const QNetworkInterface &)
261 {
263  QLatin1String("Operation on socket is not supported"));
264  return false;
265 }
266 
268 {
269  return QNetworkInterface();
270 }
271 
273 {
275  QLatin1String("Operation on socket is not supported"));
276  return false;
277 }
278 #endif // QT_NO_NETWORKINTERFACE
279 
281  quint16 *)
282 {
283  return 0;
284 }
285 
287  quint16)
288 {
289  return 0;
290 }
291 
293 {
294  return false;
295 }
296 
298 {
299  return 0;
300 }
301 #endif // QT_NO_UDPSOCKET
302 
304 {
305  Q_D(const QHttpSocketEngine);
306  if (d->socket) {
307  return d->socket->bytesToWrite();
308  } else {
309  return 0;
310  }
311 }
312 
314 {
315  Q_D(const QHttpSocketEngine);
316  if (d->socket) {
317  // convert the enum and call the real socket
319  return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
321  return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
322  }
323  return -1;
324 }
325 
327 {
329  if (d->socket) {
330  // convert the enum and call the real socket
332  d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
334  d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
335  return true;
336  }
337  return false;
338 }
339 
340 /*
341  Returns the difference between msecs and elapsed. If msecs is -1,
342  however, -1 is returned.
343 */
344 static int qt_timeout_value(int msecs, int elapsed)
345 {
346  if (msecs == -1)
347  return -1;
348 
349  int timeout = msecs - elapsed;
350  return timeout < 0 ? 0 : timeout;
351 }
352 
353 bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut)
354 {
355  Q_D(const QHttpSocketEngine);
356 
357  if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState)
358  return false;
359 
360  QElapsedTimer stopWatch;
361  stopWatch.start();
362 
363  // Wait for more data if nothing is available.
364  if (!d->socket->bytesAvailable()) {
365  if (!d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
366  if (d->socket->state() == QAbstractSocket::UnconnectedState)
367  return true;
368  setError(d->socket->error(), d->socket->errorString());
369  if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
370  *timedOut = true;
371  return false;
372  }
373  }
374 
375  // If we're not connected yet, wait until we are, or until an error
376  // occurs.
377  while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
378  // Loop while the protocol handshake is taking place.
379  }
380 
381  // Report any error that may occur.
382  if (d->state != Connected) {
383  setError(d->socket->error(), d->socket->errorString());
384  if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
385  *timedOut = true;
386  return false;
387  }
388  return true;
389 }
390 
391 bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut)
392 {
393  Q_D(const QHttpSocketEngine);
394 
395  // If we're connected, just forward the call.
396  if (d->state == Connected) {
397  if (d->socket->bytesToWrite()) {
398  if (!d->socket->waitForBytesWritten(msecs)) {
399  if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
400  *timedOut = true;
401  return false;
402  }
403  }
404  return true;
405  }
406 
407  QElapsedTimer stopWatch;
408  stopWatch.start();
409 
410  // If we're not connected yet, wait until we are, and until bytes have
411  // been received (i.e., the socket has connected, we have sent the
412  // greeting, and then received the response).
413  while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
414  // Loop while the protocol handshake is taking place.
415  }
416 
417  // Report any error that may occur.
418  if (d->state != Connected) {
419 // setError(d->socket->error(), d->socket->errorString());
420  if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
421  *timedOut = true;
422  }
423 
424  return true;
425 }
426 
427 bool QHttpSocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
428  bool checkRead, bool checkWrite,
429  int msecs, bool *timedOut)
430 {
431  Q_UNUSED(checkRead);
432 
433  if (!checkWrite) {
434  // Not interested in writing? Then we wait for read notifications.
435  bool canRead = waitForRead(msecs, timedOut);
436  if (readyToRead)
437  *readyToRead = canRead;
438  return canRead;
439  }
440 
441  // Interested in writing? Then we wait for write notifications.
442  bool canWrite = waitForWrite(msecs, timedOut);
443  if (readyToWrite)
444  *readyToWrite = canWrite;
445  return canWrite;
446 }
447 
449 {
450  Q_D(const QHttpSocketEngine);
451  return d->readNotificationEnabled;
452 }
453 
455 {
457  if (d->readNotificationEnabled == enable)
458  return;
459 
460  d->readNotificationEnabled = enable;
461  if (enable) {
462  // Enabling read notification can trigger a notification.
463  if (bytesAvailable())
465  }
466 }
467 
469 {
470  Q_D(const QHttpSocketEngine);
471  return d->writeNotificationEnabled;
472 }
473 
475 {
477  d->writeNotificationEnabled = enable;
478  if (enable && d->state == Connected && d->socket->state() == QAbstractSocket::ConnectedState)
479  QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
480 }
481 
483 {
484  Q_D(const QHttpSocketEngine);
485  return d->exceptNotificationEnabled;
486 }
487 
489 {
491  d->exceptNotificationEnabled = enable;
492 }
493 
495 {
497 
498  // Send the greeting.
499  const char method[] = "CONNECT";
500  QByteArray peerAddress = d->peerName.isEmpty() ?
501  d->peerAddress.toString().toLatin1() :
502  QUrl::toAce(d->peerName);
503  QByteArray path = peerAddress + ':' + QByteArray::number(d->peerPort);
504  QByteArray data = method;
505  data += " ";
506  data += path;
507  data += " HTTP/1.1\r\n";
508  data += "Proxy-Connection: keep-alive\r\n"
509  "User-Agent: ";
510  QVariant v = property("_q_user-agent");
511  if (v.isValid())
512  data += v.toByteArray();
513  else
514  data += "Mozilla/5.0";
515  data += "\r\n"
516  "Host: " + peerAddress + "\r\n";
518  //qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1);
519  if (priv && priv->method != QAuthenticatorPrivate::None) {
520  d->credentialsSent = true;
521  data += "Proxy-Authorization: " + priv->calculateResponse(method, path);
522  data += "\r\n";
523  }
524  data += "\r\n";
525 // qDebug() << ">>>>>>>> sending request" << this;
526 // qDebug() << data;
527 // qDebug() << ">>>>>>>";
528  d->socket->write(data);
529  d->state = ConnectSent;
530 }
531 
533 {
534 }
535 
537 {
539  if (d->state != Connected && d->socket->bytesAvailable() == 0)
540  return;
541 
542  if (d->state == Connected) {
543  // Forward as a read notification.
544  if (d->readNotificationEnabled)
546  return;
547  }
548 
549  readResponseContent:
550  if (d->state == ReadResponseContent) {
551  char dummybuffer[4096];
552  while (d->pendingResponseData) {
553  int read = d->socket->read(dummybuffer, qMin(sizeof(dummybuffer), (size_t)d->pendingResponseData));
554  if (read >= 0)
555  dummybuffer[read] = 0;
556 
557  if (read == 0)
558  return;
559  if (read == -1) {
560  d->socket->disconnectFromHost();
562  return;
563  }
564  d->pendingResponseData -= read;
565  }
566  if (d->pendingResponseData > 0)
567  return;
568  d->state = SendAuthentication;
570  return;
571  }
572 
573  // Still in handshake mode. Wait until we've got a full response.
574  bool done = false;
575  do {
576  d->readBuffer += d->socket->readLine();
577  } while (!(done = d->readBuffer.endsWith("\r\n\r\n")) && d->socket->canReadLine());
578 
579  if (!done) {
580  // Wait for more.
581  return;
582  }
583 
584  if (!d->readBuffer.startsWith("HTTP/1.")) {
585  // protocol error, this isn't HTTP
586  d->readBuffer.clear();
587  d->socket->close();
589  setError(QAbstractSocket::ProxyProtocolError, tr("Did not receive HTTP response from proxy"));
591  return;
592  }
593 
594  QHttpResponseHeader responseHeader(QString::fromLatin1(d->readBuffer));
595  d->readBuffer.clear(); // we parsed the proxy protocol response. from now on direct socket reading will be done
596 
597  int statusCode = responseHeader.statusCode();
599  if (statusCode == 200) {
600  d->state = Connected;
601  setLocalAddress(d->socket->localAddress());
602  setLocalPort(d->socket->localPort());
604  d->authenticator.detach();
605  priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
606  priv->hasFailed = false;
607  } else if (statusCode == 407) {
608  if (d->credentialsSent) {
609  //407 response again means the provided username/password were invalid.
610  d->authenticator = QAuthenticator(); //this is needed otherwise parseHttpResponse won't set the state, and then signal isn't emitted.
611  d->authenticator.detach();
612  priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
613  priv->hasFailed = true;
614  }
615  else if (d->authenticator.isNull())
616  d->authenticator.detach();
617  priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
618 
619  priv->parseHttpResponse(responseHeader, true);
620 
621  if (priv->phase == QAuthenticatorPrivate::Invalid) {
622  // problem parsing the reply
623  d->socket->close();
625  setError(QAbstractSocket::ProxyProtocolError, tr("Error parsing authentication request from proxy"));
627  return;
628  }
629 
630  bool willClose;
631  QString proxyConnectionHeader = responseHeader.value(QLatin1String("Proxy-Connection"));
632  // Although most proxies use the unofficial Proxy-Connection header, the Connection header
633  // from http spec is also allowed.
634  if (proxyConnectionHeader.isEmpty())
635  proxyConnectionHeader = responseHeader.value(QLatin1String("Connection"));
636  proxyConnectionHeader = proxyConnectionHeader.toLower();
637  if (proxyConnectionHeader == QLatin1String("close")) {
638  willClose = true;
639  } else if (proxyConnectionHeader == QLatin1String("keep-alive")) {
640  willClose = false;
641  } else {
642  // no Proxy-Connection header, so use the default
643  // HTTP 1.1's default behaviour is to keep persistent connections
644  // HTTP 1.0 or earlier, so we expect the server to close
645  willClose = (responseHeader.majorVersion() * 0x100 + responseHeader.minorVersion()) <= 0x0100;
646  }
647 
648  if (willClose) {
649  // the server will disconnect, so let's avoid receiving an error
650  // especially since the signal below may trigger a new event loop
651  d->socket->disconnectFromHost();
652  d->socket->readAll();
653  }
654 
655  if (priv->phase == QAuthenticatorPrivate::Done)
656  emit proxyAuthenticationRequired(d->proxy, &d->authenticator);
657  // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above.
658  if (priv->phase == QAuthenticatorPrivate::Done) {
660  d->socket->disconnectFromHost();
661  } else {
662  // close the connection if it isn't already and reconnect using the chosen authentication method
663  d->state = SendAuthentication;
664  if (willClose) {
665  d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
666  } else {
667  bool ok;
668  int contentLength = responseHeader.value(QLatin1String("Content-Length")).toInt(&ok);
669  if (ok && contentLength > 0) {
670  d->state = ReadResponseContent;
671  d->pendingResponseData = contentLength;
672  goto readResponseContent;
673  } else {
674  d->state = SendAuthentication;
676  }
677  }
678  return;
679  }
680  } else {
681  d->socket->close();
683  if (statusCode == 403 || statusCode == 405) {
684  // 403 Forbidden
685  // 405 Method Not Allowed
686  setError(QAbstractSocket::SocketAccessError, tr("Proxy denied connection"));
687  } else if (statusCode == 404) {
688  // 404 Not Found: host lookup error
690  } else if (statusCode == 503) {
691  // 503 Service Unavailable: Connection Refused
693  } else {
694  // Some other reply
695  //qWarning("UNEXPECTED RESPONSE: [%s]", responseHeader.toString().toLatin1().data());
696  setError(QAbstractSocket::ProxyProtocolError, tr("Error communicating with HTTP proxy"));
697  }
698  }
699 
700  // The handshake is done; notify that we're connected (or failed to connect)
702 }
703 
705 {
707  if (d->state == Connected && d->writeNotificationEnabled)
709 }
710 
712 {
714  d->readBuffer.clear();
715 
716  if (d->state != Connected) {
717  // we are in proxy handshaking stages
719  setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
720  else if (error == QAbstractSocket::ConnectionRefusedError)
721  setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
722  else if (error == QAbstractSocket::SocketTimeoutError)
723  setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
724  else if (error == QAbstractSocket::RemoteHostClosedError)
725  setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
726  else
727  setError(error, d->socket->errorString());
729  return;
730  }
731 
732  // We're connected
734  return; // ignore this error
735 
736  d->state = None;
737  setError(error, d->socket->errorString());
739  qDebug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
740  //read notification needs to always be emitted, otherwise the higher layer doesn't get the disconnected signal
742 }
743 
745 {
746  Q_UNUSED(state);
747 }
748 
750 {
752  d->readNotificationPending = false;
753  if (d->readNotificationEnabled)
755 }
756 
758 {
760  d->writeNotificationPending = false;
761  if (d->writeNotificationEnabled)
763 }
764 
766 {
768  d->connectionNotificationPending = false;
770 }
771 
773 {
775  d->readNotificationActivated = true;
776  // if there is a connection notification pending we have to emit the readNotification
777  // incase there is connection error. This is only needed for Windows, but it does not
778  // hurt in other cases.
779  if ((d->readNotificationEnabled && !d->readNotificationPending) || d->connectionNotificationPending) {
780  d->readNotificationPending = true;
781  QMetaObject::invokeMethod(this, "emitPendingReadNotification", Qt::QueuedConnection);
782  }
783 }
784 
786 {
788  d->writeNotificationActivated = true;
789  if (d->writeNotificationEnabled && !d->writeNotificationPending) {
790  d->writeNotificationPending = true;
791  QMetaObject::invokeMethod(this, "emitPendingWriteNotification", Qt::QueuedConnection);
792  }
793 }
794 
796 {
798  if (!d->connectionNotificationPending) {
799  d->connectionNotificationPending = true;
800  QMetaObject::invokeMethod(this, "emitPendingConnectionNotification", Qt::QueuedConnection);
801  }
802 }
803 
805  : readNotificationEnabled(false)
806  , writeNotificationEnabled(false)
807  , exceptNotificationEnabled(false)
808  , readNotificationActivated(false)
809  , writeNotificationActivated(false)
810  , readNotificationPending(false)
811  , writeNotificationPending(false)
812  , connectionNotificationPending(false)
813  , credentialsSent(false)
814  , pendingResponseData(0)
815 {
816  socket = 0;
818 }
819 
821 {
822 }
823 
825  const QNetworkProxy &proxy,
826  QObject *parent)
827 {
828  if (socketType != QAbstractSocket::TcpSocket)
829  return 0;
830 
831  // proxy type must have been resolved by now
832  if (proxy.type() != QNetworkProxy::HttpProxy)
833  return 0;
834 
835  // we only accept active sockets
836  if (!qobject_cast<QAbstractSocket *>(parent))
837  return 0;
838 
839  QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
840  engine->setProxy(proxy);
841  return engine;
842 }
843 
845 {
846  return 0;
847 }
848 
850 
851 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
qint64 write(const char *data, qint64 len)
double d
Definition: qnumeric_p.h:62
QString value(const QString &key) const
Returns the first value for the entry with the given key.
Definition: qhttp.cpp:732
int type
Definition: qmetatype.cpp:239
static int qt_timeout_value(int msecs, int elapsed)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static double elapsed(qint64 after, qint64 before)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol)
SocketType
This enum describes the transport layer protocol.
qint64 bytesToWrite() const
bool setOption(SocketOption option, int value)
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
void setProxy(const QNetworkProxy &networkProxy)
QHttpSocketEngine::HttpState state
void setWriteNotificationEnabled(bool enable)
bool hasPendingDatagrams() const
void parseHttpResponse(const QHttpResponseHeader &, bool isProxy)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
qint64 read(char *data, qint64 maxlen)
#define SLOT(a)
Definition: qobjectdefs.h:226
void setPeerAddress(const QHostAddress &address)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
void setLocalPort(quint16 port)
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool waitForWrite(int msecs=30000, bool *timedOut=0)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
bool connectToHost(const QHostAddress &address, quint16 port)
SocketState
This enum describes the different states in which a socket can be.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QNetworkProxy class provides a network layer proxy.
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
Definition: qurl.cpp:6158
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QIntfbScreen * connected
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
QHostAddress peerAddress() const
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)
bool connectToHostByName(const QString &name, quint16 port)
void setExceptionNotificationEnabled(bool enable)
void setPeerPort(quint16 port)
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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void setLocalAddress(const QHostAddress &address)
qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)
#define emit
Definition: qobjectdefs.h:76
SocketError
This enum describes the socket errors that can occur.
QNetworkInterface multicastInterface() const
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=0)
bool isExceptionNotificationEnabled() const
unsigned short quint16
Definition: qglobal.h:936
int socketDescriptor() const
Q_CORE_EXPORT void qWarning(const char *,...)
int minorVersion() const
Returns the minor protocol-version of the HTTP response header.
Definition: qhttp.cpp:1179
bool setMulticastInterface(const QNetworkInterface &iface)
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
QHttpSocketEngine(QObject *parent=0)
bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &interface)
The QAuthenticator class provides an authentication object.
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
bool isReadNotificationEnabled() const
QAbstractSocket::SocketType socketType
bool waitForRead(int msecs=30000, bool *timedOut=0)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void slotSocketError(QAbstractSocket::SocketError error)
QAbstractSocket::SocketError error() const
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QAbstractSocket::NetworkLayerProtocol protocol() const
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
void slotSocketStateChanged(QAbstractSocket::SocketState state)
void setSocketType(QAbstractSocket::SocketType socketType)
static const QMetaObjectPrivate * priv(const uint *data)
virtual QAbstractSocketEngine * createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent)
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)
bool bind(const QHostAddress &address, quint16 port)
QByteArray calculateResponse(const QByteArray &method, const QByteArray &path)
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QObject * parent
Definition: qobject.h:92
int option(SocketOption option) const
QString password() const
Returns the password used for authentication.
qint64 pendingDatagramSize() const
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
The QNetworkInterface class provides a listing of the host&#39;s IP addresses and network interfaces...
bool isWriteNotificationEnabled() const
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
void emitPendingConnectionNotification()
int statusCode() const
Returns the status code of the HTTP response header.
Definition: qhttp.cpp:1146
QAbstractSocket::SocketState state() const
QString user() const
Returns the user name used for authentication.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &interface)
void setReadNotificationEnabled(bool enable)
qint64 bytesAvailable() const
The QHttpResponseHeader class contains response header information for HTTP.
Definition: qhttp.h:119
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int majorVersion() const
Returns the major protocol-version of the HTTP response header.
Definition: qhttp.cpp:1168
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
void start()
Starts this timer.