Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331/* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS WinSock 2 API * FILE: dll/win32/ws2_32/src/dprocess.c * PURPOSE: Process Object * PROGRAMMER: Alex Ionescu (alex@relsoft.net) */
/* INCLUDES ******************************************************************/
#include <ws2_32.h>
/* DATA **********************************************************************/
PWSPROCESS CurrentWsProcess;
#define WsProcLock() EnterCriticalSection(&Process->ThreadLock)#define WsProcUnlock() LeaveCriticalSection(&Process->ThreadLock)
/* FUNCTIONS *****************************************************************/
INTWSAAPIWsProcInitialize(IN PWSPROCESS Process){ INT ErrorCode = WSAEFAULT; HKEY RootKey = NULL;
/* Initialize the thread list lock */ InitializeCriticalSection(&Process->ThreadLock); Process->LockReady = TRUE;
/* Open the Winsock Key */ RootKey = WsOpenRegistryRoot();
/* Create the LP Catalog change event and catalog */ Process->ProtocolCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL); Process->ProtocolCatalog = WsTcAllocate();
// FIXME: Check for Process->ProtocolCatalog == NULL
/* Initialize it */ WsTcInitializeFromRegistry(Process->ProtocolCatalog, RootKey, Process->ProtocolCatalogEvent);
/* Create the NS Catalog change event and catalog */ Process->NamespaceCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL); Process->NamespaceCatalog = WsNcAllocate();
// FIXME: Check for Process->NamespaceCatalog == NULL
/* Initialize it */ ErrorCode = WsNcInitializeFromRegistry(Process->NamespaceCatalog, RootKey, Process->NamespaceCatalogEvent);
/* Close the root key */ RegCloseKey(RootKey); return ErrorCode;}
PWSPROCESSWSAAPIWsProcAllocate(VOID){ PWSPROCESS Process;
/* Allocate the structure */ Process = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Process)); if (Process) { /* Set default non-zero values */ Process->Version = MAKEWORD(2,2); }
/* Return it */ return Process;}
INTWSAAPIWsProcOpenAsyncHelperDevice(IN PWSPROCESS Process, OUT PHANDLE Handle){ INT ErrorCode = WSASYSCALLFAILURE;
/* Lock the process */ WsProcLock();
/* Check if we have a handle, and if not, create one */ if ((Process->ApcHelper) || (WahOpenApcHelper(&Process->ApcHelper) == ERROR_SUCCESS)) { /* Return the handle */ *Handle = Process->ApcHelper; ErrorCode = ERROR_SUCCESS; }
/* Unload the process and return */ WsProcUnlock(); return ErrorCode;}
INTWSAAPIWsProcGetAsyncHelper(IN PWSPROCESS Process, OUT PHANDLE Handle){ /* Check if we have it already set up */ if (Process->ApcHelper) { /* Just return it */ *Handle = Process->ApcHelper; return ERROR_SUCCESS; } else { /* Open it for the first time */ return WsProcOpenAsyncHelperDevice(Process, Handle); }}
INTWSAAPIWsProcStartup(VOID){ INT ErrorCode = WSAEFAULT;
/* Create a new process */ CurrentWsProcess = WsProcAllocate();
/* Initialize it */ if (CurrentWsProcess) { /* Initialize the process */ ErrorCode = WsProcInitialize(CurrentWsProcess); } else { /* No memory for the process object */ ErrorCode = WSA_NOT_ENOUGH_MEMORY; }
return ErrorCode;}
PTCATALOGWSAAPIWsProcGetTCatalog(IN PWSPROCESS Process){ /* Check if the catalogs have been modified */ if (WsCheckCatalogState(Process->ProtocolCatalogEvent)) { /* Modification happened, reload them */ WsTcRefreshFromRegistry(Process->ProtocolCatalog, Process->ProtocolCatalogEvent); }
/* Return it */ return Process->ProtocolCatalog;}
PNSCATALOGWSAAPIWsProcGetNsCatalog(IN PWSPROCESS Process){ /* Check if the catalogs have been modified */ if (WsCheckCatalogState(Process->NamespaceCatalogEvent)) { /* Modification happened, reload them */ WsNcRefreshFromRegistry(Process->NamespaceCatalog, Process->NamespaceCatalogEvent); }
/* Return it */ return Process->NamespaceCatalog;}
BOOLWSAAPIWsProcDetachSocket(IN PWSPROCESS Process, IN PWAH_HANDLE Handle){ PWSSOCKET Socket = (PWSSOCKET)Handle;
/* Disassociate this socket from the table */ WahRemoveHandleContext(WsSockHandleTable, Handle);
/* If this is isn't an IFS socket */ if (!Socket->Provider) { /* Check if we have an active handle helper */ if (Process->HandleHelper) { /* Close it */ WahCloseSocketHandle(Process->HandleHelper, (SOCKET)Socket->Handle); } }
/* Remove a reference and return */ WsSockDereference(Socket); return TRUE;}
BOOLWSAAPICleanupNamespaceProviders(IN PVOID Callback, IN PNSCATALOG_ENTRY Entry){ PNS_PROVIDER Provider;
/* Get the provider */ Provider = Entry->Provider; if (Provider) { /* Do cleanup */ WsNpNSPCleanup(Provider); }
/* Return success */ return TRUE;}
BOOLWSAAPICleanupProtocolProviders(IN PVOID Callback, IN PTCATALOG_ENTRY Entry){ PTPROVIDER Provider; INT ErrorCode;
/* Get the provider */ Provider = Entry->Provider; if (Provider) { /* Do cleanup */ WsTpWSPCleanup(Provider, &ErrorCode); }
/* Return success */ return TRUE;}
VOIDWSAAPIWsProcDelete(IN PWSPROCESS Process){ /* Check if we didn't even initialize yet */ if (!Process->LockReady) return;
/* No more current process */ CurrentWsProcess = NULL;
/* If we have a socket table */ if (WsSockHandleTable) { /* Enumerate the sockets with a delete callback */ WahEnumerateHandleContexts(WsSockHandleTable, WsSockDeleteSockets, Process); }
/* Close APC Helper */ if (Process->ApcHelper) WahCloseApcHelper(Process->ApcHelper);
/* Close handle helper */ if (Process->HandleHelper) WahCloseHandleHelper(Process->HandleHelper);
/* Check for notification helper */ if (Process->NotificationHelper) { /* Close notification helper */ WahCloseNotificationHandleHelper(Process->NotificationHelper); }
/* Check if we have a protocol catalog*/ if (Process->ProtocolCatalog) { /* Enumerate it to clean it up */ WsTcEnumerateCatalogItems(Process->ProtocolCatalog, CleanupProtocolProviders, NULL);
/* Delete it */ WsTcDelete(Process->ProtocolCatalog); Process->ProtocolCatalog = NULL; }
/* Check if we have a namespace catalog*/ if (Process->NamespaceCatalog) { /* Enumerate it to clean it up */ WsNcEnumerateCatalogItems(Process->NamespaceCatalog, CleanupNamespaceProviders, NULL);
/* Delete it */ WsNcDelete(Process->NamespaceCatalog); Process->NamespaceCatalog = NULL; }
/* Delete the thread lock */ DeleteCriticalSection(&Process->ThreadLock);
/* Delete us */ HeapFree(WsSockHeap, 0, Process);}
VOIDWSAAPIWsProcSetVersion(IN PWSPROCESS Process, IN WORD VersionRequested){ WORD Major, Minor; WORD OldMajor, OldMinor;
/* Get the version data */ Major = LOBYTE(VersionRequested); Minor = HIBYTE(VersionRequested); OldMajor = LOBYTE(Process->Version); OldMinor = HIBYTE(Process->Version);
/* Check if we're going lower */ if ((Major < OldMajor) || ((Major == OldMajor) && (Minor < OldMinor))) { /* Set the new version */ Process->Version = VersionRequested; }}