Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
const bool SoneXML::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,"sone");
		Poco::XML::Element *posts=NULL;
		Poco::XML::Element *replies=NULL;
		Poco::XML::Element *txt=NULL;
		Poco::XML::Element *profile=NULL;
		Poco::XML::Element *albums=NULL;

		if(root)
		{
			posts=XMLGetFirstChild(root,"posts");
			replies=XMLGetFirstChild(root,"replies");
			profile=XMLGetFirstChild(root,"profile");
			albums=XMLGetFirstChild(root,"albums");
		}

		if(posts)
		{

			txt=XMLGetFirstChild(posts,"post");
			while(txt)
			{
				std::string id("");
				std::string timestr("");
				Poco::Timestamp::TimeVal timeval;
				Poco::DateTime messagetime;
				std::string messagetext("");

				Poco::XML::Element *el;
				el=XMLGetFirstChild(txt,"id");
				if(el && el->firstChild())
				{
					id=el->firstChild()->getNodeValue();
				}

				el=XMLGetFirstChild(txt,"time");
				if(el && el->firstChild())
				{
					timestr=el->firstChild()->getNodeValue();
					StringFunctions::Convert(timestr,timeval);
					messagetime=Poco::Timestamp(timeval*static_cast<Poco::Timestamp::TimeVal>(1000));
				}

				el=XMLGetFirstChild(txt,"text");
				if(el && el->firstChild())
				{
					messagetext=el->firstChild()->getNodeValue();
				}

				if(id!="" && messagetext!="")
				{
					m_messages.push_back(message(messagetime,id,std::string(""),messagetext));
				}

				txt=XMLGetNextSibling(txt,"post");
			}
		}

		if(replies)
		{

			txt=XMLGetFirstChild(replies,"reply");
			while(txt)
			{
				std::string id("");
				std::string replyto("");
				std::string timestr("");
				Poco::Timestamp::TimeVal timeval;
				Poco::DateTime messagetime;
				std::string messagetext("");

				Poco::XML::Element *el;
				el=XMLGetFirstChild(txt,"id");
				if(el && el->firstChild())
				{
					id=el->firstChild()->getNodeValue();
				}

				el=XMLGetFirstChild(txt,"post-id");
				if(el && el->firstChild())
				{
					replyto=el->firstChild()->getNodeValue();
				}

				el=XMLGetFirstChild(txt,"time");
				if(el && el->firstChild())
				{
					timestr=el->firstChild()->getNodeValue();
					StringFunctions::Convert(timestr,timeval);
					messagetime=Poco::Timestamp(timeval*static_cast<Poco::Timestamp::TimeVal>(1000));
				}

				el=XMLGetFirstChild(txt,"text");
				if(el && el->firstChild())
				{
					messagetext=el->firstChild()->getNodeValue();
				}

				if(id!="" && messagetext!="")
				{
					m_messages.push_back(message(messagetime,id,replyto,messagetext));
				}

				txt=XMLGetNextSibling(txt,"reply");
			}

		}

		if(profile)
		{
			std::string avatarid("");
			Poco::XML::Element *avatar=XMLGetFirstChild(profile,"avatar");
			if(avatar && avatar->firstChild() && avatar->firstChild()->getNodeValue()!="")
			{
				std::string avatarid=avatar->firstChild()->getNodeValue();
				if(albums)
				{
					Poco::XML::Element *album=XMLGetFirstChild(albums,"album");
					while(album)
					{
						Poco::XML::Element *images=XMLGetFirstChild(album,"images");
						if(images)
						{
							Poco::XML::Element *image=XMLGetFirstChild(images,"image");
							while(image)
							{
								Poco::XML::Element *imid=XMLGetFirstChild(image,"id");
								if(imid && imid->firstChild())
								{
									if(imid->firstChild()->getNodeValue()==avatarid)
									{
										Poco::XML::Element *key=XMLGetFirstChild(image,"key");
										if(key && key->firstChild())
										{
											m_avatar=key->firstChild()->getNodeValue();
										}
									}
								}
								image=XMLGetNextSibling(image,"image");
							}
						}
						album=XMLGetNextSibling(album,"album");
					}
				}
			}
		}

		parsed=true;

	}
	catch(...)
	{
	}

	return parsed;

}