RSSFeed::RssFormat RSSFeed::DetectRSSFormat(void* data, RSSParser parser) { if (parser == XML_PARSER) { XMLParser::XMLNode* rootNode = reinterpret_cast<XMLParser::XMLNode*>(data); if (rootNode != nullptr) { // Start Detection XMLParser::XMLNode rssNode = rootNode->getChildNode("rss"); if (!rssNode.isEmpty()) { return RSS_2_0; } XMLParser::XMLNode atomNode = rootNode->getChildNode("feed"); if (!atomNode.isEmpty()) { return RSS_ATOM; } } } else if (parser == XML_SIMPLE) { SimpleXML* xml = reinterpret_cast<SimpleXML*>(data); if (xml != nullptr) { if (xml->findChild("rss")) return RSS_2_0; if (xml->findChild("feed")) return RSS_ATOM; } } return RSS_2_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(); }
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&) { // ... } }
/* * 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(); } }
void ServerConfig::save(SimpleXML& xml_, const string& aTagName) noexcept { if (!hasValidConfig()) { return; } xml_.addTag(aTagName); xml_.addChildAttrib("Port", port); }
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 IgnoreManager::save(SimpleXML& aXml) { aXml.addTag("IgnoreList"); aXml.stepIn(); for(TStringHashIterC i = ignoredUsers.begin(); i != ignoredUsers.end(); ++i) { aXml.addTag("User"); aXml.addChildAttrib("Nick", Text::fromT(*i)); } aXml.stepOut(); }
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 ShareManager::save(SimpleXML& aXml) { Lock l(cs); aXml.addTag("Share"); aXml.stepIn(); for(auto& i: shares) { aXml.addTag("Directory", i.first); aXml.addChildAttrib("Virtual", i.second); } aXml.stepOut(); }
void IpManager::WatchLoad() { try { SimpleXML xml; xml.fromXML(File(Util::getPath(Util::PATH_USER_CONFIG) + "IPWatch.xml", File::READ, File::OPEN).read()); if(xml.findChild("IPWatch")) { xml.stepIn(); loadWatch(xml); xml.stepOut(); } } catch(const Exception& e) { dcdebug("IpManager::WatchLoad: %s\n", e.getError().c_str()); } }
void HubSettings::load(SimpleXML& xml) { for(uint8_t i = 0; i < StringCount; ++i) { strings[i] = xml.getChildAttrib(stringNames[i]); } for(uint8_t i = 0; i < BoolCount; ++i) { bools[i] = to3boolXml(xml.getIntChildAttrib(boolNames[i])); } for(uint8_t i = 0; i < IntCount; ++i) { auto tmp = xml.getChildAttrib(intNames[i]); if (!tmp.empty()) ints[i] = Util::toInt(tmp); } }
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 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 RawManager::loadActionRaws() { try { SimpleXML xml; xml.fromXML(File(Util::getPath(Util::PATH_USER_CONFIG) + "Raws.xml", File::READ, File::OPEN).read()); if(xml.findChild("ActionRaws")) { xml.stepIn(); loadActionRaws(xml); xml.stepOut(); } } catch(const Exception& e) { dcdebug("RawManager::loadActionRaws: %s\n", e.getError().c_str()); } }
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 ClientProfileManager::loadClientProfiles() { try { SimpleXML xml; xml.fromXML(File(Util::getConfigPath() + "Profiles.xml", File::READ, File::OPEN).read()); if(xml.findChild("Profiles")) { xml.stepIn(); loadClientProfiles(&xml); xml.stepOut(); } } catch(const Exception& e) { dcdebug("FavoriteManager::loadClientProfiles: %s\n", e.getError().c_str()); } }
bool CAGEmotionSetup::LoadEmotion(const string& p_file_name) { const string l_fileName = Util::getDataPath() + "EmoPacks\\" + p_file_name + ".xml"; if ((p_file_name == "Disabled") || !Util::fileExists(l_fileName)) { return true; } try { SimpleXML xml; xml.fromXML(File(l_fileName, File::READ, File::OPEN).read()); if (xml.findChild("Emoticons")) { xml.stepIn(); while (xml.findChild("Emoticon")) { string strEmotionText = xml.getChildAttrib("PasteText"); if (strEmotionText.empty()) { strEmotionText = xml.getChildAttrib("Expression"); } while (strEmotionText[0] == ' ') // ltrim strEmotionText.erase(0, 1); if (!strEmotionText.empty()) { // dcdebug("CAGEmotionSetup::Create: emotion:[%s]\n", Text::fromT(strEmotionText).c_str()); if (m_FilterEmotiion.count(strEmotionText)) { // dcdebug("CAGEmotionSetup::Create: dup emotion:[%s]\n", strEmotionText.c_str()); continue; } m_FilterEmotiion.insert(strEmotionText); string strEmotionBmpPath = xml.getChildAttrib("Bitmap"); if (strEmotionBmpPath.size() > 0) { if (strEmotionBmpPath[0] == '.') { // Relativni cesta - dame od aplikace strEmotionBmpPath = Util::getDataPath() + "EmoPacks\\" + strEmotionBmpPath; } else strEmotionBmpPath = "EmoPacks\\" + strEmotionBmpPath; } CAGEmotion* pEmotion = new CAGEmotion(); //[!]PPA for lock bmp //File* l__f = new File (Util::getDataPath() + strEmotionBmpPath, File::READ, File::OPEN); if (!pEmotion->Create(Text::toT(strEmotionText), strEmotionBmpPath)) { delete pEmotion; continue; } m_CountSelEmotions++; EmotionsList.push_back(pEmotion); } } xml.stepOut(); } } catch(const Exception& e) { dcdebug("CAGEmotionSetup::Create: %s\n", e.getError().c_str()); return false; } return true; }
void HubSettings::save(SimpleXML& xml) const { for(uint8_t i = 0; i < StringCount; ++i) { if(defined(strings[i])) { xml.addChildAttrib(stringNames[i], strings[i]); } } for(uint8_t i = 0; i < BoolCount; ++i) { if(defined(bools[i])) { xml.addChildAttrib(boolNames[i], toIntXml(bools[i])); } } for(uint8_t i = 0; i < IntCount; ++i) { if(defined(ints[i])) { xml.addChildAttrib(intNames[i], ints[i]); } } }
void MessageManager::load(SimpleXML& aXml) { if (aXml.findChild("ChatFilterItems")) { aXml.stepIn(); while (aXml.findChild("ChatFilterItem")) { WLock l(Ignorecs); ChatFilterItems.push_back(ChatFilterItem(aXml.getChildAttrib("Nick"), aXml.getChildAttrib("Text"), (StringMatch::Method)aXml.getIntChildAttrib("NickMethod"), (StringMatch::Method)aXml.getIntChildAttrib("TextMethod"), aXml.getBoolChildAttrib("MC"), aXml.getBoolChildAttrib("PM"), aXml.getBoolChildAttrib("Enabled"))); } aXml.stepOut(); } loadUsers(); }
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 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 DetectNetworkSetupThread::on(Complete, HttpConnection*, const string&) throw() { debug_log(AUTODETECT, "parsing response {%s}", m_buffer.c_str()); try { SimpleXML xml; xml.fromXML(m_buffer); if (xml.findChild("response")) { debug_log(AUTODETECT, "found <response>"); xml.stepIn(); if (xml.findChild("mode")) { string mode = xml.getChildData(); info_log(AUTODETECT, "mode={%s}", mode.c_str()); xml.resetCurrentChild(); string address; if (xml.findChild("address")) { string address = xml.getChildData(); info_log(AUTODETECT, "address={%s}", address.c_str()); if (!address.empty()) { SettingsManager::getInstance()->set(SettingsManager::EXTERNAL_IP, address); } } else { warn_log(AUTODETECT, "<address> not found"); } debug_log(AUTODETECT, "local address={%s}", connection.m_localIp.c_str()); if (Util::stricmp(mode, "active") == 0) { SettingsManager::getInstance()->set(SettingsManager::INCOMING_CONNECTIONS, SettingsManager::INCOMING_FIREWALL_NAT); debug_log(AUTODETECT, "setting ACTIVE mode"); } else if (Util::stricmp(mode, "passive") == 0) { SettingsManager::getInstance()->set(SettingsManager::INCOMING_CONNECTIONS, SettingsManager::INCOMING_FIREWALL_PASSIVE); } else { throw Exception("Wrong mode '" + mode + "'"); } } else { warn_log(AUTODETECT, "<mode> not found"); } } else { warn_log(AUTODETECT, "<response> not found"); } } catch (const Exception &e) { error_log(AUTODETECT, "Error parsing response: %s", e.getError().c_str()); } finalize(); }
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()); } } }
/** * \brief read this NegativeBinomial distribution from the provided XML object * \throws DistributionException if the XML object does not define the mean * and alpha tags * \todo throw exception if root tag is incorrectly named */ void ZeroTruncatedPoisson::load(const SimpleXML& xml) { vector<SimpleXML> meanX = xml.getChildren("lambda"); if (meanX.size() != 1) { stringstream ss; ss << "loading zero-truncated Poisson from XML object " << endl << xml.toString() << endl << " failed. Reason: expected a single child " << "tag of type <mean> -- didn't find it"; throw DistributionException(ss.str()); } std::stringstream ss1, ss2; ss1 << meanX[0].getData(); ss1 >> this->lambda; if (!(isfinite(this->lambda))) { stringstream ss; ss << "Loading zero-truncated Poisson failed. Reason: " << "got non-finite value for lambda"; throw DistributionException(ss.str()); } }
bool IpGuard::load() { if (noSave) { Lock l(cs); noSave = false; try { SimpleXML xml; xml.fromXML(File(Util::getPath(Util::PATH_USER_CONFIG) + "IPGuard.xml", File::READ, File::OPEN).read()); if (xml.findChild("IpRanges")) { xml.stepIn(); while (xml.findChild("Range")) { uint32_t start = Util::toUInt32(xml.getChildAttrib("Start")); uint32_t end = Util::toUInt32(xml.getChildAttrib("End")); ranges.push_front(range(++lastRange, xml.getChildAttrib("Comment"), ip(std::min(start, end)), ip(std::max(start, end)))); } xml.resetCurrentChild(); xml.stepOut(); } } catch (const Exception& e) { dcdebug("IpGuard::load: %s\n", e.getError().c_str()); } // Optimize ranges ranges.sort(); ranges.unique(merger); return true; } return false; }
void WebShortcuts::save(SimpleXML& xml) { xml.addTag("WebShortcuts"); xml.stepIn(); for(auto i: list) { xml.addTag("WebShortcut"); xml.addChildAttrib("Name", i->name); xml.addChildAttrib("Key", i->key); xml.addChildAttrib("URL", i->url); xml.addChildAttrib("Clean", i->clean); } xml.stepOut(); }
void EmoticonsManager::Load() { setUseEmoticons(false); if((SETTING(EMOTICONS_FILE) == "Disabled") || !Util::fileExists(Util::getPath(Util::PATH_EMOPACKS) + SETTING(EMOTICONS_FILE) + ".xml" )) { return; } try { SimpleXML xml; xml.fromXML(File(Util::getPath(Util::PATH_EMOPACKS) + SETTING(EMOTICONS_FILE) + ".xml", File::READ, File::OPEN).read()); if(xml.findChild("Emoticons")) { xml.stepIn(); while(xml.findChild("Emoticon")) { tstring strEmotionText = Text::toT(xml.getChildAttrib("PasteText")); if (strEmotionText.empty()) { strEmotionText = Text::toT(xml.getChildAttrib("Expression")); } string strEmotionBmpPath = xml.getChildAttrib("Bitmap"); if (!strEmotionBmpPath.empty()) { if (strEmotionBmpPath[0] == '.') { // change relative path strEmotionBmpPath = Util::getPath(Util::PATH_EMOPACKS) + strEmotionBmpPath; } else { strEmotionBmpPath = "EmoPacks\\" + strEmotionBmpPath; } } emoticons.push_back(new Emoticon(strEmotionText, strEmotionBmpPath)); } xml.stepOut(); } } catch(const Exception& e) { dcdebug("EmoticonsManager::Create: %s\n", e.getError().c_str()); return; } setUseEmoticons(true); }
bool RSSFeed::UpdateFeedOldParser(const string& data) { clearNewsList(); SimpleXML xml; try { xml.fromXML(data); xml.resetCurrentChild(); const RssFormat rssFormat = DetectRSSFormat(&xml, XML_SIMPLE); switch (rssFormat) { case RSS_2_0: return ProcessRSS(&xml, XML_SIMPLE, true); case RSS_ATOM: return ProcessAtom(&xml, XML_SIMPLE, true); } } catch (SimpleXMLException& /*ex*/) { } return false; }
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(); }
void ToolbarManager::save(SimpleXML& aXml) { aXml.addTag("Rebars"); aXml.stepIn(); for(ToolbarEntry::Iter i = toolbarEntries.begin(); i != toolbarEntries.end(); ++i) { aXml.addTag("Rebar"); aXml.addChildAttrib("Name", (*i)->getName()); aXml.addChildAttrib("ID", (*i)->getID()); aXml.addChildAttrib("CX", (*i)->getCX()); aXml.addChildAttrib("BreakLine", (*i)->getBreakLine()); aXml.addChildAttrib("BandCount", (*i)->getBandCount()); } aXml.stepOut(); }