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

rasdial.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:        rasdial.c
00005  * PURPOSE:     RAS Auto-Dial Support
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 #include "ws2_32.h"
00011 
00012 //#define NDEBUG
00013 #include <debug.h>
00014 
00015 /* DATA **********************************************************************/
00016 
00017 typedef BOOL
00018 (WSAAPI *PWS_ATTEMPT_AUTODIAL_ADDR)(
00019     IN CONST SOCKADDR FAR *Name,
00020     IN INT NameLength
00021 );
00022 
00023 typedef BOOL
00024 (WSAAPI *PWS_ATTEMPT_AUTODIAL_NAME)(IN CONST LPWSAQUERYSETW lpqsRestrictions);
00025 
00026 typedef VOID
00027 (WSAAPI *PWS_NOTE_SUCCESSFUL_HOSTENT_LOOKUP)(
00028     IN CONST CHAR FAR *Name,
00029     IN CONST ULONG Address
00030 );
00031 
00032 BOOLEAN WsRasInitialized;
00033 HINSTANCE WsRasDllHandle;
00034 CRITICAL_SECTION WsRasHelperLock;
00035 PWS_ATTEMPT_AUTODIAL_ADDR lpfnWSAttemptAutodialAddr;
00036 PWS_ATTEMPT_AUTODIAL_NAME lpfnWSAttemptAutodialName;
00037 PWS_NOTE_SUCCESSFUL_HOSTENT_LOOKUP lpfnWSNoteSuccessfulHostentLookup;
00038 
00039 #define WsRasLock()          EnterCriticalSection(&WsRasHelperLock);
00040 #define WsRasUnlock()        LeaveCriticalSection(&WsRasHelperLock);
00041 
00042 /* FUNCTIONS *****************************************************************/
00043 
00044 VOID
00045 WSAAPI
00046 WsRasInitializeAutodial(VOID)
00047 {
00048     /* Initialize the autodial lock */
00049     InitializeCriticalSection(&WsRasHelperLock);
00050 }
00051 
00052 VOID
00053 WSAAPI
00054 WsRasUninitializeAutodial(VOID)
00055 {
00056     /* Acquire lock */
00057     WsRasLock();
00058 
00059     /* Free the library if it's loaded */
00060     if (WsRasDllHandle) FreeLibrary(WsRasDllHandle);
00061     WsRasDllHandle = NULL;
00062 
00063     /* Release and delete lock */
00064     WsRasUnlock();
00065     DeleteCriticalSection(&WsRasHelperLock);
00066 }
00067 
00068 INT
00069 WSAAPI
00070 WsRasLoadHelperDll(VOID)
00071 {
00072     CHAR HelperPath[MAX_PATH];
00073     HKEY WinsockKey;
00074     INT ErrorCode;
00075     DWORD RegType = REG_SZ;
00076     DWORD RegSize = MAX_PATH;
00077 
00078     /* Acquire the lock */
00079     WsRasLock();
00080 
00081     /* Check if we were already initialiazed */
00082     if (!WsRasInitialized)
00083     {
00084         /* Open the registry root key */
00085         WinsockKey = WsOpenRegistryRoot();
00086         if (WinsockKey)
00087         {
00088             /* Read the helper's location */
00089             ErrorCode = RegQueryValueEx(WinsockKey,
00090                                         "AutodialDLL",
00091                                         0,
00092                                         &RegType,
00093                                         (LPBYTE)&HelperPath,
00094                                         &RegSize);
00095             RegCloseKey(WinsockKey);
00096 
00097             /* Make sure we read the path */
00098             if (ErrorCode == ERROR_SUCCESS)
00099             {
00100                 /* Now load it */
00101                 WsRasDllHandle = LoadLibrary(HelperPath);
00102             }
00103         }
00104 
00105         /* Check if we weren't able to load it and load the default */
00106         if (!WsRasDllHandle) WsRasDllHandle = LoadLibrary("rasadhlp.dll");
00107 
00108         /* Check again if we loaded it */
00109         if (WsRasDllHandle)
00110         {
00111             /* Get function pointers */
00112             lpfnWSAttemptAutodialAddr = 
00113                 (PVOID)GetProcAddress(WsRasDllHandle,
00114                                       "WSAttemptAutodialAddr");
00115             lpfnWSAttemptAutodialName = 
00116                 (PVOID)GetProcAddress(WsRasDllHandle,
00117                                       "WSAttemptAutodialName");
00118             lpfnWSNoteSuccessfulHostentLookup = 
00119                 (PVOID)GetProcAddress(WsRasDllHandle,
00120                                       "WSNoteSuccessfulHostentLookup");
00121         }
00122 
00123         /* Mark us as loaded */
00124         WsRasInitialized = TRUE;
00125     }
00126 
00127     /* Release lock */
00128     WsRasUnlock();
00129 
00130     /* Return status */
00131     return WsRasInitialized;
00132 }
00133 
00134 BOOL
00135 WSAAPI
00136 WSAttemptAutodialAddr(IN CONST SOCKADDR FAR *Name,
00137                       IN INT NameLength)
00138 {
00139     /* Load the helper DLL and make sure it exports this routine */
00140     if (!(WsRasLoadHelperDll()) || !(lpfnWSAttemptAutodialAddr)) return FALSE;
00141 
00142     /* Call the function in the helper */
00143     return lpfnWSAttemptAutodialAddr(Name, NameLength);
00144 }
00145 
00146 BOOL
00147 WSAAPI
00148 WSAttemptAutodialName(IN CONST LPWSAQUERYSETW lpqsRestrictions)
00149 {
00150     /* Load the helper DLL and make sure it exports this routine */
00151     if (!(WsRasLoadHelperDll()) || !(lpfnWSAttemptAutodialName)) return FALSE;
00152 
00153     /* Call the function in the helper */
00154     return lpfnWSAttemptAutodialName(lpqsRestrictions);
00155 }
00156 
00157 VOID
00158 WSAAPI
00159 WSNoteSuccessfulHostentLookup(IN CONST CHAR FAR *Name,
00160                               IN CONST ULONG Address)
00161 {
00162     /* Load the helper DLL and make sure it exports this routine */
00163     if (!(WsRasLoadHelperDll()) || !(lpfnWSNoteSuccessfulHostentLookup)) return;
00164 
00165     /* Call the function in the helper */
00166     lpfnWSNoteSuccessfulHostentLookup(Name, Address);
00167 }

Generated on Sun May 27 2012 04:27:10 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.