Example #1
0
void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &info)
{
    // status.php was found.
    qDebug() << "** Application: ownCloud found: "
             << url << " with version "
             << CheckServerJob::versionString(info)
             << "(" << CheckServerJob::version(info) << ")";

    QString version = CheckServerJob::version(info);
    _account->setServerVersion(version);

    // We cannot deal with servers < 5.0.0
    if (version.contains('.') && version.split('.')[0].toInt() < 5) {
        _errors.append( tr("The configured server for this client is too old") );
        _errors.append( tr("Please update to the latest server and restart the client.") );
        reportResult( ServerVersionMismatch );
        return;
    }

    // We attempt to work with servers >= 5.0.0 but warn users.
    // Check usages of Account::serverVersionUnsupported() for details.

    // now check the authentication
    if (_account->credentials()->ready())
        QTimer::singleShot( 0, this, SLOT( checkAuthentication() ));
    else
        reportResult( CredentialsMissingOrWrong );
}
void DFListTest::managedListTest()
{
	startFeatureTest("Managed list tests");
	DFManagedList<testStr> pl;
	testStr *msg1 = new testStr(1);
	testStr *msg2 = new testStr(2);
	testStr *msg3 = new testStr(3);
	testStr *msg4 = new testStr(4);
	testStr *msg0 = new testStr(0);

	reportResult("Verify empty() true on list creation", pl.empty());

	pl.pushBack(msg1);
	pl.pushBack(msg2);
	pl.pushBack(msg3);
	pl.pushBack(msg4);

	reportResult("Verify pushBack()", verifyStructList(pl, "1234"));

	DFPointerList::Index idx = nullptr;

	idx = pl.next(idx);
	idx = pl.next(idx);
	idx = pl.next(idx);

	// idx points to node containing msg3
	idx = pl.erase(idx);

	pl.pushFront(msg0);

	reportResult("Verify next() pushFront() and erase()", verifyStructList(pl, "0124"));

	pl.clear();
	reportResult("Verify clear()", pl.empty());
}
void DFListTest::unmanagedListTest()
{
	startFeatureTest("Unmanaged list tests");
	DFPointerList pl;
	const char *msg1 = "1";
	const char *msg2 = "2";
	const char *msg3 = "3";
	const char *msg4 = "4";
	const char *msg0 = "0";

	reportResult("Verify empty() true on list creation", pl.empty());

	pl.pushBack((void *)msg1);
	pl.pushBack((void *)msg2);
	pl.pushBack((void *)msg3);
	pl.pushBack((void *)msg4);

	reportResult("Verify pushBack()", verifyList(pl, "1234"));

	DFPointerList::Index idx = nullptr;

	idx = pl.next(idx);
	idx = pl.next(idx);
	idx = pl.next(idx);

	// idx points to node containing msg3
	idx = pl.erase(idx);

	pl.pushFront((void *)msg0);

	reportResult("Verify next() pushFront() and erase()", verifyList(pl, "0124"));

	pl.clear();
	reportResult("Verify clear()", pl.empty());
}
Example #4
0
void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &info)
{
    // status.php was found.
    qDebug() << "** Application: ownCloud found: "
             << url << " with version "
             << CheckServerJob::versionString(info)
             << "(" << CheckServerJob::version(info) << ")";

    QString version = CheckServerJob::version(info);
    _account->setServerVersion(version);

    if (version.contains('.') && version.split('.')[0].toInt() < 5) {
        _errors.append( tr("The configured server for this client is too old") );
        _errors.append( tr("Please update to the latest server and restart the client.") );
        reportResult( ServerVersionMismatch );
        return;
    }

    // now check the authentication
    AbstractCredentials *creds = _account->credentials();
    if (creds->ready()) {
        QTimer::singleShot( 0, this, SLOT( checkAuthentication() ));
    } else {
        // We can't proceed with the auth check because we don't have credentials.
        // Fetch them now! Once fetched, a new connectivity check will be
        // initiated anyway.
        creds->fetch();

        // no result is reported
        deleteLater();
    }
}
Example #5
0
void TestOutputReader::createAndReportResult(const QString &message, Result::Type type)
{
    TestResultPtr result = createDefaultResult();
    result->setDescription(message);
    result->setResult(type);
    reportResult(result);
}
Example #6
0
void ConnectionValidator::slotJobTimeout(const QUrl &url)
{
    Q_UNUSED(url);
    //_errors.append(tr("Unable to connect to %1").arg(url.toString()));
    _errors.append(tr("timeout"));
    reportResult( Timeout );
}
Example #7
0
void ConnectionValidator::slotAuthFailed(QNetworkReply *reply)
{
    Status stat = Timeout;

    if( reply->error() == QNetworkReply::AuthenticationRequiredError ||
             !_account->credentials()->stillValid(reply)) {
        qDebug() <<  reply->error() << reply->errorString();
        qDebug() << "******** Password is wrong!";
        _errors << tr("The provided credentials are not correct");
        stat = CredentialsWrong;

    } else if( reply->error() != QNetworkReply::NoError ) {
        _errors << reply->errorString();

        const int httpStatus =
                reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        if ( httpStatus == 503 ) {
            // Is this a maintenance mode reply from the server
            // or a regular 503 from somewhere else?
            QByteArray body = reply->readAll();
            if ( body.contains("Sabre\\DAV\\Exception\\ServiceUnavailable") ) {
                _errors.clear();
                stat = ServerMaintenance;
            }
        }
    }

    reportResult( stat );
}
Example #8
0
void ConnectionValidator::slotUserFetched(const QVariantMap &json)
{
    QString user = json.value("ocs").toMap().value("data").toMap().value("id").toString();
    if (!user.isEmpty()) {
        _account->setDavUser(user);
    }
    reportResult(Connected);
}
void *player3( void *arg ) {
  char *me = "player3";

  sleep( 1 );

  // At time 1
  int result = throwBlue( me, SCISSORS );
  reportResult( me, result );

  sleep( 1 );

  // At time 2
  result = throwBlue( me, PAPER );
  reportResult( me, result );

  return NULL;
}
void *player1( void *arg ) {
  char *me = "player1";

  // At time 0
  int result = throwRed( me, ROCK );

  // At time 1
  reportResult( me, result );

  sleep( 3 );

  // At time 4
  result = throwRed( me, ROCK );
  reportResult( me, result );

  return NULL;
}
Example #11
0
void ConnectionValidator::slotCapabilitiesRecieved(const QVariantMap &json)
{
    auto caps = json.value("ocs").toMap().value("data").toMap().value("capabilities");
    qDebug() << "Server capabilities" << caps;
    _account->setCapabilities(caps.toMap());
    reportResult(Connected);
    return;
}
Example #12
0
void ConnectionValidator::slotAuthSuccess()
{
    _errors.clear();
    if (!_isCheckingServerAndAuth) {
        reportResult(Connected);
        return;
    }
    checkServerCapabilities();
}
Example #13
0
void DeviceOrientation::updateSensor(){
    QCompassReading *heading = _compass.reading();
    _azymuth = heading->azimuth();
    _accuracy = heading->calibrationLevel();
    _timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();

    _validData = true;
    reportResult();
}
Example #14
0
// status.php could not be loaded (network or server issue!).
void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply)
{
    if( reply && ! _account->credentials()->stillValid(reply)) {
        _errors.append(tr("Authentication error: Either username or password are wrong."));
    }  else {
        _errors.append(tr("Unable to connect to %1").arg(_account->url().toString()));
        _errors.append( reply->errorString() );
    }
    reportResult( StatusNotFound );
}
void *player4( void *arg ) {
  char *me = "player4";

  sleep( 3 );

  // At time 3
  int result = throwBlue( me, SCISSORS );
  reportResult( me, result );

  return NULL;
}
void *player2( void *arg ) {
  char *me = "player2";

  sleep( 5 );

  // At time 5
  int result = throwRed( me, SCISSORS );
  reportResult( me, result );

  return NULL;
}
Example #17
0
void DFListTest::uintListTest()
{
	startFeatureTest("UInt list tests");
	DFUIntList pl;
	unsigned int val1 = 1;
	unsigned int val2 = 2;
	unsigned int val3 = 3;
	unsigned int val4 = 4;
	unsigned int val0 = 0;

	reportResult("Verify empty() true on list creation", pl.empty());

	unsigned int check_list1[] = { 1, 2, 3, 4 };
	pl.pushBack(val1);
	pl.pushBack(val2);
	pl.pushBack(val3);
	pl.pushBack(val4);

	reportResult("Verify pushBack()", verifyUIntList(pl, check_list1));

	DFUIntList::Index idx = nullptr;

	idx = pl.next(idx);
	idx = pl.next(idx);
	idx = pl.next(idx);

	// idx points to node containing msg3
	idx = pl.erase(idx);

	pl.pushFront(val0);

	unsigned int check_list2[] = { 0, 1, 2, 4 };
	reportResult("Verify next() pushFront() and erase()", verifyUIntList(pl, check_list2));

	pl.clear();
	reportResult("Verify clear()", pl.empty());
}
Example #18
0
void SyncObjTest::_doTests()
{
	SyncObj so;

	bool passed = true;
	so.lock();
	so.unlock();
	reportResult("Simple lock/unlock", passed);

	uint64_t now = offsetTime();
	unsigned long wait_in_us = 5000;
	so.lock();
	int rv = so.waitOnSignal(wait_in_us);
	so.unlock();
	uint64_t after = offsetTime();
	uint64_t delta_usec = after - now;

	if (rv != ETIMEDOUT) {
		DF_LOG_ERR("waitSignal() did not return ETIMEDOUT");
		passed = false;
	}

#ifdef __APPLE__
	const float error_factor = 2.0f;
#else
	const float error_factor = 1.2f;
#endif

	bool dtime_ok = (delta_usec > wait_in_us) && (delta_usec < wait_in_us * error_factor);

	if (!dtime_ok) {
		DF_LOG_ERR("waitSignal() timeout of %luus was %" PRIu64 "us", wait_in_us, delta_usec);
		passed = false;
	}

	reportResult("waitSignal() timeout", passed && dtime_ok);
}
Example #19
0
void DeviceOrientation::getHeading(int scId, int ecId, QVariantMap options) {
    Q_UNUSED(options);
    if (_compass.isConnectedToBackend() || !_compass.start()) {
        this->callback(ecId, "CompassError.COMPASS_NOT_SUPPORTED");
        return;
    }

    _successCallbacks << scId;
    _errorCallbacks << ecId;

    if (_validData) {
        reportResult();
        return;
    }
}
Example #20
0
void ConnectionValidator::checkAuthentication()
{
    AbstractCredentials *creds = _account->credentials();

    if (!creds->ready()) { // The user canceled
        reportResult(UserCanceledCredentials);
    }

    // simply GET the webdav root, will fail if credentials are wrong.
    // continue in slotAuthCheck here :-)
    qDebug() << "# Check whether authenticated propfind works.";
    PropfindJob *job = new PropfindJob(_account, "/", this);
    job->setProperties(QList<QByteArray>() << "getlastmodified");
    connect(job, SIGNAL(result(QVariantMap)), SLOT(slotAuthSuccess()));
    connect(job, SIGNAL(networkError(QNetworkReply*)), SLOT(slotAuthFailed(QNetworkReply*)));
    job->start();
}
Example #21
0
void ConnectionValidator::checkServerAndAuth()
{
    if( !_account ) {
        _errors << tr("No ownCloud account configured");
        reportResult( NotConfigured );
        return;
    }
    _isCheckingServerAndAuth = true;

    // Lookup system proxy in a thread https://github.com/owncloud/client/issues/2993
    if (ClientProxy::isUsingSystemDefault()) {
        qDebug() << "Trying to look up system proxy";
        ClientProxy::lookupSystemProxyAsync(_account->url(),
                                            this, SLOT(systemProxyLookupDone(QNetworkProxy)));
    } else {
        // We want to reset the QNAM proxy so that the global proxy settings are used (via ClientProxy settings)
        _account->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy));
        // use a queued invocation so we're as asynchronous as with the other code path
        QMetaObject::invokeMethod(this, "slotCheckServerAndAuth", Qt::QueuedConnection);
    }
}
Example #22
0
void FeatureEval::computeCorrelation(float * data, int vector_size, int size, std::vector<int> & big_to_small, int stride, int offset){

    stride = stride ? stride : vector_size;

    if(ll_->getSelection().size() == 0)
        return;

    std::set<uint16_t> labels;
    for(boost::weak_ptr<Layer> wlayer: ll_->getSelection()){
        for(uint16_t label : wlayer.lock()->getLabelSet())
            labels.insert(label);
    }

    std::vector<float> layer = get_scaled_layer_mask(cl_->active_->labels_,
                          labels,
                          big_to_small,
                          size);

    Eigen::MatrixXf correlation_mat = multi_correlate(layer, data, vector_size, size, stride, offset);
    Eigen::MatrixXf Rxx = correlation_mat.topLeftCorner(vector_size, vector_size);
    Eigen::VectorXf c = correlation_mat.block(0, vector_size, vector_size, 1);

    //std::cout << correlation_mat << std::endl;

    float R = c.transpose() * (Rxx.inverse() * c);

    qDebug() << "R^2: " << R;
    //qDebug() << "R: " << sqrt(R);

    reportResult(R, c.data(), vector_size);

    //Eigen::VectorXf tmp = (Rxx.inverse() * c);

    qDebug() << "Y -> X correlation <<<<<<<<<<<<<";
    std::cout << c << std::endl;
    //qDebug() << "Coefs <<<<<<<<<<<<<";
    //std::cout << tmp << std::endl;

}
Example #23
0
void ConnectionValidator::slotAuthFailed(QNetworkReply *reply)
{
    Status stat = Timeout;

    if( reply->error() == QNetworkReply::AuthenticationRequiredError ||
             !_account->credentials()->stillValid(reply)) {
        qDebug() <<  reply->error() << reply->errorString();
        qDebug() << "******** Password is wrong!";
        _errors << tr("The provided credentials are not correct");
        stat = CredentialsMissingOrWrong;

    } else if( reply->error() != QNetworkReply::NoError ) {
        _errors << errorMessage(reply->errorString(), reply->readAll());

        const int httpStatus =
                reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        if ( httpStatus == 503 ) {
            _errors.clear();
            stat = ServiceUnavailable;
        }
    }

    reportResult( stat );
}
Example #24
0
bool _TPCircularBufferInit(TPCircularBuffer *buffer, int32_t length, size_t structSize) {
    
    assert(length > 0);
    
    if ( structSize != sizeof(TPCircularBuffer) ) {
        fprintf(stderr, "TPCircularBuffer: Header version mismatch. Check for old versions of TPCircularBuffer in your project\n");
        abort();
    }
    
    // Keep trying until we get our buffer, needed to handle race conditions
    int retries = 3;
    while ( true ) {
        
        buffer->length = (int32_t)round_page(length);    // We need whole page sizes
        
        // Temporarily allocate twice the length, so we have the contiguous address space to
        // support a second instance of the buffer directly after
        vm_address_t bufferAddress;
        kern_return_t result = vm_allocate(mach_task_self(),
                                           &bufferAddress,
                                           buffer->length * 2,
                                           VM_FLAGS_ANYWHERE); // allocate anywhere it'll fit
        if ( result != ERR_SUCCESS ) {
            if ( retries-- == 0 ) {
                reportResult(result, "Buffer allocation");
                return false;
            }
            // Try again if we fail
            continue;
        }
        
        // Now replace the second half of the allocation with a virtual copy of the first half. Deallocate the second half...
        result = vm_deallocate(mach_task_self(),
                               bufferAddress + buffer->length,
                               buffer->length);
        if ( result != ERR_SUCCESS ) {
            if ( retries-- == 0 ) {
                reportResult(result, "Buffer deallocation");
                return false;
            }
            // If this fails somehow, deallocate the whole region and try again
            vm_deallocate(mach_task_self(), bufferAddress, buffer->length);
            continue;
        }
        
        // Re-map the buffer to the address space immediately after the buffer
        vm_address_t virtualAddress = bufferAddress + buffer->length;
        vm_prot_t cur_prot, max_prot;
        result = vm_remap(mach_task_self(),
                          &virtualAddress,   // mirror target
                          buffer->length,    // size of mirror
                          0,                 // auto alignment
                          0,                 // force remapping to virtualAddress
                          mach_task_self(),  // same task
                          bufferAddress,     // mirror source
                          0,                 // MAP READ-WRITE, NOT COPY
                          &cur_prot,         // unused protection struct
                          &max_prot,         // unused protection struct
                          VM_INHERIT_DEFAULT);
        if ( result != ERR_SUCCESS ) {
            if ( retries-- == 0 ) {
                reportResult(result, "Remap buffer memory");
                return false;
            }
            // If this remap failed, we hit a race condition, so deallocate and try again
            vm_deallocate(mach_task_self(), bufferAddress, buffer->length);
            continue;
        }
        
        if ( virtualAddress != bufferAddress+buffer->length ) {
            // If the memory is not contiguous, clean up both allocated buffers and try again
            if ( retries-- == 0 ) {
                printf("Couldn't map buffer memory to end of buffer\n");
                return false;
            }
            
            vm_deallocate(mach_task_self(), virtualAddress, buffer->length);
            vm_deallocate(mach_task_self(), bufferAddress, buffer->length);
            continue;
        }
        
        buffer->buffer = (void*)bufferAddress;
        buffer->fillCount = 0;
        buffer->head = buffer->tail = 0;
        buffer->atomic = true;
        
        return true;
    }
    return false;
}