ReactOS 0.4.15-dev-8109-gd7be748
enumprot.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/enumprot.c
5 * PURPOSE: Protocol Enumeration
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 * Pierre Schweitzer
8 */
9
10/* INCLUDES ******************************************************************/
11
12#include <ws2_32.h>
13
14#define NDEBUG
15#include <debug.h>
16
17/* FUNCTIONS *****************************************************************/
18
19BOOL
22 IN LPWSAPROTOCOL_INFOW ProtocolInfo)
23{
24 BOOL Return = FALSE;
25 DWORD i = 0;
27
28 /* Make sure we have a set */
29 if (ProtocolSet)
30 {
31 /* Get the first ID */
32 ProtocolId = ProtocolSet[i];
33
34 /* Loop the list */
35 while (ProtocolId != 0 && ProtocolInfo->iProtocol != 0)
36 {
37 /* Check if it's within ranges */
38 if ((ProtocolId >= ProtocolInfo->iProtocol) &&
39 (ProtocolId <= (ProtocolInfo->iProtocol +
40 ProtocolInfo->iProtocolMaxOffset)))
41 {
42 /* Found it */
43 Return = TRUE;
44 break;
45 }
46
47 /* Move on */
48 i++;
49 ProtocolId = ProtocolSet[i];
50 }
51 }
52 else
53 {
54 /* Assume match */
55 Return = TRUE;
56 }
57
58 /* Return result */
59 return Return;
60}
61
62VOID
66{
67 /* Check if we'll have space */
68 if ((Context->BufferUsed + sizeof(*ProtocolInfo)) <=
69 (Context->BufferLength))
70 {
71 /* Copy the data */
72 RtlMoveMemory((PVOID)((ULONG_PTR)Context->ProtocolBuffer +
73 Context->BufferUsed),
74 ProtocolInfo,
75 sizeof(*ProtocolInfo));
76
77 /* Increase the count */
78 Context->Count++;
79 }
80}
81
82BOOL
86{
88 LPWSAPROTOCOL_INFOW ProtocolInfo = &Entry->ProtocolInfo;
89
90 /* Check if this protocol matches */
91 if (CheckProtocolMatch(Context->Protocols, ProtocolInfo))
92 {
93 /* Copy the information */
94 ProtocolInfoFromContext(ProtocolInfo, Context);
95 Context->BufferUsed += sizeof(*ProtocolInfo);
96 }
97
98 /* Continue enumeration */
99 return TRUE;
100}
101
102BOOL
103WSAAPI
106{
107 INT PathLen;
109
110 /* Check if this provider matches */
111 if (IsEqualGUID(&Entry->ProviderId, &Context->ProviderId))
112 {
113 /* Get the information about the provider */
114 PathLen = wcslen(Entry->DllPath) + 1;
115 Context->FoundPathLen = PathLen;
116 Context->Found = 1;
117
118 /* If we have enough room, copy path */
119 if (PathLen <= Context->ProviderDllPathLen)
120 {
121 wcscpy(Context->ProviderDllPath, Entry->DllPath);
122 }
123
124 /* Stop enumeration */
125 return FALSE;
126 }
127 else
128 {
129 /* Continue enumeration */
130 return TRUE;
131 }
132
133}
134
136WSAAPI
138{
139 PTCATALOG Catalog;
140 HKEY WsKey;
141
142 /* Allocate the catalog */
143 Catalog = WsTcAllocate();
144 if (Catalog)
145 {
146 /* Open the WS Key */
147 WsKey = WsOpenRegistryRoot();
148
149 /* Initialize the catalog */
150 WsTcInitializeFromRegistry(Catalog, WsKey, NULL);
151
152 /* Close the key */
153 RegCloseKey(WsKey);
154 }
155
156 /* Return it */
157 return Catalog;
158}
159
160/*
161 * @implemented
162 */
163INT
164WSPAPI
166 OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer,
168 OUT LPINT lpErrno)
169{
170 INT Status;
171 PTCATALOG Catalog;
173 DPRINT("WSCEnumProtocols: %p\n", lpiProtocols);
174
175 /* Create a catalog object from the current one */
176 Catalog = OpenInitializedCatalog();
177 if (!Catalog)
178 {
179 /* Fail if we couldn't */
180 *lpErrno = WSAENOBUFS;
181 return SOCKET_ERROR;
182 }
183
184 /* Setup the context */
185 Context.Protocols = lpiProtocols;
186 Context.ProtocolBuffer = lpProtocolBuffer;
187 Context.BufferLength = lpProtocolBuffer ? *lpdwBufferLength : 0;
188 Context.BufferUsed = 0;
189 Context.Count = 0;
190 Context.ErrorCode = ERROR_SUCCESS;
191
192 /* Enumerate the catalog */
194
195 /* Get status */
196 Status = Context.Count;
197
198 /* Check the error code */
199 if (Context.ErrorCode == ERROR_SUCCESS)
200 {
201 /* Check if enough space was available */
202 if (Context.BufferLength < Context.BufferUsed)
203 {
204 /* Fail and tell them how much we need */
205 *lpdwBufferLength = Context.BufferUsed;
206 *lpErrno = WSAENOBUFS;
208 }
209 }
210 else
211 {
212 /* Failure, normalize error */
214 *lpErrno = Context.ErrorCode;
215 }
216
217 /* Delete the catalog object */
218 WsTcDelete(Catalog);
219
220 /* Return */
221 return Status;
222}
223
224/*
225 * @implemented
226 */
227INT
228WSAAPI
230 OUT LPWSAPROTOCOL_INFOA lpProtocolBuffer,
232{
233 INT error, i, count;
234 LPWSAPROTOCOL_INFOW protocolInfoW;
235 DWORD size;
236 DPRINT("WSAEnumProtocolsA: %p %p %p\n", lpiProtocols, lpProtocolBuffer, lpdwBufferLength);
237 if (!lpdwBufferLength)
238 {
240 return SOCKET_ERROR;
241 }
242 count = WSCEnumProtocols(lpiProtocols, NULL, &size, &error);
243 if (!lpProtocolBuffer || *lpdwBufferLength < (size/sizeof(WSAPROTOCOL_INFOW))*sizeof(WSAPROTOCOL_INFOA))
244 {
247 return SOCKET_ERROR;
248 }
249 protocolInfoW = HeapAlloc(WsSockHeap, 0, size);
250 count = WSCEnumProtocols(lpiProtocols, protocolInfoW, &size, &error);
251 if (SOCKET_ERROR == count)
252 {
253 HeapFree(WsSockHeap, 0, protocolInfoW);
255 return SOCKET_ERROR;
256 }
257 *lpdwBufferLength = 0;
258 for (i = 0; i < count; i++)
259 {
260 /* Copy the data */
261 RtlMoveMemory(&lpProtocolBuffer[i],
262 &protocolInfoW[i],
263 sizeof(lpProtocolBuffer[0])-sizeof(lpProtocolBuffer[0].szProtocol));
264 wcstombs(lpProtocolBuffer[i].szProtocol, protocolInfoW[i].szProtocol, sizeof(lpProtocolBuffer[0].szProtocol));
266 }
267 HeapFree(WsSockHeap, 0, protocolInfoW);
268 return i;
269}
270
271/*
272 * @implemented
273 */
274INT
275WSAAPI
277 OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer,
279{
280 INT error, count;
281 DPRINT("WSAEnumProtocolsW: %p %p %p\n", lpiProtocols, lpProtocolBuffer, lpdwBufferLength);
282 count = WSCEnumProtocols(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, &error);
283 if (SOCKET_ERROR == count)
284 {
286 return SOCKET_ERROR;
287 }
288 return count;
289}
290
291
292/*
293 * @implemented
294 */
295INT
296WSPAPI
298 OUT LPWSTR lpszProviderDllPath,
299 IN OUT LPINT lpProviderDllPathLen,
300 OUT LPINT lpErrno)
301{
302 return WSCGetProviderPath(lpProviderId, lpszProviderDllPath, lpProviderDllPathLen, lpErrno);
303}
304
305/*
306 * @implemented
307 */
308INT
309WSAAPI
312 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
313{
314 DPRINT("WSAProviderConfigChange: %p\n", lpNotificationHandle);
317 return SOCKET_ERROR;
318}
319
320/*
321 * @implemented
322 */
323INT
324WSPAPI
326 OUT LPWSTR lpszProviderDllPath,
327 IN OUT LPINT lpProviderDllPathLen,
328 OUT LPINT lpErrno)
329{
332 PNSCATALOG Catalog;
333 INT ErrorCode, PathLen;
335
336 DPRINT("WSCGetProviderPath: %p %p %p %p\n", lpProviderId, lpszProviderDllPath, lpProviderDllPathLen, lpErrno);
337
338 /* Enter prolog */
340 {
341 /* FIXME: if WSANOTINITIALISED, we should init
342 * and perform the search!
343 */
344
345 /* Leave now */
346 *lpErrno = ErrorCode;
347 return SOCKET_ERROR;
348 }
349
350 /* Get the catalog */
351 Catalog = WsProcGetNsCatalog(Process);
352
354 {
355 /* Setup the context */
356 Context.ProviderId = *lpProviderId;
357 Context.ProviderDllPath = lpszProviderDllPath;
358 Context.ProviderDllPathLen = *lpProviderDllPathLen;
359 Context.FoundPathLen = 0;
360 Context.Found = 0;
361 Context.ErrorCode = ERROR_SUCCESS;
362
364
365 /* Enumerate the catalog */
367
368 /* Check the error code */
369 if (Context.ErrorCode == ERROR_SUCCESS)
370 {
371 /* Check if provider was found */
372 if (Context.Found)
373 {
374 PathLen = Context.FoundPathLen;
375
376 /* Check whether buffer is too small
377 * If it isn't, return length without null char
378 * (see ProviderEnumerationProc)
379 */
380 if (Context.FoundPathLen <= *lpProviderDllPathLen)
381 {
382 PathLen = Context.FoundPathLen - 1;
383 }
384 else
385 {
387 }
388
389 /* Set returned/required length */
390 *lpProviderDllPathLen = PathLen;
391 }
392 else
393 {
395 }
396 }
397 else
398 {
399 ErrorCode = Context.ErrorCode;
400 }
401 }
403 {
405 }
406 _SEH2_END;
407
408 /* Do we have to return failure? */
410 {
411 *lpErrno = ErrorCode;
412 return SOCKET_ERROR;
413 }
414
415 return 0;
416}
#define UNIMPLEMENTED
Definition: debug.h:118
#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
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
INT WSPAPI WPUGetProviderPath(IN LPGUID lpProviderId, OUT LPWSTR lpszProviderDllPath, IN OUT LPINT lpProviderDllPathLen, OUT LPINT lpErrno)
Definition: enumprot.c:297
INT WSAAPI WSAEnumProtocolsA(IN LPINT lpiProtocols, OUT LPWSAPROTOCOL_INFOA lpProtocolBuffer, IN OUT LPDWORD lpdwBufferLength)
Definition: enumprot.c:229
INT WSPAPI WSCGetProviderPath(IN LPGUID lpProviderId, OUT LPWSTR lpszProviderDllPath, IN OUT LPINT lpProviderDllPathLen, OUT LPINT lpErrno)
Definition: enumprot.c:325
INT WSPAPI WSCEnumProtocols(IN LPINT lpiProtocols, OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer, IN OUT LPDWORD lpdwBufferLength, OUT LPINT lpErrno)
Definition: enumprot.c:165
BOOL WSAAPI CheckProtocolMatch(IN LPINT ProtocolSet, IN LPWSAPROTOCOL_INFOW ProtocolInfo)
Definition: enumprot.c:21
PTCATALOG WSAAPI OpenInitializedCatalog(VOID)
Definition: enumprot.c:137
BOOL WSAAPI ProtocolEnumerationProc(PVOID EnumContext, PTCATALOG_ENTRY Entry)
Definition: enumprot.c:84
BOOL WSAAPI ProviderEnumerationProc(PVOID EnumContext, PNSCATALOG_ENTRY Entry)
Definition: enumprot.c:104
INT WSAAPI WSAProviderConfigChange(IN OUT LPHANDLE lpNotificationHandle, IN LPWSAOVERLAPPED lpOverlapped, IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: enumprot.c:310
VOID WSAAPI ProtocolInfoFromContext(IN LPWSAPROTOCOL_INFOW ProtocolInfo, IN PPROTOCOL_ENUM_CONTEXT Context)
Definition: enumprot.c:64
INT WSAAPI WSAEnumProtocolsW(IN LPINT lpiProtocols, OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer, IN OUT LPDWORD lpdwBufferLength)
Definition: enumprot.c:276
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
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
Status
Definition: gdiplustypes.h:25
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
size_t __cdecl wcstombs(_Out_writes_opt_z_(_MaxCount) char *_Dest, _In_z_ const wchar_t *_Source, _In_ size_t _MaxCount)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define error(str)
Definition: mkdosfs.c:1605
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93
_In_ UINT ProtocolId
Definition: ndis.h:2924
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DPRINT
Definition: sndvol32.h:73
base of all file and directory entries
Definition: entries.h:83
Definition: ws2_32p.h:122
Definition: ws2_32p.h:86
uint32_t * LPDWORD
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define OUT
Definition: typedefs.h:40
int * LPINT
Definition: windef.h:178
#define WSAEINVAL
Definition: winerror.h:1946
#define WSAENOBUFS
Definition: winerror.h:1968
#define WSAEFAULT
Definition: winerror.h:1945
_In_ _In_opt_ _Out_writes_bytes_to_opt_ lpdwBufferLength _Inout_ LPDWORD lpdwBufferLength
Definition: winhttp.h:675
struct _WSAPROTOCOL_INFOW WSAPROTOCOL_INFOW
void(CALLBACK * LPWSAOVERLAPPED_COMPLETION_ROUTINE)(IN DWORD dwError, IN DWORD cbTransferred, IN LPWSAOVERLAPPED lpOverlapped, IN DWORD dwFlags)
Definition: winsock2.h:722
struct _WSAPROTOCOL_INFOA WSAPROTOCOL_INFOA
#define WSAAPI
Definition: winsock2.h:605
#define SOCKET_ERROR
Definition: winsock.h:333
struct _PROTOCOL_ENUM_CONTEXT * PPROTOCOL_ENUM_CONTEXT
PTCATALOG WSAAPI WsTcAllocate(VOID)
Definition: dcatalog.c:25
HKEY WSAAPI WsOpenRegistryRoot(VOID)
Definition: wsautil.c:17
VOID WSAAPI WsTcEnumerateCatalogItems(IN PTCATALOG Catalog, IN PTCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: dcatalog.c:750
DWORD WSAAPI WsTcInitializeFromRegistry(IN PTCATALOG TCatalog, HKEY, PVOID)
PNSCATALOG WSAAPI WsProcGetNsCatalog(IN PWSPROCESS Process)
Definition: dprocess.c:166
VOID WSAAPI WsNcEnumerateCatalogItems(IN PNSCATALOG Catalog, IN PNSCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: nscatalo.c:371
HANDLE WsSockHeap
Definition: dllmain.c:21
INT WSAAPI WsApiProlog(OUT PWSPROCESS *Process, OUT PWSTHREAD *Thread)
Definition: wsautil.c:91
struct _PROVIDER_ENUM_CONTEXT * PPROVIDER_ENUM_CONTEXT
VOID WSAAPI WsTcDelete(IN PTCATALOG Catalog)
Definition: dcatalog.c:883
#define WSPAPI
Definition: ws2spi.h:39
WCHAR * LPWSTR
Definition: xmlstorage.h:184