ReactOS 0.4.16-dev-321-g63bb46a
wsautil.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: dll/win32/ws2_32/src/wsautil.c
5 * PURPOSE: Winsock Utility Functions
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ws2_32.h>
12
13/* FUNCTIONS *****************************************************************/
14
15HKEY
18{
19 HKEY WinsockRootKey;
22
23 /* Open Registry Key */
26 0,
28 &WinsockRootKey);
29
30 /* Check if it wasn't found */
32 {
33 /* Create it */
36 0,
37 NULL,
40 NULL,
41 &WinsockRootKey,
43 }
44 else if (ErrorCode == ERROR_SUCCESS)
45 {
46 /* It already exists */
48 }
49
50 /* Check for failure */
51 if (ErrorCode != ERROR_SUCCESS) return NULL;
52
53 /* Check if we had to create a new key */
55 {
56 /* Write the Winsock Version */
57 RegSetValueEx(WinsockRootKey,
58 "WinSock_Registry_Version",
59 0,
60 REG_SZ,
61 (BYTE*)"2.2",
62 4);
63 }
64 else
65 {
66 /* Read the Winsock Version */
67 }
68
69 /* Return the key */
70 return WinsockRootKey;
71}
72
73BOOL
76{
77 DWORD Return;
78
79 /* Wait for the object */
80 Return = WaitForSingleObject(Event, 0);
81
82 /* Check for the value */
83 if (Return == WAIT_OBJECT_0) return TRUE;
84
85 /* If it timedout or anything else, return false */
86 return FALSE;
87}
88
89INT
93{
95
96 /* Try to get the current process */
97 if ((*Process = WsGetProcess()))
98 {
99 /* And the current thread */
101 }
102
103 /* Return init status */
104 return ErrorCode;
105}
106
107INT
108WSAAPI
110{
113
114 /* Call the prolog */
115 return WsApiProlog(&Process, &Thread);
116}
117
118INT
119WSAAPI
121{
125
126 /* Call the prolog */
128
129 /* Check for success */
131 {
132 /* Return the Thread ID */
133 *ThreadId = &Thread->WahThreadId;
134 }
135
136 /* Return status */
137 return ErrorCode;
138}
139
140INT
141WSAAPI
143 IN HANDLE CatalogEvent,
144 OUT LPDWORD UniqueId)
145{
147 HKEY RegistryKey;
148 DWORD NewUniqueId;
149 CHAR KeyBuffer[32];
150 DWORD RegType = REG_DWORD;
151 DWORD RegSize = sizeof(DWORD);
152
153 /* Start loop */
154 do
155 {
156#if 0
157 /* Ask for notifications */
159 FALSE,
161 CatalogEvent,
162 TRUE);
164 {
165 /* Normalize error code */
167 break;
168 }
169#endif
170
171 /* Read the current ID */
172 ErrorCode = RegQueryValueEx(CatalogKey,
173 "Serial_Access_Num",
174 0,
175 &RegType,
176 (LPBYTE)&NewUniqueId,
177 &RegSize);
179 {
180 /* Critical failure */
182 break;
183 }
184
185 /* Try to open it for writing */
186 sprintf(KeyBuffer, "%8.8lX", NewUniqueId);
187 ErrorCode = RegOpenKeyEx(CatalogKey,
188 KeyBuffer,
189 0,
191 &RegistryKey);
192
193 /* If the key doesn't exist or is being delete, that's ok for us */
196 {
197 /* Set success and return the new ID */
199 *UniqueId = NewUniqueId;
200 break;
201 }
202 else if (ErrorCode != ERROR_SUCCESS)
203 {
204 /* Any other failure is bad */
206 break;
207 }
208
209 /* If we could actually open the key, someone is using it :/ */
210 ErrorCode = RegCloseKey(RegistryKey);
211
212 /* In case we break out prematurely */
214
215 /* Keep looping until they let go of the registry writing */
216 } while (!WaitForSingleObject(CatalogEvent, 180 * 1000));
217
218 /* Return error code */
219 return ErrorCode;
220}
221
222INT
223WSAAPI
225 OUT LPWSAPROTOCOL_INFOA AnsiInfo)
226{
228
229 /* Copy all the data that doesn't need converting */
230 RtlCopyMemory(AnsiInfo,
231 UnicodeInfo,
232 FIELD_OFFSET(WSAPROTOCOL_INFOA, szProtocol));
233
234 /* Now convert the protocol string */
236 0,
237 UnicodeInfo->szProtocol,
238 -1,
239 AnsiInfo->szProtocol,
240 sizeof(AnsiInfo->szProtocol),
241 NULL,
242 NULL);
243 if (!ReturnValue) return WSASYSCALLFAILURE;
244
245 /* Return success */
246 return ERROR_SUCCESS;
247}
248
249/*
250 * @implemented
251 */
252VOID
253WSAAPI
255{
256 return;
257}
UINT32 void void ** ReturnValue
Definition: acevents.h:216
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, DWORD dwNotifyFilter, HANDLE hEvent, BOOL fAsynchronous)
Definition: reg.c:3152
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define DWORD
Definition: nt_native.h:44
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define REG_DWORD
Definition: sdbapi.c:596
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:120
#define WAIT_OBJECT_0
Definition: winbase.h:432
#define WSANOTINITIALISED
Definition: winerror.h:1987
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define ERROR_KEY_DELETED
Definition: winerror.h:597
#define WSANO_RECOVERY
Definition: winerror.h:2002
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define REG_NOTIFY_CHANGE_NAME
Definition: winreg.h:38
#define RegQueryValueEx
Definition: winreg.h:524
#define WSAAPI
Definition: winsock2.h:605
DWORD WSAAPI WsThreadGetCurrentThread(IN PWSPROCESS Process, IN PWSTHREAD *Thread)
Definition: dthread.c:279
FORCEINLINE PWSPROCESS WsGetProcess(VOID)
Definition: ws2_32p.h:885
#define WINSOCK_ROOT
Definition: ws2_32p.h:10
INT WSAAPI WsSetupCatalogProtection(IN HKEY CatalogKey, IN HANDLE CatalogEvent, OUT LPDWORD UniqueId)
Definition: wsautil.c:142
HKEY WSAAPI WsOpenRegistryRoot(VOID)
Definition: wsautil.c:17
INT WSAAPI WsSlowPrologTid(OUT LPWSATHREADID *ThreadId)
Definition: wsautil.c:120
BOOL WSAAPI WsCheckCatalogState(IN HANDLE Event)
Definition: wsautil.c:75
INT WSAAPI WsSlowProlog(VOID)
Definition: wsautil.c:109
INT WSAAPI MapUnicodeProtocolInfoToAnsi(IN LPWSAPROTOCOL_INFOW UnicodeInfo, OUT LPWSAPROTOCOL_INFOA AnsiInfo)
Definition: wsautil.c:224
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
VOID WSAAPI WEP(VOID)
Definition: wsautil.c:254
char CHAR
Definition: xmlstorage.h:175
unsigned char BYTE
Definition: xxhash.c:193