Ejemplo n.º 1
0
void Client::changeStatus(Client::Status status)
{
    endStatus();
    startStatus(status);

    emit userStatusChanged(status);
}
Ejemplo n.º 2
0
// Update Protocol reply recieved
void updateReplyRecieved()
{
  // Check if INIT Success
  // Release the RX buffer inside
  if (txState == INIT){
    initStatus();
  }
  else if (txState == START){
    startStatus();
  }
  else
    bmac_rx_pkt_release ();
}
Ejemplo n.º 3
0
void DatabasesCloner::_onListDatabaseFinish(const CommandCallbackArgs& cbd) {
    Status respStatus = cbd.response.getStatus();
    if (respStatus.isOK()) {
        respStatus = getStatusFromCommandResult(cbd.response.getValue().data);
    }

    UniqueLock lk(_mutex);
    if (!respStatus.isOK()) {
        LOG(1) << "listDatabases failed: " << respStatus;
        _setStatus_inlock(respStatus);
        _failed_inlock(lk);
        return;
    }

    const auto respBSON = cbd.response.getValue().data;
    // There should not be any cloners yet
    invariant(_databaseCloners.size() == 0);
    const auto dbsElem = respBSON["databases"].Obj();
    BSONForEach(arrayElement, dbsElem) {
        const BSONObj dbBSON = arrayElement.Obj();

        // Check to see if we want to exclude this db from the clone.
        if (!_includeDbFn(dbBSON)) {
            LOG(1) << "excluding db: " << dbBSON;
            continue;
        }

        const std::string dbName = dbBSON["name"].str();
        ++_clonersActive;
        std::shared_ptr<DatabaseCloner> dbCloner{nullptr};
        Status startStatus(ErrorCodes::NotYetInitialized,
                           "The DatabasesCloner could not be started.");

        // filters for DatabasesCloner.
        const auto collectionFilterPred = [dbName](const BSONObj& collInfo) {
            const auto collName = collInfo["name"].str();
            const NamespaceString ns(dbName, collName);
            if (ns.isSystem() && !legalClientSystemNS(ns.ns(), true)) {
                LOG(1) << "Skipping 'system' collection: " << ns.ns();
                return false;
            }
            if (!ns.isNormal()) {
                LOG(1) << "Skipping non-normal collection: " << ns.ns();
                return false;
            }

            LOG(2) << "Allowing cloning of collectionInfo: " << collInfo;
            return true;
        };
        const auto onCollectionFinish = [](const Status& status, const NamespaceString& srcNss) {
            if (status.isOK()) {
                LOG(1) << "collection clone finished: " << srcNss;
            } else {
                warning() << "collection clone for '" << srcNss << "' failed due to "
                          << status.toString();
            }
        };
        const auto onDbFinish = [this, dbName](const Status& status) {
            _onEachDBCloneFinish(status, dbName);
        };
        try {
            dbCloner.reset(new DatabaseCloner(
                _exec,
                _source,
                dbName,
                BSONObj(),  // do not filter collections out during listCollections call.
                collectionFilterPred,
                _storage,  // use storage provided.
                onCollectionFinish,
                onDbFinish));
            // Start database cloner.
            startStatus = dbCloner->start();
        } catch (...) {
            startStatus = exceptionToStatus();
        }

        if (!startStatus.isOK()) {
            std::string err = str::stream() << "could not create cloner for database: " << dbName
                                            << " due to: " << startStatus.toString();
            _setStatus_inlock({ErrorCodes::InitialSyncFailure, err});
            error() << err;
            break;  // exit for_each loop
        }

        // add cloner to list.
        _databaseCloners.push_back(dbCloner);
    }

    if (_databaseCloners.size() == 0) {
        if (_status.isOK()) {
            _active = false;
            lk.unlock();
            _finishFn(_status);
        } else {
            _failed_inlock(lk);
        }
    }
}
Ejemplo n.º 4
0
void Client::checkAuthentication(QString authentication, bool encrypted)
{
    QString status = "failed",
            message = QString();

    if (encrypted)
        authentication = QByteArray::fromBase64(authentication.toLatin1());

    QStringList usernamePassword = QString(authentication).split(":");
    QString hashedPassword = QCryptographicHash::hash(usernamePassword[1].toLatin1(), QCryptographicHash::Md5).toHex();

    socketOut.writeStartElement("authentication");
    socketOut.writeAttribute("id", "status");

    QSqlQuery retrieveUser;
    retrieveUser.prepare("SELECT acd_agent_id, name, password, fullname, level "
                         "FROM acd_agent "
                         "WHERE name = :username AND password = :password");

    retrieveUser.bindValue(":username", usernamePassword[0]);
    retrieveUser.bindValue(":password", hashedPassword);

    if (retrieveUser.exec()) {
        if (retrieveUser.next()) {
            username = usernamePassword[0];
            fullname = retrieveUser.value(3).toString();
            level = (Level) retrieveUser.value(4).toUInt();
            agentId = retrieveUser.value(0).toUInt();
            status = "ok";

            socketOut.writeTextElement("level", QString::number(level));
            socketOut.writeTextElement("login", QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"));

            if (!extension.isEmpty())
                socketOut.writeTextElement("extension", extension);
            else
                retrieveExtension();

            retrieveSkills();
            retrieveGroups();
            startSession();
            startStatus(Login);

            emit userLoggedIn();
        } else {
            message = "Username/Password incorrect";
        }
    } else {
        message = "Retrieve user query error";

        logFailedQuery(&retrieveUser, "retrieving user");
    }

    socketOut.writeTextElement("status", status);

    if (!message.isEmpty())
        socketOut.writeTextElement("message", message);

    socketOut.writeEndElement(); // authentication

    socket->write("\n");
}