Changeset 58242 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Oct 14, 2015 1:53:49 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/net
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkDefs.h
r55401 r58242 23 23 { 24 24 UINetworkRequestType_HEAD, 25 UINetworkRequestType_HEAD_Our, 25 26 UINetworkRequestType_GET, 26 27 UINetworkRequestType_GET_Our -
trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp
r58238 r58242 63 63 public: 64 64 65 /* Constructor:*/66 UINetworkReplyPrivateThread(const QNetworkRequest &request );65 /** Constructs network reply thread for the passed @a request of the passed @a type. */ 66 UINetworkReplyPrivateThread(const QNetworkRequest &request, UINetworkRequestType type); 67 67 68 68 /** Returns short descriptive context of thread's current operation. */ … … 77 77 /** Abort HTTP request. */ 78 78 void abort(); 79 /** Returns value for the cached reply header of the passed @a type. */ 80 QString header(QNetworkRequest::KnownHeaders type) const 81 { 82 /* Look for known header type: */ 83 switch (type) 84 { 85 case QNetworkRequest::ContentTypeHeader: return m_headers.value("Content-Type"); 86 case QNetworkRequest::ContentLengthHeader: return m_headers.value("Content-Length"); 87 case QNetworkRequest::LastModifiedHeader: return m_headers.value("Last-Modified"); 88 default: break; 89 } 90 /* Return null-string by default: */ 91 return QString(); 92 } 79 93 /** @} */ 80 94 … … 119 133 /* Variables: */ 120 134 QNetworkRequest m_request; 135 /** Holds the request type. */ 136 UINetworkRequestType m_type; 121 137 int m_iError; 122 138 /** IPRT HTTP client instance handle. */ 123 139 RTHTTP m_hHttp; 124 140 QByteArray m_reply; 141 /* Holds the cached reply headers. */ 142 QMap<QString, QString> m_headers; 125 143 126 144 static const char * const s_apszRootsZipUrls[]; … … 201 219 202 220 203 UINetworkReplyPrivateThread::UINetworkReplyPrivateThread(const QNetworkRequest &request )221 UINetworkReplyPrivateThread::UINetworkReplyPrivateThread(const QNetworkRequest &request, UINetworkRequestType type) 204 222 : m_request(request) 223 , m_type(type) 205 224 , m_iError(VINF_SUCCESS) 206 225 , m_hHttp(NIL_RTHTTP) … … 359 378 int rc = 0; 360 379 361 /* Perform blocking HTTP GET request: */ 362 void *pvResponse = 0; 363 size_t cbResponse = 0; 364 rc = RTHttpGetBinary(m_hHttp, m_request.url().toString().toUtf8().constData(), &pvResponse, &cbResponse); 365 if (RT_SUCCESS(rc)) 366 { 367 m_reply = QByteArray((char*)pvResponse, cbResponse); 368 RTHttpFreeResponse(pvResponse); 380 /* Depending on request type: */ 381 switch (m_type) 382 { 383 case UINetworkRequestType_HEAD_Our: 384 { 385 /* Perform blocking HTTP HEAD request: */ 386 void *pvResponse = 0; 387 size_t cbResponse = 0; 388 rc = RTHttpGetHeaderBinary(m_hHttp, m_request.url().toString().toUtf8().constData(), &pvResponse, &cbResponse); 389 if (RT_SUCCESS(rc)) 390 { 391 m_reply = QByteArray((char*)pvResponse, cbResponse); 392 RTHttpFreeResponse(pvResponse); 393 } 394 395 /* Paranoia: */ 396 m_headers.clear(); 397 398 /* Parse header contents: */ 399 const QString strHeaders = QString(m_reply); 400 const QStringList headers = strHeaders.split("\n", QString::SkipEmptyParts); 401 foreach (const QString &strHeader, headers) 402 { 403 const QStringList values = strHeader.split(": ", QString::SkipEmptyParts); 404 if (values.size() > 1) 405 m_headers[values.at(0)] = values.at(1); 406 } 407 408 break; 409 } 410 case UINetworkRequestType_GET_Our: 411 { 412 /* Perform blocking HTTP GET request: */ 413 void *pvResponse = 0; 414 size_t cbResponse = 0; 415 rc = RTHttpGetBinary(m_hHttp, m_request.url().toString().toUtf8().constData(), &pvResponse, &cbResponse); 416 if (RT_SUCCESS(rc)) 417 { 418 m_reply = QByteArray((char*)pvResponse, cbResponse); 419 RTHttpFreeResponse(pvResponse); 420 } 421 422 break; 423 } 424 default: 425 break; 369 426 } 370 427 … … 749 806 750 807 /* Constructor: */ 751 UINetworkReplyPrivate(const QNetworkRequest &request )808 UINetworkReplyPrivate(const QNetworkRequest &request, UINetworkRequestType type) 752 809 : m_error(QNetworkReply::NoError) 753 810 , m_pThread(0) … … 756 813 m_strErrorTemplate = tr("%1: %2", "Context description: Error description"); 757 814 /* Create and run network-reply thread: */ 758 m_pThread = new UINetworkReplyPrivateThread(request );815 m_pThread = new UINetworkReplyPrivateThread(request, type); 759 816 connect(m_pThread, SIGNAL(finished()), this, SLOT(sltFinished())); 760 817 m_pThread->start(); … … 802 859 /* API: Reply getter: */ 803 860 QByteArray readAll() { return m_pThread->readAll(); } 861 862 /** Returns value for the cached reply header of the passed @a type. */ 863 QString header(QNetworkRequest::KnownHeaders type) const { return m_pThread->header(type); } 804 864 805 865 private slots: … … 854 914 m_pReply = gNetworkManager->head(request); 855 915 break; 916 /* Prepare our network-reply (HEAD): */ 917 case UINetworkRequestType_HEAD_Our: 918 m_replyType = UINetworkReplyType_Our; 919 m_pReply = new UINetworkReplyPrivate(request, UINetworkRequestType_HEAD_Our); 920 break; 856 921 /* Prepare Qt network-reply (GET): */ 857 922 case UINetworkRequestType_GET: … … 862 927 case UINetworkRequestType_GET_Our: 863 928 m_replyType = UINetworkReplyType_Our; 864 m_pReply = new UINetworkReplyPrivate(request );929 m_pReply = new UINetworkReplyPrivate(request, UINetworkRequestType_GET_Our); 865 930 break; 866 931 } … … 887 952 { 888 953 case UINetworkReplyType_Qt: result = qobject_cast<QNetworkReply*>(m_pReply)->header(header); break; 889 case UINetworkReplyType_Our: /* TODO: header() */break;954 case UINetworkReplyType_Our: result = qobject_cast<UINetworkReplyPrivate*>(m_pReply)->header(header); break; 890 955 } 891 956 return result;
Note:
See TracChangeset
for help on using the changeset viewer.