std::map<std::string, uint8_t>* Node::attributesNamesAndTypes() { std::map<std::string, uint8_t>* result; Attributes* attr; Attributes::iterator attrit; result = NULL; attr = NULL; if ((result = new std::map<std::string, uint8_t>) != NULL) { if ((attr = this->attributes()) != NULL) { for (attrit = attr->begin(); attrit != attr->end(); attrit++) { if (attrit->second != NULL) { result->insert(std::pair<std::string, uint8_t>(attrit->first, attrit->second->type())); this->attributesNamesAndTypesFromVariant(attrit->second, result, attrit->first); delete attrit->second; } } delete attr; } } return result; }
bool ManageConfig::loadCacheConfig(Element * root_element) { if (NULL == root_element) { std::cout << ("The root element is NULL\n"); return false; } Element * cache_ele = root_element->get_element("hash-cache"); if (NULL == cache_ele) { std::cout << ("Failed to get hash-cache element\n"); return false; } Elements cache_list = cache_ele->get_elements(); for (Elements::iterator cache_it = cache_list.begin(); cache_it != cache_list.end(); ++cache_it) { CacheConfig cache_cfg; Attributes attrs = (*cache_it)->get_attributes(); for (Attributes::iterator it = attrs.begin(); it != attrs.end(); ++it) { Attribute * attr = *it; if (attr->get_name() == "ip") { cache_cfg.ip = attr->as_cstr(); } } m_cache_cfg.push_back(cache_cfg); } return true; }
bool ManageConfig::loadUnlawfulInfo(Element * root_element) { if (NULL == root_element) { std::cout << ("The root element is NULL\n"); return false; } Element * unlawfulWord_ele = root_element->get_element("unlawfulWord"); if (NULL == unlawfulWord_ele) { std::cout << ("Failed to get sql element\n"); return false; } Attributes attrs = unlawfulWord_ele->get_attributes(); for (Attributes::iterator it = attrs.begin(); it != attrs.end(); ++it) { Attribute * attr = *it; if (attr->get_name() == "file") { m_unlawful_file = attr->as_cstr(); } } return true; }
Attributes* Node::attributesByType(uint8_t type, attributeNameType tname) { Attributes* attr; Attributes* result; Attributes::iterator attrit; Variant* vptr; result = NULL; attr = NULL; if ((result = new Attributes) != NULL) { if ((attr = this->attributes()) != NULL) { for (attrit = attr->begin(); attrit != attr->end(); attrit++) { vptr = new Variant(attrit->second); result->insert(std::pair<std::string, Variant*>(attrit->first, vptr)); if (tname == ABSOLUTE_ATTR_NAME) this->attributesByTypeFromVariant(attrit->second, type, result, attrit->first); else this->attributesByTypeFromVariant(attrit->second, type, result); delete attrit->second; } delete attr; } } return result; }
void Node::attributesNamesFromVariant(Variant* variant, std::list<std::string > *names, std::string current) { if (!(variant)) return ; if (variant->type() == typeId::List) { std::list<Variant*> lvariant = variant->value<std::list< Variant*> >(); std::list<Variant*>::iterator it = lvariant.begin(); for (; it != lvariant.end(); it++) this->attributesNamesFromVariant((*it), names, current); } else if (variant->type() == typeId::Map) { Attributes mvariant = variant->value<Attributes >(); Attributes::iterator it = mvariant.begin(); std::string abs; for (; it != mvariant.end(); it++) { if (current.empty()) abs = it->first; else abs = current + '.' + it->first; names->push_back(abs); this->attributesNamesFromVariant(it->second, names, abs); } } }
std::list<std::string>* Node::attributesNames(attributeNameType tname) { std::list<std::string>* result; Attributes* attr; Attributes::iterator attrit; attr = NULL; result = NULL; if ((result = new std::list<std::string>) != NULL) { if ((attr = this->attributes()) != NULL) { for (attrit = attr->begin(); attrit != attr->end(); attrit++) { result->push_back(attrit->first); if (tname == ABSOLUTE_ATTR_NAME) this->attributesNamesFromVariant(attrit->second, result, attrit->first); else this->attributesNamesFromVariant(attrit->second, result); delete attrit->second; } delete attr; } } return (result); }
void Node::attributesByTypeFromVariant(Variant* variant, uint8_t type, Attributes* result, std::string current) { if (!(variant)) return ; if (variant->type() == typeId::List) { std::list<Variant*> lvariant = variant->value<std::list< Variant*> >(); std::list<Variant*>::iterator it = lvariant.begin(); for (; it != lvariant.end(); it++) this->attributesByTypeFromVariant((*it), type, result, current); } else if (variant->type() == typeId::Map) { Attributes mvariant = variant->value<Attributes >(); Attributes::iterator it = mvariant.begin(); std::string abs; for (; it != mvariant.end(); it++) { if (current.empty()) abs = (*it).first; else abs = current + '.' + (*it).first; if (it->second->type() == type) result->insert(std::pair<std::string, Variant*>(abs, new Variant(it->second))); else this->attributesByTypeFromVariant(it->second, type, result, abs); } } }
bool ManageConfig::loadLogsysInfo(Element * root_element) { if (NULL == root_element) { std::cout << ("The root element is NULL\n"); return false; } Element * logsys_ele = root_element->get_element("logsys"); if (NULL == logsys_ele) { std::cout << ("Failed to get hash-cache element\n"); return false; } Attributes attrs = logsys_ele->get_attributes(); for (Attributes::iterator it = attrs.begin(); it != attrs.end(); ++it) { Attribute * attr = *it; if (attr->get_name() == "ip") { m_logsys_cfg.ip = attr->as_cstr(); } else if (attr->get_name() == "port") { m_logsys_cfg.port = attr->as_cstr(); } } return true; }
void Node::attributesByTypeFromVariant(Variant* variant, uint8_t type, Attributes* result) { Variant* vptr; if (!(variant)) return ; if (variant->type() == typeId::List) { std::list<Variant*> lvariant = variant->value<std::list< Variant*> >(); std::list<Variant*>::iterator it = lvariant.begin(); for (; it != lvariant.end(); it++) this->attributesByTypeFromVariant((*it), type, result); } else if (variant->type() == typeId::Map) { Attributes mvariant = variant->value<Attributes >(); Attributes::iterator it = mvariant.begin(); for (; it != mvariant.end(); it++) { if (it->second->type() == type) { if (result->find(it->first) == result->end()) { vptr = new Variant(it->second); result->insert(std::pair<std::string, Variant*>(it->first, vptr)); } else ;//XXX, we have to find a way to manage same attributes naming at different level. At the moment, this condition is to avoid memleak } else this->attributesByTypeFromVariant(it->second, type, result); } } }
bool ManageConfig::loadGUIDAddr(Element * root_element) { if (NULL == root_element) { std::cout << ("The root element is NULL\n"); return false; } Element * guid_ele = root_element->get_element("guid"); if (NULL == guid_ele) { std::cout << ("Failed to get sql element\n"); return false; } Attributes attrs = guid_ele->get_attributes(); for (Attributes::iterator it = attrs.begin(); it != attrs.end(); ++it) { Attribute * attr = *it; if (attr->get_name() == "addr") { m_guid_addr = attr->as_cstr(); } } return true; }
SAXParser::Handler::Status HandlerPeak::startElement(const string& name, const Attributes& attributes, stream_offset position) { if (!peak) throw runtime_error("[PeakData::HandlerPeak::startElement()] Null peak."); if (name == "peak") { for (Attributes::attribute_list::const_iterator it=attributes.begin(); it!=attributes.end(); ++it) { if (it->matchName("id")) peak->id = lexical_cast<int>(it->getValue()); else if (it->matchName("mz")) peak->mz = lexical_cast<double>(it->getValue(NoXMLUnescape)); else if (it->matchName("retentionTime")) peak->retentionTime = lexical_cast<double>(it->getValue(NoXMLUnescape)); else if (it->matchName("intensity")) peak->intensity = lexical_cast<double>(it->getValue(NoXMLUnescape)); else if (it->matchName("area")) peak->area = lexical_cast<double>(it->getValue(NoXMLUnescape)); else if (it->matchName("error")) peak->error = lexical_cast<double>(it->getValue(NoXMLUnescape)); else { Peak::Attribute a = stringToAttribute(it->getName()); peak->attributes[a] = lexical_cast<double>(it->getValue(NoXMLUnescape)); } } return Status::Ok; } else if (name == "data") { return Status::Ok; } throw runtime_error(("[HandlerPeak] Unexpected element name: " + name).c_str()); }
AttributeIterator findAttribute(Attributes& attributes, const std::string& name) { CAF_CM_STATIC_FUNC_VALIDATE("MarkupParser", "findAttribute"); CAF_CM_VALIDATE_STRING(name); return std::find_if(attributes.begin(), attributes.end(), std::bind2nd(AttributeName(), name)); }
void Node::__compatibleModulesByType(const std::map<std::string, Constant*>& cmime, Attributes& dtypes, std::list<std::string>* result) { std::map<std::string, Constant*>::const_iterator cit; list<Variant*> lvalues; list<Variant*>::iterator lit; Attributes::iterator dit; bool match; for (cit = cmime.begin(); cit != cmime.end(); cit++) { match = false; if ((cit->second != NULL) && (cit->second->type() == typeId::String)) { lvalues = cit->second->values(); lit = lvalues.begin(); while (lit != lvalues.end() && !match) { dit = dtypes.begin(); while (dit != dtypes.end() && !match) { std::string cval = (*lit)->value<std::string>(); if ((dit->second != NULL) && (dit->second->type() == typeId::String) && (dit->second->value<std::string>().find(cval) != std::string::npos)) { match = true; result->push_back(cit->first); } dit++; } lit++; } } } }
/** * Function: Show_attributes * * Display both the key and value for an Attributes map. * * Since this is a non-critical message, it is only shown when the debug value * is set high enough. * * Parameter: attributes Defined as std::map<std::string, std::string> pair. * Most commonly found in data as a "name = value" pair. */ void Show_attributes(std::ostream& os, Attributes& attributes) { Monday_out(VERBOSE_LEVEL2, os, "- Num attributes: %d\n", attributes.size()); for(Attributes::iterator i = attributes.begin(); i != attributes.end(); ++i) { Monday_out(VERBOSE_LEVEL2, os, " \"%s\" = \"%s\"\n", i->first.c_str(), i->second.c_str()); } }
void AttributesParserTest::testParser1() { Attributes attrs; std::istringstream istr(""); AttributesParser parser(attrs, istr); parser.parse(); assert (attrs.begin() == attrs.end()); }
virtual Status startElement(const string& name, const Attributes& attributes, stream_offset position) { os_ << "[0x" << hex << position << "] startElement: " << name; for_each(attributes.begin(), attributes.end(), PrintAttribute(os_)); os_ << endl; return Status::Ok; };
void Writer::writeAttributes(const Attributes& attributes) { XML::Attributes::const_iterator it = attributes.begin(); XML::Attributes::const_iterator end = attributes.end(); for (; it != end; ++it) { m_buffer += Core::fmt(TXT(" %s=\"%s\""), (*it)->name().c_str(), (*it)->value().c_str()); } }
bool Node::isCompatibleModule(string modname) { ConfigManager* cm; Config* conf; Constant* constant; std::list<Variant*> values; std::list<Variant*>::iterator it; bool compat; compat = false; if (((cm = ConfigManager::Get()) != NULL) && ((conf = cm->configByName(modname)) != NULL)) { Attributes dtypes; Variant* vptr; std::string ext; vptr = this->dataType(); ext = this->extension(); if (vptr != NULL && ((constant = conf->constantByName("mime-type")) != NULL)) { dtypes = vptr->value<Attributes >(); values = constant->values(); for (Attributes::iterator mit = dtypes.begin(); mit != dtypes.end(); mit++) { if (mit->second->type() == typeId::String) { std::string dtype = mit->second->value<std::string>(); it = values.begin(); while (it != values.end() && !compat) { if ((*it)->type() == typeId::String && dtype.find((*it)->value<std::string>()) != std::string::npos) compat = true; it++; } } } delete vptr; } if (!ext.empty() && !compat && ((constant = conf->constantByName("extension-type")) != NULL)) { values = constant->values(); it = values.begin(); while (it != values.end() && !compat) { if ((*it)->type() == typeId::String && (*it)->value<std::string>().find(ext) != std::string::npos) compat = true; it++; } } } return compat; }
inline void write_all_attributes(Attributes attributes, const std::string& name, std::ostream& out) { typename Attributes::const_iterator i = attributes.begin(), end = attributes.end(); if (i != end) { out << name << " [\n"; write_attributes(attributes, out); out << "];\n"; } }
bool ManageConfig::loadAccountSQLCfg(Element * root_element) { if (NULL == root_element) { std::cout << "The root element is NULL\n"; return false; } Element * sql_ele = root_element->get_element("account-sql"); if (NULL == sql_ele) { std::cout << ("Failed to get sql element\n"); return false; } Attributes attrs = sql_ele->get_attributes(); for (Attributes::iterator it = attrs.begin(); it != attrs.end(); ++it) { Attribute * attr = *it; if (attr->get_name() == "serverIP") { m_account_sql_cfg.server_ip = attr->as_cstr(); } else if (attr->get_name() == "databaseName") { m_account_sql_cfg.database_name = attr->as_cstr(); } else if (attr->get_name() == "userName") { m_account_sql_cfg.user_name = attr->as_cstr(); } else if (attr->get_name() == "password") { m_account_sql_cfg.password = attr->as_cstr(); } else if (attr->get_name() == "port") { m_account_sql_cfg.port = attr->as_int(); } else if (attr->get_name() == "connPoolNumber") { m_account_sql_cfg.pool_number = attr->as_int(); } else if (attr->get_name() == "pingMYSQLInterval") { m_account_sql_cfg.ping_MYSQL_interval = attr->as_int(); } } return true; }
bool ManageRoundomName::loadNameCfg(Element * root_ele) { if (NULL == root_ele) { return false; } string attr_name_name = "xing"; string attr_female_name = "female"; string attr_male_name = "male"; Elements eles = root_ele->get_elements(); for (Elements::iterator it = eles.begin(); it != eles.end(); ++it) { Attributes attrs = (*it)->get_attributes(); for (Attributes::iterator attr_it = attrs.begin(); attr_it != attrs.end(); ++attr_it) { Attribute * attr = *attr_it; if (attr->get_name() == attr_name_name) { if (attr->get_value().length() > 0) { m_random_name_info.surname.push_back(attr->get_value()); } } else if (attr->get_name() == attr_female_name) { if (attr->get_value().length() > 0) { m_random_name_info.female_name.push_back(attr->get_value()); } } else if (attr->get_name() == attr_male_name) { if (attr->get_value().length() > 0) { m_random_name_info.male_name.push_back(attr->get_value()); } } } } return true; }
void XMLWriter::Impl::startElement(const string& name, const Attributes& attributes, EmptyElementTag emptyElementTag) { ostream* os = &os_; if (config_.outputObserver) os = new ostringstream; if (!style(StyleFlag_InlineOuter)) *os << indentation(); *os << "<" << name; string attributeIndentation(name.size()+1, ' '); for (Attributes::const_iterator it=attributes.begin(); it!=attributes.end(); ++it) { *os << " " << it->first << "=\""; writeEscapedAttributeXML(*os, it->second); *os << "\""; if (style(StyleFlag_AttributesOnMultipleLines) && (it+1)!=attributes.end()) *os << "\n" << indentation() << attributeIndentation; } *os << (emptyElementTag==EmptyElement ? "/>" : ">"); if (!style(StyleFlag_InlineInner) || !style(StyleFlag_InlineOuter) && emptyElementTag==EmptyElement) *os << "\n"; if (emptyElementTag == NotEmptyElement) elementStack_.push(name); if (config_.outputObserver) { config_.outputObserver->update(static_cast<ostringstream*>(os)->str()); os_ << static_cast<ostringstream*>(os)->str(); delete os; } }
bool ManageConfig::loadGateCfg(Element * root_element) { if (NULL == root_element) { std::cout << ("The root element is NULL\n"); return false; } Element * gates_ele = root_element->get_element("gates"); if (NULL == gates_ele) { std::cout << ("Failed to get gates element\n"); return false; } Elements gate_list = gates_ele->get_elements(); for (Elements::iterator gate_it = gate_list.begin(); gate_it != gate_list.end(); ++gate_it) { GateCfg gate_cfg; Attributes attrs = (*gate_it)->get_attributes(); for (Attributes::iterator it = attrs.begin(); it != attrs.end(); ++it) { Attribute * attr = *it; if (attr->get_name() == "ip") { gate_cfg.ip = attr->as_cstr(); } else if (attr->get_name() == "port") { gate_cfg.port = attr->as_int(); } } m_gate_cfg.push_back(gate_cfg); } return true; }
void Node::attributesByNameFromVariant(Variant* variant, std::string name, std::list<Variant*>* result) { if (!(variant)) return ; if (variant->type() == typeId::List) { std::list<Variant*> lvariant = variant->value<std::list< Variant*> >(); std::list<Variant*>::iterator it = lvariant.begin(); for (; it != lvariant.end(); it++) this->attributesByNameFromVariant((*it), name, result); } else if (variant->type() == typeId::Map) { Attributes mvariant = variant->value<Attributes >(); Attributes::iterator it = mvariant.begin(); for (; it != mvariant.end(); it++) { if (it->first == name) result->push_back(new Variant(it->second)); else this->attributesByNameFromVariant(it->second, name, result); } } }
Variant* Node::attributesByName(std::string name, attributeNameType tname) { Attributes* attr; Variant* result; std::list<Variant*>* vlist; Attributes::iterator attrit; Variant* vptr; result = NULL; attr = NULL; vlist = NULL; vptr = NULL; if ((attr = this->attributes()) != NULL) { if (tname == ABSOLUTE_ATTR_NAME) { std::string subname; std::string subabs; size_t idx; idx = name.find("."); if (idx != std::string::npos) { subname = name.substr(0, idx); subabs = name.substr(idx+1, name.size()); for (attrit = attr->begin(); attrit != attr->end(); attrit++) { if (attrit->first == subname) result = this->attributeByAbsoluteNameFromVariant(attrit->second, subabs); delete attrit->second; } } else { for (attrit = attr->begin(); attrit != attr->end(); attrit++) { if (attrit->first == name) result = new Variant(attrit->second); delete attrit->second; } } } else { vlist = new std::list<Variant*>; for (attrit = attr->begin(); attrit != attr->end(); attrit++) { if (attrit->first == name) if ((vptr = new Variant(attrit->second)) != NULL) vlist->push_back(vptr); this->attributesByNameFromVariant(attrit->second, name, vlist); delete attrit->second; } if (vlist->size()) result = new Variant(*vlist); delete vlist; } delete attr; } return result; }