VirtualBox

Ignore:
Timestamp:
May 22, 2019 3:27:01 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9470: Networking stuff: Switch file downloading procedure from RTHttpGetBinary to RTHttpGetFile; This allows us to avoid memory-chunk size limitation preventing large files from being downloaded; We do this only for files, not for other network requests, because we know the target filename in that case.

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

Legend:

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

    r76606 r78665  
    4444
    4545    /* Send GET request: */
    46     createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_source);
     46    createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << m_source, m_strTarget);
    4747}
    4848
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkCustomer.cpp

    r76606 r78665  
    3131
    3232void UINetworkCustomer::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> urls,
     33                                             const QString &strTarget /* = QString() */,
    3334                                             const UserDictionary requestHeaders /* = UserDictionary() */)
    3435{
    35     gNetworkManager->createNetworkRequest(enmType, urls, requestHeaders, this);
     36    gNetworkManager->createNetworkRequest(enmType, urls, strTarget, requestHeaders, this);
    3637}
    3738
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkCustomer.h

    r76581 r78665  
    5959protected:
    6060
    61     /** Creates network-request of the passed @a type on the basis of the passed @a urls and the @a requestHeaders. */
    62     void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> urls,
     61    /** Creates network-request of the passed @a type on the basis of the passed @a urls, @a strTarget and the @a requestHeaders. */
     62    void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> urls, const QString &strTarget = QString(),
    6363                              const UserDictionary requestHeaders = UserDictionary());
    6464
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.cpp

    r76825 r78665  
    102102}
    103103
    104 void UINetworkManager::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls,
     104void UINetworkManager::createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls, const QString &strTarget,
    105105                                            const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer)
    106106{
    107107    /* Create network-request: */
    108     UINetworkRequest *pNetworkRequest = new UINetworkRequest(enmType, urls, requestHeaders, pCustomer, this);
     108    UINetworkRequest *pNetworkRequest = new UINetworkRequest(enmType, urls, strTarget, requestHeaders, pCustomer, this);
    109109    /* Prepare created network-request: */
    110110    prepareNetworkRequest(pNetworkRequest);
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManager.h

    r76581 r78665  
    8787
    8888    /** Creates network-request of the passed @a type
    89       * on the basis of the passed @a urls and the @a requestHeaders for the @a pCustomer specified. */
    90     void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls,
     89      * on the basis of the passed @a urls, @a strTarget and the @a requestHeaders for the @a pCustomer specified. */
     90    void createNetworkRequest(UINetworkRequestType enmType, const QList<QUrl> &urls, const QString &strTarget,
    9191                              const UserDictionary &requestHeaders, UINetworkCustomer *pCustomer);
    9292
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.cpp

    r78066 r78665  
    6565
    6666    /** Constructs network-reply thread of the passed @a type for the passed @a url and @a requestHeaders. */
    67     UINetworkReplyPrivateThread(UINetworkRequestType type, const QUrl &url, const UserDictionary &requestHeaders);
     67    UINetworkReplyPrivateThread(UINetworkRequestType type, const QUrl &url, const QString &strTarget, const UserDictionary &requestHeaders);
    6868
    6969    /** @name APIs
     
    184184    /** Holds the request url. */
    185185    const QUrl m_url;
     186    /** Holds the request target. */
     187    const QString m_strTarget;
    186188    /** Holds the request headers. */
    187189    const UserDictionary m_requestHeaders;
     
    236238
    237239    /** Constructs network-reply private data of the passed @a type for the passed @a url and @a requestHeaders. */
    238     UINetworkReplyPrivate(UINetworkRequestType type, const QUrl &url, const UserDictionary &requestHeaders);
     240    UINetworkReplyPrivate(UINetworkRequestType type, const QUrl &url, const QString &strTarget, const UserDictionary &requestHeaders);
    239241    /** Destructs reply private data. */
    240242    ~UINetworkReplyPrivate();
     
    333335const QString UINetworkReplyPrivateThread::s_strCertificateFileName = QString("vbox-ssl-cacertificate.crt");
    334336
    335 UINetworkReplyPrivateThread::UINetworkReplyPrivateThread(UINetworkRequestType type, const QUrl &url, const UserDictionary &requestHeaders)
     337UINetworkReplyPrivateThread::UINetworkReplyPrivateThread(UINetworkRequestType type,
     338                                                         const QUrl &url,
     339                                                         const QString &strTarget,
     340                                                         const UserDictionary &requestHeaders)
    336341    : m_type(type)
    337342    , m_url(url)
     343    , m_strTarget(strTarget)
    338344    , m_requestHeaders(requestHeaders)
    339345    , m_hHttp(NIL_RTHTTP)
     
    552558        case UINetworkRequestType_GET:
    553559        {
    554             /* Perform blocking HTTP GET request: */
    555             void   *pvResponse = 0;
    556             size_t  cbResponse = 0;
    557             rc = RTHttpGetBinary(m_hHttp, m_url.toString().toUtf8().constData(), &pvResponse, &cbResponse);
    558             if (RT_SUCCESS(rc))
     560            /* Perform blocking HTTP GET request.
     561             * Keep in mind that if the target parameter is provided,
     562             * we are trying to download contents to file directly,
     563             * otherwise it will be downloaded to memory and it's
     564             * customer responsibility to save it afterwards. */
     565            if (m_strTarget.isEmpty())
    559566            {
    560                 m_reply = QByteArray((char*)pvResponse, (int)cbResponse);
    561                 RTHttpFreeResponse(pvResponse);
     567                void   *pvResponse = 0;
     568                size_t  cbResponse = 0;
     569                rc = RTHttpGetBinary(m_hHttp, m_url.toString().toUtf8().constData(), &pvResponse, &cbResponse);
     570                if (RT_SUCCESS(rc))
     571                {
     572                    m_reply = QByteArray((char*)pvResponse, (int)cbResponse);
     573                    RTHttpFreeResponse(pvResponse);
     574                }
     575            }
     576            else
     577            {
     578                rc = RTHttpGetFile(m_hHttp, m_url.toString().toUtf8().constData(), m_strTarget.toUtf8().constData());
     579                if (RT_SUCCESS(rc))
     580                {
     581                    QFile file(m_strTarget);
     582                    if (file.open(QIODevice::ReadOnly))
     583                        m_reply = file.readAll();
     584                }
    562585            }
    563586
     
    574597void UINetworkReplyPrivateThread::run()
    575598{
    576     /* Init: */
    577     RTR3InitExeNoArguments(RTR3INIT_FLAGS_SUPLIB); /** @todo r=bird: WTF? */
    578 
    579599    /* Create HTTP client: */
    580600    m_iError = RTHttpCreate(&m_hHttp);
     
    934954*********************************************************************************************************************************/
    935955
    936 UINetworkReplyPrivate::UINetworkReplyPrivate(UINetworkRequestType type, const QUrl &url, const UserDictionary &requestHeaders)
     956UINetworkReplyPrivate::UINetworkReplyPrivate(UINetworkRequestType type, const QUrl &url, const QString &strTarget, const UserDictionary &requestHeaders)
    937957    : m_error(UINetworkReply::NoError)
    938958    , m_pThread(0)
     
    942962
    943963    /* Create and run reply thread: */
    944     m_pThread = new UINetworkReplyPrivateThread(type, url, requestHeaders);
     964    m_pThread = new UINetworkReplyPrivateThread(type, url, strTarget, requestHeaders);
    945965    connect(m_pThread, &UINetworkReplyPrivateThread::sigDownloadProgress,
    946966            this, &UINetworkReplyPrivate::downloadProgress, Qt::QueuedConnection);
     
    10101030*********************************************************************************************************************************/
    10111031
    1012 UINetworkReply::UINetworkReply(UINetworkRequestType type, const QUrl &url, const UserDictionary &requestHeaders)
    1013     : m_pReply(new UINetworkReplyPrivate(type, url, requestHeaders))
     1032UINetworkReply::UINetworkReply(UINetworkRequestType type, const QUrl &url, const QString &strTarget, const UserDictionary &requestHeaders)
     1033    : m_pReply(new UINetworkReplyPrivate(type, url, strTarget, requestHeaders))
    10141034{
    10151035    /* Prepare network-reply object connections: */
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkReply.h

    r76581 r78665  
    8282    };
    8383
    84     /** Constructs network-reply of the passed @a type for the passed @a url and @a requestHeaders. */
    85     UINetworkReply(UINetworkRequestType type, const QUrl &url, const UserDictionary &requestHeaders);
     84    /** Constructs network-reply of the passed @a type for the passed @a url, @a strTarget and @a requestHeaders. */
     85    UINetworkReply(UINetworkRequestType type, const QUrl &url, const QString &strTarget, const UserDictionary &requestHeaders);
    8686    /** Destructs reply. */
    8787    ~UINetworkReply();
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.cpp

    r76606 r78665  
    2828UINetworkRequest::UINetworkRequest(UINetworkRequestType enmType,
    2929                                   const QList<QUrl> &urls,
     30                                   const QString &strTarget,
    3031                                   const UserDictionary &requestHeaders,
    3132                                   UINetworkCustomer *pCustomer,
     
    3435    , m_enmType(enmType)
    3536    , m_urls(urls)
     37    , m_strTarget(strTarget)
    3638    , m_requestHeaders(requestHeaders)
    3739    , m_pCustomer(pCustomer)
     
    192194{
    193195    /* Create network-reply: */
    194     m_pReply = new UINetworkReply(m_enmType, m_url, m_requestHeaders);
     196    m_pReply = new UINetworkReply(m_enmType, m_url, m_strTarget, m_requestHeaders);
    195197    AssertPtrReturnVoid(m_pReply.data());
    196198    {
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkRequest.h

    r76581 r78665  
    7272
    7373    /** Constructs network-request of the passed @a enmType
    74       * on the basis of the passed @a urls and the @a requestHeaders
     74      * on the basis of the passed @a urls, @a strTarget and the @a requestHeaders
    7575      * for the @a pCustomer and @a pNetworkManager specified. */
    7676    UINetworkRequest(UINetworkRequestType enmType,
    7777                     const QList<QUrl> &urls,
     78                     const QString &strTarget,
    7879                     const UserDictionary &requestHeaders,
    7980                     UINetworkCustomer *pCustomer,
     
    125126    /** Holds the request urls. */
    126127    const QList<QUrl> m_urls;
     128    /** Holds the request target. */
     129    const QString m_strTarget;
    127130    /** Holds the request headers. */
    128131    const UserDictionary m_requestHeaders;
  • trunk/src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp

    r76825 r78665  
    311311    QUrl fullUrl(m_url);
    312312    fullUrl.setQuery(url);
    313     createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << fullUrl, headers);
     313    createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << fullUrl, QString(), headers);
    314314}
    315315
  • trunk/src/VBox/Frontends/VirtualBox/src/net/tstSSLCertDownloads.cpp

    r78066 r78665  
    3737    NOREF(hTest);
    3838    QUrl Dummy1;
    39     UserDictionary Dummy2;
    40     UINetworkReplyPrivateThread TestObj(UINetworkRequestType_GET, Dummy1, Dummy2);
     39    QString strDummy2;
     40    UserDictionary Dummy3;
     41    UINetworkReplyPrivateThread TestObj(UINetworkRequestType_GET, Dummy1, strDummy2, Dummy3);
    4142
    4243    /*
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