예제 #1
0
void ValidateChecksumHeader::slotChecksumCalculated(const QByteArray& checksumType,
                                                    const QByteArray& checksum)
{
    if( checksumType != _expectedChecksumType ) {
        emit validationFailed(tr("The checksum header contained an unknown checksum type '%1'").arg(
                                  QString::fromLatin1(_expectedChecksumType)));
        return;
    }
    if( checksum != _expectedChecksum ) {
        emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed."));
        return;
    }
    emit validated(checksumType, checksum);
}
void TransmissionChecksumValidator::slotDownloadChecksumCalculated()
{
    const QByteArray hash = _watcher.future().result();

    if( hash != _expectedHash ) {
        emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed."));
    } else {
        // qDebug() << "Checksum checked and matching: " << _expectedHash;
        emit validated(hash);
    }
}
void TransmissionChecksumValidator::downloadValidation( const QByteArray& checksumHeader )
{
    // if the incoming header is empty, there was no checksum header, and
    // no validation can happen. Just continue.
    const QString csType = checksumType();

    // for empty checksum type, everything is valid.
    if( csType.isEmpty() ) {
        emit validated(QByteArray());
        return;
    }

    int indx = checksumHeader.indexOf(':');
    if( indx < 0 ) {
        qDebug() << "Checksum header malformed:" << checksumHeader;
        emit validationFailed(tr("The checksum header is malformed.")); // show must go on - even not validated.
        return;
    }

    const QByteArray type = checksumHeader.left(indx).toUpper();
    _expectedHash = checksumHeader.mid(indx+1);

    connect( &_watcher, SIGNAL(finished()), this, SLOT(slotDownloadChecksumCalculated()) );

    // start the calculation in different thread
    if( type == checkSumMD5C ) {
        _watcher.setFuture(QtConcurrent::run(FileSystem::calcMd5, _filePath));
    } else if( type == checkSumSHA1C ) {
        _watcher.setFuture(QtConcurrent::run(FileSystem::calcSha1, _filePath));
    }
#ifdef ZLIB_FOUND
    else if( type == checkSumAdlerUpperC ) {
        _watcher.setFuture(QtConcurrent::run(FileSystem::calcAdler32, _filePath));
    }
#endif
    else {
        qDebug() << "Unknown checksum type" << type;
        emit validationFailed(tr("The checksum header is malformed."));
        return;
    }
}
예제 #4
0
void ValidateChecksumHeader::start(const QString& filePath, const QByteArray& checksumHeader)
{
    // If the incoming header is empty no validation can happen. Just continue.
    if( checksumHeader.isEmpty() ) {
        emit validated(QByteArray(), QByteArray());
        return;
    }

    if( !parseChecksumHeader(checksumHeader, &_expectedChecksumType, &_expectedChecksum) ) {
        qDebug() << "Checksum header malformed:" << checksumHeader;
        emit validationFailed(tr("The checksum header is malformed."));
        return;
    }

    auto calculator = new ComputeChecksum(this);
    calculator->setChecksumType(_expectedChecksumType);
    connect(calculator, SIGNAL(done(QByteArray,QByteArray)),
            SLOT(slotChecksumCalculated(QByteArray,QByteArray)));
    calculator->start(filePath);
}
/**
	@see QRegExpValidator::validate
	@see validationFailed()
	Emet le signal validationFailed si la validation echoue
*/
QValidator::State QETRegExpValidator::validate(QString &input, int &pos) const {
	QValidator::State result = QRegExpValidator::validate(input, pos);
	if (result == QValidator::Invalid) emit(validationFailed());
	return(result);
}