X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fnntpconnection.cpp;h=84d07ffd98a592eedc2885bbdcd2a0fdfdb173b8;hb=278ee758050cb7772cd95946688c5b40104f4d8b;hp=99914cd3cea7694b093d0439ed3dfbde66917cfa;hpb=1230cc420c955e75051d011d964bc68f061ba08c;p=fms.git diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index 99914cd..84d07ff 100644 --- a/src/nntp/nntpconnection.cpp +++ b/src/nntp/nntpconnection.cpp @@ -1,17 +1,17 @@ #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 @@ -247,9 +247,8 @@ const bool NNTPConnection::HandleCommand(const NNTPCommand &command) 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; } @@ -268,6 +267,10 @@ const bool NNTPConnection::HandleGetTrustCommand(const NNTPCommand &command) std::string nntpname=""; for(int i=1; i > trustlist; + std::map trustlist; if(tr.GetTrustList(trustlist)) { SendBufferedLine("280 Trust list follows"); - for(std::map >::iterator i=trustlist.begin(); i!=trustlist.end(); i++) + for(std::map::iterator i=trustlist.begin(); i!=trustlist.end(); i++) { std::ostringstream tempstr; tempstr << (*i).first << "\t"; - if((*i).second.first>-1) + if((*i).second.m_localmessagetrust>-1) { - tempstr << (*i).second.first; + tempstr << (*i).second.m_localmessagetrust; } else { tempstr << "null"; } tempstr << "\t"; - if((*i).second.second>-1) + 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.second; + 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("."); @@ -408,7 +434,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; @@ -581,7 +607,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; @@ -638,7 +664,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) @@ -697,18 +723,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; @@ -718,16 +744,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 { @@ -739,27 +772,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"); @@ -779,7 +814,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; @@ -1050,7 +1085,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); } } @@ -1086,26 +1121,76 @@ const bool NNTPConnection::HandleSetTrustCommand(const NNTPCommand &command) { std::string type=command.m_arguments[0]; StringFunctions::UpperCase(type,type); - if(type=="MESSAGE" || type=="TRUSTLIST") + 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=""; - for(int i=1; i=-1 && trust<=100) + if(trust>=-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; } @@ -1125,6 +1210,20 @@ const bool NNTPConnection::HandleSetTrustCommand(const NNTPCommand &command) 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) { @@ -1169,11 +1268,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; @@ -1221,10 +1320,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(); @@ -1241,7 +1347,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) @@ -1486,7 +1592,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) { @@ -1494,7 +1600,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()); } } @@ -1511,7 +1617,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()); } } }