Example #1
0
void ADLSearchManager::matchesFile(DestDirList& destDirVector, DirectoryListing::File *currentFile, string& fullPath) {
	// Add to any substructure being stored
	for(DestDirList::iterator id = destDirVector.begin(); id != destDirVector.end(); ++id) {
		if(id->subdir != NULL) {
			DirectoryListing::File *copyFile = new DirectoryListing::File(*currentFile, true);
			dcassert(id->subdir->getAdls());
			
			id->subdir->files.push_back(copyFile);
		}
		id->fileAdded = false;	// Prepare for next stage
	}

	// Prepare to match searches
	if(currentFile->getName().size() < 1) {
		return;
	}

	string filePath = fullPath + "\\" + currentFile->getName();
	// Match searches
	for(SearchCollection::iterator is = collection.begin(); is != collection.end(); ++is) {
		if(destDirVector[is->ddIndex].fileAdded) {
			continue;
		}
		if(is->matchesFile(currentFile->getName(), filePath, currentFile->getSize())) {
			DirectoryListing::File *copyFile = new DirectoryListing::File(*currentFile, true);
			if(is->isForbidden && !getSentRaw()) {
				char buf[256];
				snprintf(buf, sizeof(buf), CSTRING(CHECK_FORBIDDEN), currentFile->getName().c_str());
				
				ClientManager::getInstance()->setClientStatus(user, buf, is->raw, false);

				setSentRaw(true);
			}
			destDirVector[is->ddIndex].dir->files.push_back(copyFile);
			destDirVector[is->ddIndex].fileAdded = true;

			if(is->isAutoQueue) {
				try {
					QueueManager::getInstance()->add(SETTING(DOWNLOAD_DIRECTORY) + currentFile->getName(),
						currentFile->getSize(), currentFile->getTTH(), getUser());
				} catch(const Exception&) {	}
			}

			if(breakOnFirst) {
				// Found a match, search no more
				break;
			}
		}
	}
}
Example #2
0
void ADLSearchManager::matchListing(DirectoryListing& aDirList) noexcept {
	StringMap params;
	if(aDirList.getUser())
	{
	params["userNI"] = ClientManager::getInstance()->getNicks(aDirList.getHintedUser())[0];
	params["userCID"] = aDirList.getUser()->getCID().toBase32();
	}
	setUser(aDirList.getHintedUser());
	setSentRaw(false);

	DestDirList destDirs;
	prepareDestinationDirectories(destDirs, aDirList.getRoot(), params);
	setBreakOnFirst(BOOLSETTING(ADLS_BREAK_ON_FIRST));

	string path(aDirList.getRoot()->getName());
	matchRecurse(destDirs, aDirList.getRoot(), path);

	finalizeDestinationDirectories(destDirs, aDirList.getRoot());
}
Example #3
0
void ADLSearchManager::matchesFile(DestDirList& destDirVector, DirectoryListing::File *currentFile, const string& fullPath)
{
	// Add to any substructure being stored
	for (auto id = destDirVector.begin(); id != destDirVector.end(); ++id)
	{
		if (id->subdir != NULL)
		{
			auto copyFile = new DirectoryListing::File(*currentFile, true);
			copyFile->setFlags(currentFile->getFlags());
			dcassert(id->subdir->getAdls());
			
			id->subdir->m_files.push_back(copyFile);
		}
		id->fileAdded = false;  // Prepare for next stage
	}
	
	// Prepare to match searches
	if (currentFile->getName().size() < 1)
	{
		return;
	}
	
	string filePath = fullPath + "\\" + currentFile->getName();// TODO Crash
	// Match searches
	for (auto is = collection.cbegin(); is != collection.cend(); ++is)
	{
		if (destDirVector[is->ddIndex].fileAdded)
		{
			continue;
		}
		if (is->matchesFile(currentFile->getName(), filePath, currentFile->getSize()))
		{
			auto copyFile = new DirectoryListing::File(*currentFile, true);
			copyFile->setFlags(currentFile->getFlags());
#ifdef IRAINMAN_INCLUDE_USER_CHECK
			if (is->isForbidden && !getSentRaw())
			{
				AutoArray<char> buf(FULL_MAX_PATH);
				_snprintf(buf, FULL_MAX_PATH, CSTRING(CHECK_FORBIDDEN), currentFile->getName().c_str());
				
				ClientManager::setClientStatus(user, buf.data(), is->raw, false);
				
				setSentRaw(true);
			}
#endif
			
			destDirVector[is->ddIndex].dir->m_files.push_back(copyFile);
			destDirVector[is->ddIndex].fileAdded = true;
			
			if (is->isAutoQueue)
			{
				try
				{
					QueueManager::getInstance()->add(0,/* [-] IRainman needs for support download to specify extension dir. SETTING(DOWNLOAD_DIRECTORY) + */currentFile->getName(),
					                                 currentFile->getSize(), currentFile->getTTH(), getUser()/*, Util::emptyString*/);
				}
				catch (const Exception& e)
				{
					LogManager::message("QueueManager::getInstance()->add Error = " + e.getError());
				}
			}
			
			if (breakOnFirst)
			{
				// Found a match, search no more
				break;
			}
		}
	}
}