diff options
author | Peter Powell <petpow@saberuk.com> | 2014-05-02 16:39:40 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-06-25 14:31:25 +0200 |
commit | da9adf9e29a1e7e0f914b494972013d0c0c35672 (patch) | |
tree | b60b2cf59602a93b7a3c550ca6c39c38c0b888fe /src | |
parent | d2760311db1446951b6a3894f7dc1f6a8f3ee931 (diff) |
Add formatting to InspIRCd::TimeString; switch all code to use it.
m_httpd also now uses the correct timestamp format.
Windows-specific fixes by @attilamolnar, original PR #849
Diffstat (limited to 'src')
-rw-r--r-- | src/coremods/core_info/cmd_time.cpp | 6 | ||||
-rw-r--r-- | src/filelogger.cpp | 5 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 12 | ||||
-rw-r--r-- | src/modules/m_alltime.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_httpd.cpp | 7 |
5 files changed, 14 insertions, 20 deletions
diff --git a/src/coremods/core_info/cmd_time.cpp b/src/coremods/core_info/cmd_time.cpp index 6a10dc327..95cfb12fd 100644 --- a/src/coremods/core_info/cmd_time.cpp +++ b/src/coremods/core_info/cmd_time.cpp @@ -32,12 +32,8 @@ CmdResult CommandTime::Handle (const std::vector<std::string>& parameters, User if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName) return CMD_SUCCESS; - time_t local = ServerInstance->Time(); - struct tm* timeinfo = localtime(&local); - const std::string& humanTime = asctime(timeinfo); - user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(), - ServerInstance->Config->ServerName.c_str(), humanTime.c_str()); + ServerInstance->Config->ServerName.c_str(), InspIRCd::TimeString(ServerInstance->Time()).c_str()); return CMD_SUCCESS; } diff --git a/src/filelogger.cpp b/src/filelogger.cpp index edb753a50..5786758da 100644 --- a/src/filelogger.cpp +++ b/src/filelogger.cpp @@ -45,10 +45,7 @@ void FileLogStream::OnLog(LogLevel loglevel, const std::string &type, const std: if (ServerInstance->Time() != LAST) { - time_t local = ServerInstance->Time(); - struct tm *timeinfo = localtime(&local); - - TIMESTR.assign(asctime(timeinfo), 24); + TIMESTR = InspIRCd::TimeString(ServerInstance->Time()); LAST = ServerInstance->Time(); } diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 6316d1e34..9ad481bb8 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -403,7 +403,7 @@ const char* InspIRCd::Format(const char* formatString, ...) return ret; } -std::string InspIRCd::TimeString(time_t curtime) +std::string InspIRCd::TimeString(time_t curtime, const char* format) { #ifdef _WIN32 if (curtime < 0) @@ -424,7 +424,15 @@ std::string InspIRCd::TimeString(time_t curtime) else if (timeinfo->tm_year + 1900 < 1000) timeinfo->tm_year = 0; - return std::string(asctime(timeinfo),24); + // This is the default format used by asctime without the terminating new line. + if (!format) + format = "%a %b %d %H:%M:%S %Y"; + + char buffer[512]; + if (!strftime(buffer, sizeof(buffer), format, timeinfo)) + buffer[0] = '\0'; + + return buffer; } std::string InspIRCd::GenRandomStr(int length, bool printable) diff --git a/src/modules/m_alltime.cpp b/src/modules/m_alltime.cpp index 58f7c4fb5..ceee4abbc 100644 --- a/src/modules/m_alltime.cpp +++ b/src/modules/m_alltime.cpp @@ -31,9 +31,7 @@ class CommandAlltime : public Command CmdResult Handle(const std::vector<std::string> ¶meters, User *user) { - char fmtdate[64]; - time_t now = ServerInstance->Time(); - strftime(fmtdate, sizeof(fmtdate), "%Y-%m-%d %H:%M:%S", gmtime(&now)); + const std::string fmtdate = InspIRCd::TimeString(ServerInstance->Time(), "%Y-%m-%d %H:%M:%S"); std::string msg = ":" + ServerInstance->Config->ServerName + " NOTICE " + user->nick + " :System time is " + fmtdate + " (" + ConvToStr(ServerInstance->Time()) + ") on " + ServerInstance->Config->ServerName; diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index dda39afec..efd285f8c 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -185,12 +185,7 @@ class HttpServerSocket : public BufferedSocket WriteData(http_version + " "+ConvToStr(response)+" "+Response(response)+"\r\n"); - time_t local = ServerInstance->Time(); - struct tm *timeinfo = gmtime(&local); - char *date = asctime(timeinfo); - date[strlen(date) - 1] = '\0'; - rheaders.CreateHeader("Date", date); - + rheaders.CreateHeader("Date", InspIRCd::TimeString(ServerInstance->Time(), "%a, %d %b %Y %H:%M:%S GMT")); rheaders.CreateHeader("Server", INSPIRCD_BRANCH); rheaders.SetHeader("Content-Length", ConvToStr(size)); |