void MUCUserPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == ItemLevel) { if (element == "item") { MUCUserPayload::Item item; std::string affiliation = attributes.getAttribute("affiliation"); std::string role = attributes.getAttribute("role"); std::string nick = attributes.getAttribute("nick"); std::string jid = attributes.getAttribute("jid"); item.affiliation = parseAffiliation(affiliation); item.role = parseRole(role); if (!jid.empty()) { item.realJID = JID(jid); } if (!nick.empty()) { item.nick = nick; } getPayloadInternal()->addItem(item); } else if (element == "status") { MUCUserPayload::StatusCode status; try { status.code = boost::lexical_cast<int>(attributes.getAttribute("code").c_str()); getPayloadInternal()->addStatusCode(status); } catch (boost::bad_lexical_cast&) { } } } ++level; }
void XMPPParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (!parseErrorOccurred_) { if (level_ == TopLevel) { if (element == "stream" && ns == "http://etherx.jabber.org/streams") { ProtocolHeader header; header.setFrom(attributes.getAttribute("from")); header.setTo(attributes.getAttribute("to")); header.setID(attributes.getAttribute("id")); header.setVersion(attributes.getAttribute("version")); client_->handleStreamStart(header); } else { parseErrorOccurred_ = true; } } else { if (level_ == StreamLevel) { assert(!currentElementParser_); currentElementParser_ = createElementParser(element, ns); } currentElementParser_->handleStartElement(element, ns, attributes); } } ++level_; }
void SearchPayloadParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == TopLevel) { } else if (level == PayloadLevel) { if (element == "x" && ns == "jabber:x:data") { assert(!formParser); formParser = boost::polymorphic_downcast<FormParser*>(formParserFactory->createPayloadParser()); } else if (element == "item") { assert(!currentItem); currentItem.reset(SearchPayload::Item()); currentItem->jid = JID(attributes.getAttribute("jid")); } else { currentText.clear(); } } else if (level == ItemLevel && currentItem) { currentText.clear(); } if (formParser) { formParser->handleStartElement(element, ns, attributes); } ++level; }
void IdleParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) { if (level_ == 0) { boost::posix_time::ptime since = stringToDateTime(attributes.getAttribute("since")); getPayloadInternal()->setSince(since); } ++level_; }
void ReplaceParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { if (level_ == 0) { std::string id = attributes.getAttribute("id"); getPayloadInternal()->setID(id); } level_++; }
void RosterParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level_ == PayloadLevel) { if (element == "item") { inItem_ = true; currentItem_ = RosterItemPayload(); currentItem_.setJID(JID(attributes.getAttribute("jid"))); currentItem_.setName(attributes.getAttribute("name")); std::string subscription = attributes.getAttribute("subscription"); if (subscription == "both") { currentItem_.setSubscription(RosterItemPayload::Both); } else if (subscription == "to") { currentItem_.setSubscription(RosterItemPayload::To); } else if (subscription == "from") { currentItem_.setSubscription(RosterItemPayload::From); } else if (subscription == "remove") { currentItem_.setSubscription(RosterItemPayload::Remove); } else { currentItem_.setSubscription(RosterItemPayload::None); } if (attributes.getAttribute("ask") == "subscribe") { currentItem_.setSubscriptionRequested(); } } } else if (level_ == ItemLevel) { if (element == "group") { currentText_ = ""; } else { assert(!unknownContentParser_); unknownContentParser_ = new SerializingParser(); unknownContentParser_->handleStartElement(element, ns, attributes); } } else if (unknownContentParser_) { unknownContentParser_->handleStartElement(element, ns, attributes); } ++level_; }
void testGetAttribute_Namespaced() { AttributeMap testling; testling.addAttribute("lang", "", "nl"); testling.addAttribute("lang", "http://www.w3.org/XML/1998/namespace", "en"); testling.addAttribute("lang", "", "fr"); CPPUNIT_ASSERT_EQUAL(std::string("en"), testling.getAttribute("lang", "http://www.w3.org/XML/1998/namespace")); }
void BytestreamsParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == TopLevel) { getPayloadInternal()->setStreamID(attributes.getAttribute("sid")); } else if (level == PayloadLevel) { if (element == "streamhost") { try { getPayloadInternal()->addStreamHost(Bytestreams::StreamHost(attributes.getAttribute("host"), JID(attributes.getAttribute("jid")), boost::lexical_cast<int>(attributes.getAttribute("port")))); } catch (boost::bad_lexical_cast&) { } } else if (element == "streamhost-used") { getPayloadInternal()->setUsedStreamHost(JID(attributes.getAttribute("jid"))); } } ++level; }
void DiscoInfoParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level_ == PayloadLevel) { if (element == "identity") { getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); } else if (element == "feature") { getPayloadInternal()->addFeature(attributes.getAttribute("var")); } else if (element == "x" && ns == "jabber:x:data") { assert(!formParser_); formParser_ = new FormParser(); } } if (formParser_) { formParser_->handleStartElement(element, ns, attributes); } ++level_; }
void StanzaAckParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { if (depth == 0) { std::string handledStanzasString = attributes.getAttribute("h"); try { getElementGeneric()->setHandledStanzasCount(boost::lexical_cast<int>(handledStanzasString)); } catch (const boost::bad_lexical_cast &) { } } ++depth; }
void StorageParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == BookmarkLevel) { if (element == "conference") { assert(!room); room = Storage::Room(); room->autoJoin = attributes.getBoolAttribute("autojoin", false); room->jid = JID(attributes.getAttribute("jid")); room->name = attributes.getAttribute("name"); } else if (element == "url") { assert(!url); url = Storage::URL(); url->name = attributes.getAttribute("name"); url->url = attributes.getAttribute("url"); } } else if (level == DetailLevel) { currentText = ""; } ++level; }
void LastParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { if (level_ == 0) { int seconds = 0; try { seconds = boost::lexical_cast<int>(attributes.getAttribute("seconds")); } catch (boost::bad_lexical_cast&) { } getPayloadInternal()->setSeconds(seconds); } ++level_; }
void SecurityLabelParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { ++level_; if (level_ == DisplayMarkingOrLabelLevel) { if (element == "displaymarking") { currentText_ = ""; getPayloadInternal()->setBackgroundColor(attributes.getAttribute("bgcolor")); getPayloadInternal()->setForegroundColor(attributes.getAttribute("fgcolor")); } else if (element == "label" || element == "equivalentlabel") { assert(!labelParser_); labelParser_ = new SerializingParser(); } } else if (level_ >= SecurityLabelLevel && labelParser_) { labelParser_->handleStartElement(element, ns, attributes); } }
void AuthRequestParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attribute) { if (depth_ == 0) { getElementGeneric()->setMechanism(attribute.getAttribute("mechanism")); } ++depth_; }
void FormParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level_ == TopLevel) { std::string type = attributes.getAttribute("type"); if (type == "form") { getPayloadInternal()->setType(Form::FormType); } else if (type == "submit") { getPayloadInternal()->setType(Form::SubmitType); } else if (type == "cancel") { getPayloadInternal()->setType(Form::CancelType); } else if (type == "result") { getPayloadInternal()->setType(Form::ResultType); } } else if (level_ == PayloadLevel) { if (element == "title") { currentText_.clear(); } else if (element == "instructions") { currentText_.clear(); } else if (element == "field") { std::string type; FormField::ref correspondingReportedField; if (!parsingItem_) { type = attributes.getAttribute("type"); } else { foreach(FormField::ref field, getPayloadInternal()->getReportedFields()) { if (field->getName() == attributes.getAttribute("var")) { correspondingReportedField = field; break; } } } if (type == "boolean" || boost::dynamic_pointer_cast<BooleanFormField>(correspondingReportedField)) { currentFieldParseHelper_ = BooleanFormFieldParseHelper::create(); } else if (type == "fixed" || boost::dynamic_pointer_cast<FixedFormField>(correspondingReportedField)) { currentFieldParseHelper_ = FixedFormFieldParseHelper::create(); } else if (type == "hidden" || boost::dynamic_pointer_cast<HiddenFormField>(correspondingReportedField)) { currentFieldParseHelper_ = HiddenFormFieldParseHelper::create(); } else if (type == "jid-multi" || boost::dynamic_pointer_cast<JIDMultiFormField>(correspondingReportedField)) { currentFieldParseHelper_ = JIDMultiFormFieldParseHelper::create(); } else if (type == "jid-single" || boost::dynamic_pointer_cast<JIDSingleFormField>(correspondingReportedField)) { currentFieldParseHelper_ = JIDSingleFormFieldParseHelper::create(); } else if (type == "list-multi" || boost::dynamic_pointer_cast<ListMultiFormField>(correspondingReportedField)) { currentFieldParseHelper_ = ListMultiFormFieldParseHelper::create(); } else if (type == "list-single" || boost::dynamic_pointer_cast<ListSingleFormField>(correspondingReportedField)) { currentFieldParseHelper_ = ListSingleFormFieldParseHelper::create(); } else if (type == "text-multi" || boost::dynamic_pointer_cast<TextMultiFormField>(correspondingReportedField)) { currentFieldParseHelper_ = TextMultiFormFieldParseHelper::create(); } else if (type == "text-private" || boost::dynamic_pointer_cast<TextPrivateFormField>(correspondingReportedField)) { currentFieldParseHelper_ = TextPrivateFormFieldParseHelper::create(); } else /*if (type == "text-single") || undefined */ { currentFieldParseHelper_ = TextSingleFormFieldParseHelper::create(); } if (currentFieldParseHelper_) { currentFieldParseHelper_->getField()->setName(attributes.getAttribute("var")); currentFieldParseHelper_->getField()->setLabel(attributes.getAttribute("label")); } } else if (element == "reported") {