ReactOS  0.4.14-dev-41-g31d7680
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_new/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 
16 WSAAPI
18 {
20 
21  /* Allocate the object */
23 
24  /* Return it */
25  return Provider;
26 }
27 
28 DWORD
29 WSAAPI
32 {
33  /* Reference the provider */
34  InterlockedIncrement(&Provider->RefCount);
35 
36  /* Set it as our own */
37  QueryProvider->Provider = Provider;
38 
39  /* Return success */
40  return ERROR_SUCCESS;
41 }
42 
43 VOID
44 WSAAPI
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 
62 WSAAPI
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 
80 DWORD
81 WSAAPI
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,
96  MAX_PATH,
97  NULL,
98  NULL);
99 
100  /* Expand the DLL Path */
101  ExpandEnvironmentStringsA(AnsiPath,
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 
131 Fail:
132  /* Bail out */
133  if (Provider->DllHandle) FreeLibrary(Provider->DllHandle);
134  Provider->DllHandle = NULL;
135  return ErrorCode;
136 }
137 
138 DWORD
139 WSAAPI
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 
159 VOID
160 WSAAPI
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 
178 VOID
179 WSAAPI
181 {
182  /* Decrease the reference count and check if it's zero */
183  if (!InterlockedDecrement(&Provider->RefCount))
184  {
185  /* Delete us*/
187  }
188 }
189 
190 DWORD
191 WSAAPI
193 {
194  /* Simply call the provider */
195  return WsNpLookupServiceEnd(QueryProvider->Provider,
196  QueryProvider->LookupHandle);
197 }
198 
199 DWORD
200 WSAAPI
202  IN DWORD ControlFlags,
204  LPWSAQUERYSETW Results)
205 {
206  /* Simply call the provider */
207  return WsNpLookupServiceNext(QueryProvider->Provider,
208  QueryProvider->LookupHandle,
209  ControlFlags,
210  BufferLength,
211  Results);
212 }
213 
214 DWORD
215 WSAAPI
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 
229 DWORD
230 WSAAPI
232  IN HANDLE LookupHandle)
233 {
234  /* Call the NSP */
235  return Provider->Service.NSPLookupServiceEnd(LookupHandle);
236 }
237 
238 DWORD
239 WSAAPI
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,
249  BufferLength,
250  Results);
251 }
252 
253 DWORD
254 WSAAPI
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 
INT(WSAAPI * LPNSPCLEANUP)(_In_ LPGUID lpProviderId)
Definition: ws2spi.h:494
#define IN
Definition: typedefs.h:38
DWORD WSAAPI WsNpNSPCleanup(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:140
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
DWORD WSAAPI WsNpLookupServiceBegin(IN PNS_PROVIDER Provider, IN LPWSAQUERYSETW Restrictions, IN LPWSASERVICECLASSINFOW ServiceClassInfo, IN DWORD ControlFlags, OUT PHANDLE LookupHandle)
Definition: nsprovid.c:255
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
static LPWSAQUERYSETW
Definition: sock.c:91
int32_t INT
Definition: typedefs.h:56
PNSQUERY_PROVIDER WSAAPI WsNqProvAllocate(VOID)
Definition: nsprovid.c:17
_In_ ULONG BufferLength
Definition: usbdlib.h:225
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD WSAAPI WsNqProvLookupServiceBegin(IN PNSQUERY_PROVIDER QueryProvider, IN LPWSAQUERYSETW Restrictions, IN LPWSASERVICECLASSINFOW ServiceClassInfo, IN DWORD ControlFlags)
Definition: nsprovid.c:216
DWORD WSAAPI WsNqProvInitialize(IN PNSQUERY_PROVIDER QueryProvider, IN PNS_PROVIDER Provider)
Definition: nsprovid.c:30
smooth NULL
Definition: ftsmooth.c:416
DWORD WINAPI ExpandEnvironmentStringsA(IN LPCSTR lpSrc, IN LPSTR lpDst, IN DWORD nSize)
Definition: environ.c:399
VOID WSAAPI WsNqProvDelete(IN PNSQUERY_PROVIDER QueryProvider)
Definition: nsprovid.c:45
#define FreeLibrary(x)
Definition: compat.h:405
DWORD WSAAPI WsNqProvLookupServiceNext(IN PNSQUERY_PROVIDER QueryProvider, IN DWORD ControlFlags, IN PDWORD BufferLength, LPWSAQUERYSETW Results)
Definition: nsprovid.c:201
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
DWORD WSAAPI WsNpLookupServiceEnd(IN PNS_PROVIDER Provider, IN HANDLE LookupHandle)
Definition: nsprovid.c:231
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define MAX_PATH
Definition: compat.h:26
VOID WSAAPI WsNpDereference(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define InterlockedDecrement
Definition: armddk.h:52
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
DWORD WSAAPI WsNpLookupServiceNext(IN PNS_PROVIDER Provider, IN HANDLE LookupHandle, IN DWORD ControlFlags, OUT PDWORD BufferLength, OUT LPWSAQUERYSETW Results)
Definition: nsprovid.c:240
Definition: hiveinit.c:368
_Must_inspect_result_ INT(WSAAPI * LPNSPSTARTUP)(_In_ LPGUID lpProviderId, _Inout_ LPNSP_ROUTINE lpnspRoutines)
Definition: ws2spi.h:671
struct _NSP_ROUTINE NSP_ROUTINE
#define InterlockedIncrement
Definition: armddk.h:53
DWORD WSAAPI WsNpInitialize(IN PNS_PROVIDER Provider, IN LPWSTR DllName, IN LPGUID ProviderId)
Definition: nsprovid.c:82
#define WSAAPI
Definition: winsock2.h:584
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
PNS_PROVIDER WSAAPI WsNpAllocate(VOID)
Definition: nsprovid.c:63
DWORD * PDWORD
Definition: pedump.c:68
DWORD WSAAPI WsNqProvLookupServiceEnd(IN PNSQUERY_PROVIDER QueryProvider)
Definition: nsprovid.c:192
#define OUT
Definition: typedefs.h:39
#define WSAEPROVIDERFAILEDINIT
Definition: winerror.h:1993
#define GetProcAddress(x, y)
Definition: compat.h:410
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:394
VOID WSAAPI WsNpDelete(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:161