fcf70062ea40642db86081ffab1f9230c15143ee
[reactos.git] / reactos / dll / win32 / msafd / msafd.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Ancillary Function Driver DLL
4 * FILE: dll/win32/msafd/msafd.h
5 * PURPOSE: Ancillary Function Driver DLL header
6 */
7
8 #ifndef __MSAFD_H
9 #define __MSAFD_H
10
11 #include <stdarg.h>
12
13 #define WIN32_NO_STATUS
14 #define _INC_WINDOWS
15 #define COM_NO_WINDOWS_H
16
17 #include <windef.h>
18 #include <winbase.h>
19 #include <ws2spi.h>
20 #define NTOS_MODE_USER
21 #include <ndk/exfuncs.h>
22 #include <ndk/iofuncs.h>
23 #include <ndk/obfuncs.h>
24 #include <ndk/rtlfuncs.h>
25
26 /* This includes ntsecapi.h so it needs to come after the NDK */
27 #include <wsahelp.h>
28 #include <tdi.h>
29 #include <afd/shared.h>
30 #include <mswsock.h>
31 #include "include/helpers.h"
32
33 extern HANDLE GlobalHeap;
34 extern WSPUPCALLTABLE Upcalls;
35 extern LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest;
36 extern LIST_ENTRY SockHelpersListHead;
37 extern HANDLE SockEvent;
38 extern HANDLE SockAsyncCompletionPort;
39 extern BOOLEAN SockAsyncSelectCalled;
40
41 typedef enum _SOCKET_STATE {
42 SocketOpen,
43 SocketBound,
44 SocketBoundUdp,
45 SocketConnected,
46 SocketClosed
47 } SOCKET_STATE, *PSOCKET_STATE;
48
49 typedef struct _SOCK_SHARED_INFO {
50 SOCKET_STATE State;
51 LONG RefCount;
52 INT AddressFamily;
53 INT SocketType;
54 INT Protocol;
55 INT SizeOfLocalAddress;
56 INT SizeOfRemoteAddress;
57 struct linger LingerData;
58 ULONG SendTimeout;
59 ULONG RecvTimeout;
60 ULONG SizeOfRecvBuffer;
61 ULONG SizeOfSendBuffer;
62 struct {
63 BOOLEAN Listening:1;
64 BOOLEAN Broadcast:1;
65 BOOLEAN Debug:1;
66 BOOLEAN OobInline:1;
67 BOOLEAN ReuseAddresses:1;
68 BOOLEAN ExclusiveAddressUse:1;
69 BOOLEAN NonBlocking:1;
70 BOOLEAN DontUseWildcard:1;
71 BOOLEAN ReceiveShutdown:1;
72 BOOLEAN SendShutdown:1;
73 BOOLEAN UseDelayedAcceptance:1;
74 BOOLEAN UseSAN:1;
75 }; // Flags
76 DWORD CreateFlags;
77 DWORD ServiceFlags1;
78 DWORD ProviderFlags;
79 GROUP GroupID;
80 DWORD GroupType;
81 INT GroupPriority;
82 INT SocketLastError;
83 HWND hWnd;
84 LONG Unknown;
85 DWORD SequenceNumber;
86 UINT wMsg;
87 LONG AsyncEvents;
88 LONG AsyncDisabledEvents;
89 SOCKADDR WSLocalAddress;
90 SOCKADDR WSRemoteAddress;
91 } SOCK_SHARED_INFO, *PSOCK_SHARED_INFO;
92
93 typedef struct _SOCKET_INFORMATION {
94 SOCKET Handle;
95 PSOCK_SHARED_INFO SharedData;
96 HANDLE SharedDataHandle;
97 DWORD HelperEvents;
98 PHELPER_DATA HelperData;
99 PVOID HelperContext;
100 PSOCKADDR LocalAddress;
101 PSOCKADDR RemoteAddress;
102 HANDLE TdiAddressHandle;
103 HANDLE TdiConnectionHandle;
104 PVOID AsyncData;
105 HANDLE EventObject;
106 LONG NetworkEvents;
107 CRITICAL_SECTION Lock;
108 PVOID SanData;
109 BOOL TrySAN;
110 WSAPROTOCOL_INFOW ProtocolInfo;
111 struct _SOCKET_INFORMATION *NextSocket;
112 } SOCKET_INFORMATION, *PSOCKET_INFORMATION;
113
114
115 typedef struct _SOCKET_CONTEXT {
116 SOCK_SHARED_INFO SharedData;
117 ULONG SizeOfHelperData;
118 ULONG Padding;
119 SOCKADDR LocalAddress;
120 SOCKADDR RemoteAddress;
121 /* Plus Helper Data */
122 } SOCKET_CONTEXT, *PSOCKET_CONTEXT;
123
124 typedef struct _ASYNC_DATA {
125 PSOCKET_INFORMATION ParentSocket;
126 DWORD SequenceNumber;
127 IO_STATUS_BLOCK IoStatusBlock;
128 AFD_POLL_INFO AsyncSelectInfo;
129 } ASYNC_DATA, *PASYNC_DATA;
130
131 typedef struct _AFDAPCCONTEXT
132 {
133 LPWSAOVERLAPPED lpOverlapped;
134 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine;
135 PSOCKET_INFORMATION lpSocket;
136 } AFDAPCCONTEXT, *PAFDAPCCONTEXT;
137
138 SOCKET
139 WSPAPI
140 WSPAccept(
141 IN SOCKET s,
142 OUT LPSOCKADDR addr,
143 IN OUT LPINT addrlen,
144 IN LPCONDITIONPROC lpfnCondition,
145 IN DWORD dwCallbackData,
146 OUT LPINT lpErrno);
147
148 INT
149 WSPAPI
150 WSPAddressToString(
151 IN LPSOCKADDR lpsaAddress,
152 IN DWORD dwAddressLength,
153 IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
154 OUT LPWSTR lpszAddressString,
155 IN OUT LPDWORD lpdwAddressStringLength,
156 OUT LPINT lpErrno);
157
158 INT
159 WSPAPI
160 WSPAsyncSelect(
161 IN SOCKET s,
162 IN HWND hWnd,
163 IN UINT wMsg,
164 IN LONG lEvent,
165 OUT LPINT lpErrno);
166
167 INT
168 WSPAPI WSPBind(
169 IN SOCKET s,
170 IN CONST SOCKADDR *name,
171 IN INT namelen,
172 OUT LPINT lpErrno);
173
174 INT
175 WSPAPI
176 WSPCancelBlockingCall(
177 OUT LPINT lpErrno);
178
179 INT
180 WSPAPI
181 WSPCleanup(
182 OUT LPINT lpErrno);
183
184 INT
185 WSPAPI
186 WSPCloseSocket(
187 IN SOCKET s,
188 OUT LPINT lpErrno);
189
190 INT
191 WSPAPI
192 WSPConnect(
193 IN SOCKET s,
194 IN CONST SOCKADDR *name,
195 IN INT namelen,
196 IN LPWSABUF lpCallerData,
197 OUT LPWSABUF lpCalleeData,
198 IN LPQOS lpSQOS,
199 IN LPQOS lpGQOS,
200 OUT LPINT lpErrno);
201
202 INT
203 WSPAPI
204 WSPDuplicateSocket(
205 IN SOCKET s,
206 IN DWORD dwProcessId,
207 OUT LPWSAPROTOCOL_INFOW lpProtocolInfo,
208 OUT LPINT lpErrno);
209
210 INT
211 WSPAPI
212 WSPEnumNetworkEvents(
213 IN SOCKET s,
214 IN WSAEVENT hEventObject,
215 OUT LPWSANETWORKEVENTS lpNetworkEvents,
216 OUT LPINT lpErrno);
217
218 INT
219 WSPAPI
220 WSPEventSelect(
221 IN SOCKET s,
222 IN WSAEVENT hEventObject,
223 IN LONG lNetworkEvents,
224 OUT LPINT lpErrno);
225
226 BOOL
227 WSPAPI
228 WSPGetOverlappedResult(
229 IN SOCKET s,
230 IN LPWSAOVERLAPPED lpOverlapped,
231 OUT LPDWORD lpcbTransfer,
232 IN BOOL fWait,
233 OUT LPDWORD lpdwFlags,
234 OUT LPINT lpErrno);
235
236 INT
237 WSPAPI
238 WSPGetPeerName(
239 IN SOCKET s,
240 OUT LPSOCKADDR name,
241 IN OUT LPINT namelen,
242 OUT LPINT lpErrno);
243
244 BOOL
245 WSPAPI
246 WSPGetQOSByName(
247 IN SOCKET s,
248 IN OUT LPWSABUF lpQOSName,
249 OUT LPQOS lpQOS,
250 OUT LPINT lpErrno);
251
252 INT
253 WSPAPI
254 WSPGetSockName(
255 IN SOCKET s,
256 OUT LPSOCKADDR name,
257 IN OUT LPINT namelen,
258 OUT LPINT lpErrno);
259
260 INT
261 WSPAPI
262 WSPGetSockOpt(
263 IN SOCKET s,
264 IN INT level,
265 IN INT optname,
266 OUT CHAR FAR* optval,
267 IN OUT LPINT optlen,
268 OUT LPINT lpErrno);
269
270 INT
271 WSPAPI
272 WSPIoctl(
273 IN SOCKET s,
274 IN DWORD dwIoControlCode,
275 IN LPVOID lpvInBuffer,
276 IN DWORD cbInBuffer,
277 OUT LPVOID lpvOutBuffer,
278 IN DWORD cbOutBuffer,
279 OUT LPDWORD lpcbBytesReturned,
280 IN LPWSAOVERLAPPED lpOverlapped,
281 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
282 IN LPWSATHREADID lpThreadId,
283 OUT LPINT lpErrno);
284
285 SOCKET
286 WSPAPI
287 WSPJoinLeaf(
288 IN SOCKET s,
289 IN CONST SOCKADDR *name,
290 IN INT namelen,
291 IN LPWSABUF lpCallerData,
292 OUT LPWSABUF lpCalleeData,
293 IN LPQOS lpSQOS,
294 IN LPQOS lpGQOS,
295 IN DWORD dwFlags,
296 OUT LPINT lpErrno);
297
298 INT
299 WSPAPI
300 WSPListen(
301 IN SOCKET s,
302 IN INT backlog,
303 OUT LPINT lpErrno);
304
305 INT
306 WSPAPI
307 WSPRecv(
308 IN SOCKET s,
309 IN OUT LPWSABUF lpBuffers,
310 IN DWORD dwBufferCount,
311 OUT LPDWORD lpNumberOfBytesRecvd,
312 IN OUT LPDWORD lpFlags,
313 IN LPWSAOVERLAPPED lpOverlapped,
314 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
315 IN LPWSATHREADID lpThreadId,
316 OUT LPINT lpErrno);
317
318 INT
319 WSPAPI
320 WSPRecvDisconnect(
321 IN SOCKET s,
322 OUT LPWSABUF lpInboundDisconnectData,
323 OUT LPINT lpErrno);
324
325 INT
326 WSPAPI
327 WSPRecvFrom(
328 IN SOCKET s,
329 IN OUT LPWSABUF lpBuffers,
330 IN DWORD dwBufferCount,
331 OUT LPDWORD lpNumberOfBytesRecvd,
332 IN OUT LPDWORD lpFlags,
333 OUT LPSOCKADDR lpFrom,
334 IN OUT LPINT lpFromlen,
335 IN LPWSAOVERLAPPED lpOverlapped,
336 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
337 IN LPWSATHREADID lpThreadId,
338 OUT LPINT lpErrno);
339
340 INT
341 WSPAPI
342 WSPSelect(
343 IN INT nfds,
344 IN OUT fd_set *readfds,
345 IN OUT fd_set *writefds,
346 IN OUT fd_set *exceptfds,
347 IN CONST struct timeval *timeout,
348 OUT LPINT lpErrno);
349
350 INT
351 WSPAPI
352 WSPSend(
353 IN SOCKET s,
354 IN LPWSABUF lpBuffers,
355 IN DWORD dwBufferCount,
356 OUT LPDWORD lpNumberOfBytesSent,
357 IN DWORD dwFlags,
358 IN LPWSAOVERLAPPED lpOverlapped,
359 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
360 IN LPWSATHREADID lpThreadId,
361 OUT LPINT lpErrno);
362
363 INT
364 WSPAPI
365 WSPSendDisconnect(
366 IN SOCKET s,
367 IN LPWSABUF lpOutboundDisconnectData,
368 OUT LPINT lpErrno);
369
370 INT
371 WSPAPI
372 WSPSendTo(
373 IN SOCKET s,
374 IN LPWSABUF lpBuffers,
375 IN DWORD dwBufferCount,
376 OUT LPDWORD lpNumberOfBytesSent,
377 IN DWORD dwFlags,
378 IN CONST SOCKADDR *lpTo,
379 IN INT iTolen,
380 IN LPWSAOVERLAPPED lpOverlapped,
381 IN LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
382 IN LPWSATHREADID lpThreadId,
383 OUT LPINT lpErrno);
384
385 INT
386 WSPAPI
387 WSPSetSockOpt(
388 IN SOCKET s,
389 IN INT level,
390 IN INT optname,
391 IN CONST CHAR FAR* optval,
392 IN INT optlen,
393 OUT LPINT lpErrno);
394
395 INT
396 WSPAPI
397 WSPShutdown(
398 IN SOCKET s,
399 IN INT how,
400 OUT LPINT lpErrno);
401
402 SOCKET
403 WSPAPI
404 WSPSocket(
405 IN INT af,
406 IN INT type,
407 IN INT protocol,
408 IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
409 IN GROUP g,
410 IN DWORD dwFlags,
411 OUT LPINT lpErrno);
412
413 INT
414 WSPAPI
415 WSPStringToAddress(
416 IN LPWSTR AddressString,
417 IN INT AddressFamily,
418 IN LPWSAPROTOCOL_INFOW lpProtocolInfo,
419 OUT LPSOCKADDR lpAddress,
420 IN OUT LPINT lpAddressLength,
421 OUT LPINT lpErrno);
422
423
424 PSOCKET_INFORMATION GetSocketStructure(
425 SOCKET Handle
426 );
427
428 INT TranslateNtStatusError( NTSTATUS Status );
429
430 VOID DeleteSocketStructure( SOCKET Handle );
431
432 int GetSocketInformation(
433 PSOCKET_INFORMATION Socket,
434 ULONG AfdInformationClass,
435 PBOOLEAN Boolean OPTIONAL,
436 PULONG Ulong OPTIONAL,
437 PLARGE_INTEGER LargeInteger OPTIONAL,
438 LPWSAOVERLAPPED Overlapped OPTIONAL,
439 LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL
440 );
441
442 int SetSocketInformation(
443 PSOCKET_INFORMATION Socket,
444 ULONG AfdInformationClass,
445 PBOOLEAN Boolean OPTIONAL,
446 PULONG Ulong OPTIONAL,
447 PLARGE_INTEGER LargeInteger OPTIONAL,
448 LPWSAOVERLAPPED Overlapped OPTIONAL,
449 LPWSAOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine OPTIONAL
450 );
451
452 int CreateContext(
453 PSOCKET_INFORMATION Socket
454 );
455
456 int SockAsyncThread(
457 PVOID ThreadParam
458 );
459
460 VOID
461 SockProcessAsyncSelect(
462 PSOCKET_INFORMATION Socket,
463 PASYNC_DATA AsyncData
464 );
465
466 VOID
467 SockAsyncSelectCompletionRoutine(
468 PVOID Context,
469 PIO_STATUS_BLOCK IoStatusBlock
470 );
471
472 BOOLEAN
473 SockCreateOrReferenceAsyncThread(
474 VOID
475 );
476
477 BOOLEAN SockGetAsyncSelectHelperAfdHandle(
478 VOID
479 );
480
481 VOID SockProcessQueuedAsyncSelect(
482 PVOID Context,
483 PIO_STATUS_BLOCK IoStatusBlock
484 );
485
486 VOID
487 SockReenableAsyncSelectEvent (
488 IN PSOCKET_INFORMATION Socket,
489 IN ULONG Event
490 );
491
492 typedef VOID (*PASYNC_COMPLETION_ROUTINE)(PVOID Context, PIO_STATUS_BLOCK IoStatusBlock);
493
494 FORCEINLINE
495 DWORD
496 MsafdReturnWithErrno(NTSTATUS Status,
497 LPINT Errno,
498 DWORD Received,
499 LPDWORD ReturnedBytes)
500 {
501 if (Errno)
502 {
503 *Errno = TranslateNtStatusError(Status);
504
505 if (ReturnedBytes)
506 *ReturnedBytes = (*Errno == 0) ? Received : 0;
507
508 return (*Errno == 0) ? 0 : SOCKET_ERROR;
509 }
510 else
511 {
512 DbgPrint("%s: Received invalid lpErrno pointer!\n", __FUNCTION__);
513
514 if (ReturnedBytes)
515 *ReturnedBytes = (Status == STATUS_SUCCESS) ? Received : 0;
516
517 return (Status == STATUS_SUCCESS) ? 0 : SOCKET_ERROR;
518 }
519 }
520
521 #endif /* __MSAFD_H */