예제 #1
0
파일: main.cpp 프로젝트: cdemel/SO_examples
QString networkRequest(QString path) {

    QNetworkAccessManager m_Manager;
    QEventLoop eventLoop;
    ListErrs listErrs;
    QNetworkRequest request(QUrl(QString(SERVER_URL) + path));
    QList<QSslCertificate> certList;

    qDebug() << "license server url: " << SERVER_URL;

    // Verisign G5 root cert from:
    // http://www.verisign.com/repository/roots/root-certificates/PCA-3G5.pem
    QFile certFile1(":/twitter.txt"); 
    qDebug() << "opening Verisign cert: " << certFile1.open(QIODevice::ReadOnly);
    QSslCertificate cert1(&certFile1, QSsl::Pem);
    qDebug() << "Is Verisign valid? " << cert1.isValid();
    qDebug() << "Verisign org name? " << cert1.issuerInfo(QSslCertificate::Organization);
    QByteArray dig = cert1.digest();
    qDebug() << "Verisign digest? " << (int)dig[0] << (int)dig[1] << (int)dig[2] << (int)dig[3] << (int)dig[4] << (int)dig[5];
    qDebug() << "Verisign serial number? " << cert1.serialNumber();
    qDebug() << "Verisign expires? " << cert1.expiryDate();
    qDebug() << "Verisign effective? " << cert1.effectiveDate();
    qDebug() << "version == 10.5 " << (QSysInfo::MacintoshVersion == QSysInfo::MV_10_5);
      certList.append(cert1);

    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    QSslConfiguration sslConfig(request.sslConfiguration());
    sslConfig.setCaCertificates(certList);
    request.setSslConfiguration(sslConfig);

    QNetworkReply *reply = m_Manager.get(request);
    QObject::connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
    QObject::connect(&m_Manager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), &listErrs, SLOT(go(QNetworkReply*,QList<QSslError>)));
    // Quit after 15 seconds in any event
    QTimer::singleShot(15000, &eventLoop, SLOT(quit()));
    eventLoop.exec();
    QString result = reply->readAll();
    if (reply->error() != QNetworkReply::NoError)
    {
        result = QString(NETWORK_ERROR) + " - "  + reply->errorString();
    }
    qDebug() << result;
    return result;
}
예제 #2
0
BluecherryApp::BluecherryApp()
    : nam(new QNetworkAccessManager(this)), liveView(new LiveViewManager(this)),
      audioPlayer(new AudioPlayer(this)),
      globalRate(new TransferRateCalculator(this)), m_updateChecker(0),
      m_livePaused(false), m_inPauseQuery(false),
      m_screensaverInhibited(false), m_screensaveValue(0)
{
    Q_ASSERT(!bcApp);
    bcApp = this;

    m_serverRepository = new DVRServerRepository(this);

    connect(qApp, SIGNAL(aboutToQuit()), SLOT(aboutToQuit()));

    appIcon.addFile(QLatin1String(":/icons/icon16.png"));
    appIcon.addFile(QLatin1String(":/icons/icon32.png"));
    appIcon.addFile(QLatin1String(":/icons/icon64.png"));
    appIcon.addFile(QLatin1String(":/icons/bluecherry-client.png"));
    qApp->setWindowIcon(appIcon);

    connect(nam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));

    /* Don't use the system CAs to verify certificates */
    QSslConfiguration sslConfig(QSslConfiguration::defaultConfiguration());
    sslConfig.setCaCertificates(QList<QSslCertificate>());
#if QT_VERSION >= 0x040800
    /* SNI breaks connections (before sslError, even) when the hostname does
     * not match the server. */
    sslConfig.setSslOption(QSsl::SslOptionDisableServerNameIndication, true);
#endif
    QSslConfiguration::setDefaultConfiguration(sslConfig);

    clearTempFiles();
    loadServers();
    if (shouldAddLocalServer())
        addLocalServer();
    autoConnectServers();

    sendSettingsChanged();

    m_updateChecker = new UpdateChecker(nam, this);
    connect(m_updateChecker, SIGNAL(newVersionAvailable(Version)), this, SLOT(newVersionAvailable(Version)));
    QSettings settings;

    if (!settings.value(QLatin1String("ui/disableUpdateNotifications"), false).toBool())
    {
        startUpdateChecker();
    }

    m_thumbnailManager = new ThumbnailManager(this);

    m_mediaDownloadManager = new MediaDownloadManager(this);
    m_mediaDownloadManager->setCookieJar(nam->cookieJar());

    m_eventDownloadManager = new EventDownloadManager(this);
    connect(m_serverRepository, SIGNAL(serverRemoved(DVRServer*)), m_eventDownloadManager, SLOT(serverRemoved(DVRServer*)));

    registerVideoPlayerFactory();

    connect(qApp, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(commitDataRequest(QSessionManager&)));
    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveSettings()));
}