1 #include "../../include/freenet/frostmessagexml.h"
\r
3 const std::string FrostMessageXML::FrostMakeFileName(const std::string &input) const
\r
6 std::string::size_type strpos;
\r
7 std::string invalidchars="/\\?*<>\":|#&";
\r
11 std::transform(input.begin(),input.end(),output.begin(),tolower);
\r
13 if(output.size()>0 && output[0]=='.')
\r
18 strpos=output.find_first_of(invalidchars);
\r
19 while(strpos!=std::string::npos)
\r
21 output.at(strpos)='_';
\r
22 strpos=output.find_first_of(invalidchars,strpos);
\r
28 const std::string FrostMessageXML::GetSignableContentV2() const
\r
34 temp=GetFrostDate()+separator+GetFrostTime()+separator;
\r
36 temp+=GetFrostBoard()+separator;
\r
37 temp+=GetFrostAuthor()+separator;
\r
38 temp+=GetFrostMessageID()+separator;
\r
39 if(GetFrostInReplyTo()!="")
\r
41 temp+=GetFrostInReplyTo()+separator;
\r
43 // recipient goes here - private messages ??
\r
45 // add id info even if it is -1
\r
47 std::string tempval="";
\r
48 StringFunctions::Convert(GetFrostIDLinePos(),tempval);
\r
49 temp+=tempval+separator;
\r
50 StringFunctions::Convert(GetFrostIDLineLen(),tempval);
\r
51 temp+=tempval+separator;
\r
55 temp+=GetFrostSubject()+separator+GetBody()+separator;
\r
57 std::vector<FrostMessageXML::frostboardattachment> boards=GetFrostBoardAttachments();
\r
58 for(i=0; i<boards.size(); i++)
\r
60 temp+=FrostMakeFileName(boards[i].m_name)+separator;
\r
61 if(boards[i].m_publickey!="")
\r
63 temp+=boards[i].m_publickey+separator;
\r
65 if(boards[i].m_privatekey!="")
\r
67 temp+=boards[i].m_privatekey+separator;
\r
71 std::vector<FrostMessageXML::frostfileattachment> files=GetFrostFileAttachments();
\r
72 for(i=0; i<files.size(); i++)
\r
74 temp+=files[i].m_name+separator;
\r
75 temp+=files[i].m_key+separator;
\r
81 std::string FrostMessageXML::GetXML()
\r
83 return std::string("");
\r
86 void FrostMessageXML::Initialize()
\r
88 MessageXML::Initialize();
\r
95 m_frostmessageid="";
\r
97 m_frostpublickey="";
\r
98 m_frostsignature="";
\r
99 m_frostsignaturev2="";
\r
102 const bool FrostMessageXML::ParseXML(const std::string &xml)
\r
119 Attachment type="file"
\r
123 key - key without filename
\r
127 Poco::XML::DOMParser dp;
\r
133 Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));
\r
134 Poco::XML::Element *root=XMLGetFirstChild(doc,"FrostMessage");
\r
135 Poco::XML::Element *txt=0;
\r
137 txt=XMLGetFirstChild(root,"Date");
\r
140 if(txt->firstChild())
\r
142 m_frostdate=txt->firstChild()->getNodeValue();
\r
143 m_date=SanitizeSingleString(m_frostdate);
\r
144 m_date=StringFunctions::Replace(m_date,".","-");
\r
145 if(m_date.size()<10)
\r
147 std::vector<std::string> dateparts;
\r
148 StringFunctions::Split(m_date,"-",dateparts);
\r
149 if(dateparts.size()==3)
\r
151 m_date=dateparts[0]+"-";
\r
152 if(dateparts[1].size()==1)
\r
156 m_date+=dateparts[1]+"-";
\r
157 if(dateparts[2].size()==1)
\r
161 m_date+=dateparts[2];
\r
166 txt=XMLGetFirstChild(root,"Time");
\r
169 if(txt->firstChild())
\r
171 m_frosttime=txt->firstChild()->getNodeValue();
\r
172 m_time=SanitizeSingleString(m_frosttime);
\r
173 m_time=StringFunctions::Replace(m_time,"GMT","");
\r
176 txt=XMLGetFirstChild(root,"From");
\r
179 if(txt->firstChild())
\r
181 m_frostauthor=txt->firstChild()->getNodeValue();
\r
184 txt=XMLGetFirstChild(root,"Subject");
\r
187 if(txt->firstChild())
\r
189 m_frostsubject=txt->firstChild()->getNodeValue();
\r
190 m_subject=SanitizeSingleString(m_frostsubject);
\r
193 txt=XMLGetFirstChild(root,"MessageId");
\r
196 if(txt->firstChild())
\r
198 // we have to append an @frost (or anything really) to the message ID, otherwise someone could insert valid FMS UUIDs here
\r
199 m_frostmessageid=txt->firstChild()->getNodeValue();
\r
200 m_messageid=SanitizeSingleString(m_frostmessageid)+"@frost";
\r
203 txt=XMLGetFirstChild(root,"Board");
\r
206 if(txt->firstChild())
\r
208 m_frostboard=txt->firstChild()->getNodeValue();
\r
209 std::string boardname=SanitizeSingleString(m_frostboard);
\r
210 StringFunctions::LowerCase(boardname,boardname);
\r
211 if(boardname.size()>40)
\r
213 boardname.erase(40);
\r
215 m_replyboard=boardname;
\r
216 m_boards.push_back(boardname);
\r
219 txt=XMLGetFirstChild(root,"Body");
\r
222 if(txt->firstChild())
\r
224 m_body=txt->firstChild()->getNodeValue();
\r
227 txt=XMLGetFirstChild(root,"pubKey");
\r
230 if(txt->firstChild())
\r
232 m_frostpublickey=txt->firstChild()->getNodeValue();
\r
235 txt=XMLGetFirstChild(root,"Signature");
\r
238 if(txt->firstChild())
\r
240 m_frostsignature=txt->firstChild()->getNodeValue();
\r
243 txt=XMLGetFirstChild(root,"SignatureV2");
\r
246 if(txt->firstChild())
\r
248 m_frostsignaturev2=txt->firstChild()->getNodeValue();
\r
251 txt=XMLGetFirstChild(root,"IdLinePos");
\r
254 if(txt->firstChild())
\r
256 std::string temp=txt->firstChild()->getNodeValue();
\r
257 StringFunctions::Convert(temp,m_frostidlinepos);
\r
260 txt=XMLGetFirstChild(root,"IdLineLen");
\r
263 if(txt->firstChild())
\r
265 std::string temp=txt->firstChild()->getNodeValue();
\r
266 StringFunctions::Convert(temp,m_frostidlinelen);
\r
269 Poco::XML::Element *inreplyto=XMLGetFirstChild(root,"InReplyTo");
\r
272 if(inreplyto->firstChild())
\r
275 m_frostinreplyto=inreplyto->firstChild()->getNodeValue();
\r
276 std::vector<std::string> inreplytoids;
\r
277 StringFunctions::Split(m_frostinreplyto,",",inreplytoids);
\r
278 for(std::vector<std::string>::reverse_iterator i=inreplytoids.rbegin(); i!=inreplytoids.rend(); i++)
\r
280 m_inreplyto[order++]=(*i)+"@frost";
\r
284 Poco::XML::Element *attachments=XMLGetFirstChild(root,"AttachmentList");
\r
287 Poco::XML::Element *file=XMLGetFirstChild(attachments,"Attachment");
\r
290 if(file->getAttribute("type")=="file")
\r
292 Poco::XML::Element *keyel=XMLGetFirstChild(file,"key");
\r
293 Poco::XML::Element *sizeel=XMLGetFirstChild(file,"size");
\r
294 Poco::XML::Element *nameel=XMLGetFirstChild(file,"name");
\r
296 if(keyel && keyel->firstChild() && sizeel && sizeel->firstChild() && nameel && nameel->firstChild())
\r
299 std::string key="";
\r
301 StringFunctions::Convert(sizeel->firstChild()->getNodeValue(),size);
\r
302 key=keyel->firstChild()->getNodeValue();
\r
303 key+="/"+nameel->firstChild()->getNodeValue();
\r
305 if(size!=-1 && key!="")
\r
307 m_fileattachments.push_back(fileattachment(key,size));
\r
310 m_frostfileattachments.push_back(frostfileattachment(keyel->firstChild()->getNodeValue(),size,nameel->firstChild()->getNodeValue()));
\r
313 else if(file->getAttribute("type")=="board")
\r
315 Poco::XML::Element *nameel=XMLGetFirstChild(file,"Name");
\r
316 Poco::XML::Element *descel=XMLGetFirstChild(file,"description");
\r
317 Poco::XML::Element *pubel=XMLGetFirstChild(file,"pubKey");
\r
318 Poco::XML::Element *privel=XMLGetFirstChild(file,"privKey");
\r
319 std::string name="";
\r
320 std::string desc="";
\r
321 std::string pubkey="";
\r
322 std::string privkey="";
\r
324 if(nameel && nameel->firstChild())
\r
326 name=nameel->firstChild()->getNodeValue();
\r
328 if(descel && descel->firstChild())
\r
330 desc=descel->firstChild()->getNodeValue();
\r
332 if(pubel && pubel->firstChild())
\r
334 pubkey=pubel->firstChild()->getNodeValue();
\r
336 if(privel && privel->firstChild())
\r
338 privkey=privel->firstChild()->getNodeValue();
\r
341 m_frostboardattachments.push_back(frostboardattachment(name,desc,pubkey,privkey));
\r
345 file=static_cast<Poco::XML::Element *>(file->nextSibling());
\r