summaryrefslogtreecommitdiff
path: root/libproxy/modules
diff options
context:
space:
mode:
Diffstat (limited to 'libproxy/modules')
-rw-r--r--libproxy/modules/config_envvar.cpp74
-rw-r--r--libproxy/modules/config_gnome.cpp307
-rw-r--r--libproxy/modules/config_gnome3.cpp311
-rw-r--r--libproxy/modules/config_kde.cpp266
-rw-r--r--libproxy/modules/config_macosx.cpp171
-rw-r--r--libproxy/modules/config_pacrunner.cpp172
-rw-r--r--libproxy/modules/config_sysconfig.cpp173
-rw-r--r--libproxy/modules/config_w32reg.cpp174
-rw-r--r--libproxy/modules/ignore_domain.cpp59
-rw-r--r--libproxy/modules/ignore_hostname.cpp36
-rw-r--r--libproxy/modules/ignore_ip.cpp188
-rw-r--r--libproxy/modules/network_networkmanager.cpp98
-rw-r--r--libproxy/modules/pacrunner_duktape.cpp149
-rw-r--r--libproxy/modules/pacrunner_mozjs.cpp208
-rw-r--r--libproxy/modules/pacrunner_natus.cpp114
-rw-r--r--libproxy/modules/pacrunner_webkit.cpp182
-rw-r--r--libproxy/modules/pacutils.h242
-rw-r--r--libproxy/modules/pxgconf.cpp194
-rw-r--r--libproxy/modules/pxgsettings.cpp178
-rw-r--r--libproxy/modules/wpad_dns_alias.cpp54
20 files changed, 0 insertions, 3350 deletions
diff --git a/libproxy/modules/config_envvar.cpp b/libproxy/modules/config_envvar.cpp
deleted file mode 100644
index 544819b..0000000
--- a/libproxy/modules/config_envvar.cpp
+++ /dev/null
@@ -1,74 +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 <cstdlib>
-
-#include "../extension_config.hpp"
-using namespace libproxy;
-
-class envvar_config_extension : public config_extension {
-public:
- vector<url> get_config(const url &dst) {
- const char *proxy = NULL;
- vector<url> response;
-
- // If _PX_DEBUG_PACURL is set, use it as the PAC URL.
- if (proxy = getenv("_PX_DEBUG_PACURL")) {
- response.push_back(url(string("pac+") + proxy));
- return response;
- }
-
- // If the URL is an ftp url, try to read the ftp proxy
- if (dst.get_scheme() == "ftp") {
- if (!(proxy = getenv("ftp_proxy")))
- proxy = getenv("FTP_PROXY");
- }
-
- // If the URL is an https url, try to read the https proxy
- if (dst.get_scheme() == "https") {
- if (!(proxy = getenv("https_proxy")))
- proxy = getenv("HTTPS_PROXY");
- }
-
- // If the URL is not ftp or no ftp_proxy was found, get the http_proxy
- if (!proxy) {
- if (!(proxy = getenv("http_proxy")))
- proxy = getenv("HTTP_PROXY");
- }
-
- if (!proxy)
- throw runtime_error("Unable to read configuration");
-
- response.push_back(url(proxy));
- return response;
- }
-
- string get_ignore(const url&) {
- char *ignore = getenv("no_proxy");
- 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;
- }
-};
-
-MM_MODULE_INIT_EZ(envvar_config_extension, true, NULL, NULL);
diff --git a/libproxy/modules/config_gnome.cpp b/libproxy/modules/config_gnome.cpp
deleted file mode 100644
index fcd9516..0000000
--- a/libproxy/modules/config_gnome.cpp
+++ /dev/null
@@ -1,307 +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 <cstdio> // For fileno(), fread(), pclose(), popen(), sscanf()
-#include <sys/select.h> // For select()
-#include <fcntl.h> // For fcntl()
-#include <errno.h> // For errno stuff
-#include <sys/types.h> // For stat()
-#include <sys/stat.h> // For stat()
-#include <unistd.h> // For pipe(), close(), vfork(), dup(), execl(), _exit()
-#include <signal.h> // For kill()
-
-#include "../extension_config.hpp"
-using namespace libproxy;
-
-#define BUFFERSIZE 10240
-
-#define PROXY_MODE "/system/proxy/mode"
-#define PROXY_USE_AUTHENTICATION "/system/http_proxy/use_authentication"
-#define PROXY_AUTH_PASSWORD "/system/http_proxy/authentication_password"
-#define PROXY_AUTH_USER "/system/http_proxy/authentication_user"
-#define PROXY_AUTOCONFIG_URL "/system/proxy/autoconfig_url"
-#define PROXY_IGNORE_HOSTS "/system/http_proxy/ignore_hosts"
-#define PROXY_HTTP_HOST "/system/http_proxy/host"
-#define PROXY_HTTP_PORT "/system/http_proxy/port"
-#define PROXY_FTP_HOST "/system/proxy/ftp_host"
-#define PROXY_FTP_PORT "/system/proxy/ftp_port"
-#define PROXY_SECURE_HOST "/system/proxy/secure_host"
-#define PROXY_SECURE_PORT "/system/proxy/secure_port"
-#define PROXY_SOCKS_HOST "/system/proxy/socks_host"
-#define PROXY_SOCKS_PORT "/system/proxy/socks_port"
-#define PROXY_SAME_FOR_ALL "/system/http_proxy/use_same_proxy"
-
-static const char *all_keys[] = {
- PROXY_MODE,
- PROXY_USE_AUTHENTICATION,
- PROXY_AUTH_PASSWORD,
- PROXY_AUTH_USER,
- PROXY_AUTOCONFIG_URL,
- PROXY_IGNORE_HOSTS,
- PROXY_HTTP_HOST,
- PROXY_HTTP_PORT,
- PROXY_FTP_HOST,
- PROXY_FTP_PORT,
- PROXY_SECURE_HOST,
- PROXY_SECURE_PORT,
- PROXY_SOCKS_HOST,
- PROXY_SOCKS_PORT,
- PROXY_SAME_FOR_ALL,
- NULL
-};
-
-static int popen2(const char *program, FILE** read, FILE** write, pid_t* pid) {
- if (!read || !write || !pid || !program || !*program)
- return EINVAL;
- *read = NULL;
- *write = NULL;
- *pid = 0;
-
- // Open the pipes
- int rpipe[2];
- int wpipe[2];
- if (pipe(rpipe) < 0)
- return errno;
- if (pipe(wpipe) < 0) {
- close(rpipe[0]);
- close(rpipe[1]);
- return errno;
- }
-
- switch (*pid = vfork()) {
- case -1: // Error
- close(rpipe[0]);
- close(rpipe[1]);
- close(wpipe[0]);
- close(wpipe[1]);
- return errno;
-
- case 0: // Child
- close(STDIN_FILENO); // Close stdin
- close(STDOUT_FILENO); // Close stdout
-
- // Dup the read end of the write pipe to stdin
- // Dup the write end of the read pipe to stdout
- if (dup2(wpipe[0], STDIN_FILENO) != STDIN_FILENO) _exit(1);
- if (dup2(rpipe[1], STDOUT_FILENO) != STDOUT_FILENO) _exit(2);
-
- // Close unneeded fds
- for (int i = 3; i < sysconf(_SC_OPEN_MAX); i++)
- close(i);
-
- // Exec
- execl("/bin/sh", "sh", "-c", program, (char*) NULL);
- _exit(127); // Whatever we do, don't return
-
- default: // Parent
- close(rpipe[1]);
- close(wpipe[0]);
- *read = fdopen(rpipe[0], "r");
- *write = fdopen(wpipe[1], "w");
- if (*read == NULL || *write == NULL) {
- if (*read != NULL) fclose(*read);
- if (*write != NULL) fclose(*write);
- return errno;
- }
- return 0;
- }
-}
-
-static inline uint16_t get_port(const string &port)
-{
- uint16_t retval;
-
- if (sscanf(port.c_str(), "%hu", &retval) != 1)
- retval = 0;
-
- return retval;
-}
-
-void store_response(const string &type,
- const string &host,
- const string &port,
- bool auth,
- const string &username,
- const string &password,
- vector<url> &response) {
- if (host != "" && get_port(port) != 0) {
- string tmp = type + "://";
- if (auth)
- tmp += username + ":" + password + "@";
- tmp += host + ":" + port;
- response.push_back(url(tmp));
- }
-}
-
-class gnome_config_extension : public config_extension {
-public:
- gnome_config_extension() {
- // Build the command
- int count;
- struct stat st;
- string cmd = LIBEXECDIR "/pxgconf";
- const char *pxgconf = getenv("PX_GCONF");
-
- if (pxgconf)
- cmd = string (pxgconf);
-
- if (stat(cmd.c_str(), &st))
- throw runtime_error ("Unable to open gconf helper!");
-
- for (count=0 ; all_keys[count] ; count++)
- cmd += string(" ", 1) + all_keys[count];
-
- // Get our pipes
- if (popen2(cmd.c_str(), &this->read, &this->write, &this->pid) != 0)
- throw runtime_error("Unable to run gconf helper!");
-
- // Read in our initial data
- this->read_data(count);
-
- // Set the read pipe to non-blocking
- if (fcntl(fileno(this->read), F_SETFL, O_NONBLOCK) == -1) {
- fclose(this->read);
- fclose(this->write);
- kill(this->pid, SIGTERM);
- throw runtime_error("Unable to set pipe to non-blocking!");
- }
- }
-
- ~gnome_config_extension() {
- fclose(this->read);
- fclose(this->write);
- kill(this->pid, SIGTERM);
- }
-
- vector<url> get_config(const url &dest) {
- // Check for changes in the config
- fd_set rfds;
- struct timeval timeout = { 0, 0 };
- vector<url> response;
-
- FD_ZERO(&rfds);
- FD_SET(fileno(this->read), &rfds);
- if (select(fileno(this->read)+1, &rfds, NULL, NULL, &timeout) > 0)
- this->read_data();
-
- // Mode is wpad:// or pac+http://...
- if (this->data[PROXY_MODE] == "auto") {
- string pac = this->data[PROXY_AUTOCONFIG_URL];
- response.push_back(url::is_valid(pac) ? url(string("pac+") + pac) : url("wpad://"));
- return response;
- }
-
- // Mode is http://... or socks://...
- else if (this->data[PROXY_MODE] == "manual") {
- bool auth = this->data[PROXY_USE_AUTHENTICATION] == "true";
- string username = url::encode(this->data[PROXY_AUTH_USER], URL_ALLOWED_IN_USERINFO_ELEMENT);
- string password = url::encode(this->data[PROXY_AUTH_PASSWORD], URL_ALLOWED_IN_USERINFO_ELEMENT);
-
- // Get the per-scheme proxy settings
- if (dest.get_scheme() == "http")
- store_response("http", this->data[PROXY_HTTP_HOST],
- this->data[PROXY_HTTP_PORT], auth, username, password, response);
- else if (dest.get_scheme() == "https")
- // It is expected that the configured server is an
- // HTTP server that support CONNECT method.
- store_response("http", this->data[PROXY_SECURE_HOST],
- this->data[PROXY_SECURE_PORT], auth, username, password, response);
- else if (dest.get_scheme() == "ftp")
- // It is expected that the configured server is an
- // HTTP server that handles proxying FTP URLs
- // (e.g. request with header "Host: ftp://ftp.host.org")
- store_response("http", this->data[PROXY_FTP_HOST],
- this->data[PROXY_FTP_PORT], auth, username, password, response);
-
- store_response("socks", this->data[PROXY_SOCKS_HOST],
- this->data[PROXY_SOCKS_PORT], auth, username, password, response);
-
- // In case nothing matched, try HTTP Connect and fallback to direct.
- // If there is not secure HTTP proxy, this will only add direct:// to
- // the response
- if (response.size() == 0 && dest.get_scheme() != "http") {
- store_response("http", this->data[PROXY_SECURE_HOST],
- this->data[PROXY_SECURE_PORT], auth, username, password, response);
- response.push_back(url("direct://"));
- }
- }
-
- return response;
- }
-
- string get_ignore(const url&) {
- return this->data[PROXY_IGNORE_HOSTS];
- }
-
- virtual bool set_creds(url /*proxy*/, string username, string password) {
- string auth = PROXY_USE_AUTHENTICATION "\ttrue\n";
- string user = string(PROXY_AUTH_USER "\t") + username + "\n";
- string pass = string(PROXY_AUTH_PASSWORD "\t") + password + "\n";
-
- return (fwrite(auth.c_str(), 1, auth.size(), this->write) == auth.size() &&
- fwrite(user.c_str(), 1, user.size(), this->write) == user.size() &&
- fwrite(pass.c_str(), 1, pass.size(), this->write) == pass.size());
- }
-
-private:
- FILE* read;
- FILE* write;
- pid_t pid;
- map<string, string> data;
-
- bool read_data(int num=-1) {
- if (num == 0) return true;
- if (!this->read) return false; // We need the pipe to be open
-
- for (char l[BUFFERSIZE] ; num != 0 && fgets(l, BUFFERSIZE, this->read) != NULL ; ) {
- string line = l;
- line = line.substr(0, line.rfind('\n'));
- string key = line.substr(0, line.find("\t"));
- string val = line.substr(line.find("\t")+1);
- this->data[key] = val;
- if (num > 0) num--;
- }
-
- return (num <= 0);
- }
-};
-
-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;
- }
-}
-
-static bool gnome_config_extension_test() {
- return (getenv("GNOME_DESKTOP_SESSION_ID")
- || (getenv("DESKTOP_SESSION")
- && string(getenv("DESKTOP_SESSION")) == "gnome"));
-}
-
-MM_MODULE_INIT(gnome_config_extension,
- gnome_config_extension_init,
- gnome_config_extension_test,
- NULL, NULL);
diff --git a/libproxy/modules/config_gnome3.cpp b/libproxy/modules/config_gnome3.cpp
deleted file mode 100644
index 7415027..0000000
--- a/libproxy/modules/config_gnome3.cpp
+++ /dev/null
@@ -1,311 +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 <cstdio> // For fileno(), fread(), pclose(), popen(), sscanf()
-#include <sys/select.h> // For select()
-#include <fcntl.h> // For fcntl()
-#include <errno.h> // For errno stuff
-#include <sys/types.h> // For stat()
-#include <sys/stat.h> // For stat()
-#include <unistd.h> // For pipe(), close(), vfork(), dup(), execl(), _exit()
-#include <sys/wait.h> // For waitpid()
-#include <signal.h> // For kill()
-#include <string.h> // For memset() [used in FD_ZERO() on Solaris]
-
-#include "../extension_config.hpp"
-using namespace libproxy;
-
-#define BUFFERSIZE 10240
-
-#define PROXY_MODE "org.gnome.system.proxy/mode"
-#define PROXY_USE_AUTHENTICATION "org.gnome.system.proxy.http/use-authentication"
-#define PROXY_AUTH_PASSWORD "org.gnome.system.proxy.http/authentication-password"
-#define PROXY_AUTH_USER "org.gnome.system.proxy.http/authentication-user"
-#define PROXY_AUTOCONFIG_URL "org.gnome.system.proxy/autoconfig-url"
-#define PROXY_IGNORE_HOSTS "org.gnome.system.proxy/ignore-hosts"
-#define PROXY_HTTP_HOST "org.gnome.system.proxy.http/host"
-#define PROXY_HTTP_PORT "org.gnome.system.proxy.http/port"
-#define PROXY_FTP_HOST "org.gnome.system.proxy.ftp/host"
-#define PROXY_FTP_PORT "org.gnome.system.proxy.ftp/port"
-#define PROXY_SECURE_HOST "org.gnome.system.proxy.https/host"
-#define PROXY_SECURE_PORT "org.gnome.system.proxy.https/port"
-#define PROXY_SOCKS_HOST "org.gnome.system.proxy.socks/host"
-#define PROXY_SOCKS_PORT "org.gnome.system.proxy.socks/port"
-#define PROXY_SAME_FOR_ALL "org.gnome.system.proxy/use-same-proxy"
-
-static const char *all_keys[] = {
- "org.gnome.system.proxy",
- "org.gnome.system.proxy.http",
- "org.gnome.system.proxy.https",
- "org.gnome.system.proxy.ftp",
- "org.gnome.system.proxy.socks",
- NULL
-};
-
-static int popen2(const char *program, FILE** read, FILE** write, pid_t* pid) {
- if (!read || !write || !pid || !program || !*program)
- return EINVAL;
- *read = NULL;
- *write = NULL;
- *pid = 0;
-
- // Open the pipes
- int rpipe[2];
- int wpipe[2];
- if (pipe(rpipe) < 0)
- return errno;
- if (pipe(wpipe) < 0) {
- close(rpipe[0]);
- close(rpipe[1]);
- return errno;
- }
-
- switch (*pid = vfork()) {
- case -1: // Error
- close(rpipe[0]);
- close(rpipe[1]);
- close(wpipe[0]);
- close(wpipe[1]);
- return errno;
-
- case 0: // Child
- close(STDIN_FILENO); // Close stdin
- close(STDOUT_FILENO); // Close stdout
-
- // Dup the read end of the write pipe to stdin
- // Dup the write end of the read pipe to stdout
- if (dup2(wpipe[0], STDIN_FILENO) != STDIN_FILENO) _exit(1);
- if (dup2(rpipe[1], STDOUT_FILENO) != STDOUT_FILENO) _exit(2);
-
- // Close unneeded fds
- for (int i = 3; i < sysconf(_SC_OPEN_MAX); i++)
- close(i);
-
- // Exec
- execl("/bin/sh", "sh", "-c", program, (char*) NULL);
- _exit(127); // Whatever we do, don't return
-
- default: // Parent
- close(rpipe[1]);
- close(wpipe[0]);
- *read = fdopen(rpipe[0], "r");
- *write = fdopen(wpipe[1], "w");
- if (*read == NULL || *write == NULL) {
- if (*read != NULL) fclose(*read);
- if (*write != NULL) fclose(*write);
- return errno;
- }
- return 0;
- }
-}
-
-static inline uint16_t get_port(const string &port)
-{
- uint16_t retval;
-
- if (sscanf(port.c_str(), "%hu", &retval) != 1)
- retval = 0;
-
- return retval;
-}
-
-class gnome_config_extension : public config_extension {
-public:
- gnome_config_extension() : had_initial_values(false) {
- // Build the command
- int count;
- struct stat st;
- string cmd = LIBEXECDIR "/pxgsettings";
- const char *pxgconf = getenv("PX_GSETTINGS");
-
- if (pxgconf)
- cmd = string (pxgconf);
-
- if (stat(cmd.c_str(), &st))
- throw runtime_error ("Unable to open gsettings helper!");
-
- for (count=0 ; all_keys[count] ; count++)
- cmd += string(" ", 1) + all_keys[count];
-
- // Get our pipes
- if (popen2(cmd.c_str(), &this->read, &this->write, &this->pid) != 0)
- throw runtime_error("Unable to run gconf helper!");
-
- // Set the read pipe to non-blocking
- if (fcntl(fileno(this->read), F_SETFL, O_NONBLOCK) == -1) {
- fclose(this->read);
- fclose(this->write);
- kill(this->pid, SIGTERM);
- throw runtime_error("Unable to set pipe to non-blocking!");
- }
-
- // Read in our initial data
- while (!this->had_initial_values)
- this->read_data();
- }
-
- ~gnome_config_extension() {
- fclose(this->read);
- fclose(this->write);
- kill(this->pid, SIGTERM);
- waitpid(this->pid, NULL, 0);
- }
-
- void store_response(const string &type,
- const string &host,
- const string &port,
- bool auth,
- const string &username,
- const string &password,
- vector<url> &response) {
- if (host != "" && get_port(port) != 0) {
- string tmp = type + "://";
- if (auth)
- tmp += username + ":" + password + "@";
- tmp += host + ":" + port;
- response.push_back(url(tmp));
- }
- }
-
- vector<url> get_config(const url &dest) {
- // Check for changes in the config
- fd_set rfds;
- struct timeval timeout = { 0, 0 };
- vector<url> response;
-
- FD_ZERO(&rfds);
- FD_SET(fileno(this->read), &rfds);
- while (select(fileno(this->read)+1, &rfds, NULL, NULL, &timeout) > 0)
- this->read_data();
-
- // Mode is wpad:// or pac+http://...
- if (this->data[PROXY_MODE] == "auto") {
- string pac = this->data[PROXY_AUTOCONFIG_URL];
- response.push_back(url::is_valid(pac) ? url(string("pac+") + pac) : url("wpad://"));
- return response;
- }
-
- // Mode is http://... or socks://...
- else if (this->data[PROXY_MODE] == "manual") {
- bool auth = this->data[PROXY_USE_AUTHENTICATION] == "true";
- string username = url::encode(this->data[PROXY_AUTH_USER], URL_ALLOWED_IN_USERINFO_ELEMENT);
- string password = url::encode(this->data[PROXY_AUTH_PASSWORD], URL_ALLOWED_IN_USERINFO_ELEMENT);
-
- // Get the per-scheme proxy settings
- if (dest.get_scheme() == "http")
- store_response("http", this->data[PROXY_HTTP_HOST],
- this->data[PROXY_HTTP_PORT], auth, username, password, response);
- else if (dest.get_scheme() == "https")
- // It is expected that the configured server is an
- // HTTP server that support CONNECT method.
- store_response("http", this->data[PROXY_SECURE_HOST],
- this->data[PROXY_SECURE_PORT], auth, username, password, response);
- else if (dest.get_scheme() == "ftp")
- // It is expected that the configured server is an
- // HTTP server that handles proxying FTP URLs
- // (e.g. request with header "Host: ftp://ftp.host.org")
- store_response("http", this->data[PROXY_FTP_HOST],
- this->data[PROXY_FTP_PORT], auth, username, password, response);
-
- store_response("socks", this->data[PROXY_SOCKS_HOST],
- this->data[PROXY_SOCKS_PORT], auth, username, password, response);
-
- // In case nothing matched, try HTTP Connect and fallback to direct.
- // If there is not secure HTTP proxy, this will only add direct:// to
- // the response
- if (response.size() == 0 && dest.get_scheme() != "http") {
- store_response("http", this->data[PROXY_SECURE_HOST],
- this->data[PROXY_SECURE_PORT], auth, username, password, response);
- response.push_back(url("direct://"));
- }
- }
-
- return response;
- }
-
- string get_ignore(const url&) {
- return this->data[PROXY_IGNORE_HOSTS];
- }
-
- bool set_creds(const url &/*proxy*/, const string &username, const string &password) {
- string auth = PROXY_USE_AUTHENTICATION "\ttrue\n";
- string user = string(PROXY_AUTH_USER "\t") + username + "\n";
- string pass = string(PROXY_AUTH_PASSWORD "\t") + password + "\n";
-
- return (fwrite(auth.c_str(), 1, auth.size(), this->write) == auth.size() &&
- fwrite(user.c_str(), 1, user.size(), this->write) == user.size() &&
- fwrite(pass.c_str(), 1, pass.size(), this->write) == pass.size());
- }
-
-private:
- FILE* read;
- FILE* write;
- pid_t pid;
- map<string, string> data;
- bool had_initial_values;
-
- bool read_data(int num=-1) {
- if (num == 0) return true;
- if (!this->read) return false; // We need the pipe to be open
-
- for (char l[BUFFERSIZE] ; num != 0 && fgets(l, BUFFERSIZE, this->read) != NULL ; ) {
- string line = l;
- line = line.substr(0, line.rfind('\n'));
- if (line == "") {
- this->had_initial_values = true;
- continue;
- }
- string key = line.substr(0, line.find('\t'));
- string val = line.substr(line.find('\t')+1);
- this->data[key] = val;
- if (num > 0) num--;
- }
-
- return (num <= 0);
- }
-};
-
-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;
- }
-}
-
-static bool gnome_config_extension_test() {
- const char *desktops;
-
- desktops = getenv ("XDG_CURRENT_DESKTOP");
- if (!desktops)
- return false;
-
- /* Remember that XDG_CURRENT_DESKTOP is a list of strings. */
- return strstr (desktops, "GNOME") != NULL;
-}
-
-MM_MODULE_INIT(gnome_config_extension,
- gnome_config_extension_init,
- gnome_config_extension_test,
- NULL, NULL);
diff --git a/libproxy/modules/config_kde.cpp b/libproxy/modules/config_kde.cpp
deleted file mode 100644
index 895dcde..0000000
--- a/libproxy/modules/config_kde.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
- * Copyright (C) 2021 Fabian Vogt <fvogt@suse.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 <sys/stat.h>
-#include <pwd.h>
-
-#include <algorithm>
-#include <cstdlib>
-#include <cstdio>
-#include <sstream>
-
-#ifdef WIN32
-#define popen _popen
-#define pclose _pclose
-#else
-#include <unistd.h>
-#endif
-
-#include "../extension_config.hpp"
-using namespace libproxy;
-
-class kde_config_extension : public config_extension {
-public:
- kde_config_extension()
- : cache_time(0)
- {
- try {
- // Try the KF5 one first
- command = "kreadconfig5";
- command_output("kreadconfig5 --key nonexistant");
-
- try {
- use_xdg_config_dirs();
- }
- catch(...) {}
-
- return; // Worked
- }
- catch(...) {}
-
- try {
- // The KDE4 one next
- command = "kreadconfig";
- command_output(command);
-
- try {
- parse_dir_list(command_output("kde4-config --path config"));
- }
- catch(...) {}
-
- return; // Worked
- }
- catch(...) {}
-
- // Neither worked, so throw in get_config
- command = "";
- }
-
- vector<url> get_config(const url &dst) {
- // See constructor
- if(command.empty())
- throw runtime_error("Unable to read configuration");
-
- vector<url> response;
-
- string tmp, proxyType = kde_config_val("ProxyType", "-1");
-
- // Just switch on the first byte, either a digit, '-' ("-1") or '\0'
- switch(proxyType.c_str()[0])
- {
- case '1':
- tmp = kde_config_val(dst.get_scheme() + "Proxy", "");
- if(tmp.empty()) {
- tmp = kde_config_val("httpProxy", "");
- if(tmp.empty()) {
- tmp = kde_config_val("socksProxy", "");
- if(tmp.empty())
- tmp = "direct://";
- }
- }
-
- // KDE uses "http://127.0.0.1 8080" instead of "http://127.0.0.1:8080"
- replace(tmp.begin(), tmp.end(), ' ', ':');
-
- response.push_back(url(tmp));
- break;
-
- case '2':
- tmp = "pac+" + kde_config_val("Proxy Config Script", "");
- if (url::is_valid(tmp))
- {
- response.push_back(url(tmp));
- break;
- }
- // else fallthrough
-
- case '3':
- response.push_back(url(string("wpad://")));
- break;
-
- case '4':
- throw runtime_error("User config_envvar"); // We'll bypass this config plugin and let the envvar plugin wor
-
- case '0':
- default: // Not set or unknown/illegal
- response.push_back(url("direct://"));
- break;
- }
-
- return response;
- }
-
- string get_ignore(const url&) {
- // See constructor
- if(command.empty())
- return "";
-
- string proxyType = kde_config_val("ProxyType", "-1");
- if(proxyType.c_str()[0] != '1')
- return ""; // Not manual config
-
- string prefix = kde_config_val("ReversedException", "false") != "false" ? "-" : "";
- return prefix + kde_config_val("NoProxyFor", ""); // Already in the right format
- }
-
-private:
- string command_output(const string &cmdline) {
- // Capture stderr as well
- const string command = "(" + cmdline + ")2>&1";
- FILE *pipe = popen(command.c_str(), "r");
- if (!pipe)
- throw runtime_error("Unable to run command");
-
- char buffer[128];
- string result = "";
- while (!feof(pipe)) {
- if (fgets(buffer, 128, pipe) != NULL)
- result += buffer; // TODO: If this throws bad_alloc, pipe is leaked
- }
-
- if(pclose(pipe) != 0)
- throw runtime_error("Command failed");
-
- // Trim newlines and whitespace at end
- result.erase(result.begin() + (result.find_last_not_of(" \n\t")+1), result.end());
-
- return result;
- }
-
- // Neither key nor def must contain '
- const string &kde_config_val(const string &key, const string &def) {
- if (cache_needs_refresh())
- cache.clear();
- else {
- // Already in cache?
- map<string, string>::iterator it = cache.find(key);
- if(it != cache.end())
- return it->second;
- }
-
- // Although all values are specified internally and/or validated,
- // checking is better than trusting.
- if(key.find('\'') != string::npos || def.find('\'') != string::npos)
- return def;
-
- // Add result to cache and return it
- return cache[key] = command_output(
- command + " --file kioslaverc --group 'Proxy Settings' --key '" + key + "' --default '" + def + "'");
- }
-
- // Used for cache invalidation
- struct configfile {
- string path;
- time_t mtime; // 0 means either not refreshed or doesn't exist
- };
-
- // Parses colon-delimited lists of paths to fill config_locs
- void parse_dir_list(const string &dirs) {
- string config_path;
- stringstream config_paths_stream(dirs);
-
- // Try each of the listed folders, seperated by ':'
- while (getline(config_paths_stream, config_path, ':')) {
- configfile config_loc;
- config_loc.path = config_path + "/kioslaverc";
- config_loc.mtime = 0;
- config_locs.push_back(config_loc);
- }
- }
-
- // Add XDG configuration locations to the configuration paths
- void use_xdg_config_dirs() {
- // Return environment value as std::string if set, otherwise def
- auto getenv_default = [](const char *name, const std::string &def) {
- const char *ret = getenv(name);
- return std::string(ret ? ret : def);
- };
-
- std::string homedir = getenv_default("HOME", "");
- if (homedir.empty()) {
- size_t bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (bufsize == -1)
- bufsize = 16384;
-
- std::vector<char> buf(bufsize);
- struct passwd pwd, *result;
- getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result);
- if (result)
- homedir = pwd.pw_dir;
- }
-
- if (homedir.empty())
- throw std::runtime_error("Failed to get home directory");
-
- parse_dir_list(getenv_default("XDG_CONFIG_HOME", homedir + "/.config"));
- parse_dir_list(getenv_default("XDG_CONFIG_DIRS", "/etc/xdg"));
- }
-
- // If any of the locations in config_locs changed (different mtime),
- // update config_locs and return true.
- bool cache_needs_refresh() {
- // Play safe here, if we can't determine the location,
- // don't cache at all.
- bool needs_refresh = config_locs.empty();
- struct stat config_info;
-
- for (unsigned int i = 0; i < config_locs.size(); ++i) {
- configfile &config = config_locs[i];
- time_t current_mtime = stat(config.path.c_str(), &config_info) == 0 ? config_info.st_mtime : 0;
- if (config.mtime != current_mtime) {
- config.mtime = current_mtime;
- needs_refresh = true;
- }
- }
-
- return needs_refresh;
- }
-
- // Whether to use kreadconfig or kreadconfig5
- string command;
- // When the cache was flushed last
- time_t cache_time;
- // Cache for config values
- map<string, string> cache;
- // State of the config files at the time of the last cache flush
- vector<configfile> config_locs;
-};
-
-MM_MODULE_INIT_EZ(kde_config_extension, getenv("KDE_FULL_SESSION"), NULL, NULL);
diff --git a/libproxy/modules/config_macosx.cpp b/libproxy/modules/config_macosx.cpp
deleted file mode 100644
index be81b99..0000000
--- a/libproxy/modules/config_macosx.cpp
+++ /dev/null
@@ -1,171 +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 <sstream>
-
-#include "../extension_config.hpp"
-using namespace libproxy;
-
-#include <SystemConfiguration/SystemConfiguration.h>
-
-class str : public string {
-public:
- str(CFStringRef s) : string() {
- if (!s) return;
- const char* tmp = CFStringGetCStringPtr(s, CFStringGetFastestEncoding(s));
- *this += tmp ? tmp : "";
- }
-
- str(CFArrayRef a) : string() {
- if (!a) return;
- for (CFIndex i=0 ; i < CFArrayGetCount(a) ; i++) {
- CFStringRef s = (CFStringRef) CFArrayGetValueAtIndex(a, i);
- *this += str(s);
- if (i+1 < CFArrayGetCount(a))
- *this += ",";
- }
- }
-};
-
-template <class T>
-static T getobj(CFDictionaryRef settings, string key) {
- if (!settings) return NULL;
- CFStringRef k = CFStringCreateWithCString(NULL, key.c_str(), kCFStringEncodingMacRoman);
- if (!k) return NULL;
- T retval = (T) CFDictionaryGetValue(settings, k);
- CFRelease(k);
- return retval;
-}
-
-static bool getint(CFDictionaryRef settings, string key, int64_t& answer) {
- CFNumberRef n = getobj<CFNumberRef>(settings, key);
- if (!n) return false;
- if (!CFNumberGetValue(n, kCFNumberSInt64Type, &answer))
- return false;
- return true;
-}
-
-static bool getbool(CFDictionaryRef settings, string key, bool dflt=false) {
- int64_t i;
- if (!getint(settings, key, i)) return dflt;
- return i != 0;
-}
-
-static bool protocol_url(CFDictionaryRef settings, string protocol, string& config) {
- int64_t port;
- string host;
-
- // Check ProtocolEnabled
- if (!getbool(settings, protocol + "Enable"))
- return false;
-
- // Get ProtocolPort
- if (!getint(settings, protocol + "Port", port))
- return false;
-
- // Get ProtocolProxy
- if ((host = str(getobj<CFStringRef>(settings, protocol + "Proxy"))) == "")
- return false;
-
- stringstream ss;
- if (protocol == "HTTP" || protocol == "HTTPS" || protocol == "FTP" || protocol == "Gopher")
- ss << "http://";
- else if (protocol == "RTSP")
- ss << "rtsp://";
- else if (protocol == "SOCKS")
- ss << "socks://";
- else
- return false;
- ss << host;
- ss << ":";
- ss << port;
-
- config = ss.str();
- return true;
-}
-
-static string toupper(string str) {
- string tmp;
- for (unsigned int i=0 ; str.c_str()[i] ; i++)
- tmp += toupper(str.c_str()[i]);
- return tmp;
-}
-
-static string capitalize(string str) {
- char c = toupper(str.c_str()[0]);
- return string(&c, 1) + str.substr(1);
-}
-
-class macosx_config_extension : public config_extension {
-public:
- vector<url> get_config(const url &the_url) {
- string tmp;
- CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
- vector<url> response;
-
- if (!proxies) throw runtime_error("Unable to fetch proxy configuration");
-
- // wpad://
- if (getbool(proxies, "ProxyAutoDiscoveryEnable")) {
- CFRelease(proxies);
- response.push_back(url("wpad://"));
- }
-
- // pac+http://...
- else if (getbool(proxies, "ProxyAutoConfigEnable") &&
- (tmp = str(getobj<CFStringRef>(proxies, "ProxyAutoConfigURLString"))) != "" &&
- url::is_valid(tmp)) {
- CFRelease(proxies);
- response.push_back(url(string("pac+") + tmp));
- }
-
- // http:// or socks:// (TODO: gopher:// and rtsp:// ???)
- else if ((protocol_url(proxies, toupper(the_url.get_scheme()), tmp) && url::is_valid(tmp)) ||
- (protocol_url(proxies, capitalize(the_url.get_scheme()), tmp) && url::is_valid(tmp)) ||
- (protocol_url(proxies, toupper("http"), tmp) && url::is_valid(tmp)) ||
- (protocol_url(proxies, toupper("socks"), tmp) && url::is_valid(tmp))) {
- CFRelease(proxies);
- response.push_back(url(tmp));
- }
- else {
- // direct://
- CFRelease(proxies);
- response.push_back(url("direct://"));
- }
-
- return response;
- }
-
- string get_ignore(const url&) {
- // Get config dict
- CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
- if (!proxies) return "";
-
- // Get ignores
- string tmp = str(getobj<CFArrayRef>(proxies, "ExceptionsList"));
- if (getbool(proxies, "ExcludeSimpleHostnames"))
- tmp += (tmp == "" ? string("") : string(",")) + "<local>";
-
- CFRelease(proxies);
- return tmp;
- }
-};
-
-MM_MODULE_INIT_EZ(macosx_config_extension, true, NULL, NULL);
-
diff --git a/libproxy/modules/config_pacrunner.cpp b/libproxy/modules/config_pacrunner.cpp
deleted file mode 100644
index 61faebc..0000000
--- a/libproxy/modules/config_pacrunner.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2010 Intel Corporation
- *
- * 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 "../extension_config.hpp"
-using namespace libproxy;
-
-#include <string.h>
-#include <dbus/dbus.h>
-
-class pacrunner_config_extension : public config_extension {
-public:
- pacrunner_config_extension() {
- this->conn = NULL;
- }
-
- ~pacrunner_config_extension() {
- if (this->conn) dbus_connection_close(this->conn);
- }
-
- class scoped_dbus_message {
- public:
- scoped_dbus_message(DBusMessage *msg) {
- this->msg = msg;
- }
-
- ~scoped_dbus_message() {
- if (this->msg)
- dbus_message_unref(msg);
- }
-
- private:
- DBusMessage *msg;
- };
-
- vector<url> get_config(const url &dest) {
- // Make sure we have a valid connection with a proper match
- DBusConnection *conn = this->conn;
- vector<url> response;
-
- if (!conn || !dbus_connection_get_is_connected(conn))
- {
- // If the connection was disconnected,
- // close it an clear the queue
- if (conn)
- {
- dbus_connection_close(conn);
- dbus_connection_read_write(conn, 0);
- for (DBusMessage *msg=NULL ; (msg = dbus_connection_pop_message(conn)) ; dbus_message_unref(msg)) {};
- }
-
- // Create a new connections
- conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
- this->conn = conn;
- if (!conn)
- throw runtime_error("Unable to set up DBus connection");
-
- // If connection was successful, set it up
- dbus_connection_set_exit_on_disconnect(conn, false);
- }
-
- DBusMessage *msg, *reply;
-
- msg = dbus_message_new_method_call("org.pacrunner",
- "/org/pacrunner/client",
- "org.pacrunner.Client",
- "FindProxyForURL");
- if (!msg)
- throw runtime_error("Unable to create PacRunner DBus call");
-
- string dest_str = dest.to_string();
- string dest_host = dest.get_host();
- const char *dest_cstr = dest_str.c_str();
- const char *dest_host_cstr = dest_host.c_str();
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &dest_cstr,
- DBUS_TYPE_STRING, &dest_host_cstr,
- DBUS_TYPE_INVALID);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, NULL);
-
- dbus_message_unref(msg);
-
- if (!reply)
- throw runtime_error("Failed to get DBus response from PacRunner");
-
- scoped_dbus_message smsg(reply);
- char *str = NULL;
- dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID);
-
- if (!str || !strlen(str) || !strcasecmp(str, "DIRECT"))
- response.push_back(url("direct://"));
- else if (!strncasecmp(str, "PROXY ", 6))
- response.push_back(url("http://" + string(str + 6)));
- else if (!strncasecmp(str, "SOCKS ", 6))
- response.push_back(url("socks://" + string(str + 6)));
- else if (!strncasecmp(str, "SOCKS4 ", 7))
- response.push_back(url("socks4://" + string(str + 7)));
- else if (!strncasecmp(str, "SOCKS5 ", 7))
- response.push_back(url("socks5://" + string(str + 7)));
- else {
- throw runtime_error("Unrecognised proxy response from PacRunner: " + string(str));
- }
- return response;
- }
-
-private:
- DBusConnection *conn;
-};
-
-#define TEST_TIMEOUT_MS 100
-
-static bool is_pacrunner_available(void)
-{
- DBusMessage *msg, *reply;
- DBusConnection* system;
- dbus_bool_t owned;
- bool found = false;
- const char *name = "org.pacrunner";
-
- msg = dbus_message_new_method_call("org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "NameHasOwner");
- if (!msg)
- return false;
-
- dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
-
- system = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
- if (!system)
- goto out_msg;
-
- reply = dbus_connection_send_with_reply_and_block(system, msg,
- TEST_TIMEOUT_MS,
- NULL);
- if (!reply)
- goto out_sys;
-
- if (dbus_message_get_args(reply, NULL, DBUS_TYPE_BOOLEAN, &owned,
- DBUS_TYPE_INVALID))
- found = owned;
-
-out_reply:
- dbus_message_unref(reply);
-out_sys:
- dbus_connection_close(system);
- dbus_connection_unref(system);
-out_msg:
- dbus_message_unref(msg);
-
- return found;
-}
-
-MM_MODULE_INIT_EZ(pacrunner_config_extension, is_pacrunner_available(),
- NULL, NULL);
diff --git a/libproxy/modules/config_sysconfig.cpp b/libproxy/modules/config_sysconfig.cpp
deleted file mode 100644
index 383b926..0000000
--- a/libproxy/modules/config_sysconfig.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*******************************************************************************
- * libproxy sysconfig module
- * Copyright (C) 2010 Novell Inc.
- *
- * 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 <sys/stat.h>
-#include <cstdlib>
-#include <map>
-#include <fstream>
-#include <unistd.h>
-#include <sys/types.h>
-
-
-#include "../extension_config.hpp"
-using namespace libproxy;
-using std::map;
-
-enum Trim {
- NO_TRIM = 0x00,
- L_TRIM = 0x01,
- R_TRIM = 0x02,
- TRIM = (L_TRIM|R_TRIM)
-};
-
-static std::string trim( const std::string & s, const Trim trim_r = TRIM ) {
-
- if (s.empty() || trim_r == NO_TRIM)
- return s;
-
- std::string ret(s);
-
- if (trim_r & L_TRIM) {
- std::string::size_type p = ret.find_first_not_of(" \t\n");
- if (p == std::string::npos)
- return std::string();
-
- ret = ret.substr(p);
- }
-
- if (trim_r & R_TRIM) {
- std::string::size_type p = ret.find_last_not_of(" \t\n");
- if (p == std::string::npos)
- return std::string();
-
- ret = ret.substr(0, p+1);
- }
-
- return ret;
-}
-
-static map<string,string> sysconfig_read(const string &_path) {
-
- map<string,string> ret;
- string line;
-
- ifstream in(_path.c_str());
- if (in.fail()) {
- return ret;
- }
-
- while(getline( in, line)) {
-
- if (*line.begin() != '#') {
-
- string::size_type pos = line.find('=', 0);
-
- if (pos != string::npos) {
-
- string key = trim(line.substr(0, pos));
- string value = trim(line.substr(pos + 1, line.length() - pos - 1));
-
- if (value.length() >= 2
- && *(value.begin()) == '"'
- && *(value.rbegin()) == '"') {
- value = value.substr( 1, value.length() - 2 );
- }
-
- if (value.length() >= 2
- && *(value.begin()) == '\''
- && *(value.rbegin()) == '\'' ) {
- value = value.substr( 1, value.length() - 2 );
- }
- ret[key] = value;
- } // '=' found
-
- } // not comment
-
- } // while getline
- return ret;
-}
-
-static bool should_use_sysconfig()
-{
- struct stat st;
- if (stat("/etc/sysconfig", &st) == 0)
- return (getuid() == 0);
- return false;
-}
-
-class sysconfig_config_extension : public config_extension {
-
- map<string,string> _data;
-
-public:
- sysconfig_config_extension()
- : _data(sysconfig_read("/etc/sysconfig/proxy")) {
-
- }
-
- ~sysconfig_config_extension() {
- }
-
- vector<url> get_config(const url &dst) {
- map<string,string>::const_iterator it = _data.find("PROXY_ENABLED");
- vector<url> response;
-
- if (it != _data.end() && it->second == "no") {
- response.push_back(url("direct://"));
- return response;
- }
-
- string key;
- string proxy;
-
- // If the URL is an ftp url, try to read the ftp proxy
- if (dst.get_scheme() == "ftp")
- key = "FTP_PROXY";
- else if (dst.get_scheme() == "http")
- key = "HTTP_PROXY";
- else if (dst.get_scheme() == "https")
- key = "HTTPS_PROXY";
-
- it = _data.find(key);
- if (it != _data.end())
- proxy = it->second;
-
- if (proxy.empty())
- throw runtime_error("Unable to read configuration");
-
- response.push_back(url(proxy));
- return response;
- }
-
- string get_ignore(const url&) {
- map<string,string>::const_iterator it = _data.find("NO_PROXY");
- if (it != _data.end())
- return it->second;
- return "";
- }
-
- // if we are running as root, and the module is used, then
- // make sure this is the first method tried
- virtual bool operator<(const base_extension&) const {
- return true;
- }
-};
-
-MM_MODULE_INIT_EZ(sysconfig_config_extension, should_use_sysconfig(), NULL, NULL);
-
diff --git a/libproxy/modules/config_w32reg.cpp b/libproxy/modules/config_w32reg.cpp
deleted file mode 100644
index 675c755..0000000
--- a/libproxy/modules/config_w32reg.cpp
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2009 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 <algorithm>
-#include "../extension_config.hpp"
-using namespace libproxy;
-
-#define W32REG_OFFSET_PAC (1 << 2)
-#define W32REG_OFFSET_WPAD (1 << 3)
-#define W32REG_BASEKEY "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
-#define W32REG_BUFFLEN 1024
-
-static bool get_registry(const char *key, const char *name, char **sval, uint32_t *slen, uint32_t *ival) {
- HKEY hkey;
- LONG result;
- DWORD type;
- DWORD buflen = W32REG_BUFFLEN;
- BYTE buffer[W32REG_BUFFLEN];
-
- // Don't allow the caller to specify both sval and ival
- if (sval && ival)
- return false;
-
- // Open the key
- if (RegOpenKeyExA(HKEY_CURRENT_USER, key, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
- return false;
-
- // Read the value
- result = RegQueryValueExA(hkey, name, NULL, &type, buffer, &buflen);
-
- // Close the key
- RegCloseKey(hkey);
-
- // Evaluate
- if (result != ERROR_SUCCESS)
- return false;
- switch (type)
- {
- case REG_BINARY:
- case REG_EXPAND_SZ:
- case REG_SZ:
- if (!sval) return false;
- if (slen) *slen = buflen;
- *sval = new char[buflen];
- return memcpy(*sval, buffer, buflen) != NULL;
- case REG_DWORD:
- if (ival) return memcpy(ival, buffer, buflen < sizeof(uint32_t) ? buflen : sizeof(uint32_t)) != NULL;
- }
- return false;
-}
-
-static bool is_enabled(uint8_t type) {
- char *data = NULL;
- uint32_t dlen = 0;
- bool result = false;
-
- // Get the binary value DefaultConnectionSettings
- if (!get_registry(W32REG_BASEKEY "\\Connections", "DefaultConnectionSettings", &data, &dlen, NULL))
- return false;
-
- // WPAD and PAC are contained in the 9th value
- if (dlen >= 9)
- result = (data[8] & type) == type; // Check to see if the bit is set
-
- delete data;
- return result;
-}
-
-static map<string, string> parse_manual(string data) {
- // ProxyServer comes in two formats:
- // 1.2.3.4:8080 or ftp=1.2.3.4:8080;https=1.2.3.4:8080...
- map<string, string> rval;
-
- // If we have the second format, do recursive parsing,
- // then handle just the first entry
- if (data.find(";") != string::npos) {
- rval = parse_manual(data.substr(data.find(";")+1));
- data = data.substr(0, data.find(";"));
- }
-
- // If we have the first format, just assign HTTP and we're done
- if (data.find("=") == string::npos) {
- rval["http"] = string("http://") + data;
- return rval;
- }
-
- // Otherwise set the value for this single entry and return
- string protocol = data.substr(0, data.find("="));
- try { rval[protocol] = url(protocol + "://" + data.substr(data.find("=")+1)).to_string(); }
- catch (parse_error&) {}
-
- return rval;
-}
-
-class w32reg_config_extension : public config_extension {
-public:
- vector<url> get_config(const url &dst) {
- char *tmp = NULL;
- uint32_t enabled = 0;
- vector<url> response;
-
- // WPAD
- if (is_enabled(W32REG_OFFSET_WPAD)) {
- response.push_back(url("wpad://"));
- return response;
- }
-
- // PAC
- if (is_enabled(W32REG_OFFSET_PAC) &&
- get_registry(W32REG_BASEKEY, "AutoConfigURL", &tmp, NULL, NULL) &&
- url::is_valid(string("pac+") + tmp)) {
- response.push_back(url(string("pac+") + tmp));
- delete tmp;
- return response;
- }
-
- // Manual proxy
- // Check to see if we are enabled and get the value of ProxyServer
- if (get_registry(W32REG_BASEKEY, "ProxyEnable", NULL, NULL, &enabled) && enabled &&
- get_registry(W32REG_BASEKEY, "ProxyServer", &tmp, NULL, NULL)) {
- map<string, string> manual = parse_manual(tmp);
- delete tmp;
-
- // First we look for an exact match
- if (manual.find(dst.get_scheme()) != manual.end())
- response.push_back(manual[dst.get_scheme()]);
-
- // Next we look for http
- else if (manual.find("http") != manual.end())
- response.push_back(manual["http"]);
-
- // Last we look for socks
- else if (manual.find("socks") != manual.end())
- response.push_back(manual["socks"]);
-
- return response;
- }
-
- // Direct
- response.push_back(url("direct://"));
- return response;
- }
-
- string get_ignore(const url &dst) {
- char *tmp;
- if (get_registry(W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) {
- string po = tmp;
- delete tmp;
- const char windowsDelimiter = ';';
- const char libproxyDelimiter = ',';
- replace(po.begin(), po.end(), windowsDelimiter, libproxyDelimiter );
- if (po.length()>0)
- return po;
- }
- return "";
- }
-};
-
-MM_MODULE_INIT_EZ(w32reg_config_extension, true, NULL, NULL);
diff --git a/libproxy/modules/ignore_domain.cpp b/libproxy/modules/ignore_domain.cpp
deleted file mode 100644
index f39e545..0000000
--- a/libproxy/modules/ignore_domain.cpp
+++ /dev/null
@@ -1,59 +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 <cstdio>
-
-#include "../extension_ignore.hpp"
-using namespace libproxy;
-
-class domain_ignore_extension : public ignore_extension {
-public:
- virtual bool ignore(url& url, const string &ignorestr) {
- /* Get our URL's hostname and port */
- string host = url.get_host();
- int port = url.get_port();
-
- /* Get our ignore pattern's hostname and port */
- string ihost = ignorestr;
- int iport = 0;
- if (ihost.find(':') != string::npos) {
- if (sscanf(ignorestr.substr(ihost.find(':')+1).c_str(), "%d", &iport) == 1)
- ihost = ihost.substr(0, ihost.find(':'));
- else
- iport = 0;
- }
-
- /* Hostname match (domain.com or domain.com:80) */
- if (host == ihost)
- return (iport == 0 || port == iport);
-
- /* Endswith (.domain.com or .domain.com:80) */
- if (ihost[0] == '.' && host.find(ihost) == host.size() - ihost.size() && host.size() >= ihost.size())
- return (iport == 0 || port == iport);
-
- /* Glob (*.domain.com or *.domain.com:80) */
- if (ihost[0] == '*' && host.find(ihost.substr(1)) == host.size() - ihost.substr(1).size() && host.size() >= ihost.substr(1).size())
- return (iport == 0 || port == iport);
-
- /* No match was found */
- return false;
- }
-};
-
-MM_MODULE_INIT_EZ(domain_ignore_extension, true, NULL, NULL);
diff --git a/libproxy/modules/ignore_hostname.cpp b/libproxy/modules/ignore_hostname.cpp
deleted file mode 100644
index 6caa291..0000000
--- a/libproxy/modules/ignore_hostname.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2009 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 <cstdio>
-
-#include "../extension_ignore.hpp"
-using namespace libproxy;
-
-class hostname_ignore_extension : public ignore_extension {
-public:
- virtual bool ignore(url& url, const string &ignorestr) {
- if (ignorestr == "<local>" &&
- url.get_host().find(':') == string::npos && // Make sure it's not IPv6
- url.get_host().find('.') == string::npos)
- return true;
- return false;
- }
-};
-
-MM_MODULE_INIT_EZ(hostname_ignore_extension, true, NULL, NULL);
diff --git a/libproxy/modules/ignore_ip.cpp b/libproxy/modules/ignore_ip.cpp
deleted file mode 100644
index b067f02..0000000
--- a/libproxy/modules/ignore_ip.cpp
+++ /dev/null
@@ -1,188 +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 <cstdio>
-#include <cstring>
-
-#include "../extension_ignore.hpp"
-using namespace libproxy;
-
-static inline bool
-sockaddr_equals(const struct sockaddr *ip_a, const struct sockaddr *ip_b, const struct sockaddr *nm)
-{
- if (!ip_a || !ip_b) return false;
- if (ip_a->sa_family != ip_b->sa_family) return false;
- if (nm && ip_a->sa_family != nm->sa_family) return false;
-
- /* Setup the arrays */
- uint8_t bytes = 0, *a_data = NULL, *b_data = NULL, *nm_data = NULL;
- if (ip_a->sa_family == AF_INET)
- {
- bytes = 32 / 8;
- a_data = (uint8_t *) &((struct sockaddr_in *) ip_a)->sin_addr;
- b_data = (uint8_t *) &((struct sockaddr_in *) ip_b)->sin_addr;
- nm_data = nm ? (uint8_t *) &((struct sockaddr_in *) nm)->sin_addr : NULL;
- }
- else if (ip_a->sa_family == AF_INET6)
- {
- bytes = 128 / 8;
- a_data = (uint8_t *) &((struct sockaddr_in6 *) ip_a)->sin6_addr;
- b_data = (uint8_t *) &((struct sockaddr_in6 *) ip_b)->sin6_addr;
- nm_data = nm ? (uint8_t *) &((struct sockaddr_in6 *) nm)->sin6_addr : NULL;
- }
- else
- return false;
-
- for (int i=0 ; i < bytes ; i++)
- {
- if (nm && (a_data[i] & nm_data[i]) != (b_data[i] & nm_data[i]))
- return false;
- else if (!nm && (a_data[i] != b_data[i]))
- return false;
- }
- return true;
-}
-
-static inline sockaddr *
-sockaddr_from_string(const string &ip)
-{
- struct sockaddr *result = NULL;
-
- /* Try to parse */
- struct addrinfo *info = NULL;
- struct addrinfo flags;
- flags.ai_family = AF_UNSPEC;
- flags.ai_socktype = 0;
- flags.ai_protocol = 0;
- flags.ai_flags = AI_NUMERICHOST;
- if (getaddrinfo(ip.c_str(), NULL, &flags, &info) != 0 || !info) return result;
-
- /* Copy the results into our buffer */
- result = (sockaddr *) new char[info->ai_addrlen];
- if (!result) {
- freeaddrinfo(info);
- return result;
- }
- memcpy(result, info->ai_addr, info->ai_addrlen);
- freeaddrinfo(info);
- return result;
-}
-
-static inline sockaddr *
-sockaddr_from_cidr(sa_family_t af, uint8_t cidr)
-{
- /* IPv4 */
- if (af == AF_INET)
- {
- sockaddr_in *mask = (sockaddr_in*) new char[sizeof(sockaddr_in)];
- mask->sin_family = af;
- mask->sin_addr.s_addr = htonl(~0 << (32 - (cidr > 32 ? 32 : cidr)));
-
- return (struct sockaddr *) mask;
- }
-
- /* IPv6 */
- else if (af == AF_INET6)
- {
- sockaddr_in6 *mask = (sockaddr_in6*) new char[sizeof(sockaddr_in6)];
- mask->sin6_family = af;
- for (uint8_t i=0 ; i < sizeof(mask->sin6_addr) ; i++)
- mask->sin6_addr.s6_addr[i] = ~0 << (8 - (8*i > cidr ? 0 : cidr-8*i < 8 ? cidr-8*i : 8) );
-
- return (sockaddr *) mask;
- }
-
- return NULL;
-}
-
-class ip_ignore_extension : public ignore_extension {
-public:
- virtual bool ignore(url& url, const string &ignore) {
- bool result = false;
- uint16_t port = 0;
- const struct sockaddr *dst_ip = url.get_ips(false) ? url.get_ips(false)[0] : NULL;
- struct sockaddr *ign_ip = NULL, *net_ip = NULL;
-
- /*
- * IPv4
- * IPv6
- */
- if ((ign_ip = sockaddr_from_string(ignore)))
- goto out;
-
- /*
- * IPv4/CIDR
- * IPv4/IPv4
- * IPv6/CIDR
- * IPv6/IPv6
- */
- if (ignore.find('/') != string::npos)
- {
- ign_ip = sockaddr_from_string(ignore.substr(0, ignore.find('/')));
-
- uint32_t cidr = 0;
- string mask = ignore.substr(ignore.find('/') + 1);
-
- if (mask.find('.') != string::npos)
- {
- /* A dotted netmask was used */
- net_ip = sockaddr_from_string(mask);
- }
- else
- {
- /* If CIDR notation was used, get the netmask */
- if (ign_ip && sscanf(mask.c_str(), "%d", &cidr) == 1)
- net_ip = sockaddr_from_cidr(ign_ip->sa_family, cidr);
- }
-
- if (ign_ip && net_ip && ign_ip->sa_family == net_ip->sa_family)
- goto out;
-
- delete[] ign_ip;
- delete[] net_ip;
- ign_ip = NULL;
- net_ip = NULL;
- }
-
- /*
- * IPv4:port
- * [IPv6]:port
- */
- if (ignore.rfind(':') != string::npos && sscanf(ignore.substr(ignore.rfind(':')).c_str(), ":%hu", &port) == 1 && port > 0)
- {
- ign_ip = sockaddr_from_string(ignore.substr(ignore.rfind(':')).c_str());
-
- /* Make sure this really is just a port and not just an IPv6 address */
- if (ign_ip && (ign_ip->sa_family != AF_INET6 || ignore[0] == '['))
- goto out;
-
- delete[] ign_ip;
- ign_ip = NULL;
- port = 0;
- }
-
- out:
- result = sockaddr_equals(dst_ip, ign_ip, net_ip);
- delete[] ign_ip;
- delete[] net_ip;
- return port != 0 ? (port == url.get_port() && result) : result;
- }
-};
-
-MM_MODULE_INIT_EZ(ip_ignore_extension, true, NULL, NULL);
diff --git a/libproxy/modules/network_networkmanager.cpp b/libproxy/modules/network_networkmanager.cpp
deleted file mode 100644
index 546a8ee..0000000
--- a/libproxy/modules/network_networkmanager.cpp
+++ /dev/null
@@ -1,98 +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 <stdint.h> // For uint32_t
-
-#include "../extension_network.hpp"
-using namespace libproxy;
-
-#include <dbus/dbus.h>
-#include <NetworkManager.h>
-
-// Backwards compatibility: with the switch to libnm, NM_STATE_CONNECTED is no
-// longer defined. NM_STATE_CONNECTED_GLOBAL appeared with NM 0.9 and was aliased
-#ifndef NM_STATE_CONNECTED
- #define NM_STATE_CONNECTED NM_STATE_CONNECTED_GLOBAL
-#endif
-
-class networkmanager_network_extension : public network_extension {
-public:
- networkmanager_network_extension() {
- this->conn = NULL;
- }
-
- ~networkmanager_network_extension() {
- if (this->conn) dbus_connection_close(this->conn);
- }
-
- bool changed() {
- // Make sure we have a valid connection with a proper match
- DBusConnection *conn = this->conn;
- if (!conn || !dbus_connection_get_is_connected(conn))
- {
- // If the connection was disconnected,
- // close it an clear the queue
- if (conn)
- {
- dbus_connection_close(conn);
- dbus_connection_read_write(conn, 0);
- for (DBusMessage *msg=NULL ; (msg = dbus_connection_pop_message(conn)) ; dbus_message_unref(msg)) {};
- }
-
- // Create a new connections
- conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
- this->conn = conn;
- if (!conn) return false;
-
- // If connection was successful, set it up
- dbus_connection_set_exit_on_disconnect(conn, false);
- dbus_bus_add_match(conn, "type='signal',interface='" NM_DBUS_INTERFACE "',member='StateChanged'", NULL);
- dbus_connection_flush(conn);
- }
-
- // We are guaranteed a connection,
- // so check for incoming messages
- bool changed = false;
- while (true)
- {
- DBusMessage *msg = NULL;
- uint32_t state;
-
- // Pull messages off the queue
- dbus_connection_read_write(conn, 0);
- if (!(msg = dbus_connection_pop_message(conn)))
- break;
-
- // If a message is the right type and value,
- // we'll reset the network
- if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))
- if (state == NM_STATE_CONNECTED)
- changed = true;
-
- dbus_message_unref(msg);
- }
-
- return changed;
- }
-
-private:
- DBusConnection *conn;
-};
-
-MM_MODULE_INIT_EZ(networkmanager_network_extension, true, NULL, NULL);
diff --git a/libproxy/modules/pacrunner_duktape.cpp b/libproxy/modules/pacrunner_duktape.cpp
deleted file mode 100644
index a32d946..0000000
--- a/libproxy/modules/pacrunner_duktape.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * libproxy - A library for proxy configuration
- * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
- * Copyright (C) 2021 Zhaofeng Li <hello@zhaofeng.li>
- *
- * 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 "../extension_pacrunner.hpp"
-#ifndef WIN32
-#include <unistd.h> // gethostname
-#endif
-
-using namespace libproxy;
-
-#include <duktape.h>
-#include "pacutils.h"
-
-static duk_ret_t dnsResolve(duk_context *ctx) {
- if (duk_get_top(ctx) != 1) {
- // Invalid number of arguments
- return 0;
- }
-
- // We do not need to free the string - It's managed by Duktape.
- const char *hostname = duk_get_string(ctx, 0);
- if (!hostname) {
- return 0;
- }
-
- // Look it up
- struct addrinfo *info;
- if (getaddrinfo(hostname, NULL, NULL, &info)) {
- return 0;
- }
-
- // Try for IPv4
- char tmp[INET6_ADDRSTRLEN+1];
- if (getnameinfo(info->ai_addr, info->ai_addrlen,
- tmp, INET6_ADDRSTRLEN+1,
- NULL, 0,
- NI_NUMERICHOST)) {
- freeaddrinfo(info);
- duk_push_null(ctx);
- return 1;
- }
- freeaddrinfo(info);
-
- // Create the return value
- duk_push_string(ctx, tmp);
- return 1;
-}
-
-static duk_ret_t myIpAddress(duk_context *ctx) {
- char hostname[1024];
- hostname[sizeof(hostname) - 1] = '\0';
-
- if (!gethostname(hostname, sizeof(hostname) - 1)) {
- duk_push_string(ctx, hostname);
- return dnsResolve(ctx);
- }
-
- return duk_error(ctx, DUK_ERR_ERROR, "Unable to find hostname!");
-}
-
-class duktape_pacrunner : public pacrunner {
-public:
- duktape_pacrunner(string pac, const url& pacurl) : pacrunner(pac, pacurl) {
-#ifdef WIN32
- // On windows, we need to initialize the winsock dll first.
- WSADATA WsaData;
- WSAStartup(MAKEWORD(2, 0), &WsaData);
-#endif
- this->ctx = duk_create_heap_default();
- if (!this->ctx) goto error;
- duk_push_c_function(this->ctx, dnsResolve, 1);
- duk_put_global_string(this->ctx, "dnsResolve");
-
- duk_push_c_function(this->ctx, myIpAddress, 1);
- duk_put_global_string(this->ctx, "myIpAddress");
-
- // Add other routines
- duk_push_string(this->ctx, JAVASCRIPT_ROUTINES);
- if (duk_peval_noresult(this->ctx)) {
- goto error;
- }
-
- // Add the PAC into the context
- duk_push_string(this->ctx, pac.c_str());
- if (duk_peval_noresult(this->ctx)) {
- goto error;
- }
-
- return;
- error:
- duk_destroy_heap(this->ctx);
- throw bad_alloc();
- }
-
- ~duktape_pacrunner() {
- duk_destroy_heap(this->ctx);
-#ifdef WIN32
- WSACleanup();
-#endif
- }
-
- string run(const url& url_) override {
- string url = url_.to_string();
- string host = url_.get_host();
-
- duk_get_global_string(this->ctx, "FindProxyForURL");
- duk_push_string(this->ctx, url.c_str());
- duk_push_string(this->ctx, host.c_str());
- duk_int_t result = duk_pcall(this->ctx, 2);
-
- if (result == 0) {
- // Success
- const char *proxy = duk_get_string(this->ctx, 0);
- if (!proxy) {
- duk_pop(this->ctx);
- return "";
- }
- string proxyString = string(proxy);
- duk_pop(this->ctx);
- return proxyString;
- } else {
- // Something happened. The top of the stack is an error.
- duk_pop(this->ctx);
- return "";
- }
- }
-
-private:
- duk_context *ctx;
-};
-
-PX_PACRUNNER_MODULE_EZ(duktape, "duk_create_heap_default", "duktape");
diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
deleted file mode 100644
index 129d4b5..0000000
--- a/libproxy/modules/pacrunner_mozjs.cpp
+++ /dev/null
@@ -1,208 +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 <cstring> // ?
-#include <unistd.h> // gethostname
-
-#include "../extension_pacrunner.hpp"
-using namespace libproxy;
-
-// Work around a mozjs include bug
-#ifndef JS_HAS_FILE_OBJECT
-#define JS_HAS_FILE_OBJECT 0
-#endif
-#ifdef WIN32
-#ifndef XP_WIN
-#define XP_WIN
-#endif
-#endif
-#pragma GCC diagnostic ignored "-Winvalid-offsetof"
-#include <jsapi.h>
-#pragma GCC diagnostic error "-Winvalid-offsetof"
-#include <js/Initialization.h>
-#include <js/CallArgs.h>
-#include <js/CompilationAndEvaluation.h>
-#include <js/MemoryFunctions.h>
-#include <js/SourceText.h>
-
-#include "pacutils.h"
-
-#ifndef INET_ADDRSTRLEN
-#define INET_ADDRSTRLEN 16
-#endif
-
-#ifndef INET6_ADDRSTRLEN
-#define INET6_ADDRSTRLEN 46
-#endif
-
-static void dnsResolve_(JSContext *cx, JSString *hostname, JS::CallArgs *argv) {
- char *tmp;
- // Get hostname argument
- JS::RootedString str(cx, hostname);
- JS::UniqueChars chars = JS_EncodeStringToUTF8(cx, str);
- const char *val = chars.get();
-
- // Set the default return value
- argv->rval().setNull();
-
- // Look it up
- struct addrinfo *info = nullptr;
- if (getaddrinfo(val, NULL, NULL, &info))
- goto out;
-
- // Allocate the IP address
- tmp = (char *) JS_malloc(cx, INET6_ADDRSTRLEN+1);
- memset(tmp, 0, INET6_ADDRSTRLEN+1);
-
- // Try for IPv4 and IPv6
- if (getnameinfo(info->ai_addr, info->ai_addrlen,
- tmp, INET6_ADDRSTRLEN+1,
- NULL, 0,
- NI_NUMERICHOST)) goto out;
-
- // We succeeded
- argv->rval().setString(JS_NewStringCopyZ(cx, tmp));
- tmp = nullptr;
-
- out:
- if (info) freeaddrinfo(info);
-}
-
-static bool dnsResolve(JSContext *cx, unsigned argc, JS::Value *vp) {
- JS::CallArgs argv=JS::CallArgsFromVp(argc,vp);
- dnsResolve_(cx, argv[0].toString(), &argv);
- return true;
-}
-
-static bool myIpAddress(JSContext *cx, unsigned argc, JS::Value *vp) {
- JS::CallArgs argv=JS::CallArgsFromVp(argc,vp);
- char *hostname = (char *) JS_malloc(cx, 1024);
- hostname[1023] = '\0';
-
- if (!gethostname(hostname, 1023)) {
- JSString *myhost = JS_NewStringCopyN(cx, hostname, strlen(hostname));
- dnsResolve_(cx, myhost, &argv);
- } else {
- argv.rval().setNull();
- }
-
- JS_free(cx, hostname);
- return true;
-}
-
-// Setup Javascript global class
-// This MUST be a static global
-static JSClass cls = {
- "global", JSCLASS_GLOBAL_FLAGS,
-};
-
-class mozjs_pacrunner : public pacrunner {
-public:
- mozjs_pacrunner(const string &pac, const url& pacurl) : pacrunner(pac, pacurl) {
-
- // Set defaults
- this->jsctx = nullptr;
- JS_Init();
-
- // Initialize Javascript context
- if (!(this->jsctx = JS_NewContext(1024 * 1024))) goto error;
- {
- if (!JS::InitSelfHostedCode(this->jsctx)) goto error;
-
- JS::RootedValue rval(this->jsctx);
- JS::RealmOptions realm_opts;
-
- this->jsglb = new JS::Heap<JSObject*>(JS_NewGlobalObject(
- this->jsctx, &cls,
- nullptr, JS::DontFireOnNewGlobalHook,
- realm_opts));
-
- if (!(this->jsglb)) goto error;
- JS::RootedObject global(this->jsctx,this->jsglb->get());
- if (!(this->jsar = new JSAutoRealm(this->jsctx, global))) goto error;
-
- // Define Javascript functions
- JS_DefineFunction(this->jsctx, global, "dnsResolve", dnsResolve, 1, 0);
- JS_DefineFunction(this->jsctx, global, "myIpAddress", myIpAddress, 0, 0);
- JS::CompileOptions options(this->jsctx);
-
- JS::SourceText<mozilla::Utf8Unit> routines, pac_source;
- if (!routines.init(this->jsctx,
- JAVASCRIPT_ROUTINES,
- strlen(JAVASCRIPT_ROUTINES),
- JS::SourceOwnership::Borrowed))
- goto error;
-
- if (!pac_source.init(this->jsctx,
- pac.c_str(),
- pac.length(),
- JS::SourceOwnership::Borrowed))
- goto error;
-
-
- JS::Evaluate(this->jsctx, options, routines, JS::MutableHandleValue(&rval));
-
- // Add PAC to the environment
- JS::Evaluate(this->jsctx, options, pac_source, JS::MutableHandleValue(&rval));
- return;
- }
- error:
- if (this->jsctx) JS_DestroyContext(this->jsctx);
- throw bad_alloc();
- }
-
- ~mozjs_pacrunner() {
- if (this->jsar) delete this->jsar;
- if (this->jsglb) delete this->jsglb;
- if (this->jsctx) JS_DestroyContext(this->jsctx);
- JS_ShutDown();
- }
-
- string run(const url& url_) {
- // Build arguments to the FindProxyForURL() function
- string tmpurl(url_.to_string());
- string tmphost(url_.get_host());
- JS::AutoValueArray<2> args(this->jsctx);
- args[0].setString(JS_NewStringCopyZ(this->jsctx, tmpurl.c_str()));
- args[1].setString(JS_NewStringCopyZ(this->jsctx, tmphost.c_str()));
-
- // Find the proxy (call FindProxyForURL())
- JS::RootedValue rval(this->jsctx);
- JS::RootedObject global(this->jsctx,this->jsglb->get());
- bool result = JS_CallFunctionName(this->jsctx, global, "FindProxyForURL", args, &rval);
- if (!result) return "";
- if (!rval.isString())
- return "";
-
- JS::RootedString s(this->jsctx, rval.toString());
- JS::UniqueChars chars = JS_EncodeStringToUTF8(this->jsctx, s);
- const char *tmpanswer = chars.get();
- string answer = string(tmpanswer);
-
- if (answer == "undefined") return "";
- return answer;
- }
-
-private:
- JSContext *jsctx;
- JS::Heap<JSObject*> *jsglb;
- JSAutoRealm *jsar;
-};
-
-PX_PACRUNNER_MODULE_EZ(mozjs, "JS_DefineFunction", "mozjs");
diff --git a/libproxy/modules/pacrunner_natus.cpp b/libproxy/modules/pacrunner_natus.cpp
deleted file mode 100644
index e1dc6c1..0000000
--- a/libproxy/modules/pacrunner_natus.cpp
+++ /dev/null
@@ -1,114 +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 "../extension_pacrunner.hpp"
-#include <unistd.h> // gethostname
-using namespace libproxy;
-
-#define I_ACKNOWLEDGE_THAT_NATUS_IS_NOT_STABLE
-#include <natus/natus.h>
-#include "pacutils.h"
-
-using namespace natus;
-
-static Value dnsResolve(Value& ths, Value& fnc, vector<Value>& arg) {
- Value exc = checkArguments(ths, arg, "s");
- if (exc.isException()) return exc;
-
- // Look it up
- struct addrinfo *info;
- if (getaddrinfo(arg[0].toString().c_str(), NULL, NULL, &info))
- return NULL;
-
- // Try for IPv4
- char* tmp = new char[INET6_ADDRSTRLEN+1];
- if (getnameinfo(info->ai_addr, info->ai_addrlen,
- tmp, INET6_ADDRSTRLEN+1,
- NULL, 0,
- NI_NUMERICHOST)) {
- freeaddrinfo(info);
- delete[] tmp;
- return NULL;
- }
- freeaddrinfo(info);
-
- // Create the return value
- Value ret = ths.newString(tmp);
- delete[] tmp;
- return ret;
-}
-
-static Value myIpAddress(Value& ths, Value& fnc, vector<Value>& arg) {
- char hostname[1024];
- hostname[sizeof(hostname) - 1] = '\0';
-
- if (!gethostname(hostname, sizeof(hostname) - 1)) {
- vector<Value> dnsargs;
- dnsargs.push_back(ths.newString(hostname));
- return dnsResolve(ths, fnc, dnsargs);
- }
- return ths.newString("Unable to find hostname!").toException();
-}
-
-class natus_pacrunner : public pacrunner {
-public:
- natus_pacrunner(string pac, const url& pacurl) : pacrunner(pac, pacurl) {
- Value exc;
-
- // Create the basic context
- if (!eng.initialize()) goto error;
- glb = this->eng.newGlobal();
- if (glb.isException()) goto error;
-
- // Add dnsResolve into the context
- if (!glb.set("dnsResolve", glb.newFunction(dnsResolve))) goto error;
-
- // Add myIpAddress into the context
- if (!glb.set("myIpAddress", glb.newFunction(myIpAddress))) goto error;
-
- // Add all other routines into the context
- exc = glb.evaluate(JAVASCRIPT_ROUTINES);
- if (exc.isException()) goto error;
-
- // Add the PAC into the context
- exc = glb.evaluate(pac.c_str(), pacurl.to_string());
- if (exc.isException()) goto error;
- return;
-
- error:
- throw bad_alloc();
- }
-
- string run(const url& url_) {
- vector<Value> args;
- args.push_back(glb.newString(url_.to_string()));
- args.push_back(glb.newString(url_.get_host()));
-
- Value res = glb.call("FindProxyForURL", args);
- if (res.isString() && !res.isException())
- return res.toString();
- return "";
- }
-
-private:
- Engine eng;
- Value glb;
-};
-
-PX_PACRUNNER_MODULE_EZ(natus, "nt_engine_init", "natus");
diff --git a/libproxy/modules/pacrunner_webkit.cpp b/libproxy/modules/pacrunner_webkit.cpp
deleted file mode 100644
index d907806..0000000
--- a/libproxy/modules/pacrunner_webkit.cpp
+++ /dev/null
@@ -1,182 +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 "../extension_pacrunner.hpp"
-#include <unistd.h> // gethostname
-using namespace libproxy;
-
-#ifdef __APPLE__
-// JavaScriptCore.h requires CoreFoundation
-// This is only found on Mac OS X
-#include <JavaScriptCore/JavaScriptCore.h>
-#else
-#include <JavaScriptCore/JavaScript.h>
-#endif
-#include "pacutils.h"
-
-#ifndef INET_ADDRSTRLEN
-#define INET_ADDRSTRLEN 16
-#endif
-
-#ifndef INET6_ADDRSTRLEN
-#define INET6_ADDRSTRLEN 46
-#endif
-
-static char *jstr2str(JSStringRef str, bool release)
-{
- char *tmp = new char[JSStringGetMaximumUTF8CStringSize(str)+1];
- JSStringGetUTF8CString(str, tmp, JSStringGetMaximumUTF8CStringSize(str)+1);
- if (release) JSStringRelease(str);
- return tmp;
-}
-
-static JSValueRef dnsResolve(JSContextRef ctx, JSObjectRef /*func*/, JSObjectRef /*self*/, size_t argc, const JSValueRef argv[], JSValueRef* /*exception*/)
-{
- if (argc != 1) return NULL;
- if (!JSValueIsString(ctx, argv[0])) return NULL;
-
- // Get hostname argument
- char *tmp = jstr2str(JSValueToStringCopy(ctx, argv[0], NULL), true);
-
- // Look it up
- struct addrinfo *info;
- if (getaddrinfo(tmp, NULL, NULL, &info)) {
- if (tmp) delete[] tmp;
- return NULL;
- }
- delete[] tmp;
-
- // Try for IPv4
- tmp = new char[INET6_ADDRSTRLEN+1];
- if (getnameinfo(info->ai_addr, info->ai_addrlen,
- tmp, INET6_ADDRSTRLEN+1,
- NULL, 0,
- NI_NUMERICHOST)) {
- freeaddrinfo(info);
- delete[] tmp;
- return NULL;
- }
- freeaddrinfo(info);
-
- // Create the return value
- JSStringRef str = JSStringCreateWithUTF8CString(tmp);
- JSValueRef ret = JSValueMakeString(ctx, str);
- JSStringRelease(str);
- delete[] tmp;
-
- return ret;
-}
-
-static JSValueRef myIpAddress(JSContextRef ctx, JSObjectRef func, JSObjectRef self, size_t /*argc*/, const JSValueRef[] /*argv*/, JSValueRef* /*exception*/)
-{
- char hostname[1024];
- hostname[sizeof(hostname) - 1] = '\0';
-
- if (!gethostname(hostname, sizeof(hostname) - 1)) {
- JSStringRef str = JSStringCreateWithUTF8CString(hostname);
- JSValueRef val = JSValueMakeString(ctx, str);
- JSStringRelease(str);
- JSValueRef ip = dnsResolve(ctx, func, self, 1, &val, NULL);
- return ip;
- }
- return NULL;
-}
-
-class webkit_pacrunner : public pacrunner {
-public:
- ~webkit_pacrunner() {
- JSGarbageCollect(this->jsctx);
- JSGlobalContextRelease(this->jsctx);
- }
-
- webkit_pacrunner(string pac, const url& pacurl) : pacrunner(pac, pacurl) {
- JSStringRef str = NULL;
- JSObjectRef func = NULL;
-
- // Create the basic context
- if (!(this->jsctx = JSGlobalContextCreate(NULL))) goto error;
-
- // Add dnsResolve into the context
- str = JSStringCreateWithUTF8CString("dnsResolve");
- func = JSObjectMakeFunctionWithCallback(this->jsctx, str, dnsResolve);
- JSObjectSetProperty(this->jsctx, JSContextGetGlobalObject(this->jsctx), str, func, kJSPropertyAttributeNone, NULL);
- JSStringRelease(str);
-
- // Add myIpAddress into the context
- str = JSStringCreateWithUTF8CString("myIpAddress");
- func = JSObjectMakeFunctionWithCallback(this->jsctx, str, myIpAddress);
- JSObjectSetProperty(this->jsctx, JSContextGetGlobalObject(this->jsctx), str, func, kJSPropertyAttributeNone, NULL);
- JSStringRelease(str);
-
- // Add all other routines into the context
- str = JSStringCreateWithUTF8CString(JAVASCRIPT_ROUTINES);
- if (!JSCheckScriptSyntax(this->jsctx, str, NULL, 0, NULL)) goto error;
- JSEvaluateScript(this->jsctx, str, NULL, NULL, 1, NULL);
- JSStringRelease(str);
-
- // Add the PAC into the context
- str = JSStringCreateWithUTF8CString(pac.c_str());
- if (!JSCheckScriptSyntax(this->jsctx, str, NULL, 0, NULL)) goto error;
- JSEvaluateScript(this->jsctx, str, NULL, NULL, 1, NULL);
- JSStringRelease(str);
- return;
-
- error:
- if (str) JSStringRelease(str);
- if (this->jsctx) {
- JSGarbageCollect(this->jsctx);
- JSGlobalContextRelease(this->jsctx);
- }
- throw bad_alloc();
- }
-
- string run(const url& url_) {
- JSStringRef str = NULL;
- JSValueRef val = NULL;
- string tmp;
- char *retChar = NULL;
- string retStr = "";
-
- // Run the PAC
- tmp = string("FindProxyForURL(\"") + url_.to_string() + string("\", \"") + url_.get_host() + "\");";
- str = JSStringCreateWithUTF8CString(tmp.c_str());
- if (!str) throw bad_alloc();
- if (!JSCheckScriptSyntax(this->jsctx, str, NULL, 0, NULL)) goto error;
- if (!(val = JSEvaluateScript(this->jsctx, str, NULL, NULL, 1, NULL))) goto error;
- if (!JSValueIsString(this->jsctx, val)) goto error;
- JSStringRelease(str);
-
- // Convert the return value to a string
- retChar = jstr2str(JSValueToStringCopy(this->jsctx, val, NULL), true);
- if (retChar) {
- retStr = retChar;
- delete[] retChar;
- }
- return retStr;
-
- error:
- JSStringRelease(str);
- return "";
- }
-
-private:
- JSGlobalContextRef jsctx;
-};
-
-PX_PACRUNNER_MODULE_EZ(webkit, "JSObjectMakeFunctionWithCallback", "webkit");
diff --git a/libproxy/modules/pacutils.h b/libproxy/modules/pacutils.h
deleted file mode 100644
index 3826014..0000000
--- a/libproxy/modules/pacutils.h
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * The following Javascript code was taken from Mozilla (http://www.mozilla.org)
- * and is licensed according to the LGPLv2.1+. Below is the original copyright
- * header as contained in the source file (nsProxyAutoConfig.js)
- */
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Akhil Arora <akhil.arora@sun.com>
- * Tomi Leppikangas <Tomi.Leppikangas@oulu.fi>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#define JAVASCRIPT_ROUTINES \
-"function dnsDomainIs(host, domain) {\n" \
-" return (host.length >= domain.length &&\n" \
-" host.substring(host.length - domain.length) == domain);\n" \
-"}\n" \
-"function dnsDomainLevels(host) {\n" \
-" return host.split('.').length-1;\n" \
-"}\n" \
-"function convert_addr(ipchars) {\n" \
-" var bytes = ipchars.split('.');\n" \
-" var result = ((bytes[0] & 0xff) << 24) |\n" \
-" ((bytes[1] & 0xff) << 16) |\n" \
-" ((bytes[2] & 0xff) << 8) |\n" \
-" (bytes[3] & 0xff);\n" \
-" return result;\n" \
-"}\n" \
-"function isInNet(ipaddr, pattern, maskstr) {\n"\
-" var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(ipaddr);\n"\
-" if (test == null) {\n"\
-" ipaddr = dnsResolve(ipaddr);\n"\
-" if (ipaddr == null)\n"\
-" return false;\n"\
-" } else if (test[1] > 255 || test[2] > 255 || \n"\
-" test[3] > 255 || test[4] > 255) {\n"\
-" return false; // not an IP address\n"\
-" }\n"\
-" var host = convert_addr(ipaddr);\n"\
-" var pat = convert_addr(pattern);\n"\
-" var mask = convert_addr(maskstr);\n"\
-" return ((host & mask) == (pat & mask));\n"\
-" \n"\
-"}\n"\
-"function isPlainHostName(host) {\n" \
-" return (host.search('\\\\.') == -1);\n" \
-"}\n" \
-"function isResolvable(host) {\n" \
-" var ip = dnsResolve(host);\n" \
-" return (ip != null);\n" \
-"}\n" \
-"function localHostOrDomainIs(host, hostdom) {\n" \
-" if (isPlainHostName(host)) {\n" \
-" return (hostdom.search('/^' + host + '/') != -1);\n" \
-" }\n" \
-" else {\n" \
-" return (host == hostdom);\n" \
-" }\n" \
-"}\n" \
-"function shExpMatch(url, pattern) {\n" \
-" pattern = pattern.replace(/\\./g, '\\\\.');\n" \
-" pattern = pattern.replace(/\\*/g, '.*');\n" \
-" pattern = pattern.replace(/\\?/g, '.');\n" \
-" var newRe = new RegExp('^'+pattern+'$');\n" \
-" return newRe.test(url);\n" \
-"}\n" \
-"var wdays = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};\n" \
-"var months = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};\n"\
-"function weekdayRange() {\n" \
-" function getDay(weekday) {\n" \
-" if (weekday in wdays) {\n" \
-" return wdays[weekday];\n" \
-" }\n" \
-" return -1;\n" \
-" }\n" \
-" var date = new Date();\n" \
-" var argc = arguments.length;\n" \
-" var wday;\n" \
-" if (argc < 1)\n" \
-" return false;\n" \
-" if (arguments[argc - 1] == 'GMT') {\n" \
-" argc--;\n" \
-" wday = date.getUTCDay();\n" \
-" } else {\n" \
-" wday = date.getDay();\n" \
-" }\n" \
-" var wd1 = getDay(arguments[0]);\n" \
-" var wd2 = (argc == 2) ? getDay(arguments[1]) : wd1;\n" \
-" return (wd1 == -1 || wd2 == -1) ? false\n" \
-" : (wd1 <= wday && wday <= wd2);\n" \
-"}\n" \
-"function dateRange() {\n" \
-" function getMonth(name) {\n" \
-" if (name in months) {\n" \
-" return months[name];\n" \
-" }\n" \
-" return -1;\n" \
-" }\n" \
-" var date = new Date();\n" \
-" var argc = arguments.length;\n" \
-" if (argc < 1) {\n" \
-" return false;\n" \
-" }\n" \
-" var isGMT = (arguments[argc - 1] == 'GMT');\n" \
-" if (isGMT) {\n" \
-" argc--;\n" \
-" }\n" \
-" if (argc == 1) {\n" \
-" var tmp = parseInt(arguments[0]);\n" \
-" if (isNaN(tmp)) {\n" \
-" return ((isGMT ? date.getUTCMonth() : date.getMonth()) == getMonth(arguments[0]));\n" \
-" } else if (tmp < 32) {\n" \
-" return ((isGMT ? date.getUTCDate() : date.getDate()) == tmp);\n" \
-" } else {\n" \
-" return ((isGMT ? date.getUTCFullYear() : date.getFullYear()) == tmp);\n" \
-" }\n" \
-" }\n" \
-" var year = date.getFullYear();\n" \
-" var date1, date2;\n" \
-" date1 = new Date(year, 0, 1, 0, 0, 0);\n" \
-" date2 = new Date(year, 11, 31, 23, 59, 59);\n" \
-" var adjustMonth = false;\n" \
-" for (var i = 0; i < (argc >> 1); i++) {\n" \
-" var tmp = parseInt(arguments[i]);\n" \
-" if (isNaN(tmp)) {\n" \
-" var mon = getMonth(arguments[i]);\n" \
-" date1.setMonth(mon);\n" \
-" } else if (tmp < 32) {\n" \
-" adjustMonth = (argc <= 2);\n" \
-" date1.setDate(tmp);\n" \
-" } else {\n" \
-" date1.setFullYear(tmp);\n" \
-" }\n" \
-" }\n" \
-" for (var i = (argc >> 1); i < argc; i++) {\n" \
-" var tmp = parseInt(arguments[i]);\n" \
-" if (isNaN(tmp)) {\n" \
-" var mon = getMonth(arguments[i]);\n" \
-" date2.setMonth(mon);\n" \
-" } else if (tmp < 32) {\n" \
-" date2.setDate(tmp);\n" \
-" } else {\n" \
-" date2.setFullYear(tmp);\n" \
-" }\n" \
-" }\n" \
-" if (adjustMonth) {\n" \
-" date1.setMonth(date.getMonth());\n" \
-" date2.setMonth(date.getMonth());\n" \
-" }\n" \
-" if (isGMT) {\n" \
-" var tmp = date;\n" \
-" tmp.setFullYear(date.getUTCFullYear());\n" \
-" tmp.setMonth(date.getUTCMonth());\n" \
-" tmp.setDate(date.getUTCDate());\n" \
-" tmp.setHours(date.getUTCHours());\n" \
-" tmp.setMinutes(date.getUTCMinutes());\n" \
-" tmp.setSeconds(date.getUTCSeconds());\n" \
-" date = tmp;\n" \
-" }\n" \
-" return ((date1 <= date) && (date <= date2));\n" \
-"}\n" \
-"function timeRange() {\n" \
-" var argc = arguments.length;\n" \
-" var date = new Date();\n" \
-" var isGMT= false;\n" \
-" if (argc < 1) {\n" \
-" return false;\n" \
-" }\n" \
-" if (arguments[argc - 1] == 'GMT') {\n" \
-" isGMT = true;\n" \
-" argc--;\n" \
-" }\n" \
-" var hour = isGMT ? date.getUTCHours() : date.getHours();\n" \
-" var date1, date2;\n" \
-" date1 = new Date();\n" \
-" date2 = new Date();\n" \
-" if (argc == 1) {\n" \
-" return (hour == arguments[0]);\n" \
-" } else if (argc == 2) {\n" \
-" return ((arguments[0] <= hour) && (hour <= arguments[1]));\n" \
-" } else {\n" \
-" switch (argc) {\n" \
-" case 6:\n" \
-" date1.setSeconds(arguments[2]);\n" \
-" date2.setSeconds(arguments[5]);\n" \
-" case 4:\n" \
-" var middle = argc >> 1;\n" \
-" date1.setHours(arguments[0]);\n" \
-" date1.setMinutes(arguments[1]);\n" \
-" date2.setHours(arguments[middle]);\n" \
-" date2.setMinutes(arguments[middle + 1]);\n" \
-" if (middle == 2) {\n" \
-" date2.setSeconds(59);\n" \
-" }\n" \
-" break;\n" \
-" default:\n" \
-" throw 'timeRange: bad number of arguments'\n" \
-" }\n" \
-" }\n" \
-" if (isGMT) {\n" \
-" date.setFullYear(date.getUTCFullYear());\n" \
-" date.setMonth(date.getUTCMonth());\n" \
-" date.setDate(date.getUTCDate());\n" \
-" date.setHours(date.getUTCHours());\n" \
-" date.setMinutes(date.getUTCMinutes());\n" \
-" date.setSeconds(date.getUTCSeconds());\n" \
-" }\n" \
-" return ((date1 <= date) && (date <= date2));\n" \
-"}\n" \
-""
diff --git a/libproxy/modules/pxgconf.cpp b/libproxy/modules/pxgconf.cpp
deleted file mode 100644
index ff7890f..0000000
--- a/libproxy/modules/pxgconf.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-#include <cstdio>
-#include <unistd.h>
-#include <signal.h>
-#include <stdexcept>
-
-#include <glib.h>
-#include <gconf/gconf.h>
-#include <gconf/gconf-client.h>
-
-using namespace std;
-
-static GMainLoop* loop = NULL;
-
-static int print_value(const GConfValue *value, const char *suffix) {
- int count = 0;
- GSList* cursor = NULL;
-
- if (!value) return 0;
-
- switch (value->type) {
- case GCONF_VALUE_STRING:
- return printf("%s%s", gconf_value_get_string(value), suffix);
- case GCONF_VALUE_INT:
- return printf("%d%s", gconf_value_get_int(value), suffix);
- case GCONF_VALUE_FLOAT:
- return printf("%f%s", gconf_value_get_float(value), suffix);
- case GCONF_VALUE_BOOL:
- if (gconf_value_get_bool(value))
- return printf("true%s", suffix);
- return printf("false%s", suffix);
- case GCONF_VALUE_LIST:
- cursor = gconf_value_get_list(value);
- if (g_slist_length (cursor) == 0)
- count += printf("%s", suffix);
- else for ( ; cursor ; cursor = g_slist_next(cursor))
- count += print_value((const GConfValue *) cursor->data, cursor->next ? "," : suffix);
- return count;
- case GCONF_VALUE_PAIR:
- return print_value(gconf_value_get_car(value), ",") +
- print_value(gconf_value_get_cdr(value), suffix);
- default:
- throw exception();
- }
-
-
- return 0;
-}
-
-static void on_value_change(GConfClient* /*client*/, guint /*cnxn_id*/, GConfEntry* entry, void* /*user_data*/) {
- printf("%s\t", gconf_entry_get_key(entry));
- print_value(gconf_entry_get_value(entry), "\n");
-}
-
-static void on_sig(int /*signal*/) {
- g_main_loop_quit(loop);
-}
-
-static gboolean err(GIOChannel* /*source*/, GIOCondition /*condition*/, gpointer /*data*/) {
- g_main_loop_quit(loop);
- return false;
-}
-
-static gboolean set_key(const char *key, const char *val) {
- gboolean error = false;
- GConfClient *client = gconf_client_get_default();
- GConfValue *value = gconf_client_get(client, key, NULL);
- GConfValueType type = value ? value->type : GCONF_VALUE_STRING;
- gconf_value_free(value);
-
- switch (type) {
- case GCONF_VALUE_STRING:
- error = !gconf_client_set_string(client, key, val, NULL);
- break;
- case GCONF_VALUE_INT:
- int ival;
- error = sscanf(val, "%d", &ival) != 1;
- error = error || !gconf_client_set_int(client, key, ival, NULL);
- break;
- case GCONF_VALUE_FLOAT:
- float fval;
- error = sscanf(val, "%f", &fval) != 1;
- error = error || !gconf_client_set_float(client, key, fval, NULL);
- break;
- case GCONF_VALUE_BOOL:
- error = !gconf_client_set_float(client, key, !g_strcmp0(val, "true"), NULL);
- break;
- case GCONF_VALUE_LIST:
- case GCONF_VALUE_PAIR:
- default:
- g_critical("Invalid value type!");
- error = true;
- }
-
- g_object_unref(client);
- return !error;
-}
-
-static gboolean in(GIOChannel *source, GIOCondition condition, gpointer data) {
- gchar *key, *val;
- GIOStatus st = g_io_channel_read_line(source, &key, NULL, NULL, NULL);
-
- // Remove the trailing '\n'
- for (int i=0 ; key && key[i] ; i++)
- if (key[i] == '\n')
- key[i] = '\0';
-
- // If we were successful
- if (key && st == G_IO_STATUS_NORMAL) {
- if (!g_strrstr(key, "\t"))
- goto exit;
-
- val = g_strrstr(key, "\t") + 1;
- *(val-1) = '\0';
-
- if (!set_key(key, val))
- goto exit;
-
- g_free(key);
- return true;
- }
- else if (key && st == G_IO_STATUS_AGAIN) {
- g_free(key);
- return in(source, condition, data);
- }
-
-exit:
- g_free(key);
- return err(source, condition, data);
-}
-
-int main(int argc, char **argv) {
- if (argc < 2) return 1;
-
- // Register sighup handler
- if (signal(SIGHUP, on_sig) == SIG_ERR || signal(SIGPIPE, on_sig) == SIG_ERR || signal(SIGABRT, on_sig) == SIG_ERR) {
- fprintf(stderr, "Unable to trap signals!");
- return 2;
- }
-
- // Switch stdout to line buffering
- if (setvbuf(stdout, NULL, _IOLBF, 0)) {
- fprintf(stderr, "Unable to switch stdout to line buffering!");
- return 3;
- }
-
- // Switch stdin to line buffering
- if (setvbuf(stdin, NULL, _IOLBF, 0)) {
- fprintf(stderr, "Unable to switch stdin to line buffering!");
- return 4;
- }
-
- // Init
- g_type_init();
-
- // Get the main loop
- loop = g_main_loop_new(NULL, false);
-
- // Setup our GIO Channels
- GIOChannel* inchan = g_io_channel_unix_new(fileno(stdin));
- GIOChannel* outchan = g_io_channel_unix_new(fileno(stdout));
- g_io_add_watch(inchan, G_IO_IN, in, NULL);
- g_io_add_watch(inchan, G_IO_PRI, in, NULL);
- g_io_add_watch(inchan, G_IO_ERR, err, NULL);
- g_io_add_watch(inchan, G_IO_HUP, err, NULL);
- g_io_add_watch(outchan, G_IO_ERR, err, NULL);
- g_io_add_watch(outchan, G_IO_HUP, err, NULL);
-
- // Get GConf client
- GConfClient* client = gconf_client_get_default();
-
- // Add server notifications for all keys
- for (int i=1 ; i < argc ; i++) {
- GConfValue *value;
- gconf_client_add_dir(client, argv[i], GCONF_CLIENT_PRELOAD_NONE, NULL);
- gconf_client_notify_add(client, argv[i], on_value_change, NULL, NULL, NULL);
- value = gconf_client_get(client, argv[i], NULL);
- if (value) {
- gconf_value_free (value);
- gconf_client_notify(client, argv[i]);
- } else {
- printf("%s\n", argv[i]);
- }
- }
-
- g_main_loop_run(loop);
-
- // Cleanup
- g_object_unref(client);
- g_io_channel_shutdown(inchan, FALSE, NULL);
- g_io_channel_shutdown(outchan, FALSE, NULL);
- g_io_channel_unref(inchan);
- g_io_channel_unref(outchan);
- g_main_loop_unref(loop);
-}
diff --git a/libproxy/modules/pxgsettings.cpp b/libproxy/modules/pxgsettings.cpp
deleted file mode 100644
index 2e693ad..0000000
--- a/libproxy/modules/pxgsettings.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-/*******************************************************************************
- * pxgsettings - A helper binary to query gsettings
- * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
- * Copyright (C) 2011 Dominique Leuenberger <dominique@leuenberger.net>
- *
- * 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 <cstdio>
-#include <unistd.h>
-#include <signal.h>
-#include <stdexcept>
-
-#include <glib.h>
-#include <glib-object.h>
-#include <gio/gio.h>
-
-using namespace std;
-
-static GMainLoop* loop = NULL;
-
-static int print_value(GVariant *value, const char *suffix) {
-
- if (!value) return 0;
- if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
- return printf("%s%s", g_variant_get_string(value, NULL), suffix);
- }
- else if(g_variant_is_of_type(value, G_VARIANT_TYPE_INT32)) {
- return printf("%d%s", g_variant_get_int32(value), suffix);
- }
- else if(g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
- gboolean result;
- result = g_variant_get_boolean(value);
- return printf("%s%s", result ? "true" : "false", suffix);
- }
- else if(g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
- int count;
- const gchar** items;
- items = g_variant_get_strv(value, NULL);
- for (count=0; items[count]; count++) {
- printf("%s%s", count < 1 ? "" : ",", items[count]);
- }
- printf("%s", suffix);
- return count;
- }
- else {
- throw exception();
- }
-
- return 0;
-}
-
-static void on_value_change(GSettings *settings, const gchar *key, gpointer user_data) {
- printf("%s/%s\t", (gchar *)user_data, key);
- print_value(g_settings_get_value(settings, key), "\n");
-}
-
-static void on_sig(int /*signal*/) {
- g_main_loop_quit(loop);
-}
-
-static gboolean err(GIOChannel* /*source*/, GIOCondition /*condition*/, gpointer /*data*/) {
- g_main_loop_quit(loop);
- return false;
-}
-
-static gboolean in(GIOChannel *source, GIOCondition condition, gpointer data) {
- gchar *key, *val;
- GIOStatus st = g_io_channel_read_line(source, &key, NULL, NULL, NULL);
-
- // Remove the trailing '\n'
- for (int i=0 ; key && key[i] ; i++)
- if (key[i] == '\n')
- key[i] = '\0';
-
- // If we were successful
- if (key && st == G_IO_STATUS_NORMAL) {
- if (!g_strrstr(key, "\t"))
- goto exit;
-
- val = g_strrstr(key, "\t") + 1;
- *(val-1) = '\0';
-
- g_free(key);
- return true;
- }
- else if (key && st == G_IO_STATUS_AGAIN) {
- g_free(key);
- return in(source, condition, data);
- }
-
-exit:
- g_free(key);
- return err(source, condition, data);
-}
-
-int main(int argc, char **argv) {
- if (argc < 2) return 1;
-
- // Register sighup handler
- if (signal(SIGHUP, on_sig) == SIG_ERR || signal(SIGPIPE, on_sig) == SIG_ERR || signal(SIGABRT, on_sig) == SIG_ERR) {
- fprintf(stderr, "Unable to trap signals!");
- return 2;
- }
-
- // Switch stdout to line buffering
- if (setvbuf(stdout, NULL, _IOLBF, 0)) {
- fprintf(stderr, "Unable to switch stdout to line buffering!");
- return 3;
- }
-
- // Switch stdin to line buffering
- if (setvbuf(stdin, NULL, _IOLBF, 0)) {
- fprintf(stderr, "Unable to switch stdin to line buffering!");
- return 4;
- }
-
- // Init
-#if !GLIB_CHECK_VERSION(2,36,0)
- g_type_init();
-#endif
-
- // Get the main loop
- loop = g_main_loop_new(NULL, false);
-
- // Setup our GIO Channels
- GIOChannel* inchan = g_io_channel_unix_new(fileno(stdin));
- GIOChannel* outchan = g_io_channel_unix_new(fileno(stdout));
- g_io_add_watch(inchan, G_IO_IN, in, NULL);
- g_io_add_watch(inchan, G_IO_PRI, in, NULL);
- g_io_add_watch(inchan, G_IO_ERR, err, NULL);
- g_io_add_watch(inchan, G_IO_HUP, err, NULL);
- g_io_add_watch(outchan, G_IO_ERR, err, NULL);
- g_io_add_watch(outchan, G_IO_HUP, err, NULL);
-
- // Get GSettings obkecy
- GSettings* settings;
-
- for (int i=1; i<argc; i++) {
- settings = g_settings_new(argv[i]);
-#if GLIB_CHECK_VERSION(2,46,0)
- GSettingsSchema *schema;
- g_object_get (settings, "settings-schema", &schema, NULL);
- gchar** keys = g_settings_schema_list_keys(schema);
- g_settings_schema_unref(schema);
-#else
- gchar** keys = g_settings_list_keys(settings);
-#endif
- g_signal_connect(settings, "changed", G_CALLBACK (on_value_change), argv[i]);
- for (int j=0; keys[j]; on_value_change(settings, keys[j++],argv[i] ));
- g_strfreev(keys);
- }
-
- // A blank line indicates the end of the initial values
- printf("\n");
-
- g_main_loop_run(loop);
-
- // Cleanup
- g_object_unref(settings);
- g_io_channel_shutdown(inchan, FALSE, NULL);
- g_io_channel_shutdown(outchan, FALSE, NULL);
- g_io_channel_unref(inchan);
- g_io_channel_unref(outchan);
- g_main_loop_unref(loop);
-}
diff --git a/libproxy/modules/wpad_dns_alias.cpp b/libproxy/modules/wpad_dns_alias.cpp
deleted file mode 100644
index 5b8c2e0..0000000
--- a/libproxy/modules/wpad_dns_alias.cpp
+++ /dev/null
@@ -1,54 +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 "../extension_wpad.hpp"
-using namespace libproxy;
-
-class dns_alias_wpad_extension : public wpad_extension {
-public:
- dns_alias_wpad_extension() : lasturl(NULL), lastpac(NULL) { }
- bool found() { return lastpac != NULL; }
-
- void rewind() {
- if (lasturl) delete lasturl;
- if (lastpac) delete lastpac;
- lasturl = NULL;
- lastpac = NULL;
- }
-
- url* next(char** pac) {
- if (lasturl) return NULL;
-
- lasturl = new url("http://wpad/wpad.dat");
- lastpac = *pac = lasturl->get_pac();
- if (!lastpac) {
- delete lasturl;
- lasturl = NULL;
- return NULL;
- }
-
- return lasturl;
- }
-
-private:
- url* lasturl;
- char* lastpac;
-};
-
-MM_MODULE_INIT_EZ(dns_alias_wpad_extension, true, NULL, NULL);