void BrisaMSearchClientCP::datagramReceived() {
    while (udpListener->hasPendingDatagrams()) {

        QByteArray Datagram;

        Datagram.resize(udpListener->pendingDatagramSize());
        udpListener->readDatagram(Datagram.data(), Datagram.size());

        QString temp(Datagram);
        QHttpResponseHeader *response = new QHttpResponseHeader(temp);

        if (response->statusCode() == 200) {
            QString usn = response->value("usn");
            if (usn.startsWith("uuid:")) {
                qDebug() << "BrisaMSearch received MSearch answer from "  << usn << "";
                emit msearchResponseReceived(response->value("usn"),
                                             response->value("location"),
                                             response->value("st"),
                                             response->value("ext"),
                                             response->value("server"),
                                             response->value("cache-control"));
            } else {
                qDebug() << "BrisaMSearch received MSearch from " << response->value("location")
                         << " but it does not start with string \"uuid:\". USN field is " << usn;
            }
        }

        delete response;
    }
}
Example #2
0
void
SmugMug::WebService::_slotHttpReadyRead (const QHttpResponseHeader &resp) {

    QHttp &theHttp = (_ssl ? _https : _http);

    if (resp.statusCode () != 200) {

        QString msg = QString ("[%1] %2").arg (resp.statusCode ()).arg (resp.reasonPhrase ());
        _logHttpError (msg);
        theHttp.abort();
    }
    else {

        const qint64 MaxLen (theHttp.bytesAvailable ());

        if (MaxLen) {

            char *buffer = new char [MaxLen+1];
            memset (buffer, 0, MaxLen+1);

            qint64 count = theHttp.read (buffer, MaxLen);

            _dataIn.append (buffer);

            delete [] buffer;
            buffer = 0;

            qDebug () << "Read Ready: " << count << " of " << MaxLen;
        }
    }
}
Example #3
0
/**
 * Checks for the status code and aborts the request if needed.
 */
void TextBrowser::onResponseHeaderReceived(const QHttpResponseHeader &responseHeader)
{
  if (responseHeader.statusCode() != 200) {
    stateChanged(tr("Download failed: %1.").arg(responseHeader.reasonPhrase()));
    d->http->abort();
  }
}
Example #4
0
void HttpGet::httpResponseHeader(const QHttpResponseHeader &resp)
{
    // if there is a network error abort all scheduled requests for
    // this download
    m_response = resp.statusCode();
   
    // 301 -- moved permanently
    // 302 -- found
    // 303 -- see other
    // 307 -- moved temporarily
    // in all cases, header: location has the correct address so we can follow.
    if(m_response == 301 || m_response == 302 || m_response == 303 || m_response == 307) {
        //abort without sending any signals
        http.blockSignals(true);
        http.abort();
        http.blockSignals(false);
        // start new request with new url
        qDebug() << "[HTTP] response =" << m_response << "- following";
        getFile(resp.value("location") + m_query);
    }
    else if(m_response != 200) {
        // all other errors are fatal.
        http.abort();
        qDebug() << "[HTTP] Response error:" << m_response << resp.reasonPhrase();
    }

}
Example #5
0
void HttpDownload::slotResponseHeaderReceived( const QHttpResponseHeader & resp ){

    QString contentLength = resp.value("Content-Length");

    if( !contentLength.isEmpty() ){
        long length = contentLength.toLong();
    }

    //user define!!
    if(!this->fileName.isEmpty())
            return;

    QString disposition = resp.value("Content-Disposition");

    disposition.replace(" " ,"",Qt::CaseInsensitive);
    QStringList list = disposition.split(";");

    QString fileName = "";

    QRegExp exp = QRegExp("[ ]*[filename][ ]*=[ ]*.*");
    exp.setCaseSensitivity(Qt::CaseInsensitive);

    for(int i = 0 ; i < list.size() ; i ++){
            QString tempStr = list.value(i);
            if( tempStr.contains(exp)) {
                    exp = QRegExp("[ ]*filename[ ]*=[ ]*");
                    exp.setCaseSensitivity(Qt::CaseInsensitive);
                    fileName = tempStr.remove(exp);
                    break;
            }
    }
    if(!fileName.isEmpty()){
            this->fileName = fileName;
    }
}
Example #6
0
void ownCloudInfo::qhttpResponseHeaderReceived(const QHttpResponseHeader& header)
{
    qDebug() << "Resp:" << header.toString();
    if (header.statusCode() == 201)
        emit webdavColCreated( QNetworkReply::NoError );
    else
        qDebug() << "http request failed" << header.toString();
}
Example #7
0
void FileDownloader::readResponseHeader(const QHttpResponseHeader &responseHeader) {
	if (responseHeader.statusCode() != 200) {
		emit downloadFailed(responseHeader.reasonPhrase());
		http_request_aborted = true;
		hide();
		http->abort();
		return;
	}
}
Example #8
0
void FlexWatchCam::httpReadyRead(const QHttpResponseHeader & resp)
{
  if(resp.statusCode() != 200)
    QMessageBox::warning(0, "Error", tr("StatusCode = %1").arg(resp.statusCode()));
  else {
    QByteArray array = http_.readAll();
    processing(array);
  }
}
Example #9
0
void HttpEngine::handleUploadHeaders(QHttpResponseHeader header)
{
	if(header.statusCode() != 200)
		throw header.reasonPhrase();
	
	qint64 clen = header.value("content-length").toLongLong();
	while(m_strResponse.size() < clen)
		m_strResponse += m_pRemote->read(1024);
	emit finished(false);
}
Example #10
0
void MythHttpHandler::ResponseHeaderReceived(const QHttpResponseHeader &resp)
{
    QMutexLocker locker(&m_lock);

    LOG(VB_NETWORK, LOG_DEBUG, LOC +
        QString("ResponseHeaderReceived(%1,%2) url: %3")
            .arg(resp.statusCode()).arg(resp.reasonPhrase())
            .arg(m_cur_url.toString()));
    m_cur_status_id  = resp.statusCode();
    m_cur_status_str = resp.reasonPhrase();
}
Example #11
0
void RequestParser::serveIndex()
{
	QHttpResponseHeader header;
	header.setStatusLine(200, "OK", 1,1);
	QByteArray buffer = "<HTML><BODY>Index</BODY></HTML>";

	header.setContentLength(buffer.length());
	header.setContentType("text/html");
	emit write(header.toString().toUtf8());
	emit write(buffer);
	exit(0);
}
Example #12
0
void HttpFileReceiver::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
    if ( responseHeader.statusCode() >= 400 )
    {
        fetcher->httpRequestAborted = true;
        QString detailedError( "HttpFileReceiver::readReasponseHeader:- status code: %1 "
                               "reason phrase: %2" );
        detailedError = detailedError.arg( responseHeader.statusCode() )
                                     .arg( responseHeader.reasonPhrase() );
        fetcher->error = detailedError; 
    }
}
/*---------------------------------------------------------------------------*/
QVariant HttpRecognizer::comment( IConnection* connection )
{
	Q_ASSERT (connection);
	if (!mConnections.contains( connection->networkInfo() ))
		return "No comment yet";

	const HttpConnection con = mConnections.value( connection->networkInfo() );
	const QHttpRequestHeader request = con.lastRequestHeader();
	const QHttpResponseHeader response = con.lastResponseHeader();

	return request.method() + " " + request.value( "host" ) + request.path()
		+ (response.isValid() ? "\nHTTP " + QString::number( response.statusCode() ) + " " + response.reasonPhrase() : "" );
}
void AcsMessageBuilder::buildHttpHeaderResponse(QHttpResponseHeader &responseHeader,
                                            int iContentLength,
                                            int code, 
                                            const QString& status)
{
    responseHeader.setStatusLine(code, status);
    responseHeader.setContentLength(iContentLength);
    if(iContentLength == 0){
        responseHeader.setContentType("text/plain");
    } else {
        responseHeader.setContentType("text/xml; charset=\"utf-8\"");
    }
    return;
}
void OracleImporter::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
	switch (responseHeader.statusCode()) {
		case 200:
		case 301:
		case 302:
		case 303:
		case 307:
			break;
		default:
			QMessageBox::information(0, tr("HTTP"), tr("Download failed: %1.").arg(responseHeader.reasonPhrase()));
			http->abort();
			deleteLater();
	}
}
void DJDownloadManager::httpReadyRead ( const QHttpResponseHeader & response )
{
	int status	= response.statusCode();
	djDebug() << "httpReadyRead" << status << m_file->fileName();
	if ( !m_file->fileName().isEmpty() )
		m_file->write( m_http->readAll() );
}
Example #17
0
void HttpCore::readResponseHeader(const QHttpResponseHeader &responseHeader){
    switch (responseHeader.statusCode()) {
         case 200:                   // Ok
         case 301:                   // Moved Permanently
         case 303:                   // See Other
         case 307:                   // Temporary Redirect
             // these are not error conditions
             break;

         default:
             emit(requestError(tr("Download failed: %1.").arg(responseHeader.reasonPhrase())));;
             this->aborted=true;
             http->abort();
         }
    return;
}
Example #18
0
/**
  This method will ...
*
@param [inout] reqData: ...
@param [out] error: error description for an invalid request
*
@return: can we serve this request?
*******************************************************************************/
std::string CuteHttpParser::makeOkResp(CuteSrvRequest& reqData, const std::string& respStr)
{
    QHttpResponseHeader ok;

    ok.setStatusLine(200);
    ok.addValue("Content-Type", "text/html");
    ok.setContentLength(respStr.size());  

    string resp = ok.toString().toLatin1().constData();;

    // add content
    resp.append(respStr);
    resp.append(c_httpLineEnd);

    return resp;
}
Example #19
0
void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, bool isProxy)
{
    QList<QPair<QString, QString> > values = header.values();
    const char *search = isProxy ? "proxy-authenticate" : "www-authenticate";

    method = None;
    /*
      Fun from the HTTP 1.1 specs, that we currently ignore:

      User agents are advised to take special care in parsing the WWW-
      Authenticate field value as it might contain more than one challenge,
      or if more than one WWW-Authenticate header field is provided, the
      contents of a challenge itself can contain a comma-separated list of
      authentication parameters.
    */

    QString headerVal;
    for (int i = 0; i < values.size(); ++i) {
        const QPair<QString, QString> &current = values.at(i);
        if (current.first.toLower() != QLatin1String(search))
            continue;
        QString str = current.second;
        if (method < Basic && str.startsWith(QLatin1String("Basic"), Qt::CaseInsensitive)) {
            method = Basic; headerVal = str.mid(6);
        } else if (method < Ntlm && str.startsWith(QLatin1String("NTLM"), Qt::CaseInsensitive)) {
            method = Ntlm;
            headerVal = str.mid(5);
        } else if (method < DigestMd5 && str.startsWith(QLatin1String("Digest"), Qt::CaseInsensitive)) {
            method = DigestMd5;
            headerVal = str.mid(7);
        }
    }

    challenge = headerVal.trimmed().toLatin1();
    QHash<QByteArray, QByteArray> options = parseDigestAuthenticationChallenge(challenge);

    switch(method) {
    case Basic:
        realm = QString::fromLatin1(options.value("realm"));
        if (user.isEmpty())
            phase = Done;
        break;
    case Ntlm:
        // #### extract from header
        realm = QString();
        break;
    case DigestMd5: {
        realm = QString::fromLatin1(options.value("realm"));
        if (options.value("stale").toLower() == "true")
            phase = Start;
        if (user.isEmpty())
            phase = Done;
        break;
    }
    default:
        realm = QString();
        challenge = QByteArray();
        phase = Invalid;
    }
}
void DBoxFE_ProfileWizard::readResponseHeader( const QHttpResponseHeader &responseHeader ) {
  if ( responseHeader.statusCode() != 200 ) {
    QMessageBox::information( this, dbfe->winTitle(), tr( "Download failed: %1." ).arg( responseHeader.reasonPhrase() ) );
    httpRequestAborted = true;
    m_http->abort();
    return ;
  }
}
void FeedFetcher::readData(const QHttpResponseHeader& response_header) {
    if(!impl_->current_feed_.get())
        return;
    int statusCode =  response_header.statusCode();
    qDebug() << statusCode;
    if (statusCode == 200) {
        //TODO in order to insert CDATA to invalid XML atom,
        //we need capture data of full page
        bytes_.append(impl_->http_->readAll());
//         qDebug() << bytes_.size() << " bytes received.";
        // insert CDATA FLAG if not exists
    } else if ((statusCode >300 || statusCode <300)
        && (response_header.hasKey("location") || response_header.hasKey("Location"))) {
        qDebug()<<response_header.statusCode();
        QUrl location = QUrl(response_header.value("location"));
        if (location.isEmpty()) {
            location = QUrl(response_header.value("Location"));
        }
        qDebug() << location;
        impl_->http_.get()->setHost(location.host(),80);
        impl_->connection_id_ = impl_->http_.get()->get(location.toString());
    } else if (statusCode == 404) {
       //NOTE: Do Nothing
       qDebug() << "404 !!";
    } else {
        qDebug() << "Received non-200 response code: "
                 << statusCode << response_header.toString();
    }
}
Example #22
0
void UtubeData::readData(const QHttpResponseHeader &resp) {
  if (resp.statusCode() != 200) {
    mHttp->abort();
    qDebug() << "UTUBE: Error." << endl;
  } else {
    mXml.addData(mHttp->readAll());
    parseXml();
  }
}
Example #23
0
void RSSFetcher::readData(const QHttpResponseHeader &resp)
{
    if (resp.statusCode() != 200)
        m_http.abort();
    else {
        m_xml.addData(m_http.readAll());
        parseXml();
    }
}
Example #24
0
void RSSListing::readData(const QHttpResponseHeader &resp)
{
    if (resp.statusCode() != 200)
        http.abort();
    else {
        xml.addData(http.readAll());
        parseXml();
    }
}
Example #25
0
void ArchLinuxNewsReader::readData(const QHttpResponseHeader &resp)
{
    if (resp.statusCode() != 200)
        http->abort();
    else {
        xml.addData(http->readAll());
        parseXml();
    }
}
Example #26
0
void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
  switch (responseHeader.statusCode()) {
  case 200:                   // Ok
  case 301:                   // Moved Permanently
  case 302:                   // Found
  case 303:                   // See Other
  case 307:                   // Temporary Redirect
    // these are not error conditions
    break;

  default:
    QMessageBox::information(0, tr("HTTP"),
           tr("Download failed: %1.")
           .arg(responseHeader.reasonPhrase()));
    httpRequestAborted = true;
    http->abort();
  }
}
Example #27
0
void HttpThread::readResponseHeader(QHttpResponseHeader const& responseHeader)
{
qDebug() << "httpResponseHeader" << responseHeader.statusCode();
    switch (responseHeader.statusCode()) {
       case 200:   // Ok
       case 301:   // Moved Permanently
       case 302:   // Found
       case 303:   // See Other
       case 307:   // Temporary Redirect
           break;  // these are not error conditions

       default:
          m_errorMessage = "HTTP request failed: " + responseHeader.reasonPhrase();
qDebug() << "Error message:" << m_errorMessage;
          m_terminate = true;
          m_httpActive = false;
          m_http->abort();
    }
}
Example #28
0
void
SmugMug::WebService::_slotDownloadHttpReadyRead (const QHttpResponseHeader &resp) {

    if (_downloadId) {

        qDebug () << "_slotDownloadHttpReadyRead" << resp.statusCode () << resp.reasonPhrase ();

        if (resp.statusCode () != 200) {

            qWarning () << "---- Download Http Error -----------------------------------";
            qWarning () << "Response Reason:" << resp.reasonPhrase () << endl
                        << "Request:" << _downloadHttp.currentRequest ().path () << endl
                        << "Bytes returned:" << _downloadHttp.bytesAvailable () << endl
                        << "-----------------------------------------------------" << endl;

            _downloadAborted = true;
            _downloadHttp.abort();
        }
    }
}
Example #29
0
void QAuthenticatorPrivate::parseHttpResponse(const QHttpResponseHeader &header, bool isProxy)
{
    const QList<QPair<QString, QString> > values = header.values();
    QList<QPair<QByteArray, QByteArray> > rawValues;

    QList<QPair<QString, QString> >::const_iterator it, end;
    for (it = values.constBegin(), end = values.constEnd(); it != end; ++it)
        rawValues.append(qMakePair(it->first.toLatin1(), it->second.toUtf8()));

    // continue in byte array form
    parseHttpResponse(rawValues, isProxy);
}
Example #30
0
void Gmail::readData(const QHttpResponseHeader &resp)
{
    if (resp.statusCode() != 200)
    {
        http.abort();
        //emit probleme de connection
    }
    else {
        xml.addData(http.readAll());
        getEmails();
    }
}