std::string getHTTPHeaderTimestamp () { // CHECKME This is probably called often enough that optimizing it makes // sense. There's no point in doing all this work if this function // gets called multiple times a second. char buffer[96]; time_t now; time (&now); struct tm now_gmt{}; #ifndef _MSC_VER gmtime_r(&now, &now_gmt); #else gmtime_s(&now_gmt, &now); #endif strftime (buffer, sizeof (buffer), "Date: %a, %d %b %Y %H:%M:%S +0000\r\n", &now_gmt); return std::string (buffer); }
/* Format Timestamp from EventLog */ char * TimeToString(DWORD dw) { time_t tt; struct tm stm; char result[32]; static char * formatted_result = "YYYY-mm-DDTHH:MM:ssz"; tt = (time_t) dw; /* Format timestamp string */ if (gmtime_s(&stm, &tt) == 0) { strftime(result, sizeof(result), "%Y-%m-%dT%H:%M:%SZ", &stm); } else result[0] = '\0'; strncpy_s(formatted_result, sizeof(result), result, _TRUNCATE); return formatted_result; }
std::string CTimeStamp::ToShortGMTString() const { char TimeString[128]; //struct tm* Tm = gmtime(&m_TimeB.time); struct tm Tm; errno_t err = gmtime_s(&Tm, &m_TimeB.time); Assert(err == 0); if (err != 0) return std::string("!!Error!!"); const char* Format = "%d.%m.%y [%H:%M:%S."; strftime(TimeString, sizeof TimeString, Format, &Tm); char MilliString[5]; sprintf_s(MilliString, "%03u]", m_TimeB.millitm); return std::string(TimeString) + MilliString; }
/* prettify date/time */ static char *prettify_date(u8 *data, size_t length) { if (data != NULL && length == 4) { time_t time = (time_t) (data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]); struct tm tm; static char result[64]; /* large enough */ #ifdef _WIN32 if (0 != gmtime_s(&tm, &time)) return NULL; #else if (NULL == gmtime_r(&time, &tm)) return NULL; #endif strftime(result, sizeof(result), "%Y-%m-%d %H:%M:%S", &tm); return result; } return NULL; }
void Log::log(const std::string& type, const std::string& message, const long& line, const std::string& function, const std::string& file) { //Get the current time time_t t = time(0); tm *cT = new tm(); gmtime_s(cT, &t); //Find the name of the file unsigned found = file.find_last_of("/\\"); logFile << "[" << cT->tm_hour << ":" << cT->tm_min << ":" << cT->tm_sec << "]:" << "[" << line << "]:" << "[" << function << "]:" << "[" << file.substr(found + 1) << "]:" << type << " - " << message << "\n"; delete cT; }
void HttpServletResponse::SetDateHeader(const std::string& name, long long date) { // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 const char* months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; const char* days[7] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; std::time_t timeep = date / 1000; std::tm t; #ifdef US_PLATFORM_WINDOWS if (gmtime_s(&t, &timeep) != 0) #else if (gmtime_r(&timeep, &t) != nullptr) #endif { char dataStr[30]; int n = snprintf(dataStr, 30, "%s, %02d %s %d %02d:%02d:%02d GMT", days[t.tm_wday], t.tm_mday, months[t.tm_mon], (1900 + t.tm_year), t.tm_hour, t.tm_min, t.tm_sec); if (n < 0) return; this->SetHeader(name, dataStr); } }
/** * Return UTC Unix time as string in ISO date/time format. */ std::string to_iso() const { if (m_timestamp == 0) { return std::string(""); } struct tm tm; time_t sse = seconds_since_epoch(); #ifndef _MSC_VER gmtime_r(&sse, &tm); #else gmtime_s(&tm, &sse); #endif std::string s(timestamp_length, '\0'); /* This const_cast is ok, because we know we have enough space in the string for the format we are using (well at least until the year will have 5 digits). And by setting the size afterwards from the result of strftime we make sure thats set right, too. */ s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length, timestamp_format(), &tm)); return s; }
RoutingKey CreateRoutingKey (const IdentHash& ident) { uint8_t buf[41]; // ident + yyyymmdd memcpy (buf, (const uint8_t *)ident, 32); time_t t = time (nullptr); struct tm tm; // WARNING!!! check if it is correct #ifdef _WIN32 gmtime_s(&tm, &t); // тут возвращается какое-то значение sprintf'ом. может стоит его проверять? // http://msdn.microsoft.com/en-us/library/ce3zzk1k.aspx sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); #else gmtime_r(&t, &tm); // тут возвращается какое-то значение sprintf'ом. может стоит его проверять? sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); #endif RoutingKey key; CryptoPP::SHA256().CalculateDigest(key.hash, buf, 40); return key; }
const char *http_mkrfc1123(char *buf, size_t size, time_t t) { #ifdef ACL_WINDOWS # if _MSC_VER >= 1500 struct tm gmt_buf, *gmt = &gmt_buf; if (gmtime_s(gmt, &t) != 0) gmt = NULL; # else struct tm *gmt = gmtime(&t); # endif #else struct tm gmt_buf, *gmt = gmtime_r(&t, &gmt_buf); #endif buf[0] = 0; if (gmt != NULL) strftime(buf, size - 1, RFC1123_STRFTIME, gmt); return (buf); }
void easily_pcsp(Ini ini, const std::chrono::time_point<std::chrono::system_clock> start, const bool gm_mode) { if (gm_mode) return; try { const time_t minute = static_cast<time_t>(ini.getnum("EPCSP", "time", 0)) * 60; if (minute != 0) { tm end; gmtime_s(&end, &minute); tm current; using clock = std::chrono::system_clock; for (time_t now = clock::to_time_t(clock::now()); current.tm_hour == end.tm_hour && current.tm_min == end.tm_min; now = clock::to_time_t(clock::now()), localtime_s(¤t, &now)) { if (end_flag) return; } mutex.lock(); pcsp_end = true; mutex.unlock(); } } catch (std::exception) {} }
LONG WINAPI exceptionFilter(EXCEPTION_POINTERS *pExceptionInfo) { LONG result = EXCEPTION_CONTINUE_SEARCH; HMODULE hDll = LoadLibraryW(L"DBGHELP.DLL"); if (!hDll) return result; MINIDUMPWRITEDUMP *pDump = reinterpret_cast<MINIDUMPWRITEDUMP*>(GetProcAddress(hDll, "MiniDumpWriteDump")); if (!pDump) return result; MINIDUMP_EXCEPTION_INFORMATION exInfo = { GetCurrentThreadId(), pExceptionInfo, FALSE }; const time_t now = time(0); struct tm timeinfo; gmtime_s(&timeinfo, &now); wcsftime(fileName + lstrlenW(fileName), 16, L"%Y%m%d-%H%M%S", &timeinfo); lstrcatW(fileName, L".dmp"); HANDLE hFile = CreateFileW(fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL); if (hFile == INVALID_HANDLE_VALUE) return result; pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &exInfo, NULL, NULL); CloseHandle(hFile); for (int i = lstrlenW(fileName) - 1; i >= 0; i--) { if ('\\' == fileName[i] || '/' == fileName[i]) { fileName[i] = 0; break; } } lstrcatW(fileName, L"\\crashreport.exe"); ShellExecuteW(NULL, L"open", fileName, NULL, NULL, SW_SHOWNORMAL); return EXCEPTION_EXECUTE_HANDLER; }
static void nn_global_submit_level (int i, struct nn_sock *s, char *name, int value) { /* Length of buffer is: len(hostname) + len(appname) + len(socket_name) + len(timebuf) + len(str(value)) + len(static characters) 63 + 63 + 63 + 20 + 20 + 60 = 289 */ char buf[512]; char timebuf[20]; time_t numtime; struct tm strtime; int len; if(self.print_statistics) { fprintf(stderr, "nanomsg: socket.%s: %s: %d\n", s->socket_name, name, value); } if (self.statistics_socket >= 0) { /* TODO(tailhook) add HAVE_GMTIME_R ifdef */ time(&numtime); #ifdef NN_HAVE_WINDOWS gmtime_s (&strtime, &numtime); #else gmtime_r (&numtime, &strtime); #endif strftime (timebuf, 20, "%Y-%m-%dT%H:%M:%S", &strtime); if(*s->socket_name) { len = sprintf (buf, "ESTP:%s:%s:socket.%s:%s: %sZ 10 %d", self.hostname, self.appname, s->socket_name, name, timebuf, value); } else { len = sprintf (buf, "ESTP:%s:%s:socket.%d:%s: %sZ 10 %d", self.hostname, self.appname, i, name, timebuf, value); } nn_assert (len < (int)sizeof(buf)); (void) nn_send (self.statistics_socket, buf, len, NN_DONTWAIT); } }
std::wstring GetBuildTimeFromAddress(void* codeAddress) { // Get the base of the address reservation. This lets this // function be passed any function or global variable address // in a DLL or EXE. MEMORY_BASIC_INFORMATION memoryInfo; if (VirtualQuery(codeAddress, &memoryInfo, sizeof(memoryInfo)) != sizeof(memoryInfo)) { UIETWASSERT(0); return L""; } void* ModuleHandle = memoryInfo.AllocationBase; // Walk the PE data structures to find the link time stamp. IMAGE_DOS_HEADER *DosHeader = (IMAGE_DOS_HEADER*)ModuleHandle; if (IMAGE_DOS_SIGNATURE != DosHeader->e_magic) { UIETWASSERT(0); return L""; } IMAGE_NT_HEADERS *NTHeader = (IMAGE_NT_HEADERS*)((char *)DosHeader + DosHeader->e_lfanew); if (IMAGE_NT_SIGNATURE != NTHeader->Signature) { UIETWASSERT(0); return L""; } tm linkTime = {}; gmtime_s(&linkTime, (time_t*)&NTHeader->FileHeader.TimeDateStamp); // Print out the module information. The %.24s is necessary to trim // the new line character off of the date string returned by asctime(). // _wasctime_s requires a 26-character buffer. wchar_t ascTimeBuf[26]; _wasctime_s(ascTimeBuf, &linkTime); wchar_t buffer[100]; swprintf_s(buffer, L"%.24s GMT (%08lx)", ascTimeBuf, NTHeader->FileHeader.TimeDateStamp); // Return buffer+4 because we don't need the day of the week. return buffer + 4; }
/* * Wraps `gmtime` functionality for multiple platforms. This * converts a time value to a time structure in UTC. * * Returns 0 on success, -1 on failure. */ static int get_gmtime(NPY_TIME_T *ts, struct tm *tms) { char *func_name = "<unknown>"; #if defined(_WIN32) #if defined(_MSC_VER) && (_MSC_VER >= 1400) if (gmtime_s(tms, ts) != 0) { func_name = "gmtime_s"; goto fail; } #elif defined(__GNUC__) && defined(NPY_MINGW_USE_CUSTOM_MSVCR) if (_gmtime64_s(tms, ts) != 0) { func_name = "_gmtime64_s"; goto fail; } #else struct tm *tms_tmp; tms_tmp = gmtime(ts); if (tms_tmp == NULL) { func_name = "gmtime"; goto fail; } memcpy(tms, tms_tmp, sizeof(struct tm)); #endif #else if (gmtime_r(ts, tms) == NULL) { func_name = "gmtime_r"; goto fail; } #endif return 0; fail: PyErr_Format(PyExc_OSError, "Failed to use '%s' to convert " "to a UTC time", func_name); return -1; }
void LSAPIInit::getCompileTime(LPWSTR pwzValue, size_t cchValue) { IMAGE_DOS_HEADER* dosheader; IMAGE_NT_HEADERS* ntheader; time_t lsexetime; time_t lsapitime; time_t compiletime; // Get the litestep.exe build time. dosheader = (IMAGE_DOS_HEADER*)GetModuleHandle(NULL); ASSERT(dosheader); ASSERT(dosheader->e_magic == IMAGE_DOS_SIGNATURE); ntheader = MakePtr(IMAGE_NT_HEADERS*, dosheader, dosheader->e_lfanew); ASSERT(ntheader); lsexetime = (time_t)(ntheader->FileHeader.TimeDateStamp); // Get the lsapi.dll build time (TODO: don't hardcode "lsapi.dll") dosheader = (IMAGE_DOS_HEADER*)GetModuleHandle(_T("lsapi.dll")); ASSERT(dosheader); ASSERT(dosheader->e_magic == IMAGE_DOS_SIGNATURE); ntheader = MakePtr(IMAGE_NT_HEADERS*, dosheader, dosheader->e_lfanew); ASSERT(ntheader); lsapitime = (time_t)(ntheader->FileHeader.TimeDateStamp); compiletime = std::max(lsexetime, lsapitime); tm timeStruct; if (gmtime_s(&timeStruct, &compiletime) == 0) { wcsftime(pwzValue, cchValue, L"\"Compiled on %b %d %Y at %H:%M:%S UTC\"", &timeStruct); } else { StringCchPrintfW(pwzValue, cchValue, L"\"Compiled at an unknown time\""); } }
int Utility::GetSystemTimeUTC(CString& sTime) { sTime.Empty(); // Get system time in UTC format time_t cur_time; time(&cur_time); char szDateTime[64]; #if _MSC_VER<1400 struct tm* timeinfo = gmtime(&cur_time); strftime(szDateTime, 64, "%Y-%m-%dT%H:%M:%SZ", timeinfo); #else struct tm timeinfo; gmtime_s(&timeinfo, &cur_time); strftime(szDateTime, 64, "%Y-%m-%dT%H:%M:%SZ", &timeinfo); #endif sTime = szDateTime; return 0; }
void os_gmtime(date_t* date, int64_t sec, int64_t nsec) { int64_t overflow_sec = nsec / 1000000000; nsec -= (overflow_sec * 1000000000); if(nsec < 0) { nsec += 1000000000; overflow_sec--; } time_t t = sec + overflow_sec; struct tm tm; #ifdef PLATFORM_IS_WINDOWS gmtime_s(&tm, &t); #else gmtime_r(&t, &tm); #endif tm_to_date(&tm, nsec, date); }
PONY_API void ponyint_gmtime(date_t* date, int64_t sec, int64_t nsec) { time_t overflow_sec = (time_t)(nsec / 1000000000); nsec -= (overflow_sec * 1000000000); if(nsec < 0) { nsec += 1000000000; overflow_sec--; } time_t t = (time_t)sec + overflow_sec; struct tm tm; #ifdef PLATFORM_IS_WINDOWS gmtime_s(&tm, &t); #else gmtime_r(&t, &tm); #endif tm_to_date(&tm, (int)nsec, date); }
LEMON_SYS_API void LemonUTCDateTime( __lemon_inout LemonDateTime * datetime, __lemon_in LemonTime now, __lemon_inout LemonErrorInfo * errorCode){ LEMON_RESET_ERRORINFO(*errorCode); tm current; errno_t error = gmtime_s(¤t,&now.Seconds); if(0 != error){ LEMON_POSIX_ERROR(*errorCode,errno); return; } datetime->Year = current.tm_year + 1900; datetime->Month = current.tm_mon; datetime->DayOfWeek = current.tm_wday; datetime->DayOfYear = current.tm_yday; datetime->DayOfMonth = current.tm_mday; datetime->Hour = current.tm_hour; datetime->Minute = current.tm_min; datetime->Second = current.tm_sec; datetime->Microseconds = now.Microseconds; datetime->UTC = lemon_true; }
// Export a date to RFC 1123 format int Time::toDate(char * buffer, const bool iso8601) const { #if defined(_WIN32) || defined(_POSIX) if (!buffer) return 30; const char * monthName[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; const char * dayName[] = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" }; struct tm ekT = {0}; time_t t = (time_t)preciseTime(); #ifdef _WIN32 gmtime_s(&ekT, &t); #else gmtime_r(&t, &ekT); #endif if (iso8601) return sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02dZ", ekT.tm_year + 1900, ekT.tm_mon + 1, ekT.tm_mday, ekT.tm_hour, ekT.tm_min, ekT.tm_sec); return sprintf(buffer, "%s, %02d %s %04d %02d:%02d:%02d %s", dayName[ekT.tm_wday], ekT.tm_mday, monthName[ekT.tm_mon], ekT.tm_year + 1900, ekT.tm_hour, ekT.tm_min, ekT.tm_sec, "GMT") + 1; #else if (iso8601) return sprintf(buffer, "1970-01-01T00:00:00Z"); strcpy(buffer, "Sun, 01 Jan 1970 00:00:00 GMT"); return strlen(buffer); #endif }
struct tm* gmtime_r(const time_t* clock, struct tm* res) { gmtime_s(res, clock); return res; }
tm* gmtime_r(const time_t *clock, tm *result) { return gmtime_s(result, clock) == 0 ? result : 0; }
void O2ReportMaker:: GetReport(string &out, bool pub) { double ptime; double ptimeavg; int handle_c; int thread_c; PerformanceCounter->GetValue(ptime, ptimeavg, handle_c, thread_c); long tzoffset; _get_timezone(&tzoffset); // start time time_t starttime = PerformanceCounter->GetStartTime(); wchar_t starttime_str[32]; if (starttime != 0) { time_t t = starttime - tzoffset; struct tm tm; gmtime_s(&tm, &t); wcsftime(starttime_str, 32, L"%Y/%m/%d %H:%M:%S", &tm); } else wcscpy_s(starttime_str, 32, L"-"); // uptime uint64 uptime = PerformanceCounter->GetUptime(); wchar_t uptime_str[32]; if (uptime != 0) { swprintf_s(uptime_str, 32, L"%I64dd %02I64d:%02I64d:%02I64d", uptime/86400, (uptime%86400)/3600, (uptime%3600)/60, uptime%60); } else wcscpy_s(uptime_str, 32, L"-"); // uptime (累計) uint64 total_uptime = PerformanceCounter->GetTotalUptime() + uptime; wchar_t total_uptime_str[32]; swprintf_s(total_uptime_str, 32, L"%I64dd %02I64d:%02I64d:%02I64d", total_uptime/86400, (total_uptime%86400)/3600, (total_uptime%3600)/60, total_uptime%60); wchar_t ptime_str[32]; swprintf_s(ptime_str, 32, L"%.1f%% (%.1f%%)", ptime, ptimeavg); // 送受信バイト数 (現在のセッション) uint64 total_u = Server_P2P->GetSendByte() + Client->GetSendByte(); uint64 total_d = Server_P2P->GetRecvByte() + Client->GetRecvByte(); wchar_t traffic_u[32]; swprintf_s(traffic_u, 32, L"%.1f(%.1f)", (uptime == 0 ? 0 : (double)total_u/1024/uptime), (uptime == 0 ? 0 : (double)total_u/uptime*8)); wchar_t traffic_d[32]; swprintf_s(traffic_d, 32, L"%.1f(%.1f)", (uptime == 0 ? 0 : (double)total_d/1024/uptime), (uptime == 0 ? 0 : (double)total_d/uptime*8)); wchar_t traffic_ud[32]; swprintf_s(traffic_ud, 32, L"%.1f(%.1f)", (uptime == 0 ? 0 : (double)(total_u+total_d)/1024/uptime), (uptime == 0 ? 0 : (double)(total_u+total_d)/uptime*8)); // 送受信バイト数 (累計) uint64 accum_total_u = PerformanceCounter->GetTotalSend() + total_u; uint64 accum_total_d = PerformanceCounter->GetTotalRecv() + total_d; wchar_t a_traffic_u[32]; swprintf_s(a_traffic_u, 32, L"%.1f(%.1f)", (total_uptime == 0 ? 0 : (double)accum_total_u/1024/total_uptime), (total_uptime == 0 ? 0 : (double)accum_total_u/total_uptime*8)); wchar_t a_traffic_d[32]; swprintf_s(a_traffic_d, 32, L"%.1f(%.1f)", (total_uptime == 0 ? 0 : (double)accum_total_d/1024/total_uptime), (total_uptime == 0 ? 0 : (double)accum_total_d/total_uptime*8)); wchar_t a_traffic_ud[32]; swprintf_s(a_traffic_ud, 32, L"%.1f(%.1f)", (total_uptime == 0 ? 0 : (double)(accum_total_u+accum_total_d)/1024/total_uptime), (total_uptime == 0 ? 0 : (double)(accum_total_u+accum_total_d)/total_uptime*8)); //dat数、サイズ uint64 datnum = 0; uint64 datsize = 0; uint64 pubnum = 0; DatDB->select_report(PUBLISH_ORIGINAL_TT, datnum, datsize, pubnum); //publish率 wchar_t publishper[32]; if (datnum == 0) wcscpy_s(publishper, 32, L"0.0%"); else { swprintf(publishper, 32, L"%.1f%% (%I64u)", (double)pubnum/datnum*100.0, pubnum); } wstring tmpstr; wstring xml; xml += L"<?xml version=\"1.0\" encoding=\""; xml += _T(DEFAULT_XML_CHARSET); xml += L"\"?>"EOL; if (pub) xml += L"<?xml-stylesheet type=\"text/xsl\" href=\"/profile.xsl\"?>"; xml += L"<report>"EOL; // // 名前、コメント、閲覧履歴 // if (pub) { makeCDATA(Profile->GetNodeNameW(), tmpstr); xml += L"<name>"; xml += tmpstr; xml += L"</name>"EOL; xml += L"<category>"EOL; xml += L"<table>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"ID"); hashT hash; Profile->GetID(hash); wstring hashstr; hash.to_string(hashstr); xml_AddElement(xml, L"td", L"class=\"L\"", hashstr.c_str()); xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"コメント"); makeCDATA(Profile->GetComment(), tmpstr); xml += L" <pre>"; xml += tmpstr; xml += L"</pre>"EOL; xml += L"</tr>"EOL; // if (Profile->IsPublicRecentDat()) { xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"閲覧履歴"); xml += L"<pre>"; O2KeyList recent; Server_Proxy->GetRecentDatList(recent); tmpstr.erase(); for (O2KeyListIt it = recent.begin(); it != recent.end(); it++) { wchar_t timestr[TIMESTR_BUFF_SIZE]; struct tm tm; localtime_s(&tm, &it->date); wcsftime(timestr, TIMESTR_BUFF_SIZE, L"%Y/%m/%d %H:%M:%S", &tm); tmpstr += timestr; tmpstr += L" [ "; tmpstr += it->url; tmpstr += L" ] "; tmpstr += it->title; tmpstr += L"\r\n"; } makeCDATA(tmpstr, tmpstr); xml += tmpstr; xml += L"</pre>"EOL; xml += L"</tr>"EOL; } xml += L"</table>"EOL; xml += L"</category>"EOL; } // // 概要 // if (!pub || Profile->IsPublicReport()) { xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"概要"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"状態"); xml_AddElement(xml, L"td", L"type=\"h\"", L"CPU(平均)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"ハンドル"); xml_AddElement(xml, L"td", L"type=\"h\"", L"スレッド"); xml_AddElement(xml, L"td", L"type=\"h\"", L"総dat数"); xml_AddElement(xml, L"td", L"type=\"h\"", L"総datサイズ"); xml_AddElement(xml, L"td", L"type=\"h\"", L"publish率"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; if (PerformanceCounter->IsActive()) xml_AddElement(xml, L"td", L"class=\"active\"", L"稼動中"); else xml_AddElement(xml, L"td", L"class=\"deactive\"", L"停止中"); xml_AddElement(xml, L"td", L"class=\"C\"", ptime_str); xml_AddElement(xml, L"td", L"class=\"N\"", handle_c); xml_AddElement(xml, L"td", L"class=\"N\"", thread_c); xml_AddElement(xml, L"td", L"class=\"N\"", datnum); xml_AddElement(xml, L"td", L"class=\"N\"", datsize); xml_AddElement(xml, L"td", L"class=\"R\"", publishper); xml += L"</tr>"EOL; xml += L"</table>"EOL; // xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"起動日時"); xml_AddElement(xml, L"td", L"type=\"h\"", L"グローバルIP"); xml_AddElement(xml, L"td", (Server_P2P->IsActive() ? L"type=\"h\" class=\"active\"" : L"type=\"h\" class=\"deactive\""), L"P2P"); xml_AddElement(xml, L"td", (Server_Proxy->IsActive() ? L"type=\"h\" class=\"active\"" : L"type=\"h\" class=\"deactive\""), L"Proxy"); xml_AddElement(xml, L"td", (Server_Admin->IsActive() ? L"type=\"h\" class=\"active\"" : L"type=\"h\" class=\"deactive\""), L"Admin"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Ver"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; wstring ipstr; ulong2ipstr(Profile->GetIP(), ipstr); xml_AddElement(xml, L"td", L"class=\"C\"", starttime_str); xml_AddElement(xml, L"td", L"class=\"C\"", ipstr.c_str()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetP2PPort()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetProxyPort()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetAdminPort()); xml_AddElement(xml, L"td", L"class=\"C\"", Profile->GetUserAgentW()); xml += L"</tr>"EOL; xml += L"</table>"EOL; // xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"稼働時間"); xml_AddElement(xml, L"td", L"type=\"h\"", L"上り"); xml_AddElement(xml, L"td", L"type=\"h\"", L"下り"); xml_AddElement(xml, L"td", L"type=\"h\"", L"合計"); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"上りKB/s(bps)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"下りKB/s(bps)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"合計KB/s(bps)"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"今回"); xml_AddElement(xml, L"td", L"class=\"C\"", uptime_str); xml_AddElement(xml, L"td", L"class=\"N\"", total_u); xml_AddElement(xml, L"td", L"class=\"N\"", total_d); xml_AddElement(xml, L"td", L"class=\"N\"", total_u+total_d); xml_AddElement(xml, L"td", L"", L""); xml_AddElement(xml, L"td", L"class=\"R\"", traffic_u); xml_AddElement(xml, L"td", L"class=\"R\"", traffic_d); xml_AddElement(xml, L"td", L"class=\"R\"", traffic_ud); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"累計"); xml_AddElement(xml, L"td", L"class=\"C\"", total_uptime_str); xml_AddElement(xml, L"td", L"class=\"N\"", accum_total_u); xml_AddElement(xml, L"td", L"class=\"N\"", accum_total_d); xml_AddElement(xml, L"td", L"class=\"N\"", accum_total_u+accum_total_d); xml_AddElement(xml, L"td", L"", L""); xml_AddElement(xml, L"td", L"class=\"R\"", a_traffic_u); xml_AddElement(xml, L"td", L"class=\"R\"", a_traffic_d); xml_AddElement(xml, L"td", L"class=\"R\"", a_traffic_ud); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; // // DB // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"DB"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"Node"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Friend"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Key"); xml_AddElement(xml, L"td", L"type=\"h\"", L"SakuKey"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Query"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Saku"); xml_AddElement(xml, L"td", L"type=\"h\"", L"IM"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Broadcast"); xml_AddElement(xml, L"td", L"type=\"h\"", L"BCQueue"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Logger"); xml_AddElement(xml, L"td", L"type=\"h\"", L"IPFilter"); xml_AddElement(xml, L"td", L"type=\"h\"", L"DatRequest"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"保持数"); xml_AddElement(xml, L"td", L"class=\"N\"", NodeDB->count()); xml_AddElement(xml, L"td", L"class=\"N\"", FriendDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", KeyDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", SakuKeyDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", QueryDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", SakuDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", IMDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", BroadcastDB->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", Job_Broadcast->GetQueueCount()); xml_AddElement(xml, L"td", L"class=\"N\"", Logger->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", IPFilter_P2P->Count()+IPFilter_Proxy->Count()+IPFilter_Admin->Count()); xml_AddElement(xml, L"td", L"class=\"N\"", Job_QueryDat->GetRequestQueueCount()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; // // Server // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"Server"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"dat"); xml_AddElement(xml, L"td", L"type=\"h\"", L"collection"); xml_AddElement(xml, L"td", L"type=\"h\"", L"im"); xml_AddElement(xml, L"td", L"type=\"h\"", L"broadcast"); xml_AddElement(xml, L"td", L"type=\"h\"", L"profile"); xml_AddElement(xml, L"td", L"type=\"h\"", L"ping"); xml_AddElement(xml, L"td", L"type=\"h\"", L"store"); xml_AddElement(xml, L"td", L"type=\"h\"", L"findnode"); xml_AddElement(xml, L"td", L"type=\"h\"", L"findvalue"); xml_AddElement(xml, L"td", L"type=\"h\"", L"ERROR"); xml_AddElement(xml, L"td", L"type=\"h\"", L"?"); xml_AddElement(xml, L"td", L"type=\"h\"", L"計"); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"Proxy"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Admin"); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"接続回数"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath("?")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionCountByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetTotalSessionCount()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetTotalSessionCount()); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("?")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetSendByte()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetSendByte()); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"down"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath("?")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetRecvByteByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetRecvByte()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetRecvByte()); xml += L"</tr>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up + down"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("dat") + Server_P2P->GetRecvByteByPath("dat")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("collection") + Server_P2P->GetRecvByteByPath("collection")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("im") + Server_P2P->GetRecvByteByPath("im")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("broadcast") + Server_P2P->GetRecvByteByPath("broadcast")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("profile") + Server_P2P->GetRecvByteByPath("profile")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ping") + Server_P2P->GetRecvByteByPath("ping")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("store") + Server_P2P->GetRecvByteByPath("store")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findnode") + Server_P2P->GetRecvByteByPath("findnode")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("findvalue") + Server_P2P->GetRecvByteByPath("findvalue")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("ERROR") + Server_P2P->GetRecvByteByPath("ERROR")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath("UNKNOWN") + Server_P2P->GetRecvByteByPath("UNKNOWN")); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSendByteByPath(NULL) + Server_P2P->GetRecvByteByPath(NULL)); xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Proxy->GetSendByte() + Server_Proxy->GetRecvByte()); xml_AddElement(xml, L"td", L"class=\"N\"", Server_Admin->GetRecvByte() + Server_Admin->GetRecvByte()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"同時接続数ピーク"); xml_AddElement(xml, L"td", L"class=\"N\"", Server_P2P->GetSessionPeak()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; // // Agent // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"Agent"); xml += L"<table>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); size_t i; for (i = 0; i < Jobs.size(); i++) { if (Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"type=\"h\" class=\"active\"", Jobs[i]->GetName()); else xml_AddElement(xml, L"td", L"type=\"h\" class=\"deactive\"", Jobs[i]->GetName()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"実行"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"C\"", L"-"); else if (Jobs[i]->IsWorking()) xml_AddElement(xml, L"td", L"class=\"active\"", L"実行中"); else xml_AddElement(xml, L"td", L"class=\"wait\"", L"待機"); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"間隔(s)"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"C\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"C\"", Jobs[i]->GetInterval()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"起動まで"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive() || Jobs[i]->IsWorking()) xml_AddElement(xml, L"td", L"class=\"C\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"C\"", Jobs[i]->GetRemain()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"接続回数"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetTotalSessionCount()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetSendByte()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"down"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetRecvByte()); } xml += L"</tr>"EOL; // xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"up+down"); for (i = 0; i < Jobs.size(); i++) { if (!Jobs[i]->IsActive()) xml_AddElement(xml, L"td", L"class=\"R\"", L"-"); else xml_AddElement(xml, L"td", L"class=\"N\"", Jobs[i]->GetSendByte()+Jobs[i]->GetRecvByte()); } xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L"同時接続数ピーク"); xml_AddElement(xml, L"td", L"class=\"N\"", Client->GetSessionPeak()); xml += L"</tr>"EOL; xml += L"</table>"EOL; xml += L"</category>"EOL; if (O2DEBUG && TRACE_CONNECTIONS && !pub) { // // Connections // xml += L"<category>"EOL; xml_AddElement(xml, L"caption", NULL, L"Connections"); xml += L"<table>"EOL; xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"type=\"h\"", L""); xml_AddElement(xml, L"td", L"type=\"h\"", L"IP"); xml_AddElement(xml, L"td", L"type=\"h\"", L"Port"); xml_AddElement(xml, L"td", L"type=\"h\"", L"接続時間(s)"); xml_AddElement(xml, L"td", L"type=\"h\"", L"recv"); xml_AddElement(xml, L"td", L"type=\"h\"", L"send"); xml_AddElement(xml, L"td", L"type=\"h\"", L"rbuff"); xml += L"</tr>"EOL; O2SocketSessionPList lst; time_t now = time(NULL); Server_P2P->GetSessionList(lst); for (O2SocketSessionPListIt it = lst.begin(); it != lst.end(); it++) { O2SocketSession *ss = *it; wstring e_ip; ip2e(ss->ip, e_ip); xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"class=\"C\"", L"Server"); xml_AddElement(xml, L"td", L"class=\"C\"", e_ip.c_str()); xml_AddElement(xml, L"td", L"class=\"C\"", ss->port); xml_AddElement(xml, L"td", L"class=\"R\"", now - ss->connect_t); xml_AddElement(xml, L"td", L"class=\"N\"", ss->rbuffoffset); xml_AddElement(xml, L"td", L"class=\"N\"", ss->sbuffoffset); wstring rbuff; ascii2unicode(ss->rbuff, rbuff); xml_AddElement(xml, L"td", L"class=\"L\"", rbuff.c_str(), true); xml += L"</tr>"EOL; delete *it; } lst.clear(); Client->GetSessionList(lst); for (O2SocketSessionPListIt it = lst.begin(); it != lst.end(); it++) { O2SocketSession *ss = *it; wstring e_ip; ip2e(ss->ip, e_ip); xml += L"<tr>"EOL; xml_AddElement(xml, L"td", L"class=\"C\"", L"Agent"); xml_AddElement(xml, L"td", L"class=\"C\"", e_ip.c_str()); xml_AddElement(xml, L"td", L"class=\"C\"", ss->port); xml_AddElement(xml, L"td", L"class=\"R\"", now - ss->connect_t); xml_AddElement(xml, L"td", L"class=\"N\"", ss->rbuffoffset); xml_AddElement(xml, L"td", L"class=\"N\"", ss->sbuffoffset); wstring rbuff; ascii2unicode(ss->rbuff, rbuff); xml_AddElement(xml, L"td", L"class=\"L\"", rbuff.c_str(), true); xml += L"</tr>"EOL; delete *it; } xml += L"</table>"EOL; xml += L"</category>"EOL; } } xml += L"</report>"EOL; FromUnicode(_T(DEFAULT_XML_CHARSET), xml, out); }
struct tm * mailcore::win32_gmtime_r(const time_t *clock, struct tm *result) { gmtime_s(result, clock); return result; }
int VtFile_rescanHash(struct VtFile *file_scan, const char *hash, time_t rescan_date, int period, int repeat, const char *notify_url, bool notify_changes_only) { CURL *curl; CURLcode res; int ret = 0; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; char buff[32]; struct tm time_result; static const char header_buf[] = "Expect:"; long http_response_code = 0; VtApiPage_resetBuffer((struct VtApiPage *) file_scan); curl = curl_easy_init(); if (!curl) { VT_ERROR("init curl\n"); goto cleanup; } // initialize custom header list (stating that Expect: 100-continue is not wanted headerlist = curl_slist_append(headerlist, header_buf); DBG(1, "hash to rescan'%s'\n", hash); DBG(1, "Api Key = '%s'\n", file_scan->api_key); ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "resource", CURLFORM_COPYCONTENTS, hash, CURLFORM_END); if (ret) VT_ERROR("Adding hash %s\n", hash); if (rescan_date) { #ifdef WINDOWS if (!gmtime_s(&time_result, &rescan_date)) { VT_ERROR("Converting time\n"); goto cleanup; } #else if (!gmtime_r(&rescan_date, &time_result)) { VT_ERROR("Converting time\n"); goto cleanup; } #endif ret = strftime(buff, sizeof(buff)-1, "%Y%m%d%H%M%S", &time_result); ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "date", CURLFORM_COPYCONTENTS, buff, CURLFORM_END); if (ret) VT_ERROR("Adding date %s\n", buff); } if (period) { snprintf(buff, sizeof(buff) -1, "%d", period); ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "period", CURLFORM_COPYCONTENTS, buff, CURLFORM_END); if (ret) VT_ERROR("Adding period %s\n", buff); } if (repeat) { snprintf(buff, sizeof(buff) - 1 , "%d", repeat); ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "repeat", CURLFORM_COPYCONTENTS, buff, CURLFORM_END); if (ret) VT_ERROR("Adding repeat %s\n", buff); } if (notify_url) { ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "notify_url", CURLFORM_COPYCONTENTS, notify_url, CURLFORM_END); if (ret) VT_ERROR("Adding notify_url %s\n", notify_url); if (notify_changes_only) { ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "notify_changes_only", CURLFORM_COPYCONTENTS, "1", CURLFORM_END); } } ret = curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "apikey", CURLFORM_COPYCONTENTS, file_scan->api_key, CURLFORM_END); if (ret) VT_ERROR("Adding key\n"); curl_easy_setopt(curl, CURLOPT_URL, VT_API_BASE_URL "file/rescan"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); // set form set_std_curl_data(file_scan, curl); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); DBG(1, "Perform done\n"); /* Check for errors */ if(res != CURLE_OK) { VT_ERROR("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); ret = res; goto cleanup; } else { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_response_code); if (http_response_code != 200) { VT_ERROR("HTTP Response code: %ld\n", http_response_code); ret = http_response_code; goto cleanup; } } DBG(1, "Page:\n%s\n",file_scan->buffer); if (file_scan->response) VtResponse_put(&file_scan->response); file_scan->response = VtResponse_new(); ret = VtResponse_fromJSONstr(file_scan->response, file_scan->buffer); if (ret) { VT_ERROR("Parsing JSON\n"); goto cleanup; } cleanup: /* always cleanup */ curl_easy_cleanup(curl); if (formpost) curl_formfree(formpost); // cleanup the formpost chain if (headerlist) curl_slist_free_all (headerlist); // free headers return ret; }
void rfc822::mkdate_cst(time_t t, char *buf, size_t size) { struct tm *p; int offset = 0; #ifdef WIN32 # if _MSC_VER >= 1500 struct tm tm_buf; long s; p = &tm_buf; if (localtime_s(p, &t) != 0) p = NULL; # else p = localtime(&t); # endif #else struct tm tm_buf; p = localtime_r(&t, &tm_buf); #endif buf[0] = 0; if (p == NULL) return; #if USE_TIME_ALTZONE offset = -_timezone; if (p->tm_isdst > 0) offset = -altzone; if (offset % 60) { offset = 0; #ifdef WIN32 # if _MSC_VER >= 1500 p = &tm_buf; if (gmtime_s(p, &t) != 0) p = NULL; # else p = gmtime(&t); # endif #else p = gmtime_r(&t, &tm_buf); #endif } offset /= 60; #else #if USE_TIME_DAYLIGHT #ifdef WIN32 # if _MSC_VER >= 1500 if ( _get_timezone(&s) != 0) s = 0; offset =- s; # else offset = - _timezone; # endif #elif !defined(ACL_FREEBSD) // XXX -zsx offset = - timezone; #endif if (p == NULL) return; if (p->tm_isdst > 0) offset += 60 * 60; if (offset % 60) { offset = 0; #ifdef WIN32 # if _MSC_VER >= 1500 p = &tm_buf; if (gmtime_s(p, &t) != 0) p = NULL; # else p = gmtime(&t); # endif #else p = gmtime_r(&t, &tm_buf); #endif } offset /= 60; #else #if USE_TIME_GMTOFF offset = p->tm_gmtoff; if (offset % 60) { offset = 0; #ifdef WIN32 # if _MSC_VER >= 1500 p = &tm_buf; if (gmtime_s(p, &t) != 0) p = NULL; # else p = gmtime(&t); # endif #else p = gmtime_r(&t, &tm_buf); #endif } offset /= 60; #else #ifdef WIN32 # if _MSC_VER >= 1500 p = &tm_buf; if (gmtime_s(p, &t) != 0) p = NULL; # else p = gmtime(&t); # endif #else p = gmtime_r(&t, &tm_buf); #endif offset = 0; #endif #endif #endif offset = (offset % 60) + offset / 60 * 100; #if defined(WIN32) && _MSC_VER >= 1500 _snprintf_s(buf, size, size, "%s, %02d %s %04d %02d:%02d:%02d %+05d (CST)", wdays[p->tm_wday], p->tm_mday, months[p->tm_mon], p->tm_year + 1900, p->tm_hour, p->tm_min, p->tm_sec, offset); #else snprintf(buf, size, "%s, %02d %s %04d %02d:%02d:%02d %+05d (CST)", wdays[p->tm_wday], p->tm_mday, months[p->tm_mon], p->tm_year + 1900, p->tm_hour, p->tm_min, p->tm_sec, offset); #endif }
tm* gmtime_r(const time_t* t, tm* res) { if (!gmtime_s(res, t)) { return res; } return nullptr; }
void O2IMDB:: MakeIMElement(O2IMessage &im, O2IMSelectCondition &cond, wstring &xml) { wchar_t tmp[16]; wstring tmpstr; xml += L"<message>" EOL; if (cond.mask & IM_XMLELM_IP) { ip2e(im.ip, tmpstr); xml += L" <ip>"; xml += tmpstr; xml += L"</ip>" EOL; } if (cond.mask & IM_XMLELM_PORT) { swprintf_s(tmp, 16, L"%d", im.port); xml += L" <port>"; xml += tmp; xml += L"</port>" EOL; } if (cond.mask & IM_XMLELM_ID) { im.id.to_string(tmpstr); xml += L" <id>"; xml += tmpstr; xml += L"</id>" EOL; } if (cond.mask & IM_XMLELM_PUBKEY) { im.pubkey.to_string(tmpstr); xml += L" <pubkey>"; xml += tmpstr; xml += L"</pubkey>" EOL; } if (cond.mask & IM_XMLELM_NAME) { xml += L" <name>"; xml += im.name; xml += L"</name>" EOL; } if (cond.mask & IM_XMLELM_DATE) { if (im.date == 0) xml += L" <date></date>" EOL; else { long tzoffset; #ifdef _WIN32 /** windows */ _get_timezone(&tzoffset); #else /** unix */ tzoffset = getGmtOffset(); #endif if (!cond.timeformat.empty()) { time_t t = im.date - tzoffset; wchar_t timestr[TIMESTR_BUFF_SIZE]; struct tm tm; #ifdef _WIN32 /** windows */ gmtime_s(&tm, &t); #else /** unix */ gmtime_r(&t, &tm); #endif wcsftime(timestr, TIMESTR_BUFF_SIZE, cond.timeformat.c_str(), &tm); xml += L" <date>"; xml += timestr; xml += L"</date>" EOL; } else { time_t2datetime(im.date, - tzoffset, tmpstr); xml += L" <date>"; xml += tmpstr; xml += L"</date>" EOL; } } } if (cond.mask & IM_XMLELM_MSG) { makeCDATA(im.msg, tmpstr); xml += L" <msg>"; xml += tmpstr; xml += L"</msg>" EOL; } if (cond.mask & IM_XMLELM_KEY) { im.key.to_string(tmpstr); xml += L" <key>"; xml += tmpstr; xml += L"</key>" EOL; } if (cond.mask & IM_XMLELM_MINE) { xml += L" <mine>"; xml += im.mine ? L"1" : L"0"; xml += L"</mine>" EOL; } xml += L"</message>" EOL; }
// converts the supplied string into a 64-bit time object (UTC) uint64_t CTimeSupport::ConvertStringToTime(const string& timeString) { char buffer[26]; struct tm time_tm; char* end_ptr = NULL; // reset the structure time_t convertTimeT = time(NULL); gmtime_s(&time_tm, &convertTimeT); char* pTime = (char*)timeString.c_str(); unsigned char timeLen = (unsigned char)timeString.size(); // establish the month bool foundMonth = false; for(unsigned int i = 0; i < 12; i++) { if(strncmp(pTime + 4, MONTHS[i], 3) == 0) { time_tm.tm_mon = i; foundMonth = true; break; } } if(!foundMonth) { cout << "ERROR: Unable to convert the month when parsing the timestamp." << endl; exit(1); } // establish the day of the month unsigned char startPos = 8; while(pTime[startPos] == ' ') startPos++; unsigned char endPos = startPos; while(pTime[endPos] != ' ') endPos++; unsigned char monthDayLen = endPos - startPos; //bool hasLeadingZero = false; //if((buffer[startPos] == '0') && (monthDayLen > 1)) hasLeadingZero = true; memcpy(buffer, pTime + startPos, monthDayLen); buffer[monthDayLen] = 0; time_tm.tm_mday = (int)strtol(buffer, &end_ptr, 10); if(end_ptr == buffer) { cout << "ERROR: Could not convert the day of the month string to an integer." << endl; exit(1); } // establish the hour startPos = endPos + 1; endPos = startPos; while(pTime[endPos] != ':') endPos++; unsigned int hourLen = endPos - startPos; memcpy(buffer, pTime + startPos, hourLen); buffer[hourLen] = 0; time_tm.tm_hour = (int)strtol(buffer, &end_ptr, 10); if(end_ptr == buffer) { cout << "ERROR: Could not convert the hour string to an integer." << endl; exit(1); } // establish the minutes memcpy(buffer, pTime + startPos + hourLen + 1, 2); buffer[2] = 0; time_tm.tm_min = (int)strtol(buffer, &end_ptr, 10); if(end_ptr == buffer) { cout << "ERROR: Could not convert the minute string to an integer." << endl; exit(1); } // establish the seconds memcpy(buffer, pTime + startPos + hourLen + 4, 2); buffer[2] = 0; time_tm.tm_sec = (int)strtol(buffer, &end_ptr, 10); if(end_ptr == buffer) { cout << "ERROR: Could not convert the second string to an integer." << endl; exit(1); } // establish the year memcpy(buffer, pTime + timeLen - 4, 4); buffer[4] = 0; time_tm.tm_year = (int)strtol(buffer, &end_ptr, 10) - 1900; if(end_ptr == buffer) { cout << "ERROR: Could not convert the year string to an integer." << endl; exit(1); } // UTC has no DST time_tm.tm_isdst = 0; // automatically guess the rest time_tm.tm_yday = -1; time_tm.tm_wday = -1; // convert the tm structure into epoch time return ConvertTimeT(mktime(&time_tm) - GetUtcOffset()); }
/* Catches calls to the POSIX gmtime_r and converts them to a related WIN32 version. */ struct tm *gmtime_r (time_t *t, struct tm *gmt) { gmtime_s (gmt, t); return gmt; }