Exemple #1
0
void Translator::translate(const QString &text, const QString &language, QObject *sender) {
	qDebug() << "Translator::translate() " + text;

	Configuration *config = Configuration::getInstance();

	QUrl translatorUrl("http://ajax.googleapis.com/ajax/services/language/translate");
	QString request = "?v=1.0&q=" + QUrl::toPercentEncoding(text) + "&format=html&langpair=%7C" + language;

	QHttpRequestHeader header;
	header.setRequest("GET", translatorUrl.path() + request);
	header.setValue("Host", translatorUrl.host());
	header.setValue("Referer", "Qwit");

	if (config->useProxy) {
		http->setProxy(config->proxyAddress, config->proxyPort, config->proxyUsername, config->proxyPassword);
	} else {
		http->setProxy(QNetworkProxy(QNetworkProxy::NoProxy));
	}

	if(translatorUrl.toString().indexOf("https") == 0) {
		http->setHost(translatorUrl.host(), QHttp::ConnectionModeHttps, translatorUrl.port(443));
	} else {
		http->setHost(translatorUrl.host(), QHttp::ConnectionModeHttp, translatorUrl.port(80));
	}

	buffer = new QBuffer(this);
	buffer->open(QIODevice::WriteOnly);
	int requestId = http->request(header, 0, buffer);
	requestSender[requestId] = sender;
}
Exemple #2
0
QHttpRequestHeader *BrisaEventProxy::getRenewRequest(const int timeout) const {
    if (this->getSid().isEmpty()) {
        qWarning() << "Renew failed: SID field not filled.";
        return NULL;
    }

    QHttpRequestHeader *request = new QHttpRequestHeader("SUBSCRIBE", eventSub);
    request->setValue("HOST", host + ":" + port);
    request->setValue("SID", getSid());
    request->setValue("TIMEOUT", (timeout > 0)
                                    ? "Second-" + QString().setNum(timeout)
                                    : "INFINITE");
    return request;
}
Exemple #3
0
void HttpThread::run()
{
    QHttpRequestHeader header;
    header.setRequest("GET",url.path());
    header.setValue("Range","bytes="+QString::number(startByte)+"-"+QString::number(endByte));
    QString userAgent = "getit/0.1";
    header.setValue("Host", url.host());
    header.setValue("Accept", "*/*");
    header.setValue("User-Agent", userAgent);
    http.setHost(url.host());
    http.request(header);
    connect(&http,SIGNAL(readyRead(QHttpResponseHeader)),this,SLOT(writeToFile(QHttpResponseHeader)));
    connect(&http,SIGNAL(done(bool)),this,SLOT(finished(bool)));
    this->exec();
}
void MusicBrainzDownloader::loadNextPage()
{
LAST_STEP("MusicBrainzDownloader::loadNextPage");
    CB_ASSERT (!m_pQHttp->hasPendingRequests());
    CB_ASSERT (!m_pImageQHttp->hasPendingRequests());

    ++m_nLastLoadedPage;
    CB_ASSERT (m_nLastLoadedPage <= m_nTotalPages - 1);

    //m_eState = NEXT;
    setWaiting(SEARCH);
    //char a [20];
    //sprintf(a, "&page=%d", m_nLastLoadedPage + 1);
    //string s (m_strQuery + a);

    QHttpRequestHeader header ("GET", convStr(m_strQuery));
    //header.setValue("Host", "www.musicbrainz.org");
    header.setValue("Host", "musicbrainz.org");
    //header.setValue("Accept-Encoding", "gzip");
    delay();
    //qDebug("--------------\npath %s", header.path().toUtf8().constData());
    //qDebug("qry %s", m_strQuery.c_str());
    m_pQHttp->request(header);
    //cout << "sent search " << m_pQHttp->request(header) << " for page " << (m_nLastLoadedPage + 1) << endl;
}
QString GoogleTranslateHttp::request(const QString &text, const QString &fromLanguage,
                                                          const QString &toLanguage)
{
    const QString &word = GoogleTranslateUtil::getSearchWord(text);
    qDebug() << "Searching " << word << " from = " << fromLanguage << " to = " << toLanguage;
    QString url = QString("/translate_a/t?client=t&sl="+
                           fromLanguage +
                           "&tl=" +
                           toLanguage);
    setHost("www.google.com");

    QHttpRequestHeader header = QHttpRequestHeader("POST", url, 1, 1);
    header.setValue("Host", "www.google.com");
    header.setValue("User-Agent", "Mozilla/5.0");
    header.setContentLength(word.length());

    QByteArray ba("text=");
    ba.append(word.toUtf8());
    QHttp::request(header, ba);

    loop.exec();
    return QString::fromUtf8(readAll());
}
Exemple #6
0
void CEditorWidget::translateIt()
{
    m_Http->abort();
    QString text = QString::fromUtf8(QUrl::toPercentEncoding( plainTextEdit_Input->text() ));
    QString url = QString("/translate_a/t?client=t&sl="
                       +  QString( gGoogleLang[comboBox_LangSrc->currentIndex()].code )
                       + "&tl="
                       + QString( gGoogleLang[comboBox_LangDest->currentIndex()].code ) );

    QHttpRequestHeader header = QHttpRequestHeader("POST", url, 1, 1);
    header.setValue("Host", "www.google.com");
    header.setValue("User-Agent", "Mozilla/5.0");
    header.setValue("Accept-Encoding", "deflate");
    header.setContentLength( text.length() );
    header.setValue("Connection", "Close");

    QByteArray ba("text=");
    ba.append( text );

    m_Http->setHost("www.google.com");
    m_Http->request(header,ba);

    setBlocking( true );
}
Exemple #7
0
QString ImportIconsWizard::wget(QUrl& url,const QString& strParam )
{
    QByteArray raw(strParam.toAscii());
    QBuffer data(&raw);
    QHttpRequestHeader header;

    header.setContentType(QString("application/x-www-form-urlencoded"));
    header.setContentLength(raw.size());

    header.setValue("User-Agent", "MythTV Channel Icon lookup bot");

    QString str = HttpComms::postHttp(url,&header,&data);

    return str;
}
Exemple #8
0
QHttpRequestHeader *BrisaEventProxy::getSubscriptionRequest(const int timeout) {
    QHttpRequestHeader *request = new QHttpRequestHeader("SUBSCRIBE", eventSub);

    // Remote host
    request->setValue("HOST", host + ":" + QString().setNum(port));

    // Our URL for receiving notifications
    const QUrl url = this->getUrl();

    qDebug() << "Url: " << url.host() << " port: " << url.port();
    request->setValue("CALLBACK", "<http://"
                                    + url.host()
                                    + ":"
                                    + QString().setNum(url.port())
                                    + "/"
                                    + QString().setNum(deliveryPath)
                                    + ">");

    request->setValue("NT", "upnp:event");
    request->setValue("TIMEOUT", (timeout > 0)
                                    ? "Second-" + QString().setNum(timeout)
                                    : "INFINITE"); // INFINITE is obsolete in UPnP 1.1
    return request;
}
void MusicBrainzDownloader::requestAlbum(int nAlbum)
{
LAST_STEP("MusicBrainzDownloader::requestAlbum");
    //CB_ASSERT (!m_pQHttp->hasPendingRequests() && !m_pImageQHttp->hasPendingRequests());  // ttt1 triggered: https://sourceforge.net/apps/mantisbt/mp3diags/view.php?id=36 ?? perhaps might happen when MB returns errors ; see also DiscogsDownloader::requestAlbum
    CB_ASSERT (!m_pQHttp->hasPendingRequests());
    CB_ASSERT (!m_pImageQHttp->hasPendingRequests());

    m_nLoadingAlbum = nAlbum;
    setWaiting(ALBUM);
    //string s ("/release/" + m_vAlbums[nAlbum].m_strId + "?f=xml&api_key=f51e9c8f6c");
    string s ("/ws/1/release/" + m_vAlbums[nAlbum].m_strId + "?type=xml&inc=tracks+artist+release-events+url-rels");

    QHttpRequestHeader header ("GET", convStr(s));
    header.setValue("Host", "musicbrainz.org");
    //header.setValue("Accept-Encoding", "gzip");
    delay();
    m_pQHttp->request(header);
    //cout << "sent album " << m_vAlbums[nAlbum].m_strId << " - " << m_pQHttp->request(header) << endl;
    addNote("getting album info ...");
}
QString ImportIconsWizard::wget(QUrl& url,const QString& strParam )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QByteArray raw(strParam.toLatin1());
    QBuffer data(&raw);
    QHttpRequestHeader header;

    header.setContentType(QString("application/x-www-form-urlencoded"));
    header.setContentLength(raw.size());

    header.setValue("User-Agent", "MythTV Channel Icon lookup bot");

    QString str = HttpComms::postHttp(url,&header,&data);

    return str;
#else
#warning ImportIconsWizard::wget() not ported to Qt5
    return QString();
#endif
}
Exemple #11
0
void HttpComms::request(QUrl               &url, 
                        QHttpRequestHeader &header, 
                        int                 timeoutms, 
                        QIODevice          *pData /* = NULL*/ )
{
    quint16 port = 80;

    if (url.port() != -1) 
        port = url.port();
    
    http->setHost(url.host(), port);

    m_url = url.toString();
    m_curRequest = header;

    if (m_timer)
        m_timer->stop();

    if (timeoutms > 0 )
    {
        if (!m_timer)
        {
            m_timer = new QTimer();
            connect(m_timer, SIGNAL(timeout()), SLOT(timeout()));
        }
        m_timeoutInterval = timeoutms;
        m_timer->setSingleShot(true);
        m_timer->start(timeoutms);
    }

    if (!m_cookie.isEmpty())
    {
        header.setValue("Cookie", m_cookie);
    }

    http->request(header, pData);
}
Exemple #12
0
void
SmugMug::WebService::_uploadMultipartHttpPost (
    const QString &AlbumId,
    const QString &FileName,
    const QString &Caption) {

    const QString BOUNDARY = "----------ThIs_Is_tHe_bouNdaRY_$";
    const QString CFLF = "\r\n";

    QUrl url (UploadEndpoint + "/photos/xmladd.mg");

    _dataOut.clear ();

    QByteArray imageData;
    QFileInfo fi (FileName);
    QFile file (fi.absoluteFilePath ());
    if (file.open (QIODevice::ReadOnly)) {

        imageData = file.readAll ();
        file.close ();
    }

    // Album ID
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"AlbumID\"") + CFLF + CFLF;
    _dataOut += AlbumId + CFLF;

    // Session ID
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"SessionID\"") + CFLF + CFLF;
    _dataOut += _sessionId + CFLF;

    // Byte Count
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"ByteCount\"") + CFLF + CFLF;
    _dataOut += QString::number (imageData.length ()) + CFLF;

    // Response Type
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"ResponseType\"") + CFLF + CFLF;
    _dataOut += QString ("REST") + CFLF;

    // MD5 Sum
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"MD5Sum\"") + CFLF + CFLF;
    _dataOut += md5_digest (imageData) + CFLF;
//   _dataOut += QString ("a234ab01efe2775e9f69477831c3d3ca") + CFLF;

    // Caption
    if (!Caption.isEmpty ()) {

        _dataOut += QString ("--") + BOUNDARY + CFLF;
        _dataOut += QString ("Content-Disposition: form-data; name=\"Caption\"") + CFLF + CFLF;
        _dataOut += Caption + CFLF;
    }

    // Add the file
    _dataOut += QString ("--") + BOUNDARY + CFLF;

    _dataOut += QString ("Content-Disposition: form-data; name=\"Image\"") +
                QString ("; filename=\"%1\"").arg (fi.fileName ()) + CFLF;

    _dataOut += QString ("Content-Type: image/jpeg") + CFLF;
    _dataOut += QString ("Content-length: %1").arg (imageData.length ()) + CFLF + CFLF;

    qDebug () << _dataOut;

    _dataOut += imageData;
    _dataOut += CFLF;

    _dataOut += QString ("--") + BOUNDARY + "--" + CFLF;

    QHttpRequestHeader header ("POST", url.path ());
    header.setValue ("Host", url.host ());
//   header.setValue ("Cookie", QString ("SMSESS=") + _sessionId);
    header.setContentType (QString ("multipart/form-data; boundary=") + BOUNDARY);
    header.setContentLength (_dataOut.length ());
//   header.setValue ("Connection", "Keep-Alive");

    qDebug () << header.toString ();

    _idImageUpload = _httpRequest (url, header, _dataOut);

    qDebug () << "imageUpload:" << fi.absoluteFilePath ();
}
Exemple #13
0
bool SOAPClient::SendSOAPRequest( const QString    &sMethod, 
                                        QStringMap &list, 
                                        int        &nErrCode, 
                                        QString    &sErrDesc,
                                        bool        bInQtThread )
{
    QUrl url( m_url );

    url.setPath( m_sControlPath );

    // --------------------------------------------------------------
    // Add appropriate headers
    // --------------------------------------------------------------

    QHttpRequestHeader header;

    header.setValue("CONTENT-TYPE", "text/xml; charset=\"utf-8\"" );
    header.setValue("SOAPACTION"  , QString( "\"%1#GetConnectionInfo\"" )
                                       .arg( m_sNamespace ));

    // --------------------------------------------------------------
    // Build request payload
    // --------------------------------------------------------------

    QByteArray  aBuffer;
    QTextStream os( &aBuffer );

    os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; 
    os << "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
    os << " <s:Body>\r\n";
    os << "  <u:" << sMethod << " xmlns:u=\"" << m_sNamespace << "\">\r\n";

    // --------------------------------------------------------------
    // Add parameters from list
    // --------------------------------------------------------------

    for ( QStringMap::iterator it  = list.begin(); 
                               it != list.end(); 
                             ++it ) 
    {                                                               
        os << "   <" << it.key() << ">";
        os << HTTPRequest::Encode( *it );
        os << "</"   << it.key() << ">\r\n";
    }

    os << "  </u:" << sMethod << ">\r\n";
    os << " </s:Body>\r\n";
    os << "</s:Envelope>\r\n";

    os.flush();

    // --------------------------------------------------------------
    // Perform Request
    // --------------------------------------------------------------

    QBuffer     buff( &aBuffer );

    QString sXml = HttpComms::postHttp( url, 
                                        &header,
                                        (QIODevice *)&buff,
                                        10000, // ms
                                        3,     // retries
                                        0,     // redirects
                                        false, // allow gzip
                                        NULL,  // login
                                        bInQtThread );

    // --------------------------------------------------------------
    // Parse response
    // --------------------------------------------------------------

    list.clear();

    QDomDocument doc;

    if ( !doc.setContent( sXml, true, &sErrDesc, &nErrCode ))
    {
        VERBOSE( VB_UPNP, QString( "MythXMLClient::SendSOAPRequest( %1 ) - Invalid response from %2" )
                             .arg( sMethod   )
                             .arg( url.toString() ));
        return false;
    }

    // --------------------------------------------------------------
    // Is this a valid response?
    // --------------------------------------------------------------

    QString      sResponseName = sMethod + "Response";
    QDomNodeList oNodeList     = doc.elementsByTagNameNS( m_sNamespace, sResponseName );

    if (oNodeList.count() > 0)
    {
        QDomNode oMethod = oNodeList.item(0);

        if (!oMethod.isNull())
        {

            for ( QDomNode oNode = oMethod.firstChild(); !oNode.isNull(); 
                           oNode = oNode.nextSibling() )
            {
                QDomElement e = oNode.toElement();

                if (!e.isNull())
                {
                    QString sName  = e.tagName();
                    QString sValue = "";
    
                    QDomText  oText = oNode.firstChild().toText();
    
                    if (!oText.isNull())
                        sValue = oText.nodeValue();

                    list.insert(QUrl::fromPercentEncoding(sName.toUtf8()),
                                QUrl::fromPercentEncoding(sValue.toUtf8()));
                }
            }
        }

        return true;
    }

    // --------------------------------------------------------------
    // Must be a fault... parse it to return reason
    // --------------------------------------------------------------

    nErrCode = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPResult/errorCode"       , 500 );
    sErrDesc = GetNodeValue( doc, "Envelope/Body/Fault/detail/UPnPResult/errorDescription", QString( "Unknown" ));

    return false;
}
Exemple #14
0
QHttpRequestHeader *BrisaEventProxy::getUnsubscriptionRequest() const {
    QHttpRequestHeader *request = new QHttpRequestHeader("UNSUBSCRIBE", eventSub);
    request->setValue("HOST", this->host + ":" + this->port);
    request->setValue("SID", this->SID);
    return request;
}