version 0.3.0
[fms.git] / src / nntp / nntpconnection.cpp
index eecbec6..6e53237 100644 (file)
@@ -1,17 +1,17 @@
 #include "../../include/nntp/nntpconnection.h"\r
 #include "../../include/nntp/uwildmat.h"\r
 #include "../../include/stringfunctions.h"\r
-#include "../../include/datetime.h"\r
 #include "../../include/boardlist.h"\r
 #include "../../include/message.h"\r
 #include "../../include/messagelist.h"\r
 #include "../../include/option.h"\r
 #include "../../include/nntp/extensiontrust.h"\r
+#include "../../include/threadwrapper/cancelablethread.h"\r
 \r
 #include <algorithm>\r
-\r
-//#include <zthread/Thread.h>\r
-#include "../../include/pthreadwrapper/thread.h"\r
+#include <Poco/DateTime.h>\r
+#include <Poco/DateTimeFormatter.h>\r
+#include <Poco/Timestamp.h>\r
 \r
 #ifdef XMEM\r
        #include <xmem.h>\r
@@ -247,9 +247,8 @@ const bool NNTPConnection::HandleCommand(const NNTPCommand &command)
 \r
 const bool NNTPConnection::HandleDateCommand(const NNTPCommand &command)\r
 {\r
-       DateTime now;\r
-       now.SetToGMTime();\r
-       SendBufferedLine("111 "+now.Format("%Y%m%d%H%M%S"));\r
+       Poco::DateTime now;\r
+       SendBufferedLine("111 "+Poco::DateTimeFormatter::format(now,"%Y%m%d%H%M%S"));\r
        return true;\r
 }\r
 \r
@@ -435,7 +434,7 @@ const bool NNTPConnection::HandleGroupCommand(const NNTPCommand &command)
        else\r
        {\r
                SendBufferedLine("501 Syntax error");\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleGroupCommand syntax error");\r
+               m_log->debug("NNTPConnection::HandleGroupCommand syntax error");\r
        }\r
 \r
        return true;\r
@@ -608,7 +607,7 @@ const bool NNTPConnection::HandleListCommand(const NNTPCommand &command)
        {\r
                // unknown arg\r
                SendBufferedLine("501 Syntax error");\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleListCommand unhandled LIST variant");\r
+               m_log->debug("NNTPConnection::HandleListCommand unhandled LIST variant");\r
        }\r
 \r
        return true;\r
@@ -665,7 +664,7 @@ const bool NNTPConnection::HandleListGroupCommand(const NNTPCommand &command)
        {\r
                // unknown arg\r
                SendBufferedLine("501 Syntax error");\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleListGroupCommand unknown arguments");\r
+               m_log->debug("NNTPConnection::HandleListGroupCommand unknown arguments");\r
        }\r
 \r
        if(validgroup)\r
@@ -724,18 +723,18 @@ const bool NNTPConnection::HandleModeCommand(const NNTPCommand &command)
                                SendBufferedLine("201 Posting prohibited");\r
                        }\r
                        \r
-                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleModeCommand set mode to reader");\r
+                       m_log->debug("NNTPConnection::HandleModeCommand set mode to reader");\r
                }\r
                else\r
                {\r
                        SendBufferedLine("501 Syntax error");\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleModeCommand unknown MODE argument : "+arg);\r
+                       m_log->debug("NNTPConnection::HandleModeCommand unknown MODE argument : "+arg);\r
                }\r
        }\r
        else\r
        {\r
                SendBufferedLine("501 Syntax error");\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleModeCommand no argument supplied for MODE");     \r
+               m_log->debug("NNTPConnection::HandleModeCommand no argument supplied for MODE");        \r
        }\r
 \r
        return true;\r
@@ -745,16 +744,23 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command)
 {\r
        if(command.m_arguments.size()>=2)\r
        {\r
-               DateTime date;\r
-               int tempint;\r
+               Poco::DateTime date;\r
+               int tempyear=0;\r
+               int tempmonth=0;\r
+               int tempday=0;\r
                if(command.m_arguments[0].size()==8)\r
                {\r
-                       StringFunctions::Convert(command.m_arguments[0].substr(0,4),tempint);\r
-                       date.SetYear(tempint);\r
-                       StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempint);\r
-                       date.SetMonth(tempint);\r
-                       StringFunctions::Convert(command.m_arguments[0].substr(6,2),tempint);\r
-                       date.SetDay(tempint);\r
+                       StringFunctions::Convert(command.m_arguments[0].substr(0,4),tempyear);\r
+                       StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempmonth);\r
+                       StringFunctions::Convert(command.m_arguments[0].substr(6,2),tempday);\r
+                       try\r
+                       {\r
+                               date.assign(tempyear,tempmonth,tempday,date.hour(),date.minute(),date.second());\r
+                       }\r
+                       catch(...)\r
+                       {\r
+                               m_log->fatal("NNTPConnection::HandleNewGroupsCommand error assigning date");\r
+                       }\r
                }\r
                else\r
                {\r
@@ -766,27 +772,29 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command)
                        the current year, and the previous century otherwise.\r
                        */\r
                        int century;\r
-                       DateTime now;\r
-                       now.SetToGMTime();\r
-                       century=now.GetYear()-(now.GetYear()%100);\r
+                       Poco::DateTime now;\r
+                       century=now.year()-(now.year()%100);\r
 \r
-                       StringFunctions::Convert(command.m_arguments[0].substr(0,2),tempint);\r
-                       tempint<=now.GetYear()-century ? tempint+=century : tempint+=(century-100);\r
+                       StringFunctions::Convert(command.m_arguments[0].substr(0,2),tempyear);\r
+                       tempyear<=now.year()-century ? tempyear+=century : tempyear+=(century-100);\r
                        \r
                        //tempint > 50 ? tempint+=1900 : tempint+=2000;\r
                        \r
-                       date.SetYear(tempint);\r
-                       StringFunctions::Convert(command.m_arguments[0].substr(2,2),tempint);\r
-                       date.SetMonth(tempint);\r
-                       StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempint);\r
-                       date.SetDay(tempint);\r
+                       StringFunctions::Convert(command.m_arguments[0].substr(2,2),tempmonth);\r
+                       StringFunctions::Convert(command.m_arguments[0].substr(4,2),tempday);\r
+                       try\r
+                       {\r
+                               date.assign(tempyear,tempmonth,tempday);\r
+                       }\r
+                       catch(...)\r
+                       {\r
+                               m_log->fatal("NNTPConnection::HandleNewGroupsCommand error assigning date");\r
+                       }\r
                }\r
 \r
-               date.Normalize();\r
-\r
                BoardList bl;\r
 \r
-               bl.LoadNew(date.Format("%Y-%m-%d %H:%M:%S"));\r
+               bl.LoadNew(Poco::DateTimeFormatter::format(date,"%Y-%m-%d %H:%M:%S"));\r
 \r
                SendBufferedLine("231 List of new newsgroups follows");\r
 \r
@@ -806,7 +814,7 @@ const bool NNTPConnection::HandleNewGroupsCommand(const NNTPCommand &command)
        else\r
        {\r
                SendBufferedLine("501 Syntax error");\r
-               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleNewGroupsCommand syntax error");\r
+               m_log->debug("NNTPConnection::HandleNewGroupsCommand syntax error");\r
        }\r
 \r
        return true;\r
@@ -1077,7 +1085,7 @@ void NNTPConnection::HandleReceivedData()
                        {\r
                                SendBufferedLine("500 Unknown command");\r
 \r
-                               m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPConnection::HandleReceivedData received unhandled NNTP command : "+commandline);\r
+                               m_log->debug("NNTPConnection::HandleReceivedData received unhandled NNTP command : "+commandline);\r
                        }\r
 \r
                }\r
@@ -1260,11 +1268,11 @@ const bool NNTPConnection::HandleQuitCommand(const NNTPCommand &command)
        SendBufferedLine("205 Connection Closing");\r
        SocketSend();\r
        Disconnect();\r
-       m_log->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPConnection::HandleQuitCommand client closed connection");\r
+       m_log->information("NNTPConnection::HandleQuitCommand client closed connection");\r
        return true;\r
 }\r
 \r
-void NNTPConnection::Run()\r
+void NNTPConnection::run()\r
 {\r
        struct timeval tv;\r
        fd_set writefs,readfs;\r
@@ -1312,10 +1320,9 @@ void NNTPConnection::Run()
                }\r
                else if(rval==SOCKET_ERROR)\r
                {\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::run select returned -1 : "+GetSocketErrorMessage());   \r
+                       m_log->error("NNTPConnection::run select returned -1 : "+GetSocketErrorMessage());      \r
                }\r
 \r
-//     }while(!Disconnected() && !ZThread::Thread::interrupted());\r
        }while(!Disconnected() && !IsCancelled());\r
 \r
        Disconnect();\r
@@ -1332,7 +1339,7 @@ void NNTPConnection::SendArticleOverInfo(Message &message)
        line=tempval+"\t";\r
        line+=message.GetSubject()+"\t";\r
        line+=message.GetFromName()+"\t";\r
-       line+=message.GetDateTime().Format("%a, %d %b %y %H:%M:%S -0000")+"\t";\r
+       line+=Poco::DateTimeFormatter::format(message.GetDateTime(),"%w, %d %b %y %H:%M:%S -0000")+"\t";\r
        line+=message.GetNNTPArticleID()+"\t";\r
        references=message.GetInReplyTo();\r
        if(references.size()>0)\r
@@ -1577,7 +1584,7 @@ void NNTPConnection::SocketReceive()
        else if(rval==0)\r
        {\r
                Disconnect();\r
-               m_log->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPConnection::SocketReceive remote host closed connection");\r
+               m_log->information("NNTPConnection::SocketReceive remote host closed connection");\r
        }\r
        else if(rval==-1)\r
        {\r
@@ -1585,7 +1592,7 @@ void NNTPConnection::SocketReceive()
                StringFunctions::Convert(GetSocketErrorNumber(),errnostr);\r
                // error on receive - close the connection\r
                Disconnect();\r
-               m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketReceive recv returned -1 : "+errnostr+" - "+GetSocketErrorMessage());\r
+               m_log->error("NNTPConnection::SocketReceive recv returned -1 : "+errnostr+" - "+GetSocketErrorMessage());\r
        }\r
 }\r
 \r
@@ -1602,7 +1609,7 @@ void NNTPConnection::SocketSend()
                {\r
                        std::string errnostr;\r
                        StringFunctions::Convert(GetSocketErrorNumber(),errnostr);\r
-                       m_log->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPConnection::SocketSend returned -1 : "+errnostr+" - "+GetSocketErrorMessage());\r
+                       m_log->error("NNTPConnection::SocketSend returned -1 : "+errnostr+" - "+GetSocketErrorMessage());\r
                }\r
        }\r
 }\r