X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fnntpconnection.cpp;fp=src%2Fnntp%2Fnntpconnection.cpp;h=6e53237d3c183b0640406dcdcd7dfb48e7b3dd2c;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=eecbec605844ac1c1ef1d0ecebf7ad60591a481f;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af;p=fms.git diff --git a/src/nntp/nntpconnection.cpp b/src/nntp/nntpconnection.cpp index eecbec6..6e53237 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; } @@ -435,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; @@ -608,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; @@ -665,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) @@ -724,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; @@ -745,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 { @@ -766,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"); @@ -806,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; @@ -1077,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); } } @@ -1260,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; @@ -1312,10 +1320,9 @@ 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()); } -// }while(!Disconnected() && !ZThread::Thread::interrupted()); }while(!Disconnected() && !IsCancelled()); Disconnect(); @@ -1332,7 +1339,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) @@ -1577,7 +1584,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) { @@ -1585,7 +1592,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()); } } @@ -1602,7 +1609,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()); } } }