X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fnntpconnection.cpp;h=eecbec605844ac1c1ef1d0ecebf7ad60591a481f;hb=3f6f19146f015fa8d2c89f1e72cd467dbc4115aa;hp=b3eeecc583734ef824dcc2c111a0a01a58546768;hpb=0574a75431d98ed64c5cc6291600bb3759b399a6;p=fms.git diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index b3eeecc..eecbec6 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -6,6 +6,7 @@ #include "../../include/message.h" #include "../../include/messagelist.h" #include "../../include/option.h" +#include "../../include/nntp/extensiontrust.h" #include @@ -148,6 +149,7 @@ const bool NNTPConnection::HandleCapabilitiesCommand(const NNTPCommand &command) { SendBufferedLine("AUTHINFO USER"); } + SendBufferedLine("XFMSTRUST"); SendBufferedLine("."); return true; @@ -227,6 +229,18 @@ const bool NNTPConnection::HandleCommand(const NNTPCommand &command) { return HandleAuthInfoCommand(command); } + if(command.m_command=="XGETTRUST") + { + return HandleGetTrustCommand(command); + } + if(command.m_command=="XSETTRUST") + { + return HandleSetTrustCommand(command); + } + if(command.m_command=="XGETTRUSTLIST") + { + return HandleGetTrustListCommand(command); + } return false; } @@ -239,6 +253,161 @@ const bool NNTPConnection::HandleDateCommand(const NNTPCommand &command) return true; } +const bool NNTPConnection::HandleGetTrustCommand(const NNTPCommand &command) +{ + if(command.m_arguments.size()>=2) + { + std::string type=command.m_arguments[0]; + StringFunctions::UpperCase(type,type); + if(type=="MESSAGE" || type=="TRUSTLIST" || type=="PEERMESSAGE" || type=="PEERTRUSTLIST") + { + if(m_status.m_authenticated) + { + bool found=false; + int trust=-1; + std::string nntpname=""; + for(int i=1; i=0 && found) + { + std::string truststr=""; + StringFunctions::Convert(trust,truststr); + SendBufferedLine("280 "+truststr); + } + else if(found) + { + SendBufferedLine("281 null"); + } + else + { + SendBufferedLine("480 Identity not found"); + } + + } + else + { + SendBufferedLine("480 User not authenticated"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + return true; +} + +const bool NNTPConnection::HandleGetTrustListCommand(const NNTPCommand &command) +{ + if(m_status.m_authenticated) + { + TrustExtension tr(m_status.m_authuser.GetID()); + std::map trustlist; + if(tr.GetTrustList(trustlist)) + { + SendBufferedLine("280 Trust list follows"); + for(std::map::iterator i=trustlist.begin(); i!=trustlist.end(); i++) + { + std::ostringstream tempstr; + tempstr << (*i).first << "\t"; + if((*i).second.m_localmessagetrust>-1) + { + tempstr << (*i).second.m_localmessagetrust; + } + else + { + tempstr << "null"; + } + tempstr << "\t"; + if((*i).second.m_localtrustlisttrust>-1) + { + tempstr << (*i).second.m_localtrustlisttrust; + } + else + { + tempstr << "null"; + } + tempstr << "\t"; + if((*i).second.m_peermessagetrust>-1) + { + tempstr << (*i).second.m_peermessagetrust; + } + else + { + tempstr << "null"; + } + tempstr << "\t"; + if((*i).second.m_peertrustlisttrust>-1) + { + tempstr << (*i).second.m_peertrustlisttrust; + } + else + { + tempstr << "null"; + } + tempstr << "\t"; + tempstr << (*i).second.m_messagetrustcomment; + tempstr << "\t"; + tempstr << (*i).second.m_trustlisttrustcomment; + + SendBufferedLine(tempstr.str()); + } + SendBufferedLine("."); + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + else + { + SendBufferedLine("480 User not authenticated"); + } + return true; +} + const bool NNTPConnection::HandleGroupCommand(const NNTPCommand &command) { if(command.m_arguments.size()==1) @@ -938,6 +1107,147 @@ void NNTPConnection::HandleReceivedData() } } +const bool NNTPConnection::HandleSetTrustCommand(const NNTPCommand &command) +{ + if(command.m_arguments.size()>=3) + { + std::string type=command.m_arguments[0]; + StringFunctions::UpperCase(type,type); + if(type=="MESSAGE" || type=="TRUSTLIST" || type=="MESSAGECOMMENT" || type=="TRUSTLISTCOMMENT") + { + if(m_status.m_authenticated) + { + bool found=false; + bool valid=false; + int trust=-1; + std::string comment=""; + std::string nntpname=""; + + if(type=="MESSAGE" || type=="TRUSTLIST") + { + for(int i=1; i=-1 && trust<=100) + { + valid=true; + } + } + else + { + int startpos=-1; + // get nntpname + for(int i=1; i0 && command.m_arguments[i][0]!='\"') + { + if(i!=1) + { + nntpname+=" "; + } + nntpname+=command.m_arguments[i]; + } + else + { + startpos=i; + } + } + + // get comment + for(int i=startpos; i0 && comment[0]=='\"') + { + comment.erase(0,1); + } + if(comment.size()>0 && comment[comment.size()-1]=='\"') + { + comment.erase(comment.size()-1); + } + + valid=true; + } + + TrustExtension tr(m_status.m_authuser.GetID()); + + if(type=="MESSAGE") + { + if(tr.SetMessageTrust(nntpname,trust)) + { + found=true; + } + } + if(type=="TRUSTLIST") + { + if(tr.SetTrustListTrust(nntpname,trust)) + { + found=true; + } + } + if(type=="MESSAGECOMMENT") + { + if(tr.SetMessageTrustComment(nntpname,comment)) + { + found=true; + } + } + if(type=="TRUSTLISTCOMMENT") + { + if(tr.SetTrustListTrustComment(nntpname,comment)) + { + found=true; + } + } + + if(found && valid) + { + SendBufferedLine("280 Trust Set"); + } + else if(found==false) + { + SendBufferedLine("480 Identity not found"); + } + else + { + SendBufferedLine("501 Syntax error"); + } + + } + else + { + SendBufferedLine("480 User not authenticated"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + } + else + { + SendBufferedLine("501 Syntax error"); + } + return true; +} + const bool NNTPConnection::HandleStatCommand(const NNTPCommand &command) { SendArticleParts(command);