X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessagelistxml.cpp;h=eb57240d3fdbf33f3863d75b0e610ce47dac4e6b;hb=76805933f794915a72b7f0a21b12af6654759f4f;hp=c05bb665489c56f2f1b9a72200b0497bdb7a2ac7;hpb=6b896a9e1dc143bba86795be1e9336549db9b85f;p=fms.git diff --git a/src/freenet/messagelistxml.cpp b/src/freenet/messagelistxml.cpp index c05bb66..eb57240 100644 --- a/src/freenet/messagelistxml.cpp +++ b/src/freenet/messagelistxml.cpp @@ -9,11 +9,21 @@ MessageListXML::MessageListXML() Initialize(); } -void MessageListXML::AddMessage(const std::string &date, const long index, const std::vector boards) +void MessageListXML::AddMessage(const std::string &date, const long index, const std::vector &boards) { m_messages.push_back(message(date,index,boards)); } +void MessageListXML::AddExternalMessage(const std::string &identity, const std::string &date, const long index, const std::vector &boards) +{ + m_externalmessages.push_back(externalmessage("Keyed",identity,date,index,boards)); +} + +void MessageListXML::AddExternalMessage(const std::string &messagekey, const std::string &date, const std::vector &boards) +{ + m_externalmessages.push_back(externalmessage("Anonymous",messagekey,date,boards)); +} + std::vector MessageListXML::GetBoards(const long index) { if(index>=0 && index MessageListXML::GetExternalBoards(const long index) +{ + if(index>=0 && index(); + } +} + +std::string MessageListXML::GetExternalDate(const long index) +{ + if(index>=0 && index=0 && index=0 && index=0 && index=0 && index=0 && index doc=new Poco::XML::Document; + Poco::AutoPtr root=doc->createElement("MessageList"); - td.LinkEndChild(tdec); - tid=new TiXmlElement("MessageList"); - td.LinkEndChild(tid); + doc->appendChild(root); for(std::vector::iterator i=m_messages.begin(); i!=m_messages.end(); i++) { - TiXmlElement *tr=new TiXmlElement("Message"); - tid->LinkEndChild(tr); - tr->LinkEndChild(XMLCreateTextElement("Date",(*i).m_date)); - tr->LinkEndChild(XMLCreateTextElement("Index",(*i).m_index)); - TiXmlElement *brds=new TiXmlElement("Boards"); - tr->LinkEndChild(brds); + Poco::AutoPtr tr=doc->createElement("Message"); + root->appendChild(tr); + tr->appendChild(XMLCreateTextElement(doc,"Date",(*i).m_date)); + tr->appendChild(XMLCreateTextElement(doc,"Index",(*i).m_index)); + + Poco::AutoPtr boards=doc->createElement("Boards"); + tr->appendChild(boards); for(std::vector::iterator j=(*i).m_boards.begin(); j!=(*i).m_boards.end(); j++) { - brds->LinkEndChild(XMLCreateCDATAElement("Board",(*j))); + boards->appendChild(XMLCreateCDATAElement(doc,"Board",(*j))); } } - td.Accept(&tp); - return std::string(tp.CStr()); + for(std::vector::iterator i=m_externalmessages.begin(); i!=m_externalmessages.end(); i++) + { + Poco::AutoPtr tr=doc->createElement("ExternalMessage"); + root->appendChild(tr); + tr->appendChild(XMLCreateTextElement(doc,"Type",(*i).m_type)); + if((*i).m_type=="Keyed") + { + tr->appendChild(XMLCreateCDATAElement(doc,"Identity",(*i).m_identity)); + tr->appendChild(XMLCreateTextElement(doc,"Index",(*i).m_index)); + } + else + { + tr->appendChild(XMLCreateCDATAElement(doc,"MessageKey",(*i).m_messagekey)); + } + tr->appendChild(XMLCreateTextElement(doc,"Date",(*i).m_date)); + + Poco::AutoPtr boards=doc->createElement("Boards"); + tr->appendChild(boards); + for(std::vector::iterator j=(*i).m_boards.begin(); j!=(*i).m_boards.end(); j++) + { + boards->appendChild(XMLCreateCDATAElement(doc,"Board",(*j))); + } + } + + return GenerateXML(doc); } void MessageListXML::Initialize() { m_messages.clear(); + m_externalmessages.clear(); } const bool MessageListXML::ParseXML(const std::string &xml) { - TiXmlDocument td; - td.Parse(xml.c_str()); - if(!td.Error()) - { - std::string tempstr; - std::string date; - long index; - std::vector boards; - TiXmlText *txt; - TiXmlHandle hnd(&td); - TiXmlNode *node; - TiXmlNode *node2; + bool parsed=false; + Poco::XML::DOMParser dp; - Initialize(); + Initialize(); + + try + { + Poco::AutoPtr doc=dp.parseString(FixCDATA(xml)); + Poco::XML::Element *root=XMLGetFirstChild(doc,"MessageList"); - node=hnd.FirstChild("MessageList").FirstChild("Message").ToNode(); + Poco::XML::Element *node=XMLGetFirstChild(root,"Message"); while(node) { - date=""; - index=-1; - boards.clear(); + std::string date=""; + int index=-1; + std::vector boards; - TiXmlHandle hnd2(node); - txt=hnd2.FirstChild("Date").FirstChild().ToText(); - if(txt) + Poco::XML::Element *node2=XMLGetFirstChild(node,"Date"); + if(node2 && node2->firstChild()) { - date=txt->ValueStr(); + date=SanitizeSingleString(node2->firstChild()->getNodeValue()); } - txt=hnd2.FirstChild("Index").FirstChild().ToText(); - if(txt) + node2=XMLGetFirstChild(node,"Index"); + if(node2 && node2->firstChild()) { - tempstr=txt->ValueStr(); - StringFunctions::Convert(tempstr,index); + std::string indexstr=SanitizeSingleString(node2->firstChild()->getNodeValue()); + StringFunctions::Convert(indexstr,index); } - node2=hnd2.FirstChild("Boards").FirstChild("Board").ToNode(); - while(node2) + node2=XMLGetFirstChild(node,"Boards"); + if(node2) { - if(node2->FirstChild()) + Poco::XML::Element *node3=XMLGetFirstChild(node2,"Board"); + while(node3) { - boards.push_back(node2->FirstChild()->ValueStr()); + if(node3 && node3->firstChild()) + { + std::string boardname=SanitizeSingleString(node3->firstChild()->getNodeValue()); + StringFunctions::LowerCase(boardname,boardname); + if(boardname.size()>40) + { + boardname.erase(40); + } + boards.push_back(boardname); + } + node3=XMLGetNextSibling(node3,"Board"); } - node2=node2->NextSibling("Board"); } m_messages.push_back(message(date,index,boards)); - node=node->NextSibling("Message"); + node=XMLGetNextSibling(node,"Message"); } - return true; + node=XMLGetFirstChild(root,"ExternalMessage"); + while(node) + { + std::string type=""; + std::string identity=""; + std::string date=""; + int index=-1; + std::vector boards; + + Poco::XML::Element *node2=XMLGetFirstChild(node,"Type"); + if(node2 && node2->firstChild()) + { + type=SanitizeSingleString(node2->firstChild()->getNodeValue()); + } + + if(type=="Keyed") + { + node2=XMLGetFirstChild(node,"Identity"); + if(node2 && node2->firstChild()) + { + identity=SanitizeSingleString(node2->firstChild()->getNodeValue()); + } + node2=XMLGetFirstChild(node,"Date"); + if(node2 && node2->firstChild()) + { + date=SanitizeSingleString(node2->firstChild()->getNodeValue()); + } + node2=XMLGetFirstChild(node,"Index"); + if(node2 && node2->firstChild()) + { + std::string indexstr=SanitizeSingleString(node2->firstChild()->getNodeValue()); + StringFunctions::Convert(indexstr,index); + } + node2=XMLGetFirstChild(node,"Boards"); + if(node2) + { + Poco::XML::Element *node3=XMLGetFirstChild(node2,"Board"); + while(node3) + { + if(node3 && node3->firstChild()) + { + std::string boardname=SanitizeSingleString(node3->firstChild()->getNodeValue()); + StringFunctions::LowerCase(boardname,boardname); + if(boardname.size()>40) + { + boardname.erase(40); + } + boards.push_back(boardname); + } + node3=XMLGetNextSibling(node3,"Board"); + } + } + m_externalmessages.push_back(externalmessage("Keyed",identity,date,index,boards)); + } + + node=XMLGetNextSibling(node,"ExternalMessage"); + } + parsed=true; } - else + catch(...) { - return false; } + + return parsed; }