string CEntityInfo::getRenameCommand(symbolPtr* pSym,string newname) {
    string command;
    string selectTag = prepareQuery(etag(pSym));
    string permissionCode = "1";

    if(IsPublic(pSym)) permissionCode = "0";
    else if(IsProtected(pSym)) permissionCode = "2";
    else if(IsPrivate(pSym))   permissionCode = "3";

    switch(pSym->get_kind()) {
    case DD_MODULE:
        command="Impact:ChangeFilename " + selectTag +
                " {" + newname + "}";
        break;
    case DD_INTERFACE:
    case DD_CLASS:


        command = "Impact:ChangeClassname " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_ENUM:
    case DD_UNION:
        command = "Impact:ChangeUnionEnumStructName " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_FIELD:
        command = "Impact:ChangeFieldName " + selectTag +
                  " {" + newname + "} " + permissionCode;
        break;
    case DD_FUNC_DECL:
        command = "Impact:ChangeFunctionName " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_TYPEDEF:
        command = "Impact:ChangeTypedefName " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_MACRO:
        command = "Impact:ChangeMacroName " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_TEMPLATE:
        command = "Impact:ChangeTemplateName " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_VAR_DECL:
        command = "Impact:ChangeVariableName " + selectTag +
                  " {" + newname + "}";
        break;
    case DD_PACKAGE:
        command ="Impact:RenamePackage " + selectTag +
                 " { " + newname + "}";
    }
    return command;
}
string CEntityInfo::getChangeBodyCommand(symbolPtr* pSym) {
    string command;
    string selectTag = prepareQuery(etag(pSym));
    switch(pSym->get_kind()) {
    case DD_FUNC_DECL:
        command = "Impact:ChangeFunctionBody " + selectTag;
        break;
    case DD_MACRO:
        command = "Impact:ChangeMacroBody " + selectTag;
        break;
    case DD_TEMPLATE:
        command = "Impact:ChangeTemplateBody " + selectTag;
        break;
    }
    return command;
}
Beispiel #3
0
InstVersion *MinecraftVersion::copyVersion(InstVersionList *newParent) const
{
	if (isMeta())
	{
		MinecraftVersion *version = new MinecraftVersion((MinecraftVersion *)m_linkedVersion);
		return version;
	}
	else
	{
		MinecraftVersion *version = new MinecraftVersion(
					descriptor(), name(), timestamp(), downloadURL(), etag(), newParent);
		version->setVersionType(versionType());
		version->setIsForNewLauncher(isForNewLauncher());
		return version;
	}
}
Beispiel #4
0
bool SyncJournalDb::setFileRecord( const SyncJournalFileRecord& record )
{
    QMutexLocker locker(&_mutex);
    qlonglong phash = getPHash(record._path);
    if( checkConnect() ) {
        QByteArray arr = record._path.toUtf8();
        int plen = arr.length();

        // _setFileRecordQuery->prepare("INSERT OR REPLACE INTO metadata "
        //                            "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid) "
        //                            "VALUES ( ? , ?, ? , ? , ? , ? , ?,  ? , ? , ?, ? )" );
        QString etag( record._etag );
        if( etag.isEmpty() ) etag = "";
        QString fileId( record._fileId);
        if( fileId.isEmpty() ) fileId = "";

        _setFileRecordQuery->bindValue(0, QString::number(phash));
        _setFileRecordQuery->bindValue(1, plen);
        _setFileRecordQuery->bindValue(2, record._path );
        _setFileRecordQuery->bindValue(3, record._inode );
        _setFileRecordQuery->bindValue(4, record._uid );
        _setFileRecordQuery->bindValue(5, record._gid );
        _setFileRecordQuery->bindValue(6, record._mode );
        _setFileRecordQuery->bindValue(7, QString::number(record._modtime.toTime_t()));
        _setFileRecordQuery->bindValue(8, QString::number(record._type) );
        _setFileRecordQuery->bindValue(9, etag );
        _setFileRecordQuery->bindValue(10, fileId );

        if( !_setFileRecordQuery->exec() ) {
            qWarning() << "Error SQL statement setFileRecord: " << _setFileRecordQuery->lastQuery() <<  " :"
                       << _setFileRecordQuery->lastError().text();
            return false;
        }

        qDebug() <<  _setFileRecordQuery->lastQuery() << phash << plen << record._path << record._inode
                 << record._uid << record._gid << record._mode
                 << QString::number(record._modtime.toTime_t()) << QString::number(record._type)
                 << record._etag << record._fileId;
        _setFileRecordQuery->finish();

        return true;
    } else {
        qDebug() << "Failed to connect database.";
        return false; // checkConnect failed.
    }
}
Beispiel #5
0
void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot()
{
    if (!_ignoredFirst) {
        // This is a sanity check, if we haven't _ignoredFirst then it means we never received any directoryListingIteratedSlot
        // which means somehow the server XML was bogus
        emit finishedWithError(ERRNO_WRONG_CONTENT, QLatin1String("Server error: PROPFIND reply is not XML formatted!"));
        deleteLater();
        return;
    } else if (!_error.isEmpty()) {
        emit finishedWithError(ERRNO_WRONG_CONTENT, _error);
        deleteLater();
        return;
    }
    emit etag(_firstEtag);
    emit etagConcatenation(_etagConcatenation);
    emit finishedWithResult();
    deleteLater();
}
Beispiel #6
0
/*!
 * Универсальный метод для отдачи тела фида.
 */
bool FeedHandler::serveFeed(ChatChannel channel, const QString &feedName)
{
  if (!ifMethodAllowed())
    return true;

  if (!channel || !channel->feeds().all().contains(feedName)) {
    setNoStore();
    m_response->writeHead(Tufao::HttpServerResponse::NOT_FOUND);
    m_response->end();
    return true;
  }

  FeedPtr feed = channel->feed(feedName);
  qint64 date  = feed->head().date();

  RestReplyCache &cache = m_cache[channel->id() + feedName.toUtf8()];
  if (cache.date != date) {
    cache.date = date;
    cache.etag = etag(date, m_path.toUtf8());

    cache.body = JSON::generate(feed->feed());
  }

  setLastModified(date);
  setETag(cache.etag);
  setNoCache();

  if (!ifModified(cache.etag)) {
    m_response->writeHead(Tufao::HttpServerResponse::NOT_MODIFIED);
    m_response->end();
    return true;
  }

  m_response->writeHead(Tufao::HttpServerResponse::OK);
  if (m_request->method() != "HEAD") {
    setContentLength(cache.body.size());
    m_response->end(cache.body);
  }
  else
    m_response->end();

  return true;
}
string CEntityInfo::getChangeTypeCommand(symbolPtr* pSym,string newtype) {
    string command;
    string selectTag = prepareQuery(etag(pSym));

    switch(pSym->get_kind()) {
    case DD_FIELD:
        command = "Impact:ChangeVariableType " + selectTag + " " +
                  "{" + newtype + "}";
        break;
    case DD_FUNC_DECL:
        command = "Impact:ChangeFunctionType " + selectTag + " " +
                  "{" + newtype + "}";
        break;
    case DD_VAR_DECL:
        command = "Impact:ChangeVariableType " + selectTag + " " +
                  "{" + newtype + "}";
        break;
    }
    return command;
}
Beispiel #8
0
void SyncEngine::startSync()
{
    if (_journal->exists()) {
        QVector< SyncJournalDb::PollInfo > pollInfos = _journal->getPollInfos();
        if (!pollInfos.isEmpty()) {
            qDebug() << "Finish Poll jobs before starting a sync";
            CleanupPollsJob *job = new CleanupPollsJob(pollInfos, _account,
                                                       _journal, _localPath, this);
            connect(job, SIGNAL(finished()), this, SLOT(startSync()));
            connect(job, SIGNAL(aborted(QString)), this, SLOT(slotCleanPollsJobAborted(QString)));
            job->start();
            return;
        }
    }

    Q_ASSERT(!_syncRunning);
    _syncRunning = true;

    Q_ASSERT(_csync_ctx);

    if (!QDir(_localPath).exists()) {
        // No _tr, it should only occur in non-mirall
        emit csyncError("Unable to find local sync folder.");
        finalize(false);
        return;
    }

    // Check free size on disk first.
    const qint64 minFree = criticalFreeSpaceLimit();
    const qint64 freeBytes = Utility::freeDiskSpace(_localPath);
    if (freeBytes >= 0) {
        qDebug() << "There are" << freeBytes << "bytes available at" << _localPath
                 << "and at least" << minFree << "are required";
        if (freeBytes < minFree) {
            emit csyncError(tr("Only %1 are available, need at least %2 to start").arg(
                                Utility::octetsToString(freeBytes),
                                Utility::octetsToString(minFree)));
            finalize(false);
            return;
        }
    } else {
        qDebug() << "Could not determine free space available at" << _localPath;
    }

    _syncedItems.clear();
    _syncItemMap.clear();
    _needsUpdate = false;

    csync_resume(_csync_ctx);

    int fileRecordCount = -1;
    if (!_journal->exists()) {
        qDebug() << "=====sync looks new (no DB exists)";
    } else {
        qDebug() << "=====sync with existing DB";
    }

    qDebug() <<  "=====Using Qt" << qVersion();
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    qDebug() <<  "=====Using SSL library version"
             <<  QSslSocket::sslLibraryVersionString().toUtf8().data();
#endif

    fileRecordCount = _journal->getFileRecordCount(); // this creates the DB if it does not exist yet

    if( fileRecordCount == -1 ) {
        qDebug() << "No way to create a sync journal!";
        emit csyncError(tr("Unable to initialize a sync journal."));
        finalize(false);
        return;
        // database creation error!
    }

    _csync_ctx->read_remote_from_db = true;

    // This tells csync to never read from the DB if it is empty
    // thereby speeding up the initial discovery significantly.
    _csync_ctx->db_is_empty = (fileRecordCount == 0);

    auto selectiveSyncBlackList = _journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList);
    bool usingSelectiveSync = (!selectiveSyncBlackList.isEmpty());
    qDebug() << (usingSelectiveSync ? "====Using Selective Sync" : "====NOT Using Selective Sync");

    csync_set_userdata(_csync_ctx, this);

    _stopWatch.start();

    qDebug() << "#### Discovery start #################################################### >>";

    _discoveryMainThread = new DiscoveryMainThread(account());
    _discoveryMainThread->setParent(this);
    connect(this, SIGNAL(finished(bool)), _discoveryMainThread, SLOT(deleteLater()));
    qDebug() << "=====Server" << account()->serverVersion()
             <<  QString("rootEtagChangesNotOnlySubFolderEtags=%1").arg(account()->rootEtagChangesNotOnlySubFolderEtags());
    if (account()->rootEtagChangesNotOnlySubFolderEtags()) {
        connect(_discoveryMainThread, SIGNAL(etag(QString)), this, SLOT(slotRootEtagReceived(QString)));
    } else {
        connect(_discoveryMainThread, SIGNAL(etagConcatenation(QString)), this, SLOT(slotRootEtagReceived(QString)));
    }

    DiscoveryJob *discoveryJob = new DiscoveryJob(_csync_ctx);
    discoveryJob->_selectiveSyncBlackList = selectiveSyncBlackList;
    discoveryJob->_selectiveSyncWhiteList =
        _journal->getSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList);
    discoveryJob->_newBigFolderSizeLimit = _newBigFolderSizeLimit;
    discoveryJob->moveToThread(&_thread);
    connect(discoveryJob, SIGNAL(finished(int)), this, SLOT(slotDiscoveryJobFinished(int)));
    connect(discoveryJob, SIGNAL(folderDiscovered(bool,QString)),
            this, SIGNAL(folderDiscovered(bool,QString)));

    connect(discoveryJob, SIGNAL(newBigFolder(QString)),
            this, SIGNAL(newBigFolder(QString)));


    // This is used for the DiscoveryJob to be able to request the main thread/
    // to read in directory contents.
    qDebug() << Q_FUNC_INFO << _remotePath << _remoteUrl;
    _discoveryMainThread->setupHooks( discoveryJob, _remotePath);

    // Starts the update in a seperate thread
    QMetaObject::invokeMethod(discoveryJob, "start", Qt::QueuedConnection);
}
string CEntityInfo::entityName(symbolPtr* pSym) {
    string result;
    string command = "printformat \"%s\" name;name " + prepareQuery(etag(pSym));
    exec(command,result);
    return result;
}
Beispiel #10
0
static int record_select(int nfield, char const *field[], void* vxml)
/*
* Receive fields from domain selection query.  These must be:
* ip [0], count [1], dispo [2], d_dkim [3], d_spf [4], reason [5], domain [6],
* spf [7], spf_result [8], spf_helo [9], spf_result [10], and
* dkim [11], dkim_result [12] (repeated any number of times, NULL values skipped)
*/
{
	if (nfield < 10)
	{
		(*do_log)(LOG_ERR, "only %d record field(s)%s", nfield, bailout);
		return -1;
	}

	xml_tree *xml = vxml;

	stag(xml, "record");
	stag(xml, "row");
	xtag(xml, "source_ip", field[0]);
	xtag(xml, "count", field[1]);

	stag(xml, "policy_evaluated");
	xtag(xml, "disposition", field[2]);
	xtag(xml, "dkim", field[3]);
	xtag(xml, "spf", field[4]);

	// reason, if given, is type + [space comment]
	if (field[5] && strcmp(field[5], "none") != 0)
	{
		stag(xml, "reason");

		char const *c = field[5];
		int ch;
		while (isalnum(ch = *(unsigned char*)c) || ch == '_')
			++c;
		xtagn(xml, "type", field[5], c - field[5]);
		if (isspace(ch))
			xtag(xml, "comment", c+1);
		etag(xml); // reason
	}
	etag(xml); // policy evaluated
	etag(xml); // row

	stag(xml, "identifiers");
	xtag(xml, "header_from", field[6]);
	etag(xml);

	stag(xml, "auth_results");
	for (int i = 11; i+1 < nfield; i += 2)
		if (field[i] && field[i+1])
		{
			stag(xml, "dkim");
			xtag(xml, "domain", field[i]);
			xtag(xml, "result", field[i+1]);
			etag(xml); // dkim
		}

	stag(xml, "spf");
	if (field[7] && field[8] && field[9] && field[10])
	{
		bool pass8 = strcmp(field[8], "pass") == 0,
			pass10 = strcmp(field[10], "pass") == 0;
		if (pass8 == pass10)
		{
			// if both or neither are pass, output helo only if
			// it is better aligned than mfrom
			if (field[6] &&
				is_parent_domain_of(field[6], field[9]) &&
				!is_parent_domain_of(field[6], field[7]))
					field[7] = NULL;
		}
		else if (pass10)
			field[7] = NULL;
	}

	if (field[7] && field[8])
	{
		xtag(xml, "domain", field[7]);
		xtag(xml, "result", field[8]);
		xtag(xml, "scope", "mfrom");
	}
	else if (field[9] && field[10])
	{
		xtag(xml, "domain", field[9]);
		xtag(xml, "result", field[10]);
		xtag(xml, "scope", "helo");
	}
	else
	{
		xtag(xml, "domain", "");
		xtag(xml, "result", "none");
	}
	etag(xml); // spf
	etag(xml); // auth_results
	etag(xml); // record

	return xml_flush(xml, 0);
}