Exemple #1
0
	/*
	 * Save all indexes to disk
	 */
	void IndexManager::saveIndexes(SimpleXML& xml)
	{
		xml.addTag("Files");
		xml.stepIn();

		Lock l(cs);
		for(auto i = tthList.cbegin(); i != tthList.cend(); ++i)
		{
			xml.addTag("File");
			xml.addChildAttrib("TTH", i->first.toBase32());

			xml.stepIn();
			for(auto j = i->second.cbegin(); j != i->second.cend(); ++j)
			{
				const Source& source = *j;

				if(source.getPartial())
					continue;	// don't store partial sources

				xml.addTag("Source");
				xml.addChildAttrib("CID", source.getCID().toBase32());
				xml.addChildAttrib("I4", source.getIp());
				xml.addChildAttrib("U4", source.getUdpPort());
				xml.addChildAttrib("SI", source.getSize());
				xml.addChildAttrib("EX", source.getExpires());
			}
			xml.stepOut();
		}

		xml.stepOut();
	}
Exemple #2
0
void MessageManager::saveUsers() {
    SimpleXML xml;

    xml.addTag("Ignored");
    xml.stepIn();

    xml.addTag("Users");
    xml.stepIn();

    //TODO: cache this information?
    {
        RLock l(Ignorecs);
        for (const auto& u : ignoredUsers) {
            xml.addTag("User");
            xml.addChildAttrib("CID", u->getCID().toBase32());
            auto ou = ClientManager::getInstance()->findOnlineUser(u->getCID(), "");
            if (ou) {
                xml.addChildAttrib("Nick", ou->getIdentity().getNick());
                xml.addChildAttrib("Hub", ou->getHubUrl());
                xml.addChildAttrib("LastSeen", GET_TIME());
            }
            else {
                auto ofu = ClientManager::getInstance()->getOfflineUser(u->getCID());
                xml.addChildAttrib("Nick", ofu ? ofu->getNick() : "");
                xml.addChildAttrib("Hub", ofu ? ofu->getUrl() : "");
                xml.addChildAttrib("LastSeen", ofu ? ofu->getLastSeen() : GET_TIME());
            }
        }
    }
    xml.stepOut();
    xml.stepOut();

    SettingsManager::saveSettingFile(xml, CONFIG_DIR, CONFIG_NAME);
}
	bool WebServerManager::load() noexcept {
		try {
			SimpleXML xml;
			SettingsManager::loadSettingFile(xml, CONFIG_DIR, CONFIG_NAME, true);
			if (xml.findChild("WebServer")) {
				xml.stepIn();

				if (xml.findChild("Config")) {
					xml.stepIn();
					loadServer(xml, "Server", plainServerConfig);
					loadServer(xml, "TLSServer", tlsServerConfig);

					if (xml.findChild("Threads")) {
						xml.stepIn();
						serverThreads = min(Util::toInt(xml.getData()), 2);
						xml.stepOut();
					}

					xml.stepOut();
				}

				fire(WebServerManagerListener::LoadSettings(), xml);

				xml.stepOut();
			}
		} catch (const Exception& e) {
			LogManager::getInstance()->message(STRING_F(LOAD_FAILED_X, CONFIG_NAME % e.getError()), LogMessage::SEV_ERROR);
		}

		return hasValidConfig();
	}
Exemple #4
0
	/*
	 * Loads existing indexes from disk
	 */
	void IndexManager::loadIndexes(SimpleXML& xml)
	{
		xml.resetCurrentChild();
		if(xml.findChild("Files"))
		{
			xml.stepIn();
			while(xml.findChild("File"))
			{
				const TTHValue tth = TTHValue(xml.getChildAttrib("TTH"));
				SourceList sources;

				xml.stepIn();
				while(xml.findChild("Source"))
				{
					Source source;
					source.setCID(CID(xml.getChildAttrib("CID")));
					source.setIp(xml.getChildAttrib("I4"));
					source.setUdpPort(static_cast<uint16_t>(xml.getIntChildAttrib("U4")));
					source.setSize(xml.getLongLongChildAttrib("SI"));
					source.setExpires(xml.getLongLongChildAttrib("EX"));
					source.setPartial(false);

					sources.push_back(source);
				}

				tthList.insert(std::make_pair(tth, sources));
				xml.stepOut();
			}
			xml.stepOut();
		}
	}
Exemple #5
0
void ResourceManager::loadLanguage(const string& aFile) {
	try {
		File f(aFile, File::READ, File::OPEN);
		SimpleXML xml;
		xml.fromXML(f.read());

		unordered_map<string, int> h;
		
		for(int i = 0; i < LAST; ++i) {
			h[names[i]] = i;
		}

		if(xml.findChild("Language")) {
			rtl = xml.getBoolChildAttrib("RightToLeft");

			xml.stepIn();
			if(xml.findChild("Strings")) {
				xml.stepIn();

				while(xml.findChild("String")) {
					unordered_map<string, int>::const_iterator j = h.find(xml.getChildAttrib("Name"));

					if(j != h.end()) {
						strings[j->second] = xml.getChildData();
					}
				}
				createWide();
			}
		}
	} catch(const Exception&) {
		// ...
	}
}
Exemple #6
0
void MessageManager::loadUsers() {
    try {
        SimpleXML xml;
        SettingsManager::loadSettingFile(xml, CONFIG_DIR, CONFIG_NAME);
        auto cm = ClientManager::getInstance();
        if (xml.findChild("Ignored")) {
            xml.stepIn();
            xml.resetCurrentChild();
            if (xml.findChild("Users")) {
                xml.stepIn();
                while (xml.findChild("User")) {
                    UserPtr user = cm->getUser(CID(xml.getChildAttrib("CID")));
                    {
                        WLock(cm->getCS());
                        cm->addOfflineUser(user, xml.getChildAttrib("Nick"), xml.getChildAttrib("Hub"), (uint32_t)xml.getIntChildAttrib("LastSeen"));
                    }
                    WLock l(Ignorecs);
                    ignoredUsers.emplace(user);
                    user->setFlag(User::IGNORED);
                }
                xml.stepOut();
            }
            xml.stepOut();
        }
    }
    catch (const Exception& e) {
        LogManager::getInstance()->message(STRING_F(LOAD_FAILED_X, CONFIG_NAME % e.getError()), LogManager::LOG_ERROR);
    }
}
	bool WebServerManager::save(std::function<void(const string&)> aCustomErrorF) noexcept {
		SimpleXML xml;

		xml.addTag("WebServer");
		xml.stepIn();

		{
			xml.addTag("Config");
			xml.stepIn();
			plainServerConfig.save(xml, "Server");
			tlsServerConfig.save(xml, "TLSServer");
			xml.stepOut();
		}

		fire(WebServerManagerListener::SaveSettings(), xml);

		xml.stepOut();

		auto errorF = aCustomErrorF;
		if (!errorF) {
			// Avoid crashes if the file is saved when core is not loaded
			errorF = [](const string&) {};
		}

		return SettingsManager::saveSettingFile(xml, CONFIG_DIR, CONFIG_NAME, errorF);
	}
void ClientProfileManager::saveClientProfiles() {
	try {
		SimpleXML xml;
		xml.addTag("Profiles");
		xml.stepIn();

		xml.addTag("ClientProfilesV2");
		xml.stepIn();
		for(ClientProfile::List::const_iterator l = clientProfiles.begin(); l != clientProfiles.end(); ++l) {
			xml.addTag("ClientProfile");
			xml.stepIn();
			xml.addTag("Name", l->getName());
			xml.addTag("Version", l->getVersion());
			xml.addTag("Tag", l->getTag());
			xml.addTag("ExtendedTag", l->getExtendedTag());
			xml.addTag("Lock", l->getLock());
			xml.addTag("Pk", l->getPk());
			xml.addTag("Supports", l->getSupports());
			xml.addTag("TestSUR", l->getTestSUR());
			xml.addTag("UserConCom", l->getUserConCom());
			xml.addTag("Status", l->getStatus());
			xml.addTag("CheatingDescription", l->getCheatingDescription());
			xml.addTag("RawToSend", Util::toString(l->getRawToSend()));
			//xml.addTag("TagVersion", Util::toString(l->getTagVersion()));
			xml.addTag("UseExtraVersion", Util::toString(l->getUseExtraVersion()));
			xml.addTag("CheckMismatch", Util::toString(l->getCheckMismatch()));
			xml.addTag("Connection", l->getConnection());
			xml.addTag("Comment", l->getComment());
			xml.addTag("Recheck", l->getRecheck());
			xml.addTag("SkipExtended", l->getSkipExtended());
			xml.stepOut();
		}
		xml.stepOut();

		xml.addTag("Params");
		xml.stepIn();
		for(StringMap::iterator m = params.begin(); m != params.end(); ++m) {
			xml.addTag("Param");
			xml.addChildAttrib("Name", m->first);
			xml.addChildAttrib("RegExp", m->second);
		}
		xml.stepOut();

		xml.stepOut();

		string fname = Util::getConfigPath() + "Profiles.xml";

		File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE);
		f.write(SimpleXML::utf8Header);
		f.write(xml.toXML());
		f.close();
		File::deleteFile(fname);
		File::renameFile(fname + ".tmp", fname);

	} catch(const Exception& e) {
		dcdebug("FavoriteManager::saveClientProfiles: %s\n", e.getError().c_str());
	}
}
Exemple #9
0
void SettingsManager::save(string const& aFileName) {

	SimpleXML xml;
	xml.addTag("DCPlusPlus");
	xml.stepIn();
	xml.addTag("Settings");
	xml.stepIn();

	int i;
	string type("type"), curType("string");
	
	for(i=STR_FIRST; i<STR_LAST; i++)
	{
		if (i == INCOMING_CONNECTIONS) continue;
		if(i == CONFIG_VERSION) {
			xml.addTag(settingTags[i], m_version);
			xml.addChildAttrib(type, curType);
		} else if(isSet[i]) {
			xml.addTag(settingTags[i], get(StrSetting(i), false));
			xml.addChildAttrib(type, curType);
		}
	}

	curType = "int";
	for(i=INT_FIRST; i<INT_LAST; i++)
	{
		if(isSet[i]) {
			xml.addTag(settingTags[i], get(IntSetting(i), false));
			xml.addChildAttrib(type, curType);
		}
	}
	curType = "int64";
	for(i=INT64_FIRST; i<INT64_LAST; i++)
	{
		if(isSet[i])
		{
			xml.addTag(settingTags[i], get(Int64Setting(i), false));
			xml.addChildAttrib(type, curType);
		}
	}
	xml.stepOut();
	
	fire(SettingsManagerListener::Save(), xml);

	try {
		File out(aFileName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE);
		BufferedOutputStream<false> f(&out);
		f.write(SimpleXML::utf8Header);
		xml.toXML(&f);
		f.flush();
		out.close();
		File::deleteFile(aFileName);
		File::renameFile(aFileName + ".tmp", aFileName);
	} catch(const FileException&) {
		// ...
	}
}
Exemple #10
0
void AutoSearch::saveToXml(SimpleXML& xml) {
	xml.addTag("Autosearch");
	xml.addChildAttrib("Enabled", getEnabled());
	xml.addChildAttrib("SearchString", getSearchString());
	xml.addChildAttrib("FileType", getFileType());
	xml.addChildAttrib("Action", getAction());
	xml.addChildAttrib("Remove", getRemove());
	xml.addChildAttrib("Target", getTarget());
	xml.addChildAttrib("TargetType", getTargetType());
	xml.addChildAttrib("MatcherType", getMethod()),
	xml.addChildAttrib("MatcherString", getMatcherString()),
	xml.addChildAttrib("UserMatch", getNickPattern());
	xml.addChildAttrib("ExpireTime", getExpireTime());
	xml.addChildAttrib("CheckAlreadyQueued", getCheckAlreadyQueued());
	xml.addChildAttrib("CheckAlreadyShared", getCheckAlreadyShared());
	xml.addChildAttrib("SearchDays", searchDays.to_string());
	xml.addChildAttrib("StartTime", startTime.toString());
	xml.addChildAttrib("EndTime", endTime.toString());
	xml.addChildAttrib("LastSearchTime", Util::toString(getLastSearch()));
	xml.addChildAttrib("MatchFullPath", getMatchFullPath());
	xml.addChildAttrib("ExcludedWords", getExcludedString());
	xml.addChildAttrib("SearchInterval", Util::toString(getSearchInterval()));
	xml.addChildAttrib("ItemType", Util::toString(getAsType()));
	xml.addChildAttrib("Token", Util::toString(getToken()));
	xml.addChildAttrib("TimeAdded", Util::toString(getTimeAdded()));
	xml.addChildAttrib("Group", getGroup());
	xml.addChildAttrib("UserMatcherExclude", getUserMatcherExclude());

	xml.stepIn();

	xml.addTag("Params");
	xml.addChildAttrib("Enabled", getUseParams());
	xml.addChildAttrib("CurNumber", getCurNumber());
	xml.addChildAttrib("MaxNumber", getMaxNumber());
	xml.addChildAttrib("MinNumberLen", getNumberLen());
	xml.addChildAttrib("LastIncFinish", getLastIncFinish());

	if (!getFinishedPaths().empty()) {
		xml.addTag("FinishedPaths");
		xml.stepIn();
		for (auto& p : getFinishedPaths()) {
			xml.addTag("Path", p.first);
			xml.addChildAttrib("FinishTime", p.second);
		}
		xml.stepOut();
	}

	if (!getBundles().empty()) {
		xml.addTag("Bundles");
		xml.stepIn();
		for (const auto& b : getBundles()) {
			xml.addTag("Bundle", Util::toString(b->getToken()));
		}
		xml.stepOut();
	}
	xml.stepOut();
}
void FireResourceManager::loadLanguage(const string& aFile) {
	try {
		File f(aFile, File::READ, File::OPEN);
		SimpleXML xml;
		xml.fromXML(f.read());

		HASH_MAP<string, int> h;
//FireDC++ start
		HASH_MAP<string, int> e;
		
//FireDC++ end
		for(int i = 0; i < LAST; ++i) {
			h[names[i]] = i;
		}
//FireDC++ start
		for(int i = 0; i < LASTTWO; ++i) {
			e[namesTwo[i]] = i;
		}
//FireDC++ end
		if(xml.findChild("Language")) {
			rtl = xml.getBoolChildAttrib("RightToLeft");

			xml.stepIn();
			if(xml.findChild("Strings")) {
				xml.stepIn();

				while(xml.findChild("String")) {
					HASH_MAP<string, int>::iterator j = h.find(xml.getChildAttrib("Name"));

					if(j != h.end()) {
						strings[j->second] = xml.getChildData();
					}
				}
				createWide();
			}
//FireDC++ start
			xml.stepOut();
			if(xml.findChild("StringsTwo")) {
				xml.stepIn();

				while(xml.findChild("StringTwo")) {
					HASH_MAP<string, int>::iterator j = e.find(xml.getChildAttrib("Name"));

					if(j != e.end()) {
						stringsTwo[j->second] = xml.getChildData();
					}
				}
				createWideTwo();
			}
//FireDC++ end
		}
	} catch(const Exception&) {
		// ...
	}
}
void FireSettingsManager::load(string const& aFileName)
{
	try {
		SimpleXML xml;
		
		xml.fromXML(File(aFileName, File::READ, File::OPEN).read());
		
		xml.resetCurrentChild();
		
		xml.stepIn();
		
		if(xml.findChild("FireSettings"))
		{
			xml.stepIn();

			int i;
			
			for(i=STR_FIRST; i<STR_LAST; i++)
			{
				const string& attr = settingTags[i];
				dcassert(attr.find("SENTRY") == string::npos);
				
				if(xml.findChild(attr))
					set(StrSetting(i), xml.getChildData());
				xml.resetCurrentChild();
			}
			for(i=INT_FIRST; i<INT_LAST; i++)
			{
				const string& attr = settingTags[i];
				dcassert(attr.find("SENTRY") == string::npos);
				
				if(xml.findChild(attr))
					set(IntSetting(i), Util::toInt(xml.getChildData()));
				xml.resetCurrentChild();
			}
			for(i=INT64_FIRST; i<INT64_LAST; i++)
			{
				const string& attr = settingTags[i];
				dcassert(attr.find("SENTRY") == string::npos);
				
				if(xml.findChild(attr))
					set(Int64Setting(i), Util::toInt64(xml.getChildData()));
				xml.resetCurrentChild();
			}
			
			xml.stepOut();
		}
	
		fire(FireSettingsManagerListener::Load(), xml);
//		fire(FireSettingsManagerListener::Load(), &xml);
		xml.stepOut();

	} catch(const Exception&) {
	}
}
Exemple #13
0
void ADLSearchManager::save() const
{
	// Prepare xml string for saving
	try
	{
		SimpleXML xml;
		
		xml.addTag("ADLSearch");
		xml.stepIn();
		
		// Predicted several groups of searches to be differentiated
		// in multiple categories. Not implemented yet.
		xml.addTag("SearchGroup");
		xml.stepIn();
		
		// Save all searches
		for (auto i = collection.cbegin(); i != collection.cend(); ++i)
		{
			const ADLSearch& search = *i;
			if (search.searchString.empty())
			{
				continue;
			}
			xml.addTag("Search");
			xml.stepIn();
			
			xml.addTag("SearchString", search.searchString);
			xml.addTag("SourceType", search.SourceTypeToString(search.sourceType));
			xml.addTag("DestDirectory", search.destDir);
			xml.addTag("IsActive", search.isActive);
			xml.addTag("IsForbidden", search.isForbidden);
			xml.addTag("Raw", search.raw);
			xml.addTag("MaxSize", search.maxFileSize);
			xml.addTag("MinSize", search.minFileSize);
			xml.addTag("SizeType", search.SizeTypeToString(search.typeFileSize));
			xml.addTag("IsAutoQueue", search.isAutoQueue);
			xml.stepOut();
		}
		
		xml.stepOut();
		
		xml.stepOut();
		
		// Save string to file
		try
		{
			File fout(getConfigFile(), File::WRITE, File::CREATE | File::TRUNCATE);
			fout.write(SimpleXML::utf8Header);
			fout.write(xml.toXML());
			fout.close();
		}
		catch (const FileException&) {   }
	}
	catch (const SimpleXMLException&) { }
}
Exemple #14
0
	/*
	 * Save bootstrap nodes to disk
	 */
	void KBucket::saveNodes(SimpleXML& xml)
	{
		xml.addTag("Nodes");
		xml.stepIn();

		// get 50 random nodes to bootstrap from them next time
		Node::Map closestToMe;
		getClosestNodes(CID::generate(), closestToMe, 50, 3);

		for(Node::Map::const_iterator j = closestToMe.begin(); j != closestToMe.end(); j++)
		{
			const Node::Ptr& node = j->second;

			xml.addTag("Node");
			xml.addChildAttrib("CID", node->getUser()->getCID().toBase32());
			xml.addChildAttrib("type", node->getType());
			xml.addChildAttrib("verified", node->isIpVerified());

			if(!node->getUDPKey().key.isZero() && !node->getUDPKey().ip.empty())
			{
				xml.addChildAttrib("key", node->getUDPKey().key.toBase32());
				xml.addChildAttrib("keyIP", node->getUDPKey().ip);
			}

			StringMap params;
			node->getIdentity().getParams(params, Util::emptyString, false, true);

			for(StringMap::const_iterator i = params.begin(); i != params.end(); i++)
				xml.addChildAttrib(i->first, i->second);
		}

		xml.stepOut();
	}
Exemple #15
0
	/*
	 * Loads existing nodes from disk
	 */
	void KBucket::loadNodes(SimpleXML& xml)
	{
		xml.resetCurrentChild();
		if(xml.findChild("Nodes"))
		{
			xml.stepIn();
			while(xml.findChild("Node"))
			{
				CID cid			= CID(xml.getChildAttrib("CID"));
				string i4		= xml.getChildAttrib("I4");
				uint16_t u4		= static_cast<uint16_t>(xml.getIntChildAttrib("U4"));

				if(Utils::isGoodIPPort(i4, u4))
				{
					UDPKey udpKey;
					string key		= xml.getChildAttrib("key");
					string keyIp	= xml.getChildAttrib("keyIP");

					if(!key.empty() && !keyIp.empty())
					{
						udpKey.key = CID(key);
						udpKey.ip = keyIp;
					}

					//addUser(cid, i4, u4);
					BootstrapManager::getInstance()->addBootstrapNode(i4, u4, cid, udpKey);
				}
			}
			xml.stepOut();
		}
	}
Exemple #16
0
void ShareManager::load(SimpleXML& aXml) {
	Lock l(cs);

	aXml.resetCurrentChild();
	if(aXml.findChild("Share")) {
		aXml.stepIn();
		while(aXml.findChild("Directory")) {
			string realPath = aXml.getChildData();
			if(realPath.empty()) {
				continue;
			}
			// make sure realPath ends with a PATH_SEPARATOR
			if(realPath[realPath.size() - 1] != PATH_SEPARATOR) {
				realPath += PATH_SEPARATOR;
			}

			const string& virtualName = aXml.getChildAttrib("Virtual");
			string vName = validateVirtual(virtualName.empty() ? Util::getLastDir(realPath) : virtualName);
			shares[move(realPath)] = vName;
			if(directories.find(vName) == directories.end()) {
				directories[vName] = Directory::create(vName);
			}
		}
		aXml.stepOut();
	}
}
void ClientManager::saveUsers() const {
	try {
		SimpleXML xml;
		xml.addTag("Users");
		xml.stepIn();

		{
			Lock l(cs);
			for(auto& i: nicks) {
				if(i.second.second) {
					xml.addTag("User");
					xml.addChildAttrib("CID", i.first.toBase32());
					xml.addChildAttrib("Nick", i.second.first);
				}
			}
		}

		xml.stepOut();

		const string fName = getUsersFile();
		File out(fName + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE);
		BufferedOutputStream<false> f(&out);
		f.write(SimpleXML::utf8Header);
		xml.toXML(&f);
		f.flush();
		out.close();
		File::deleteFile(fName);
		File::renameFile(fName + ".tmp", fName);
	} catch(const Exception&) { }
}
void HighlightManager::load(SimpleXML& aXml) {
    aXml.resetCurrentChild();

    if(aXml.findChild("Highlights")) {
        aXml.stepIn();
        while(aXml.findChild("Highlight")) {
            ColorSettings cs;
            cs.setMatch( Text::utf8ToWide( aXml.getChildAttrib("Match") ) );
            cs.setBold(	aXml.getBoolChildAttrib("Bold") );
            cs.setItalic( aXml.getBoolChildAttrib("Italic") );
            cs.setUnderline( aXml.getBoolChildAttrib("Underline") );
            cs.setStrikeout( aXml.getBoolChildAttrib("Strikeout") );
            cs.setIncludeNickList( aXml.getBoolChildAttrib("IncludeNickList") );
            cs.setCaseSensitive( aXml.getBoolChildAttrib("CaseSensitive") );
            cs.setWholeLine( aXml.getBoolChildAttrib("WholeLine") );
            cs.setWholeWord( aXml.getBoolChildAttrib("WholeWord") );
            cs.setPopup( aXml.getBoolChildAttrib("Popup") );
            cs.setTab( aXml.getBoolChildAttrib("Tab") );
            cs.setPlaySound( aXml.getBoolChildAttrib("PlaySound") );
            cs.setLog( aXml.getBoolChildAttrib("LastLog") );
            cs.setFlashWindow( aXml.getBoolChildAttrib("FlashWindow") );
            cs.setMatchType( aXml.getIntChildAttrib("MatchType") );
            cs.setHasFgColor( aXml.getBoolChildAttrib("HasFgColor") );
            cs.setHasBgColor( aXml.getBoolChildAttrib("HasBgColor") );
            cs.setBgColor( (int)aXml.getLongLongChildAttrib("BgColor") );
            cs.setFgColor( (int)aXml.getLongLongChildAttrib("FgColor") );
            cs.setSoundFile( Text::utf8ToWide( aXml.getChildAttrib("SoundFile") ) );

            colorSettings.push_back(cs);
        }
        aXml.stepOut();
    } else {
        aXml.resetCurrentChild();
    }
}
Exemple #19
0
void IpGuard::save()
{
	Lock l(cs);
	
	SimpleXML xml;
	xml.addTag("IpRanges");
	xml.stepIn();
	for (RangeIter i = ranges.begin(); i != ranges.end(); ++i)
	{
		xml.addTag("Range");
		xml.addChildAttrib("Start", Util::toString(i->start.iIP));
		xml.addChildAttrib("End", Util::toString(i->end.iIP));
		xml.addChildAttrib("Comment", i->name);
	}
	xml.stepOut();
	
	try
	{
		string fname = Util::getPath(Util::PATH_USER_CONFIG) + "IPGuard.xml";
		
		File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE);
		f.write(SimpleXML::utf8Header);
		f.write(xml.toXML());
		f.close();
		File::deleteFile(fname);
		File::renameFile(fname + ".tmp", fname);
	}
	catch (const Exception& e)
	{
		dcdebug("IpGuard::save: %s\n", e.getError().c_str());
	}
}
void HighlightManager::save(SimpleXML& aXml) {
    aXml.addTag("Highlights");
    aXml.stepIn();

    ColorIter iter = colorSettings.begin();
    for(; iter != colorSettings.end(); ++iter) {
        aXml.addTag("Highlight");

        aXml.addChildAttrib("Match", Text::wideToUtf8((*iter).getMatch()));
        aXml.addChildAttrib("Bold", (*iter).getBold());
        aXml.addChildAttrib("Italic", (*iter).getItalic());
        aXml.addChildAttrib("Underline", (*iter).getUnderline());
        aXml.addChildAttrib("Strikeout", (*iter).getStrikeout());
        aXml.addChildAttrib("IncludeNickList", (*iter).getIncludeNickList());
        aXml.addChildAttrib("CaseSensitive", (*iter).getCaseSensitive());
        aXml.addChildAttrib("WholeLine", (*iter).getWholeLine());
        aXml.addChildAttrib("WholeWord", (*iter).getWholeWord());
        aXml.addChildAttrib("Popup", (*iter).getPopup());
        aXml.addChildAttrib("Tab", (*iter).getTab());
        aXml.addChildAttrib("PlaySound", (*iter).getPlaySound());
        aXml.addChildAttrib("LastLog", (*iter).getLog());
        aXml.addChildAttrib("FlashWindow", (*iter).getFlashWindow() );
        aXml.addChildAttrib("MatchType", (*iter).getMatchType());
        aXml.addChildAttrib("HasFgColor", (*iter).getHasFgColor());
        aXml.addChildAttrib("HasBgColor", (*iter).getHasBgColor());
        aXml.addChildAttrib("FgColor", Util::toString((*iter).getFgColor()));
        aXml.addChildAttrib("BgColor", Util::toString((*iter).getBgColor()));
        aXml.addChildAttrib("SoundFile", Text::wideToUtf8((*iter).getSoundFile()));
    }//end for

    aXml.stepOut();
}
Exemple #21
0
	void WebUserManager::on(WebServerManagerListener::LoadSettings, SimpleXML& xml_) noexcept {
		if (xml_.findChild("WebUsers")) {
			xml_.stepIn();
			while (xml_.findChild("WebUser")) {
				const auto& username = xml_.getChildAttrib("Username");
				const auto& password = xml_.getChildAttrib("Password");

				if (username.empty() || password.empty()) {
					continue;
				}

				const auto& permissions = xml_.getChildAttrib("Permissions");

				// Set as admin mainly for compatibility with old accounts if no permissions were found
				auto user = std::make_shared<WebUser>(username, password, permissions.empty());

				user->setLastLogin(xml_.getIntChildAttrib("LastLogin"));
				if (!permissions.empty()) {
					user->setPermissions(permissions);
				}

				users.emplace(username, user);

			}
			xml_.stepOut();
		}

		xml_.resetCurrentChild();
	}
void RawManager::loadActionRaws(SimpleXML& aXml) {
	aXml.resetCurrentChild();
	while(aXml.findChild("Action")) {
		Action* a = NULL;
		try {
			a = addAction(aXml.getIntChildAttrib("ID"), aXml.getChildAttrib("Name"), aXml.getBoolChildAttrib("Enabled"));
		} catch(const Exception&) {
			continue;
		}

		aXml.stepIn();
		while(aXml.findChild("Raw")) {
			try {
				Raw r;
				r.setEnabled(aXml.getBoolChildAttrib("Enabled"));
				r.setId(aXml.getIntChildAttrib("ID"));
				r.setName(aXml.getChildAttrib("Name"));
				r.setRaw(aXml.getChildAttrib("Raw"));
				r.setTime(aXml.getIntChildAttrib("Time"));
				r.setLua(aXml.getBoolChildAttrib("UseLua"));
				addRaw(a, r);
			} catch(const Exception&) {
				// ...
			}
		}
		aXml.stepOut();
	}
}
void IpManager::onIPUpdate(string buf, bool isFailed) {
	if(!isFailed) {
		if(!buf.empty()) {
			try {
				SimpleXML xml;
				xml.fromXML(buf);
				if(xml.findChild("html")) {
					xml.stepIn();
					if(xml.findChild("body")) {
						string x = xml.getChildData().substr(20);
						if(Util::isPrivateIp(x)) {
							SettingsManager::getInstance()->set(SettingsManager::INCOMING_CONNECTIONS, SettingsManager::INCOMING_FIREWALL_PASSIVE);
						}
						SettingsManager::getInstance()->set(SettingsManager::EXTERNAL_IP, x);				
					} else {
						SettingsManager::getInstance()->set(SettingsManager::EXTERNAL_IP, Util::getLocalIp());
					}
				}
			} catch(const SimpleXMLException&) {
				//...
			}
		}
	} else {
		if(!SETTING(NO_IP_OVERRIDE)) {
			if(Util::isPrivateIp(Util::getLocalIp())) {
				SettingsManager::getInstance()->set(SettingsManager::INCOMING_CONNECTIONS, SettingsManager::INCOMING_FIREWALL_PASSIVE);
			}
			SettingsManager::getInstance()->set(SettingsManager::EXTERNAL_IP, Util::getLocalIp());
		}
	}

}
void HighlightManager::save(SimpleXML& aXml){
	aXml.addTag("Highlights");
	aXml.stepIn();

	for(const auto& hl: colorSettings) {
		aXml.addTag("Highlight");
		aXml.addChildAttrib("Context", hl.getContext());
		aXml.addChildAttrib("Match", Text::fromT(hl.getMatch()));
		aXml.addChildAttrib("Bold", hl.getBold());
		aXml.addChildAttrib("Italic", hl.getItalic());
		aXml.addChildAttrib("Underline", hl.getUnderline());
		aXml.addChildAttrib("Strikeout", hl.getStrikeout());
		aXml.addChildAttrib("CaseSensitive", hl.getCaseSensitive());
		aXml.addChildAttrib("WholeLine", hl.getWholeLine());
		aXml.addChildAttrib("WholeWord", hl.getWholeWord());
		aXml.addChildAttrib("Popup", hl.getPopup());
		aXml.addChildAttrib("Tab", hl.getTab());
		aXml.addChildAttrib("PlaySound", hl.getPlaySound());
		//aXml.addChildAttrib("LastLog", hl.getLog());
		aXml.addChildAttrib("FlashWindow", hl.getFlashWindow() );
		aXml.addChildAttrib("MatchType", hl.getMatchType());
		aXml.addChildAttrib("HasFgColor", hl.getHasFgColor());
		aXml.addChildAttrib("HasBgColor", hl.getHasBgColor());
		aXml.addChildAttrib("FgColor", Util::toString(hl.getFgColor()));
		aXml.addChildAttrib("BgColor", Util::toString(hl.getBgColor()));
		aXml.addChildAttrib("SoundFile", hl.getSoundFile());
		aXml.addChildAttrib("MatchColumn", hl.getMatchColumn());
	}//end for

	aXml.stepOut();
}
void RSSManager::load(SimpleXML& aXml)
{
	{
		CFlyLock(g_csFeed);
		aXml.resetCurrentChild();
		if (aXml.findChild("Rss"))
		{
			aXml.stepIn();
			while (aXml.findChild("Feed"))
			{
				const string& realURL = aXml.getChildData();
				if (realURL.empty())
				{
					continue;
				}
				const string& sourceName = aXml.getChildAttrib("Name");
				const string& codeingType = aXml.getChildAttrib("Codeing");
				
				const size_t iCodeingType = Util::toInt(codeingType);
				
				// add only unique RSS feeds
				addNewFeed(realURL, sourceName, getCodeing(iCodeingType));
			}
			aXml.stepOut();
		}
	}
	updateFeeds();
}
void IgnoreManager::load(SimpleXML& aXml) {
	if(aXml.findChild("IgnoreList")) {
		aXml.stepIn();
		while(aXml.findChild("User")) {	
			ignoredUsers.insert(Text::toT(aXml.getChildAttrib("Nick")));
		}
		aXml.stepOut();
	}
}
void IpManager::WatchSave() {
	Lock l(cs);
	try {
		SimpleXML xml;

		xml.addTag("IPWatch");
		xml.stepIn();
		{
			xml.addTag("IPWatch");
			xml.stepIn();
			{
				for(IPWatch::Iter i = ipwatch.begin(); i != ipwatch.end(); ++i) {
					xml.addTag("IPWatch");
					xml.addChildAttrib("Mode", (*i)->getMode());
					xml.addChildAttrib("Pattern", (*i)->getPattern());
					xml.addChildAttrib("Task", (*i)->getTask());
					xml.addChildAttrib("Action", (*i)->getAction());
					xml.addChildAttrib("DisplayCheat", (*i)->getDisplayCheat());
					xml.addChildAttrib("Cheat", (*i)->getCheat());
					xml.addChildAttrib("MatchType", (*i)->getMatchType());
					xml.addChildAttrib("ISP", (*i)->getIsp());
				}
			}
			xml.stepOut();
			xml.addTag("RevisionInfo");
			xml.stepIn();
			{
				xml.addTag("Version", getIpWatchVersion());
			}
			xml.stepOut();
		}
		xml.stepOut();

		string fname = Util::getPath(Util::PATH_USER_CONFIG) + "IPWatch.xml";
		File f(fname + ".tmp", File::WRITE, File::CREATE | File::TRUNCATE);
		f.write(SimpleXML::utf8Header);
		f.write(xml.toXML());
		f.close();
		File::deleteFile(fname);
		File::renameFile(fname + ".tmp", fname);
	} catch(const Exception& e) {
		dcdebug("IpManager::WatchSave: %s\n", e.getError().c_str());
	}
}
void HighlightManager::load(SimpleXML& aXml){
	aXml.resetCurrentChild();

	if(aXml.findChild("Highlights")) {
		aXml.stepIn();
		while(aXml.findChild("Highlight")) {
			try{
				ColorSettings cs;
				cs.setContext(aXml.getIntChildAttrib("Context"));
				cs.setMatch( Text::utf8ToWide( aXml.getChildAttrib("Match") ) );
				cs.setBold(	aXml.getBoolChildAttrib("Bold") );
				cs.setItalic( aXml.getBoolChildAttrib("Italic") );
				cs.setUnderline( aXml.getBoolChildAttrib("Underline") );
				cs.setStrikeout( aXml.getBoolChildAttrib("Strikeout") );
				//Convert old setting to correct context
				if(aXml.getBoolChildAttrib("IncludeNickList") == true)
					cs.setContext(CONTEXT_NICKLIST);
				cs.setCaseSensitive( aXml.getBoolChildAttrib("CaseSensitive") );
				cs.setWholeLine( aXml.getBoolChildAttrib("WholeLine") );
				cs.setWholeWord( aXml.getBoolChildAttrib("WholeWord") );
				cs.setPopup( aXml.getBoolChildAttrib("Popup") );
				cs.setTab( aXml.getBoolChildAttrib("Tab") );
				cs.setPlaySound( aXml.getBoolChildAttrib("PlaySound") );
				//cs.setLog( aXml.getBoolChildAttrib("LastLog") );
				cs.setFlashWindow( aXml.getBoolChildAttrib("FlashWindow") );
				cs.setMatchType( aXml.getIntChildAttrib("MatchType") );
				cs.setHasFgColor( aXml.getBoolChildAttrib("HasFgColor") );
				cs.setHasBgColor( aXml.getBoolChildAttrib("HasBgColor") );
				cs.setBgColor( (int)aXml.getLongLongChildAttrib("BgColor") );
				cs.setFgColor( (int)aXml.getLongLongChildAttrib("FgColor") );
				cs.setSoundFile( Text::utf8ToWide( aXml.getChildAttrib("SoundFile") ) );
				cs.setMatchColumn(aXml.getIntChildAttrib("MatchColumn"));

				cs.setRegexp();
				colorSettings.push_back(cs);
			}catch(...) { }
		}
		aXml.stepOut();
	} else {
		aXml.resetCurrentChild();
	}
	//convert the old setting to highlights
	if(!SETTING(HIGHLIGHT_LIST).empty()) {
		ColorSettings cs;
		cs.setContext(CONTEXT_FILELIST);
		cs.setMatch(Text::toT(SETTING(HIGHLIGHT_LIST)));
		cs.setHasFgColor(true);
		cs.setFgColor( SETTING(LIST_HL_COLOR) );
		cs.setHasBgColor(true);
		cs.setBgColor( SETTING(LIST_HL_BG_COLOR) );
		SettingsManager::getInstance()->set(SettingsManager::HIGHLIGHT_LIST, "");
		SettingsManager::getInstance()->set(SettingsManager::USE_HIGHLIGHT, true);
		colorSettings.push_back(cs);
	}

}
void ResourceManager::loadLanguage(const string& aFile) {
	try {
		File f(aFile, File::READ, File::OPEN, File::BUFFER_SEQUENTIAL, false);
		SimpleXML xml;
		xml.fromXML(f.read());

		unordered_map<string, int> h;
		
		for(int i = 0; i < LAST; ++i) {
			h[names[i]] = i;
		}

		string childName = "String";
		string attribName = "Name";
		if (xml.findChild("Language")) {
			rtl = xml.getBoolChildAttrib("RightToLeft");

			xml.stepIn();
			if (xml.findChild("Strings")) {
				xml.stepIn();
			}
		} else {
			xml.resetCurrentChild();
			if (xml.findChild("resources")) {
				xml.stepIn();
				childName = "string";
				attribName = "name";
			} else {
				throw Exception("Invalid format");
			}
		}

		while (xml.findChild(childName)) {
			const auto j = h.find(xml.getChildAttrib(attribName));
			if(j != h.end()) {
				strings[j->second] = xml.getChildData();
			}
		}
		createWide();
	} catch(const Exception& e) {
		LogManager::getInstance()->message("Failed to load the language file " + aFile + ": " + e.getError(), LogManager::LOG_ERROR);
	}
}
void RawManager::on(SettingsManagerListener::Save, SimpleXML& xml) throw() {
	xml.addTag("ADLSPoints");
	xml.stepIn();
	for(IntMap::const_iterator i = points.begin(); i != points.end(); ++i) {
		xml.addTag("PointsSetting");
		xml.addChildAttrib("Points", i->first);
		xml.addChildAttrib("Action", i->second);
	}
	xml.stepOut();
}