ReactOS 0.4.15-dev-7674-gc0b4db1
nsprovid.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/nsprovid.c
5 * PURPOSE: Namespace Provider Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ws2_32.h>
12
13/* FUNCTIONS *****************************************************************/
14
18{
20
21 /* Allocate the object */
23
24 /* Return it */
25 return Provider;
26}
27
32{
33 /* Reference the provider */
35
36 /* Set it as our own */
37 QueryProvider->Provider = Provider;
38
39 /* Return success */
40 return ERROR_SUCCESS;
41}
42
43VOID
46{
47 /* Check if we have a provider */
48 if (QueryProvider->Provider)
49 {
50 /* Dereference it */
51 WsNpDereference(QueryProvider->Provider);
52
53 /* Clear it */
54 QueryProvider->Provider = NULL;
55 }
56
57 /* Delete us */
58 HeapFree(WsSockHeap, 0, QueryProvider);
59}
60
64{
66
67 /* Allocate the object */
69 if (Provider)
70 {
71 /* Set non-null data */
72 Provider->RefCount = 1;
73 Provider->Service.cbSize = sizeof(NSP_ROUTINE);
74 }
75
76 /* Return it */
77 return Provider;
78}
79
83 IN LPWSTR DllName,
84 IN LPGUID ProviderId)
85{
87 LPNSPSTARTUP NSPStartupProc;
88 CHAR AnsiPath[MAX_PATH], ExpandedDllPath[MAX_PATH];
89
90 /* Convert the path to ANSI */
92 0,
93 DllName,
94 -1,
95 AnsiPath,
97 NULL,
98 NULL);
99
100 /* Expand the DLL Path */
102 ExpandedDllPath,
103 MAX_PATH);
104
105 /* Load the DLL */
106 Provider->DllHandle = LoadLibraryA(ExpandedDllPath);
107 if (!Provider->DllHandle)
108 {
109 /* Fail */
111 goto Fail;
112 }
113
114 /* Get the pointer to NSPStartup */
115 NSPStartupProc = (LPNSPSTARTUP)GetProcAddress(Provider->DllHandle,
116 "NSPStartup");
117 if (!NSPStartupProc)
118 {
119 /* Fail */
121 goto Fail;
122 }
123
124 /* Call it */
125 (*NSPStartupProc)(ProviderId, &Provider->Service);
126
127 /* Save the provider ID */
128 Provider->ProviderId = *ProviderId;
129 return ErrorCode;
130
131Fail:
132 /* Bail out */
133 if (Provider->DllHandle) FreeLibrary(Provider->DllHandle);
134 Provider->DllHandle = NULL;
135 return ErrorCode;
136}
137
138DWORD
139WSAAPI
141{
143 LPNSPCLEANUP lpNSPCleanup = NULL;
144
145 /* Make sure we have a loaded handle */
146 if (Provider->DllHandle)
147 {
148 /* Get the pointer and clear it */
149 lpNSPCleanup = InterlockedExchangePointer((PVOID*)&Provider->Service.NSPCleanup,
150 NULL);
151 /* If it's not NULL, call it */
152 if (lpNSPCleanup) ErrorCode = lpNSPCleanup(&Provider->ProviderId);
153 }
154
155 /* Return */
156 return ErrorCode;
157}
158
159VOID
160WSAAPI
162{
163 /* Make sure we have a loaded handle */
164 if (Provider->DllHandle)
165 {
166 /* Clean us up */
168
169 /* Unload the library */
170 FreeLibrary(Provider->DllHandle);
171 Provider->DllHandle = NULL;
172 }
173
174 /* Delete us */
176}
177
178VOID
179WSAAPI
181{
182 /* Decrease the reference count and check if it's zero */
183 if (!InterlockedDecrement(&Provider->RefCount))
184 {
185 /* Delete us*/
187 }
188}
189
190DWORD
191WSAAPI
193{
194 /* Simply call the provider */
195 return WsNpLookupServiceEnd(QueryProvider->Provider,
196 QueryProvider->LookupHandle);
197}
198
199DWORD
200WSAAPI
202 IN DWORD ControlFlags,
204 LPWSAQUERYSETW Results)
205{
206 /* Simply call the provider */
207 return WsNpLookupServiceNext(QueryProvider->Provider,
208 QueryProvider->LookupHandle,
209 ControlFlags,
211 Results);
212}
213
214DWORD
215WSAAPI
217 IN LPWSAQUERYSETW Restrictions,
218 IN LPWSASERVICECLASSINFOW ServiceClassInfo,
219 IN DWORD ControlFlags)
220{
221 /* Simply call the provider */
222 return WsNpLookupServiceBegin(QueryProvider->Provider,
223 Restrictions,
224 ServiceClassInfo,
225 ControlFlags,
226 &QueryProvider->LookupHandle);
227}
228
229DWORD
230WSAAPI
232 IN HANDLE LookupHandle)
233{
234 /* Call the NSP */
235 return Provider->Service.NSPLookupServiceEnd(LookupHandle);
236}
237
238DWORD
239WSAAPI
241 IN HANDLE LookupHandle,
242 IN DWORD ControlFlags,
244 OUT LPWSAQUERYSETW Results)
245{
246 /* Call the NSP */
247 return Provider->Service.NSPLookupServiceNext(LookupHandle,
248 ControlFlags,
250 Results);
251}
252
253DWORD
254WSAAPI
256 IN LPWSAQUERYSETW Restrictions,
257 IN LPWSASERVICECLASSINFOW ServiceClassInfo,
258 IN DWORD ControlFlags,
259 OUT PHANDLE LookupHandle)
260{
261 /* Call the NSP */
262 return Provider->Service.NSPLookupServiceBegin(&Provider->ProviderId,
263 Restrictions,
264 ServiceClassInfo,
265 ControlFlags,
266 LookupHandle);
267}
268
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define CP_ACP
Definition: compat.h:109
#define GetProcAddress(x, y)
Definition: compat.h:753
#define HeapAlloc
Definition: compat.h:733
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define WideCharToMultiByte
Definition: compat.h:111
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:399
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
int Fail
Definition: ehthrow.cxx:24
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
DWORD WSAAPI WsNqProvLookupServiceNext(IN PNSQUERY_PROVIDER QueryProvider, IN DWORD ControlFlags, IN PDWORD BufferLength, LPWSAQUERYSETW Results)
Definition: nsprovid.c:201
DWORD WSAAPI WsNqProvLookupServiceBegin(IN PNSQUERY_PROVIDER QueryProvider, IN LPWSAQUERYSETW Restrictions, IN LPWSASERVICECLASSINFOW ServiceClassInfo, IN DWORD ControlFlags)
Definition: nsprovid.c:216
DWORD WSAAPI WsNpLookupServiceNext(IN PNS_PROVIDER Provider, IN HANDLE LookupHandle, IN DWORD ControlFlags, OUT PDWORD BufferLength, OUT LPWSAQUERYSETW Results)
Definition: nsprovid.c:240
DWORD WSAAPI WsNpLookupServiceEnd(IN PNS_PROVIDER Provider, IN HANDLE LookupHandle)
Definition: nsprovid.c:231
PNSQUERY_PROVIDER WSAAPI WsNqProvAllocate(VOID)
Definition: nsprovid.c:17
DWORD WSAAPI WsNqProvLookupServiceEnd(IN PNSQUERY_PROVIDER QueryProvider)
Definition: nsprovid.c:192
DWORD WSAAPI WsNqProvInitialize(IN PNSQUERY_PROVIDER QueryProvider, IN PNS_PROVIDER Provider)
Definition: nsprovid.c:30
DWORD WSAAPI WsNpNSPCleanup(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:140
DWORD WSAAPI WsNpInitialize(IN PNS_PROVIDER Provider, IN LPWSTR DllName, IN LPGUID ProviderId)
Definition: nsprovid.c:82
VOID WSAAPI WsNpDereference(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:180
VOID WSAAPI WsNpDelete(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:161
PNS_PROVIDER WSAAPI WsNpAllocate(VOID)
Definition: nsprovid.c:63
VOID WSAAPI WsNqProvDelete(IN PNSQUERY_PROVIDER QueryProvider)
Definition: nsprovid.c:45
DWORD WSAAPI WsNpLookupServiceBegin(IN PNS_PROVIDER Provider, IN LPWSAQUERYSETW Restrictions, IN LPWSASERVICECLASSINFOW ServiceClassInfo, IN DWORD ControlFlags, OUT PHANDLE LookupHandle)
Definition: nsprovid.c:255
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
DWORD * PDWORD
Definition: pedump.c:68
static LPWSAQUERYSETW
Definition: sock.c:90
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
#define WSAEPROVIDERFAILEDINIT
Definition: winerror.h:1993
#define WSAAPI
Definition: winsock2.h:605
HANDLE WsSockHeap
Definition: dllmain.c:21
_Must_inspect_result_ INT(WSAAPI * LPNSPSTARTUP)(_In_ LPGUID lpProviderId, _Inout_ LPNSP_ROUTINE lpnspRoutines)
Definition: ws2spi.h:671
struct _NSP_ROUTINE NSP_ROUTINE
INT(WSAAPI * LPNSPCLEANUP)(_In_ LPGUID lpProviderId)
Definition: ws2spi.h:494
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char CHAR
Definition: xmlstorage.h:175