VirtualBox

Changeset 11401 in vbox for trunk


Ignore:
Timestamp:
Aug 13, 2008 4:46:39 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
34690
Message:

Fe/Qt4: New Version notifier reworked according latest requirements (package type in url's body and all the extended information in user-agent header). Network framework reworked to use headers+body for POST request instead of just URL.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxNetworkFramework.h

    r8155 r11401  
    2929#include <QThread>
    3030#include <QDataStream>
     31#include <QStringList>
    3132
    3233typedef happyhttp::Connection HConnect;
     
    5253    }
    5354
    54     void postRequest (const QString &aHost, const QString &aUrl);
     55    void postRequest (const QString &aHost, const QString &aUrl, const QString &aBody,
     56                      const QStringList &aHeaders = QStringList());
    5557
    5658signals:
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxRegistrationDlg.h

    r9729 r11401  
    7070private:
    7171
    72     void postRequest (const QString &aHost, const QString &aPath);
     72    void postRequest (const QString &aHost, const QString &aUrl, const QString &aBody);
    7373    void abortRegisterRequest (const QString &aReason);
    74     QString getPlatform();
    7574    void finish();
    7675
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUpdateDlg.h

    r10611 r11401  
    127127
    128128    /* Private functions */
    129     void searchAbort (const QString &aReason);
    130     void searchComplete (const QString &aFullList);
     129    void networkAbort (const QString &aReason);
     130    void processResponse (const QString &aResponse);
    131131
    132132    /* Private variables */
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxNetworkFramework.cpp

    r8155 r11401  
    132132
    133133void VBoxNetworkFramework::postRequest (const QString &aHost,
    134                                         const QString &aUrl)
     134                                        const QString &aUrl,
     135                                        const QString &aBody,
     136                                        const QStringList &aHeaders)
    135137{
    136138    /* Network requests thread class */
     
    139141    public:
    140142
    141         Thread (QObject *aProc, const QString &aHost, const QString &aUrl)
    142             : mProc (aProc), mHost (aHost), mUrl (aUrl) {}
     143        Thread (QObject *aHandler, const QString &aHost, const QString &aUrl,
     144                const QString &aBody, const QStringList &aHeaders)
     145            : mHandler (aHandler), mHost (aHost), mUrl (aUrl)
     146            , mBody (aBody), mHeaders (aHeaders) {}
    143147
    144148        virtual void run()
     
    146150            try
    147151            {
     152                /* Create & setup connection */
    148153                HConnect conn (mHost.toAscii().constData(), 80);
    149                 conn.setcallbacks (onBegin, onData, onFinish, mProc);
    150                 const char *headers[] =
    151                 {
    152                     "Connection", "close",
    153                     "Content-type", "application/x-www-form-urlencoded",
    154                     "Accept", "text/plain",
    155                     0
    156                 };
    157 
    158                 conn.request ("POST", mUrl.toAscii().constData(), headers, 0, 0);
     154                conn.setcallbacks (onBegin, onData, onFinish, mHandler);
     155
     156                /* Format POST request */
     157                conn.putrequest ("POST", mUrl.toAscii().constData());
     158
     159                /* Append standard headers */
     160                conn.putheader ("Connection", "close");
     161                conn.putheader ("Content-Length", mBody.size());
     162                conn.putheader ("Content-type", "application/x-www-form-urlencoded");
     163                conn.putheader ("Accept", "text/plain");
     164
     165                /* Append additional headers */
     166                for (int i = 0; i < mHeaders.size(); i = i + 2)
     167                    conn.putheader (mHeaders [i].toAscii().constData(),
     168                                    mHeaders [i + 1].toAscii().constData());
     169
     170                /* Finishing header */
     171                conn.endheaders();
     172
     173                /* Append & send body */
     174                conn.send ((const unsigned char*) mBody.toAscii().constData(),
     175                           mBody.toAscii().size());
     176
     177                /* Pull the connection for response */
    159178                while (conn.outstanding())
    160179                    conn.pump();
     
    162181            catch (happyhttp::Wobbly &ex)
    163182            {
    164                 QApplication::postEvent (mProc, new PostErrorEvent (ex.what()));
     183                QApplication::postEvent (mHandler, new PostErrorEvent (ex.what()));
    165184            }
    166185        }
     
    168187    private:
    169188
    170         QObject  *mProc;
    171         QString   mHost;
    172         QString   mUrl;
     189        QObject *mHandler;
     190        QString mHost;
     191        QString mUrl;
     192        QString mBody;
     193        QStringList mHeaders;
    173194    };
    174195
     
    176197        mNetworkThread->wait (1000);
    177198    delete mNetworkThread;
    178     mNetworkThread = new Thread (this, aHost, aUrl);
     199    mNetworkThread = new Thread (this, aHost, aUrl, aBody, aHeaders);
    179200    mNetworkThread->start();
    180201}
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxRegistrationDlg.cpp

    r11388 r11401  
    332332
    333333    /* Handshake */
    334     QString argument = QString ("?version=%1").arg (version);
    335     postRequest (mUrl.host(), mUrl.path() + argument);
     334    QString body = QString ("version=%1").arg (version);
     335    postRequest (mUrl.host(), mUrl.path(), body);
    336336}
    337337
     
    341341    mHandshake = false;
    342342    QString version = vboxGlobal().virtualBox().GetVersion();
    343     QString platform = getPlatform();
     343    QString platform = vboxGlobal().platformInfo();
    344344    QString name = mLeName->text();
    345345    QString email = mLeEmail->text();
     
    351351
    352352    /* Registration */
    353     QString argument;
    354     argument += QString ("?version=%1").arg (version);
    355     argument += QString ("&key=%1").arg (mKey);
    356     argument += QString ("&platform=%1").arg (platform);
    357     argument += QString ("&name=%1").arg (name);
    358     argument += QString ("&email=%1").arg (email);
    359     argument += QString ("&private=%1").arg (prvt);
    360 
    361     postRequest (mUrl.host(), mUrl.path() + argument);
     353    QString body;
     354    body += QString ("version=%1").arg (version);
     355    body += QString ("&key=%1").arg (mKey);
     356    body += QString ("&platform=%1").arg (platform);
     357    body += QString ("&name=%1").arg (name);
     358    body += QString ("&email=%1").arg (email);
     359    body += QString ("&private=%1").arg (prvt);
     360
     361    postRequest (mUrl.host(), mUrl.path(), body);
    362362}
    363363
     
    442442
    443443void VBoxRegistrationDlg::postRequest (const QString &aHost,
    444                                        const QString &aPath)
     444                                       const QString &aUrl,
     445                                       const QString &aBody)
    445446{
    446447    delete mNetfw;
     
    455456             SLOT (onNetError (const QString&)));
    456457    mTimeout->start (MaxWaitTime);
    457     mNetfw->postRequest (aHost, aPath);
     458    mNetfw->postRequest (aHost, aUrl, aBody);
    458459}
    459460
     
    475476}
    476477
    477 QString VBoxRegistrationDlg::getPlatform()
    478 {
    479     QString platform;
    480 
    481 #if defined (Q_OS_WIN)
    482     platform = "win";
    483 #elif defined (Q_OS_LINUX)
    484     platform = "linux";
    485 #elif defined (Q_OS_MACX)
    486     platform = "macosx";
    487 #elif defined (Q_OS_OS2)
    488     platform = "os2";
    489 #elif defined (Q_OS_FREEBSD)
    490     platform = "freebsd";
    491 #elif defined (Q_OS_SOLARIS)
    492     platform = "solaris";
    493 #else
    494     platform = "unknown";
    495 #endif
    496 
    497     /* the format is <system>.<bitness> */
    498     platform += QString (".%1").arg (ARCH_BITS);
    499 
    500     /* add more system information */
    501 #if defined (Q_OS_WIN)
    502     OSVERSIONINFO versionInfo;
    503     ZeroMemory (&versionInfo, sizeof (OSVERSIONINFO));
    504     versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    505     GetVersionEx (&versionInfo);
    506     int major = versionInfo.dwMajorVersion;
    507     int minor = versionInfo.dwMinorVersion;
    508     int build = versionInfo.dwBuildNumber;
    509     QString sp = QString::fromUtf16 ((ushort*)versionInfo.szCSDVersion);
    510 
    511     QString distrib;
    512     if (major == 6)
    513         distrib = QString ("Windows Vista %1");
    514     else if (major == 5)
    515     {
    516         if (minor == 2)
    517             distrib = QString ("Windows Server 2003 %1");
    518         else if (minor == 1)
    519             distrib = QString ("Windows XP %1");
    520         else if (minor == 0)
    521             distrib = QString ("Windows 2000 %1");
    522         else
    523             distrib = QString ("Unknown %1");
    524     }
    525     else if (major == 4)
    526     {
    527         if (minor == 90)
    528             distrib = QString ("Windows Me %1");
    529         else if (minor == 10)
    530             distrib = QString ("Windows 98 %1");
    531         else if (minor == 0)
    532             distrib = QString ("Windows 95 %1");
    533         else
    534             distrib = QString ("Unknown %1");
    535     }
    536     else
    537         distrib = QString ("Unknown %1");
    538     distrib = distrib.arg (sp);
    539     QString version = QString ("%1.%2").arg (major).arg (minor);
    540     QString kernel = QString ("%1").arg (build);
    541     platform += QString (" [Distribution: %1 | Version: %2 | Build: %3]")
    542         .arg (distrib).arg (version).arg (kernel);
    543 #elif defined (Q_OS_OS2)
    544     // TODO: add sys info for os2 if any...
    545 #elif defined (Q_OS_LINUX) || defined (Q_OS_MACX) || defined (Q_OS_FREEBSD) || defined (Q_OS_SOLARIS)
    546     /* Get script path */
    547     char szAppPrivPath [RTPATH_MAX];
    548     int rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath));
    549     Assert (RT_SUCCESS (rc));
    550     /* Run script */
    551     QByteArray result =
    552         Process::singleShot (QString (szAppPrivPath) + "/VBoxSysInfo.sh");
    553     if (!result.isNull())
    554         platform += QString (" [%1]").arg (QString (result).trimmed());
    555 #endif
    556     return platform;
    557 }
    558 
    559478void VBoxRegistrationDlg::finish()
    560479{
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxUpdateDlg.cpp

    r11186 r11401  
    221221    , mNetfw (0)
    222222    , mTimeout (new QTimer (this))
    223     , mUrl ("http://www.virtualbox.org/download/latest_version")
     223    , mUrl ("http://innotek.de/query.php")
    224224    , mForceRun (aForceRun)
    225225    , mSuicide (false)
     
    284284void VBoxUpdateDlg::search()
    285285{
    286     /* Show progress bar */
    287     mPbCheck->show();
    288 
    289     /* Start downloading latest releases file */
     286    /* Create & setup network framework */
    290287    mNetfw = new VBoxNetworkFramework();
    291288    connect (mNetfw, SIGNAL (netBegin (int)),
     
    297294    connect (mNetfw, SIGNAL (netError (const QString&)),
    298295             SLOT (onNetError (const QString&)));
     296
     297    QString body = QString ("platform=%1")
     298                   .arg (vboxGlobal().virtualBox().GetPackageType());
     299    QStringList header ("User-Agent");
     300    header << QString ("VirtualBox %1 <%2>")
     301              .arg (vboxGlobal().virtualBox().GetVersion())
     302              .arg (vboxGlobal().platformInfo());
     303
     304    /* Show progress bar & send composed information */
     305    mPbCheck->show();
    299306    mTimeout->start (MaxWaitTime);
    300     mNetfw->postRequest (mUrl.host(), mUrl.path());
     307    mNetfw->postRequest (mUrl.host(), mUrl.path(), body, header);
    301308}
    302309
     
    309316void VBoxUpdateDlg::processTimeout()
    310317{
    311     searchAbort (tr ("Connection timed out."));
     318    networkAbort (tr ("Connection timed out."));
    312319}
    313320
     
    318325
    319326    if (aStatus == 404)
    320         searchAbort (tr ("Could not locate the latest version "
     327        networkAbort (tr ("Could not locate the latest version "
    321328            "list on the server (response: %1).").arg (aStatus));
    322329    else
     
    338345
    339346    mTimeout->stop();
    340     searchComplete (aTotalData);
     347    processResponse (aTotalData);
    341348}
    342349
     
    344351void VBoxUpdateDlg::onNetError (const QString &aError)
    345352{
    346     searchAbort (aError);
     353    networkAbort (aError);
    347354}
    348355
     
    355362}
    356363
    357 void VBoxUpdateDlg::searchAbort (const QString &aReason)
     364void VBoxUpdateDlg::networkAbort (const QString &aReason)
    358365{
    359366    /* Protect against double kill request. */
     
    380387}
    381388
    382 void VBoxUpdateDlg::searchComplete (const QString &aFullList)
     389void VBoxUpdateDlg::processResponse (const QString &aResponse)
    383390{
    384391    /* Hide progress bar */
    385392    mPbCheck->hide();
    386393
    387     QStringList list = aFullList.split ("\n", QString::SkipEmptyParts);
    388 
    389     QString latestVersion (list [0]);
    390     latestVersion.remove (QRegExp ("Version: "));
    391     QString currentVersion (vboxGlobal().virtualBox().GetVersion());
    392     VBoxVersion cv (currentVersion);
    393     VBoxVersion lv (latestVersion);
    394 
    395     if (cv < lv)
    396     {
    397         /* Search for the current platform link */
    398         QString packageType = vboxGlobal().virtualBox().GetPackageType();
    399         for (int i = 1; i < list.size(); ++ i)
    400         {
    401             QStringList platformInfo = list [i].split (": ");
    402             if (packageType == platformInfo [0])
    403             {
    404                 /* If newer version of necessary package found */
    405                 if (isHidden())
    406                 {
    407                     /* For background update */
    408                     vboxProblem().showUpdateSuccess (vboxGlobal().mainWindow(),
    409                         lv.toString(), platformInfo [1]);
    410                     QTimer::singleShot (0, this, SLOT (accept()));
    411                 }
    412                 else
    413                 {
    414                     /* For wizard update */
    415                     mTextSuccessInfo->setText (mTextSuccessInfo->text()
    416                         .arg (lv.toString(), platformInfo [1], platformInfo [1]));
    417                     mTextSuccessInfo->show();
    418                     mPageStack->setCurrentIndex (1);
    419                 }
    420                 return;
    421             }
    422         }
    423     }
    424 
    425     /* If no newer version of necessary package found */
    426     if (isHidden())
    427     {
    428         /* For background update */
    429         if (mForceRun)
    430             vboxProblem().showUpdateNotFound (vboxGlobal().mainWindow());
    431         QTimer::singleShot (0, this, SLOT (accept()));
    432     }
    433     else
    434     {
    435         /* For wizard update */
    436         mTextNotFoundInfo->show();
    437         mPageStack->setCurrentIndex (1);
    438     }
    439 }
    440 
     394    if (aResponse.indexOf (QRegExp ("^\\d+\\.\\d+\\.\\d+ \\S+$")) == 0)
     395    {
     396        /* Newer version of necessary package found */
     397        QStringList response = aResponse.split (" ", QString::SkipEmptyParts);
     398
     399        if (isHidden())
     400        {
     401            /* For background update */
     402            vboxProblem().showUpdateSuccess (vboxGlobal().mainWindow(),
     403                response [0], response [1]);
     404            QTimer::singleShot (0, this, SLOT (accept()));
     405        }
     406        else
     407        {
     408            /* For wizard update */
     409            mTextSuccessInfo->setText (mTextSuccessInfo->text()
     410                .arg (response [0], response [1], response [1]));
     411            mTextSuccessInfo->show();
     412            mPageStack->setCurrentIndex (1);
     413        }
     414    }
     415    else /* if (aResponse == "UPTODATE") */
     416    {
     417        /* No newer version of necessary package found */
     418        if (isHidden())
     419        {
     420            /* For background update */
     421            if (mForceRun)
     422                vboxProblem().showUpdateNotFound (vboxGlobal().mainWindow());
     423            QTimer::singleShot (0, this, SLOT (accept()));
     424        }
     425        else
     426        {
     427            /* For wizard update */
     428            mTextNotFoundInfo->show();
     429            mPageStack->setCurrentIndex (1);
     430        }
     431    }
     432}
     433
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