#include "../../include/message.h"\r
#include "../../include/messagelist.h"\r
#include "../../include/option.h"\r
+#include "../../include/nntp/extensiontrust.h"\r
\r
#include <algorithm>\r
\r
{\r
SendBufferedLine("AUTHINFO USER");\r
}\r
+ SendBufferedLine("XFMSTRUST");\r
SendBufferedLine(".");\r
\r
return true;\r
{\r
return HandleAuthInfoCommand(command);\r
}\r
+ if(command.m_command=="XGETTRUST")\r
+ {\r
+ return HandleGetTrustCommand(command);\r
+ }\r
+ if(command.m_command=="XSETTRUST")\r
+ {\r
+ return HandleSetTrustCommand(command);\r
+ }\r
+ if(command.m_command=="XGETTRUSTLIST")\r
+ {\r
+ return HandleGetTrustListCommand(command);\r
+ }\r
\r
return false;\r
}\r
return true;\r
}\r
\r
+const bool NNTPConnection::HandleGetTrustCommand(const NNTPCommand &command)\r
+{\r
+ if(command.m_arguments.size()>=2)\r
+ {\r
+ std::string type=command.m_arguments[0];\r
+ StringFunctions::UpperCase(type,type);\r
+ if(type=="MESSAGE" || type=="TRUSTLIST" || type=="PEERMESSAGE" || type=="PEERTRUSTLIST")\r
+ {\r
+ if(m_status.m_authenticated)\r
+ {\r
+ bool found=false;\r
+ int trust=-1;\r
+ std::string nntpname="";\r
+ for(int i=1; i<command.m_arguments.size(); i++)\r
+ {\r
+ if(i!=1)\r
+ {\r
+ nntpname+=" ";\r
+ }\r
+ nntpname+=command.m_arguments[i];\r
+ }\r
+\r
+ TrustExtension tr(m_status.m_authuser.GetID());\r
+\r
+ if(type=="MESSAGE")\r
+ {\r
+ if(tr.GetMessageTrust(nntpname,trust))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ else if(type=="TRUSTLIST")\r
+ {\r
+ if(tr.GetTrustListTrust(nntpname,trust))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ else if(type=="PEERMESSAGE")\r
+ {\r
+ if(tr.GetPeerMessageTrust(nntpname,trust))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ else if(type=="PEERTRUSTLIST")\r
+ {\r
+ if(tr.GetPeerTrustListTrust(nntpname,trust))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+\r
+ if(trust>=0 && found)\r
+ {\r
+ std::string truststr="";\r
+ StringFunctions::Convert(trust,truststr);\r
+ SendBufferedLine("280 "+truststr);\r
+ }\r
+ else if(found)\r
+ {\r
+ SendBufferedLine("281 null");\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("480 Identity not found");\r
+ }\r
+\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("480 User not authenticated");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("501 Syntax error");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("501 Syntax error");\r
+ }\r
+ return true;\r
+} \r
+\r
+const bool NNTPConnection::HandleGetTrustListCommand(const NNTPCommand &command)\r
+{\r
+ if(m_status.m_authenticated)\r
+ {\r
+ TrustExtension tr(m_status.m_authuser.GetID());\r
+ std::map<std::string,TrustExtension::trust> trustlist;\r
+ if(tr.GetTrustList(trustlist))\r
+ {\r
+ SendBufferedLine("280 Trust list follows");\r
+ for(std::map<std::string,TrustExtension::trust>::iterator i=trustlist.begin(); i!=trustlist.end(); i++)\r
+ {\r
+ std::ostringstream tempstr;\r
+ tempstr << (*i).first << "\t";\r
+ if((*i).second.m_localmessagetrust>-1)\r
+ {\r
+ tempstr << (*i).second.m_localmessagetrust;\r
+ } \r
+ else\r
+ {\r
+ tempstr << "null";\r
+ }\r
+ tempstr << "\t";\r
+ if((*i).second.m_localtrustlisttrust>-1)\r
+ {\r
+ tempstr << (*i).second.m_localtrustlisttrust;\r
+ }\r
+ else\r
+ {\r
+ tempstr << "null";\r
+ }\r
+ tempstr << "\t";\r
+ if((*i).second.m_peermessagetrust>-1)\r
+ {\r
+ tempstr << (*i).second.m_peermessagetrust;\r
+ }\r
+ else\r
+ {\r
+ tempstr << "null";\r
+ }\r
+ tempstr << "\t";\r
+ if((*i).second.m_peertrustlisttrust>-1)\r
+ {\r
+ tempstr << (*i).second.m_peertrustlisttrust;\r
+ }\r
+ else\r
+ {\r
+ tempstr << "null";\r
+ }\r
+ tempstr << "\t";\r
+ tempstr << (*i).second.m_messagetrustcomment;\r
+ tempstr << "\t";\r
+ tempstr << (*i).second.m_trustlisttrustcomment;\r
+\r
+ SendBufferedLine(tempstr.str());\r
+ }\r
+ SendBufferedLine(".");\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("501 Syntax error");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("480 User not authenticated");\r
+ }\r
+ return true;\r
+}\r
+\r
const bool NNTPConnection::HandleGroupCommand(const NNTPCommand &command)\r
{\r
if(command.m_arguments.size()==1)\r
}\r
}\r
\r
+const bool NNTPConnection::HandleSetTrustCommand(const NNTPCommand &command)\r
+{\r
+ if(command.m_arguments.size()>=3)\r
+ {\r
+ std::string type=command.m_arguments[0];\r
+ StringFunctions::UpperCase(type,type);\r
+ if(type=="MESSAGE" || type=="TRUSTLIST" || type=="MESSAGECOMMENT" || type=="TRUSTLISTCOMMENT")\r
+ {\r
+ if(m_status.m_authenticated)\r
+ {\r
+ bool found=false;\r
+ bool valid=false;\r
+ int trust=-1;\r
+ std::string comment="";\r
+ std::string nntpname="";\r
+\r
+ if(type=="MESSAGE" || type=="TRUSTLIST")\r
+ {\r
+ for(int i=1; i<command.m_arguments.size()-1; i++)\r
+ {\r
+ if(i!=1)\r
+ {\r
+ nntpname+=" ";\r
+ }\r
+ nntpname+=command.m_arguments[i];\r
+ }\r
+\r
+ if(command.m_arguments[command.m_arguments.size()-1]!="null")\r
+ {\r
+ StringFunctions::Convert(command.m_arguments[command.m_arguments.size()-1],trust);\r
+ }\r
+\r
+ if(trust>=-1 && trust<=100)\r
+ {\r
+ valid=true;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ int startpos=-1;\r
+ // get nntpname\r
+ for(int i=1; i<command.m_arguments.size() && startpos==-1; i++)\r
+ {\r
+ if(command.m_arguments[i].size()>0 && command.m_arguments[i][0]!='\"')\r
+ {\r
+ if(i!=1)\r
+ {\r
+ nntpname+=" ";\r
+ }\r
+ nntpname+=command.m_arguments[i];\r
+ }\r
+ else\r
+ {\r
+ startpos=i;\r
+ }\r
+ }\r
+\r
+ // get comment\r
+ for(int i=startpos; i<command.m_arguments.size(); i++)\r
+ {\r
+ if(i!=startpos)\r
+ {\r
+ comment+=" ";\r
+ }\r
+ comment+=command.m_arguments[i];\r
+ }\r
+ // strip " from comment beginning and end\r
+ if(comment.size()>0 && comment[0]=='\"')\r
+ {\r
+ comment.erase(0,1);\r
+ }\r
+ if(comment.size()>0 && comment[comment.size()-1]=='\"')\r
+ {\r
+ comment.erase(comment.size()-1);\r
+ }\r
+\r
+ valid=true;\r
+ }\r
+\r
+ TrustExtension tr(m_status.m_authuser.GetID());\r
+\r
+ if(type=="MESSAGE")\r
+ {\r
+ if(tr.SetMessageTrust(nntpname,trust))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ if(type=="TRUSTLIST")\r
+ {\r
+ if(tr.SetTrustListTrust(nntpname,trust))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ if(type=="MESSAGECOMMENT")\r
+ {\r
+ if(tr.SetMessageTrustComment(nntpname,comment))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+ if(type=="TRUSTLISTCOMMENT")\r
+ {\r
+ if(tr.SetTrustListTrustComment(nntpname,comment))\r
+ {\r
+ found=true;\r
+ }\r
+ }\r
+\r
+ if(found && valid)\r
+ {\r
+ SendBufferedLine("280 Trust Set");\r
+ }\r
+ else if(found==false)\r
+ {\r
+ SendBufferedLine("480 Identity not found");\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("501 Syntax error");\r
+ }\r
+\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("480 User not authenticated");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("501 Syntax error");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ SendBufferedLine("501 Syntax error");\r
+ }\r
+ return true;\r
+}\r
+\r
const bool NNTPConnection::HandleStatCommand(const NNTPCommand &command)\r
{\r
SendArticleParts(command);\r