Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef nsAutodialWin_h__ |
michael@0 | 6 | #define nsAutodialWin_h__ |
michael@0 | 7 | |
michael@0 | 8 | #include <windows.h> |
michael@0 | 9 | #include <ras.h> |
michael@0 | 10 | #include <rasdlg.h> |
michael@0 | 11 | #include <raserror.h> |
michael@0 | 12 | #include "nscore.h" |
michael@0 | 13 | #include "nspr.h" |
michael@0 | 14 | |
michael@0 | 15 | // For Windows NT 4, 2000, and XP, we sometimes want to open the RAS dialup |
michael@0 | 16 | // window ourselves, since those versions aren't very nice about it. |
michael@0 | 17 | // See bug 93002. If the RAS autodial service is running, (Remote Access |
michael@0 | 18 | // Auto Connection Manager, aka RasAuto) we will force it to dial |
michael@0 | 19 | // on network error by adding the target address to the autodial |
michael@0 | 20 | // database. If the service is not running, we will open the RAS dialogs |
michael@0 | 21 | // instead. |
michael@0 | 22 | // |
michael@0 | 23 | // The OS can be configured to always dial, or dial when there is no |
michael@0 | 24 | // connection. We implement both by dialing when a network error occurs. |
michael@0 | 25 | // |
michael@0 | 26 | // An object of this class checks with the OS when it is constructed and |
michael@0 | 27 | // remembers those settings. If required, it can be resynced with |
michael@0 | 28 | // the OS at anytime with the Init() method. At the time of implementation, |
michael@0 | 29 | // the caller creates an object of this class each time a network error occurs. |
michael@0 | 30 | // In this case, the initialization overhead is not significant, and it will |
michael@0 | 31 | // guaranteed to be in sync with OS. |
michael@0 | 32 | // |
michael@0 | 33 | // To use, create an instance and call ShouldDialOnNetworkError() to determine |
michael@0 | 34 | // if you should dial or not. That function only return true for the |
michael@0 | 35 | // target OS's so the caller doesn't have to deal with OS version checking. |
michael@0 | 36 | // |
michael@0 | 37 | |
michael@0 | 38 | class nsAutodial |
michael@0 | 39 | { |
michael@0 | 40 | private: |
michael@0 | 41 | |
michael@0 | 42 | // |
michael@0 | 43 | // Some helper functions to query the OS for autodial configuration. |
michael@0 | 44 | // |
michael@0 | 45 | |
michael@0 | 46 | // Determine if the autodial service is running on this PC. |
michael@0 | 47 | bool IsAutodialServiceRunning(); |
michael@0 | 48 | |
michael@0 | 49 | // Get the number of RAS connection entries configured from the OS. |
michael@0 | 50 | int NumRASEntries(); |
michael@0 | 51 | |
michael@0 | 52 | // Get the name of the default connection from the OS. |
michael@0 | 53 | nsresult GetDefaultEntryName(wchar_t* entryName, int bufferSize); |
michael@0 | 54 | |
michael@0 | 55 | // Get the name of the first RAS dial entry from the OS. |
michael@0 | 56 | nsresult GetFirstEntryName(wchar_t* entryName, int bufferSize); |
michael@0 | 57 | |
michael@0 | 58 | // Check to see if RAS already has a dialup connection going. |
michael@0 | 59 | bool IsRASConnected(); |
michael@0 | 60 | |
michael@0 | 61 | // Get the autodial behavior from the OS. |
michael@0 | 62 | int QueryAutodialBehavior(); |
michael@0 | 63 | |
michael@0 | 64 | // Add the specified address to the autodial directory. |
michael@0 | 65 | bool AddAddressToAutodialDirectory(char16ptr_t hostName); |
michael@0 | 66 | |
michael@0 | 67 | // Get the current TAPI dialing location. |
michael@0 | 68 | int GetCurrentLocation(); |
michael@0 | 69 | |
michael@0 | 70 | // See if autodial is enabled for specified location. |
michael@0 | 71 | bool IsAutodialServiceEnabled(int location); |
michael@0 | 72 | |
michael@0 | 73 | // |
michael@0 | 74 | // Autodial behavior. This comes from the Windows registry, set in the ctor. |
michael@0 | 75 | // Object won't pick up changes to the registry automatically, but can be |
michael@0 | 76 | // refreshed at anytime by calling Init(). So if the user changed the |
michael@0 | 77 | // autodial settings, they wouldn't be noticed unless Init() is called. |
michael@0 | 78 | int mAutodialBehavior; |
michael@0 | 79 | |
michael@0 | 80 | int mAutodialServiceDialingLocation; |
michael@0 | 81 | |
michael@0 | 82 | enum { AUTODIAL_NEVER = 1 }; // Never autodial. |
michael@0 | 83 | enum { AUTODIAL_ALWAYS = 2 }; // Always autodial as set in Internet Options. |
michael@0 | 84 | enum { AUTODIAL_ON_NETWORKERROR = 3 }; // Autodial when a connection error occurs as set in Internet Options. |
michael@0 | 85 | enum { AUTODIAL_USE_SERVICE = 4 }; // Use the RAS autodial service to dial. |
michael@0 | 86 | |
michael@0 | 87 | // Number of RAS connection entries in the phonebook. |
michael@0 | 88 | int mNumRASConnectionEntries; |
michael@0 | 89 | |
michael@0 | 90 | // Default connection entry name. |
michael@0 | 91 | wchar_t mDefaultEntryName[RAS_MaxEntryName + 1]; |
michael@0 | 92 | |
michael@0 | 93 | // Don't try to dial again within a few seconds of when user pressed cancel. |
michael@0 | 94 | static PRIntervalTime mDontRetryUntil; |
michael@0 | 95 | |
michael@0 | 96 | public: |
michael@0 | 97 | |
michael@0 | 98 | // ctor |
michael@0 | 99 | nsAutodial(); |
michael@0 | 100 | |
michael@0 | 101 | // dtor |
michael@0 | 102 | virtual ~nsAutodial(); |
michael@0 | 103 | |
michael@0 | 104 | // Get the autodial info from the OS and init this obj with it. Call it any |
michael@0 | 105 | // time to refresh the object's settings from the OS. |
michael@0 | 106 | nsresult Init(); |
michael@0 | 107 | |
michael@0 | 108 | // Dial the default RAS dialup connection. |
michael@0 | 109 | nsresult DialDefault(const char16_t* hostName); |
michael@0 | 110 | |
michael@0 | 111 | // Should we try to dial on network error? |
michael@0 | 112 | bool ShouldDialOnNetworkError(); |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | #endif // !nsAutodialWin_h__ |
michael@0 | 116 |