ReactOS 0.4.15-dev-8219-ge8b88cf
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/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
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
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
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
120VOID
121WSAAPI
123{
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
141VOID
142WSAAPI
144{
145 /* Decrease the reference count and check if it's zero */
146 if (!InterlockedDecrement(&Provider->RefCount))
147 {
148 /* Delete us*/
150 }
151}
#define InterlockedDecrement
Definition: armddk.h:52
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#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 HEAP_ZERO_MEMORY
Definition: compat.h:134
INT WSPAPI WSPCleanup(OUT LPINT lpErrno)
Definition: dllmain.c:3247
INT WSPAPI WPUFDIsSet(IN SOCKET s, IN LPFD_SET set)
Definition: select.c:122
VOID WSAAPI WsTpDereference(IN PTPROVIDER Provider)
Definition: dprovide.c:143
DWORD WSAAPI WsTpWSPCleanup(IN PTPROVIDER Provider, IN LPINT lpErrNo)
Definition: dprovide.c:100
DWORD WSAAPI WsTpInitialize(IN PTPROVIDER Provider, IN LPSTR DllName, IN LPWSAPROTOCOL_INFOW ProtocolInfo)
Definition: dprovide.c:38
PTPROVIDER WSAAPI WsTpAllocate(VOID)
Definition: dprovide.c:20
VOID WSAAPI WsTpDelete(IN PTPROVIDER Provider)
Definition: dprovide.c:122
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
INT WSPAPI WPUGetProviderPath(IN LPGUID lpProviderId, OUT LPWSTR lpszProviderDllPath, IN OUT LPINT lpProviderDllPathLen, OUT LPINT lpErrno)
Definition: enumprot.c:297
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define DPRINT
Definition: sndvol32.h:73
INT WSPAPI WPUCloseSocketHandle(IN SOCKET s, OUT LPINT lpErrno)
Definition: socklife.c:176
SOCKET WSPAPI WPUCreateSocketHandle(IN DWORD dwCatalogEntryId, IN DWORD_PTR dwContext, OUT LPINT lpErrno)
Definition: socklife.c:188
SOCKET WSPAPI WPUModifyIFSHandle(IN DWORD dwCatalogEntryId, IN SOCKET ProposedHandle, OUT LPINT lpErrno)
Definition: socklife.c:201
INT WSPAPI WPUQuerySocketHandleContext(IN SOCKET s, OUT PDWORD_PTR lpContext, OUT LPINT lpErrno)
Definition: socklife.c:289
INT WSPAPI WPUCloseThread(IN LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
Definition: sputil.c:50
INT WSPAPI WPUQueryBlockingCallback(IN DWORD dwCatalogEntryId, OUT LPBLOCKINGCALLBACK FAR *lplpfnCallback, OUT PDWORD_PTR lpdwContext, OUT LPINT lpErrno)
Definition: sputil.c:102
WSAEVENT WSPAPI WPUCreateEvent(OUT LPINT lpErrno)
Definition: sputil.c:62
INT WSPAPI WPUOpenCurrentThread(OUT LPWSATHREADID lpThreadId, OUT LPINT lpErrno)
Definition: sputil.c:73
INT WSPAPI WPUQueueApc(IN LPWSATHREADID lpThreadId, IN LPWSAUSERAPC lpfnUserApc, IN DWORD_PTR dwContext, OUT LPINT lpErrno)
Definition: sputil.c:173
BOOL WSPAPI WPUResetEvent(IN WSAEVENT hEvent, OUT LPINT lpErrno)
Definition: sputil.c:187
BOOL WSPAPI WPUCloseEvent(IN WSAEVENT hEvent, OUT LPINT lpErrno)
Definition: sputil.c:38
BOOL WSPAPI WPUSetEvent(IN WSAEVENT hEvent, OUT LPINT lpErrno)
Definition: sputil.c:199
BOOL WSPAPI WPUPostMessage(IN HWND hWnd, IN UINT Msg, IN WPARAM wParam, IN LPARAM lParam)
Definition: sputil.c:85
Definition: ws2spi.h:46
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int32_t INT
Definition: typedefs.h:58
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define ExpandEnvironmentStrings
Definition: winbase.h:3774
#define LoadLibrary
Definition: winbase.h:3862
int * LPINT
Definition: windef.h:178
#define WSAAPI
Definition: winsock2.h:605
#define SOCKET_ERROR
Definition: winsock.h:333
HANDLE WsSockHeap
Definition: dllmain.c:21
int(WSPAPI * LPWSPCLEANUP)(_Out_ LPINT lpErrno)
Definition: ws2spi.h:100
_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
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175