VirtualBox

Changeset 58425 in vbox


Ignore:
Timestamp:
Oct 27, 2015 11:20:26 AM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Networking cleanup/rework (part 23): Pass network-request headers separately from network-request object, that allows to abstract from network-request object type.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/net
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkCustomer.cpp

    r58423 r58425  
    4242}
    4343
    44 void UINetworkCustomer::createNetworkRequest(UINetworkRequestType type, const QList<QNetworkRequest> requests)
     44void UINetworkCustomer::createNetworkRequest(UINetworkRequestType type, const QList<QNetworkRequest> requests,
     45                                             const UserDictionary requestHeaders /* = UserDictionary() */)
    4546{
    46     gNetworkManager->createNetworkRequest(type, requests, this);
     47    gNetworkManager->createNetworkRequest(type, requests, requestHeaders, this);
    4748}
    4849
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkCustomer.h

    r58423 r58425  
    5555protected:
    5656
    57     /** Creates network-request of the passed @a type on the basis of the passed @a requests. */
    58     void createNetworkRequest(UINetworkRequestType type, const QList<QNetworkRequest> requests);
     57    /** Creates network-request of the passed @a type on the basis of the passed @a requests and the @a requestHeaders. */
     58    void createNetworkRequest(UINetworkRequestType type, const QList<QNetworkRequest> requests,
     59                              const UserDictionary requestHeaders = UserDictionary());
    5960
    6061private:
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkDefs.h

    r58252 r58425  
    1919#define ___UINetworkDefs_h___
    2020
     21/* Qt includes: */
     22#include <QMap>
     23
    2124/** Network request types. */
    2225enum UINetworkRequestType
     
    2629};
    2730
     31/** User dictionary. */
     32typedef QMap<QString, QString> UserDictionary;
     33
    2834#endif /* !___UINetworkDefs_h___ */
    2935
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp

    r58423 r58425  
    108108
    109109void UINetworkManager::createNetworkRequest(UINetworkRequestType type, const QList<QNetworkRequest> &requests,
    110                                             UINetworkCustomer *pCustomer)
     110                                            const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer)
    111111{
    112112    /* Create network-request: */
    113     UINetworkRequest *pNetworkRequest = new UINetworkRequest(type, requests, pCustomer, this);
     113    UINetworkRequest *pNetworkRequest = new UINetworkRequest(type, requests, requestHeaders, pCustomer, this);
    114114    /* Prepare created network-request: */
    115115    prepareNetworkRequest(pNetworkRequest);
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h

    r58423 r58425  
    8282    friend class UINetworkCustomer;
    8383    /** Creates network-request of the passed @a type
    84       * on the basis of the passed @a requests for the @a pCustomer specified. */
     84      * on the basis of the passed @a requests and the @a requestHeaders for the @a pCustomer specified. */
    8585    void createNetworkRequest(UINetworkRequestType type, const QList<QNetworkRequest> &requests,
    86                               UINetworkCustomer *pCustomer);
     86                              const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer);
    8787
    8888private:
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r58423 r58425  
    7070public:
    7171
    72     /** Constructs network-reply thread of the passed @a type for the passed @a request. */
    73     UINetworkReplyPrivateThread(UINetworkRequestType type, const QNetworkRequest &request);
     72    /** Constructs network-reply thread of the passed @a type for the passed @a request and @a requestHeaders. */
     73    UINetworkReplyPrivateThread(UINetworkRequestType type, const QNetworkRequest &request, const UserDictionary &requestHeaders);
    7474
    7575    /** @name APIs
     
    130130        /** Applies raw headers.
    131131          * @param  hHttp    Brings the HTTP client instance.
    132           * @param  headers  Brings the list of headers to be applied.
    133           * @param  request  Brings the request which contains values for the headers to be applied. */
    134         static int applyRawHeaders(RTHTTP hHttp, const QList<QByteArray> &headers, const QNetworkRequest &request);
     132          * @param  headers  Brings the map of headers to be applied. */
     133        static int applyRawHeaders(RTHTTP hHttp, const UserDictionary &headers);
    135134
    136135        /** Returns the number of certificates found in a search result array.
     
    192191    const UINetworkRequestType m_type;
    193192    /** Holds the request instance. */
    194     QNetworkRequest m_request;
     193    const QNetworkRequest m_request;
     194    /** Holds the request headers. */
     195    const UserDictionary m_requestHeaders;
    195196
    196197    /** Holds the IPRT HTTP client instance handle. */
     
    242243public:
    243244
    244     /** Constructs network-reply private data of the passed @a type for the passed @a request. */
    245     UINetworkReplyPrivate(UINetworkRequestType type, const QNetworkRequest &request);
     245    /** Constructs network-reply private data of the passed @a type for the passed @a request and @a requestHeaders. */
     246    UINetworkReplyPrivate(UINetworkRequestType type, const QNetworkRequest &request, const UserDictionary &requestHeaders);
    246247    /** Destructs reply private data. */
    247248    ~UINetworkReplyPrivate();
     
    342343const QString UINetworkReplyPrivateThread::s_strCertificateFileName = QString("vbox-ssl-cacertificate.crt");
    343344
    344 UINetworkReplyPrivateThread::UINetworkReplyPrivateThread(UINetworkRequestType type, const QNetworkRequest &request)
     345UINetworkReplyPrivateThread::UINetworkReplyPrivateThread(UINetworkRequestType type, const QNetworkRequest &request, const UserDictionary &requestHeaders)
    345346    : m_type(type)
    346347    , m_request(request)
     348    , m_requestHeaders(requestHeaders)
    347349    , m_hHttp(NIL_RTHTTP)
    348350    , m_iError(VINF_SUCCESS)
     
    501503
    502504    /* Make sure we have a raw headers at all: */
    503     QList<QByteArray> headers = m_request.rawHeaderList();
    504     if (headers.isEmpty())
     505    if (m_requestHeaders.isEmpty())
    505506        return VINF_SUCCESS;
    506507
    507508    /* Apply raw headers: */
    508     return applyRawHeaders(m_hHttp, headers, m_request);
     509    return applyRawHeaders(m_hHttp, m_requestHeaders);
    509510}
    510511
     
    635636
    636637/* static */
    637 int UINetworkReplyPrivateThread::applyRawHeaders(RTHTTP hHttp, const QList<QByteArray> &headers, const QNetworkRequest &request)
     638int UINetworkReplyPrivateThread::applyRawHeaders(RTHTTP hHttp, const UserDictionary &headers)
    638639{
    639640    /* Make sure HTTP is created: */
     
    644645    QVector<QByteArray> formattedHeaders;
    645646    QVector<const char*> formattedHeaderPointers;
    646     foreach (const QByteArray &header, headers)
     647    foreach (const QString &header, headers.keys())
    647648    {
    648649        /* Prepare formatted representation: */
    649         QString strFormattedString = QString("%1: %2").arg(QString(header), QString(request.rawHeader(header)));
     650        QString strFormattedString = QString("%1: %2").arg(header, headers.value(header));
    650651        formattedHeaders << strFormattedString.toAscii();
    651652        formattedHeaderPointers << formattedHeaders.last().constData();
     
    918919*********************************************************************************************************************************/
    919920
    920 UINetworkReplyPrivate::UINetworkReplyPrivate(UINetworkRequestType type, const QNetworkRequest &request)
     921UINetworkReplyPrivate::UINetworkReplyPrivate(UINetworkRequestType type, const QNetworkRequest &request, const UserDictionary &requestHeaders)
    921922    : m_error(UINetworkReply::NoError)
    922923    , m_pThread(0)
     
    926927
    927928    /* Create and run reply thread: */
    928     m_pThread = new UINetworkReplyPrivateThread(type, request);
     929    m_pThread = new UINetworkReplyPrivateThread(type, request, requestHeaders);
    929930    connect(m_pThread, SIGNAL(sigDownloadProgress(qint64, qint64)),
    930931            this, SIGNAL(downloadProgress(qint64, qint64)), Qt::QueuedConnection);
     
    991992*********************************************************************************************************************************/
    992993
    993 UINetworkReply::UINetworkReply(UINetworkRequestType type, const QNetworkRequest &request)
    994     : m_pReply(new UINetworkReplyPrivate(type, request))
     994UINetworkReply::UINetworkReply(UINetworkRequestType type, const QNetworkRequest &request, const UserDictionary &requestHeaders)
     995    : m_pReply(new UINetworkReplyPrivate(type, request, requestHeaders))
    995996{
    996997    /* Prepare network-reply object connections: */
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.h

    r58423 r58425  
    8484    };
    8585
    86     /** Constructs network-reply of the passed @a type for the passed @a request. */
    87     UINetworkReply(UINetworkRequestType type, const QNetworkRequest &request);
     86    /** Constructs network-reply of the passed @a type for the passed @a request and @a requestHeaders. */
     87    UINetworkReply(UINetworkRequestType type, const QNetworkRequest &request, const UserDictionary &requestHeaders);
    8888    /** Destructs reply. */
    8989    ~UINetworkReply();
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp

    r58423 r58425  
    3737UINetworkRequest::UINetworkRequest(UINetworkRequestType type,
    3838                                   const QList<QNetworkRequest> &requests,
     39                                   const UserDictionary &requestHeaders,
    3940                                   UINetworkCustomer *pCustomer,
    4041                                   UINetworkManager *pNetworkManager)
     
    4344    , m_uuid(QUuid::createUuid())
    4445    , m_requests(requests)
     46    , m_requestHeaders(requestHeaders)
    4547    , m_iCurrentRequestIndex(0)
    4648    , m_pCustomer(pCustomer)
     
    188190{
    189191    /* Make network-request: */
    190     m_pReply = new UINetworkReply(m_type, m_request);
     192    m_pReply = new UINetworkReply(m_type, m_request, m_requestHeaders);
    191193    AssertMsg(m_pReply, ("Unable to make network-request!\n"));
    192194    /* Prepare listeners for m_pReply: */
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.h

    r58423 r58425  
    5858
    5959    /** Constructs network-request of the passed @a type
    60       * on the basis of the @a requests
     60      * on the basis of the passed @a requests and the @a requestHeaders
    6161      * for the @a pCustomer and @a pNetworkManager specified. */
    6262    UINetworkRequest(UINetworkRequestType type,
    6363                     const QList<QNetworkRequest> &requests,
     64                     const UserDictionary &requestHeaders,
    6465                     UINetworkCustomer *pCustomer,
    6566                     UINetworkManager *pNetworkManager);
     
    103104    QUuid m_uuid;
    104105    QList<QNetworkRequest> m_requests;
     106    /** Holds the request headers. */
     107    const UserDictionary m_requestHeaders;
    105108    QNetworkRequest m_request;
    106109    int m_iCurrentRequestIndex;
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp

    r58423 r58425  
    198198        QNetworkRequest request;
    199199        request.setUrl(url);
    200         request.setRawHeader("User-Agent", strUserAgent.toAscii());
    201         createNetworkRequest(UINetworkRequestType_GET, QList<QNetworkRequest>() << request);
     200        UserDictionary headers;
     201        headers["User-Agent"] = strUserAgent;
     202        createNetworkRequest(UINetworkRequestType_GET, QList<QNetworkRequest>() << request, headers);
    202203    }
    203204
  • trunk/src/VBox/Frontends/VirtualBox/src/net/tstSSLCertDownloads.cpp

    r58423 r58425  
    4545{
    4646    NOREF(hTest);
    47     QNetworkRequest Dummy;
    48     UINetworkReplyPrivateThread TestObj(UINetworkRequestType_GET, Dummy);
     47    QNetworkRequest Dummy1;
     48    UserDictionary Dummy2;
     49    UINetworkReplyPrivateThread TestObj(UINetworkRequestType_GET, Dummy1, Dummy2);
    4950
    5051    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette