const bool BoardListXML::ParseXML(const std::string &xml) { bool parsed=false; Poco::XML::DOMParser dp; dp.setEntityResolver(0); Initialize(); try { Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml)); Poco::XML::Element *root=XMLGetFirstChild(doc,"BoardList"); Poco::XML::Element *boardel=NULL; boardel=XMLGetFirstChild(root,"Board"); while(boardel) { std::string name=""; std::string description=""; Poco::XML::Element *txt=XMLGetFirstChild(boardel,"Name"); if(txt && txt->firstChild()) { name=SanitizeSingleString(txt->firstChild()->getNodeValue()); StringFunctions::LowerCase(name,name); } txt=XMLGetFirstChild(boardel,"Description"); if(txt && txt->firstChild()) { description=SanitizeSingleString(txt->firstChild()->getNodeValue()); } if(name!="" && description!="") { m_boards.push_back(board(name,description)); } boardel=XMLGetNextSibling(boardel,"Board"); } parsed=true; } catch(...) { } return parsed; }
const bool IdentityIntroductionXML::ParseXML(const std::string &xml) { FreenetSSKKey ssk; bool parsed=false; Poco::XML::DOMParser dp; dp.setEntityResolver(0); Initialize(); try { Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml)); Poco::XML::Element *root=XMLGetFirstChild(doc,"IdentityIntroduction"); Poco::XML::Element *txt=NULL; txt=XMLGetFirstChild(root,"Identity"); if(txt) { if(txt->firstChild()) { m_identity=SanitizeSingleString(txt->firstChild()->getNodeValue()); if(ssk.TryParse(m_identity)==false) { return false; } m_identity=ssk.GetBaseKey(); } } parsed=true; } catch(...) { } return parsed; }
const bool MessageXML::ParseXML(const std::string &xml) { bool parsed=false; Poco::XML::DOMParser dp; dp.setEntityResolver(0); Initialize(); try { Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml)); Poco::XML::Element *root=XMLGetFirstChild(doc,"Message"); Poco::XML::Element *txt=NULL; txt=XMLGetFirstChild(root,"Date"); if(txt) { if(txt->firstChild()) { m_date=SanitizeSingleString(txt->firstChild()->getNodeValue()); } } txt=XMLGetFirstChild(root,"Time"); if(txt) { if(txt->firstChild()) { m_time=SanitizeSingleString(txt->firstChild()->getNodeValue()); } } txt=XMLGetFirstChild(root,"Subject"); if(txt) { if(txt->firstChild()) { m_subject=SanitizeSingleString(txt->firstChild()->getNodeValue()); } } txt=XMLGetFirstChild(root,"MessageID"); if(txt) { if(txt->firstChild()) { m_messageid=SanitizeSingleString(txt->firstChild()->getNodeValue()); } } txt=XMLGetFirstChild(root,"ReplyBoard"); if(txt) { if(txt->firstChild()) { m_replyboard=SanitizeSingleString(txt->firstChild()->getNodeValue()); // strip off everything after , in board name if(m_replyboard.find(',')!=std::string::npos) { m_replyboard.erase(m_replyboard.find(',')); } m_replyboard=Board::FixBoardName(m_replyboard); } } txt=XMLGetFirstChild(root,"Body"); if(txt) { if(txt->firstChild()) { m_body=txt->firstChild()->getNodeValue(); } } Poco::XML::Element *boards=XMLGetFirstChild(root,"Boards"); if(boards) { Poco::XML::Element *board=XMLGetFirstChild(boards,"Board"); while(board) { if(board->firstChild()) { std::string boardname=SanitizeSingleString(board->firstChild()->getNodeValue()); // strip off everything after , in board name if(boardname.find(',')!=std::string::npos) { boardname.erase(boardname.find(',')); } boardname=Board::FixBoardName(boardname); m_boards.push_back(boardname); } board=XMLGetNextSibling(board,"Board"); } } Poco::XML::Element *inreplyto=XMLGetFirstChild(root,"InReplyTo"); if(inreplyto) { Poco::XML::Element *message=XMLGetFirstChild(inreplyto,"Message"); while(message) { Poco::XML::Element *orderel=XMLGetFirstChild(message,"Order"); Poco::XML::Element *messageidel=XMLGetFirstChild(message,"MessageID"); if(orderel && orderel->firstChild() && messageidel && messageidel->firstChild()) { int order=-1; std::string messageid=""; StringFunctions::Convert(orderel->firstChild()->getNodeValue(),order); messageid=messageidel->firstChild()->getNodeValue(); if(order!=-1 && messageid!="") { m_inreplyto[order]=messageid; } } message=XMLGetNextSibling(message,"Message"); } } Poco::XML::Element *attachments=XMLGetFirstChild(root,"Attachments"); if(attachments) { Poco::XML::Element *file=XMLGetFirstChild(attachments,"File"); while(file) { Poco::XML::Element *keyel=XMLGetFirstChild(file,"Key"); Poco::XML::Element *sizeel=XMLGetFirstChild(file,"Size"); if(keyel && keyel->firstChild() && sizeel && sizeel->firstChild()) { int size=-1; std::string key=""; StringFunctions::Convert(sizeel->firstChild()->getNodeValue(),size); key=keyel->firstChild()->getNodeValue(); if(size!=-1 && key!="") { m_fileattachments.push_back(fileattachment(key,size)); } } file=XMLGetNextSibling(file,"File"); } } parsed=true; } catch(Poco::Exception &e) { m_lasterror="Caught exception - "+e.displayText(); } catch(...) { } return parsed; }