Reactos

[SRVSVC][WKSSVC][NET] Improve server and workstation statistics

- Server and Workstation services return proper boot time.
- Net formats boot time properly.

CORE-19198

Eric Kohl bb7a6134 318a040c

+68 -31
+31 -29
base/applications/network/net/cmdStatistics.c
··· 18 18 LARGE_INTEGER LargeValue; 19 19 FILETIME FileTime, LocalFileTime; 20 20 SYSTEMTIME SystemTime; 21 - WORD wHour; 21 + WCHAR DateBuffer[32], TimeBuffer[32]; 22 22 INT nPaddedLength = 35; 23 23 NET_API_STATUS Status; 24 24 ··· 44 44 FileTimeToLocalFileTime(&FileTime, &LocalFileTime); 45 45 FileTimeToSystemTime(&LocalFileTime, &SystemTime); 46 46 47 - wHour = SystemTime.wHour; 48 - if (wHour == 0) 49 - { 50 - wHour = 12; 51 - } 52 - else if (wHour > 12) 53 - { 54 - wHour = wHour - 12; 55 - } 47 + GetDateFormatW(LOCALE_USER_DEFAULT, 48 + DATE_SHORTDATE, 49 + &SystemTime, 50 + NULL, 51 + DateBuffer, 52 + ARRAYSIZE(DateBuffer)); 53 + 54 + GetTimeFormatW(LOCALE_USER_DEFAULT, 55 + 0, 56 + &SystemTime, 57 + NULL, 58 + TimeBuffer, 59 + ARRAYSIZE(TimeBuffer)); 56 60 57 61 PrintMessageString(4600); 58 - ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n", 59 - SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, 60 - wHour, SystemTime.wMinute, 61 - (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM"); 62 + ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer); 62 63 63 64 PrintPaddedMessageString(4601, nPaddedLength); 64 65 ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens); ··· 131 132 LARGE_INTEGER LargeValue; 132 133 FILETIME FileTime, LocalFileTime; 133 134 SYSTEMTIME SystemTime; 134 - WORD wHour; 135 + WCHAR DateBuffer[32], TimeBuffer[32]; 135 136 INT nPaddedLength = 47; 136 137 NET_API_STATUS Status; 137 138 ··· 142 143 goto done; 143 144 144 145 Status = NetStatisticsGet(NULL, 145 - SERVICE_SERVER, 146 + SERVICE_WORKSTATION, 146 147 0, 147 148 0, 148 149 (LPBYTE*)&StatisticsInfo); ··· 159 160 FileTimeToLocalFileTime(&FileTime, &LocalFileTime); 160 161 FileTimeToSystemTime(&LocalFileTime, &SystemTime); 161 162 162 - wHour = SystemTime.wHour; 163 - if (wHour == 0) 164 - { 165 - wHour = 12; 166 - } 167 - else if (wHour > 12) 168 - { 169 - wHour = wHour - 12; 170 - } 163 + GetDateFormatW(LOCALE_USER_DEFAULT, 164 + DATE_SHORTDATE, 165 + &SystemTime, 166 + NULL, 167 + DateBuffer, 168 + ARRAYSIZE(DateBuffer)); 169 + 170 + GetTimeFormatW(LOCALE_USER_DEFAULT, 171 + 0, 172 + &SystemTime, 173 + NULL, 174 + TimeBuffer, 175 + ARRAYSIZE(TimeBuffer)); 171 176 172 177 PrintMessageString(4600); 173 - ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n", 174 - SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, 175 - wHour, SystemTime.wMinute, 176 - (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM"); 178 + ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer); 177 179 178 180 PrintPaddedMessageString(4630, nPaddedLength); 179 181 ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart);
+1
base/services/srvsvc/precomp.h
··· 10 10 #include <winreg.h> 11 11 #include <winsvc.h> 12 12 #include <lmserver.h> 13 + #include <ndk/exfuncs.h> 13 14 14 15 #include <srvsvc_s.h> 15 16
+17 -1
base/services/srvsvc/rpcserver.c
··· 476 476 DWORD Options, 477 477 LPSTAT_SERVER_0 *InfoStruct) 478 478 { 479 - PSTAT_SERVER_0 pStatBuffer; 479 + SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo; 480 + PSTAT_SERVER_0 pStatBuffer = NULL; 481 + NTSTATUS Status; 480 482 481 483 TRACE("NetrServerStatisticsGet(%p %p %lu 0x%lx %p)\n", 482 484 ServerName, Service, Level, Options, InfoStruct); ··· 492 494 return ERROR_NOT_ENOUGH_MEMORY; 493 495 494 496 ZeroMemory(pStatBuffer, sizeof(STAT_SERVER_0)); 497 + 498 + /* Query the boot time */ 499 + Status = NtQuerySystemInformation(SystemTimeOfDayInformation, 500 + &TimeOfDayInfo, 501 + sizeof(TimeOfDayInfo), 502 + NULL); 503 + if (NT_SUCCESS(Status)) 504 + { 505 + ULONG Seconds = 0; 506 + if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds)) 507 + { 508 + pStatBuffer->sts0_start = Seconds; 509 + } 510 + } 495 511 496 512 // FIXME: Return the actual statistcs data! 497 513
+1
base/services/wkssvc/precomp.h
··· 17 17 #include <ntsecapi.h> 18 18 #include <ntmsv1_0.h> 19 19 //#include <ntstatus.h> 20 + #include <ndk/exfuncs.h> 20 21 #include <ndk/obfuncs.h> 21 22 #include <ndk/psfuncs.h> 22 23 #include <ndk/rtlfuncs.h>
+18 -1
base/services/wkssvc/rpcserver.c
··· 1012 1012 unsigned long Options, 1013 1013 LPSTAT_WORKSTATION_0 *Buffer) 1014 1014 { 1015 - PSTAT_WORKSTATION_0 pStatBuffer; 1015 + SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo; 1016 + PSTAT_WORKSTATION_0 pStatBuffer = NULL; 1017 + NTSTATUS Status; 1016 1018 1017 1019 TRACE("NetrWorkstationStatisticsGet(%p %p %lu 0x%lx %p)\n", 1018 1020 ServerName, ServiceName, Level, Options, Buffer); ··· 1028 1030 return ERROR_NOT_ENOUGH_MEMORY; 1029 1031 1030 1032 ZeroMemory(pStatBuffer, sizeof(STAT_WORKSTATION_0)); 1033 + 1034 + /* Query the boot time */ 1035 + Status = NtQuerySystemInformation(SystemTimeOfDayInformation, 1036 + &TimeOfDayInfo, 1037 + sizeof(TimeOfDayInfo), 1038 + NULL); 1039 + if (NT_SUCCESS(Status)) 1040 + { 1041 + ULONG Seconds = 0; 1042 + if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds)) 1043 + { 1044 + pStatBuffer->StatisticsStartTime.u.HighPart = 0; 1045 + pStatBuffer->StatisticsStartTime.u.LowPart = Seconds; 1046 + } 1047 + } 1031 1048 1032 1049 // FIXME: Return the actual statistcs data! 1033 1050