X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fnntpconnection.cpp;h=0212e239b8149c87a786193301dc45c847229299;hb=221236a4d3aac4144529d418ce368db5c98facb0;hp=b3eeecc583734ef824dcc2c111a0a01a58546768;hpb=0574a75431d98ed64c5cc6291600bb3759b399a6;p=fms.git diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index b3eeecc..0212e23 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -1,26 +1,26 @@ #include "../../include/nntp/nntpconnection.h" #include "../../include/nntp/uwildmat.h" #include "../../include/stringfunctions.h" -#include "../../include/datetime.h" #include "../../include/boardlist.h" #include "../../include/message.h" #include "../../include/messagelist.h" #include "../../include/option.h" +#include "../../include/nntp/extensiontrust.h" +#include "../../include/threadwrapper/cancelablethread.h" #include - -//#include -#include "../../include/pthreadwrapper/thread.h" +#include +#include +#include #ifdef XMEM #include #endif -NNTPConnection::NNTPConnection(SOCKET sock) +NNTPConnection::NNTPConnection(SOCKET sock):m_socket(sock) { - std::string tempval; + std::string tempval(""); - m_socket=sock; m_tempbuffer.resize(32768); m_status.m_isposting=false; @@ -148,6 +148,7 @@ const bool NNTPConnection::HandleCapabilitiesCommand(const NNTPCommand &command) { SendBufferedLine("AUTHINFO USER"); } + SendBufferedLine("XFMSTRUST"); SendBufferedLine("."); return true; @@ -227,15 +228,181 @@ 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; } const bool NNTPConnection::HandleDateCommand(const NNTPCommand &command) { - DateTime now; - now.SetToGMTime(); - SendBufferedLine("111 "+now.Format("%Y%m%d%H%M%S")); + Poco::DateTime now; + SendBufferedLine("111 "+Poco::DateTimeFormatter::format(now,"%Y%m%d%H%M%S")); + 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; } @@ -266,7 +433,7 @@ const bool NNTPConnection::HandleGroupCommand(const NNTPCommand &command) else { SendBufferedLine("501 Syntax error"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleGroupCommand syntax error"); + m_log->debug("NNTPConnection::HandleGroupCommand syntax error"); } return true; @@ -439,7 +606,7 @@ const bool NNTPConnection::HandleListCommand(const NNTPCommand &command) { // unknown arg SendBufferedLine("501 Syntax error"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleListCommand unhandled LIST variant"); + m_log->debug("NNTPConnection::HandleListCommand unhandled LIST variant"); } return true; @@ -496,7 +663,7 @@ const bool NNTPConnection::HandleListGroupCommand(const NNTPCommand &command) { // unknown arg SendBufferedLine("501 Syntax error"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleListGroupCommand unknown arguments"); + m_log->debug("NNTPConnection::HandleListGroupCommand unknown arguments"); } if(validgroup) @@ -555,18 +722,18 @@ const bool NNTPConnection::HandleModeCommand(const NNTPCommand &command) SendBufferedLine("201 Posting prohibited"); } - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleModeCommand set mode to reader"); + m_log->debug("NNTPConnection::HandleModeCommand set mode to reader"); } else { SendBufferedLine("501 Syntax error"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleModeCommand unknown MODE argument : "+arg); + m_log->debug("NNTPConnection::HandleModeCommand unknown MODE argument : "+arg); } } else { SendBufferedLine("501 Syntax error"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleModeCommand no argument supplied for MODE"); + m_log->debug("NNTPConnection::HandleModeCommand no argument supplied for MODE"); } return true; @@ -576,16 +743,23 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command) { if(command.m_arguments.size()>=2) { - DateTime date; - int tempint; + Poco::DateTime date; + int tempyear=0; + int tempmonth=0; + int tempday=0; if(command.m_arguments[0].size()==8) { - StringFunctions::Convert(command.m_arguments[0].substr(0,4),tempint); - date.SetYear(tempint); - StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempint); - date.SetMonth(tempint); - StringFunctions::Convert(command.m_arguments[0].substr(6,2),tempint); - date.SetDay(tempint); + StringFunctions::Convert(command.m_arguments[0].substr(0,4),tempyear); + StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempmonth); + StringFunctions::Convert(command.m_arguments[0].substr(6,2),tempday); + try + { + date.assign(tempyear,tempmonth,tempday,date.hour(),date.minute(),date.second()); + } + catch(...) + { + m_log->fatal("NNTPConnection::HandleNewGroupsCommand error assigning date"); + } } else { @@ -597,27 +771,29 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command) the current year, and the previous century otherwise. */ int century; - DateTime now; - now.SetToGMTime(); - century=now.GetYear()-(now.GetYear()%100); + Poco::DateTime now; + century=now.year()-(now.year()%100); - StringFunctions::Convert(command.m_arguments[0].substr(0,2),tempint); - tempint<=now.GetYear()-century ? tempint+=century : tempint+=(century-100); + StringFunctions::Convert(command.m_arguments[0].substr(0,2),tempyear); + tempyear<=now.year()-century ? tempyear+=century : tempyear+=(century-100); //tempint > 50 ? tempint+=1900 : tempint+=2000; - date.SetYear(tempint); - StringFunctions::Convert(command.m_arguments[0].substr(2,2),tempint); - date.SetMonth(tempint); - StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempint); - date.SetDay(tempint); + StringFunctions::Convert(command.m_arguments[0].substr(2,2),tempmonth); + StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempday); + try + { + date.assign(tempyear,tempmonth,tempday); + } + catch(...) + { + m_log->fatal("NNTPConnection::HandleNewGroupsCommand error assigning date"); + } } - date.Normalize(); - BoardList bl; - bl.LoadNew(date.Format("%Y-%m-%d %H:%M:%S")); + bl.LoadNew(Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S")); SendBufferedLine("231 List of new newsgroups follows"); @@ -637,7 +813,7 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command) else { SendBufferedLine("501 Syntax error"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleNewGroupsCommand syntax error"); + m_log->debug("NNTPConnection::HandleNewGroupsCommand syntax error"); } return true; @@ -908,7 +1084,7 @@ void NNTPConnection::HandleReceivedData() { SendBufferedLine("500 Unknown command"); - m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleReceivedData received unhandled NNTP command : "+commandline); + m_log->debug("NNTPConnection::HandleReceivedData received unhandled NNTP command : "+commandline); } } @@ -938,6 +1114,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); @@ -950,11 +1267,11 @@ const bool NNTPConnection::HandleQuitCommand(const NNTPCommand &command) SendBufferedLine("205 Connection Closing"); SocketSend(); Disconnect(); - m_log->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPConnection::HandleQuitCommand client closed connection"); + m_log->information("NNTPConnection::HandleQuitCommand client closed connection"); return true; } -void NNTPConnection::Run() +void NNTPConnection::run() { struct timeval tv; fd_set writefs,readfs; @@ -1002,10 +1319,17 @@ void NNTPConnection::Run() } else if(rval==SOCKET_ERROR) { - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::run select returned -1 : "+GetSocketErrorMessage()); + m_log->error("NNTPConnection::run select returned -1 : "+GetSocketErrorMessage()); + } + + //process all remaining commands in buffer + std::vector::size_type rbs=0; + while(rbs!=m_receivebuffer.size()) + { + rbs=m_receivebuffer.size(); + HandleReceivedData(); } -// }while(!Disconnected() && !ZThread::Thread::interrupted()); }while(!Disconnected() && !IsCancelled()); Disconnect(); @@ -1022,7 +1346,7 @@ void NNTPConnection::SendArticleOverInfo(Message &message) line=tempval+"\t"; line+=message.GetSubject()+"\t"; line+=message.GetFromName()+"\t"; - line+=message.GetDateTime().Format("%a, %d %b %y %H:%M:%S -0000")+"\t"; + line+=Poco::DateTimeFormatter::format(message.GetDateTime(),"%w, %d %b %y %H:%M:%S -0000")+"\t"; line+=message.GetNNTPArticleID()+"\t"; references=message.GetInReplyTo(); if(references.size()>0) @@ -1267,7 +1591,7 @@ void NNTPConnection::SocketReceive() else if(rval==0) { Disconnect(); - m_log->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPConnection::SocketReceive remote host closed connection"); + m_log->information("NNTPConnection::SocketReceive remote host closed connection"); } else if(rval==-1) { @@ -1275,7 +1599,7 @@ void NNTPConnection::SocketReceive() StringFunctions::Convert(GetSocketErrorNumber(),errnostr); // error on receive - close the connection Disconnect(); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketReceive recv returned -1 : "+errnostr+" - "+GetSocketErrorMessage()); + m_log->error("NNTPConnection::SocketReceive recv returned -1 : "+errnostr+" - "+GetSocketErrorMessage()); } } @@ -1292,7 +1616,7 @@ void NNTPConnection::SocketSend() { std::string errnostr; StringFunctions::Convert(GetSocketErrorNumber(),errnostr); - m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketSend returned -1 : "+errnostr+" - "+GetSocketErrorMessage()); + m_log->error("NNTPConnection::SocketSend returned -1 : "+errnostr+" - "+GetSocketErrorMessage()); } } }