2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: dll/win32/ws2_32_new/src/enumprot.c
5 * PURPOSE: Protocol Enumeration
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS *****************************************************************/
20 CheckProtocolMatch(IN LPINT ProtocolSet
,
21 IN LPWSAPROTOCOL_INFOW ProtocolInfo
)
27 /* Make sure we have a set */
30 /* Get the first ID */
31 ProtocolId
= ProtocolSet
[i
];
34 while (ProtocolId
!= 0 && ProtocolInfo
->iProtocol
!= 0)
36 /* Check if it's within ranges */
37 if ((ProtocolId
>= ProtocolInfo
->iProtocol
) &&
38 (ProtocolId
<= (ProtocolInfo
->iProtocol
+
39 ProtocolInfo
->iProtocolMaxOffset
)))
48 ProtocolId
= ProtocolSet
[i
];
63 ProtocolInfoFromContext(IN LPWSAPROTOCOL_INFOW ProtocolInfo
,
64 IN PPROTOCOL_ENUM_CONTEXT Context
)
66 /* Check if we'll have space */
67 if ((Context
->BufferUsed
+ sizeof(*ProtocolInfo
)) <=
68 (Context
->BufferLength
))
71 RtlMoveMemory((PVOID
)((ULONG_PTR
)Context
->ProtocolBuffer
+
74 sizeof(*ProtocolInfo
));
76 /* Increase the count */
83 ProtocolEnumerationProc(PVOID EnumContext
,
84 PTCATALOG_ENTRY Entry
)
86 PPROTOCOL_ENUM_CONTEXT Context
= (PPROTOCOL_ENUM_CONTEXT
)EnumContext
;
87 LPWSAPROTOCOL_INFOW ProtocolInfo
= &Entry
->ProtocolInfo
;
89 /* Check if this protocol matches */
90 if (CheckProtocolMatch(Context
->Protocols
, ProtocolInfo
))
92 /* Copy the information */
93 ProtocolInfoFromContext(ProtocolInfo
, Context
);
94 Context
->BufferUsed
+= sizeof(*ProtocolInfo
);
97 /* Continue enumeration */
103 OpenInitializedCatalog(VOID
)
108 /* Allocate the catalog */
109 Catalog
= WsTcAllocate();
112 /* Open the WS Key */
113 WsKey
= WsOpenRegistryRoot();
115 /* Initialize the catalog */
116 WsTcInitializeFromRegistry(Catalog
, WsKey
, NULL
);
131 WSCEnumProtocols(IN LPINT lpiProtocols
,
132 OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer
,
133 IN OUT LPDWORD lpdwBufferLength
,
138 PROTOCOL_ENUM_CONTEXT Context
;
139 DPRINT("WSCEnumProtocols: %p\n", lpiProtocols
);
141 /* Create a catalog object from the current one */
142 Catalog
= OpenInitializedCatalog();
145 /* Fail if we couldn't */
146 *lpErrno
= WSAENOBUFS
;
150 /* Setup the context */
151 Context
.Protocols
= lpiProtocols
;
152 Context
.ProtocolBuffer
= lpProtocolBuffer
;
153 Context
.BufferLength
= lpProtocolBuffer
? *lpdwBufferLength
: 0;
154 Context
.BufferUsed
= 0;
156 Context
.ErrorCode
= ERROR_SUCCESS
;
158 /* Enumerate the catalog */
159 WsTcEnumerateCatalogItems(Catalog
, ProtocolEnumerationProc
, &Context
);
162 Status
= Context
.Count
;
164 /* Check the error code */
165 if (Context
.ErrorCode
== ERROR_SUCCESS
)
167 /* Check if enough space was available */
168 if (Context
.BufferLength
< Context
.BufferUsed
)
170 /* Fail and tell them how much we need */
171 *lpdwBufferLength
= Context
.BufferUsed
;
172 *lpErrno
= WSAENOBUFS
;
173 Status
= SOCKET_ERROR
;
178 /* Failure, normalize error */
179 Status
= SOCKET_ERROR
;
180 *lpErrno
= Context
.ErrorCode
;
183 /* Delete the catalog object */
195 WSAEnumProtocolsA(IN LPINT lpiProtocols
,
196 OUT LPWSAPROTOCOL_INFOA lpProtocolBuffer
,
197 IN OUT LPDWORD lpdwBufferLength
)
200 LPWSAPROTOCOL_INFOW protocolInfoW
;
202 DPRINT("WSAEnumProtocolsA: %p %p %p\n", lpiProtocols
, lpProtocolBuffer
, lpdwBufferLength
);
203 if (!lpdwBufferLength
)
205 SetLastError(WSAENOBUFS
);
208 count
= WSCEnumProtocols(lpiProtocols
, NULL
, &size
, &error
);
209 if (!lpProtocolBuffer
|| *lpdwBufferLength
< (size
/sizeof(WSAPROTOCOL_INFOW
))*sizeof(WSAPROTOCOL_INFOA
))
211 *lpdwBufferLength
= (size
/sizeof(WSAPROTOCOL_INFOW
))*sizeof(WSAPROTOCOL_INFOA
);
212 SetLastError(WSAENOBUFS
);
215 protocolInfoW
= HeapAlloc(WsSockHeap
, 0, size
);
216 count
= WSCEnumProtocols(lpiProtocols
, protocolInfoW
, &size
, &error
);
217 if (SOCKET_ERROR
== count
)
219 HeapFree(WsSockHeap
, 0, protocolInfoW
);
223 *lpdwBufferLength
= 0;
224 for (i
= 0; i
< count
; i
++)
227 RtlMoveMemory(&lpProtocolBuffer
[i
],
229 sizeof(lpProtocolBuffer
[0])-sizeof(lpProtocolBuffer
[0].szProtocol
));
230 wcstombs(lpProtocolBuffer
[i
].szProtocol
, protocolInfoW
[i
].szProtocol
, sizeof(lpProtocolBuffer
[0].szProtocol
));
231 *lpdwBufferLength
+= sizeof(WSAPROTOCOL_INFOA
);
233 HeapFree(WsSockHeap
, 0, protocolInfoW
);
242 WSAEnumProtocolsW(IN LPINT lpiProtocols
,
243 OUT LPWSAPROTOCOL_INFOW lpProtocolBuffer
,
244 IN OUT LPDWORD lpdwBufferLength
)
247 DPRINT("WSAEnumProtocolsW: %p %p %p\n", lpiProtocols
, lpProtocolBuffer
, lpdwBufferLength
);
248 count
= WSCEnumProtocols(lpiProtocols
, lpProtocolBuffer
, lpdwBufferLength
, &error
);
249 if (SOCKET_ERROR
== count
)
263 WPUGetProviderPath(IN LPGUID lpProviderId
,
264 OUT LPWSTR lpszProviderDllPath
,
265 IN OUT LPINT lpProviderDllPathLen
,
268 return WSCGetProviderPath(lpProviderId
, lpszProviderDllPath
, lpProviderDllPathLen
, lpErrno
);
276 WSAProviderConfigChange(IN OUT LPHANDLE lpNotificationHandle
,
277 IN LPWSAOVERLAPPED lpOverlapped
,
278 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
)
280 DPRINT("WSAProviderConfigChange: %p\n", lpNotificationHandle
);
282 SetLastError(WSAEINVAL
);
291 WSCGetProviderPath(IN LPGUID lpProviderId
,
292 OUT LPWSTR lpszProviderDllPath
,
293 IN OUT LPINT lpProviderDllPathLen
,
296 DPRINT("WSCGetProviderPath: %p %p %p %p\n", lpProviderId
, lpszProviderDllPath
, lpProviderDllPathLen
, lpErrno
);
298 SetLastError(WSAEINVAL
);