Index: cmake/mingw32.cmake =================================================================== --- cmake/mingw32.cmake (revision 753) +++ cmake/mingw32.cmake (revision 797) @@ -15,3 +15,5 @@ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +# We want libgcc being statically linked. Everything else is annoying +set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc") Index: cmake/paths.cmk =================================================================== --- cmake/paths.cmk (revision 753) +++ cmake/paths.cmk (revision 797) @@ -1,11 +1,11 @@ if(WIN32) set(CMAKE_INSTALL_PREFIX "" CACHE PATH "Install prefix") - set(BIN_INSTALL_DIR "" CACHE PATH "Binary install dir") - set(LIB_INSTALL_DIR "" CACHE PATH "Library install dir") - set(LIBEXEC_INSTALL_DIR "" CACHE PATH "Private executable install dir") + set(BIN_INSTALL_DIR . CACHE PATH "Binary install dir") + set(LIB_INSTALL_DIR . CACHE PATH "Library install dir") + set(LIBEXEC_INSTALL_DIR . CACHE PATH "Private executable install dir") set(INCLUDE_INSTALL_DIR include CACHE PATH "Include install dir") - set(SYSCONF_INSTALL_DIR "" CACHE PATH "Configuration install dir") - set(SHARE_INSTALL_DIR "" CACHE PATH "Data install dir") + set(SYSCONF_INSTALL_DIR . CACHE PATH "Configuration install dir") + set(SHARE_INSTALL_DIR . CACHE PATH "Data install dir") else(WIN32) set(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Install prefix") set(BIN_INSTALL_DIR bin CACHE PATH "Binary install dir") Index: bindings/ruby/Libproxy.i =================================================================== --- bindings/ruby/Libproxy.i (revision 753) +++ bindings/ruby/Libproxy.i (revision 797) @@ -4,7 +4,6 @@ #include "../../libproxy/proxy.h" %} - %typemap(out) char ** { VALUE arr = rb_ary_new2(255); int i; @@ -15,7 +14,7 @@ } %typemap(freearg) char ** { - free($source); + free($source); } %include "../../libproxy/proxy.h" Index: bindings/ruby/test.rb =================================================================== --- bindings/ruby/test.rb (revision 753) +++ bindings/ruby/test.rb (revision 797) @@ -1,8 +1,7 @@ require 'Libproxy' pf = Libproxy.px_proxy_factory_new - proxies = Libproxy.px_proxy_factory_get_proxies(pf, "http://www.google.com") -print proxies - +proxies.each { |proxy| print proxy + " " } +print "\n" Index: bindings/python/CMakeLists.txt =================================================================== --- bindings/python/CMakeLists.txt (revision 753) +++ bindings/python/CMakeLists.txt (revision 797) @@ -12,21 +12,11 @@ message(STATUS "Found python version ${PYTHON_VERSION}") - if (IS_ABSOLUTE "${LIB_INSTALL_DIR}") - set(libdir "${LIB_INSTALL_DIR}") - else() - set(libdir "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") - endif() - - if (IS_DIRECTORY "${libdir}/python${PYTHON_VERSION}/site-packages") - set(PYTHON_SITEPKG_DIR "${libdir}/python${PYTHON_VERSION}/site-packages") - else() - execute_process(COMMAND - ${PYTHON_EXECUTABLE} - -c "import distutils.sysconfig ; print distutils.sysconfig.get_python_lib(plat_specific=0)" - OUTPUT_VARIABLE PYTHON_SITEPKG_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - endif() + execute_process(COMMAND + ${PYTHON_EXECUTABLE} + -c "import distutils.sysconfig ; print distutils.sysconfig.get_python_lib(plat_specific=0)" + OUTPUT_VARIABLE PYTHON_SITEPKG_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) endif() message(STATUS "Using PYTHON_SITEPKG_DIR=${PYTHON_SITEPKG_DIR}") Index: bindings/perl/src/CMakeLists.txt =================================================================== --- bindings/perl/src/CMakeLists.txt (revision 753) +++ bindings/perl/src/CMakeLists.txt (revision 797) @@ -1,5 +1,4 @@ include_directories( ${PERL_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/libproxy ) -link_directories(${LIBPROXY_LIBRARY_DIRS}) # Run doxsubpp.pl to run xsubpp on Libproxy.xs add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Libproxy.c @@ -10,9 +9,6 @@ set(Libproxy_LIB_SRCS Libproxy.c) -set(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER}) -set(CMAKE_C_FLAGS ${PERL_CXX_FLAGS} ) - set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/perl/blib/arch/auto/Net) add_library(PLlibproxy SHARED ${Libproxy_LIB_SRCS}) Index: utils/CMakeLists.txt =================================================================== --- utils/CMakeLists.txt (revision 753) +++ utils/CMakeLists.txt (revision 797) @@ -1,5 +1,4 @@ include_directories("../libproxy") -link_directories(${LIBPROXY_LIBRARY_DIRS}) add_executable(proxy proxy.c) target_link_libraries(proxy libproxy) Index: libmodman/test/main.hpp =================================================================== --- libmodman/test/main.hpp (revision 753) +++ libmodman/test/main.hpp (revision 797) @@ -20,6 +20,8 @@ #ifndef MAIN_HPP_ #define MAIN_HPP_ +#include + #include "../module_manager.hpp" using namespace std; Index: libmodman/module_manager.cpp =================================================================== --- libmodman/module_manager.cpp (revision 753) +++ libmodman/module_manager.cpp (revision 797) @@ -20,6 +20,7 @@ #include // For sort() #include // For stat() #include +#include #ifdef WIN32 #include @@ -42,7 +43,7 @@ #define pdlopenl(filename) LoadLibraryEx(filename, NULL, DONT_RESOLVE_DLL_REFERENCES) #define pdlclose(module) FreeLibrary((pdlmtype) module) static void* pdlsym(pdlmtype mod, string sym) { - return GetProcAddress(mod, sym.c_str()); + return (void *) GetProcAddress(mod, sym.c_str()); } static pdlmtype pdlreopen(const char* filename, pdlmtype module) { Index: libmodman/module.hpp =================================================================== --- libmodman/module.hpp (revision 753) +++ libmodman/module.hpp (revision 797) @@ -26,10 +26,9 @@ #define MM_MODULE_BUILTIN #endif -#ifdef WIN32 +#ifdef _MSC_VER #define __MM_DLL_EXPORT __declspec(dllexport) #else -#include #define __MM_DLL_EXPORT __attribute__ ((visibility("default"))) #endif @@ -79,10 +78,10 @@ template class __MM_DLL_EXPORT extension : public base_extension { public: -#ifdef WIN32 +#ifdef _MSC_VER static const char* base_type() { return __FUNCSIG__; } #else - static const char* base_type() { return typeid(basetype).name(); } + static const char* base_type() { return __PRETTY_FUNCTION__; } #endif static bool singleton() { return sngl; } @@ -96,7 +95,11 @@ struct __MM_DLL_EXPORT mm_module { - const unsigned int vers; +/* For some unknown reason, when vers is const VC++ (win32) NULLs out the whole struct. + * This obviously breaks module loading. I'd love to know the reason for this, so if + * anyone knows, please tell me. In the meantime, vers not being const is by design, + * so don't change it. */ + unsigned int vers; const char* name; const char* (*type)(); libmodman::base_extension** (*init)(); Index: libmodman/CMakeLists.txt =================================================================== --- libmodman/CMakeLists.txt (revision 753) +++ libmodman/CMakeLists.txt (revision 797) @@ -3,19 +3,17 @@ if (WIN32) add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) else(WIN32) - set(CMAKE_CXX_FLAGS "-fvisibility=hidden ${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "-fvisibility=hidden -fPIC ${CMAKE_CXX_FLAGS}") endif(WIN32) include_directories(${CMAKE_SOURCE_DIR}) -add_library(modman SHARED +add_library(modman STATIC module.hpp module_manager.hpp module_manager.cpp) if(NOT WIN32) target_link_libraries(modman dl) endif() -set_target_properties(modman PROPERTIES PREFIX "lib" VERSION 1.0.0 SOVERSION 1) -install(TARGETS modman DESTINATION ${LIB_INSTALL_DIR}) ### Tests add_testdirectory(test) Index: libproxy/test/url-test.cpp =================================================================== --- libproxy/test/url-test.cpp (revision 753) +++ libproxy/test/url-test.cpp (revision 797) @@ -59,6 +59,12 @@ { bool rtv = true; +#ifdef WIN32 + WSADATA wsadata; + WORD vers = MAKEWORD(2, 2); + WSAStartup(vers, &wsadata); +#endif + try_url ("file:///allo", rtv, "file", "", "", @@ -131,6 +137,17 @@ "", "", "", 0, "80"); + + /* Handle the case where there is nothing other than the scheme */ + try_url ("http://", rtv, + "http", + "", "", + "", 80, + ""); + +#ifdef WIN32 + WSACleanup(); +#endif return !rtv; } Index: libproxy/cmake/libproxy.cmk =================================================================== --- libproxy/cmake/libproxy.cmk (revision 753) +++ libproxy/cmake/libproxy.cmk (revision 797) @@ -18,5 +18,6 @@ set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/proxy.cpp PROPERTY COMPILE_DEFINITIONS MODULEDIR="${MODULEDIR}";BUILTIN_MODULES=${BUILTIN_MODULES}) set_target_properties(libproxy PROPERTIES PREFIX "" VERSION 1.0.0 SOVERSION 1) +set_target_properties(libproxy PROPERTIES LINK_INTERFACE_LIBRARIES "") install(TARGETS libproxy DESTINATION ${LIB_INSTALL_DIR}) install(FILES proxy.h DESTINATION ${INCLUDE_INSTALL_DIR}) Index: libproxy/cmake/modules.cmk =================================================================== --- libproxy/cmake/modules.cmk (revision 753) +++ libproxy/cmake/modules.cmk (revision 797) @@ -14,11 +14,12 @@ include(cmake/modules/config_macosx.cmk) include(cmake/modules/network_networkmanager.cmk) include(cmake/modules/pacrunner_mozjs.cmk) +include(cmake/modules/pacrunner_natus.cmk) include(cmake/modules/pacrunner_webkit.cmk) # Build the pacrunner into libproxy unless we are building for multiple engines set(BIPR 1) -if(MOZJS_FOUND AND WEBKIT_FOUND) +if((MOZJS_FOUND AND WEBKIT_FOUND) OR (MOZJS_FOUND AND NATUS_FOUND) OR (WEBKIT_FOUND AND NATUS_FOUND)) set(BIPR 0) endif() @@ -36,6 +37,7 @@ px_module(ignore_ip 1 1) px_module(network_networkmanager "${NM_FOUND}" 0 ${NM_LIBRARIES}) px_module(pacrunner_mozjs "${MOZJS_FOUND}" ${BIPR} ${MOZJS_LIBRARIES}) +px_module(pacrunner_natus "${NATUS_FOUND}" ${BIPR} ${NATUS_LIBRARIES}) px_module(pacrunner_webkit "${WEBKIT_FOUND}" ${BIPR} ${WEBKIT_LIBRARIES}) px_module(wpad_dns_alias 1 1) message("") Index: libproxy/cmake/modules/pacrunner_natus.cmk =================================================================== --- libproxy/cmake/modules/pacrunner_natus.cmk (revision 0) +++ libproxy/cmake/modules/pacrunner_natus.cmk (revision 797) @@ -0,0 +1,7 @@ +if(WIN32) + set(NATUS_FOUND 0) +elseif(APPLE) + set(NATUS_FOUND 0) +else() + px_check_modules(NATUS natus) +endif() \ No newline at end of file Index: libproxy/cmake/modules/pacrunner_mozjs.cmk =================================================================== --- libproxy/cmake/modules/pacrunner_mozjs.cmk (revision 753) +++ libproxy/cmake/modules/pacrunner_mozjs.cmk (revision 797) @@ -7,16 +7,19 @@ include_directories("${MOZJS_INCLUDE_DIR}") endif() elseif(NOT APPLE) - set(MOZJS_SEARCH_ORDER "xulrunner-js;firefox-js;mozilla-js;seamonkey-js" CACHE STRING "MozJS search order") + set(MOZJS_SEARCH_ORDER "mozilla-js;xulrunner-js;firefox-js;seamonkey-js" CACHE STRING "MozJS search order") option(WITH_MOZJS "Search for MOZJS package" ON) if (WITH_MOZJS) - pkg_search_module(MOZJS ${MOZJS_SEARCH_ORDER}) - if(MOZJS_FOUND) - include_directories(${MOZJS_INCLUDE_DIRS}) - link_directories(${MOZJS_LIBRARY_DIRS}) - else() - set(MOZJS_FOUND 0) - endif() + foreach(MOZJSLIB ${MOZJS_SEARCH_ORDER}) + pkg_search_module(MOZJS ${MOZJSLIB}>=2.0b12) + if(MOZJS_FOUND) + include_directories(${MOZJS_INCLUDE_DIRS}) + link_directories(${MOZJS_LIBRARY_DIRS}) + break() + else() + set(MOZJS_FOUND 0) + endif() + endforeach() else() set(MOZJS_FOUND 0) endif() Index: libproxy/cmake/modules/pacrunner_webkit.cmk =================================================================== --- libproxy/cmake/modules/pacrunner_webkit.cmk (revision 753) +++ libproxy/cmake/modules/pacrunner_webkit.cmk (revision 797) @@ -12,5 +12,9 @@ set(WEBKIT_FOUND 1) endif() else() - px_check_modules(WEBKIT webkit-1.0) -endif() \ No newline at end of file + if(WITH_WEBKIT3) + px_check_modules(WEBKIT webkitgtk-3.0) + else() + px_check_modules(WEBKIT webkit-1.0) + endif() +endif() Index: libproxy/url.cpp =================================================================== --- libproxy/url.cpp (revision 753) +++ libproxy/url.cpp (revision 797) @@ -36,12 +36,9 @@ #ifdef WIN32 #include -#define pfsize(st) (st.st_size) #define close _close #define read _read #define SHUT_RDWR SD_BOTH -#else -#define pfsize(st) (st.st_blksize * st.st_blocks) #endif #include "url.hpp" @@ -56,13 +53,6 @@ // This is the maximum pac size (to avoid memory attacks) #define PAC_MAX_SIZE 102400 -const string url::GENERIC_DELIMITERS(":/?#[]@"); -const string url::SUBCOMPONENT_DELIMITERS("!$&'()*+,;="); -const string url::ALLOWED_IN_USERINFO_ELEMENT(url::SUBCOMPONENT_DELIMITERS); -const string url::ALLOWED_IN_USERINFO(url::ALLOWED_IN_USERINFO_ELEMENT + ":"); -const string url::ALLOWED_IN_PATH_ELEMENT(url::SUBCOMPONENT_DELIMITERS + ":@"); -const string url::ALLOWED_IN_PATH(url::ALLOWED_IN_PATH_ELEMENT + "/"); - static inline int get_default_port(string scheme) { struct servent *serv; size_t plus = scheme.find('+'); @@ -109,8 +99,8 @@ string url::encode(const string &data, const string &valid_reserved) { ostringstream encoded; - for (int i=0; data[i]; i++) { - if (isalnum(data[i]) + for (unsigned int i=0; i < data.size(); i++) { + if (isalnum((unsigned char)data[i]) || valid_reserved.find(data[i]) != string::npos || string("-._~").find(data[i]) != string::npos) encoded << data[i]; @@ -211,7 +201,8 @@ host_start = userinfo_end + 1; /* Check for IPv6 IP */ - if (hier_part[host_start] == '[') { + if (host_start < hier_part.size() + && hier_part[host_start] == '[') { host_end = hier_part.find(']', host_start); if (host_end == string::npos) throw parse_error("Invalid URL: " + url); @@ -232,7 +223,7 @@ /* Get port */ m_port = get_default_port(m_scheme); - if (host_end != hier_part.size() + if (host_end < hier_part.size() && hier_part[host_end] == ':') { size_t port_start = host_end + 1; m_port = atoi(hier_part.c_str() + port_start); @@ -400,10 +391,12 @@ struct stat st; if ((sock = ::open(m_path.c_str(), O_RDONLY)) < 0) return NULL; - if (!fstat(sock, &st) && pfsize(st) < PAC_MAX_SIZE) { - buffer = new char[pfsize(st)+1]; - if (read(sock, buffer, pfsize(st)) == 0) { - delete buffer; + + if (!fstat(sock, &st) && st.st_size < PAC_MAX_SIZE) { + buffer = new char[st.st_size+1]; + memset(buffer, 0, st.st_size+1); + if (read(sock, buffer, st.st_size) == 0) { + delete[] buffer; buffer = NULL; } } @@ -435,7 +428,7 @@ if (sock < 0) return NULL; // Build the request string - request = "GET " + m_path + " HTTP/1.1\r\n"; + request = "GET " + (m_path.size() > 0 ? m_path : "/") + " HTTP/1.1\r\n"; request += "Host: " + m_host + "\r\n"; request += "Accept: " + string(PAC_MIME_TYPE) + "\r\n"; request += "Connection: close\r\n"; Index: libproxy/url.hpp =================================================================== --- libproxy/url.hpp (revision 753) +++ libproxy/url.hpp (revision 797) @@ -27,6 +27,13 @@ #include "config.hpp" +#define URL_GENERIC_DELIMITERS ":/?#[]@" +#define URL_SUBCOMPONENT_DELIMITERS "!$&'()*+,;=" +#define URL_ALLOWED_IN_USERINFO_ELEMENT URL_SUBCOMPONENT_DELIMITERS +#define URL_ALLOWED_IN_USERINFO URL_ALLOWED_IN_USERINFO_ELEMENT ":" +#define URL_ALLOWED_IN_PATH_ELEMENT URL_SUBCOMPONENT_DELIMITERS ":@" +#define URL_ALLOWED_IN_PATH URL_ALLOWED_IN_PATH_ELEMENT "/" + namespace libproxy { using namespace std; @@ -38,13 +45,6 @@ class DLL_PUBLIC url { public: - static const string ALLOWED_IN_PATH; - static const string ALLOWED_IN_PATH_ELEMENT; - static const string ALLOWED_IN_USERINFO; - static const string ALLOWED_IN_USERINFO_ELEMENT; - static const string GENERIC_DELIMITERS; - static const string SUBCOMPONENT_DELIMITERS; - static bool is_valid(const string url); static string encode(const string &data, const string &valid_reserved = ""); Index: libproxy/proxy.cpp =================================================================== --- libproxy/proxy.cpp (revision 753) +++ libproxy/proxy.cpp (revision 797) @@ -21,6 +21,7 @@ #include // For strdup() #include // For cerr #include // For exception +#include // Only for debug messages. #include @@ -164,7 +165,7 @@ proxy_factory::~proxy_factory() { lock(); - if (this->pac) delete this->pac; + if (this->pac) delete[] this->pac; if (this->pacurl) delete this->pacurl; unlock(); @@ -260,7 +261,7 @@ /* Check our ignore patterns */ ignores = this->mm.get_extensions(); - invign = confign[0] == '-'; + invign = confign.size() > 0 && confign[0] == '-'; if (invign) confign = confign.substr(1); for (size_t i=0 ; i < confign.size() && !ignored;) { size_t next = confign.find(',', i); Index: libproxy/modules/pacrunner_mozjs.cpp =================================================================== --- libproxy/modules/pacrunner_mozjs.cpp (revision 753) +++ libproxy/modules/pacrunner_mozjs.cpp (revision 797) @@ -42,12 +42,12 @@ #define INET6_ADDRSTRLEN 46 #endif -static JSBool dnsResolve(JSContext *cx, JSObject * /*obj*/, uintN /*argc*/, jsval *argv, jsval *rval) { +static JSBool dnsResolve_(JSContext *cx, jsval hostname, jsval *vp) { // Get hostname argument - char *tmp = JS_strdup(cx, JS_GetStringBytes(JS_ValueToString(cx, argv[0]))); + char *tmp = JS_EncodeString(cx, JS_ValueToString(cx, hostname)); // Set the default return value - *rval = JSVAL_NULL; + JS_SET_RVAL(cx, vp, JSVAL_NULL); // Look it up struct addrinfo *info = NULL; @@ -66,7 +66,7 @@ NI_NUMERICHOST)) goto out; // We succeeded - *rval = STRING_TO_JSVAL(JS_NewString(cx, tmp, strlen(tmp))); + JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(JS_NewStringCopyN(cx, tmp, strlen(tmp)))); tmp = NULL; out: @@ -75,15 +75,20 @@ return true; } -static JSBool myIpAddress(JSContext *cx, JSObject *obj, uintN /*argc*/, jsval * /*argv*/, jsval *rval) { +static JSBool dnsResolve(JSContext *cx, uintN /*argc*/, jsval *vp) { + jsval *argv = JS_ARGV(cx, vp); + return dnsResolve_(cx, argv[0], vp); +} + +static JSBool myIpAddress(JSContext *cx, uintN /*argc*/, jsval *vp) { char *hostname = (char *) JS_malloc(cx, 1024); if (!gethostname(hostname, 1023)) { - JSString *myhost = JS_NewString(cx, hostname, strlen(hostname)); + JSString *myhost = JS_NewStringCopyN(cx, hostname, strlen(hostname)); jsval arg = STRING_TO_JSVAL(myhost); - return dnsResolve(cx, obj, 1, &arg, rval); + return dnsResolve_(cx, 1, &arg); } JS_free(cx, hostname); - *rval = JSVAL_NULL; + JS_SET_RVAL(cx, vp, JSVAL_NULL); return true; } @@ -91,7 +96,7 @@ // This MUST be a static global static JSClass cls = { "global", JSCLASS_GLOBAL_FLAGS, - JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; @@ -111,7 +116,7 @@ //JS_SetOptions(this->jsctx, JSOPTION_VAROBJFIX); //JS_SetVersion(this->jsctx, JSVERSION_LATEST); //JS_SetErrorReporter(cx, reportError); - if (!(this->jsglb = JS_NewObject(this->jsctx, &cls, NULL, NULL))) goto error; + if (!(this->jsglb = JS_NewCompartmentAndGlobalObject(this->jsctx, &cls, NULL))) goto error; if (!JS_InitStandardClasses(this->jsctx, this->jsglb)) goto error; // Define Javascript functions @@ -147,15 +152,19 @@ throw bad_alloc(); } jsval args[2] = { - STRING_TO_JSVAL(JS_NewString(this->jsctx, tmpurl, strlen(tmpurl))), - STRING_TO_JSVAL(JS_NewString(this->jsctx, tmphost, strlen(tmphost))) + STRING_TO_JSVAL(JS_NewStringCopyN(this->jsctx, tmpurl, strlen(tmpurl))), + STRING_TO_JSVAL(JS_NewStringCopyN(this->jsctx, tmphost, strlen(tmphost))) }; // Find the proxy (call FindProxyForURL()) jsval rval; JSBool result = JS_CallFunctionName(this->jsctx, this->jsglb, "FindProxyForURL", 2, args, &rval); if (!result) return ""; - string answer = string(JS_GetStringBytes(JS_ValueToString(this->jsctx, rval))); + + char * tmpanswer = JS_EncodeString(this->jsctx, JS_ValueToString(this->jsctx, rval)); + string answer = string(tmpanswer); + JS_free(this->jsctx, tmpanswer); + if (answer == "undefined") return ""; return answer; } Index: libproxy/modules/pacrunner_natus.cpp =================================================================== --- libproxy/modules/pacrunner_natus.cpp (revision 0) +++ libproxy/modules/pacrunner_natus.cpp (revision 797) @@ -0,0 +1,111 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2006 Nathaniel McCallum + * + * 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" +using namespace libproxy; + +#define I_ACKNOWLEDGE_THAT_NATUS_IS_NOT_STABLE +#include +#include "pacutils.h" + +using namespace natus; + +static Value dnsResolve(Value& ths, Value& fnc, vector& 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& arg) { + char hostname[1024]; + if (!gethostname(hostname, 1023)) { + vector 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) throw (bad_alloc) : 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_) throw (bad_alloc) { + vector 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"); Index: libproxy/modules/config_gnome.cpp =================================================================== --- libproxy/modules/config_gnome.cpp (revision 753) +++ libproxy/modules/config_gnome.cpp (revision 797) @@ -102,10 +102,8 @@ if (dup2(rpipe[1], STDOUT_FILENO) != STDOUT_FILENO) _exit(2); // Close unneeded fds - close(rpipe[0]); - close(rpipe[1]); - close(wpipe[0]); - close(wpipe[1]); + for (int i = 3; i < sysconf(_SC_OPEN_MAX); i++) + close(i); // Exec execl("/bin/sh", "sh", "-c", program, (char*) NULL); @@ -194,8 +192,8 @@ else if (this->data[PROXY_MODE] == "manual") { string type, host, port; 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); + 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); bool same_proxy = this->data[PROXY_SAME_FOR_ALL] == "true"; // If socks is set use it (except when same_proxy is set) Index: NEWS =================================================================== --- NEWS (revision 753) +++ NEWS (revision 797) @@ -1,3 +1,14 @@ +New in version 0.4.7 +============================== +* Support/require xulrunner 2.0+ +* Support linking againgst libwebkit-gtk3 (-DWITH_WEBKIT3=ON) +* Issues closed: + - #149: always test for the right python noarch module path + - #155: Cannot compile with Firefox 4 + - #156: libproxy should build against webkitgtk-3.0 + - #158: Won't compile w/ xulrunner 2.0 final + - #159: libproxy fails with autoconfiguration "http://proxy.domain.com" + New in version 0.4.6 ============================== * Fixed a crash in the URL parser Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 753) +++ CMakeLists.txt (revision 797) @@ -24,6 +24,8 @@ include(cmake/ctest.cmk) include(cmake/paths.cmk) +option(WITH_WEBKIT3 "Build against gtk-3 version of webkitgtk" OFF) + ### Subdirectories # Conditionally build bundled libmodman option(FORCE_SYSTEM_LIBMODMAN "Force using system libmodman" OFF) @@ -44,8 +46,12 @@ endif() endif() +# Conditionally build bindings +if(NOT WIN32) + add_subdirectory(bindings) +endif() + # Always build these add_subdirectory(libproxy) -add_subdirectory(bindings) add_subdirectory(utils)