Class OsxProxySearchStrategy
java.lang.Object
com.github.markusbernhardt.proxy.search.desktop.osx.OsxProxySearchStrategy
- All Implemented Interfaces:
ProxySearchStrategy
Loads the OSX system proxy settings from the settings file.
All settings are stored in OSX in a special XML file format. These settings file are named plist files and contain nested dictionaries, arrays and values.
To parse this file we use a parser that is derived from a plist parser that comes with the xmlwise XML parser package:
http://code.google.com/p/xmlwise/
I modified that parser to work with the default Java XML parsing library.
The plist file is located on OSX at:
/Library/Preferences/SystemConfiguration/preferences.plist
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ProxySelector
autodetectProxyIfAvailable
(PListParser.Dict proxySettings, ProxySelector result) Invoke WPAD proxy detection if configured.private ProxySelector
buildSelector
(PListParser.Dict proxySettings) Build a selector from the given settings.getName()
Gets the printable name of the search strategy.Create a list of Ethernet interfaces that are connectedLoads the proxy settings and initializes a proxy selector for the OSX proxy settings.private File
Gets the settings file to parse the settings from.private ProxySelector
installExceptionList
(PListParser.Dict proxySettings, ProxySelector result) Install a host name base filter to handle the proxy exclude list.private ProxySelector
installPacProxyIfAvailable
(PListParser.Dict proxySettings, ProxySelector result) Use a PAC based proxy selector if configured.private void
installSelectorForProtocol
(PListParser.Dict proxySettings, ProtocolDispatchSelector ps, String protocol) Installs a proxy selector for the given protocoll on the ProtocolDispatchSelectorprivate ProxySelector
installSimpleHostFilter
(PListParser.Dict proxySettings, ProxySelector result) Install a filter to ignore simple host names without domain name.private void
installSocksProxy
(PListParser.Dict proxySettings, ProtocolDispatchSelector ps) Build a socks proxy and set it for the socks protocol.private boolean
Checks if the given value is set to "on".private boolean
Check if a given network interface is interesting for us.private String
toCommaSeparatedString
(List<?> proxyExceptions) Convert a list to a comma separated list.
-
Field Details
-
OVERRIDE_SETTINGS_FILE
- See Also:
-
OVERRIDE_ACCEPTED_DEVICES
- See Also:
-
SETTINGS_FILE
- See Also:
-
-
Constructor Details
-
OsxProxySearchStrategy
public OsxProxySearchStrategy()ProxySelector- See Also:
-
-
Method Details
-
getProxySelector
Loads the proxy settings and initializes a proxy selector for the OSX proxy settings.- Specified by:
getProxySelector
in interfaceProxySearchStrategy
- Returns:
- a configured ProxySelector, null if none is found.
- Throws:
ProxyException
- on file reading error.
-
getName
Gets the printable name of the search strategy.- Specified by:
getName
in interfaceProxySearchStrategy
- Returns:
- the printable name of the search strategy
-
buildSelector
Build a selector from the given settings.- Parameters:
proxySettings
- to parse- Returns:
- the configured selector
- Throws:
ProxyException
- on error
-
getNetworkInterfaces
Create a list of Ethernet interfaces that are connected- Returns:
- a list of available interface names
- Throws:
SocketException
-
isInterfaceAllowed
Check if a given network interface is interesting for us.- Parameters:
ni
- the interface to check- Returns:
- true if accepted else false.
- Throws:
SocketException
- on error.
-
getSettingsFile
Gets the settings file to parse the settings from.- Returns:
- the settings file.
-
installSimpleHostFilter
Install a filter to ignore simple host names without domain name.- Parameters:
proxySettings
- the dictionary containing all settingsresult
- the proxy selector that needs to be adapted.- Returns:
- a wrapped proxy selector that will ignore simple names.
-
installExceptionList
Install a host name base filter to handle the proxy exclude list.- Parameters:
proxySettings
- the dictionary containing all settingsresult
- the proxy selector that needs to be adapted.- Returns:
- a wrapped proxy selector that will handle the exclude list.
-
toCommaSeparatedString
Convert a list to a comma separated list.- Parameters:
proxyExceptions
- list of elements.- Returns:
- a comma separated string of the list's content.
-
autodetectProxyIfAvailable
private ProxySelector autodetectProxyIfAvailable(PListParser.Dict proxySettings, ProxySelector result) throws ProxyException Invoke WPAD proxy detection if configured.- Parameters:
proxySettings
- the settings to analyse.result
- the current proxy selector.- Returns:
- a WPAD proxy selector or the passed in proxy selector.
- Throws:
ProxyException
- on automatic detection errors.
-
installPacProxyIfAvailable
private ProxySelector installPacProxyIfAvailable(PListParser.Dict proxySettings, ProxySelector result) Use a PAC based proxy selector if configured.- Parameters:
proxySettings
- the settings to analyse.result
- the current proxy selector.- Returns:
- a PAC proxy selector or the passed in proxy selector.
-
installSocksProxy
Build a socks proxy and set it for the socks protocol.- Parameters:
proxySettings
- to read the config values from.ps
- the ProtocolDispatchSelector to install the new proxy on.
-
installSelectorForProtocol
private void installSelectorForProtocol(PListParser.Dict proxySettings, ProtocolDispatchSelector ps, String protocol) Installs a proxy selector for the given protocoll on the ProtocolDispatchSelector- Parameters:
proxySettings
- to read the config for the procotol from.ps
- the ProtocolDispatchSelector to install the new selector on.protocol
- to use.
-
isActive
Checks if the given value is set to "on".- Parameters:
value
- the value to test.- Returns:
- true if it is set else false.
-