diff --git a/backends/twitter/TwitterPlugin.cpp b/backends/twitter/TwitterPlugin.cpp index 3eca8cd5..ac22b00c 100644 --- a/backends/twitter/TwitterPlugin.cpp +++ b/backends/twitter/TwitterPlugin.cpp @@ -382,12 +382,21 @@ void TwitterPlugin::directMessageResponse(std::string &user, std::vector getTimeline(std::string &xml) std::vector statuses; Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml); + if(rootElement == NULL) { + LOG4CXX_ERROR(logger, "Error while parsing XML") + return statuses; + } + if(rootElement->getName() != "statuses") { LOG4CXX_ERROR(logger, "XML doesn't correspond to timeline") return statuses; @@ -87,6 +92,11 @@ std::vector getDirectMessages(std::string &xml) std::vector DMs; Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml); + if(rootElement == NULL) { + LOG4CXX_ERROR(logger, "Error while parsing XML") + return DMs; + } + if(rootElement->getName() != TwitterReponseTypes::directmessages) { LOG4CXX_ERROR(logger, "XML doesn't correspond to direct-messages") return DMs; @@ -107,6 +117,11 @@ std::vector getUsers(std::string &xml) std::vector users; Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml); + if(rootElement == NULL) { + LOG4CXX_ERROR(logger, "Error while parsing XML") + return users; + } + if(rootElement->getName() != TwitterReponseTypes::users) { LOG4CXX_ERROR(logger, "XML doesn't correspond to user list") return users; @@ -127,6 +142,11 @@ std::vector getIDs(std::string &xml) std::vector IDs; Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml); + if(rootElement == NULL) { + LOG4CXX_ERROR(logger, "Error while parsing XML") + return IDs; + } + if(rootElement->getName() != TwitterReponseTypes::id_list) { LOG4CXX_ERROR(logger, "XML doesn't correspond to id_list"); return IDs; @@ -146,6 +166,11 @@ std::string getErrorMessage(std::string &xml) std::string error; Swift::ParserElement::ref rootElement = Swift::StringTreeParser::parse(xml); + if(rootElement == NULL) { + LOG4CXX_ERROR(logger, "Error while parsing XML"); + return ""; + } + const std::string xmlns = rootElement->getNamespace(); const Swift::ParserElement::ref errorElement = rootElement->getChild(TwitterReponseTypes::error, xmlns);