Bug 709562 - Part 1. nsAutoDialWin does not need to load rasapi32/rasdlg dynamically. r=jimm
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 03 Jan 2012 19:08:12 +0900
changeset 83680 6ed882263c14a860b8cd8616e6dbada7f8aaf372
parent 83679 6ffca345df2b4bb45d57b2fbb690c1a09786e67b
child 83681 6c8e6f6a8ac8a374504a8b3f82ccda25f2ab64c3
push id21784
push usermak77@bonardo.net
push dateWed, 04 Jan 2012 12:28:24 +0000
treeherdermozilla-central@0eec6ba6a87a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs709562
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 709562 - Part 1. nsAutoDialWin does not need to load rasapi32/rasdlg dynamically. r=jimm
netwerk/base/src/nsAutodialWin.cpp
netwerk/base/src/nsAutodialWin.h
toolkit/library/Makefile.in
--- a/netwerk/base/src/nsAutodialWin.cpp
+++ b/netwerk/base/src/nsAutodialWin.cpp
@@ -67,29 +67,16 @@ static PRLogModuleInfo* gLog = nsnull;
 
 #define LOGD(args) PR_LOG(gLog, PR_LOG_DEBUG, args)
 #define LOGE(args) PR_LOG(gLog, PR_LOG_ERROR, args)
 
 // Don't try to dial again within a few seconds of when user pressed cancel.
 #define NO_RETRY_PERIOD_SEC 5
 PRIntervalTime nsAutodial::mDontRetryUntil = 0;
 
-
-tRASPHONEBOOKDLG nsAutodial::mpRasPhonebookDlg = nsnull;
-tRASENUMCONNECTIONS nsAutodial::mpRasEnumConnections = nsnull;
-tRASENUMENTRIES nsAutodial::mpRasEnumEntries = nsnull;
-tRASDIALDLG nsAutodial::mpRasDialDlg = nsnull;
-tRASSETAUTODIALADDRESS nsAutodial::mpRasSetAutodialAddress = nsnull;
-tRASGETAUTODIALADDRESS nsAutodial::mpRasGetAutodialAddress = nsnull;
-tRASGETAUTODIALENABLE nsAutodial::mpRasGetAutodialEnable = nsnull;
-tRASGETAUTODIALPARAM nsAutodial::mpRasGetAutodialParam = nsnull;
-
-HINSTANCE nsAutodial::mhRASdlg = nsnull;
-HINSTANCE nsAutodial::mhRASapi32 = nsnull;
-
 // ctor. 
 nsAutodial::nsAutodial()
 :   mAutodialBehavior(AUTODIAL_DEFAULT),
     mNumRASConnectionEntries(0),
     mAutodialServiceDialingLocation(-1)
 {
     mOSVerInfo.dwOSVersionInfoSize = sizeof(mOSVerInfo);
     GetVersionEx(&mOSVerInfo);
@@ -163,23 +150,20 @@ bool nsAutodial::ShouldDialOnNetworkErro
 // The autodial info is set in Control Panel | Internet Options | Connections.
 // The values are stored in the registry. This function gets those values from
 // the registry and determines if we should never dial, always dial, or dial
 // when there is no network found.
 int nsAutodial::QueryAutodialBehavior()
 {
     if (IsAutodialServiceRunning())
     {
-        if (!LoadRASapi32DLL())
-            return AUTODIAL_NEVER;
-
         // Is Autodial service enabled for the current login session?
         DWORD disabled = 0;
         DWORD size = sizeof(DWORD);
-        if ((*mpRasGetAutodialParam)(RASADP_LoginSessionDisable, &disabled, &size) == ERROR_SUCCESS)
+        if (RasGetAutodialParamW(RASADP_LoginSessionDisable, &disabled, &size) == ERROR_SUCCESS)
         {
             if (!disabled)
             {
                 // If current dialing location has autodial on, we'll let the service dial.
                 mAutodialServiceDialingLocation = GetCurrentLocation();
                 if (IsAutodialServiceEnabled(mAutodialServiceDialingLocation))
                 {
                     return AUTODIAL_USE_SERVICE;
@@ -292,31 +276,27 @@ nsresult nsAutodial::DialDefault(const P
     {
         AddAddressToAutodialDirectory(hostName);
         return NS_ERROR_FAILURE;    // don't retry
     }
 
     // Do the dialing ourselves.
     else
     {
-        // Don't need to load the dll before this.
-        if (!LoadRASdlgDLL())
-            return NS_ERROR_NULL_POINTER;
-
         // If a default dial entry is configured, use it.
         if (mDefaultEntryName[0] != '\0') 
         {
             LOGD(("Autodial: Dialing default: %s.",mDefaultEntryName));
 
             RASDIALDLG rasDialDlg;
             memset(&rasDialDlg, 0, sizeof(rasDialDlg));
             rasDialDlg.dwSize = sizeof(rasDialDlg);
 
-            bool dialed = 
-             (*mpRasDialDlg)(nsnull, mDefaultEntryName, nsnull, &rasDialDlg);
+            BOOL dialed = 
+             RasDialDlgW(nsnull, mDefaultEntryName, nsnull, &rasDialDlg);
 
             if (!dialed)
             {
                 if (rasDialDlg.dwError != 0)
                 {
                     LOGE(("Autodial ::RasDialDlg failed: Error: %d.", 
                      rasDialDlg.dwError));
                 }
@@ -336,17 +316,17 @@ nsresult nsAutodial::DialDefault(const P
         else
         {
             LOGD(("Autodial: Prompting for phonebook entry."));
 
             RASPBDLG rasPBDlg;
             memset(&rasPBDlg, 0, sizeof(rasPBDlg));
             rasPBDlg.dwSize = sizeof(rasPBDlg);
  
-            bool dialed = (*mpRasPhonebookDlg)(nsnull, nsnull, &rasPBDlg);
+            BOOL dialed = RasPhonebookDlgW(nsnull, nsnull, &rasPBDlg);
 
             if (!dialed)
             {
                 if (rasPBDlg.dwError != 0)
                 {
                     LOGE(("Autodial: ::RasPhonebookDlg failed: Error = %d.", 
                      rasPBDlg.dwError));
                 }
@@ -371,72 +351,61 @@ nsresult nsAutodial::DialDefault(const P
 // Check to see if RAS is already connected.
 bool nsAutodial::IsRASConnected()
 {
     DWORD connections;
     RASCONN rasConn;
     rasConn.dwSize = sizeof(rasConn);
     DWORD structSize = sizeof(rasConn);
 
-    if (!LoadRASapi32DLL())
-        return false;
-
-    DWORD result = (*mpRasEnumConnections)(&rasConn, &structSize, &connections);
+    DWORD result = RasEnumConnectionsW(&rasConn, &structSize, &connections);
 
     // ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
     if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
     {
         return (connections > 0);
     }
 
     LOGE(("Autodial: ::RasEnumConnections failed: Error = %d", result));
     return false;
 }
 
 // Get the first RAS dial entry name from the phonebook.
 nsresult nsAutodial::GetFirstEntryName(PRUnichar* entryName, int bufferSize)
 {
-    // Need to load the DLL if not loaded yet.
-    if (!LoadRASapi32DLL())
-        return NS_ERROR_NULL_POINTER;
-
     RASENTRYNAMEW rasEntryName;
     rasEntryName.dwSize = sizeof(rasEntryName);
     DWORD cb = sizeof(rasEntryName);
     DWORD cEntries = 0;
 
     DWORD result = 
-     (*mpRasEnumEntries)(nsnull, nsnull, &rasEntryName, &cb, &cEntries);
+     RasEnumEntriesW(nsnull, nsnull, &rasEntryName, &cb, &cEntries);
 
     // ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
     if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
     {
         wcsncpy(entryName, rasEntryName.szEntryName,
                 bufferSize / sizeof(*entryName));
         return NS_OK;
     }
 
     return NS_ERROR_FAILURE;
 }
 
 // Get the number of RAS dial entries in the phonebook.
 int nsAutodial::NumRASEntries()
 {
-    // Need to load the DLL if not loaded yet.
-    if (!LoadRASapi32DLL())
-        return 0;
-
     RASENTRYNAMEW rasEntryName;
     rasEntryName.dwSize = sizeof(rasEntryName);
     DWORD cb = sizeof(rasEntryName);
     DWORD cEntries = 0;
 
 
     DWORD result = 
-     (*mpRasEnumEntries)(nsnull, nsnull, &rasEntryName, &cb, &cEntries);
+     RasEnumEntriesW(nsnull, nsnull, &rasEntryName, &cb, &cEntries);
 
     // ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
     if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
     {
         return (int)cEntries;
     }
 
     return 0;
@@ -465,19 +434,18 @@ nsresult nsAutodial::GetDefaultEntryName
     // For Windows 2K: HKCU/RemoteAccess/InternetProfile.
 
     const PRUnichar* key = nsnull;
     const PRUnichar* val = nsnull;
 
     HKEY hKey = 0;
     LONG result = 0;
 
-    // Windows NT and 2000
-    if ((mOSVerInfo.dwMajorVersion == 4) // Windows NT
-     || ((mOSVerInfo.dwMajorVersion == 5) && (mOSVerInfo.dwMinorVersion == 0))) // Windows 2000
+    // Windows 2000
+    if ((mOSVerInfo.dwMajorVersion == 5) && (mOSVerInfo.dwMinorVersion == 0)) // Windows 2000
     {
         key = L"RemoteAccess";
         val = L"InternetProfile";
 
         result = ::RegOpenKeyExW(
                     HKEY_CURRENT_USER, 
                     key, 
                     0, 
@@ -577,49 +545,45 @@ bool nsAutodial::IsAutodialServiceRunnin
     }
 
     return (status.dwCurrentState == SERVICE_RUNNING);
 }
 
 // Add the specified address to the autodial directory.
 bool nsAutodial::AddAddressToAutodialDirectory(const PRUnichar* hostName)
 {
-    // Need to load the DLL if not loaded yet.
-    if (!LoadRASapi32DLL())
-        return false;
-
     // First see if there is already a db entry for this address. 
     RASAUTODIALENTRYW autodialEntry;
     autodialEntry.dwSize = sizeof(autodialEntry);
     DWORD size = sizeof(autodialEntry);
     DWORD entries = 0;
 
-    DWORD result = (*mpRasGetAutodialAddress)(hostName, 
-                                              nsnull, 
-                                              &autodialEntry, 
-                                              &size, 
-                                              &entries);
+    DWORD result = RasGetAutodialAddressW(hostName, 
+                                          nsnull, 
+                                          &autodialEntry, 
+                                          &size, 
+                                          &entries);
 
     // If there is already at least 1 entry in db for this address, return.
     if (result != ERROR_FILE_NOT_FOUND)
     {
         LOGD(("Autodial: Address %s already in autodial db.", hostName));
         return false;
     }
 
     autodialEntry.dwSize = sizeof(autodialEntry);
     autodialEntry.dwFlags = 0;
     autodialEntry.dwDialingLocation = mAutodialServiceDialingLocation;
     GetDefaultEntryName(autodialEntry.szEntry, sizeof(autodialEntry.szEntry));
 
-    result = (*mpRasSetAutodialAddress)(hostName, 
-                                        0, 
-                                        &autodialEntry, 
-                                        sizeof(autodialEntry), 
-                                        1);
+    result = RasSetAutodialAddressW(hostName, 
+                                    0, 
+                                    &autodialEntry, 
+                                    sizeof(autodialEntry), 
+                                    1);
 
     if (result != ERROR_SUCCESS)
     {
         LOGE(("Autodial ::RasSetAutodialAddress failed result %d.", result));
         return false;
     }
 
     LOGD(("Autodial: Added address %s to RAS autodial db for entry %s.",
@@ -663,99 +627,17 @@ int nsAutodial::GetCurrentLocation()
 }
 
 // Check to see if autodial for the specified location is enabled. 
 bool nsAutodial::IsAutodialServiceEnabled(int location)
 {
     if (location < 0)
         return false;
 
-    if (!LoadRASapi32DLL())
-        return false;
-
     BOOL enabled;
-    if ((*mpRasGetAutodialEnable)(location, &enabled) != ERROR_SUCCESS)
+    if (RasGetAutodialEnableW(location, &enabled) != ERROR_SUCCESS)
     {
         LOGE(("Autodial: Error calling RasGetAutodialEnable()"));
         return false;
     }
 
     return enabled;
 }
-
-
-
-bool nsAutodial::LoadRASapi32DLL()
-{
-    if (!mhRASapi32)
-    {
-        mhRASapi32 = ::LoadLibraryW(L"rasapi32.dll");
-        if ((UINT_PTR)mhRASapi32 > 32)
-        {
-            // RasEnumConnections
-            mpRasEnumConnections = (tRASENUMCONNECTIONS)
-             ::GetProcAddress(mhRASapi32, "RasEnumConnectionsW");
-
-            // RasEnumEntries
-            mpRasEnumEntries = (tRASENUMENTRIES)
-             ::GetProcAddress(mhRASapi32, "RasEnumEntriesW");
-
-            // RasSetAutodialAddress
-            mpRasSetAutodialAddress = (tRASSETAUTODIALADDRESS)
-                ::GetProcAddress(mhRASapi32, "RasSetAutodialAddressW");
-
-            // RasGetAutodialAddress
-            mpRasGetAutodialAddress = (tRASGETAUTODIALADDRESS)
-             ::GetProcAddress(mhRASapi32, "RasGetAutodialAddressW");
-
-            // RasGetAutodialEnable
-            mpRasGetAutodialEnable = (tRASGETAUTODIALENABLE)
-             ::GetProcAddress(mhRASapi32, "RasGetAutodialEnableW");
-
-            // RasGetAutodialParam
-            mpRasGetAutodialParam = (tRASGETAUTODIALPARAM)
-             ::GetProcAddress(mhRASapi32, "RasGetAutodialParamW");
-        }
-
-    }
-
-    if (!mhRASapi32 
-        || !mpRasEnumConnections 
-        || !mpRasEnumEntries 
-        || !mpRasSetAutodialAddress
-        || !mpRasGetAutodialAddress
-        || !mpRasGetAutodialEnable
-        || !mpRasGetAutodialParam)
-    {
-        LOGE(("Autodial: Error loading RASAPI32.DLL."));
-        return false;
-    }
-
-    return true;
-}
-
-bool nsAutodial::LoadRASdlgDLL()
-{
-    if (!mhRASdlg)
-    {
-        mhRASdlg = ::LoadLibraryW(L"rasdlg.dll");
-        if ((UINT_PTR)mhRASdlg > 32)
-        {
-            // RasPhonebookDlg
-            mpRasPhonebookDlg =
-             (tRASPHONEBOOKDLG)::GetProcAddress(mhRASdlg, "RasPhonebookDlgW");
-
-            // RasDialDlg
-            mpRasDialDlg =
-             (tRASDIALDLG)::GetProcAddress(mhRASdlg, "RasDialDlgW");
-
-        }
-    }
-
-    if (!mhRASdlg || !mpRasPhonebookDlg || !mpRasDialDlg)
-    {
-        LOGE(("Autodial: Error loading RASDLG.DLL."));
-        return false;
-    }
-
-    return true;
-}
-
--- a/netwerk/base/src/nsAutodialWin.h
+++ b/netwerk/base/src/nsAutodialWin.h
@@ -40,40 +40,16 @@
 
 #include <windows.h>
 #include <ras.h>
 #include <rasdlg.h>
 #include <raserror.h>
 #include "nscore.h"
 #include "nspr.h"
 
-#if (WINVER < 0x401)
-/* AutoDial address properties.
-*/
-typedef struct tagRASAUTODIALENTRYA {
-    DWORD dwSize;
-    DWORD dwFlags;
-    DWORD dwDialingLocation;
-    PRUnichar szEntry[RAS_MaxEntryName + 1];
-} RASAUTODIALENTRYW, *LPRASAUTODIALENTRYW;
-typedef RASAUTODIALENTRYW RASAUTODIALENTRY, *LPRASAUTODIALENTRY;
-
-#define RASADP_LoginSessionDisable              1
-
-#endif  // WINVER
-
-// Loading the RAS DLL dynamically. 
-typedef DWORD (WINAPI* tRASPHONEBOOKDLG)(LPWSTR,LPWSTR,LPRASPBDLG);
-typedef DWORD (WINAPI* tRASDIALDLG)(LPWSTR,LPWSTR,LPWSTR,LPRASDIALDLG);
-typedef DWORD (WINAPI* tRASENUMCONNECTIONS)(LPRASCONN,LPDWORD,LPDWORD);
-typedef DWORD (WINAPI* tRASENUMENTRIES)(LPWSTR,LPWSTR,LPRASENTRYNAMEW,LPDWORD,LPDWORD);
-typedef DWORD (WINAPI* tRASSETAUTODIALADDRESS)(LPCWSTR,DWORD,LPRASAUTODIALENTRYW,DWORD,DWORD);
-typedef DWORD (WINAPI* tRASGETAUTODIALADDRESS)(LPCWSTR,LPDWORD,LPRASAUTODIALENTRYW,LPDWORD,LPDWORD);
-typedef DWORD (WINAPI* tRASGETAUTODIALENABLE)(DWORD,LPBOOL);
-typedef DWORD (WINAPI* tRASGETAUTODIALPARAM)(DWORD,LPVOID,LPDWORD);
 // For Windows NT 4, 2000, and XP, we sometimes want to open the RAS dialup 
 // window ourselves, since those versions aren't very nice about it. 
 // See bug 93002. If the RAS autodial service is running, (Remote Access 
 // Auto Connection Manager, aka RasAuto) we will force it to dial
 // on network error by adding the target address to the autodial
 // database. If the service is not running, we will open the RAS dialogs
 // instead.
 //
@@ -148,34 +124,16 @@ private:
     PRUnichar mDefaultEntryName[RAS_MaxEntryName + 1];  
 
     // Don't try to dial again within a few seconds of when user pressed cancel.
     static PRIntervalTime mDontRetryUntil;
 
     // OS version info.
     OSVERSIONINFO mOSVerInfo;
 
-    // DLL instance handles.
-    static HINSTANCE mhRASdlg;
-    static HINSTANCE mhRASapi32;
-
-    // DLL function pointers.
-    static tRASPHONEBOOKDLG mpRasPhonebookDlg;
-    static tRASENUMCONNECTIONS	mpRasEnumConnections;
-    static tRASENUMENTRIES mpRasEnumEntries;
-    static tRASDIALDLG mpRasDialDlg;
-    static tRASSETAUTODIALADDRESS mpRasSetAutodialAddress;
-    static tRASGETAUTODIALADDRESS mpRasGetAutodialAddress;
-    static tRASGETAUTODIALENABLE mpRasGetAutodialEnable;
-    static tRASGETAUTODIALPARAM mpRasGetAutodialParam;
-
-    bool LoadRASapi32DLL();
-    bool LoadRASdlgDLL();
-
-
 public:
   
     // ctor
     nsAutodial();
 
     // dtor
     virtual ~nsAutodial();
 
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -543,17 +543,17 @@ ifeq ($(OS_ARCH),SunOS)
 ifdef GNU_CC
 EXTRA_DSO_LDOPTS += -lelf
 else
 EXTRA_DSO_LDOPTS += -lelf -ldemangle
 endif
 endif
 
 ifeq ($(OS_ARCH),WINNT)
-OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 uuid version winspool comdlg32 imm32 winmm wsock32 msimg32 shlwapi psapi ws2_32 dbghelp)
+OS_LIBS += $(call EXPAND_LIBNAME,shell32 ole32 uuid version winspool comdlg32 imm32 winmm wsock32 msimg32 shlwapi psapi ws2_32 dbghelp rasapi32 rasdlg)
 ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC))
 OS_LIBS += $(call EXPAND_LIBNAME,imagehlp)
 endif
 ifdef MOZ_CRASHREPORTER
 OS_LIBS += $(call EXPAND_LIBNAME,wininet)
 endif
 endif # WINNT