Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / base / src / nsAutodialWin.h
blob104136d191f651a88cccfc6acbf200d26627f7d2
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is Mozilla.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2002
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Steve Meredith <smeredith@netscape.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsAutodialWin_h__
39 #define nsAutodialWin_h__
41 #include <windows.h>
42 #include <ras.h>
43 #include <rasdlg.h>
44 #include <raserror.h>
45 #include "nscore.h"
46 #include "nspr.h"
48 #if (WINVER < 0x401)
49 /* AutoDial address properties.
51 typedef struct tagRASAUTODIALENTRYA {
52 DWORD dwSize;
53 DWORD dwFlags;
54 DWORD dwDialingLocation;
55 PRUnichar szEntry[RAS_MaxEntryName + 1];
56 } RASAUTODIALENTRYW, *LPRASAUTODIALENTRYW;
57 typedef RASAUTODIALENTRYW RASAUTODIALENTRY, *LPRASAUTODIALENTRY;
59 #define RASADP_LoginSessionDisable 1
61 #endif // WINVER
63 // Loading the RAS DLL dynamically.
64 typedef DWORD (WINAPI* tRASPHONEBOOKDLG)(LPWSTR,LPWSTR,LPRASPBDLG);
65 typedef DWORD (WINAPI* tRASDIALDLG)(LPWSTR,LPWSTR,LPWSTR,LPRASDIALDLG);
66 typedef DWORD (WINAPI* tRASENUMCONNECTIONS)(LPRASCONN,LPDWORD,LPDWORD);
67 typedef DWORD (WINAPI* tRASENUMENTRIES)(LPWSTR,LPWSTR,LPRASENTRYNAMEW,LPDWORD,LPDWORD);
68 typedef DWORD (WINAPI* tRASSETAUTODIALADDRESS)(LPCWSTR,DWORD,LPRASAUTODIALENTRYW,DWORD,DWORD);
69 typedef DWORD (WINAPI* tRASGETAUTODIALADDRESS)(LPCWSTR,LPDWORD,LPRASAUTODIALENTRYW,LPDWORD,LPDWORD);
70 typedef DWORD (WINAPI* tRASGETAUTODIALENABLE)(DWORD,LPBOOL);
71 typedef DWORD (WINAPI* tRASGETAUTODIALPARAM)(DWORD,LPVOID,LPDWORD);
72 // For Windows NT 4, 2000, and XP, we sometimes want to open the RAS dialup
73 // window ourselves, since those versions aren't very nice about it.
74 // See bug 93002. If the RAS autodial service is running, (Remote Access
75 // Auto Connection Manager, aka RasAuto) we will force it to dial
76 // on network error by adding the target address to the autodial
77 // database. If the service is not running, we will open the RAS dialogs
78 // instead.
80 // The OS can be configured to always dial, or dial when there is no
81 // connection. We implement both by dialing when a network error occurs.
83 // An object of this class checks with the OS when it is constructed and
84 // remembers those settings. If required, it can be resynced with
85 // the OS at anytime with the Init() method. At the time of implementation,
86 // the caller creates an object of this class each time a network error occurs.
87 // In this case, the initialization overhead is not significant, and it will
88 // guaranteed to be in sync with OS.
90 // To use, create an instance and call ShouldDialOnNetworkError() to determine
91 // if you should dial or not. That function only return true for the
92 // target OS's so the caller doesn't have to deal with OS version checking.
95 class nsRASAutodial
97 private:
100 // Some helper functions to query the OS for autodial configuration.
103 // Determine if the autodial service is running on this PC.
104 PRBool IsAutodialServiceRunning();
106 // Get the number of RAS connection entries configured from the OS.
107 int NumRASEntries();
109 // Get the name of the default connection from the OS.
110 nsresult GetDefaultEntryName(PRUnichar* entryName, int bufferSize);
112 // Get the name of the first RAS dial entry from the OS.
113 nsresult GetFirstEntryName(PRUnichar* entryName, int bufferSize);
115 // Check to see if RAS already has a dialup connection going.
116 PRBool IsRASConnected();
118 // Get the autodial behavior from the OS.
119 int QueryAutodialBehavior();
121 // Add the specified address to the autodial directory.
122 PRBool AddAddressToAutodialDirectory(const PRUnichar* hostName);
124 // Get the current TAPI dialing location.
125 int GetCurrentLocation();
127 // See if autodial is enabled for specified location.
128 PRBool IsAutodialServiceEnabled(int location);
131 // Autodial behavior. This comes from the Windows registry, set in the ctor.
132 // Object won't pick up changes to the registry automatically, but can be
133 // refreshed at anytime by calling Init(). So if the user changed the
134 // autodial settings, they wouldn't be noticed unless Init() is called.
135 int mAutodialBehavior;
137 int mAutodialServiceDialingLocation;
139 enum { AUTODIAL_NEVER = 1 }; // Never autodial.
140 enum { AUTODIAL_ALWAYS = 2 }; // Always autodial as set in Internet Options.
141 enum { AUTODIAL_ON_NETWORKERROR = 3 }; // Autodial when a connection error occurs as set in Internet Options.
142 enum { AUTODIAL_USE_SERVICE = 4 }; // Use the RAS autodial service to dial.
144 // Number of RAS connection entries in the phonebook.
145 int mNumRASConnectionEntries;
147 // Default connection entry name.
148 PRUnichar mDefaultEntryName[RAS_MaxEntryName + 1];
150 // Don't try to dial again within a few seconds of when user pressed cancel.
151 static PRIntervalTime mDontRetryUntil;
153 // OS version info.
154 OSVERSIONINFO mOSVerInfo;
156 // DLL instance handles.
157 static HINSTANCE mhRASdlg;
158 static HINSTANCE mhRASapi32;
160 // DLL function pointers.
161 static tRASPHONEBOOKDLG mpRasPhonebookDlg;
162 static tRASENUMCONNECTIONS mpRasEnumConnections;
163 static tRASENUMENTRIES mpRasEnumEntries;
164 static tRASDIALDLG mpRasDialDlg;
165 static tRASSETAUTODIALADDRESS mpRasSetAutodialAddress;
166 static tRASGETAUTODIALADDRESS mpRasGetAutodialAddress;
167 static tRASGETAUTODIALENABLE mpRasGetAutodialEnable;
168 static tRASGETAUTODIALPARAM mpRasGetAutodialParam;
170 PRBool LoadRASapi32DLL();
171 PRBool LoadRASdlgDLL();
174 public:
176 // ctor
177 nsRASAutodial();
179 // dtor
180 virtual ~nsRASAutodial();
182 // Get the autodial info from the OS and init this obj with it. Call it any
183 // time to refresh the object's settings from the OS.
184 nsresult Init();
186 // Dial the default RAS dialup connection.
187 nsresult DialDefault(const PRUnichar* hostName);
189 // Should we try to dial on network error?
190 PRBool ShouldDialOnNetworkError();
193 #endif // !nsAutodialWin_h__