ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dprocess.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS WinSock 2 API
00004  * FILE:        dprocess.c
00005  * PURPOSE:     Process Object
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 #include "ws2_32.h"
00011 
00012 /* DATA **********************************************************************/
00013 PWSPROCESS CurrentWsProcess;
00014 
00015 #define WsProcLock()      EnterCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
00016 #define WsProcUnlock()    LeaveCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
00017 
00018 /* FUNCTIONS *****************************************************************/
00019 
00020 INT
00021 WSAAPI
00022 WsProcInitialize(IN PWSPROCESS Process)
00023 {
00024     INT ErrorCode = WSAEFAULT;
00025     HKEY RootKey = NULL;
00026 
00027     /* Initialize the thread list lock */
00028     InitializeCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
00029     Process->LockReady = TRUE;
00030 
00031     /* Open the Winsock Key */
00032     RootKey = WsOpenRegistryRoot();
00033 
00034     /* Create the LP Catalog change event and catalog */
00035     Process->ProtocolCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
00036     Process->ProtocolCatalog = WsTcAllocate();
00037 
00038     /* Initialize it */
00039     WsTcInitializeFromRegistry(Process->ProtocolCatalog,
00040                                RootKey,
00041                                Process->ProtocolCatalogEvent);
00042 
00043     /* Create the NS Catalog change event and catalog */
00044     Process->NamespaceCatalogEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
00045     Process->NamespaceCatalog = WsNcAllocate();
00046 
00047     /* Initialize it */
00048     ErrorCode = WsNcInitializeFromRegistry(Process->NamespaceCatalog,
00049                                            RootKey,
00050                                            Process->NamespaceCatalogEvent);
00051 
00052     /* Close the root key */
00053     RegCloseKey(RootKey);
00054     return ErrorCode;
00055 }
00056 
00057 PWSPROCESS
00058 WSAAPI
00059 WsProcAllocate(VOID)
00060 {
00061     PWSPROCESS Process;
00062 
00063     /* Allocate the structure */
00064     Process = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Process));
00065 
00066     /* Set default non-zero values */
00067     Process->Version = MAKEWORD(2,2);
00068 
00069     /* Return it */
00070     return Process;
00071 }
00072 
00073 INT
00074 WSAAPI
00075 WsProcOpenAsyncHelperDevice(IN PWSPROCESS Process,
00076                             OUT PHANDLE Handle)
00077 {
00078     INT ErrorCode = WSASYSCALLFAILURE;
00079 
00080     /* Lock the process */
00081     WsProcLock();
00082 
00083     /* Check if we have a handle, and if not, create one */
00084     if ((Process->ApcHelper) ||
00085         (WahOpenApcHelper(&Process->ApcHelper) == ERROR_SUCCESS))
00086     {
00087         /* Return the handle */
00088         *Handle = Process->ApcHelper;
00089         ErrorCode = ERROR_SUCCESS;
00090     }
00091 
00092     /* Unload the process and return */
00093     WsProcUnlock();
00094     return ErrorCode;
00095 }
00096 
00097 INT
00098 WSAAPI
00099 WsProcGetAsyncHelper(IN PWSPROCESS Process,
00100                      OUT PHANDLE Handle)
00101 {
00102     /* Check if we have it already set up */
00103     if (Process->ApcHelper)
00104     {
00105         /* Just return it */
00106         *Handle = Process->ApcHelper;
00107         return ERROR_SUCCESS;
00108     }
00109     else
00110     {
00111         /* Open it for the first time */
00112         return WsProcOpenAsyncHelperDevice(Process, Handle);
00113     }
00114 }
00115 
00116 INT
00117 WSAAPI
00118 WsProcStartup(VOID)
00119 {
00120     INT ErrorCode = WSAEFAULT;
00121 
00122     /* Create a new process */
00123     CurrentWsProcess = WsProcAllocate();
00124 
00125     /* Initialize it */
00126     if (CurrentWsProcess)
00127     {
00128         /* Initialize the process */
00129         ErrorCode = WsProcInitialize(CurrentWsProcess);
00130     }
00131     else
00132     {
00133         /* No memory for the process object */
00134         ErrorCode = WSA_NOT_ENOUGH_MEMORY;
00135     }
00136 
00137     return ErrorCode;
00138 }
00139 
00140 PTCATALOG
00141 WSAAPI
00142 WsProcGetTCatalog(IN PWSPROCESS Process)
00143 {
00144     /* Check if the catalogs have been modified */
00145     if (WsCheckCatalogState(Process->ProtocolCatalogEvent))
00146     {
00147         /* Modification happened, reload them */
00148         WsTcRefreshFromRegistry(Process->ProtocolCatalog,
00149                                 Process->ProtocolCatalogEvent);
00150     }
00151 
00152     /* Return it */
00153     return Process->ProtocolCatalog;
00154 }
00155 
00156 PNSCATALOG
00157 WSAAPI
00158 WsProcGetNsCatalog(IN PWSPROCESS Process)
00159 {
00160     /* Check if the catalogs have been modified */
00161     if (WsCheckCatalogState(Process->NamespaceCatalogEvent))
00162     {
00163         /* Modification happened, reload them */
00164         WsNcRefreshFromRegistry(Process->NamespaceCatalog,
00165                                 Process->NamespaceCatalogEvent);
00166     }
00167 
00168     /* Return it */
00169     return Process->NamespaceCatalog;
00170 }
00171 
00172 BOOL
00173 WSAAPI
00174 WsProcDetachSocket(IN PWSPROCESS Process,
00175                    IN PWAH_HANDLE Handle)
00176 {
00177     PWSSOCKET Socket = (PWSSOCKET)Handle;
00178 
00179     /* Disassociate this socket from the table */
00180     WahRemoveHandleContext(WsSockHandleTable, Handle);
00181 
00182     /* If this is isn't an IFS socket */
00183     if (!Socket->Provider)
00184     {
00185         /* Check if we have an active handle helper */
00186         if (Process->HandleHelper)
00187         {
00188             /* Close it */
00189             WahCloseSocketHandle(Process->HandleHelper, (SOCKET)Socket->Handle);
00190         }
00191     }
00192 
00193     /* Remove a reference and return */
00194     WsSockDereference(Socket);
00195     return TRUE;
00196 }
00197 
00198 BOOL
00199 WSAAPI
00200 CleanupNamespaceProviders(IN PVOID Callback,
00201                           IN PNSCATALOG_ENTRY Entry)
00202 {
00203     PNS_PROVIDER Provider;
00204 
00205     /* Get the provider */
00206     Provider = Entry->Provider;
00207     if (Provider)
00208     {
00209         /* Do cleanup */
00210         WsNpNSPCleanup(Provider);
00211     }
00212 
00213     /* Return success */
00214     return TRUE;
00215 }
00216 
00217 BOOL
00218 WSAAPI
00219 CleanupProtocolProviders(IN PVOID Callback,
00220                          IN PTCATALOG_ENTRY Entry)
00221 {
00222     PTPROVIDER Provider;
00223     INT ErrorCode;
00224 
00225     /* Get the provider */
00226     Provider = Entry->Provider;
00227     if (Provider)
00228     {
00229         /* Do cleanup */
00230         WsTpWSPCleanup(Provider, &ErrorCode);
00231     }
00232 
00233     /* Return success */
00234     return TRUE;
00235 }
00236 
00237 VOID
00238 WSAAPI
00239 WsProcDelete(IN PWSPROCESS Process)
00240 {
00241     /* Check if we didn't even initialize yet */
00242     if (!Process->LockReady) return;
00243 
00244     /* No more current process */
00245     CurrentWsProcess = NULL;
00246 
00247     /* If we have a socket table */
00248     if (WsSockHandleTable)
00249     {
00250         /* Enumerate the sockets with a delete callback */
00251         WahEnumerateHandleContexts(WsSockHandleTable,
00252                                    WsSockDeleteSockets,
00253                                    Process);
00254     }
00255 
00256     /* Close APC Helper */
00257     if (Process->ApcHelper) WahCloseApcHelper(Process->ApcHelper);
00258 
00259     /* Close handle helper */
00260     if (Process->HandleHelper) WahCloseHandleHelper(Process->HandleHelper);
00261 
00262     /* Check for notification helper */
00263     if (Process->NotificationHelper)
00264     {
00265         /* Close notification helper */
00266         WahCloseNotificationHandleHelper(Process->NotificationHelper);
00267     }
00268 
00269     /* Check if we have a protocol catalog*/
00270     if (Process->ProtocolCatalog)
00271     {
00272         /* Enumerate it to clean it up */
00273         WsTcEnumerateCatalogItems(Process->ProtocolCatalog,
00274                                   CleanupProtocolProviders,
00275                                   NULL);
00276 
00277         /* Delete it */
00278         WsTcDelete(Process->ProtocolCatalog);
00279         Process->ProtocolCatalog = NULL;
00280     }
00281 
00282     /* Check if we have a namespace catalog*/
00283     if (Process->NamespaceCatalog)
00284     {
00285         /* Enumerate it to clean it up */
00286         WsNcEnumerateCatalogItems(Process->NamespaceCatalog,
00287                                   CleanupNamespaceProviders,
00288                                   NULL);
00289 
00290         /* Delete it */
00291         WsNcDelete(Process->NamespaceCatalog);
00292         Process->NamespaceCatalog = NULL;
00293     }
00294 
00295     /* Delete the thread lock */
00296     DeleteCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
00297 }
00298 
00299 VOID
00300 WSAAPI
00301 WsProcSetVersion(IN PWSPROCESS Process,
00302                  IN WORD VersionRequested)
00303 {
00304     WORD Major, Minor;
00305     WORD OldMajor, OldMinor;
00306 
00307     /* Get the version data */
00308     Major = LOBYTE(VersionRequested);
00309     Minor = HIBYTE(VersionRequested);
00310     OldMajor = LOBYTE(Process->Version);
00311     OldMinor = HIBYTE(Process->Version);
00312 
00313     /* Check if we're going lower */
00314     if ((Major < OldMajor) || ((Major == OldMajor) && (Minor < OldMinor)))
00315     {
00316         /* Set the new version */
00317         Process->Version = VersionRequested;
00318     }
00319 }

Generated on Sat May 26 2012 04:25:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.