[W32TIME] Implement a rudimentary version of W32TimeSyncNow. CORE-13001
authorThomas Faber <thomas.faber@reactos.org>
Sun, 3 Jun 2018 14:28:57 +0000 (16:28 +0200)
committerThomas Faber <thomas.faber@reactos.org>
Sun, 7 Jul 2019 10:45:03 +0000 (12:45 +0200)
base/services/CMakeLists.txt
base/services/w32time/CMakeLists.txt [new file with mode: 0644]
base/services/w32time/ntpclient.c [moved from dll/cpl/timedate/ntpclient.c with 99% similarity]
base/services/w32time/w32time.c [moved from dll/cpl/timedate/w32time.c with 97% similarity]
base/services/w32time/w32time.h [new file with mode: 0644]
base/services/w32time/w32time.spec [new file with mode: 0644]
dll/cpl/timedate/CMakeLists.txt
dll/cpl/timedate/internettime.c
dll/cpl/timedate/timedate.h

index 15bdd77..62b5a90 100644 (file)
@@ -14,6 +14,7 @@ add_subdirectory(tcpsvcs)
 add_subdirectory(telnetd)
 add_subdirectory(tftpd)
 add_subdirectory(umpnpmgr)
+add_subdirectory(w32time)
 add_subdirectory(wkssvc)
 add_subdirectory(wlansvc)
 add_subdirectory(wmisvc)
diff --git a/base/services/w32time/CMakeLists.txt b/base/services/w32time/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5cc5a3b
--- /dev/null
@@ -0,0 +1,12 @@
+
+spec2def(w32time.dll w32time.spec ADD_IMPORTLIB)
+
+add_library(w32time SHARED
+    w32time.c
+    ntpclient.c
+    ${CMAKE_CURRENT_BINARY_DIR}/w32time.def)
+
+set_module_type(w32time win32dll UNICODE)
+
+add_importlibs(w32time ws2_32 advapi32 msvcrt kernel32 ntdll)
+add_cd_file(TARGET w32time DESTINATION reactos/system32 FOR all)
similarity index 99%
rename from dll/cpl/timedate/ntpclient.c
rename to base/services/w32time/ntpclient.c
index fc378c6..8ba5910 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 
-#include "timedate.h"
+#include "w32time.h"
 
 #include <winsock2.h>
 
similarity index 97%
rename from dll/cpl/timedate/w32time.c
rename to base/services/w32time/w32time.c
index dfbf143..675bb90 100644 (file)
@@ -5,7 +5,7 @@
  * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
  */
 
-#include "timedate.h"
+#include "w32time.h"
 
 /* Get the domain name from the registry */
 static DWORD
@@ -207,11 +207,14 @@ UpdateSystemTime(ULONG ulTime)
 }
 
 
-DWORD
-SyncTimeNow(VOID)
+DWORD WINAPI
+W32TimeSyncNow(LPCWSTR cmdline,
+               UINT blocking,
+               UINT flags)
 {
     DWORD dwError;
     ULONG ulTime;
+
     dwError = GetTimeFromServer(&ulTime);
     if (dwError != ERROR_SUCCESS)
     {
diff --git a/base/services/w32time/w32time.h b/base/services/w32time/w32time.h
new file mode 100644 (file)
index 0000000..bd65de4
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef _W32TIME_H
+#define _W32TIME_H
+
+#include <stdarg.h>
+
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+#define WIN32_NO_STATUS
+
+#include <windef.h>
+#include <winbase.h>
+#include <winnls.h>
+#include <winreg.h>
+
+#define NTPPORT 123
+
+
+/* ntpclient.c */
+// NTP timestamp
+typedef struct _TIMEPACKET
+{
+  DWORD dwInteger;
+  DWORD dwFractional;
+} TIMEPACKET, *PTIMEPACKET;
+
+// NTP packet
+typedef struct _NTPPACKET
+{
+  BYTE LiVnMode;
+  BYTE Stratum;
+  char Poll;
+  char Precision;
+  long RootDelay;
+  long RootDispersion;
+  char ReferenceID[4];
+  TIMEPACKET ReferenceTimestamp;
+  TIMEPACKET OriginateTimestamp;
+  TIMEPACKET ReceiveTimestamp;
+  TIMEPACKET TransmitTimestamp;
+}NTPPACKET, *PNTPPACKET;
+
+ULONG GetServerTime(LPWSTR lpAddress);
+
+#endif /* _W32TIME_H */
diff --git a/base/services/w32time/w32time.spec b/base/services/w32time/w32time.spec
new file mode 100644 (file)
index 0000000..12b8db5
--- /dev/null
@@ -0,0 +1 @@
+18 stdcall W32TimeSyncNow(wstr long long)
index 5103df0..d1b5275 100644 (file)
@@ -6,10 +6,8 @@ list(APPEND SOURCE
     dateandtime.c
     internettime.c
     monthcal.c
-    ntpclient.c
     timedate.c
     timezone.c
-    w32time.c
     timedate.h)
 
 file(GLOB timedate_rc_deps resources/*.*)
@@ -21,6 +19,6 @@ add_library(timedate MODULE
     ${CMAKE_CURRENT_BINARY_DIR}/timedate.def)
 
 set_module_type(timedate cpl UNICODE)
-add_importlibs(timedate advapi32 user32 gdi32 comctl32 ws2_32 iphlpapi msvcrt kernel32)
+add_importlibs(timedate w32time advapi32 user32 gdi32 comctl32 ws2_32 iphlpapi msvcrt kernel32)
 add_pch(timedate timedate.h SOURCE)
 add_cd_file(TARGET timedate DESTINATION reactos/system32 FOR all)
index 7c97184..a5f102a 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "timedate.h"
 
+DWORD WINAPI W32TimeSyncNow(LPCWSTR cmdline, UINT blocking, UINT flags);
+
 static VOID
 CreateNTPServerList(HWND hwnd)
 {
@@ -208,7 +210,7 @@ InetTimePageProc(HWND hwndDlg,
 
                     SetNTPServer(hwndDlg);
 
-                    dwError = SyncTimeNow();
+                    dwError = W32TimeSyncNow(L"localhost", 0, 0);
                     if (dwError != ERROR_SUCCESS)
                     {
                         DisplayWin32Error(dwError);
index 73b2a3a..8cf7dbb 100644 (file)
@@ -23,7 +23,6 @@
 #define MAX_VALUE_NAME 16383
 #define SERVERLISTSIZE 6
 #define BUFSIZE 1024
-#define NTPPORT 123
 #define ID_TIMER 1
 
 typedef struct
@@ -67,37 +66,6 @@ BOOL RegisterClockControl(VOID);
 VOID UnregisterClockControl(VOID);
 
 
-/* ntpclient.c */
-// NTP timestamp
-typedef struct _TIMEPACKET
-{
-  DWORD dwInteger;
-  DWORD dwFractional;
-} TIMEPACKET, *PTIMEPACKET;
-
-// NTP packet
-typedef struct _NTPPACKET
-{
-  BYTE LiVnMode;
-  BYTE Stratum;
-  char Poll;
-  char Precision;
-  long RootDelay;
-  long RootDispersion;
-  char ReferenceID[4];
-  TIMEPACKET ReferenceTimestamp;
-  TIMEPACKET OriginateTimestamp;
-  TIMEPACKET ReceiveTimestamp;
-  TIMEPACKET TransmitTimestamp;
-}NTPPACKET, *PNTPPACKET;
-
-ULONG GetServerTime(LPWSTR lpAddress);
-
-
-/* w32time.c */
-DWORD SyncTimeNow(VOID);
-
-
 /* monthcal.c */
 #define MCCM_SETDATE    (WM_USER + 1)
 #define MCCM_GETDATE    (WM_USER + 2)