diff options
author | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-02-05 06:52:13 +0000 |
---|---|---|
committer | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-02-05 06:52:13 +0000 |
commit | 25e1080dd5ae9ce82a33828d8acaaa4c61f44145 (patch) | |
tree | 2b46686d96490d0a8753c146183dee4c126d064b /libproxy/modules | |
parent | ee59072c05c9a94556c3470a5a60571b84105781 (diff) | |
download | libproxy-25e1080dd5ae9ce82a33828d8acaaa4c61f44145.tar.gz |
massive rework; split off libmodman; make unit tests for libmodman; remove config_wpad; remove config_file (both intenal and module); remove config ordering support; merge lukas' kde plugin rework
git-svn-id: http://libproxy.googlecode.com/svn/trunk@513 c587cffe-e639-0410-9787-d7902ae8ed56
Diffstat (limited to 'libproxy/modules')
-rw-r--r-- | libproxy/modules/config_envvar.cpp | 14 | ||||
-rw-r--r-- | libproxy/modules/config_file.cpp | 68 | ||||
-rw-r--r-- | libproxy/modules/config_gnome.cpp | 37 | ||||
-rw-r--r-- | libproxy/modules/config_kde4.cpp | 140 | ||||
-rw-r--r-- | libproxy/modules/config_macosx.cpp | 5 | ||||
-rw-r--r-- | libproxy/modules/config_w32reg.cpp | 2 | ||||
-rw-r--r-- | libproxy/modules/config_wpad.cpp | 33 | ||||
-rw-r--r-- | libproxy/modules/ignore_domain.cpp | 8 | ||||
-rw-r--r-- | libproxy/modules/ignore_hostname.cpp | 10 | ||||
-rw-r--r-- | libproxy/modules/ignore_ip.cpp | 8 | ||||
-rw-r--r-- | libproxy/modules/network_networkmanager.cpp | 13 | ||||
-rw-r--r-- | libproxy/modules/pacrunner_mozjs.cpp | 2 | ||||
-rw-r--r-- | libproxy/modules/pacrunner_webkit.cpp | 4 | ||||
-rw-r--r-- | libproxy/modules/wpad_dns_alias.cpp | 14 |
14 files changed, 140 insertions, 218 deletions
diff --git a/libproxy/modules/config_envvar.cpp b/libproxy/modules/config_envvar.cpp index 2ad012f..507587c 100644 --- a/libproxy/modules/config_envvar.cpp +++ b/libproxy/modules/config_envvar.cpp @@ -19,14 +19,11 @@ #include <cstdlib> -#include "../module_config.hpp" +#include "../extension_config.hpp" using namespace com::googlecode::libproxy; -class envvar_config_module : public config_module { +class envvar_config_extension : public config_extension { public: - PX_MODULE_ID(NULL); - PX_MODULE_CONFIG_CATEGORY(config_module::CATEGORY_NONE); - url get_config(url url) throw (runtime_error) { char *proxy = NULL; @@ -58,6 +55,11 @@ public: ignore = ignore ? ignore : getenv("NO_PROXY"); return string(ignore ? ignore : ""); } + + // Make sure that envvar is pushed to the back behind all other config extensions + virtual bool operator<(const base_extension&) const { + return false; + } }; -PX_MODULE_LOAD(config, envvar, true); +MM_MODULE_EZ(envvar_config_extension, true, NULL); diff --git a/libproxy/modules/config_file.cpp b/libproxy/modules/config_file.cpp deleted file mode 100644 index 66296e1..0000000 --- a/libproxy/modules/config_file.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#include "../config_file.hpp" -#include "../module_config.hpp" -using namespace com::googlecode::libproxy; - -class system_file_config_module : public config_module { -public: - PX_MODULE_ID("config_file_system"); - PX_MODULE_CONFIG_CATEGORY(config_module::CATEGORY_SYSTEM); - - system_file_config_module() { - this->cf.load(this->get_filename()); - } - - url get_config(url) throw (runtime_error) { - if (this->cf.is_stale()) - this->cf.load(this->get_filename()); - string tmp = ""; - this->cf.get_value("proxy", tmp); - return tmp; - } - - string get_ignore(url) { - if (this->cf.is_stale()) - this->cf.load(this->get_filename()); - string tmp = ""; - this->cf.get_value("ignore", tmp); - return tmp; - } - -protected: - virtual string get_filename() { return SYSCONFDIR "proxy.conf"; } - -private: - config_file cf; -}; - -class user_file_config_module : public system_file_config_module { -public: - PX_MODULE_ID("config_file_user"); - PX_MODULE_CONFIG_CATEGORY(config_module::CATEGORY_USER); - -protected: - virtual string get_filename() { return string(getenv("HOME")) + string("/.proxy.conf"); } -}; - -extern "C" DLL_PUBLIC bool PX_MODULE_LOAD_NAME(module_manager& mm) { - bool success = mm.register_module<config_module>(new user_file_config_module); - return mm.register_module<config_module>(new system_file_config_module) || success; -} diff --git a/libproxy/modules/config_gnome.cpp b/libproxy/modules/config_gnome.cpp index 27af9bf..7a28302 100644 --- a/libproxy/modules/config_gnome.cpp +++ b/libproxy/modules/config_gnome.cpp @@ -25,7 +25,7 @@ #include <signal.h> // For kill() #include "xhasclient.cpp" // For xhasclient() -#include "../module_config.hpp" +#include "../extension_config.hpp" using namespace com::googlecode::libproxy; static const char *_all_keys[] = { @@ -93,12 +93,9 @@ static int popen2(const char *program, int* read, int* write, pid_t* pid) { } } -class gnome_config_module : public config_module { +class gnome_config_extension : public config_extension { public: - PX_MODULE_ID(NULL); - PX_MODULE_CONFIG_CATEGORY(config_module::CATEGORY_SESSION); - - gnome_config_module() { + gnome_config_extension() { // Build the command int count; string cmd = LIBEXECDIR "pxgconf"; @@ -121,7 +118,7 @@ public: this->update_data(count); } - ~gnome_config_module() { + ~gnome_config_extension() { close(this->read); close(this->write); kill(this->pid, SIGTERM); @@ -252,11 +249,25 @@ private: } }; -// If we are running in GNOME, then make sure this plugin is registered. -extern "C" DLL_PUBLIC bool PX_MODULE_LOAD_NAME(module_manager& mm) { - if (xhasclient("gnome-session", "gnome-settings-daemon", "gnome-panel", NULL)) { - try { return mm.register_module<config_module>(new gnome_config_module); } - catch (runtime_error) {} +// Only attempt to load this module if we are in a gnome session +static bool gnome_config_extension_test() { + return xhasclient("gnome-session", "gnome-settings-daemon", "gnome-panel", NULL); +} + +static base_extension** gnome_config_extension_init() { + base_extension** retval = new base_extension*[2]; + retval[1] = NULL; + try { + retval[0] = new gnome_config_extension(); + return retval; + } + catch (runtime_error) { + delete retval; + return NULL; } - return false; } + +MM_MODULE_DEFINE = { + MM_MODULE_RECORD(gnome_config_extension, gnome_config_extension_init, gnome_config_extension_test, NULL), + MM_MODULE_LAST, +}; diff --git a/libproxy/modules/config_kde4.cpp b/libproxy/modules/config_kde4.cpp index 37ee00e..13f5c50 100644 --- a/libproxy/modules/config_kde4.cpp +++ b/libproxy/modules/config_kde4.cpp @@ -17,86 +17,108 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ******************************************************************************/ -#include <kstandarddirs.h> // For KStandardDirs -#include "xhasclient.cpp" // For xhasclient(...) +#include "kconfig.h" +#include "kconfiggroup.h" +#include "xhasclient.cpp" // For xhasclient(...) -#include "../config_file.hpp" -#include "../module_config.hpp" +#include "../extension_config.hpp" using namespace com::googlecode::libproxy; -class kde_config_module : public config_module { +class kde_config_extension : public config_extension { public: - PX_MODULE_ID(NULL); - PX_MODULE_CONFIG_CATEGORY(config_module::CATEGORY_SESSION); - url get_config(url dst) throw (runtime_error) { - string cfg, ptype; + /* The constructor of KConfig uses qAppName() which asumes a QApplication object to exist. + If not, an error message is written. This error message and all others seems to be disabled for + libraries, but to be sure, we can reemplace temporaly Qt's internal message handler by a + dummy implementation. */ + // QtMsgHandler oldHandler = qInstallMsgHandler(dummyMessageHandler); // supress Qt messages + + string cfg; + int ptype; // Open the config file - if (this->cf.is_stale()) - { - QString localdir = KStandardDirs().localkdedir(); - QByteArray ba = localdir.toLatin1(); - if (!cf.load(string(ba.data()) + "/share/config/kioslaverc")) - throw runtime_error("Unable to load kde config file!"); - } + KConfig kde_cf("kioslaverc", KConfig::NoGlobals); // like in kprotocolmanager.cpp + KConfigGroup kde_settings(&kde_cf, "Proxy Settings"); // accessing respective group // Read the config file to find out what type of proxy to use - if (this->cf.get_value("Proxy Settings", "ProxyType", ptype)) { - - // Use a manual proxy - if (ptype == "1") { - if (!this->cf.get_value("Proxy Settings", dst.get_scheme() + "Proxy", cfg) && - !this->cf.get_value("Proxy Settings", "httpProxy", cfg) && - !this->cf.get_value("Proxy Settings", "socksProxy", cfg)) - cfg = "direct://"; - } - - // Use a manual PAC - else if (ptype == "2") - { - if (this->cf.get_value("Proxy Settings", "Proxy Config Script", cfg) && - url::is_valid("pac+" + cfg)) + ptype = kde_settings.readEntry("ProxyType", 0); + + QByteArray ba; + QString manual_proxy; + switch (ptype) { + case 1: // Use a manual proxy + manual_proxy = kde_settings.readEntry(QString(dst.get_scheme().c_str()) + "Proxy", ""); + if (manual_proxy.isEmpty()) { + manual_proxy = kde_settings.readEntry("httpProxy", ""); + if (manual_proxy.isEmpty()) { + manual_proxy = kde_settings.readEntry("socksProxy", ""); + if (manual_proxy.isEmpty()) { + manual_proxy = "direct://"; + }; + }; + }; + // The result of toLatin1() is undefined for non-Latin1 strings. + // However, KDE saves this entry using IDN and percent-encoding, so no problem... + ba = manual_proxy.toLatin1(); + cfg = string(ba.data()); + break; + case 2: // Use a manual PAC + // The result of toLatin1() is undefined for non-Latin1 strings. + // However, KDE saves this entry using IDN and percent-encoding, so no problem... + ba = kde_settings.readEntry("Proxy Config Script", "").toLatin1(); + cfg = string(ba.data()); + if (url::is_valid("pac+" + cfg)) cfg = "pac+" + cfg; else cfg = "wpad://"; - } - - // Use WPAD - else if (ptype == "3") + break; + case 3: // Use WPAD cfg = "wpad://"; - - // Use envvar - else if (ptype == "4") + break; + case 4: // Use envvar throw runtime_error("User config_envvar"); // We'll bypass this config plugin and let the envvar plugin work - - return com::googlecode::libproxy::url(cfg); - } - - // Don't use any proxy - return com::googlecode::libproxy::url("direct://"); + break; + default: + cfg = "direct://"; + break; + }; + + // qInstallMsgHandler(oldHandler); // restore old behaviour + return com::googlecode::libproxy::url(cfg); } string get_ignore(url /*dst*/) { // TODO: support ReversedException - // Open the config file - if (this->cf.is_stale()) - { - QString localdir = KStandardDirs().localkdedir(); - QByteArray ba = localdir.toLatin1(); - if (!cf.load(string(ba.data()) + "/share/config/kioslaverc")) - return ""; - } + /* The constructor of KConfig uses qAppName() which asumes a QApplication object to exist. + If not, an error message is written. This error message and all others seems to be disabled for + libraries, but to be sure, we can reemplace temporaly Qt's internal message handler by a + dummy implementation. */ + // QtMsgHandler oldHandler = qInstallMsgHandler(dummyMessageHandler); // supress Qt messages - string ign; - if (this->cf.get_value("Proxy Settings", "NoProxyFor", ign)) - return ign; - return ""; + string returnValue; + // Open the config file + KConfig kde_cf("kioslaverc", KConfig::NoGlobals); // like in kprotocolmanager.cpp + KConfigGroup kde_settings(&kde_cf, "Proxy Settings"); // accessing respective group + + if (kde_settings.readEntry("ProxyType", 0) == 1) { // apply ignore list only for manual proxy configuration + QStringList list = kde_settings.readEntry("NoProxyFor", QStringList()); + for (int i = 0; i < list.size(); ++i) { + list[i] = QUrl(list.at(i)).toEncoded(); + }; + returnValue = string(list.join(",").toLatin1().data()); + } else { + returnValue = ""; + }; + + // qInstallMsgHandler(oldHandler); // restore old behaviour + return returnValue; } - +/* private: - config_file cf; + void dummyMessageHandler(QtMsgType, const char *) { + } +*/ }; -PX_MODULE_LOAD(config, kde, xhasclient("kicker", NULL)); +MM_MODULE_EZ(kde_config_extension, xhasclient("kicker", NULL), NULL); diff --git a/libproxy/modules/config_macosx.cpp b/libproxy/modules/config_macosx.cpp index 087f312..4ed3f1e 100644 --- a/libproxy/modules/config_macosx.cpp +++ b/libproxy/modules/config_macosx.cpp @@ -68,7 +68,7 @@ static bool getbool(CFDictionaryRef settings, string key, bool dflt=false) { } static bool protocol_url(CFDictionaryRef settings, string protocol, string& config) { - int64_t port; + int64_t port; string host; // Check ProtocolEnabled @@ -167,5 +167,4 @@ public: } }; -PX_MODULE_LOAD(config, macosx, true); - +PX_MODULE_INFO_EZ(config_module, config_macosx, NULL, macosx_config_module, true); diff --git a/libproxy/modules/config_w32reg.cpp b/libproxy/modules/config_w32reg.cpp index f53367a..189e83c 100644 --- a/libproxy/modules/config_w32reg.cpp +++ b/libproxy/modules/config_w32reg.cpp @@ -165,4 +165,4 @@ public: } }; -PX_MODULE_LOAD(config, w32reg, true); +PX_MODULE_INFO_EZ(config_module, config_w32reg, NULL, w32reg_config_module, true); diff --git a/libproxy/modules/config_wpad.cpp b/libproxy/modules/config_wpad.cpp deleted file mode 100644 index 086b87c..0000000 --- a/libproxy/modules/config_wpad.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#include "../module_config.hpp" -using namespace com::googlecode::libproxy; - -class wpad_config_module : public config_module { -public: - PX_MODULE_ID(NULL); - PX_MODULE_CONFIG_CATEGORY(config_module::CATEGORY_NONE); - - url get_config(url) throw (runtime_error) { - return url("wpad://"); - } -}; - -PX_MODULE_LOAD(config, wpad, true); diff --git a/libproxy/modules/ignore_domain.cpp b/libproxy/modules/ignore_domain.cpp index 9d4445b..410e436 100644 --- a/libproxy/modules/ignore_domain.cpp +++ b/libproxy/modules/ignore_domain.cpp @@ -19,13 +19,11 @@ #include <cstdio> -#include "../module_ignore.hpp" +#include "../extension_ignore.hpp" using namespace com::googlecode::libproxy; -class domain_ignore_module : public ignore_module { +class domain_ignore_extension : public ignore_extension { public: - PX_MODULE_ID(NULL); - virtual bool ignore(url& url, string ignorestr) { /* Get our URL's hostname and port */ string host = url.get_host(); @@ -58,4 +56,4 @@ public: } }; -PX_MODULE_LOAD(ignore, domain, true); +MM_MODULE_EZ(domain_ignore_extension, true, NULL); diff --git a/libproxy/modules/ignore_hostname.cpp b/libproxy/modules/ignore_hostname.cpp index 0aa695a..bb9444c 100644 --- a/libproxy/modules/ignore_hostname.cpp +++ b/libproxy/modules/ignore_hostname.cpp @@ -19,15 +19,13 @@ #include <cstdio> -#include "../module_ignore.hpp" +#include "../extension_ignore.hpp" using namespace com::googlecode::libproxy; -class hostname_ignore_module : public ignore_module { +class hostname_ignore_extension : public ignore_extension { public: - PX_MODULE_ID(NULL); - virtual bool ignore(url& url, string ignorestr) { - if (ignorestr == "<local>" && + if (ignorestr == "<local>" && url.get_host().find(':') == string::npos && // Make sure it's not IPv6 url.get_host().find('.') == string::npos) return true; @@ -35,4 +33,4 @@ public: } }; -PX_MODULE_LOAD(ignore, hostname, true); +MM_MODULE_EZ(hostname_ignore_extension, true, NULL); diff --git a/libproxy/modules/ignore_ip.cpp b/libproxy/modules/ignore_ip.cpp index 4d89edf..de55417 100644 --- a/libproxy/modules/ignore_ip.cpp +++ b/libproxy/modules/ignore_ip.cpp @@ -20,7 +20,7 @@ #include <cstdio> #include <cstring> -#include "../module_ignore.hpp" +#include "../extension_ignore.hpp" using namespace com::googlecode::libproxy; static inline bool @@ -106,10 +106,8 @@ _sockaddr_from_cidr(sa_family_t af, uint8_t cidr) return NULL; } -class ip_ignore_module : public ignore_module { +class ip_ignore_extension : public ignore_extension { public: - PX_MODULE_ID(NULL); - virtual bool ignore(url& url, string ignore) { bool result = false; uint16_t port = 0; @@ -176,4 +174,4 @@ public: } }; -PX_MODULE_LOAD(ignore, ip, true); +MM_MODULE_EZ(ip_ignore_extension, true, NULL); diff --git a/libproxy/modules/network_networkmanager.cpp b/libproxy/modules/network_networkmanager.cpp index 869c735..f696ebb 100644 --- a/libproxy/modules/network_networkmanager.cpp +++ b/libproxy/modules/network_networkmanager.cpp @@ -19,22 +19,19 @@ #include <stdint.h> // For uint32_t -#include "../module_network.hpp" +#include "../extension_network.hpp" using namespace com::googlecode::libproxy; #include <dbus/dbus.h> #include <NetworkManager/NetworkManager.h> - -class networkmanager_network_module : public network_module { +class networkmanager_network_extension : public network_extension { public: - PX_MODULE_ID(NULL); - - networkmanager_network_module() { + networkmanager_network_extension() { this->conn = NULL; } - ~networkmanager_network_module() { + ~networkmanager_network_extension() { if (this->conn) dbus_connection_close(this->conn); } @@ -92,4 +89,4 @@ private: DBusConnection *conn; }; -PX_MODULE_LOAD(network, networkmanager, true); +MM_MODULE_EZ(networkmanager_network_extension, true, NULL); diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp index 59f1a7e..c82608b 100644 --- a/libproxy/modules/pacrunner_mozjs.cpp +++ b/libproxy/modules/pacrunner_mozjs.cpp @@ -160,4 +160,4 @@ private: JSObject *jsglb; }; -PX_DEFINE_PACRUNNER_MODULE(mozjs, true); +PX_PACRUNNER_MODULE_EZ(mozjs, true, "JS_DefineFunction"); diff --git a/libproxy/modules/pacrunner_webkit.cpp b/libproxy/modules/pacrunner_webkit.cpp index 61b3adb..c0a1a54 100644 --- a/libproxy/modules/pacrunner_webkit.cpp +++ b/libproxy/modules/pacrunner_webkit.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ******************************************************************************/ -#include "../module_pacrunner.hpp" +#include "../extension_pacrunner.hpp" using namespace com::googlecode::libproxy; #include <JavaScriptCore/JavaScript.h> @@ -160,4 +160,4 @@ private: JSGlobalContextRef jsctx; }; -PX_DEFINE_PACRUNNER_MODULE(webkit, true); +PX_PACRUNNER_MODULE_EZ(webkit, true, "JSObjectMakeFunctionWithCallback"); diff --git a/libproxy/modules/wpad_dns_alias.cpp b/libproxy/modules/wpad_dns_alias.cpp index c010413..32e1b40 100644 --- a/libproxy/modules/wpad_dns_alias.cpp +++ b/libproxy/modules/wpad_dns_alias.cpp @@ -17,16 +17,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ******************************************************************************/ -#include "../module_wpad.hpp" +#include "../extension_wpad.hpp" using namespace com::googlecode::libproxy; -class dns_alias_wpad_module : public wpad_module { +class dns_alias_wpad_extension : public wpad_extension { public: - PX_MODULE_ID(NULL); - - dns_alias_wpad_module() { rewind(); } - bool found() { return lastpac != NULL; } - void rewind() { lasturl = NULL; lastpac = NULL; } + dns_alias_wpad_extension() { rewind(); } + bool found() { return lastpac != NULL; } + void rewind() { lasturl = NULL; lastpac = NULL; } url* next(char** pac) { if (lasturl) return false; @@ -46,4 +44,4 @@ private: char* lastpac; }; -PX_MODULE_LOAD(wpad, dns_alias, true); +MM_MODULE_EZ(dns_alias_wpad_extension, true, NULL); |