void StanzaParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (inStanza()) { if (!inPayload()) { assert(!currentPayloadParser_); PayloadParserFactory* payloadParserFactory = factories_->getPayloadParserFactory(element, ns, attributes); if (payloadParserFactory) { currentPayloadParser_.reset(payloadParserFactory->createPayloadParser()); } else { currentPayloadParser_.reset(new UnknownPayloadParser()); } } assert(currentPayloadParser_); currentPayloadParser_->handleStartElement(element, ns, attributes); } else { boost::optional<std::string> from = attributes.getAttributeValue("from"); if (from) { getStanza()->setFrom(JID(*from)); } boost::optional<std::string> to = attributes.getAttributeValue("to"); if (to) { getStanza()->setTo(JID(*to)); } boost::optional<std::string> id = attributes.getAttributeValue("id"); if (id) { getStanza()->setID(*id); } handleStanzaAttributes(attributes); } ++currentDepth_; }
void PubSubOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { if (boost::optional<JID> jid = JID::parse(*attributeValue)) { getPayloadInternal()->setJID(*jid); } } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { getPayloadInternal()->setSubscriptionID(*attributeValue); } } if (level == 1) { if (element == "x" && ns == "jabber:x:data") { currentPayloadParser = boost::make_shared<FormParser>(); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void PubSubSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { getPayloadInternal()->setSubscriptionID(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { if (boost::optional<JID> jid = JID::parse(*attributeValue)) { getPayloadInternal()->setJID(*jid); } } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { getPayloadInternal()->setSubscription(*value); } } } if (level == 1) { if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") { currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void PubSubItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) { try { getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue)); } catch (boost::bad_lexical_cast&) { } } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { getPayloadInternal()->setSubscriptionID(*attributeValue); } } if (level == 1) { if (element == "item" && ns == "http://jabber.org/protocol/pubsub") { currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void MAMQueryParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level_ == TopLevel) { boost::optional<std::string> attributeValue; if ((attributeValue = attributes.getAttributeValue("queryid"))) { getPayloadInternal()->setQueryID(*attributeValue); } if ((attributeValue = attributes.getAttributeValue("node"))) { getPayloadInternal()->setNode(*attributeValue); } } else if (level_ == PayloadLevel) { if (element == "x" && ns == "jabber:x:data") { formParser_ = boost::make_shared<FormParser>(); } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { resultSetParser_ = boost::make_shared<ResultSetParser>(); } } if (formParser_) { /* parsing a nested Form */ formParser_->handleStartElement(element, ns, attributes); } if (resultSetParser_) { /* parsing a nested ResultSet */ resultSetParser_->handleStartElement(element, ns, attributes); } ++level_; }
void PubSubEventSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { if (boost::optional<JID> jid = JID::parse(*attributeValue)) { getPayloadInternal()->setJID(*jid); } } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) { if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) { getPayloadInternal()->setSubscription(*value); } } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) { getPayloadInternal()->setSubscriptionID(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) { getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue)); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { try { getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttributeValue("block-size").get_value_or("0"))); } catch (boost::bad_lexical_cast &) { getPayloadInternal()->setBlockSize(0); } getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); ++level; }
void DeliveryReceiptParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributeMap) { if (level_ == 0) { if (element == "received") { if (attributeMap.getAttributeValue("id").is_initialized()) { getPayloadInternal()->setReceivedID(attributeMap.getAttributeValue("id").get()); } } } ++level_; }
void JingleFileTransferFileInfoParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { charData.clear(); if (element == "hash") { hashAlg = attributes.getAttributeValue("algo").get_value_or(""); } else if (element == "range") { rangeOffset = safeLexicalCast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("")); } ++level; }
void PresenceParser::handleStanzaAttributes(const AttributeMap& attributes) { boost::optional<std::string> type = attributes.getAttributeValue("type"); if (type) { if (*type == "unavailable") { getStanzaGeneric()->setType(Presence::Unavailable); } else if (*type == "probe") { getStanzaGeneric()->setType(Presence::Probe); } else if (*type == "subscribe") { getStanzaGeneric()->setType(Presence::Subscribe); } else if (*type == "subscribed") { getStanzaGeneric()->setType(Presence::Subscribed); } else if (*type == "unsubscribe") { getStanzaGeneric()->setType(Presence::Unsubscribe); } else if (*type == "unsubscribed") { getStanzaGeneric()->setType(Presence::Unsubscribed); } else if (*type == "error") { getStanzaGeneric()->setType(Presence::Error); } else { std::cerr << "Unknown Presence type: " << *type << std::endl; getStanzaGeneric()->setType(Presence::Available); } } else { getStanzaGeneric()->setType(Presence::Available); } }
void PubSubSubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { if (boost::optional<JID> jid = JID::parse(*attributeValue)) { getPayloadInternal()->setJID(*jid); } } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void PubSubDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) { if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) { getPayloadInternal()->setType(*value); } } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void PubSubEventRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) { getPayloadInternal()->setURI(*attributeValue); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void PubSubOwnerAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) { if (boost::optional<JID> jid = JID::parse(*attributeValue)) { getPayloadInternal()->setJID(*jid); } } if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) { if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) { getPayloadInternal()->setType(*value); } } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void JingleParser::handleStartElement(const std::string& element, const std::string &ns, const AttributeMap& attributes) { if (level == 0) { // <jingle > tag JinglePayload::ref payload = getPayloadInternal(); payload->setAction(stringToAction(attributes.getAttributeValue("action").get_value_or(""))); payload->setInitiator(JID(attributes.getAttributeValue("initiator").get_value_or(""))); payload->setResponder(JID(attributes.getAttributeValue("responder").get_value_or(""))); payload->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); } if (level == 1) { PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); if (payloadParserFactory) { currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void PubSubAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level == 0) { if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) { getPayloadInternal()->setNode(*attributeValue); } } if (level == 1) { if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") { currentPayloadParser = std::make_shared<PubSubAffiliationParser>(parsers); } } if (level >= 1 && currentPayloadParser) { currentPayloadParser->handleStartElement(element, ns, attributes); } ++level; }
void MessageParser::handleStanzaAttributes(const AttributeMap& attributes) { boost::optional<std::string> type = attributes.getAttributeValue("type"); if (type) { if (*type == "chat") { getStanzaGeneric()->setType(Message::Chat); } else if (*type == "error") { getStanzaGeneric()->setType(Message::Error); } else if (*type == "groupchat") { getStanzaGeneric()->setType(Message::Groupchat); } else if (*type == "headline") { getStanzaGeneric()->setType(Message::Headline); } else { getStanzaGeneric()->setType(Message::Normal); } } }
void MAMFinParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { if (level_ == TopLevel) { getPayloadInternal()->setComplete(attributes.getBoolAttribute("complete", false)); getPayloadInternal()->setStable(attributes.getBoolAttribute("stable", true)); boost::optional<std::string> attributeValue; if ((attributeValue = attributes.getAttributeValue("queryid"))) { getPayloadInternal()->setQueryID(*attributeValue); } } else if (level_ == PayloadLevel) { if (element == "set" && ns == "http://jabber.org/protocol/rsm") { resultSetParser_ = boost::make_shared<ResultSetParser>(); } } if (resultSetParser_) { /* parsing a nested ResultSet */ resultSetParser_->handleStartElement(element, ns, attributes); } ++level_; }
void JingleS5BTransportMethodPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == 0) { getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); std::string mode = attributes.getAttributeValue("mode").get_value_or("tcp"); if (mode == "tcp") { getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); } else if(mode == "udp") { getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); } else { SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); } getPayloadInternal()->setDstAddr(attributes.getAttributeValue("dstaddr").get_value_or("")); } else if (level == 1) { if (element == "candidate") { JingleS5BTransportPayload::Candidate candidate; candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); int port = -1; try { port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); } catch(boost::bad_lexical_cast &) { } candidate.hostPort = HostAddressPort(HostAddress(attributes.getAttributeValue("host").get_value_or("")), port); candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); int priority = -1; try { priority = boost::lexical_cast<int>(attributes.getAttributeValue("priority").get_value_or("-1")); } catch(boost::bad_lexical_cast &) { } candidate.priority = priority; candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or("direct")); getPayloadInternal()->addCandidate(candidate); } else if (element == "candidate-used") { getPayloadInternal()->setCandidateUsed(attributes.getAttributeValue("cid").get_value_or("")); } else if (element == "candidate-error") { getPayloadInternal()->setCandidateError(true); } else if (element == "activated") { getPayloadInternal()->setActivated(attributes.getAttributeValue("cid").get_value_or("")); } else if (element == "proxy-error") { getPayloadInternal()->setProxyError(true); } } ++level; }