ReactOS  0.4.13-dev-100-gc8611ae
dprovide.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/dprovide.c
5  * PURPOSE: Transport Provider Object
6  * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <ws2_32.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS *****************************************************************/
17 
19 WSAAPI
21 {
23 
24  /* Allocate the object */
26  if (Provider)
27  {
28  /* Setup non-zero data */
29  Provider->RefCount = 1;
30  }
31 
32  /* Return it */
33  return Provider;
34 }
35 
36 DWORD
37 WSAAPI
39  IN LPSTR DllName,
40  IN LPWSAPROTOCOL_INFOW ProtocolInfo)
41 {
42  WORD VersionRequested = MAKEWORD(2,2);
43  LPWSPSTARTUP WSPStartupProc;
44  WSPDATA WspData;
45  CHAR ExpandedDllPath[MAX_PATH];
47  DPRINT("WsTpInitialize: %p, %p, %p\n", Provider, DllName, ProtocolInfo);
48 
49  /* Clear the tables */
50  RtlZeroMemory(&Provider->UpcallTable, sizeof(Provider->UpcallTable));
51  RtlZeroMemory(&Provider->Service, sizeof(Provider->Service));
52 
53  /* Set up the Upcall Table */
54  Provider->UpcallTable.lpWPUCloseEvent = WPUCloseEvent;
55  Provider->UpcallTable.lpWPUCloseSocketHandle = WPUCloseSocketHandle;
56  Provider->UpcallTable.lpWPUCreateEvent = WPUCreateEvent;
57  Provider->UpcallTable.lpWPUCreateSocketHandle = WPUCreateSocketHandle;
58  Provider->UpcallTable.lpWPUFDIsSet = WPUFDIsSet;
59  Provider->UpcallTable.lpWPUGetProviderPath = WPUGetProviderPath;
60  Provider->UpcallTable.lpWPUModifyIFSHandle = WPUModifyIFSHandle;
61  Provider->UpcallTable.lpWPUPostMessage = WPUPostMessage;
62  Provider->UpcallTable.lpWPUQueryBlockingCallback = WPUQueryBlockingCallback;
63  Provider->UpcallTable.lpWPUQuerySocketHandleContext = WPUQuerySocketHandleContext;
64  Provider->UpcallTable.lpWPUQueueApc = WPUQueueApc;
65  Provider->UpcallTable.lpWPUResetEvent = WPUResetEvent;
66  Provider->UpcallTable.lpWPUSetEvent = WPUSetEvent;
67  Provider->UpcallTable.lpWPUOpenCurrentThread = WPUOpenCurrentThread;
68  Provider->UpcallTable.lpWPUCloseThread = WPUCloseThread;
69 
70  /* Expand the DLL Path */
71  ExpandEnvironmentStrings(DllName, ExpandedDllPath, MAX_PATH);
72 
73  /* Load the DLL */
74  Provider->DllHandle = LoadLibrary(ExpandedDllPath);
75 
76  if (!Provider->DllHandle)
77  {
78  return SOCKET_ERROR;
79  }
80  /* Get the pointer to WSPStartup */
81  WSPStartupProc = (LPWSPSTARTUP)GetProcAddress(Provider->DllHandle, "WSPStartup");
82 
83  if (!WSPStartupProc)
84  {
85  return SOCKET_ERROR;
86  }
87  /* Call it */
88  ErrorCode = (*WSPStartupProc)(VersionRequested,
89  &WspData,
90  ProtocolInfo,
91  Provider->UpcallTable,
92  &Provider->Service);
93 
94  /* Return */
95  return ErrorCode;
96 }
97 
98 DWORD
99 WSAAPI
101  IN LPINT lpErrNo)
102 {
105 
106  /* Make sure we have a loaded handle */
107  if (Provider->DllHandle)
108  {
109  /* Get the pointer and clear it */
110  WSPCleanup = InterlockedExchangePointer((PVOID*)&Provider->Service.lpWSPCleanup,
111  NULL);
112  /* If it's not NULL, call it */
113  if (WSPCleanup) ErrorCode = WSPCleanup(lpErrNo);
114  }
115 
116  /* Return */
117  return ErrorCode;
118 }
119 
120 VOID
121 WSAAPI
123 {
124  INT ErrorCode;
125 
126  /* Make sure we have a loaded handle */
127  if (Provider->DllHandle)
128  {
129  /* Clean us up */
131 
132  /* Unload the library */
133  FreeLibrary(Provider->DllHandle);
134  Provider->DllHandle = NULL;
135  }
136 
137  /* Delete us */
139 }
140 
141 VOID
142 WSAAPI
144 {
145  /* Decrease the reference count and check if it's zero */
146  if (!InterlockedDecrement(&Provider->RefCount))
147  {
148  /* Delete us*/
150  }
151 }
SOCKET WSPAPI WPUCreateSocketHandle(IN DWORD dwCatalogEntryId, IN DWORD_PTR dwContext, OUT LPINT lpErrno)
Definition: socklife.c:188
#define SOCKET_ERROR
Definition: winsock.h:333
#define IN
Definition: typedefs.h:38
INT WSPAPI WPUQuerySocketHandleContext(IN SOCKET s, OUT PDWORD_PTR lpContext, OUT LPINT lpErrno)
Definition: socklife.c:289
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LoadLibrary
Definition: winbase.h:3676
int(WSPAPI * LPWSPCLEANUP)(_Out_ LPINT lpErrno)
Definition: ws2spi.h:100
#define MAKEWORD(a, b)
Definition: typedefs.h:247
char CHAR
Definition: xmlstorage.h:175
#define ExpandEnvironmentStrings
Definition: winbase.h:3588
SOCKET WSPAPI WPUModifyIFSHandle(IN DWORD dwCatalogEntryId, IN SOCKET ProposedHandle, OUT LPINT lpErrno)
Definition: socklife.c:201
INT WSPAPI WPUFDIsSet(IN SOCKET s, IN LPFD_SET set)
Definition: select.c:122
char * LPSTR
Definition: xmlstorage.h:182
WSAEVENT WSPAPI WPUCreateEvent(OUT LPINT lpErrno)
Definition: sputil.c:62
int32_t INT
Definition: typedefs.h:56
INT WSPAPI WSPCleanup(OUT LPINT lpErrno)
Definition: dllmain.c:3234
PTPROVIDER WSAAPI WsTpAllocate(VOID)
Definition: dprovide.c:20
INT WSPAPI WPUQueryBlockingCallback(IN DWORD dwCatalogEntryId, OUT LPBLOCKINGCALLBACK FAR *lplpfnCallback, OUT PDWORD_PTR lpdwContext, OUT LPINT lpErrno)
Definition: sputil.c:102
Definition: ws2spi.h:46
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
INT WSPAPI WPUCloseSocketHandle(IN SOCKET s, OUT LPINT lpErrno)
Definition: socklife.c:176
VOID WSAAPI WsTpDelete(IN PTPROVIDER Provider)
Definition: dprovide.c:122
#define FreeLibrary(x)
Definition: compat.h:405
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
VOID WSAAPI WsTpDereference(IN PTPROVIDER Provider)
Definition: dprovide.c:143
BOOL WSPAPI WPUCloseEvent(IN WSAEVENT hEvent, OUT LPINT lpErrno)
Definition: sputil.c:38
BOOL WSPAPI WPUResetEvent(IN WSAEVENT hEvent, OUT LPINT lpErrno)
Definition: sputil.c:187
BOOL WSPAPI WPUSetEvent(IN WSAEVENT hEvent, OUT LPINT lpErrno)
Definition: sputil.c:199
#define MAX_PATH
Definition: compat.h:26
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
INT WSPAPI WPUOpenCurrentThread(OUT LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
Definition: sputil.c:73
#define InterlockedDecrement
Definition: armddk.h:52
DWORD WSAAPI WsTpInitialize(IN PTPROVIDER Provider, IN LPSTR DllName, IN LPWSAPROTOCOL_INFOW ProtocolInfo)
Definition: dprovide.c:38
INT WSPAPI WPUCloseThread(IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
Definition: sputil.c:50
INT WSPAPI WPUQueueApc(IN LPWSATHREADID lpThreadId, IN LPWSAUSERAPC lpfnUserApc, IN DWORD_PTR dwContext, OUT LPINT lpErrno)
Definition: sputil.c:173
#define WSAAPI
Definition: winsock2.h:584
_Must_inspect_result_ int(WSPAPI * LPWSPSTARTUP)(_In_ WORD wVersionRequested, _In_ LPWSPDATA lpWSPData, _In_ LPWSAPROTOCOL_INFOW lpProtocolInfo, _In_ WSPUPCALLTABLE UpcallTable, _Out_ LPWSPPROC_TABLE lpProcTable)
Definition: ws2spi.h:622
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
DWORD WSAAPI WsTpWSPCleanup(IN PTPROVIDER Provider, IN LPINT lpErrNo)
Definition: dprovide.c:100
INT WSPAPI WPUGetProviderPath(IN LPGUID lpProviderId, OUT LPWSTR lpszProviderDllPath, IN OUT LPINT lpProviderDllPathLen, OUT LPINT lpErrno)
Definition: enumprot.c:297
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define GetProcAddress(x, y)
Definition: compat.h:410
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:394
BOOL WSPAPI WPUPostMessage(IN HWND hWnd, IN UINT Msg, IN WPARAM wParam, IN LPARAM lParam)
Definition: sputil.c:85
int * LPINT
Definition: windef.h:178