Back to index

lightning-sunbird  0.9+nobinonly
nsAutodialWin.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2002
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Steve Meredith <smeredith@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsAutodialWin_h__
00039 #define nsAutodialWin_h__
00040 
00041 #include <windows.h>
00042 #include <ras.h>
00043 #include <rasdlg.h>
00044 #include <raserror.h>
00045 #include "nscore.h"
00046 #include "nspr.h"
00047 
00048 #if (WINVER < 0x401)
00049 /* AutoDial address properties.
00050 */
00051 typedef struct tagRASAUTODIALENTRYA {
00052     DWORD dwSize;
00053     DWORD dwFlags;
00054     DWORD dwDialingLocation;
00055     CHAR szEntry[RAS_MaxEntryName + 1];
00056 } RASAUTODIALENTRYA, *LPRASAUTODIALENTRYA;
00057 typedef RASAUTODIALENTRYA RASAUTODIALENTRY, *LPRASAUTODIALENTRY;
00058 
00059 #define RASADP_LoginSessionDisable              1
00060 
00061 #endif  // WINVER
00062 
00063 // Loading the RAS DLL dynamically. 
00064 typedef DWORD (WINAPI* tRASPHONEBOOKDLG)(LPTSTR,LPTSTR,LPRASPBDLG);
00065 typedef DWORD (WINAPI* tRASDIALDLG)(LPTSTR,LPTSTR,LPTSTR,LPRASDIALDLG);
00066 typedef DWORD (WINAPI* tRASENUMCONNECTIONS)(LPRASCONN,LPDWORD,LPDWORD);
00067 typedef DWORD (WINAPI* tRASENUMENTRIES)(LPTSTR,LPTSTR,LPRASENTRYNAME,LPDWORD,LPDWORD);
00068 typedef DWORD (WINAPI* tRASSETAUTODIALADDRESS)(LPCTSTR,DWORD,LPRASAUTODIALENTRY,DWORD,DWORD);
00069 typedef DWORD (WINAPI* tRASGETAUTODIALADDRESS)(LPCTSTR,LPDWORD,LPRASAUTODIALENTRY,LPDWORD,LPDWORD);
00070 typedef DWORD (WINAPI* tRASGETAUTODIALENABLE)(DWORD,LPBOOL);
00071 typedef DWORD (WINAPI* tRASGETAUTODIALPARAM)(DWORD,LPVOID,LPDWORD);
00072 // For Windows NT 4, 2000, and XP, we sometimes want to open the RAS dialup 
00073 // window ourselves, since those versions aren't very nice about it. 
00074 // See bug 93002. If the RAS autodial service is running, (Remote Access 
00075 // Auto Connection Manager, aka RasAuto) we will force it to dial
00076 // on network error by adding the target address to the autodial
00077 // database. If the service is not running, we will open the RAS dialogs
00078 // instead.
00079 //
00080 // The OS can be configured to always dial, or dial when there is no 
00081 // connection. We implement both by dialing when a network error occurs.
00082 //
00083 // An object of this class checks with the OS when it is constructed and 
00084 // remembers those settings. If required, it can be resynced with
00085 // the OS at anytime with the Init() method. At the time of implementation,
00086 // the caller creates an object of this class each time a network error occurs. 
00087 // In this case, the initialization overhead is not significant, and it will
00088 // guaranteed to be in sync with OS.
00089 //
00090 // To use, create an instance and call ShouldDialOnNetworkError() to determine 
00091 // if you should dial or not. That function only return true for the
00092 // target OS's so the caller doesn't have to deal with OS version checking.
00093 //
00094 
00095 class nsRASAutodial
00096 {
00097 private:
00098 
00099     //
00100     // Some helper functions to query the OS for autodial configuration.
00101     //
00102 
00103     // Determine if the autodial service is running on this PC.
00104     PRBool IsAutodialServiceRunning();
00105 
00106     // Get the number of RAS connection entries configured from the OS.
00107     int NumRASEntries();
00108 
00109     // Get the name of the default connection from the OS.
00110     nsresult GetDefaultEntryName(char* entryName, int bufferSize);
00111 
00112     // Get the name of the first RAS dial entry from the OS.
00113     nsresult GetFirstEntryName(char* entryName, int bufferSize);
00114 
00115     // Check to see if RAS already has a dialup connection going.
00116     PRBool IsRASConnected();
00117 
00118     // Get the autodial behavior from the OS.
00119     int QueryAutodialBehavior();
00120 
00121     // Add the specified address to the autodial directory.
00122     PRBool AddAddressToAutodialDirectory(const char* hostName);
00123 
00124     // Get the  current TAPI dialing location.
00125     int GetCurrentLocation();
00126 
00127     // See if autodial is enabled for specified location.
00128     PRBool IsAutodialServiceEnabled(int location);
00129 
00130     //
00131     // Autodial behavior. This comes from the Windows registry, set in the ctor. 
00132     // Object won't pick up changes to the registry automatically, but can be 
00133     // refreshed at anytime by calling Init(). So if the user changed the 
00134     // autodial settings, they wouldn't be noticed unless Init() is called.
00135     int mAutodialBehavior;
00136 
00137     int mAutodialServiceDialingLocation;
00138 
00139     enum { AUTODIAL_NEVER = 1 };            // Never autodial.
00140     enum { AUTODIAL_ALWAYS = 2 };           // Always autodial as set in Internet Options.
00141     enum { AUTODIAL_ON_NETWORKERROR = 3 };  // Autodial when a connection error occurs as set in Internet Options.
00142     enum { AUTODIAL_USE_SERVICE = 4 };      // Use the RAS autodial service to dial.
00143 
00144     // Number of RAS connection entries in the phonebook. 
00145     int mNumRASConnectionEntries;
00146 
00147     // Default connection entry name.
00148     char mDefaultEntryName[RAS_MaxEntryName + 1];  
00149 
00150     // Don't try to dial again within a few seconds of when user pressed cancel.
00151     static PRIntervalTime mDontRetryUntil;
00152 
00153     // OS version info.
00154     OSVERSIONINFO mOSVerInfo;
00155 
00156     // DLL instance handles.
00157     static HINSTANCE mhRASdlg;
00158     static HINSTANCE mhRASapi32;
00159 
00160     // DLL function pointers.
00161     static tRASPHONEBOOKDLG mpRasPhonebookDlg;
00162     static tRASENUMCONNECTIONS     mpRasEnumConnections;
00163     static tRASENUMENTRIES mpRasEnumEntries;
00164     static tRASDIALDLG mpRasDialDlg;
00165     static tRASSETAUTODIALADDRESS mpRasSetAutodialAddress;
00166     static tRASGETAUTODIALADDRESS mpRasGetAutodialAddress;
00167     static tRASGETAUTODIALENABLE mpRasGetAutodialEnable;
00168     static tRASGETAUTODIALPARAM mpRasGetAutodialParam;
00169 
00170     PRBool LoadRASapi32DLL();
00171     PRBool LoadRASdlgDLL();
00172 
00173 
00174 public:
00175   
00176     // ctor
00177     nsRASAutodial();
00178 
00179     // dtor
00180     virtual ~nsRASAutodial();
00181 
00182     // Get the autodial info from the OS and init this obj with it. Call it any
00183     // time to refresh the object's settings from the OS.
00184     nsresult Init();
00185 
00186     // Dial the default RAS dialup connection.
00187     nsresult DialDefault(const char* hostName);
00188 
00189     // Should we try to dial on network error?
00190     PRBool ShouldDialOnNetworkError();
00191 };
00192 
00193 #endif // !nsAutodialWin_h__
00194