diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-05-02 10:53:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-02 10:53:36 +0200 |
commit | d159c5f40ff7e82354e45116d9b66b1f596d9320 (patch) | |
tree | 34506d9ee6c699444a170c6bba8c925c45407d3e | |
parent | 8fec01ed4b95afc71bf7710bf5b736a5de03b343 (diff) | |
parent | 5272fb3d114f0d012871380bd429546c73f0226d (diff) | |
download | libproxy-git-d159c5f40ff7e82354e45116d9b66b1f596d9320.tar.gz |
Merge pull request #201 from janbrummer/rewrite
Complete rewrite
203 files changed, 6449 insertions, 10530 deletions
diff --git a/.cproject b/.cproject deleted file mode 100644 index 7bf7857..0000000 --- a/.cproject +++ /dev/null @@ -1,1307 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<?fileVersion 4.0.0?> - -<cproject> -<storageModule moduleId="org.eclipse.cdt.core.settings"> -<cconfiguration id="org.eclipse.cdt.core.default.config.1"> -<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.1" moduleId="org.eclipse.cdt.core.settings" name="Configuration"> -<externalSettings/> -<extensions> -<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> -<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"> -<attribute key="addr2line" value="addr2line"/> -<attribute key="c++filt" value="c++filt"/> -</extension> -</extensions> -</storageModule> -<storageModule moduleId="org.eclipse.cdt.core.language.mapping"> -<project-mappings/> -</storageModule> -<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> -<storageModule moduleId="org.eclipse.cdt.core.pathentry"> -<pathentry excluding="**/CMakeFiles/" kind="out" path=""/> -<pathentry kind="mac" name="_POSIX_C_SOURCE" path="" value="1"/> -<pathentry kind="mac" name="_BSD_SOURCE" path="" value=""/> -<pathentry kind="mac" name="__STDC__" path="" value="1"/> -<pathentry kind="mac" name="__STDC_HOSTED__" path="" value="1"/> -<pathentry kind="mac" name="__GNUC__" path="" value="4"/> -<pathentry kind="mac" name="__GNUC_MINOR__" path="" value="4"/> -<pathentry kind="mac" name="__GNUC_PATCHLEVEL__" path="" value="2"/> -<pathentry kind="mac" name="__GNUC_RH_RELEASE__" path="" value="20"/> -<pathentry kind="mac" name="__SIZE_TYPE__" path="" value="long"/> -<pathentry kind="mac" name="unsigned" path="" value="int"/> -<pathentry kind="mac" name="__PTRDIFF_TYPE__" path="" value="long"/> -<pathentry kind="mac" name="int" path="" value="__WCHAR_TYPE__"/> -<pathentry kind="mac" name="__INTMAX_TYPE__" path="" value="long"/> -<pathentry kind="mac" name="long" path="" value="unsigned"/> -<pathentry kind="mac" name="short" path="" value="unsigned"/> -<pathentry kind="mac" name="__GXX_ABI_VERSION" path="" value="1002"/> -<pathentry kind="mac" name="__SCHAR_MAX__" path="" value="127"/> -<pathentry kind="mac" name="__SHRT_MAX__" path="" value="32767"/> -<pathentry kind="mac" name="__INT_MAX__" path="" value="2147483647"/> -<pathentry kind="mac" name="__LONG_MAX__" path="" value="9223372036854775807L"/> -<pathentry kind="mac" name="__LONG_LONG_MAX__" path="" value="9223372036854775807LL"/> -<pathentry kind="mac" name="__WCHAR_MAX__" path="" value="2147483647"/> -<pathentry kind="mac" name="__CHAR_BIT__" path="" value="8"/> -<pathentry kind="mac" name="__INTMAX_MAX__" path="" value="9223372036854775807L"/> -<pathentry kind="mac" name="__FLT_EVAL_METHOD__" path="" value="0"/> -<pathentry kind="mac" name="__DEC_EVAL_METHOD__" path="" value="2"/> -<pathentry kind="mac" name="__FLT_RADIX__" path="" value="2"/> -<pathentry kind="mac" name="__FLT_MANT_DIG__" path="" value="24"/> -<pathentry kind="mac" name="__FLT_DIG__" path="" value="6"/> -<pathentry kind="mac" name="__FLT_MIN_EXP__" path="" value="(-125)"/> -<pathentry kind="mac" name="__FLT_MIN_10_EXP__" path="" value="(-37)"/> -<pathentry kind="mac" name="__FLT_MAX_EXP__" path="" value="128"/> -<pathentry kind="mac" name="__FLT_MAX_10_EXP__" path="" value="38"/> -<pathentry kind="mac" name="__FLT_MAX__" path="" value="3.40282347e+38F"/> -<pathentry kind="mac" name="__FLT_MIN__" path="" value="1.17549435e-38F"/> -<pathentry kind="mac" name="__FLT_EPSILON__" path="" value="1.19209290e-7F"/> -<pathentry kind="mac" name="__FLT_DENORM_MIN__" path="" value="1.40129846e-45F"/> -<pathentry kind="mac" name="__FLT_HAS_DENORM__" path="" value="1"/> -<pathentry kind="mac" name="__FLT_HAS_INFINITY__" path="" value="1"/> -<pathentry kind="mac" name="__FLT_HAS_QUIET_NAN__" path="" value="1"/> -<pathentry kind="mac" name="__DBL_MANT_DIG__" path="" value="53"/> -<pathentry kind="mac" name="__DBL_DIG__" path="" value="15"/> -<pathentry kind="mac" name="__DBL_MIN_EXP__" path="" value="(-1021)"/> -<pathentry kind="mac" name="__DBL_MIN_10_EXP__" path="" value="(-307)"/> -<pathentry kind="mac" name="__DBL_MAX_EXP__" path="" value="1024"/> -<pathentry kind="mac" name="__DBL_MAX_10_EXP__" path="" value="308"/> -<pathentry kind="mac" name="__DBL_MAX__" path="" value="1.7976931348623157e+308"/> -<pathentry kind="mac" name="__DBL_MIN__" path="" value="2.2250738585072014e-308"/> -<pathentry kind="mac" name="__DBL_EPSILON__" path="" value="2.2204460492503131e-16"/> -<pathentry kind="mac" name="__DBL_DENORM_MIN__" path="" value="4.9406564584124654e-324"/> -<pathentry kind="mac" name="__DBL_HAS_DENORM__" path="" value="1"/> -<pathentry kind="mac" name="__DBL_HAS_INFINITY__" path="" value="1"/> -<pathentry kind="mac" name="__DBL_HAS_QUIET_NAN__" path="" value="1"/> -<pathentry kind="mac" name="__LDBL_MANT_DIG__" path="" value="64"/> -<pathentry kind="mac" name="__LDBL_DIG__" path="" value="18"/> -<pathentry kind="mac" name="__LDBL_MIN_EXP__" path="" value="(-16381)"/> -<pathentry kind="mac" name="__LDBL_MIN_10_EXP__" path="" value="(-4931)"/> -<pathentry kind="mac" name="__LDBL_MAX_EXP__" path="" value="16384"/> -<pathentry kind="mac" name="__LDBL_MAX_10_EXP__" path="" value="4932"/> -<pathentry kind="mac" name="__DECIMAL_DIG__" path="" value="21"/> -<pathentry kind="mac" name="__LDBL_MAX__" path="" value="1.18973149535723176502e+4932L"/> -<pathentry kind="mac" name="__LDBL_MIN__" path="" value="3.36210314311209350626e-4932L"/> -<pathentry kind="mac" name="__LDBL_EPSILON__" path="" value="1.08420217248550443401e-19L"/> -<pathentry kind="mac" name="__LDBL_DENORM_MIN__" path="" value="3.64519953188247460253e-4951L"/> -<pathentry kind="mac" name="__LDBL_HAS_DENORM__" path="" value="1"/> -<pathentry kind="mac" name="__LDBL_HAS_INFINITY__" path="" value="1"/> -<pathentry kind="mac" name="__LDBL_HAS_QUIET_NAN__" path="" value="1"/> -<pathentry kind="mac" name="__DEC32_MANT_DIG__" path="" value="7"/> -<pathentry kind="mac" name="__DEC32_MIN_EXP__" path="" value="(-94)"/> -<pathentry kind="mac" name="__DEC32_MAX_EXP__" path="" value="97"/> -<pathentry kind="mac" name="__DEC32_MIN__" path="" value="1E-95DF"/> -<pathentry kind="mac" name="__DEC32_MAX__" path="" value="9.999999E96DF"/> -<pathentry kind="mac" name="__DEC32_EPSILON__" path="" value="1E-6DF"/> -<pathentry kind="mac" name="__DEC32_SUBNORMAL_MIN__" path="" value="0.000001E-95DF"/> -<pathentry kind="mac" name="__DEC64_MANT_DIG__" path="" value="16"/> -<pathentry kind="mac" name="__DEC64_MIN_EXP__" path="" value="(-382)"/> -<pathentry kind="mac" name="__DEC64_MAX_EXP__" path="" value="385"/> -<pathentry kind="mac" name="__DEC64_MIN__" path="" value="1E-383DD"/> -<pathentry kind="mac" name="__DEC64_MAX__" path="" value="9.999999999999999E384DD"/> -<pathentry kind="mac" name="__DEC64_EPSILON__" path="" value="1E-15DD"/> -<pathentry kind="mac" name="__DEC64_SUBNORMAL_MIN__" path="" value="0.000000000000001E-383DD"/> -<pathentry kind="mac" name="__DEC128_MANT_DIG__" path="" value="34"/> -<pathentry kind="mac" name="__DEC128_MIN_EXP__" path="" value="(-6142)"/> -<pathentry kind="mac" name="__DEC128_MAX_EXP__" path="" value="6145"/> -<pathentry kind="mac" name="__DEC128_MIN__" path="" value="1E-6143DL"/> -<pathentry kind="mac" name="__DEC128_MAX__" path="" value="9.999999999999999999999999999999999E6144DL"/> -<pathentry kind="mac" name="__DEC128_EPSILON__" path="" value="1E-33DL"/> -<pathentry kind="mac" name="__DEC128_SUBNORMAL_MIN__" path="" value="0.000000000000000000000000000000001E-6143DL"/> -<pathentry kind="mac" name="__REGISTER_PREFIX__" path="" value=""/> -<pathentry kind="mac" name="__USER_LABEL_PREFIX__" path="" value=""/> -<pathentry kind="mac" name="__VERSION__" path="" value=""4.4.2"/> -<pathentry kind="mac" name="20091222" path="" value="(Red"/> -<pathentry kind="mac" name="Hat" path="" value="4.4.2-20)""/> -<pathentry kind="mac" name="__GNUC_GNU_INLINE__" path="" value="1"/> -<pathentry kind="mac" name="_LP64" path="" value="1"/> -<pathentry kind="mac" name="__LP64__" path="" value="1"/> -<pathentry kind="mac" name="__NO_INLINE__" path="" value="1"/> -<pathentry kind="mac" name="__FINITE_MATH_ONLY__" path="" value="0"/> -<pathentry kind="mac" name="__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1" path="" value="1"/> -<pathentry kind="mac" name="__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2" path="" value="1"/> -<pathentry kind="mac" name="__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4" path="" value="1"/> -<pathentry kind="mac" name="__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8" path="" value="1"/> -<pathentry kind="mac" name="__GCC_HAVE_DWARF2_CFI_ASM" path="" value="1"/> -<pathentry kind="mac" name="__SIZEOF_INT__" path="" value="4"/> -<pathentry kind="mac" name="__SIZEOF_LONG__" path="" value="8"/> -<pathentry kind="mac" name="__SIZEOF_LONG_LONG__" path="" value="8"/> -<pathentry kind="mac" name="__SIZEOF_SHORT__" path="" value="2"/> -<pathentry kind="mac" name="__SIZEOF_FLOAT__" path="" value="4"/> -<pathentry kind="mac" name="__SIZEOF_DOUBLE__" path="" value="8"/> -<pathentry kind="mac" name="__SIZEOF_LONG_DOUBLE__" path="" value="16"/> -<pathentry kind="mac" name="__SIZEOF_SIZE_T__" path="" value="8"/> -<pathentry kind="mac" name="__SIZEOF_WCHAR_T__" path="" value="4"/> -<pathentry kind="mac" name="__SIZEOF_WINT_T__" path="" value="4"/> -<pathentry kind="mac" name="__SIZEOF_PTRDIFF_T__" path="" value="8"/> -<pathentry kind="mac" name="__SIZEOF_POINTER__" path="" value="8"/> -<pathentry kind="mac" name="__amd64" path="" value="1"/> -<pathentry kind="mac" name="__amd64__" path="" value="1"/> -<pathentry kind="mac" name="__x86_64" path="" value="1"/> -<pathentry kind="mac" name="__x86_64__" path="" value="1"/> -<pathentry kind="mac" name="__k8" path="" value="1"/> -<pathentry kind="mac" name="__k8__" path="" value="1"/> -<pathentry kind="mac" name="__MMX__" path="" value="1"/> -<pathentry kind="mac" name="__SSE__" path="" value="1"/> -<pathentry kind="mac" name="__SSE2__" path="" value="1"/> -<pathentry kind="mac" name="__SSE_MATH__" path="" value="1"/> -<pathentry kind="mac" name="__SSE2_MATH__" path="" value="1"/> -<pathentry kind="mac" name="__gnu_linux__" path="" value="1"/> -<pathentry kind="mac" name="__linux" path="" value="1"/> -<pathentry kind="mac" name="__linux__" path="" value="1"/> -<pathentry kind="mac" name="linux" path="" value="1"/> -<pathentry kind="mac" name="__unix" path="" value="1"/> -<pathentry kind="mac" name="__unix__" path="" value="1"/> -<pathentry kind="mac" name="unix" path="" value="1"/> -<pathentry kind="mac" name="__ELF__" path="" value="1"/> -<pathentry kind="mac" name="__DECIMAL_BID_FORMAT__" path="" value="1"/> -<pathentry kind="mac" name="__BIGGEST_ALIGNMENT__" path="" value="16"/> -<pathentry kind="mac" name="__cplusplus" path="" value="1"/> -<pathentry kind="mac" name="__GNUG__" path="" value="4"/> -<pathentry kind="mac" name="__GXX_WEAK__" path="" value="1"/> -<pathentry kind="mac" name="__DEPRECATED" path="" value="1"/> -<pathentry kind="mac" name="__GXX_RTTI" path="" value="1"/> -<pathentry kind="mac" name="__EXCEPTIONS" path="" value="1"/> -<pathentry kind="mac" name="_GNU_SOURCE" path="" value="1"/> -<pathentry include="/home/nathaniel/Projects/libproxy" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/NetworkManager" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/dbus-1.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/lib64/dbus-1.0/include" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/webkit-1.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/glib-2.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/lib64/glib-2.0/include" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/gtk-2.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/libsoup-2.4" kind="inc" path="" system="true"/> -<pathentry include="/usr/lib64/gtk-2.0/include" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/atk-1.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/cairo" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/pango-1.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/pixman-1" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/freetype2" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/libpng12" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/libxml2" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/xulrunner-sdk-1.9.1/stable" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/xulrunner-sdk-1.9.1/js" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/nspr4" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/gconf/2" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/orbit-2.0" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/kde4" kind="inc" path="" system="true"/> -<pathentry include="/home/nathaniel/Projects/libproxy/libproxy" kind="inc" path="" system="true"/> -<pathentry include="/usr/local/include" kind="inc" path="" system="true"/> -<pathentry include="/usr/lib/gcc/x86_64-redhat-linux/4.4.2/include" kind="inc" path="" system="true"/> -<pathentry include="/usr/include" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/c++/4.4.2" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/c++/4.4.2/x86_64-redhat-linux" kind="inc" path="" system="true"/> -<pathentry include="/usr/include/c++/4.4.2/backward" kind="inc" path="" system="true"/> -</storageModule> -<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> -<buildTargets> -<target name=": install" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>install</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": install/local" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>install/local</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": install/strip" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>install/strip</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": list_install_components" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>list_install_components</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": rebuild_cache" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>rebuild_cache</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": test" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>test</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": all" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>all</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": clean" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>clean</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] libmodman" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] libmodman/fast" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": all" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>all</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": clean" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>clean</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] module_manager.cpp.o" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>module_manager.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] module_manager.cpp.i" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>module_manager.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] module_manager.cpp.s" path="libmodman" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>module_manager.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] condition" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>condition</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] condition/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>condition/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] condition_one" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>condition_one</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] condition_one/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>condition_one/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] condition_two" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>condition_two</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] condition_two/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>condition_two/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] singleton" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>singleton</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] singleton/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>singleton/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] singleton_one" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>singleton_one</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] singleton_one/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>singleton_one/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] singleton_two" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>singleton_two</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] singleton_two/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>singleton_two/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] sorted" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>sorted</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] sorted/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>sorted/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] sorted_one" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>sorted_one</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] sorted_one/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>sorted_one/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] sorted_two" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>sorted_two</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] sorted_two/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>sorted_two/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] symbol" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbol</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] symbol/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbol/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] symbol_one" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbol_one</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] symbol_one/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbol_one/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] symbol_two" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbol_two</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] symbol_two/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbol_two/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] symbollnk" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbollnk</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] symbollnk/fast" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>symbollnk/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": all" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>all</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": clean" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>clean</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/condition_one.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/condition_one.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/condition_one.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/condition_one.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/condition_one.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/condition_one.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/condition_two.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/condition_two.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/condition_two.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/condition_two.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/condition_two.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/condition_two.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/singleton_one.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/singleton_one.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/singleton_one.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/singleton_one.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/singleton_one.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/singleton_one.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/singleton_two.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/singleton_two.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/singleton_two.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/singleton_two.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/singleton_two.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/singleton_two.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/sorted_one.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/sorted_one.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/sorted_one.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/sorted_one.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/sorted_one.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/sorted_one.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/sorted_two.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/sorted_two.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/sorted_two.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/sorted_two.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/sorted_two.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/sorted_two.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/symbol_one.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/symbol_one.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/symbol_one.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/symbol_one.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/symbol_one.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/symbol_one.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] libmodman/test/symbol_two.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/symbol_two.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] libmodman/test/symbol_two.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/symbol_two.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] libmodman/test/symbol_two.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libmodman/test/symbol_two.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] main.cpp.o" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>main.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] main.cpp.i" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>main.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] main.cpp.s" path="libmodman/test" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>main.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] config_envvar" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>config_envvar</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] config_envvar/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>config_envvar/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] config_gnome" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>config_gnome</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] config_gnome/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>config_gnome/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] config_kde4" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>config_kde4</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] config_kde4/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>config_kde4/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] ignore_domain" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>ignore_domain</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] ignore_domain/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>ignore_domain/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] ignore_hostname" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>ignore_hostname</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] ignore_hostname/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>ignore_hostname/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] ignore_ip" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>ignore_ip</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] ignore_ip/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>ignore_ip/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] libproxy" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libproxy</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] libproxy/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>libproxy/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] network_networkmanager" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>network_networkmanager</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] network_networkmanager/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>network_networkmanager/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] pacrunner_mozjs" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>pacrunner_mozjs</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] pacrunner_mozjs/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>pacrunner_mozjs/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] pacrunner_webkit" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>pacrunner_webkit</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] pacrunner_webkit/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>pacrunner_webkit/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] pxgconf" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>pxgconf</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] pxgconf/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>pxgconf/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": uninstall" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>uninstall</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] wpad_dns_alias" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>wpad_dns_alias</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[lib] wpad_dns_alias/fast" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>wpad_dns_alias/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": all" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>all</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": clean" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>clean</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] extension_config.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_config.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] extension_config.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_config.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] extension_config.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_config.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] extension_pacrunner.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_pacrunner.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] extension_pacrunner.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_pacrunner.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] extension_pacrunner.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_pacrunner.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] extension_wpad.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_wpad.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] extension_wpad.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_wpad.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] extension_wpad.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>extension_wpad.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/config_envvar.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_envvar.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/config_envvar.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_envvar.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/config_envvar.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_envvar.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/config_gnome.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_gnome.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/config_gnome.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_gnome.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/config_gnome.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_gnome.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/config_kde4.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_kde4.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/config_kde4.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_kde4.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/config_kde4.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/config_kde4.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/ignore_domain.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_domain.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/ignore_domain.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_domain.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/ignore_domain.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_domain.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/ignore_hostname.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_hostname.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/ignore_hostname.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_hostname.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/ignore_hostname.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_hostname.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/ignore_ip.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_ip.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/ignore_ip.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_ip.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/ignore_ip.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/ignore_ip.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/network_networkmanager.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/network_networkmanager.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/network_networkmanager.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/network_networkmanager.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/network_networkmanager.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/network_networkmanager.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/pacrunner_mozjs.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pacrunner_mozjs.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/pacrunner_mozjs.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pacrunner_mozjs.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/pacrunner_mozjs.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pacrunner_mozjs.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/pacrunner_webkit.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pacrunner_webkit.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/pacrunner_webkit.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pacrunner_webkit.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/pacrunner_webkit.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pacrunner_webkit.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/pxgconf.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pxgconf.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/pxgconf.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pxgconf.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/pxgconf.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/pxgconf.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] modules/wpad_dns_alias.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/wpad_dns_alias.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] modules/wpad_dns_alias.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/wpad_dns_alias.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] modules/wpad_dns_alias.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>modules/wpad_dns_alias.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] proxy.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] proxy.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] proxy.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] url.cpp.o" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>url.cpp.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] url.cpp.i" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>url.cpp.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] url.cpp.s" path="libproxy" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>url.cpp.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": all" path="bindings" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>all</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": clean" path="bindings" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>clean</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] proxy" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[exe] proxy/fast" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy/fast</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": all" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>all</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name=": clean" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>clean</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[obj] proxy.c.o" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy.c.o</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[pre] proxy.c.i" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy.c.i</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -<target name="[to asm] proxy.c.s" path="utils" targetID="org.eclipse.cdt.make.MakeTargetBuilder"> -<buildCommand>/usr/bin/gmake</buildCommand> -<buildArguments/> -<buildTarget>proxy.c.s</buildTarget> -<stopOnError>true</stopOnError> -<useDefaultCommand>false</useDefaultCommand> -</target> -</buildTargets> -</storageModule> -<storageModule moduleId="scannerConfiguration"> -<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/> -<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"> -<buildOutputProvider> -<openAction enabled="true" filePath=""/> -<parser enabled="true"/> -</buildOutputProvider> -<scannerInfoProvider id="specsFile"> -<runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="/usr/lib64/ccache/gcc" useDefault="true"/> -<parser enabled="true"/> -</scannerInfoProvider> -</profile> -<profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"> -<buildOutputProvider> -<openAction enabled="true" filePath=""/> -<parser enabled="true"/> -</buildOutputProvider> -<scannerInfoProvider id="makefileGenerator"> -<runAction arguments="-f ${project_name}_scd.mk" command="/usr/bin/gmake" useDefault="true"/> -<parser enabled="true"/> -</scannerInfoProvider> -</profile> -</storageModule> -</cconfiguration> -</storageModule> -<storageModule moduleId="cdtBuildSystem" version="4.0.0"> -<project id="libproxy.null.1" name="libproxy"/> -</storageModule> -</cproject> diff --git a/.github/coverity.sh b/.github/coverity.sh new file mode 100755 index 0000000..80fa8c2 --- /dev/null +++ b/.github/coverity.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: LGPL-2.1-or-later + +set -eux + +COVERITY_SCAN_TOOL_BASE="/tmp/coverity-scan-analysis" +COVERITY_SCAN_PROJECT_NAME="libproxy" + +function coverity_install_script { + local platform tool_url tool_archive + + platform=$(uname) + tool_url="https://scan.coverity.com/download/${platform}" + tool_archive="/tmp/cov-analysis-${platform}.tgz" + + set +x # this is supposed to hide COVERITY_SCAN_TOKEN + echo -e "\033[33;1mDownloading Coverity Scan Analysis Tool...\033[0m" + wget -nv -O "$tool_archive" "$tool_url" --post-data "project=$COVERITY_SCAN_PROJECT_NAME&token=${COVERITY_SCAN_TOKEN:?}" + set -x + + mkdir -p "$COVERITY_SCAN_TOOL_BASE" + pushd "$COVERITY_SCAN_TOOL_BASE" + tar xzf "$tool_archive" + popd +} + +function run_coverity { + local results_dir tool_dir results_archive sha response status_code + + results_dir="cov-int" + tool_dir=$(find "$COVERITY_SCAN_TOOL_BASE" -type d -name 'cov-analysis*') + results_archive="analysis-results.tgz" + sha=$(git rev-parse --short HEAD) + + meson build + COVERITY_UNSUPPORTED=1 "$tool_dir/bin/cov-build" --dir "$results_dir" sh -c "ninja -C ./build -v" + "$tool_dir/bin/cov-import-scm" --dir "$results_dir" --scm git --log "$results_dir/scm_log.txt" + + tar czf "$results_archive" "$results_dir" + + set +x # this is supposed to hide COVERITY_SCAN_TOKEN + echo -e "\033[33;1mUploading Coverity Scan Analysis results...\033[0m" + response=$(curl \ + --silent --write-out "\n%{http_code}\n" \ + --form project="$COVERITY_SCAN_PROJECT_NAME" \ + --form token="${COVERITY_SCAN_TOKEN:?}" \ + --form email="${COVERITY_SCAN_NOTIFICATION_EMAIL:?}" \ + --form file="@$results_archive" \ + --form version="$sha" \ + --form description="Daily build" \ + https://scan.coverity.com/builds) + printf "\033[33;1mThe response is\033[0m\n%s\n" "$response" + status_code=$(echo "$response" | sed -n '$p') + if [ "$status_code" != "200" ]; then + echo -e "\033[33;1mCoverity Scan upload failed: $(echo "$response" | sed '$d').\033[0m" + return 1 + fi + set -x +} + +coverity_install_script +run_coverity diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f75c17f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,112 @@ +name: Build + +on: [push, pull_request] + +jobs: + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + sudo apt-get update + sudo apt install \ + libglib2.0-dev \ + libgirepository1.0-dev \ + duktape-dev \ + libsoup-3.0-dev \ + meson \ + gcovr \ + gi-docgen \ + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev \ + valac + - name: Build setup + run: meson setup build -Db_coverage=true + - name: Build + run: ninja -C build + - name: Tests and Coverage + run: | + ninja test -C build + ninja coverage -C build + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: ./build/docs/libproxy-1.0/ + - name: CodeCov + uses: codecov/codecov-action@v3 + + build-osx: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: | + 3.10 + - name: Setup + run: | + pip install meson ninja + brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen curl vala + echo 'PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/gi-docgen/lib/pkgconfig' >> $GITHUB_ENV + - name: Build and Test + run: | + meson setup build + ninja -C build + ninja -C build test + + build-windows: + runs-on: windows-latest + continue-on-error: true + defaults: + run: + shell: msys2 {0} + steps: + - uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + install: >- + base-devel + git + mingw-w64-x86_64-toolchain + mingw-w64-x86_64-ccache + mingw-w64-x86_64-pkg-config + mingw-w64-x86_64-gobject-introspection + mingw-w64-x86_64-python-gobject + mingw-w64-x86_64-meson + mingw-w64-x86_64-glib2 + mingw-w64-x86_64-duktape + mingw-w64-x86_64-gi-docgen + mingw-w64-x86_64-libsoup3 + mingw-w64-x86_64-curl + mingw-w64-x86_64-vala + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + - name: Build and Test + # Disable docs for the moment until msys2 gi-docgen update has landed + run: | + meson setup build -Ddocs=false + ninja -C build + ninja -C build test + + # Deploy job + deploy: + # needs: [build-linux, build-osx, build-windows] + needs: build-linux + if: github.ref == 'refs/heads/main' + + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 0000000..b3a9e9b --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,43 @@ +--- +# vi: ts=2 sw=2 et: +# SPDX-License-Identifier: LGPL-2.1-or-later +# +name: Coverity + +on: + workflow_dispatch: + schedule: + # Run Coverity daily at midnight + - cron: '0 0 * * *' + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-22.04 + if: github.repository == 'libproxy/libproxy' + env: + # Set in repo settings -> secrets -> actions + COVERITY_SCAN_TOKEN: "${{ secrets.COVERITY_SCAN_TOKEN }}" + COVERITY_SCAN_NOTIFICATION_EMAIL: "${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}" + steps: + - name: Repository checkout + uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b + - name: Ubuntu Setup + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt install \ + libglib2.0-dev \ + libgirepository1.0-dev \ + duktape-dev \ + libsoup-3.0-dev \ + meson \ + gcovr \ + gi-docgen \ + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev \ + valac + - name: Build & upload the results + run: .github/coverity.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9748355 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +# https://docs.github.com/en/actions + +name: "Release" + +on: # yamllint disable-line rule:truthy + push: + tags: + - "**" + +jobs: + release: + name: "Release" + + runs-on: "ubuntu-latest" + + steps: + - name: "Determine tag" + run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" + + - name: "Create release" + uses: "actions/github-script@v6" + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + try { + const response = await github.rest.repos.createRelease({ + draft: false, + generate_release_notes: true, + name: process.env.RELEASE_TAG, + owner: context.repo.owner, + prerelease: false, + repo: context.repo.repo, + tag_name: process.env.RELEASE_TAG, + }); + + core.exportVariable('RELEASE_ID', response.data.id); + core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url); + } catch (error) { + core.setFailed(error.message); + } @@ -1,23 +1,2 @@ -CMakeFiles -*.cmake -Makefile -CMakeCache.txt -*.swp -Temporary -*.tcl -*.so* -*.pm - -/bindings/perl/src/Libproxy.c -/libproxy-1.0.pc -/libproxy/pxgsettings -/libproxy/pxgconf -/libproxy/test/get-pac-test -/libproxy/test/url-test -/libproxy/test/url-encode -/utils/proxy - -# ignore Visual Studio 2019 Files -/.vs -/out -CMakeSettings.json
\ No newline at end of file +/_build/ +/build/ diff --git a/.project b/.project deleted file mode 100644 index 0cbd4af..0000000 --- a/.project +++ /dev/null @@ -1,111 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>libproxy@libproxy</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.cdt.make.core.makeBuilder</name> - <triggers>clean,full,incremental,</triggers> - <arguments> - <dictionary> - <key>org.eclipse.cdt.make.core.cleanBuildTarget</key> - <value>clean</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.enableCleanBuild</key> - <value>true</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.append_environment</key> - <value>true</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.stopOnError</key> - <value>true</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key> - <value>true</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.build.command</key> - <value>/usr/bin/gmake</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.contents</key> - <value>org.eclipse.cdt.make.core.activeConfigSettings</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.build.target.inc</key> - <value>all</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.build.arguments</key> - <value></value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.buildLocation</key> - <value>/home/nathaniel/Projects/libproxy</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key> - <value>false</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.environment</key> - <value>VERBOSE=1|</value> - <value></value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.enableFullBuild</key> - <value>true</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.build.target.auto</key> - <value>all</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.enableAutoBuild</key> - <value>false</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.build.target.clean</key> - <value>clean</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.fullBuildTarget</key> - <value>all</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.buildArguments</key> - <value></value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.build.location</key> - <value>/home/nathaniel/Projects/libproxy</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.make.core.autoBuildTarget</key> - <value>all</value> - </dictionary> - <dictionary> - <key>org.eclipse.cdt.core.errorOutputParser</key> - <value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;</value> - </dictionary> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.cdt.core.ccnature</nature> - <nature>org.eclipse.cdt.make.core.makeNature</nature> - <nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature> - <nature>org.eclipse.cdt.core.cnature</nature> - </natures> -</projectDescription> diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 67abba4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -language: cpp - -os: - - linux - - osx - -compiler: - - clang - - gcc - -matrix: - allow_failures: - - os: osx - -before_install: - - | - export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/pyenv/d' | tr "\n" ":" | sed "s|::|:|g") - # work-around for issue https://github.com/travis-ci/travis-ci/issues/6307 - # might not be necessary in the future - if [ "$TRAVIS_OS_NAME" == "osx" ]; then - command curl -sSL https://rvm.io/mpapis.asc | gpg --import - - rvm get stable - fi - -install: -# create /etc/sysconfig so that the build process enables this module (build test) - - | - if [[ "$TRAVIS_OS_NAME" = "linux" ]]; then - sudo mkdir /etc/sysconfig - sudo apt-get -qq update - sudo apt-get install -y libjavascriptcoregtk-3.0-dev - fi - -script: - - | - cmake . \ - -DWITH_PERL=ON \ - -DWITH_PYTHON2=ON \ - -DWITH_GNOME3=ON \ - -DWITH_KDE=ON \ - -DWITH_WEBKIT3=ON \ - -DWITH_MOZJS=ON \ - -DBIPR=0 - - make - - sudo make install - - make test diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index 7594699..0000000 --- a/AUTHORS +++ /dev/null @@ -1,5 +0,0 @@ -Nathaniel McCallum <nathaniel@natemccallum.com> -Alex Panait <kippled@gmail.com> -Dominique Leuenberger <dominique-libproxy@leuenberger.net> -Gonéri Le Bouder <goneri@rulezlan.org> - Perl bindings -Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5e79958 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,288 @@ +# Release Notes + +## [Unreleased] + +### Changed + +- Total rewrite in order to address current pain points: + - No documentation + - ABI crashes + - No tests + - No CI + - Missing async API + +## [0.4.18] + +### Changed + +- build: Allow configuration of sysconfig module +- config_envvar: Add environment variable for pacrunner debugging +- build: disable mozjs by default +- python: Support Python 3.10 and above +- Add Duktape pacrunner module +- config_kde: Compute list of config file locations ourselves +- cpmfog_gnome3: Add gnome-wayland to permitted DESKTOP_SESSION + +## [0.4.17] + +## Changed + +- python bindings: fix "TypeError: _argtypes_ must be a sequence of types" (#125) + +## [0.4.16] + +### Changed + +- Port to, and require, SpiderMonkey 68 +- Use closesocket() instead of close() on Windows +- Add symbol versions - be ready to introduce new APIs as needed +- Add public px_proxy_factory_free_proxies function +- Add PacRunner config backend (largely untested; feedback welcome!) +- Small performance improvements +- pxgsettings: use the correct syntax to connect to the changed signal (silences annoying output on console) +- Support python3 up to version 3.9 +- Fix buffer overflow when PAC is enabled (CVE-2020-26154) +- Rewrite url::recvline to be nonrecursive (CVE-2020-25219) +- Remove nonfunctional and crashy pacrunner caching +- Never use system libmodman (no other consumers, not maintained) + +## [0.4.15] + +### Changed + +- Port to, and require, SpiderMonkey 38. +- Fix "NetworkManager plugin not being built" (gh#libproxy/libproxy#53). +- Fix "networkmanager plugin not working (gh#libproxy/libproxy#58). +- Fix "Invalid read after free" (gh#libproxy/libproxy#59). +- Fix intermittent unit test failures. + +## [0.4.14] + +### Changed + +- Parallel build support for python2 and python3. + -DWITH_PYTHON has been replaced with -DWITH_PYTHON2 and + -DWITH_PYTHON3 to have full control over this. Default is + ON for both (issue#22) +- Minor fixes to the PAC retriever code (issue#40) +- Fallback to mcs instead of gmcs for the mono bindings (issue#37) +- Fix build using cmake 3.7 +- Fix deprecation warnings of pxgsettings with glib 2.46 +- Improve the get-pac test suite (issue#47) + +## [0.4.13] + +### Changed + +- Allow linking webkit pacrunner against javascriptcore-4.0 + (webkit2). +- Allow to disable building of the KDE module (-DWITH_KDE=ON/OFF). +- Fix compilation errors with CLang on MacOSX. +- bindings: perl: Add an option to explicitly link against libperl.so + Some distributions want to do it, other prefer not to, the library + is anyway in context of perl. +- config_kde: Add a basic cache and invalidation: performance improvement + for the KDE module. + +## [0.4.12] + +### Changed + +- Move development to github.com/libproxy/libproxy +- Fix fd leak in get_pac (Bug #185) +- Detect running MATE session (Bug #186, Part1). +- Fix linking of perl bindings to pthread (Bug #182) +- Correctly detect spidermonky (mozjs185) (Bug #188) +- Stop pxgsettings from segfaulting on exit (Bug #192) +- Fix test #10 (Bug #189) +- Fix build on Mac OS X (Bug #183) +- Add a generic KDE Config module (fix crashes of Qt5 based + apps) (issue#4) + +## [0.4.11] + +### Changed + +- Build fixes with cmake 2.8.10+ +- Quick release without built binaries / files (Address Bug #184) + +## [0.4.10] + +### Changed + +- Fix http chunk encoded PAC that was broken in previous release +- Add HTTP client unit test +- Fix more coding style issues + +## [0.4.9] + +### Changed + +- CVE-2012-4504 Fixed buffer overflow when downloading PAC +- Fix infinit loop uppon network errors + +## [0.4.8] + +### Changed + +- Only support standalone mozjs185 as mozilla js engine. + xulrunner being part of the now lightning fast moving firefox + is impossible to be tracked as a dependency and it is not + supported by Mozilla to be used in this scenario. +- Support building with javascritpcoregtk 1.5 + (got split out of webkitgtk). +- Support sending multiple results. +- Issues fixed: + - #166: Libproxy does not parse NO_PROXY correct when the line + contains spaces + - #164: If gconf's value is an empty list, pxgconf will make + /usr/bin/proxy wait forever + - #60: use lib js for embedded solutions + - #160: strdup and gethostbyname not declared on OSX 10.7 + - #168: .pc file should be installed under OSX as well. + - #170: Also check for "Transfer-Encoding: chunked". + - #171: mozjs pacrunner: Fix parameters of dnsResolve_() + - #172: Allow to forcibly build pacrunner as module (-DBIPR={ON,OFF}) + - #173: Libproxy doesn't build with gcc 4.7 + - #147: Use ${CMAKE_DL_LIBS} instead of assuming libdl is correct. + - #176: python bindings: guard the destructor. + - #177: Speed up importing of libproxy in python. + - #179: CMAKE 2.8.8 does not define PKG_CONFIG_FOUND + +## [0.4.7] + +### Changed + +- Support/require xulrunner 2.0+ +- Support linking againgst libwebkit-gtk3 (-DWITH_WEBKIT3=ON) +- Port to gsettings for gnome3. (-DWITH_GNOME3=ON[default]) +- 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" + - #131: GSettings-based GNOME plugin + - #150: SUSE sysconfig/proxy config support + +## [0.4.6] + +### Changed + +- Fixed a crash in the URL parser +- Fixed build issues with Visual Studio +- Updated the INSTALL file +- Install Python binding in prefix path if site-packages exists +- Fixed compilation with Visual Studio + + +## [0.4.5] + +### Changed + +- C# bindings are installable (-DWITH_DOTNET=ON) +- C# bindings installation path can be changed using -DGAC_DIR= +- Internal libmodman build fixed +- Installation dirs are now all relative to CMAKE_INSTALL_PREFIX +- Fixed test while using --as-needed linker flag +- Fixed generation of libproxy-1.0.pc +- Basic support for Mingw added (not yet 100% functional) +- Ruby binding implemented (not yet in the build system) +- Fixed modules not being found caused by relative LIBEXEC_INSTALL_DIR +- Fixed bug with builtin plugins (Issue 133) +- Vala bindings installation path can be changed using -DVAPI_DIR= +- Python bindings installation path can be changed using -DPYTHON_SITEPKG_DIR= +- Perl bindings can be installed in vendor directory (-DPERL_VENDORARCH=ON) +- Perl bindings installation path can be change using -DPX_PERL_ARCH= +- Unit test now builds on OSX + +## [0.4.4] + +### Changed + +- Add support for optionally building using a system libmodman +- Rework build system to be cleaner +- Fix two major build system bugs: 127, 128 + +## [0.4.3] + +### Changed + +- Test can now be out-compiled using BUILD_TESTING=OFF +- Fixed python binding not handling NULL pointer +- Pyhton binding now support Python version 3 +- Rewrote URL parser to comply with unit test +- Username and password are now URL encoded +- Scheme comparison is now non-case sensitive +- Fixed deadlock using WebKit has PAC runner +- Fixed OS X compilation of Perl bindings + +## [0.4.2] + +### Changed + +- Fixed python binding that failed on missing px_free symbole +- Workaround cmake bug with dynamic libraries in non-standard folders + +## [0.4.1] + +### Changed + +- Perl bindings have been integrated into the CMake Build System +- Vala bindings are installed if -DWITH_VALA=yes is passed to cmake +- All extensions can be disabled using WITH_*=OFF cmake options +- socks5:// and socks4:// can now be returned +- Many bugfixes + +## [0.4.0] + +### Changed + +- C++ rewrite +- Small API change (px_proxy_factory_get_proxy() can now return NULL) +- SOVERSION bump +- libmodman is now a seperate library +- Migrate to cmake +- Windows support (config_w32reg, ignore_hostname; VC++ support) +- MacOSX support (config_macosx, ignore_hostname) +- Built-in modules support +- Support for chunked encoding +- Move to hidden visibility by default +- KDE's KConfig symantics are fully supported +- Removeal of all PX_* env variables (no longer needed) +- Symbol based detection of relevant pacrunner +- Reworked config_gnome to not suck (its *much* faster) +- Many other things I can't remember + +## [0.3.1] + +### Changed + +- Bugfixes + + config file parser reads all sections + + KDE session detection based on environment varibales, + as suggested by KDE upstream. +- KDE configuration module is the first module in C++ and + now links to libkdecore4 in order to properly detect the + configuration folder for kde. +- At the moment we're not compatible with KDE3. Sorry. +- .NET bindings can now properly be installed and it should + be possible for packagers to provide them. + +## [0.3.0] + +### Changed + +- WARNING!!! Slight API change!!! see docs + for px_proxy_factory_get_proxies() +- Credentials support (see API change above) +- A complete rewrite of the module manager +- file:// as valid PAC URLs +- Sample Mono application +- Automake 1.11 shaved output +- gnome backend rewrite (now w/o thread issues) +- Test suite base functionality exists +- Many solaris build fixes +- Seamonkey support as JS pacrunner +- Bugfixes +- Compiles for MS Windows using Mingw diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 08f9170..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -### Required -cmake_minimum_required(VERSION 3.15) - -project(libproxy) - -if(POLICY CMP0011) - cmake_policy(SET CMP0011 NEW) -endif(POLICY CMP0011) -if(POLICY CMP0054) - cmake_policy(SET CMP0054 NEW) -endif(POLICY CMP0054) - -# Make sure we look in our cmake folder for additional definitions -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake ) - -### Make sure we have a build type -# This fixes an install issue where installs fail -# when find_package(KDE4) is present. I'm still -# not sure why this happens, but this definitely fixes -# it. It also fixes tests not running in this case. -# See issues 127 and 128. -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE RelWithDebInfo) - set(CMAKE_INSTALL_CONFIG_NAME RelWithDebInfo) -else() - set(CMAKE_INSTALL_CONFIG_NAME ${CMAKE_BUILD_TYPE}) -endif() - -include(cmake/cpack.cmk) -include(cmake/ctest.cmk) -include(cmake/paths.cmk) - -option(WITH_WEBKIT3 "Build against gtk-3 version of webkitgtk" OFF) -option(BUILD_SHARED_LIBS "Build using shared libraries" ON) - -if(WIN32) - option(MSVC_STATIC "Use statically-linked runtime library" ON) - if(MSVC_STATIC) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") - endif() -endif() - -### Subdirectories - -add_subdirectory(libmodman) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - -# Conditionally build bindings -if(NOT WIN32) - add_subdirectory(bindings) -endif() - -# Always build these -add_subdirectory(libproxy) -add_subdirectory(utils) - diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index 27cc851..0000000 --- a/ChangeLog +++ /dev/null @@ -1,162 +0,0 @@ -Wed Sep 1 16:03:00 2010 Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - * == Released 0.4.6 === - * Fixed a crash in the URL parser - * Fixed build issues with Visual Studio - * Updated the INSTALL file - * Install Python binding in prefix path if site-packages exists - * Fixed compilation with Visual Studio - * Complete list of bug fixes: - + 135, 136, 138 - -Mon Jun 7 11:37:00 2010 Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - * === Released 0.4.5 === - * C# bindings are installable (-DWITH_DOTNET=ON) - * C# bindings installation path can be changed using -DGAC_DIR= - * Internal libmodman build fixed - * Installation dirs are now all relative to CMAKE_INSTALL_PREFIX - * Fixed test while using --as-needed linker flag - * Fixed generation of libproxy-1.0.pc - * Basic support for Mingw added (not yet 100% functional) - * Ruby binding implemented (not yet in the build system) - * Fixed modules not being found caused by relative LIBEXEC_INSTALL_DIR - * Fixed bug with builtin plugins (Issue 133) - * Vala bindings installation path can be changed using -DVAPI_DIR= - * Python bindings installation path can be changed using -DPYTHON_SITEPKG_DIR= - * Perl bindings can be installed in vendor directory (-DPERL_VENDORARCH=ON) - * Perl bindings installation path can be change using -DPX_PERL_ARCH= - * Unit test now builds on OSX - * Complete list of bug fixes: - + 125, 126, 130, 132, 133 - -Sun Jun 13 11:00:00 2010 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.4.4 === - * Add support for optionally building using a system libmodman - * Rework build system to be cleaner - * Fix two major build system bugs: 127, 128 - -Mon Jun 7 11:37:00 2010 Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - * === Released 0.4.3 === - * Test can now be out-compiled using BUILD_TESTING=OFF - * Fixed python binding not handling NULL pointer - * Pyhton binding now support Python version 3 - * Implented URL unit test - * Rewrote URL parser to comply with unit test - * Username and password are now URL encoded - * Scheme comparison is now non-case sensitive - * Fixed deadlock using WebKit has PAC runner - * Fixed OS X compilation of Perl bindings - * Complete list of bug fixes: - + 123, 122, 121, 117, 116, 112, 109 - -Tue May 18 11:54:00 2010 Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - * === Released 0.4.2 === - * Fixed python binding that failed on missing px_free symbole - * Workaround cmake bug with dynamic libraries in non-standard folders - -Tue May 18 10:30:00 2010 Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - * === Released 0.4.1 === - * Improved cross-platform build - * Added Perl and Vala bindings - * Fix multiple infinite loop bugs - * Fix random crash with Gnome backend - * Standardized Gnome backend based on Mozilla and Chrome behavior - * Removed dependency to X11 in Gnome backend - * Allow disabling features at build time using WITH_* cmake options - * Module path can now be altered using PX_MODULE_PATH environment - * pxgconf helper location can be altered using PX_GCONF environment - * Removed proxy scheme filtering, we now trust config modules - * socks5:// and socks4:// is now allowed - * Fix crash when password is empty string - * Complete list of bug fixes: - + 19, 59, 65, 86, 87, 88, 89, 90, 91, 92, 93, 97, 98, - 99, 100, 101, 102, 103, 106, 108, 110 - * Known issues: - + 109 - Scheme comparison is case sensitive - + 112 - Username and password are not URI encoded - -Thu Feb 25 20:12:57 2010 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.4.0 === - * C++ rewrite - * Small API change (px_proxy_factory_get_proxy() can now return NULL) - * SOVERSION bump - * libmodman is now a seperate library - * Migrate to cmake - * Windows support (config_w32reg, ignore_hostname; VC++ support) - * MacOSX support (config_macosx, ignore_hostname) - * Built-in modules support - * Support for chunked encoding - * Move to hidden visibility by default - * KDE's KConfig symantics are fully supported - * Removeal of all PX_* env variables (no longer needed) - * Symbol based detection of relevant pacrunner - * Reworked config_gnome to not suck (its *much* faster) - * Many other things I can't remember - -Thu Oct 08 21:26:00 2009 Dominique Leuenberger <dominique@leuenberger.net> - * === Released 0.3.1 === - * Bugfixes - + config file parser reads all sections - + KDE session detection based on environment varibales, - as suggested by KDE upstream. - * KDE configuration module is the first module in C++ and - now links to libkdecore4 in order to properly detect the - configuration folder for kde. - * At the moment we're not compatible with KDE3. Sorry. - * .NET bindings can now properly be installed and it should - be possible for packagers to provide them. - -Thu Aug 14 15:38:00 2009 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.3.0 === - * WARNING!!! Slight API change (still ABI compat)!!! - see docs for px_proxy_factory_get_proxies() - * Credentials support (see API change above) - * A complete rewrite of the module manager - * file:// as valid PAC URLs - * Sample Mono application - * Automake 1.11 shaved output - * gnome backend rewrite (now w/o thread issues) - * Test suite base functionality exists - * Many solaris build fixes - * Seamonkey support as JS pacrunner - * Bugfixes - * Compiles for MS Windows using Mingw - -Thu Jun 05 17:05:12 2008 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.2.3 === - * New plugin: webkit (JavaScript) - * Massive speed improvements in all javascript plugins - * Bug fixes - * Memory leak fixes - * pkgconfig support - -Wed Jan 09 04:18:45 2008 Jeff Schroeder <jeffschroeder@computer.org> - * === Released 0.2.2 === - * Python bindings fix - * Added pthreads support from r191 in trunk - * Removed local copy of strdup() in proxy.c for OS X build issues - -Wed Dec 20 19:11:23 2007 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.2.1 === - * Build fix for mozjs - * Python bindings fix for renamed function - * Split off x_has_client() into its own file - -Wed Dec 12 20:12:56 2007 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.2 === - * Added Python bindings - * Added .NET bindings - * NetworkManager plugin - * KDE plugin - * File plugin - * More accurate GNOME session detection - * Ignore pattern support - * px_proxy_factory_get_proxy() renamed to px_proxy_factory_get_proxies() - * Relicense from LGPLv3+ to LGPLv2.1+ - * Sacrifice re-homeing session support for massive performance gains - * Tons of bug fixes, memory leaks, etc - -Wed Oct 31 13:09:10 2007 Nathaniel McCallum <nathaniel@natemccallum.com> - * === Released 0.1 === - * AUTHORS: Added authors - * README: basic readme info - * src/lib/proxy.h: add missing doc line diff --git a/INSTALL b/INSTALL deleted file mode 100644 index ab307f9..0000000 --- a/INSTALL +++ /dev/null @@ -1,158 +0,0 @@ - -Quick Start -########### - -From source directory -1. mkdir build -2. cd build -3. cmake .. -4. make -5. make install - -More advanced installation options: -################################### - -Example: - cmake .. - -DCMAKE_INSTALL_PREFIX=/usr - -DLIB_SUFIX=64 - -DWITH_VALA=yes - -DWITH_DOTNET=yes - -DPERL_VENDORINSTALL=yes - -DCMAKE_BUILD_TYPE=None - -DCMAKE_CXX_FLAGS="-O2" - -DCMAKE_C_FLAGS="-O2" - -This example would configure libproxy to be installed in /usr with all other -location using defaults relative to it, except that libraries will be install in -/usr/lib64. It also enable Vala and .NET bindings and tell the build system -to install the Perl binding in the vendor directory (the one used by -distribution, in contrast to the one used by users). - -Path options: -============= - -CMAKE_INSTALL_PREFIX: Default to "/usr/local". This is the base install - directory. All other path, except SYSCONF_INSTALL_DIR - are by default relative to this one. - -BIN_INSTALL_DIR: Default to "bin". This is where executable are install. - -LIB_INSTALL_DIR: Default to "lib${LIB_SUFFIX}". This is where libraries - are insalled. - -LIB_SUFFIX: Default to "". This is used on multilib 64bit OS where it - would be set to "64". - -LIBEXEC_INSTALL_DIR: Default to "libexec". This is where non-interactive helper - executable are installed (e.g. pxgconf for Gnome support). - -INCLUDE_INSTALL_DIR: Default to "include". This is where libproxy header is - installed (proxy.h). - -SYSCONF_INSTALL_DIR: Default to "/etc". This is the place where system wide - configuration files are placed, currently unused. Note - that this path does not have a relative path has default. - -SHARE_INSTALL_DIR: Default to "share". This base path used for CMake modules - finders and the Vala bindings. - -MODULE_INSTALL_DIR: Default to "${LIB_INSTALL_DIR}/${PROJECT_NAME}/${PROJECT_VERSION}/modules". - This is where libproxy extensions are installed. Note that - extentions API/ABI is not yet stable, so you should be - carefull when changing this path not to mix different - version of extensions together. The module path can also - be altered at runtime using PX_MODULE_PATH environement. - - -Boolean options: -================ - -BIPR: Default to ON. Build Internal Pac Runner. - If only one pacrunner is to be built, then the default - is to link it internal to libproxy. As soon as two are - to be built, they are always made as a module. - Setting this to OFF allows to build a pacrunner as - module even if only one is to be built. - -FORCE_SYSTEM_LIBMODMAN: Default to OFF. Forces the build system to generate an - error if libmodman cannot be found on your system. By - default libmodman will fallback to using internal copy - of that library. - -PERL_VENDORINSTALL: Default to OFF. Tells cmake to install the perl binding - in the vendor directory, which is the one used by most - packagers. - -PERL_LINK_LIBPERL: Default to ON if PERL_VENDORINSTALL is OFF, default to - OFF otherwise. Explicitly links the Perl binding - against libperl.so. It must be ON for linking to work - when --no-undefined is passed to the linker. - -WITH_DOTNET: Default to OFF. Enable Mono .NET bindings. - -WITH_GNOME2: Default to OFF. Enable Gnome2/GConf bindings. - -WITH_GNOME3: Default to ON. Build the Gnome3/GSettings bindings. - instead of Gnome2/GConf based one. - -WITH_KDE: Default to ON. Enables plug-in to read proxy settings - from either KDE4 or KDE Frameworks 5. - Note: this plug-in only has a *runtime* dependency on - either kreadconfig or kreadconfig5. - -WITH_MOZJS: Default to OFF. Enable Mozilla javascript bindings. As - Mozilla Javascript engine is often installed multiple - you can set prefered order using MOZJS_SEARCH_ORDER, - wich defaults to "xulrunner-js;firefox-js;mozilla-js;seamonkey-js". - -WITH_NM: Default to ON. Enable NetworkManager bindings. - -WITH_PERL: Default to ON. Enable Perl bindings. - -WITH_PYTHON2: Default to ON. Enable Python bindings. - -WITH_PYTHON3: Default to ON. Enable Python bindings. - -WITH_VALA: Default to OFF. Enable Vala bindings. - -WITH_WEBKIT: Default to ON. Enable Webkit Java Script engine. - -WITH_WEBKIT3: Default to OFF: Enable Webkit GTK3 support. - -WITH_DUKTAPE: Defaults to ON. Enable Duktape JavaScript engine. - -Bindings Path: -============== - -Most bindings require to be installed in a system specific directory. Libproxy -build system tries to find those directory. Sometimes this behaviour can be -annoying since bindings will not be installed relatively to CMAKE_INSTALL_PREFIX. -For this reason, all bindings provides path overrides. - -GAC_DIR: For the Mono .NET binding -VAPI_DIR: For the Vala bindings -PX_PERL_ARCH: For the Perl bindings -PYTHON_SITEPKG_DIR: For the Python bindings - - -Make options: -============= - -Of course you can use parallel build using "make -j2". It's also nice to see -the exact compile/link command being executed. This can be done using -"make VERBOSE=1" command. - -To install in a sub-directory, DESTDIR can be used has make parameter. - make install [DESTDIR=/any/prefix/to/prepend] - -CFLAGS in libproxy: -=================== - -We are currently having issue with CMake and CFLAGS. As shown in the example, -we have found a simple way that prevents CMAKE from choosing for you the -CFLAGS you want. As being demonstrated, you can disable CMAKE default CFLAGS -by setting an invalid (but not empty) CMAKE_BUILD_TYPE (e.g. None). You can -then set your flags using CMAKE_CXX_FLAGS, and CMAKE_C_FLAGS. Both variable -are required since libproxy contains C++ and C code. - @@ -1,233 +0,0 @@ -New in version 0.4.18: -============================== -* build: Allow configuration of sysconfig module -* config_envvar: Add environment variable for pacrunner debugging -* build: disable mozjs by default -* python: Support Python 3.10 and above -* Add Duktape pacrunner module -* config_kde: Compute list of config file locations ourselves -* cpmfog_gnome3: Add gnome-wayland to permitted DESKTOP_SESSION - -New in version 0.4.17: -============================== -* python bindings: fix "TypeError: _argtypes_ must be a sequence of types" (#125) - -New in version 0.4.16: -============================== -* Port to, and require, SpiderMonkey 68 -* Use closesocket() instead of close() on Windows -* Add symbol versions - be ready to introduce new APIs as needed -* Add public px_proxy_factory_free_proxies function -* Add PacRunner config backend (largely untested; feedback welcome!) -* Small performance improvements -* pxgsettings: use the correct syntax to connect to the changed signal (silences annoying output on console) -* Support python3 up to version 3.9 -* Fix buffer overflow when PAC is enabled (CVE-2020-26154) -* Rewrite url::recvline to be nonrecursive (CVE-2020-25219) -* Remove nonfunctional and crashy pacrunner caching -* Never use system libmodman (no other consumers, not maintained) - -New in Version 0.4.15: -============================== -* Port to, and require, SpiderMonkey 38. -* Fix "NetworkManager plugin not being built" (gh#libproxy/libproxy#53). -* Fix "networkmanager plugin not working (gh#libproxy/libproxy#58). -* Fix "Invalid read after free" (gh#libproxy/libproxy#59). -* Fix intermittent unit test failures. - -New in Version 0.4.14: -============================== -* Parallel build support for python2 and python3. - -DWITH_PYTHON has been replaced with -DWITH_PYTHON2 and - -DWITH_PYTHON3 to have full control over this. Default is - ON for both (issue#22) -* Minor fixes to the PAC retriever code (issue#40) -* Fallback to mcs instead of gmcs for the mono bindings (issue#37) -* Fix build using cmake 3.7 -* Fix deprecation warnings of pxgsettings with glib 2.46 -* Improve the get-pac test suite (issue#47) - -New in Version 0.4.13 -============================== -* Allow linking webkit pacrunner against javascriptcore-4.0 - (webkit2). -* Allow to disable building of the KDE module (-DWITH_KDE=ON/OFF). -* Fix compilation errors with CLang on MacOSX. -* bindings: perl: Add an option to explicitly link against libperl.so - Some distributions want to do it, other prefer not to, the library - is anyway in context of perl. -* config_kde: Add a basic cache and invalidation: performance improvement - for the KDE module. - -New in version 0.4.12 -============================== -* Move development to github.com/libproxy/libproxy -* Fix fd leak in get_pac (Bug #185) -* Detect running MATE session (Bug #186, Part1). -* Fix linking of perl bindings to pthread (Bug #182) -* Correctly detect spidermonky (mozjs185) (Bug #188) -* Stop pxgsettings from segfaulting on exit (Bug #192) -* Fix test #10 (Bug #189) -* Fix build on Mac OS X (Bug #183) -* Add a generic KDE Config module (fix crashes of Qt5 based - apps) (issue#4) - -New in version 0.4.11 -============================== -* Build fixes with cmake 2.8.10+ -* Quick release without built binaries / files (Address Bug #184) - -New in version 0.4.10 -============================== -* Fix http chunk encoded PAC that was broken in previous release -* Add HTTP client unit test -* Fix more coding style issues - -New in version 0.4.9 -============================== -* CVE-2012-4504 Fixed buffer overflow when downloading PAC -* Fix infinit loop uppon network errors - -New in version 0.4.8 -============================== -* Only support standalone mozjs185 as mozilla js engine. - xulrunner being part of the now lightning fast moving firefox - is impossible to be tracked as a dependency and it is not - supported by Mozilla to be used in this scenario. -* Support building with javascritpcoregtk 1.5 - (got split out of webkitgtk). -* Support sending multiple results. -* Issues fixed: - - #166: Libproxy does not parse NO_PROXY correct when the line - contains spaces - - #164: If gconf's value is an empty list, pxgconf will make - /usr/bin/proxy wait forever - - #60: use lib js for embedded solutions - - #160: strdup and gethostbyname not declared on OSX 10.7 - - #168: .pc file should be installed under OSX as well. - - #170: Also check for "Transfer-Encoding: chunked". - - #171: mozjs pacrunner: Fix parameters of dnsResolve_() - - #172: Allow to forcibly build pacrunner as module (-DBIPR={ON,OFF}) - - #173: Libproxy doesn't build with gcc 4.7 - - #147: Use ${CMAKE_DL_LIBS} instead of assuming libdl is correct. - - #176: python bindings: guard the destructor. - - #177: Speed up importing of libproxy in python. - - #179: CMAKE 2.8.8 does not define PKG_CONFIG_FOUND - -New in version 0.4.7 -============================== -* Support/require xulrunner 2.0+ -* Support linking againgst libwebkit-gtk3 (-DWITH_WEBKIT3=ON) -* Port to gsettings for gnome3. (-DWITH_GNOME3=ON[default]) -* 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" - - #131: GSettings-based GNOME plugin - - #150: SUSE sysconfig/proxy config support - -New in version 0.4.6 -============================== -* Fixed a crash in the URL parser -* Fixed build issues with Visual Studio -* Updated the INSTALL file -* Install Python binding in prefix path if site-packages exists -* Fixed compilation with Visual Studio - - -New in version 0.4.5 -=============================== -* C# bindings are installable (-DWITH_DOTNET=ON) -* C# bindings installation path can be changed using -DGAC_DIR= -* Internal libmodman build fixed -* Installation dirs are now all relative to CMAKE_INSTALL_PREFIX -* Fixed test while using --as-needed linker flag -* Fixed generation of libproxy-1.0.pc -* Basic support for Mingw added (not yet 100% functional) -* Ruby binding implemented (not yet in the build system) -* Fixed modules not being found caused by relative LIBEXEC_INSTALL_DIR -* Fixed bug with builtin plugins (Issue 133) -* Vala bindings installation path can be changed using -DVAPI_DIR= -* Python bindings installation path can be changed using -DPYTHON_SITEPKG_DIR= -* Perl bindings can be installed in vendor directory (-DPERL_VENDORARCH=ON) -* Perl bindings installation path can be change using -DPX_PERL_ARCH= -* Unit test now builds on OSX - -New in version 0.4.4 -=============================== -* Add support for optionally building using a system libmodman -* Rework build system to be cleaner -* Fix two major build system bugs: 127, 128 - -New in version 0.4.3 -=============================== -* Test can now be out-compiled using BUILD_TESTING=OFF -* Fixed python binding not handling NULL pointer -* Pyhton binding now support Python version 3 -* Rewrote URL parser to comply with unit test -* Username and password are now URL encoded -* Scheme comparison is now non-case sensitive -* Fixed deadlock using WebKit has PAC runner -* Fixed OS X compilation of Perl bindings - -New in version 0.4.2 -=============================== -* Fixed python binding that failed on missing px_free symbole -* Workaround cmake bug with dynamic libraries in non-standard folders - -New in version 0.4.1 -=============================== -* Perl bindings have been integrated into the CMake Build System -* Vala bindings are installed if -DWITH_VALA=yes is passed to cmake -* All extensions can be disabled using WITH_*=OFF cmake options -* socks5:// and socks4:// can now be returned -* Many bugfixes - -New in version 0.4.0 -=============================== -* C++ rewrite -* Small API change (px_proxy_factory_get_proxy() can now return NULL) -* SOVERSION bump -* libmodman is now a seperate library -* Migrate to cmake -* Windows support (config_w32reg, ignore_hostname; VC++ support) -* MacOSX support (config_macosx, ignore_hostname) -* Built-in modules support -* Support for chunked encoding -* Move to hidden visibility by default -* KDE's KConfig symantics are fully supported -* Removeal of all PX_* env variables (no longer needed) -* Symbol based detection of relevant pacrunner -* Reworked config_gnome to not suck (its *much* faster) -* Many other things I can't remember - -New in version 0.3.1 -==================== -- Bugfixes - + config file parser reads all sections - + KDE session detection based on environment varibales, - as suggested by KDE upstream. -- KDE configuration module is the first module in C++ and - now links to libkdecore4 in order to properly detect the - configuration folder for kde. -- At the moment we're not compatible with KDE3. Sorry. -- .NET bindings can now properly be installed and it should - be possible for packagers to provide them. - -New in version 0.3.0 -==================== -* WARNING!!! Slight API change!!! see docs - for px_proxy_factory_get_proxies() -* Credentials support (see API change above) -* A complete rewrite of the module manager -* file:// as valid PAC URLs -* Sample Mono application -* Automake 1.11 shaved output -* gnome backend rewrite (now w/o thread issues) -* Test suite base functionality exists -* Many solaris build fixes -* Seamonkey support as JS pacrunner -* Bugfixes -* Compiles for MS Windows using Mingw @@ -1,4 +0,0 @@ -Thanks for trying libproxy! - -To use libproxy in your application, check out the external API in the -proxy.h. diff --git a/README.md b/README.md new file mode 100644 index 0000000..768248a --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ + +[](https://app.codecov.io/github/libproxy/libproxy) +[](https://scan.coverity.com/projects/libproxy) + +# Libproxy +libproxy is a library that provides automatic proxy configuration management. + +## The Problem +Problem statement: Applications suck at correctly and consistently supporting proxy configuration. + +Proxy configuration is problematic for a number of reasons: + +- There are a variety of places to get configuration information +- There are a variety of proxy types +- Proxy auto-configuration (PAC) requires Javascript (which most applications don't have) +- Automatically determining PAC location requires an implementation of the WPAD protocol + +These issues make programming with support for proxies hard. Application developers only want to answer the question: Given a network resource, how do I reach it? Because this is their concern, most applications just give up and try to read the proxy from an environment variable. This is problematic because: + +- Given the increased use of mobile computing, network switching frequently occurs during the lifetime of an application +- Each application is required to implement the (non-trivial) WPAD and PAC protocols, including a Javascript engine +- It prevents a network administrator from locking down settings on a particular host or user +- In most cases, the environmental variable is almost never correct by default + +## The Solution +libproxy exists to answer the question: Given a network resource, how do I reach it? It handles all the details, enabling you to get back to programming. + +GNOME? KDE? Command line? WPAD? PAC? Network changed? +It doesn't matter! Just ask libproxy what proxy to use: you get simple code and your users get correct, consistant behavior and broad infrastructure compatibility. Why use libproxy? + +## libproxy offers the following features: +- support for all major platforms: Windows, Mac and Linux/UNIX +- extremely small core footprint +- minimal dependencies within libproxy core +- only 4 functions in the stable-ish external API +- dynamic adjustment to changing network topology +- a standard way of dealing with proxy settings across all scenarios +- a sublime sense of joy and accomplishment + +## Repology + +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) +[](https://repology.org/project/libproxy/versions) + diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index 2df3945..0000000 --- a/autogen.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -cmake ./ diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt deleted file mode 100644 index 2b0ede4..0000000 --- a/bindings/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -option(WITH_PYTHON2 "Enables Python 2 bindings" ON) -if (WITH_PYTHON2) - add_subdirectory(python/python2) -endif() - -option(WITH_PYTHON3 "Enables Python 3 bindings" ON) -if (WITH_PYTHON3) - add_subdirectory(python/python3) -endif() - -option(WITH_DOTNET "Enables C# bindings" OFF) -if (WITH_DOTNET) - add_subdirectory(csharp) -endif() - -#perl bindings live in their own subdir. -option(WITH_PERL "Enables Perl bindings" ON) -if (WITH_PERL) - add_subdirectory(perl) -endif() - -# Install Vala bindings / Install only when -DWITH_VALA is passed to cmake. -option(WITH_VALA "Enables Vala bindings" OFF) -if(WITH_VALA) - if (NOT VAPI_DIR) - set(VAPI_DIR ${SHARE_INSTALL_DIR}/vala/vapi) - endif() - install(FILES vala/libproxy-1.0.vapi DESTINATION ${VAPI_DIR}) - set(VAPI_DIR ${VAPI_DIR} CACHE PATH "Vala API directory") -endif() diff --git a/bindings/csharp/AssemblyInfo.cs b/bindings/csharp/AssemblyInfo.cs deleted file mode 100644 index 2baa161..0000000 --- a/bindings/csharp/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2008-2010 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 - ******************************************************************************/ - -using System; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly:AssemblyVersion("0.4.6")] -[assembly:AssemblyTitle ("LibProxy#")] -[assembly:AssemblyDescription ("A library that provides automatic proxy configuration management.")] -[assembly:AssemblyCopyright ("Copyright (c) 2006-2009 Nathaniel McCallum")] -[assembly:AssemblyCompany ("")] -[assembly:AssemblyDelaySign(false)] -[assembly:AssemblyKeyFile("libproxy.snk")] -[assembly:CLSCompliant(false)] - diff --git a/bindings/csharp/CMakeLists.txt b/bindings/csharp/CMakeLists.txt deleted file mode 100644 index d433fc6..0000000 --- a/bindings/csharp/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -PROJECT(libproxy-sharp) - -enable_language(CSharp) - -SET(KEYFILE ${CMAKE_CURRENT_SOURCE_DIR}/libproxy.snk) - -CSHARP_ADD_LIBRARY(libproxy-sharp libproxy.cs AssemblyInfo.cs COMPILE_FLAGS /warn:0 "/keyfile:${KEYFILE}") -SET_PROPERTY(TARGET libproxy-sharp PROPERTY pkg-config_template_basename libproxy-sharp-1.0) - -GET_LIBRARY_OUTPUT_DIR(library_target_dir) -FILE(WRITE ${library_target_dir}/libproxy-sharp.dll.config "<configuration><dllmap dll=\"proxy\" target=\"libproxy.so.1\"/></configuration>") - -INSTALL_ASSEMBLY(libproxy-sharp DESTINATION lib PACKAGE libproxy-sharp) - diff --git a/bindings/csharp/libproxy-sharp-1.0.pc.cmake b/bindings/csharp/libproxy-sharp-1.0.pc.cmake deleted file mode 100644 index 5e2f4a4..0000000 --- a/bindings/csharp/libproxy-sharp-1.0.pc.cmake +++ /dev/null @@ -1,5 +0,0 @@ - -Name: Libproxy# -Description: Libproxy# - .NET Binding to libproxy -Version: 0.4.6 -Libs: -r:@assembly@ diff --git a/bindings/csharp/libproxy.cs b/bindings/csharp/libproxy.cs deleted file mode 100644 index 4002e2a..0000000 --- a/bindings/csharp/libproxy.cs +++ /dev/null @@ -1,81 +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 - ******************************************************************************/ - -namespace libproxy { - using System; - using System.Runtime.InteropServices; - - public class ProxyFactory { - private HandleRef self; - - [DllImport ("proxy")] - private static extern - IntPtr px_proxy_factory_new(); - - [DllImport ("proxy")] - private static extern - IntPtr px_proxy_factory_get_proxies(HandleRef self, string url); - - [DllImport ("proxy")] - private static extern - void px_proxy_factory_free_proxies(IntPtr proxies); - - [DllImport ("proxy")] - private static extern - void px_proxy_factory_free(HandleRef self); - - public ProxyFactory() - { - this.self = new HandleRef(this, px_proxy_factory_new()); - } - - public string[] GetProxies(string url) - { - int count = 0; - - // Get the results - // TODO: If we call both this function and px_proxy_factory_free() - // this crashes, figure out why... - IntPtr array = px_proxy_factory_get_proxies(this.self, url); - - // Count the number of returned strings - while (Marshal.ReadIntPtr(array, count * IntPtr.Size) != IntPtr.Zero) count++; - - // Allocate a correctly sized array - string[] proxies = new string[count]; - - // Fill the response array - for (int i=0 ; i < count ; i++) - { - IntPtr p = Marshal.ReadIntPtr(array, i * IntPtr.Size); - proxies[i] = Marshal.PtrToStringAnsi(p); - } - - px_proxy_factory_free_proxies(array); - - return proxies; - } - - ~ProxyFactory() - { - // TODO: See note above... - px_proxy_factory_free(this.self); - } - } -} diff --git a/bindings/csharp/libproxy.snk b/bindings/csharp/libproxy.snk Binary files differdeleted file mode 100644 index 3dc1731..0000000 --- a/bindings/csharp/libproxy.snk +++ /dev/null diff --git a/bindings/perl/CMakeLists.txt b/bindings/perl/CMakeLists.txt deleted file mode 100644 index 368bc56..0000000 --- a/bindings/perl/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -find_package(Perl) -include (FindPerlLibs) - -if(PERL_FOUND AND PERLLIBS_FOUND) - - # Enable override of perl packge install directory. - set(PX_PERL_ARCH ${PX_PERL_ARCH} CACHE PATH "Install directory for Perl package.") - - if(NOT PX_PERL_ARCH) - # Some distributions install perl packages in vendor when shipped with the distro. - # Let's make their lifes easier by offering an install flag for this usecase. - option(PERL_VENDORINSTALL "Install Perl package in vendor directory" OFF) - - # Offer an option to explicitly link against libperl.so, with a default - # that depends on the value of the PERL_VENDORINSTALL option: if the - # binding is installed into a version-independent directory such as - # vendor_perl the chances of it needing a rebuild on each Perl update are - # lower. Note: not linking against libperl.so does not work if - # --no-undefined is passed to the linker. - if(PERL_VENDORINSTALL) - option(PERL_LINK_LIBPERL "Explicitly link against libperl.so" OFF) - else() - option(PERL_LINK_LIBPERL "Explicitly link against libperl.so" ON) - endif() - - if(PERL_VENDORINSTALL) - set (PX_PERL_ARCH ${PERL_VENDORARCH}) - set (PX_PERL_LIB ${PERL_VENDORLIB}) - else() - # PERL_SITEARCH is actually not defined in latest FindPerlLibs.cmake macros, thus - # we have to find the correct path on our own. - EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MConfig -e "print \$Config{sitearch}" - OUTPUT_VARIABLE PX_PERL_ARCH) - set (PX_PERL_LIB ${PERL_SITELIB}) - endif() - - # PERL_EXTRA_C_FLAGS is not complete, we need full flags (including e.g. - # _FILE_OFFSET_BITS=64) for compatibility. - EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MConfig -e "print \$Config{ccflags}" - OUTPUT_VARIABLE PX_PERL_CCFLAGS) - # Convert it to a "list" suitable for target_compile_options. - string(REPLACE " " ";" PX_PERL_CCFLAGS ${PX_PERL_CCFLAGS}) - endif() - - add_subdirectory(lib) - add_subdirectory(src) - add_subdirectory(t) -endif() - diff --git a/bindings/perl/lib/CMakeLists.txt b/bindings/perl/lib/CMakeLists.txt deleted file mode 100644 index 7c36e51..0000000 --- a/bindings/perl/lib/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_custom_target(PMlibproxy ALL ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Libproxy.pm ${CMAKE_BINARY_DIR}/perl/Net/Libproxy.pm) -install( FILES Libproxy.pm DESTINATION ${PX_PERL_ARCH}/Net ) diff --git a/bindings/perl/lib/Libproxy.pm b/bindings/perl/lib/Libproxy.pm deleted file mode 100644 index 67670fe..0000000 --- a/bindings/perl/lib/Libproxy.pm +++ /dev/null @@ -1,75 +0,0 @@ -package Net::Libproxy; -use 5.008000; -use warnings; -our $VERSION = '0.04'; - -require Exporter; -require DynaLoader; -@ISA = qw(Exporter DynaLoader); -@EXPORT = qw(proxy_factory_new proxy_factory_get_proxies); - -bootstrap Net::Libproxy; - -sub new { - my $self; - - $self->{pf} = Net::Libproxy::proxy_factory_new(); - - bless $self; -} - -sub getProxies { - my ($self, $url) = @_; - - return Net::Libproxy::proxy_factory_get_proxies($self->{pf}, $url); -} - -1; - - -=head1 NAME - -Net::Libproxy - Perl binding for libproxy ( http://code.google.com/p/libproxy/ ) - -=head1 SYNOPSIS - - use Net::Libproxy; - - $p = new Net::Libproxy; - $proxies = $p->getProxies('http://code.google.com/p/libproxy/'); - - foreach my $proxy (@$proxies) { - print $proxy."\n"; - } - -=head1 DESCRIPTION - -libproxy is a lightweight library which makes it easy to develop -applications proxy-aware with a simple and stable API. - -=head2 EXPORT - -These two functions are also exported. -proxy_factory_new() -proxy_factory_get_proxies() - -=head1 SEE ALSO - -Libproxy homepage: http://code.google.com/p/libproxy/ -Net::Libproxy on Gitorious: http://gitorious.org/net-libproxy -You can also read proxy.h and Net/Libproxy.pm - -=head1 AUTHOR - -Goneri Le Bouder, E<lt>goneri@rulezlan.orgE<gt> - -=head1 COPYRIGHT AND LICENSE - -Copyright (C) 2009 by Goneri Le Bouder - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself, either Perl version 5.10.0 or, -at your option, any later version of Perl 5 you may have available. - - -=cut diff --git a/bindings/perl/src/CMakeLists.txt b/bindings/perl/src/CMakeLists.txt deleted file mode 100644 index 2800a85..0000000 --- a/bindings/perl/src/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -include_directories( ${PERL_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/libproxy ) - -# Run doxsubpp.pl to run xsubpp on Libproxy.xs -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Libproxy.c - COMMAND ${PERL_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/doxsubpp.pl - ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Libproxy.xs ${CMAKE_CURRENT_BINARY_DIR}/Libproxy.c - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/Libproxy.xs libproxy - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - -set(Libproxy_LIB_SRCS Libproxy.c) - -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/perl/auto/Net/Libproxy) -add_library(PLlibproxy SHARED ${Libproxy_LIB_SRCS}) - -set(PLlibproxy_LIB_DEPENDENCIES libproxy pthread) -if(PERL_LINK_LIBPERL) - set(PLlibproxy_LIB_DEPENDENCIES ${PERL_LIBRARY} ${PLlibproxy_LIB_DEPENDENCIES}) -endif() - -target_link_libraries(PLlibproxy ${PLlibproxy_LIB_DEPENDENCIES}) -target_compile_options(PLlibproxy PRIVATE ${PX_PERL_CCFLAGS}) -set_target_properties(PLlibproxy PROPERTIES OUTPUT_NAME "Libproxy") -set_target_properties(PLlibproxy PROPERTIES PREFIX "") - -install( TARGETS PLlibproxy DESTINATION ${PX_PERL_ARCH}/auto/Net/Libproxy ) diff --git a/bindings/perl/src/Libproxy.xs b/bindings/perl/src/Libproxy.xs deleted file mode 100644 index bf5c2bb..0000000 --- a/bindings/perl/src/Libproxy.xs +++ /dev/null @@ -1,98 +0,0 @@ -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - -#include <proxy.h> - - -void XS_pack_charPtrPtr( SV * arg, char ** array, int count) { - int i; - AV * avref; - avref = (AV*)sv_2mortal((SV*)newAV()); - for (i=0; i<count; i++) { - av_push(avref, newSVpv(array[i], strlen(array[i]))); - } - SvSetSV( arg, newRV((SV*)avref)); -} - -/* http://www.perlmonks.org/?node_id=680842 */ -static char ** -XS_unpack_charPtrPtr (SV *arg) { - char **ret; - AV *av; - I32 i; - - if (!arg || !SvOK (arg) || !SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) - croak ("array reference expected"); - - av = (AV *)SvRV (arg); - ret = malloc ((av_len (av) + 1 + 1) * sizeof (char *)); - if (!ret) - croak ("malloc failed"); - - for (i = 0; i <= av_len (av); i++) { - SV **elem = av_fetch (av, i, 0); - - if (!elem || !*elem) { - free (ret); - croak ("missing element in list"); - } - - ret[i] = SvPV_nolen (*elem); - } - - ret[i] = NULL; - - return ret; -} - - -MODULE = Net::Libproxy PACKAGE = Net::Libproxy - -PROTOTYPES: DISABLE - -pxProxyFactory * -proxy_factory_new() - PREINIT: - pxProxyFactory *pf; - CODE: - pf = px_proxy_factory_new(); - RETVAL = pf; - OUTPUT: - RETVAL - -char ** -proxy_factory_get_proxies(pf, url) - pxProxyFactory * pf - char * url - PREINIT: - char ** array; - int count_charPtrPtr; - int i; - CODE: - array = px_proxy_factory_get_proxies(pf, url); - RETVAL = array; - i = 0; - while( array[i] != NULL ) { - i++; - } - count_charPtrPtr = i; - OUTPUT: - RETVAL - -void -proxy_factory_free_proxies(proxies) - char ** proxies - CODE: - px_proxy_factory_free_proxies(proxies); - -MODULE = Net::Libproxy PACKAGE = Net::Libproxy::ProxyFactoryPtr - -void -DESTROY(pf) - pxProxyFactory * pf - CODE: - printf("Net::Libproxy::DESTROY\n"); - px_proxy_factory_free(pf); - - diff --git a/bindings/perl/src/doxsubpp.pl b/bindings/perl/src/doxsubpp.pl deleted file mode 100644 index 57ab4dd..0000000 --- a/bindings/perl/src/doxsubpp.pl +++ /dev/null @@ -1,23 +0,0 @@ -use strict; -use warnings; -use ExtUtils::MakeMaker; - -my $perl = $ARGV[0]; -my $in = $ARGV[1]; -my $out = $ARGV[2]; - -my $mm = ExtUtils::MakeMaker->new( { - NAME => 'Libproxy', - NEEDS_LINKING => 1, -} ); - -my $perl_include_path = $mm->{PERL_INC}; -my @xsubinfo = split "\n", $mm->tool_xsubpp(); - -my $xsubppdir = (map{ my $foo = $_; $foo =~ s/XSUBPPDIR = //; $foo } grep{ m/^XSUBPPDIR =/ } @xsubinfo)[0]; -my $xsubpp = "$xsubppdir/xsubpp"; - -my $xsubppargs = (map{ my $foo = $_; $foo =~ s/XSUBPPARGS = //; $foo } grep{ m/^XSUBPPARGS =/ } @xsubinfo)[0]; - -my $cmd = "$perl $xsubpp $xsubppargs -typemap typemap $in > $out"; -system $cmd; diff --git a/bindings/perl/src/typemap b/bindings/perl/src/typemap deleted file mode 100644 index 62be990..0000000 --- a/bindings/perl/src/typemap +++ /dev/null @@ -1,2 +0,0 @@ -TYPEMAP -pxProxyFactory * T_PTROBJ diff --git a/bindings/perl/t/CMakeLists.txt b/bindings/perl/t/CMakeLists.txt deleted file mode 100644 index cb18fd3..0000000 --- a/bindings/perl/t/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_test(NAME perl COMMAND prove -b ${CMAKE_CURRENT_SOURCE_DIR}) -set_property(TEST perl APPEND PROPERTY ENVIRONMENT "PERL5LIB=${CMAKE_BINARY_DIR}/perl") diff --git a/bindings/perl/t/Libproxy.t b/bindings/perl/t/Libproxy.t deleted file mode 100644 index 5c4fe61..0000000 --- a/bindings/perl/t/Libproxy.t +++ /dev/null @@ -1,15 +0,0 @@ -# Before `make install' is performed this script should be runnable with
-# `make test'. After `make install' it should work as `perl Foo.t'
-
-#########################
-
-# change 'tests => 1' to 'tests => last_test_to_print';
-
-use Test::More tests => 1;
-BEGIN { use_ok('Net::Libproxy') };
-
-#########################
-
-# Insert your test code below, the Test::More module is use()ed here so read
-# its man page ( perldoc Test::More ) for help writing this test script.
-
diff --git a/bindings/python/libproxy.py b/bindings/python/libproxy.py deleted file mode 100644 index 21c64b4..0000000 --- a/bindings/python/libproxy.py +++ /dev/null @@ -1,145 +0,0 @@ -# encoding: utf-8 -############################################################################### -# 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 -############################################################################### - -"A library for proxy configuration and autodetection." - -import ctypes -import ctypes.util -import platform - -import sys - -def _load(name, *versions): - for ver in versions: - try: return ctypes.cdll.LoadLibrary('lib%s.so.%s' % (name, ver)) - except: pass - name_ver = ctypes.util.find_library(name) - if name_ver: - return ctypes.cdll.LoadLibrary(name_ver) - raise ImportError("Unable to find %s library" % name) - -# Load libproxy -_libproxy = _load("proxy", 1) -_libproxy.px_proxy_factory_new.restype = ctypes.POINTER(ctypes.c_void_p) -_libproxy.px_proxy_factory_free.argtypes = [ctypes.c_void_p] -_libproxy.px_proxy_factory_get_proxies.restype = ctypes.POINTER(ctypes.c_void_p) -_libproxy.px_proxy_factory_free_proxies.argtypes = [ctypes.POINTER(ctypes.c_void_p)] - -class ProxyFactory(object): - """A ProxyFactory object is used to provide potential proxies to use - in order to reach a given URL (via 'getProxies(url)'). - - This instance should be kept around as long as possible as it contains - cached data to increase performance. Memory usage should be minimal (cache - is small) and the cache lifespan is handled automatically. - - Usage is pretty simple: - pf = libproxy.ProxyFactory() - for url in urls: - proxies = pf.getProxies(url) - for proxy in proxies: - if proxy == "direct://": - # Fetch URL without using a proxy - elif proxy.startswith("http://"): - # Fetch URL using an HTTP proxy - elif proxy.startswith("socks://"): - # Fetch URL using a SOCKS proxy - - if fetchSucceeded: - break - """ - - class ProxyResolutionError(RuntimeError): - """Exception raised when proxy cannot be resolved generally - due to invalid URL""" - pass - - def __init__(self): - self._pf = _libproxy.px_proxy_factory_new() - - def getProxies(self, url): - """Given a URL, returns a list of proxies in priority order to be used - to reach that URL. - - A list of proxy strings is returned. If the first proxy fails, the - second should be tried, etc... In all cases, at least one entry in the - list will be returned. There are no error conditions. - - Regarding performance: this method always blocks and may be called - in a separate thread (is thread-safe). In most cases, the time - required to complete this function call is simply the time required - to read the configuration (e.g from GConf, Kconfig, etc). - - In the case of PAC, if no valid PAC is found in the cache (i.e. - configuration has changed, cache is invalid, etc), the PAC file is - downloaded and inserted into the cache. This is the most expensive - operation as the PAC is retrieved over the network. Once a PAC exists - in the cache, it is merely a JavaScript invocation to evaluate the PAC. - One should note that DNS can be called from within a PAC during - JavaScript invocation. - - In the case of WPAD, WPAD is used to automatically locate a PAC on the - network. Currently, we only use DNS for this, but other methods may - be implemented in the future. Once the PAC is located, normal PAC - performance (described above) applies. - - """ - if type(url) != str: - raise TypeError("url must be a string!") - - if type(url) is bytes: - # Python 2: str is bytes - url_bytes = url - else: - # Python 3: str is unicode - # TODO: Does this need to be encoded from IRI to ASCII (ACE) URI, - # for example http://кц.рф/пример -> - # http://xn--j1ay.xn--p1ai/%D0%BF%D1%80%D0%B8%D0%BC%D0%B5%D1%80? - # Or is libproxy designed to accept IRIs like - # http://кц.рф/пример? Passing in an IRI does seem to work - # acceptably in practice, so do that for now. - url_bytes = url.encode('utf-8') - - proxies = [] - array = _libproxy.px_proxy_factory_get_proxies(self._pf, url_bytes) - - if not bool(array): - raise ProxyFactory.ProxyResolutionError( - "Can't resolve proxy for '%s'" % url) - - i=0 - while array[i]: - proxy_bytes = ctypes.cast(array[i], ctypes.c_char_p).value - if type(proxy_bytes) is str: - # Python 2 - proxies.append(proxy_bytes) - else: - # Python 3 - proxies.append(proxy_bytes.decode('utf-8', errors='replace')) - i += 1 - - _libproxy.px_proxy_factory_free_proxies(array) - - return proxies - - def __del__(self): - if _libproxy: - _libproxy.px_proxy_factory_free(self._pf) - diff --git a/bindings/python/python2/CMakeLists.txt b/bindings/python/python2/CMakeLists.txt deleted file mode 100644 index f4d2b91..0000000 --- a/bindings/python/python2/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -find_package(Python2Interp) - -if(PYTHON2INTERP_FOUND) - set(PYTHON2_SITEPKG_DIR "${PYTHON2_SITEPKG_DIR}" CACHE PATH "Python 2 site-package directory.") - - if(NOT PYTHON2_SITEPKG_DIR) - execute_process(COMMAND - ${PYTHON2_EXECUTABLE} - -c "import sys; print('{}.{}'.format(*sys.version_info[0:2]))" - OUTPUT_VARIABLE PYTHON2_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - - message(STATUS "Found python 2 version ${PYTHON2_VERSION}") - - execute_process(COMMAND - ${PYTHON2_EXECUTABLE} - -c "import distutils.sysconfig ; print (distutils.sysconfig.get_python_lib(plat_specific=0))" - OUTPUT_VARIABLE PYTHON2_SITEPKG_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - endif() - - message(STATUS "Using PYTHON2_SITEPKG_DIR=${PYTHON2_SITEPKG_DIR}") - - install(FILES ../libproxy.py DESTINATION ${PYTHON2_SITEPKG_DIR}) -endif() diff --git a/bindings/python/python3/CMakeLists.txt b/bindings/python/python3/CMakeLists.txt deleted file mode 100644 index fc3b24b..0000000 --- a/bindings/python/python3/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -find_package(Python3Interp) - -if(PYTHON3INTERP_FOUND) - set(PYTHON3_SITEPKG_DIR "${PYTHON3_SITEPKG_DIR}" CACHE PATH "Python 3 site-package directory.") - - if(NOT PYTHON3_SITEPKG_DIR) - execute_process(COMMAND - ${PYTHON3_EXECUTABLE} - -c "import sys; print('{}.{}'.format(*sys.version_info[0:2]))" - OUTPUT_VARIABLE PYTHON3_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - - message(STATUS "Found python 3 version ${PYTHON3_VERSION}") - - execute_process(COMMAND - ${PYTHON3_EXECUTABLE} - -c "import distutils.sysconfig ; print (distutils.sysconfig.get_python_lib(plat_specific=0))" - OUTPUT_VARIABLE PYTHON3_SITEPKG_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - endif() - - message(STATUS "Using PYTHON3_SITEPKG_DIR=${PYTHON3_SITEPKG_DIR}") - - install(FILES ../libproxy.py DESTINATION ${PYTHON3_SITEPKG_DIR}) -endif() diff --git a/bindings/ruby/Libproxy.i b/bindings/ruby/Libproxy.i deleted file mode 100644 index 183acba..0000000 --- a/bindings/ruby/Libproxy.i +++ /dev/null @@ -1,21 +0,0 @@ -/* libproxy.i */ -%module Libproxy -%{ -#include "../../libproxy/proxy.h" -%} - -%typemap(out) char ** { - VALUE arr = rb_ary_new2(255); - int i; - for (i=0; $1[i]; i++) { - rb_ary_push(arr, rb_str_new2($1[i])); - } - $result = arr; -} - -%typemap(freearg) char ** { - free($source); -} - -%include "../../libproxy/proxy.h" - diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb deleted file mode 100644 index efd13eb..0000000 --- a/bindings/ruby/extconf.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'mkmf' -$libs = append_library($libs, "proxy") -create_makefile('Libproxy') diff --git a/bindings/ruby/test.rb b/bindings/ruby/test.rb deleted file mode 100644 index 5730a32..0000000 --- a/bindings/ruby/test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'Libproxy' - -pf = Libproxy.px_proxy_factory_new -proxies = Libproxy.px_proxy_factory_get_proxies(pf, "http://www.google.com") - -proxies.each { |proxy| print proxy + " " } -print "\n" diff --git a/bindings/vala/libproxy-1.0.vapi b/bindings/vala/libproxy-1.0.vapi deleted file mode 100644 index bec22d0..0000000 --- a/bindings/vala/libproxy-1.0.vapi +++ /dev/null @@ -1,10 +0,0 @@ -[CCode (cprefix = "px", lower_case_cprefix = "px_", cheader_filename = "proxy.h")] -namespace Libproxy { - [Compact] - [CCode (free_function = "px_proxy_factory_free")] - public class ProxyFactory { - public ProxyFactory (); - [CCode (array_length = false, array_null_terminated = true)] - public string[] get_proxies (string url); - } -} diff --git a/cmake/CMakeCSharpCompiler.cmake.in b/cmake/CMakeCSharpCompiler.cmake.in deleted file mode 100644 index a14bade..0000000 --- a/cmake/CMakeCSharpCompiler.cmake.in +++ /dev/null @@ -1,10 +0,0 @@ -set(CMAKE_CSharp_COMPILER "@CMAKE_CSharp_COMPILER@") -set(CMAKE_CSharp_COMPILER_LOADED @CMAKE_CSharp_COMPILER_LOADED@) - -# Don't do that otherwise you can't change the path later -#set(GAC_DIR @GAC_DIR@) - -set(_csc_default_lib_path @_csc_default_lib_path@ CACHE INTERNAL "") - -set(CMAKE_CSharp_COMPILER_ENV_VAR "CSC") - diff --git a/cmake/CMakeCSharpInformation.cmake b/cmake/CMakeCSharpInformation.cmake deleted file mode 100644 index 2331ccf..0000000 --- a/cmake/CMakeCSharpInformation.cmake +++ /dev/null @@ -1,379 +0,0 @@ -# copyright (c) 2007, 2009 Arno Rehn arno@arnorehn.de -# copyright (c) 2008 Helio castro helio@kde.org -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# This file adds support for the C# language to cmake. -# -# It adds the following functions: -# -# csharp_add_executable (<name> <source files> [UNSAFE] [WINEXE] [REFERENCES <references>] -# [COMPILE_FLAGS <flags to be passed to the compiler>] -# [COMPILE_DEFINITIONS <additional definitions>] ) -# -# csharp_add_library (<name> <source files> [UNSAFE] [REFERENCES <references>] -# [COMPILE_FLAGS <flags to be passed to the compiler>] -# [COMPILE_DEFINITIONS <additional definitions>] ) -# -# install_assembly (<target name> [NO_GAC] DESTINATION <assembly destination directory> -# [PACKAGE <package name>] ) -# The assembly destination directory is only used if we compile with Visual C# and thus can't use gacutil. -# If a package is specified and a file called <target>.pc.cmake exists in the current source directory, -# this function will configure the template file. All occurences of @assembly@ will be replaced with -# the path to the assembly. The resulting <target>.pc file will be installed to -# <CMAKE_INSTALL_PREFIX>/lib/pkgconfig/ . If you want to have a different basename for the template file, -# set the 'pkg-config_template_basename' property of the target with set_property. -# -# Example: -# ------------------------------ -# cmake code: -# ------------------------------ -# csharp_add_library(foo foo.cs) -# install_assembly(foo DESTINATION lib) -# -# ------------------------------ -# contents of foo.pc.cmake file: -# ------------------------------ -# Name: Foo -# Description: Foo library -# Version: 1.0 -# Libs: -r:@assembly@ - -# ----- support macros ----- -macro(GET_LIBRARY_OUTPUT_DIR var) - if (NOT LIBRARY_OUTPUT_PATH) - set(${var} ${CMAKE_CURRENT_BINARY_DIR}) - else (NOT LIBRARY_OUTPUT_PATH) - set(${var} ${LIBRARY_OUTPUT_PATH}) - endif (NOT LIBRARY_OUTPUT_PATH) -endmacro(GET_LIBRARY_OUTPUT_DIR) - -macro(GET_EXECUTABLE_OUTPUT_DIR var) - if (NOT EXECUTABLE_OUTPUT_PATH) - set(${var} ${CMAKE_CURRENT_BINARY_DIR}) - else (NOT EXECUTABLE_OUTPUT_PATH) - set(${var} ${EXECUTABLE_OUTPUT_PATH}) - endif (NOT EXECUTABLE_OUTPUT_PATH) -endmacro(GET_EXECUTABLE_OUTPUT_DIR) - -# This does just not always work... why?! -# macro(MAKE_PROPER_FILE_LIST var) -# foreach(file ${ARGN}) -# if (IS_ABSOLUTE "${file}") -# file(GLOB globbed "${file}") -# else (IS_ABSOLUTE "${file}") -# file(GLOB globbed "${CMAKE_CURRENT_SOURCE_DIR}/${file}") -# endif (IS_ABSOLUTE "${file}") -# -# foreach (glob ${globbed}) -# file(TO_NATIVE_PATH "${glob}" native) -# list(APPEND proper_file_list "${native}") -# endforeach (glob ${globbed}) -# endforeach(file ${ARGN}) -# endmacro(MAKE_PROPER_FILE_LIST) - -# ----- actual functions ----- - -# ----- add an executable ----- -function(csharp_add_executable target) - set(current "s") - set(dotnet_target "exe") - - foreach (arg ${ARGN}) - file(TO_NATIVE_PATH ${arg} native_path) - - if (arg STREQUAL "UNSAFE") - set (unsafe "/unsafe") - elseif (arg STREQUAL "WINEXE") - set (dotnet_target "winexe") - elseif (arg STREQUAL "REFERENCES") - set (current "r") - elseif (arg STREQUAL "COMPILE_FLAGS") - set (current "flags") - elseif (arg STREQUAL "COMPILE_DEFINITIONS") - set (current "defs") - else (arg STREQUAL "UNSAFE") - if (current STREQUAL "s") - # source file - list(APPEND sources ${native_path}) - elseif (current STREQUAL "r") - # reference - if (TARGET ${arg}) - # this is an existing target - get the target assembly - get_property(prop TARGET ${arg} PROPERTY _assembly) - list(APPEND references "/r:${prop}") - list(APPEND deps ${arg}) - else (TARGET ${arg}) - # something different (e.g. assembly name in the gac) - list(APPEND references "/r:${native_path}") - endif (TARGET ${arg}) - elseif (current STREQUAL "flags") - list(APPEND _csc_opts "${arg}") - elseif (current STREQUAL "defs") - list(APPEND _csc_opts "/define:${arg}") - endif (current STREQUAL "s") - endif (arg STREQUAL "UNSAFE") - endforeach (arg ${ARGN}) - - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - list(APPEND _csc_opts "/define:DEBUG") - list(APPEND _csc_opts "/debug") - endif (CMAKE_BUILD_TYPE STREQUAL "Debug") - - get_executable_output_dir(outdir) - if (NOT IS_ABSOLUTE "${outdir}") - message(FATAL_ERROR "Directory \"${outdir}\" is not an absolute path!") - endif (NOT IS_ABSOLUTE "${outdir}") - - file(RELATIVE_PATH relative_path "${CMAKE_BINARY_DIR}" "${outdir}/${target}.exe") - file(TO_NATIVE_PATH "${outdir}/${target}" native_target) - - # inlined - this doesn't work as a macro :( - foreach(file ${sources}) - file(TO_CMAKE_PATH "${file}" cmake_file) - - if (IS_ABSOLUTE "${cmake_file}") - file(GLOB globbed "${cmake_file}") - else (IS_ABSOLUTE "${cmake_file}") - file(GLOB globbed "${CMAKE_CURRENT_SOURCE_DIR}/${cmake_file}") - endif (IS_ABSOLUTE "${cmake_file}") - - foreach (glob ${globbed}) - file(TO_CMAKE_PATH "${glob}" cmake_path) - list(APPEND cmake_file_list "${cmake_path}") - endforeach (glob ${globbed}) - if (NOT globbed) - list(APPEND cmake_file_list "${cmake_file}") - endif (NOT globbed) - list(APPEND compiler_file_list ${file}) - endforeach(file ${sources}) - - get_directory_property(compile_definitions COMPILE_DEFINITIONS) - foreach (def ${compile_definitions}) - # macros with values aren't supported by C# - if (NOT def MATCHES ".*=.*") - list(APPEND _csc_opts "/define:${def}") - endif (NOT def MATCHES ".*=.*") - endforeach (def ${compile_definitions}) - - get_directory_property(link_dirs LINK_DIRECTORIES) - foreach (dir ${link_dirs}) - list(APPEND _csc_opts "/lib:${dir}") - endforeach (dir ${link_dirs}) - - add_custom_command(OUTPUT "${outdir}/${target}.stubexe" - COMMAND "${CMAKE_COMMAND}" -E make_directory "${outdir}" # create the output dir - COMMAND "${CMAKE_CSharp_COMPILER}" /nologo /target:${dotnet_target} "/out:${native_target}.exe" # build the executable - ${_csc_opts} ${unsafe} ${references} ${compiler_file_list} - COMMAND "${CMAKE_COMMAND}" -E touch "${outdir}/${target}.stubexe" # create the stub so that DEPENDS will work - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" # working directory is the source directory, so we don't have to care about relative paths - DEPENDS ${cmake_file_list} - COMMENT "Building ${relative_path}" VERBATIM) # nice comment - add_custom_target(${target} ALL DEPENDS "${outdir}/${target}.stubexe" SOURCES ${cmake_file_list}) # create the actual target - set_property(TARGET ${target} PROPERTY _assembly "${native_target}.exe") - set_property(TARGET ${target} PROPERTY _assembly_type "exe") - if (deps) - add_dependencies(${target} ${deps}) - endif(deps) -endfunction(csharp_add_executable) - -# ----- add a library ----- -function(csharp_add_library target) - set(current "s") - - foreach (arg ${ARGN}) - file(TO_NATIVE_PATH ${arg} native_path) - - if (arg STREQUAL "UNSAFE") - set (unsafe "/unsafe") - elseif (arg STREQUAL "REFERENCES") - set (current "r") - elseif (arg STREQUAL "COMPILE_FLAGS") - set (current "flags") - elseif (arg STREQUAL "COMPILE_DEFINITIONS") - set (current "defs") - else (arg STREQUAL "UNSAFE") - if (current STREQUAL "s") - # source file - list(APPEND sources ${native_path}) - elseif (current STREQUAL "r") - # reference - if (TARGET ${arg}) - # this is an existing target - get the target assembly - get_property(prop TARGET ${arg} PROPERTY _assembly) - list(APPEND references "/r:${prop}") - list(APPEND deps ${arg}) - else (TARGET ${arg}) - # something different (e.g. assembly name in the gac) - list(APPEND references "/r:${native_path}") - endif (TARGET ${arg}) - elseif (current STREQUAL "flags") - list(APPEND _csc_opts "${arg}") - elseif (current STREQUAL "defs") - list(APPEND _csc_opts "/define:${arg}") - endif (current STREQUAL "s") - endif (arg STREQUAL "UNSAFE") - endforeach (arg ${ARGN}) - - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - list(APPEND _csc_opts "/define:DEBUG") - list(APPEND _csc_opts "/debug") - endif (CMAKE_BUILD_TYPE STREQUAL "Debug") - - get_library_output_dir(outdir) - if (NOT IS_ABSOLUTE "${outdir}") - message(FATAL_ERROR "Directory \"${outdir}\" is not an absolute path!") - endif (NOT IS_ABSOLUTE "${outdir}") - - file(RELATIVE_PATH relative_path "${CMAKE_BINARY_DIR}" "${outdir}/${target}.dll") - file(TO_NATIVE_PATH "${outdir}/${target}" native_target) - - # inlined - this doesn't work as a macro :( - foreach(file ${sources}) - file(TO_CMAKE_PATH "${file}" cmake_file) - - if (IS_ABSOLUTE "${cmake_file}") - file(GLOB globbed "${cmake_file}") - else (IS_ABSOLUTE "${cmake_file}") - file(GLOB globbed "${CMAKE_CURRENT_SOURCE_DIR}/${cmake_file}") - endif (IS_ABSOLUTE "${cmake_file}") - - foreach (glob ${globbed}) - file(TO_CMAKE_PATH "${glob}" cmake_path) - list(APPEND cmake_file_list "${cmake_path}") - endforeach (glob ${globbed}) - if (NOT globbed) - list(APPEND cmake_file_list "${cmake_file}") - endif (NOT globbed) - list(APPEND compiler_file_list ${file}) - endforeach(file ${sources}) - -# message("CMake File List for target ${target}: ${cmake_file_list}") - - get_directory_property(compile_definitions COMPILE_DEFINITIONS) - foreach (def ${compile_definitions}) - # macros with values aren't supported by C# - if (NOT def MATCHES ".*=.*") - list(APPEND _csc_opts "/define:${def}") - endif (NOT def MATCHES ".*=.*") - endforeach (def ${compile_definitions}) - - get_directory_property(link_dirs LINK_DIRECTORIES) - foreach (dir ${link_dirs}) - list(APPEND _csc_opts "/lib:${dir}") - endforeach (dir ${link_dirs}) - - add_custom_command(OUTPUT "${outdir}/${target}.dll" - COMMAND "${CMAKE_COMMAND}" -E make_directory "${outdir}" # create the output dir - COMMAND "${CMAKE_CSharp_COMPILER}" /nologo /target:library "/out:${native_target}.dll" # build the library - ${_csc_opts} ${unsafe} ${references} ${compiler_file_list} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" # working directory is the source directory, so we don't have to care about relative paths - DEPENDS ${cmake_file_list} - COMMENT "Building ${relative_path}" VERBATIM) # nice comment - add_custom_target(${target} ALL DEPENDS "${outdir}/${target}.dll" SOURCES ${cmake_file_list}) # create the actual target - set_property(TARGET ${target} PROPERTY _assembly "${native_target}.dll") - set_property(TARGET ${target} PROPERTY _assembly_type "dll") - if (deps) - add_dependencies(${target} ${deps}) - endif(deps) -endfunction(csharp_add_library) - -# ----- install an assembly ----- -function(install_assembly) - set (current "t") - - foreach (arg ${ARGN}) - # flag handling - if (arg STREQUAL "NO_GAC") - set(no_gac TRUE) - # option handling - elseif (arg STREQUAL DESTINATION) - set (current "d") - elseif (arg STREQUAL "PACKAGE") - set (current "p") - # value handling - elseif (current STREQUAL "t") - set (target ${arg}) - elseif (current STREQUAL "d") - if (IS_ABSOLUTE "${arg}") - set (destination_dir "${arg}") - else (IS_ABSOLUTE "${arg}") - set (destination_dir "${CMAKE_INSTALL_PREFIX}/${arg}") - endif (IS_ABSOLUTE "${arg}") - elseif (current STREQUAL "p") - set (package ${arg}) - endif (arg STREQUAL "NO_GAC") - endforeach (arg) - - if (NOT destination_dir) - message(FATAL_ERROR "The destination directory is mandatory, even if the assembly is installed into the GAC.") - elseif (NOT target) - message(FATAL_ERROR "No target given.") - endif (NOT destination_dir) - - # retrieve the absolute path of the generated assembly - get_property(filename TARGET ${target} PROPERTY _assembly) - get_property(type TARGET ${target} PROPERTY _assembly_type) - get_property(pc_file TARGET ${target} PROPERTY pkg-config_template_basename) - - if (NOT pc_file) - set (pc_file ${target}) - endif (NOT pc_file) - - # default assembly location (for pkg-config) - set(assembly "${GAC_DIR}/${package}/${target}.dll") - - if (NOT filename) - message(FATAL_ERROR "Couldn't retrieve the assembly filename for target ${target}! Are you sure the target is a .NET library assembly?") - endif (NOT filename) - - if (package) - set (package_option "-package ${package}") - endif (package) - - if (NOT MONO_FOUND OR no_gac OR type STREQUAL "exe") - install(FILES "${filename}" DESTINATION ${destination_dir}) - if (EXISTS "${filename}.config") - install(FILES "${filename}.config" DESTINATION ${destination_dir}) - endif (EXISTS "${filename}.config") - - # don't install anything into the GAC - set (no_gac TRUE) - # set new assembly location for pkg-config - set(assembly "${destination_dir}/${target}.${type}") - endif (NOT MONO_FOUND OR no_gac OR type STREQUAL "exe") - - if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${pc_file}.pc.cmake") - configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/${pc_file}.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${pc_file}.pc" @ONLY) - - if (NOT LIB_INSTALL_DIR) - set (LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib) - endif (NOT LIB_INSTALL_DIR) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${pc_file}.pc" DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - endif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${pc_file}.pc.cmake") - - if (no_gac) - return() - endif (no_gac) - - # So we have the mono runtime and we can use gacutil (it has the -root option, which the MS version doesn't have). - install(CODE "execute_process(COMMAND ${GACUTIL_EXECUTABLE} -i ${filename} ${package_option} -root ${CMAKE_CURRENT_BINARY_DIR}/tmp_gac)") - file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/tmp_gac/mono) - file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tmp_gac/mono) - install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tmp_gac/mono/ DESTINATION ${GAC_DIR} ) -endfunction(install_assembly) - -set(CMAKE_CSharp_INFORMATION_LOADED 1) - diff --git a/cmake/CMakeDetermineCSharpCompiler.cmake b/cmake/CMakeDetermineCSharpCompiler.cmake deleted file mode 100644 index 86532eb..0000000 --- a/cmake/CMakeDetermineCSharpCompiler.cmake +++ /dev/null @@ -1,102 +0,0 @@ -# copyright (c) 2007, 2009 Arno Rehn arno@arnorehn.de -# copyright (c) 2008 Helio castro helio@kde.org -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# determine the compiler to use for C# programs -# NOTE, a generator may set CMAKE_CSharp_COMPILER before -# loading this file to force a compiler. - -if(NOT CMAKE_CSharp_COMPILER) - # prefer the environment variable CSC - if($ENV{CSC} MATCHES ".+") - if (EXISTS $ENV{CSC}) - message(STATUS "Found compiler set in environment variable CSC: $ENV{CSC}.") - set(CMAKE_CSharp_COMPILER $ENV{CSC}) - else (EXISTS $ENV{CSC}) - message(SEND_ERROR "Could not find compiler set in environment variable CSC:\n$ENV{CSC}.") - endif (EXISTS $ENV{CSC}) - endif($ENV{CSC} MATCHES ".+") - - # if no compiler has been specified yet, then look for one - if (NOT CMAKE_CSharp_COMPILER) - find_package(Mono) - set (CMAKE_CSharp_COMPILER "${GMCS_EXECUTABLE}") - - # still not found, try csc.exe - if (NOT CMAKE_CSharp_COMPILER) - get_filename_component(dotnet_path "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework;InstallRoot]" PATH) - find_program(CMAKE_CSharp_COMPILER NAMES csc PATHS "${dotnet_path}/Framework/v2.0.50727") - file(TO_NATIVE_PATH "${dotnet_path}/Framework/v2.0.50727" native_path) - message(STATUS "Looking for csc: ${CMAKE_CSharp_COMPILER}") - - # give up - if (NOT CMAKE_CSharp_COMPILER) - message (STATUS "Couldn't find a valid C# compiler. Set either CMake_CSharp_COMPILER or the CSC environment variable to a valid path.") - endif (NOT CMAKE_CSharp_COMPILER) - endif (NOT CMAKE_CSharp_COMPILER) - endif (NOT CMAKE_CSharp_COMPILER) - -endif(NOT CMAKE_CSharp_COMPILER) - -# now try to find the gac location -if (CMAKE_CSharp_COMPILER AND NOT GAC_DIR AND MONO_FOUND) - find_package(PkgConfig) - - if (PKG_CONFIG_FOUND) - pkg_search_module(MONO_CECIL mono-cecil) - if(MONO_CECIL_FOUND) - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} mono-cecil --variable=assemblies_dir OUTPUT_VARIABLE GAC_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) - endif(MONO_CECIL_FOUND) - - pkg_search_module(CECIL cecil) - if(CECIL_FOUND) - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} cecil --variable=assemblies_dir OUTPUT_VARIABLE GAC_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) - endif(CECIL_FOUND) - - if (NOT GAC_DIR) - execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} mono --variable=libdir OUTPUT_VARIABLE MONO_LIB_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) - if (MONO_LIB_DIR) - set (GAC_DIR "${MONO_LIB_DIR}/mono") - message (STATUS "Could not find cecil, guessing GAC dir from mono prefix: ${GAC_DIR}") - endif (MONO_LIB_DIR) - endif (NOT GAC_DIR) - endif (PKG_CONFIG_FOUND) - - if (NOT GAC_DIR) - set (GAC_DIR "/usr/lib/mono") - message(STATUS "Could not find cecil or mono. Using default GAC dir: ${GAC_DIR}") - endif (NOT GAC_DIR) -endif (CMAKE_CSharp_COMPILER AND NOT GAC_DIR AND MONO_FOUND) - -# Create a cache entry so the user can modify this. -set(GAC_DIR "${GAC_DIR}" CACHE PATH "Location of the GAC") -message(STATUS "Using GAC dir: ${GAC_DIR}") - -mark_as_advanced(CMAKE_CSharp_COMPILER) - -if (CMAKE_CSharp_COMPILER) - set (CMAKE_CSharp_COMPILER_LOADED 1) -endif (CMAKE_CSharp_COMPILER) - -# configure variables set in this file for fast reload later on -if(NOT CMAKE_PLATFORM_INFO_DIR) # pre-2.8.10 - set(CMAKE_PLATFORM_INFO_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}) -endif() - -configure_file(${CMAKE_SOURCE_DIR}/cmake/CMakeCSharpCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeCSharpCompiler.cmake IMMEDIATE @ONLY) -set(CMAKE_CSharp_COMPILER_ENV_VAR "CSC") - diff --git a/cmake/CMakeTestCSharpCompiler.cmake b/cmake/CMakeTestCSharpCompiler.cmake deleted file mode 100644 index 8b0e9a2..0000000 --- a/cmake/CMakeTestCSharpCompiler.cmake +++ /dev/null @@ -1,2 +0,0 @@ -SET(CMAKE_CSharp_COMPILER_WORKS 1 CACHE INTERNAL "") - diff --git a/cmake/FindMono.cmake b/cmake/FindMono.cmake deleted file mode 100644 index d4aa0ca..0000000 --- a/cmake/FindMono.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# - Try to find the mono, mcs, gmcs and gacutil -# -# defines -# -# MONO_FOUND - system has mono, mcs, gmcs and gacutil -# MONO_PATH - where to find 'mono' -# GMCS_PATH - where to find 'gmcs' -# GACUTIL_PATH - where to find 'gacutil' -# -# copyright (c) 2007 Arno Rehn arno@arnorehn.de -# -# Redistribution and use is allowed according to the terms of the GPL license. - -FIND_PROGRAM (MONO_EXECUTABLE mono) -FIND_PROGRAM (GMCS_EXECUTABLE NAMES gmcs mcs) -FIND_PROGRAM (GACUTIL_EXECUTABLE gacutil) - -SET (MONO_FOUND FALSE CACHE INTERNAL "") - -IF (MONO_EXECUTABLE AND GMCS_EXECUTABLE AND GACUTIL_EXECUTABLE) - SET (MONO_FOUND TRUE CACHE INTERNAL "") -ENDIF (MONO_EXECUTABLE AND GMCS_EXECUTABLE AND GACUTIL_EXECUTABLE) - -IF (NOT Mono_FIND_QUIETLY) - MESSAGE(STATUS "Path of mono: ${MONO_EXECUTABLE}") - MESSAGE(STATUS "Path of gmcs: ${GMCS_EXECUTABLE}") - MESSAGE(STATUS "Path of gacutil: ${GACUTIL_EXECUTABLE}") -ENDIF (NOT Mono_FIND_QUIETLY) - -IF (NOT MONO_FOUND) - IF (Mono_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find one or more of the following programs: mono, gmcs, gacutil") - ENDIF (Mono_FIND_REQUIRED) -ENDIF (NOT MONO_FOUND) - -MARK_AS_ADVANCED(MONO_EXECUTABLE GMCS_EXECUTABLE GACUTIL_EXECUTABLE) - diff --git a/cmake/FindPython2Interp.cmake b/cmake/FindPython2Interp.cmake deleted file mode 100644 index 021a526..0000000 --- a/cmake/FindPython2Interp.cmake +++ /dev/null @@ -1,162 +0,0 @@ -#.rst: -# FindPython2Interp -# ---------------- -# -# Find python 3 interpreter (based on original FindPythonInterp from cmake) -# -# This module finds if Python interpreter is installed and determines -# where the executables are. This code sets the following variables: -# -# :: -# -# PYTHON2INTERP_FOUND - Was the Python executable found -# PYTHON2_EXECUTABLE - path to the Python interpreter -# -# -# -# :: -# -# PYTHON2_VERSION_STRING - Python version found e.g. 2.5.1 -# PYTHON2_VERSION_MAJOR - Python major version found e.g. 1 -# PYTHON2_VERSION_MINOR - Python minor version found e.g. 5 -# PYTHON2_VERSION_PATCH - Python patch version found e.g. 1 -# -#============================================================================= -# Copyright 2005-2010 Kitware, Inc. -# Copyright 2011 Bjoern Ricks <bjoern.ricks@gmail.com> -# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> -# Copyright 2016 Dominique Leuenberger <dimstar@opensuse.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Kitware, Inc. nor the names of Contributors -# may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -unset(_Python2_NAMES) - -set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) - -if(Python2Interp_FIND_VERSION) - if(Python2Interp_FIND_VERSION_COUNT GREATER 1) - set(_PYTHON2_FIND_MAJ_MIN "${Python2Interp_FIND_VERSION_MAJOR}.${Python2Interp_FIND_VERSION_MINOR}") - list(APPEND _Python2_NAMES - python${_PYTHON2_FIND_MAJ_MIN} - python${Python2Interp_FIND_VERSION_MAJOR}) - unset(_PYTHON2_FIND_OTHER_VERSIONS) - if(NOT Python2Interp_FIND_VERSION_EXACT) - foreach(_PYTHON2_V ${_PYTHON${Python2Interp_FIND_VERSION_MAJOR}_VERSIONS}) - if(NOT _PYTHON2_V VERSION_LESS _PYTHON2_FIND_MAJ_MIN) - list(APPEND _PYTHON2_FIND_OTHER_VERSIONS ${_PYTHON2_V}) - endif() - endforeach() - endif() - unset(_PYTHON2_FIND_MAJ_MIN) - else() - list(APPEND _Python2_NAMES python${Python2Interp_FIND_VERSION_MAJOR}) - set(_PYTHON2_FIND_OTHER_VERSIONS ${_PYTHON${Python2Interp_FIND_VERSION_MAJOR}_VERSIONS}) - endif() -else() - set(_PYTHON2_FIND_OTHER_VERSIONS ${_PYTHON2_VERSIONS}) -endif() -find_program(PYTHON2_EXECUTABLE NAMES ${_Python2_NAMES}) - -# If FindPythonInterp has already found the major and minor version, -# insert that version next to get consistent versions of the interpreter and -# library. -if(DEFINED PYTHON2LIBS_VERSION_STRING) - string(REPLACE "." ";" _PYTHON2LIBS_VERSION "${PYTHON2LIBS_VERSION_STRING}") - list(GET _PYTHON2LIBS_VERSION 0 _PYTHON2LIBS_VERSION_MAJOR) - list(GET _PYTHON2LIBS_VERSION 1 _PYTHON2LIBS_VERSION_MINOR) - list(APPEND _Python2_VERSIONS ${_PYTHON2LIBS_VERSION_MAJOR}.${_PYTHON2LIBS_VERSION_MINOR}) -endif() -# Search for the current active python version first -list(APPEND _Python2_VERSIONS ";") - -unset(_PYTHON2_VERSIONS) - -# Search for newest python version if python executable isn't found -if(NOT PYTHON2_EXECUTABLE) - foreach(_CURRENT_VERSION IN LISTS _Python2_VERSIONS) - set(_Python2_NAMES python${_CURRENT_VERSION}) - if(WIN32) - list(APPEND _Python2_NAMES python) - endif() - find_program(PYTHON2_EXECUTABLE - NAMES ${_Python2_NAMES} - PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath] - ) - endforeach() -endif() - -# determine python version string -if(PYTHON2_EXECUTABLE) - execute_process(COMMAND "${PYTHON2_EXECUTABLE}" -c - "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))" - OUTPUT_VARIABLE _VERSION - RESULT_VARIABLE _PYTHON2_VERSION_RESULT - ERROR_QUIET) - if(NOT _PYTHON2_VERSION_RESULT) - string(REPLACE ";" "." PYTHON2_VERSION_STRING "${_VERSION}") - list(GET _VERSION 0 PYTHON2_VERSION_MAJOR) - list(GET _VERSION 1 PYTHON2_VERSION_MINOR) - list(GET _VERSION 2 PYTHON2_VERSION_PATCH) - if(PYTHON2_VERSION_PATCH EQUAL 0) - # it's called "Python 3.1", not "3.1.0" - string(REGEX REPLACE "\\.0$" "" PYTHON2_VERSION_STRING "${PYTHON2_VERSION_STRING}") - endif() - else() - # sys.version predates sys.version_info, so use that - execute_process(COMMAND "${PYTHON2_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)" - OUTPUT_VARIABLE _VERSION - RESULT_VARIABLE _PYTHON2_VERSION_RESULT - ERROR_QUIET) - if(NOT _PYTHON2_VERSION_RESULT) - string(REGEX REPLACE " .*" "" PYTHON2_VERSION_STRING "${_VERSION}") - string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON2_VERSION_MAJOR "${PYTHON2_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON2_VERSION_MINOR "${PYTHON2_VERSION_STRING}") - if(PYTHON2_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.([0-9]+)") - set(PYTHON2_VERSION_PATCH "${CMAKE_MATCH_1}") - else() - set(PYTHON2_VERSION_PATCH "0") - endif() - else() - # sys.version was first documented for Python 1.5, so assume - # this is older. - set(PYTHON2_VERSION_STRING "1.4") - set(PYTHON2_VERSION_MAJOR "1") - set(PYTHON2_VERSION_MINOR "4") - set(PYTHON2_VERSION_PATCH "0") - endif() - endif() - unset(_PYTHON2_VERSION_RESULT) - unset(_VERSION) -endif() - -# handle the QUIETLY and REQUIRED arguments and set PYTHON2INTERP_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Python2Interp REQUIRED_VARS PYTHON2_EXECUTABLE VERSION_VAR PYTHON2_VERSION_STRING) - -mark_as_advanced(PYTHON2_EXECUTABLE) diff --git a/cmake/FindPython3Interp.cmake b/cmake/FindPython3Interp.cmake deleted file mode 100644 index d2f5d74..0000000 --- a/cmake/FindPython3Interp.cmake +++ /dev/null @@ -1,162 +0,0 @@ -#.rst: -# FindPython3Interp -# ---------------- -# -# Find python 3 interpreter (based on original FindPythonInterp from cmake) -# -# This module finds if Python interpreter is installed and determines -# where the executables are. This code sets the following variables: -# -# :: -# -# PYTHON3INTERP_FOUND - Was the Python executable found -# PYTHON3_EXECUTABLE - path to the Python interpreter -# -# -# -# :: -# -# PYTHON3_VERSION_STRING - Python version found e.g. 3.5.1 -# PYTHON3_VERSION_MAJOR - Python major version found e.g. 3 -# PYTHON3_VERSION_MINOR - Python minor version found e.g. 5 -# PYTHON3_VERSION_PATCH - Python patch version found e.g. 1 -# -#============================================================================= -# Copyright 2005-2010 Kitware, Inc. -# Copyright 2011 Bjoern Ricks <bjoern.ricks@gmail.com> -# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> -# Copyright 2016 Dominique Leuenberger <dimstar@opensuse.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Kitware, Inc. nor the names of Contributors -# may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -unset(_Python3_NAMES) - -set(_Python3_VERSIONS 3.11 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0) - -if(Python3Interp_FIND_VERSION) - if(Python3Interp_FIND_VERSION_COUNT GREATER 1) - set(_PYTHON3_FIND_MAJ_MIN "${Python3Interp_FIND_VERSION_MAJOR}.${Python3Interp_FIND_VERSION_MINOR}") - list(APPEND _Python3_NAMES - python${_PYTHON3_FIND_MAJ_MIN} - python${Python3Interp_FIND_VERSION_MAJOR}) - unset(_PYTHON3_FIND_OTHER_VERSIONS) - if(NOT Python3Interp_FIND_VERSION_EXACT) - foreach(_PYTHON3_V ${_PYTHON${Python3Interp_FIND_VERSION_MAJOR}_VERSIONS}) - if(NOT _PYTHON3_V VERSION_LESS _PYTHON3_FIND_MAJ_MIN) - list(APPEND _PYTHON3_FIND_OTHER_VERSIONS ${_PYTHON3_V}) - endif() - endforeach() - endif() - unset(_PYTHON3_FIND_MAJ_MIN) - else() - list(APPEND _Python3_NAMES python${Python3Interp_FIND_VERSION_MAJOR}) - set(_PYTHON3_FIND_OTHER_VERSIONS ${_PYTHON${Python3Interp_FIND_VERSION_MAJOR}_VERSIONS}) - endif() -else() - set(_PYTHON3_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS}) -endif() -find_program(PYTHON3_EXECUTABLE NAMES ${_Python3_NAMES}) - -# If FindPythonInterp has already found the major and minor version, -# insert that version next to get consistent versions of the interpreter and -# library. -if(DEFINED PYTHON3LIBS_VERSION_STRING) - string(REPLACE "." ";" _PYTHON3LIBS_VERSION "${PYTHON3LIBS_VERSION_STRING}") - list(GET _PYTHON3LIBS_VERSION 0 _PYTHON3LIBS_VERSION_MAJOR) - list(GET _PYTHON3LIBS_VERSION 1 _PYTHON3LIBS_VERSION_MINOR) - list(APPEND _Python3_VERSIONS ${_PYTHON3LIBS_VERSION_MAJOR}.${_PYTHON3LIBS_VERSION_MINOR}) -endif() -# Search for the current active python version first -list(APPEND _Python3_VERSIONS ";") - -unset(_PYTHON3_VERSIONS) - -# Search for newest python version if python executable isn't found -if(NOT PYTHON3_EXECUTABLE) - foreach(_CURRENT_VERSION IN LISTS _Python3_VERSIONS) - set(_Python3_NAMES python${_CURRENT_VERSION}) - if(WIN32) - list(APPEND _Python3_NAMES python3) - endif() - find_program(PYTHON3_EXECUTABLE - NAMES ${_Python3_NAMES} - PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath] - ) - endforeach() -endif() - -# determine python version string -if(PYTHON3_EXECUTABLE) - execute_process(COMMAND "${PYTHON3_EXECUTABLE}" -c - "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))" - OUTPUT_VARIABLE _VERSION3 - RESULT_VARIABLE _PYTHON3_VERSION_RESULT - ERROR_QUIET) - if(NOT _PYTHON3_VERSION_RESULT) - string(REPLACE ";" "." PYTHON3_VERSION_STRING "${_VERSION3}") - list(GET _VERSION3 0 PYTHON3_VERSION_MAJOR) - list(GET _VERSION3 1 PYTHON3_VERSION_MINOR) - list(GET _VERSION3 2 PYTHON3_VERSION_PATCH) - if(PYTHON3_VERSION_PATCH EQUAL 0) - # it's called "Python 3.1", not "3.1.0" - string(REGEX REPLACE "\\.0$" "" PYTHON3_VERSION_STRING "${PYTHON3_VERSION_STRING}") - endif() - else() - # sys.version predates sys.version_info, so use that - execute_process(COMMAND "${PYTHON3_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)" - OUTPUT_VARIABLE _VERSION3 - RESULT_VARIABLE _PYTHON3_VERSION_RESULT - ERROR_QUIET) - if(NOT _PYTHON3_VERSION_RESULT) - string(REGEX REPLACE " .*" "" PYTHON3_VERSION_STRING "${_VERSION3}") - string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON3_VERSION_MAJOR "${PYTHON3_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON3_VERSION_MINOR "${PYTHON3_VERSION_STRING}") - if(PYTHON3_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.([0-9]+)") - set(PYTHON3_VERSION_PATCH "${CMAKE_MATCH_1}") - else() - set(PYTHON3_VERSION_PATCH "0") - endif() - else() - # sys.version was first documented for Python 1.5, so assume - # this is older. - set(PYTHON3_VERSION_STRING "1.4") - set(PYTHON3_VERSION_MAJOR "1") - set(PYTHON3_VERSION_MINOR "4") - set(PYTHON3_VERSION_PATCH "0") - endif() - endif() - unset(_PYTHON3_VERSION_RESULT) - unset(_VERSION3) -endif() - -# handle the QUIETLY and REQUIRED arguments and set PYTHON3INTERP_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Python3Interp REQUIRED_VARS PYTHON3_EXECUTABLE PYTHON3_VERSION_STRING) - -mark_as_advanced(PYTHON3_EXECUTABLE) diff --git a/cmake/cpack.cmk b/cmake/cpack.cmk deleted file mode 100644 index 2098fd5..0000000 --- a/cmake/cpack.cmk +++ /dev/null @@ -1,21 +0,0 @@ -set(CPACK_IGNORE_FILES "CMakeCache.txt;install_manifest.txt;/Testing/;/Makefile$;\\\\.tar.gz$;\\\\.so[.0-9]*$;/build/;/_CPack_Packages/;/CMakeFiles/;/CVS/;/\\\\.svn/;/\\\\.git/;\\\\.swp$;\\\\.#;/#") -set(CPACK_SOURCE_IGNORE_FILES ${CPACK_IGNORE_FILES}) -set(CPACK_SOURCE_GENERATOR TXZ ZIP) -set(CPACK_SOURCE_TOPLEVEL_TAG "") - -function(set_project_version MAJOR MINOR PATCH) - if(NOT PROJECT_NAME OR "${PROJECT_NAME}" STREQUAL "Project") - message(FATAL_ERROR "PROJECT_NAME MUST be defined before calling set_project_version()") - endif() - set(CPACK_PACKAGE_VERSION_MAJOR ${MAJOR}) - set(CPACK_PACKAGE_VERSION_MINOR ${MINOR}) - set(CPACK_PACKAGE_VERSION_PATCH ${PATCH}) - set(CPACK_PACKAGE_VERSION "${MAJOR}.${MINOR}.${PATCH}") - set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}") - set(PROJECT_VERSION "${CPACK_PACKAGE_VERSION}" PARENT_SCOPE) - set(PROJECT_VERSION_MAJOR "${MAJOR}" PARENT_SCOPE) - set(PROJECT_VERSION_MINOR "${MINOR}" PARENT_SCOPE) - set(PROJECT_VERSION_PATCH "${PATCH}" PARENT_SCOPE) - include(CPack) -endfunction(set_project_version) - diff --git a/cmake/ctest.cmk b/cmake/ctest.cmk deleted file mode 100644 index 2e5223a..0000000 --- a/cmake/ctest.cmk +++ /dev/null @@ -1,8 +0,0 @@ -include(CTest) -enable_testing() - -function(add_testdirectory DIR) - if (BUILD_TESTING) - add_subdirectory(${DIR}) - endif (BUILD_TESTING) -endfunction(add_testdirectory) diff --git a/cmake/mingw32.cmake b/cmake/mingw32.cmake deleted file mode 100644 index 9f04ebf..0000000 --- a/cmake/mingw32.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# the name of the target operating system -SET(CMAKE_SYSTEM_NAME Windows) - -# which compilers to use for C and C++ -SET(CMAKE_C_COMPILER i686-pc-mingw32-gcc) -SET(CMAKE_CXX_COMPILER i686-pc-mingw32-g++) - -# here is the target environment located -SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32 ) - -# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search -# programs in the host environment -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -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") diff --git a/cmake/paths.cmk b/cmake/paths.cmk deleted file mode 100644 index 593ebc1..0000000 --- a/cmake/paths.cmk +++ /dev/null @@ -1,17 +0,0 @@ -if(WIN32 AND NOT MINGW) - 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(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") -else(WIN32 AND NOT MINGW) - set(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH "Install prefix") - set(BIN_INSTALL_DIR bin CACHE PATH "Binary install dir") - set(LIB_INSTALL_DIR lib${LIB_SUFFIX} CACHE PATH "Library install dir") - set(LIBEXEC_INSTALL_DIR libexec CACHE PATH "Private executable install dir") - set(INCLUDE_INSTALL_DIR include CACHE PATH "Include install dir") - set(SYSCONF_INSTALL_DIR /etc CACHE PATH "Configuration install dir") - set(SHARE_INSTALL_DIR share CACHE PATH "Data install dir") -endif(WIN32 AND NOT MINGW) diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..625abb3 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,4 @@ +coverage: + ignore: + - tests + - src/tools
\ No newline at end of file diff --git a/data/canonicalize_filename.sh b/data/canonicalize_filename.sh new file mode 100644 index 0000000..49c4dec --- /dev/null +++ b/data/canonicalize_filename.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# Provide the canonicalize filename (physical filename with out any symlinks) +# like the GNU version readlink with the -f option regardless of the version of +# readlink (GNU or BSD). + +# This file is part of a set of unofficial pre-commit hooks available +# at github. +# Link: https://github.com/ddddavidmartin/Pre-commit-hooks +# Contact: David Martin, ddddavidmartin@fastmail.com + +########################################################### +# There should be no need to change anything below this line. + +# Canonicalize by recursively following every symlink in every component of the +# specified filename. This should reproduce the results of the GNU version of +# readlink with the -f option. +# +# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac +canonicalize_filename () { + local target_file="$1" + local physical_directory="" + local result="" + + # Need to restore the working directory after work. + local working_dir="`pwd`" + + cd -- "$(dirname -- "$target_file")" + target_file="$(basename -- "$target_file")" + + # Iterate down a (possible) chain of symlinks + while [ -L "$target_file" ] + do + target_file="$(readlink -- "$target_file")" + cd -- "$(dirname -- "$target_file")" + target_file="$(basename -- "$target_file")" + done + + # Compute the canonicalized name by finding the physical path + # for the directory we're in and appending the target file. + physical_directory="`pwd -P`" + result="$physical_directory/$target_file" + + # restore the working directory after work. + cd -- "$working_dir" + + echo "$result" +} diff --git a/data/check-code-style b/data/check-code-style new file mode 100755 index 0000000..3b9ca19 --- /dev/null +++ b/data/check-code-style @@ -0,0 +1,60 @@ +#!/bin/bash + +SOURCE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" + +UNCRUSTIFY=$(command -v uncrustify) +if [ -z "$UNCRUSTIFY" ]; +then + echo "Uncrustify is not installed on your system." + exit 1 +fi + +LINEUP_PARAMETERS="$SOURCE_ROOT/data/lineup-parameters" +if [ ! -x "$LINEUP_PARAMETERS" ]; +then + echo "lineup-parameters script is missing" + exit 1 +fi + +# create a filename to store our generated patch +prefix="libproxy-ccs" +suffix="$(date +%C%y-%m-%d_%Hh%Mm%Ss)" +patch="/tmp/$prefix-$suffix.patch" + +# clean up old patches +rm -f /tmp/$prefix*.patch + +pushd $SOURCE_ROOT +for DIR in src +do + # Aligning prototypes is not working yet, so avoid headers + for FILE in $(find "$DIR" -name "*.c" ! -path "*/contrib/*") + do + "$UNCRUSTIFY" -q -c "data/uncrustify.cfg" -f "$FILE" -o "$FILE.uncrustify" + "$LINEUP_PARAMETERS" "$FILE.uncrustify" > "$FILE.temp" && mv "$FILE.temp" "$FILE.uncrustify" + diff -urN "$FILE" "$FILE.uncrustify" | \ + sed -e "1s|--- |--- a/|" -e "2s|+++ |+++ b/|" >> "$patch" + rm "$FILE.uncrustify" + done +done +popd + +if [ ! -s "$patch" ] ; then + printf "** Commit is valid. \\o/\n" + rm -f "$patch" + exit 0 +fi + +printf "** Commit does not comply to the correct style :(\n\n" + +if hash colordiff 2> /dev/null; then + colordiff < $patch +else + cat "$patch" +fi + +printf "\n" +printf "You can apply these changed with: git apply $patch\n" +printf "\n" + +exit 1 diff --git a/data/install-git-hook.sh b/data/install-git-hook.sh new file mode 100644 index 0000000..355867b --- /dev/null +++ b/data/install-git-hook.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +cd "$MESON_SOURCE_ROOT" + +[ -d .git ] || exit 2 # not a git repo +[ ! -f .git/hooks/pre-commit ] || exit 2 # already installed + +cp data/pre-commit-hook .git/hooks/pre-commit +cp data/canonicalize_filename.sh .git/hooks/canonicalize_filename.sh +chmod +x .git/hooks/pre-commit +echo "Activated pre-commit hook"
\ No newline at end of file diff --git a/data/lineup-parameters b/data/lineup-parameters new file mode 100755 index 0000000..aae22de --- /dev/null +++ b/data/lineup-parameters @@ -0,0 +1,210 @@ +#!/usr/bin/env python3 +# +# Copyright © 2019 Michael Catanzaro <mcatanzaro@gnome.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Based on original C lineup-parameters by Sébastien Wilmet <swilmet@gnome.org> +# Rewritten in Python to allow simple execution from source directory. +# +# Usage: lineup-parameters [file] +# If the file is not given, stdin is read. +# The result is printed to stdout. +# +# The restrictions: +# - The function name must be at column 0, followed by a space and an opening +# parenthesis; +# - One parameter per line; +# - A parameter must follow certain rules (see the regex in the code), but it +# doesn't accept all possibilities of the C language. +# - The opening curly brace ("{") of the function must also be at column 0. +# +# If one restriction is missing, the function declaration is not modified. +# +# Example: +# +# gboolean +# frobnitz (Frobnitz *frobnitz, +# gint magic_number, +# GError **error) +# { +# ... +# } +# +# Becomes: +# +# gboolean +# frobnitz (Frobnitz *frobnitz, +# gint magic_number, +# GError **error) +# { +# ... +# } +# +# TODO: support "..." vararg parameter + +import argparse +import re +import sys + +from typing import NamedTuple + +# https://regexr.com/ is your friend. +functionNameRegex = re.compile(r'^(\w+) ?\(') +parameterRegex = re.compile( + r'^\s*(?P<type>(const\s+)?\w+)' + r'\s+(?P<stars>\**)' + r'\s*(?P<name>\w+)' + r'\s*(?P<end>,|\))' + r'\s*$') +openingCurlyBraceRegex = re.compile(r'^{\s*$') + + +def matchFunctionName(line): + match = functionNameRegex.match(line) + if match: + functionName = match.group(1) + firstParamPosition = match.end(0) + return (functionName, firstParamPosition) + return (None, 0) + + +class ParameterInfo(NamedTuple): + paramType: str + name: str + numStars: int + isLastParameter: bool + + +def matchParameter(line): + _, firstParamPosition = matchFunctionName(line) + match = parameterRegex.match(line[firstParamPosition:]) + if match is None: + return None + paramType = match.group('type') + assert(paramType is not None) + name = match.group('name') + assert(name is not None) + stars = match.group('stars') + numStars = len(stars) if stars is not None else 0 + end = match.group('end') + isLastParameter = True if end is not None and end == ')' else False + return ParameterInfo(paramType, name, numStars, isLastParameter) + + +def matchOpeningCurlyBrace(line): + return True if openingCurlyBraceRegex.match(line) is not None else False + + +# Length returned is number of lines the declaration takes up +def getFunctionDeclarationLength(remainingLines): + for i in range(len(remainingLines)): + currentLine = remainingLines[i] + parameterInfo = matchParameter(currentLine) + if parameterInfo is None: + return 0 + if parameterInfo.isLastParameter: + if i + 1 == len(remainingLines): + return 0 + nextLine = remainingLines[i + 1] + if not matchOpeningCurlyBrace(nextLine): + return 0 + return i + 1 + return 0 + + +def getParameterInfos(remainingLines, length): + parameterInfos = [] + for i in range(length): + parameterInfos.append(matchParameter(remainingLines[i])) + return parameterInfos + + +def computeSpacing(parameterInfos): + maxTypeLength = 0 + maxStarsLength = 0 + for parameterInfo in parameterInfos: + maxTypeLength = max(maxTypeLength, len(parameterInfo.paramType)) + maxStarsLength = max(maxStarsLength, parameterInfo.numStars) + return (maxTypeLength, maxStarsLength) + + +def printParameter(parameterInfo, maxTypeLength, maxStarsLength, outfile): + outfile.write(f'{parameterInfo.paramType:<{maxTypeLength + 1}}') + paramNamePaddedWithStars = f'{parameterInfo.name:*>{parameterInfo.numStars + len(parameterInfo.name)}}' + outfile.write(f'{paramNamePaddedWithStars:>{maxStarsLength + len(parameterInfo.name)}}') + + +def printFunctionDeclaration(remainingLines, length, useTabs, outfile): + functionName, _ = matchFunctionName(remainingLines[0]) + assert(functionName is not None) + outfile.write(f'{functionName} (') + numSpacesToParenthesis = len(functionName) + 2 + whitespace = '' + if useTabs: + tabs = ''.ljust(numSpacesToParenthesis // 8, '\t') + spaces = ''.ljust(numSpacesToParenthesis % 8) + whitespace = tabs + spaces + else: + whitespace = ''.ljust(numSpacesToParenthesis) + parameterInfos = getParameterInfos(remainingLines, length) + maxTypeLength, maxStarsLength = computeSpacing(parameterInfos) + numParameters = len(parameterInfos) + for i in range(numParameters): + parameterInfo = parameterInfos[i] + if i != 0: + outfile.write(whitespace) + printParameter(parameterInfo, maxTypeLength, maxStarsLength, outfile) + if i + 1 != numParameters: + outfile.write(',\n') + outfile.write(')\n') + + +def parseContents(infile, useTabs, outfile): + lines = infile.readlines() + i = 0 + while i < len(lines): + line = lines[i] + functionName, _ = matchFunctionName(line) + if functionName is None: + outfile.write(line) + i += 1 + continue + remainingLines = lines[i:] + length = getFunctionDeclarationLength(remainingLines) + if length == 0: + outfile.write(line) + i += 1 + continue + printFunctionDeclaration(remainingLines, length, useTabs, outfile) + i += length + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description='Line up parameters of C functions') + parser.add_argument('infile', nargs='?', + type=argparse.FileType('r'), + default=sys.stdin, + help='input C source file') + parser.add_argument('-o', metavar='outfile', nargs='?', + type=argparse.FileType('w'), + default=sys.stdout, + help='where to output modified file') + parser.add_argument('--tabs', action='store_true', + help='whether use tab characters in the output') + args = parser.parse_args() + parseContents(args.infile, args.tabs, args.o) + args.infile.close() + args.o.close() diff --git a/data/pre-commit-hook b/data/pre-commit-hook new file mode 100644 index 0000000..24b2ff2 --- /dev/null +++ b/data/pre-commit-hook @@ -0,0 +1,17 @@ +#!/bin/bash + +. "$(dirname -- "$0")/canonicalize_filename.sh" + + +# exit on error +set -e + +# Absolute path to this script +SCRIPT="$(canonicalize_filename "$0")" +# Absolute path this script is in, e.g. /home/user/bin/ +SCRIPTPATH="$(dirname -- "$SCRIPT")" + +echo $SCRIPTPATH +cd $SCRIPTPATH/../../ +data/check-code-style +cd -
\ No newline at end of file diff --git a/data/uncrustify.cfg b/data/uncrustify.cfg new file mode 100644 index 0000000..211c438 --- /dev/null +++ b/data/uncrustify.cfg @@ -0,0 +1,111 @@ +# indent using tabs +output_tab_size = 2 +indent_columns = output_tab_size +indent_with_tabs = 0 + +# indent case +indent_switch_case = indent_columns +indent_case_brace = 0 + +indent_ternary_operator = 2 + +# newlines +newlines = lf +nl_after_semicolon = true +nl_start_of_file = remove +nl_end_of_file = force +nl_end_of_file_min = 1 + +# spaces +sp_return_paren = force # "return (1);" vs "return(1);" +sp_sizeof_paren = force # "sizeof (int)" vs "sizeof(int)" +sp_assign = force +sp_arith = force +sp_bool = force +sp_compare = force +sp_after_comma = force +sp_case_label = force +sp_else_brace = force +sp_brace_else = force +sp_func_call_paren = force # "foo (" vs "foo(" +sp_func_proto_paren = force # "int foo ();" vs "int foo();" +sp_func_def_paren = force +sp_before_ptr_star = force +sp_after_ptr_star_qualifier = force # "const char * const" vs. "const char *const" +sp_after_ptr_star = remove +sp_between_ptr_star = remove # "**var" vs "* *var" +sp_inside_paren = remove # "( 1 )" vs "(1)" +sp_inside_fparen = remove # "( 1 )" vs "(1)" - functions +sp_inside_sparen = remove # "( 1 )" vs "(1)" - if/for/etc +sp_after_cast = remove # "(int) a" vs "(int)a" +sp_func_call_user_paren = remove # For gettext, "_()" vs. "_ ()" +set func_call_user _ N_ C_ # Needed for sp_after_cast +sp_before_semi = remove +sp_paren_paren = remove # Space between (( and )) + +eat_blanks_before_close_brace = true +eat_blanks_after_open_brace = true + +# K&R style for curly braces +nl_assign_brace = remove +nl_enum_brace = remove # "enum {" vs "enum \n {" +nl_union_brace = remove # "union {" vs "union \n {" +nl_struct_brace = remove # "struct {" vs "struct \n {" +nl_do_brace = remove # "do {" vs "do \n {" +nl_if_brace = remove # "if () {" vs "if () \n {" +nl_for_brace = remove # "for () {" vs "for () \n {" +nl_else_brace = remove # "else {" vs "else \n {" +nl_elseif_brace = remove # "else if {" vs "else if \n {" +nl_while_brace = remove # "while () {" vs "while () \n {" +nl_switch_brace = remove # "switch () {" vs "switch () \n {" +nl_before_case = false +nl_fcall_brace = add # "foo() {" vs "foo()\n{" +nl_fdef_brace = add # "int foo() {" vs "int foo()\n{" +nl_brace_while = remove +nl_brace_else = remove +nl_squeeze_ifdef = true +nl_case_colon_brace = remove +nl_after_brace_open = true + +# Function calls and parameters +nl_func_paren = remove +nl_func_def_paren = remove +nl_func_decl_start = remove +nl_func_def_start = remove +nl_func_decl_args = force +nl_func_def_args = force +nl_func_decl_end = remove +nl_func_def_end = remove +nl_func_type_name = force + +# Code modifying options (non-whitespace) +mod_remove_extra_semicolon = true + +# Align +align_func_params = true +align_single_line_func = true +align_var_def_star_style = 2 + +# one liners +nl_func_leave_one_liners = true +nl_enum_leave_one_liners = true +nl_assign_leave_one_liners = true + +# Comments +cmt_cpp_to_c = true # "/* */" vs. "//" +cmt_convert_tab_to_spaces = true +cmt_star_cont = true # Whether to put a star on subsequent comment lines +cmt_sp_after_star_cont = 1 # The number of spaces to insert after the star on subsequent comment lines +cmt_reflow_mode = 2 +cmt_c_nl_start = false # false/true +cmt_c_nl_end = true # false/true +# For multi-line comments with a '*' lead, remove leading spaces if the first and last lines of +# the comment are the same length. Default=True +cmt_multi_check_last = true +# Disable touching multi-line comments. +cmt_indent_multi = false + +# Encoding +utf8_bom = remove +utf8_force = true + diff --git a/doc/libproxy_files.dia b/doc/libproxy_files.dia Binary files differdeleted file mode 100644 index ba61fa6..0000000 --- a/doc/libproxy_files.dia +++ /dev/null diff --git a/docs/applications.md b/docs/applications.md new file mode 100644 index 0000000..79fe046 --- /dev/null +++ b/docs/applications.md @@ -0,0 +1,24 @@ +Title: Applications - Who is using Libproxy? +Slug: ApplicationMatrix + +# Applications - Who is using Libproxy? + + +| Application | Upstream | Patches | +| --- | -- | -- | +| apt | NO | AVAILABLE | +| cURL | NO | AVAILABLE | +| eid-viewer | YES | - | +| glib-networking | YES | - | +| libQt5Network | YES | - | +| libzypp | YES | - | +| Mozilla Firefox | YES | - | +| neon | YES | - | +| openconnect | YES | - | +| python-requests | NO | AVAILABLE | +| seamonkey | YES | - | +| signond | YES | - | +| signond_ui | YES | - | +| vagalume | YES | - | +| wget | NO | [Patch](https://build.opensuse.org/package/show/openSUSE:Factory/wget) | + diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..35c3596 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,15 @@ +Title: Architecture - Difference between library and D-Bus service +Slug: Architecture + + +# Architecture + +Starting with release 0.5.0 Libproxy is making use of glib. glib has many +advantages and helps to get rid of one of the major issues we have had with +previous versions of Libproxy. To name a few advantages: + +- Testing Framework +- Make use of existing plugin loader +- Automatic documentation out of code +- Gobject Introspection bindings for almost every programming language + diff --git a/docs/build-steps.md b/docs/build-steps.md new file mode 100644 index 0000000..2590c4e --- /dev/null +++ b/docs/build-steps.md @@ -0,0 +1,84 @@ +Title: Build steps - How to compile libproxy +Slug: building + +# Build steps - How to compile libproxy + +## Fedora + +### Dependencies + +``` +sudo dnf install glib2-devel duktape-devel libsoup3-devel meson gcovr gi-docgen libcurl-devel vala gsettings-desktop-schemas-devel gobject-introspection-devel +``` + +### Build Setup + +``` +meson setup build +``` + +### Compilation + +``` +ninja -C build +``` + +### Installation + +``` +ninja -C build install +``` + +## OS X + +### Dependencies + +``` +pip install meson ninja +brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen curl vala +``` + +### Build Setup + +``` +meson setup build +``` + +### Compilation + +``` +ninja -C build +``` + +### Installation + +``` +ninja -C build install +``` + +## Windows (MSYS2) + +### Dependencies + +``` +pacman -S base-devel git mingw-w64-x86_64-toolchain mingw-w64-x86_64-ccache mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gobject-introspection mingw-w64-x86_64-python-gobject mingw-w64-x86_64-meson mingw-w64-x86_64-glib mingw-w64-x86_64-duktape mingw-w64-x86_64-gi-docgen mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-curl mingw-w64-x86_64-vala +``` + +### Build Setup + +``` +meson setup build +``` + +### Compilation + +``` +ninja -C build +``` + +### Installation + +``` +ninja -C build install +``` + diff --git a/docs/configuration-logic.md b/docs/configuration-logic.md new file mode 100644 index 0000000..783a8db --- /dev/null +++ b/docs/configuration-logic.md @@ -0,0 +1,87 @@ +Title: Configuration Logic +Slug: Design + +# Configuration Logic + +## Introduction +As the proxy configuration predates libproxy, we need to consider previous +implementation behavior to ensure consistency with user expectations. This page +presents analyses of well known implementation base on the platform they run on. + +## Linux +On Linux the pioneer of proxy support is Mozilla browsers (former Netscape). +But other browsers do support proxy and has it's own proxy configuration +interpretation logic. Current GNOME proxy settings is a copy of Firefox +settings. + +### Firefox +When using Firefox internal manual settings, the proxy is selected base on the +most specific proxy (e.g. HTTP before SOCKS). Only one proxy is selected, if +connection to that proxy fails, then connection fails. + +``` + IF protocol specific proxy is set THEN use it + ELSE IF SOCKS proxy is set THEN use it + ELSE use direct connection. +``` + +### Firefox and Chromium (with GNOME settings) +After some testing we found that Chromium mimics perfectly Firefox behavior +when using system settings. When using manual proxy configuration mode, those +browsers chooses a proxy base on the most generic solution (SOCKS) to the most +specific (per protocol proxies), with an exception when a single proxy is set +for all protocols. Only one protocol is selected and no fallback will occur in +the case of failures. Those browsers support SOCKS, HTTP, HTTPS, FTP and +Firefox also support Gopher. You can also set the configuration to use a +specific PAC file or to automatically discover one (WPAD) but those does not +contain any special logic. Next is the logic represent as pseudo code: + +``` + IF not using same proxy for all protocols THEN + IF SOCKS is set THEN use it + ELSE IF protocol specific proxy is set THEN use it + ELSE IF using same proxy for all protocols THEN + IF SOCKS is set THEN use it + IF no proxy has been set THEN use direct connection +``` + +## OS X +OS X uses it's own way for proxy settings. It supports protocols including +SOCKS, HTTP, HTTPS, FTP, Gopher, RTSP, and automatic configuration through PAC +files. For sake of simplicity, we have tested the logic with the default browser +Safari. + +### Safari +Safari interpret proxy logic differently from Firefox. If multiple proxy are +configured, it try each of them until a connection is established. From our +testing the order seems to be from most specific to most generic (starting with +manual configuration). Next is the logic represented as pseudo code: + +``` + DEFINE proxy_list as list + IF protocol specific proxy is set THEN add it to proxy_list + IF SOCKS proxy is set THEN append it to proxy_list + IF PAC auto-configuration is set THEN append it to proxy_list + FOREACH proxy in proxy_list + connect to proxy + IF connection failed THEN continue + ELSE stop +``` + +## Windows +Windows user most often use Internet Explorer, Firefox or Opera for browsing. +Analyses as shown that Firefox acts exactly the same as on Linux, except that +same logic is applied for internal settings and system setting (IE settings). +Internet explorer also act the same way, and Opera only support protocol +specific proxies (no SOCKS). So essentially, if chooses choose the most +specific proxy, and if that one fails the own connection fails. + +## Conclusion +Base on current result, we see that the most common logic is to select a proxy +starting from the most specific (HTTP, FTP, etc.) to the least specific +(SOCKS, PAC then WPAD). OS X pushes a bit further by trying all the configure +proxy that match the protocol. This technique is interesting for libproxy +since it warranty that connection will be possible for all cases covered by +the others. The only difference with the GNOME environment is that OS X may +connect through an HTTP server while Firefox and Chromium (on Gnome) would +connect to a SOCKS server if both are available. diff --git a/docs/libproxy.svg b/docs/libproxy.svg new file mode 100644 index 0000000..70d3793 --- /dev/null +++ b/docs/libproxy.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g fill="#2a488c"><path d="M4.96 8.635V11H1.367c-.206 0-.368.205-.368.467v1.058c0 .262.162.467.368.467h10.264c.206 0 .368-.205.368-.467v-1.058c0-.262-.162-.467-.368-.467H7.977V8.635z"/><path d="M3.8 0C2.849 0 2 .793 2 1.746v6.613c0 .953.849 1.746 1.868 1.746h5.264c1.02 0 1.868-.793 1.868-1.746V1.746C11 .793 10.151 0 9.132 0zM4 2h5c0 .317 0-.316 0 0v6H4s0 .044 0 0V2c0-.044 0 0 0 0z" style="line-height:normal;-inkscape-font-specification:'Bitstream Vera Sans';text-indent:0;text-align:start;text-decoration-line:none;text-transform:none;marker:none" color="#fff" font-weight="400" font-family="Bitstream Vera Sans" overflow="visible"/><path d="M5 2.971h3v1.003H5zm2 2.005h1v1.002H7z" style="marker:none" color="#fff" overflow="visible"/><path d="M9.229 3c.07 0 0 .209 0 .476v1.078c0 .267.07.476.16.476h4.451c.09 0 .16-.209.16-.476V3.476c0-.267-.07-.476-.16-.476-.16 0-4.585.063-4.611 0zm-3.256 8.624c.08-.06.253.039.394.223l.573.747c.142.184.191.375.112.435l-3.935 2.954c-.08.059-.253-.039-.395-.224l-.573-.746c-.141-.184-.19-.376-.111-.435 0 0 3.946-2.893 3.935-2.954z"/><path d="M7.027 11.624c-.08-.06-.253.039-.394.223l-.573.747c-.142.184-.191.375-.112.435l3.935 2.954c.08.059.253-.039.395-.224l.573-.746c.141-.184.19-.376.111-.435 0 0-3.946-2.893-3.935-2.954z"/></g></svg>
\ No newline at end of file diff --git a/docs/meson.build b/docs/meson.build new file mode 100644 index 0000000..3c2fae9 --- /dev/null +++ b/docs/meson.build @@ -0,0 +1,47 @@ +if get_option('docs') + +expand_content_md_files = [ + 'architecture.md', + 'applications.md', + 'build-steps.md', + 'configuration-logic.md', + 'perl.md', + 'python.md', + 'ruby.md', + 'vala.md', +] + +toml_data = configuration_data() +toml_data.set('VERSION', meson.project_version()) + +px_toml = configure_file( + input: 'px.toml.in', + output: 'px.toml', + configuration: toml_data +) + +gidocgen = find_program('gi-docgen') + +docs_dir = datadir / 'doc' + +custom_target('px-doc', + input: [ px_toml, libproxy_gir[0] ], + output: 'libproxy-@0@'.format(api_version), + command: [ + gidocgen, + 'generate', + '--quiet', + '--add-include-path=@0@'.format(meson.current_source_dir() + '/src'), + '--config=@INPUT0@', + '--output-dir=@OUTPUT@', + '--no-namespace-dir', + '--content-dir=@0@'.format(meson.current_source_dir()), + '@INPUT1@', + ], + depend_files: [ expand_content_md_files ], + build_by_default: true, + install: true, + install_dir: docs_dir, +) + +endif diff --git a/docs/perl.md b/docs/perl.md new file mode 100644 index 0000000..eee6bbe --- /dev/null +++ b/docs/perl.md @@ -0,0 +1,21 @@ +Title: How to use libproxy in Perl +Slug: snippets + +# How to use libproxy in Perl + +``` +#!/usr/bin/perl +use warnings; +use Glib::Object::Introspection; +Glib::Object::Introspection->setup( + basename => 'Px', + version => '1.0', + package => 'Px'); + +my $pf = new Px::ProxyFactory; + +$proxies = $pf->get_proxies("https://github.com/libproxy/libproxy"); +foreach my $proxy (@$proxies) { + print $proxy."\n"; +} +``` diff --git a/docs/proxy-authentication.md b/docs/proxy-authentication.md new file mode 100644 index 0000000..de7a905 --- /dev/null +++ b/docs/proxy-authentication.md @@ -0,0 +1,7 @@ +Title: Proxy Authentication +Slug: ProxyAuthentication + + +# Proxy Authentication +Because proxy authentication is protocol specific, it is outside the scope of this library. libproxy tells you WHICH proxy servers to try to use, +not HOW to use them. diff --git a/docs/px.toml.in b/docs/px.toml.in new file mode 100644 index 0000000..8cab536 --- /dev/null +++ b/docs/px.toml.in @@ -0,0 +1,71 @@ +[library] +version = "@VERSION@" +description = "Simplifyed proxy handling" +authors = "libproxy Team" +license = "LGPL-2.1-or-later" +browse_url = "https://github.com/libproxy/libproxy" +repository_url = "https://github.com/libproxy/libproxy" +website_url = "https://libproxy.github.io/libproxy/" +# logo_url = "libproxy.svg" +dependencies = [ + "GObject-2.0", + "Gio-2.0", + "GLib-2.0", + "Soup-3.0", + "curl-1.0", +] +devhelp = true +search_index = true + +[dependencies."GObject-2.0"] +name = "GObject" +description = "The base type system library" +docs_url = "https://developer.gnome.org/gobject/stable" + +[dependencies."Gio-2.0"] +name = "Gio" +description = "Gio is a library providing useful classes for general purpose I/O, networking, IPC, settings, and other high level application functionality" +docs_url = "https://developer.gnome.org/gio/stable" + +[dependencies."GLib-2.0"] +name = "GLib" +description = "The base utility library" +docs_url = "https://developer.gnome.org/glib/stable" + +[dependencies."Soup-3.0"] +name = "Soup" +description = "HTTP client/server library for GNOME" +docs_url = "https://libsoup.org/libsoup-3.0/index.html" + +[dependencies."curl-1.0"] +name = "cURL" +description = "Library for transferring data" +docs_url = "https://github.com/curl/curl" + +[theme] +name = "basic" +show_index_summary = false +show_class_hierarchy = false + +[source-location] +# The base URL for the web UI +base_url = "https://gitlab.gnome.org/jbrummer/libproxy/-/blob/main/" +# The format for links, using "filename" and "line" for the format +file_format = "{filename}#L{line}" + +[extra] +content_files = [ + "architecture.md", + "applications.md", + "build-steps.md", + "configuration-logic.md", + "proxy-authentication.md", + "perl.md", + "python.md", + "ruby.md", + "vala.md", +] + +content_images = [ + "libproxy.svg" +] diff --git a/docs/python.md b/docs/python.md new file mode 100644 index 0000000..8094e0b --- /dev/null +++ b/docs/python.md @@ -0,0 +1,30 @@ +Title: How to use libproxy in Python +Slug: snippets + +# How to use libproxy in Python + +``` +import gi +gi.require_version('Libproxy', '1.0') +from gi.repository import Libproxy +import requests + +url = 'https://github.com/libproxy/libproxy' + +pf = Libproxy.ProxyFactory() +proxies = pf.get_proxies(url) + +success = False +for proxy in proxies: + response = requests.get(url) #, proxies=proxies) + + if response.status_code == 200: + success = True + break + +if success: + print(f"The requested URL {url} could be retrieved using the current setup!") +else: + print(f"The requested URL {url} could *NOT* be retrieved using the current setup") +``` + diff --git a/docs/ruby.md b/docs/ruby.md new file mode 100644 index 0000000..ceddbd8 --- /dev/null +++ b/docs/ruby.md @@ -0,0 +1,20 @@ +Title: How to use libproxy in Ruby +Slug: snippets + +# How to use libproxy in Ruby + +``` +#!/usr/bin/ruby + +require 'gir_ffi' +GirFFI.setup :Libproxy + +pf = Libproxy::ProxyFactory.new() + +proxies = pf.get_proxies("https://github.com/libproxy/libproxy") +proxies.each do |proxy| + puts proxy +end + +pf.free() +``` diff --git a/docs/samples.md b/docs/samples.md new file mode 100644 index 0000000..f73aa0f --- /dev/null +++ b/docs/samples.md @@ -0,0 +1,4 @@ +Title: How to use libproxy in language X? +Slug: building + +# Samples - How to use libproxy in language X? diff --git a/samples/dotnet/Makefile b/docs/samples/dotnet/Makefile index 587f83b..587f83b 100644 --- a/samples/dotnet/Makefile +++ b/docs/samples/dotnet/Makefile diff --git a/samples/dotnet/proxy.cs b/docs/samples/dotnet/proxy.cs index a8ce5e4..a8ce5e4 100644 --- a/samples/dotnet/proxy.cs +++ b/docs/samples/dotnet/proxy.cs diff --git a/samples/libcurl/Makefile b/docs/samples/libcurl/Makefile index 35b4597..35b4597 100644 --- a/samples/libcurl/Makefile +++ b/docs/samples/libcurl/Makefile diff --git a/samples/libcurl/curlget.c b/docs/samples/libcurl/curlget.c index 00954e9..00954e9 100644 --- a/samples/libcurl/curlget.c +++ b/docs/samples/libcurl/curlget.c diff --git a/samples/perl/sample.pl b/docs/samples/perl/sample.pl index e8850fc..e8850fc 100644 --- a/samples/perl/sample.pl +++ b/docs/samples/perl/sample.pl diff --git a/samples/vala/Makefile b/docs/samples/vala/Makefile index 3e42a34..3e42a34 100644 --- a/samples/vala/Makefile +++ b/docs/samples/vala/Makefile diff --git a/samples/vala/sample.vala b/docs/samples/vala/sample.vala index 1cec8cf..1cec8cf 100644 --- a/samples/vala/sample.vala +++ b/docs/samples/vala/sample.vala diff --git a/docs/vala.md b/docs/vala.md new file mode 100644 index 0000000..b1332ac --- /dev/null +++ b/docs/vala.md @@ -0,0 +1,32 @@ +Title: How to use libproxy in Vala +Slug: snippets + +# How to use libproxy in Vala + + +## Makefile + +``` +all: sample + +sample: sample.vala + valac --pkg libproxy-1.0 sample.vala + +clean: + rm sample +``` + +## Source + +``` +using px; + +void main() { + var pf = new px.ProxyFactory(); + string[] proxies = pf.get_proxies("https://github.com/libproxy/libproxy"); + + foreach (string proxy in proxies) { + stdout.printf ("%s\n", proxy); + } +} +``` diff --git a/docs/version.xml.in b/docs/version.xml.in new file mode 100644 index 0000000..d78bda9 --- /dev/null +++ b/docs/version.xml.in @@ -0,0 +1 @@ +@VERSION@ diff --git a/libmodman/CMakeLists.txt b/libmodman/CMakeLists.txt deleted file mode 100644 index 8264b33..0000000 --- a/libmodman/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -### Main library -# Flags / Definitions / Environment -if (WIN32) - add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) -else(WIN32) - set(CMAKE_CXX_FLAGS "-fvisibility=hidden -fPIC ${CMAKE_CXX_FLAGS}") -endif(WIN32) -include_directories(${CMAKE_SOURCE_DIR}) - -add_library(modman STATIC - module.hpp - module_manager.hpp - module_manager.cpp) -if(NOT WIN32) - target_link_libraries(modman ${CMAKE_DL_LIBS}) -endif() - -### Tests -add_testdirectory(test) diff --git a/libmodman/module.hpp b/libmodman/module.hpp deleted file mode 100644 index 2d974aa..0000000 --- a/libmodman/module.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * 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 - ******************************************************************************/ - -#ifndef MODULE_HPP_ -#define MODULE_HPP_ - -#include <cstdlib> // For NULL - -#ifndef MM_MODULE_BUILTIN -#define MM_MODULE_BUILTIN -#endif - -#ifdef _MSC_VER -#define __MM_DLL_EXPORT __declspec(dllexport) -#else -#define __MM_DLL_EXPORT __attribute__ ((visibility("default"))) -#endif - -#define __MM_MODULE_VERSION 2 -#define __MM_MODULE_VARNAME__(suffix, name) mm_ ## name ## _ ## suffix -#define __MM_MODULE_VARNAME_(suffix, name) __MM_MODULE_VARNAME__(suffix, name) -#define __MM_MODULE_VARNAME(name) __MM_MODULE_VARNAME_(MM_MODULE_BUILTIN, name) - -#define MM_MODULE_INIT(mtype, minit, mtest, msymb, msmod) \ - extern "C" __MM_DLL_EXPORT struct mm_module __MM_MODULE_VARNAME(info); \ - struct mm_module __MM_MODULE_VARNAME(info) = { \ - __MM_MODULE_VERSION, \ - # mtype, \ - mtype::base_type, \ - minit, mtest, msymb, msmod \ - } - -#define MM_MODULE_INIT_EZ(clsname, mtest, msymb, msmod) \ - static libmodman::base_extension** clsname ## _init() { \ - libmodman::base_extension** retval = new libmodman::base_extension*[2]; \ - retval[0] = new clsname(); \ - retval[1] = NULL; \ - return retval; \ - } \ - static bool clsname ## _test() { return mtest; } \ - MM_MODULE_INIT(clsname, clsname ## _init, clsname ## _test, msymb, msmod) - -/* Helper macro for loading builtins */ - -#define MM_DEF_BUILTIN(modname) \ - extern "C" struct mm_module __MM_MODULE_VARNAME_(modname,info) - -#define MM_BUILTIN(modname) __MM_MODULE_VARNAME_(modname,info) - - -namespace libmodman { - -class __MM_DLL_EXPORT base_extension { -public: - static const char* base_type() { return NULL; } - static bool singleton() { return false; } - virtual ~base_extension() {} - virtual const char* get_base_type() const =0; - virtual bool operator<(const base_extension&) const =0; -}; - -template <class basetype, bool sngl=false> -class __MM_DLL_EXPORT extension : public base_extension { -public: -#ifdef _MSC_VER - static const char* base_type() { return __FUNCSIG__; } -#else - static const char* base_type() { return __PRETTY_FUNCTION__; } -#endif - - static bool singleton() { return sngl; } - virtual const char* get_base_type() const { return basetype::base_type(); } - virtual bool operator<(const base_extension&) const { return false; }; -}; - -} - -extern "C" { - -struct __MM_DLL_EXPORT mm_module -{ -/* 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)(); - bool (*test)(); - const char* symb; - const char* smod; -}; - -} - -#endif /* MODULE_HPP_ */ diff --git a/libmodman/module_manager.cpp b/libmodman/module_manager.cpp deleted file mode 100644 index 88e6198..0000000 --- a/libmodman/module_manager.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * 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> // For sort() -#include <sys/stat.h> // For stat() -#include <iostream> -#include <typeinfo> - -#ifdef WIN32 -#include <windows.h> -#else -#include <dlfcn.h> // For dlopen(), etc... -#include <dirent.h> // For opendir(), readdir(), closedir() -#endif - -#include "module_manager.hpp" -using namespace libmodman; - -#include <cstdio> - -#define _LOAD_FAIL -1 -#define _LOAD_LAZY 0 -#define _LOAD_SUCC 1 - -#ifdef WIN32 -#define pdlmtype HMODULE -#define pdlopenl(filename) LoadLibraryEx(filename, NULL, DONT_RESOLVE_DLL_REFERENCES) -#define pdlclose(module) FreeLibrary((pdlmtype) module) -static void* pdlsym(pdlmtype mod, const string &sym) { - return (void *) GetProcAddress(mod, sym.c_str()); -} - -static pdlmtype pdlreopen(const char* filename, pdlmtype module) { - pdlclose(module); - return LoadLibrary(filename); -} - -static string pdlerror() { - std::string e; - LPTSTR msg; - - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &msg, - 0, - NULL); - e = std::string((const char*) msg); - LocalFree(msg); - return e; -} - -static bool pdlsymlinked(const char* modn, const char* symb) { - return (GetProcAddress(GetModuleHandle(modn), symb) != NULL || \ - GetProcAddress(GetModuleHandle(NULL), symb) != NULL); -} - -static string prep_type_name(string name) { - string prefix = "<class "; - string suffix = ","; - if (name.find(prefix) != name.npos) - name = name.substr(name.find(prefix) + prefix.size()); - if (name.find(suffix) != name.npos) - name = name.substr(0, name.find(suffix)); - return name; -} -#else -#define pdlmtype void* -#define pdlopenl(filename) dlopen(filename, RTLD_LAZY | RTLD_LOCAL) -#define pdlclose(module) dlclose((pdlmtype) module) -#define pdlreopen(filename, module) module -static void* pdlsym(pdlmtype mod, const string &sym) { - return dlsym(mod, sym.c_str()); -} - -static string pdlerror() { - return dlerror(); -} - -bool pdlsymlinked(const char* modn, const char* symb) { - void* mod = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL); - if (mod) { - void* sym = dlsym(mod, symb); - dlclose(mod); - return sym != NULL; - } - return false; -} - -#define prep_type_name(name) name -#endif - -#define _str(s) #s -#define __str(s) _str(s) - -#ifndef _MOD_SUFFIX -#ifdef WIN32 -#define _MOD_SUFFIX "dll" -#define CR "" -#else -#define _MOD_SUFFIX "so" -#define CR "\r" -#endif -#endif - -module_manager::~module_manager() { - // Free all extensions - for (map<string, vector<base_extension*> >::iterator i=this->extensions.begin() ; i != this->extensions.end() ; i++) { - for (vector<base_extension*>::iterator j=i->second.begin() ; j != i->second.end() ; j++) - delete *j; - i->second.clear(); - } - this->extensions.clear(); - - // Free all modules - for (set<void*>::iterator i=this->modules.begin() ; i != this->modules.end() ; i++) - pdlclose(*i); - this->modules.clear(); -} - -static int load(map<string, vector<base_extension*> >& extensions, - set<string>& singletons, - mm_module *mod, - bool lazy, - bool symbreq) { - const char* debug = getenv("_MM_DEBUG"); - - if (!mod || mod->vers != __MM_MODULE_VERSION || !mod->type || !mod->init) { - if (debug) - cerr << "failed!" << endl - << "\tUnable to find basic module info!" << endl; - return _LOAD_FAIL; - } - - // Get the module type - string types = mod->type(); - - // Make sure the type is registered - if (extensions.find(types) == extensions.end()) { - if (debug) - cerr << "failed!" << endl - << "\tUnknown extension type: " << prep_type_name(types) << endl; - return _LOAD_FAIL; - } - - // If this is a singleton and we already have an instance, don't instantiate - if (singletons.find(types) != singletons.end() && - extensions[types].size() > 0) { - if (debug) - cerr << "failed!" << endl - << "\tNot loading subsequent singleton for: " << prep_type_name(types) << endl; - return _LOAD_FAIL; - } - - // If a symbol is defined, we'll search for it in the main process - if (mod->symb && mod->smod && !pdlsymlinked(mod->smod, mod->symb)) { - // If the symbol is not found and the symbol is required, error - if (symbreq) { - if (debug) - cerr << "failed!" << endl - << "\tUnable to find required symbol: " - << mod->symb << endl; - return _LOAD_FAIL; - } - - // If the symbol is not found and not required, we'll load only - // if there are no other modules of this type - else if (extensions[types].size() > 0) { - if (debug) - cerr << "failed!" << endl - << "\tUnable to find required symbol: " - << mod->symb << endl; - return _LOAD_FAIL; - } - } - - // We've passed all the tests this far, do it again in non-lazy mode - if (lazy) return _LOAD_LAZY; - - // If our execution test succeeds, call init() - if ((mod->test && mod->test()) || !mod->test) { - base_extension** exts = mod->init(); - if (!exts) { - if (debug) - cerr << "failed!" << endl - << "\tinit() returned no extensions!" << endl; - return _LOAD_FAIL; - } - - if (debug) - cerr << "success" << endl; - - // init() returned extensions we need to register - for (unsigned int i=0 ; exts[i] ; i++) { - if (debug) - cerr << "\tRegistering " - << typeid(*exts[i]).name() << "(" - << prep_type_name(exts[i]->get_base_type()) << ")" << endl; - extensions[exts[i]->get_base_type()].push_back(exts[i]); - } - delete[] exts; - return _LOAD_SUCC; - } - - if (debug) - cerr << "failed!" << endl - << "\tTest execution failed." << endl; - return _LOAD_FAIL; -} - -bool module_manager::load_builtin(mm_module *mod) { - const char* debug = getenv("_MM_DEBUG"); - if (debug) - cerr << "loading : builtin module " << mod->name << CR; - - // Do the load with the specified prefix - int status = load(this->extensions, this->singletons, mod, false, false); - return status == _LOAD_SUCC; -} - -bool module_manager::load_file(const string &filename, bool symbreq) { - const char* debug = getenv("_MM_DEBUG"); - - // Stat the file to make sure it is a file - struct stat st; - if (stat(filename.c_str(), &st) != 0) return false; - if ((st.st_mode & S_IFMT) != S_IFREG) return false; - - if (debug) - cerr << "loading : " << filename << CR; - - // Open the module - pdlmtype dlobj = pdlopenl(filename.c_str()); - if (!dlobj) { - if (debug) - cerr << "failed!" << endl - << "\t" << pdlerror() << endl; - return false; - } - - // If we have already loaded this module, return true - if (this->modules.find((void*) dlobj) != this->modules.end()) { - if (debug) - cerr << "preload" << endl; - pdlclose(dlobj); - return true; - } - - // Try and finish the load - struct mm_module *mod_info = (mm_module*) pdlsym(dlobj, __str(__MM_MODULE_VARNAME(info))); - int status = load(this->extensions, this->singletons, mod_info, true, symbreq); - if (status == _LOAD_LAZY) { // Reload the module in non-lazy mode - dlobj = pdlreopen(filename.c_str(), dlobj); - if (!dlobj) { - if (debug) - cerr << "failed!" << endl - << "\tUnable to reload module: " << pdlerror() << endl; - return false; - } - mod_info = (mm_module*) pdlsym(dlobj, __str(__MM_MODULE_VARNAME(info))); - status = load(this->extensions, this->singletons, mod_info, false, symbreq); - } - if (status == _LOAD_FAIL) { - pdlclose(dlobj); - return false; - } - - // Add the dlobject to our known modules - this->modules.insert((void*) dlobj); - - // Yay, we did it! - return true; -} - -bool module_manager::load_dir(const string &dirname, bool symbreq) { - vector<string> files; - -#ifdef WIN32 - WIN32_FIND_DATA fd; - HANDLE search; - - string srch = dirname + "\\*." + _MOD_SUFFIX; - search = FindFirstFile(srch.c_str(), &fd); - if (search != INVALID_HANDLE_VALUE) { - do { - files.push_back(dirname + "\\" + fd.cFileName); - } while (FindNextFile(search, &fd)); - FindClose(search); - } -#else - struct dirent *ent; - - DIR *moduledir = opendir(dirname.c_str()); - if (moduledir) { - while((ent = readdir(moduledir))) { - string tmp = ent->d_name; - if (tmp.find(_MOD_SUFFIX, tmp.size() - string(_MOD_SUFFIX).size()) != tmp.npos) - files.push_back(dirname + "/" + tmp); - } - closedir(moduledir); - } -#endif - - // Perform our load alphabetically - sort(files.begin(), files.end()); - - // Try to do the load - bool loaded = false; - for (vector<string>::iterator it = files.begin() ; it != files.end() ; it++) - loaded = this->load_file(*it, symbreq) || loaded; - return loaded; -} diff --git a/libmodman/module_manager.hpp b/libmodman/module_manager.hpp deleted file mode 100644 index 7820575..0000000 --- a/libmodman/module_manager.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * 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 - ******************************************************************************/ - -#ifndef MODULE_MANAGER_HPP_ -#define MODULE_MANAGER_HPP_ - -#include <algorithm> -#include <map> -#include <set> -#include <string> -#include <vector> -#include <cassert> - -#include "module.hpp" - -namespace libmodman { -using namespace std; - -class __MM_DLL_EXPORT module_manager { -public: - ~module_manager(); - bool load_builtin(mm_module *mod); - bool load_file(const string &filename, bool symbreq=true); - bool load_dir(const string &dirname, bool symbreq=true); - - template <class T> vector<T*> get_extensions() const { - struct pcmp { - static bool cmp(T* x, T* y) { return *x < *y; } - }; - - map<string, vector<base_extension*> >::const_iterator it = this->extensions.find(T::base_type()); - vector<T*> retlist; - - if (it != this->extensions.end()) { - vector<base_extension*> extlist = it->second; - - for (size_t i=0 ; i < extlist.size() ; i++) { - T* obj = dynamic_cast<T*>(extlist[i]); - if (obj) - retlist.push_back(obj); - else - assert (obj != NULL); - } - - sort(retlist.begin(), retlist.end(), &pcmp::cmp); - } - - return retlist; - } - - template <class T> bool register_type() { - if (T::singleton()) { - if (!this->singletons.insert(T::base_type()).second) - return false; - } - else - this->singletons.erase(T::base_type()); - this->extensions[T::base_type()]; - return true; - } - -private: - set<void*> modules; - set<string> singletons; - map<string, vector<base_extension*> > extensions; -}; - -} - -#endif /* MODULE_MANAGER_HPP_ */ diff --git a/libmodman/test/CMakeLists.txt b/libmodman/test/CMakeLists.txt deleted file mode 100644 index 168b130..0000000 --- a/libmodman/test/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -##### -## LibModMan Tests -#### - -# Functions -function(mm_create_module MODTYPE MODNAME MODCOND MODSYMB MODSMOD) - configure_file(module.cpp.in - ${CMAKE_CURRENT_BINARY_DIR}/${MODTYPE}_${MODNAME}.cpp - @ONLY) - add_library(${MODTYPE}_${MODNAME} - MODULE - ${CMAKE_CURRENT_BINARY_DIR}/${MODTYPE}_${MODNAME}.cpp) - set_target_properties(${MODTYPE}_${MODNAME} - PROPERTIES PREFIX "" - LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}/modules/${MODTYPE}) - target_link_libraries(${MODTYPE}_${MODNAME} modman) -endfunction(mm_create_module) - -function(mm_create_program name EXTTYPE) - add_executable(${name} main.cpp) - target_link_libraries(${name} modman) - set_property(TARGET ${name} PROPERTY - COMPILE_DEFINITIONS - EXTTYPE=${EXTTYPE}_extension) - if(${ARGC} GREATER 2) - target_link_libraries(${name} ${ARGN};modman) - set_property(TARGET ${name} PROPERTY - COMPILE_DEFINITIONS - EXTTYPE=${EXTTYPE}_extension;SYMB=1) - if(NOT WIN32 AND NOT APPLE) - set_property(TARGET ${name} PROPERTY - LINK_FLAGS -Wl,--no-as-needed) - endif() - endif() -endfunction(mm_create_program) - -# Modules -mm_create_module(condition one false NULL NULL) -mm_create_module(condition two true NULL NULL) -mm_create_module(singleton one true NULL NULL) -mm_create_module(singleton two true NULL NULL) -mm_create_module(sorted one true NULL NULL) -mm_create_module(sorted two true NULL NULL) -mm_create_module(builtin one true NULL NULL) -if (WIN32) - mm_create_module(symbol one true \"asdfoia\" \"ws2_32\") - mm_create_module(symbol two true \"recv\" \"ws2_32\") -else() - mm_create_module(symbol one true \"asdfoia\" \"z\") - mm_create_module(symbol two true \"deflate\" \"z\") -endif() - -# Programs -mm_create_program(condition condition) -mm_create_program(singleton singleton) -mm_create_program(sorted sorted) -mm_create_program(symbol symbol) -if (WIN32) - mm_create_program(symbollnk symbol ws2_32) -else() - mm_create_program(symbollnk symbol z) -endif() -add_executable(builtin - builtin.cpp - ${CMAKE_CURRENT_BINARY_DIR}/builtin_one.cpp) -target_link_libraries(builtin modman) -set_property(TARGET builtin PROPERTY COMPILE_DEFINITIONS - EXTTYPE=builtin_extension;BUILTIN_MODULE=extension;MM_MODULE_BUILTIN=extension) - -# Tests -add_test(NAME condition COMMAND condition $<TARGET_FILE_DIR:condition_one> two) -add_test(NAME singleton COMMAND singleton $<TARGET_FILE_DIR:singleton_one> one) -add_test(NAME sorted COMMAND sorted $<TARGET_FILE_DIR:sorted_one> two one) -add_test(NAME symbol COMMAND symbollnk $<TARGET_FILE_DIR:symbol_one> two) -add_test(NAME nosymbol COMMAND symbol $<TARGET_FILE_DIR:symbol_one>) -add_test(NAME nosymreq COMMAND symbol $<TARGET_FILE_DIR:symbol_one> one) -add_test(NAME builtin COMMAND builtin) - diff --git a/libmodman/test/main.cpp b/libmodman/test/main.cpp deleted file mode 100644 index cf930c1..0000000 --- a/libmodman/test/main.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * 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 <iostream> -#include <vector> -#include <cstring> -#ifdef WIN32 -#ifdef SYMB -#include <winsock2.h> -#endif -#endif - -#include "main.hpp" - -int main(int argc, const char** argv) { - module_manager mm; -#ifdef WIN32 -#ifdef SYMB - void* symb = recv; -#endif -#endif - - if (argc < 2) { - cout << "Usage: " << argv[0] << " MODULEDIR MODNAME ..." << endl; - return 1; - } - - if (!mm.register_type<EXTTYPE>()) { - cout << "Unable to register type!" << endl; - return 2; - } - - if (!mm.load_dir(argv[1]) && argc > 2) { - if (!mm.load_dir(argv[1], false)) { - cout << "Unable to load modules!" << endl; - return 3; - } - } - - vector<EXTTYPE*> exts = mm.get_extensions<EXTTYPE>(); - if (exts.size() != (unsigned int) argc - 2) { - cout << "Wrong number of extensions found!" << endl; - return 4; - } - - for (unsigned int i=0 ; i < exts.size() ; i++) { - if (!strstr(typeid(*(exts[i])).name(), argv[i+2])) { - cout << "Unable to find extension! Here's the list:" << endl; - for (unsigned int j=0 ; j < exts.size() ; j++) - cout << "\t" << typeid(*(exts[j])).name() << endl; - return 5; - } - } - - return 0; -} diff --git a/libmodman/test/main.hpp b/libmodman/test/main.hpp deleted file mode 100644 index 0a08c63..0000000 --- a/libmodman/test/main.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * 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 - ******************************************************************************/ - -#ifndef MAIN_HPP_ -#define MAIN_HPP_ - -#include <typeinfo> - -#include "../module_manager.hpp" - -using namespace std; -using namespace libmodman; - -class __MM_DLL_EXPORT singleton_extension : public extension<singleton_extension, true> {}; - -class __MM_DLL_EXPORT sorted_extension : public extension<sorted_extension> { -public: - virtual bool operator<(const base_extension& other) const { - return string(typeid(*this).name()) > string(typeid(other).name()); - } -}; - -class __MM_DLL_EXPORT symbol_extension : public extension<symbol_extension> {}; -class __MM_DLL_EXPORT condition_extension : public extension<condition_extension> {}; -class __MM_DLL_EXPORT builtin_extension : public extension<builtin_extension> {}; - -#endif /* MAIN_HPP_ */ diff --git a/libproxy.doap b/libproxy.doap new file mode 100644 index 0000000..e32d37e --- /dev/null +++ b/libproxy.doap @@ -0,0 +1,21 @@ +<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:foaf="http://xmlns.com/foaf/0.1/" + xmlns:gnome="http://api.gnome.org/doap-extensions#" + xmlns="http://usefulinc.com/ns/doap#"> + + <name xml:lang="en">libproxy</name> + <shortdesc xml:lang="en">libproxy is a library that provides automatic proxy configuration management.</shortdesc> + <homepage rdf:resource="https://github.com/libproxy/libproxy/" /> + <download-page rdf:resource="https://github.com/libproxy/libproxy/releases" /> + <bug-database rdf:resource="https://github.com/libproxy/libproxy/issues" /> + <category rdf:resource="http://api.gnome.org/doap-extensions#productivity" /> + <programming-language>C</programming-language> + + <maintainer> + <foaf:Person> + <foaf:name>Jan-Michael Brummer</foaf:name> + <foaf:mbox rdf:resource="mailto:jan-michael.brummer1@volkswagen.de" /> + </foaf:Person> + </maintainer> +</Project> diff --git a/libproxy.spec.in b/libproxy.spec.in deleted file mode 100644 index 550a855..0000000 --- a/libproxy.spec.in +++ /dev/null @@ -1,398 +0,0 @@ -# -# spec file for package libproxy (Version 0.4.0) -# -# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany. -# -# All modifications and additions to the file contributed by third parties -# remain the property of their copyright owners, unless otherwise agreed -# upon. The license for this file, and modifications and additions to the -# file, is the same license as for the pristine package itself (unless the -# license for the pristine package is not an Open Source License, in which -# case the license is the MIT License). An "Open Source License" is a -# license that conforms to the Open Source Definition (Version 1.9) -# published by the Open Source Initiative. - -# Please submit bugfixes or comments via http://bugs.opensuse.org/ -# - -# norootforbuild - -%define build_core_not_modules 1 -%if 0%{suse_version} > 1120 -%define xulrunner_ver 192 -%else -%if 0%{suse_version} > 1110 -%define xulrunner_ver 191 -%else -%if 0%{suse_version} >= 1100 -%define xulrunner_ver 190 -%else -%define xulrunner_ver 181 -%endif -%endif -%endif -Url: http://code.google.com/p/libproxy/ -%define _name libproxy - -Name: libproxy -Group: System/Libraries -Summary: Libproxy provides consistent proxy configuration to applications -Version: @VERSION@ -Release: 4 -Source: http://libproxy.googlecode.com/files/%{_name}-%{version}.tar.bz2 -Source99: baselibs.conf -License: LGPLv2.1+ -BuildRoot: %{_tmppath}/%{name}-%{version}-build -BuildRequires: cmake -BuildRequires: gcc-c++ -BuildRequires: pkg-config -BuildRequires: zlib-devel -%if !%build_core_not_modules -BuildRequires: dbus-1-devel -BuildRequires: gconf2-devel -# For directory ownership, but also because we want to rebuild the modules if -# the library changed -BuildRequires: libproxy1 -BuildRequires: libwebkit-devel -BuildRequires: mozilla-xulrunner%{xulrunner_ver}-devel -BuildRequires: NetworkManager-devel -BuildRequires: libkde4-devel -BuildRequires: libqt4-devel -%else -BuildRequires: python-devel -%endif - -%if %suse_version <= 1110 -%define python_sitelib %{py_sitedir} -%endif - -%description -libproxy offers the following features: * extremely small core - footprint (< 35K) - -* no external dependencies within libproxy core (libproxy modules - may have dependencies) - -* only 3 functions in the stable external API - -* dynamic adjustment to changing network topology - -* a standard way of dealing with proxy settings across all scenarios - - -%if %build_core_not_modules - -%package tools -License: GPLv2+ ; LGPLv2.1+ -Summary: A simple application using libproxy -Group: System/Libraries -Requires: libproxy1 = %{version} - -%description tools -A simple application that will use libproxy to give the results you can -expect from other applications. It can be used to debug what would -happen in various cases. - - -%package devel -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy provides consistent proxy configuration to applications - Development Files -Group: Development/Libraries/C and C++ -Requires: libproxy1 = %{version} - -%description devel -libproxy offers the following features: * extremely small core - footprint (< 35K) - -* no external dependencies within libproxy core (libproxy modules - may have dependencies) - -* only 3 functions in the stable external API - -* dynamic adjustment to changing network topology - -* a standard way of dealing with proxy settings across all scenarios - - -%package -n libproxy1 -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy provides consistent proxy configuration to applications -Group: System/Libraries - -%description -n libproxy1 -libproxy offers the following features: * extremely small core - footprint (< 35K) - -* no external dependencies within libproxy core (libproxy modules - may have dependencies) - -* only 3 functions in the stable external API - -* dynamic adjustment to changing network topology - -* a standard way of dealing with proxy settings across all scenarios - -%package -n libmodman0_0_0 -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy's Module Management Library -Group: System/Libraries - -%description -n libmodman0_0_0 -A module management library taking care of loading / unload modules -including heuristics in detecting which bindings might already -be used by an application and favouring this one. - - -%package -n python-libproxy -License: GPLv2+ ; LGPLv2.1+ -Summary: Python bindings for libproxy -Group: System/Libraries -BuildArch: noarch -Requires: libproxy1 = %{version} -%py_requires - -%description -n python-libproxy -libproxy offers the following features: * extremely small core - footprint (< 35K) - -* no external dependencies within libproxy core (libproxy modules - may have dependencies) - -* only 3 functions in the stable external API - -* dynamic adjustment to changing network topology - -* a standard way of dealing with proxy settings across all scenarios - - -%package -n perl-Net-Libproxy -License: GPLv2+ ; LGPLv2.1+ -Summary: Perl bindings for libproxy -Group: Development/Libraries/Perl -Requires: libproxy1 = %{version} -Requires: perl = %{perl_version}%py_requires - -%description -n perl-Net-Libproxy -libproxy offers the following features: * extremely small core - footprint (< 35K) - -* no external dependencies within libproxy core (libproxy modules - may have dependencies) - -* only 3 functions in the stable external API - -* dynamic adjustment to changing network topology - -* a standard way of dealing with proxy settings across all scenarios - - -%package -n libproxy-sharp -License: GPLv2+ ; LGPLv2.1+ -Summary: .Net bindings for libproxy -Group: Development/Languages/Mono -Requires: libproxy1 = %{version} - -%description -n libproxy-sharp -libproxy offers the following features: * extremely small core - footprint (< 35K) - -* no external dependencies within libproxy core (libproxy modules - may have dependencies) - -* only 3 functions in the stable external API - -* dynamic adjustment to changing network topology - -* a standard way of dealing with proxy settings across all scenarios - - -%else - -%package -n libproxy1-config-gnome -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy module for GNOME configuration -Group: System/Libraries -Requires: libproxy1 = %{version} -Recommends: libproxy1-pacrunner = %{version} -Recommends: libproxy1-wpad-dns = %{version} -Supplements: packageand(libproxy1:gconf2) -Provides: libproxy-gnome = %{version} -Obsoletes: libproxy-gnome < %{version} - -%description -n libproxy1-config-gnome -A module to extend libproxy with capabilities to query GNOME about -proxy settings. - - -%package -n libproxy1-config-kde4 -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy module for KDE configuration -Group: System/Libraries -Requires: libproxy1 = %{version} -Recommends: libproxy1-pacrunner = %{version} -Recommends: libproxy1-wpad-dns = %{version} -Supplements: packageand(libproxy1:libkde4) -Provides: libproxy-kde = %{version} -Obsoletes: libproxy-kde < %{version} - -%description -n libproxy1-config-kde4 -A module to extend libproxy with capabilities to query KDE4 about proxy -settings. - - -%package -n libproxy1-pacrunner-mozjs -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy module to support wpad/pac parsing via Mozilla JavaScript Engine -Group: System/Libraries -Requires: libproxy1 = %{version} -Supplements: packageand(libproxy1:mozilla-xulrunner%{xulrunner_ver}) -# A virtual symbol to identify that this is a pacrunner. -Provides: libproxy1-pacrunner = %{version} - -%description -n libproxy1-pacrunner-mozjs -A module to extend libproxy with capabilities to pass addresses to a -WPAD/PAC script and have it find the correct proxy. - - -%package -n libproxy1-pacrunner-webkit -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy module to support WPAD/PAC parsing via WebKit JavaScript Engine -Group: System/Libraries -Requires: libproxy1 = %{version} -Supplements: packageand(libproxy1:libwebkit-1) -# A virtual symbol to identify that this is a pacrunner. -Provides: libproxy1-pacrunner = %{version} - -%description -n libproxy1-pacrunner-webkit -A module to extend libproxy with capabilities to pass addresses to a -WPAD/PAC script and have it find the correct proxy. - - -%package -n libproxy1-networkmanager -License: GPLv2+ ; LGPLv2.1+ -Summary: Libproxy module for NetworkManager configuration -Group: System/Libraries -Requires: libproxy1 = %{version} -Supplements: packageand(libproxy1:NetworkManager) - -%description -n libproxy1-networkmanager -A module to extend libproxy with capabilities to query NetworkManager -about network configuration changes. - -%endif - -%prep -%setup -q -n %{_name}-%{version} -mkdir build - -%build -cd build -cmake \ - -DCMAKE_INSTALL_PREFIX=%{_prefix} \ - -Dlibdir=%{_libdir} \ - -Dlibexecdir=%{_libexecdir}/libproxy \ - -Ddatadir=%{_datadir} \ - -Dmoduledir=%{_libdir}/libproxy/%{version}/modules \ - -DWITH_VALA=yes \ - -DPERL_VENDORINSTALL=yes \ -.. -%{__make} %{?jobs:-j%jobs} VERBOSE=1 - -%install -cd build -%makeinstall -%if %build_core_not_modules -# Build the basic directory structure for the modules so we can -# own the directories in the main library package -install -d %{buildroot}%{_libexecdir}/libproxy -install -d %{buildroot}%{_libdir}/%{name}/%{version}/modules -%else -# remove files that are part of the core -rm %{buildroot}%{_includedir}/*.h -# Delete all files that exist in the base libproxy package -rm %{buildroot}%{_bindir}/proxy -rm %{buildroot}%{_libdir}/libproxy.so* -rm %{buildroot}%{_libdir}/libmodman.so* -rm %{buildroot}%{python_sitelib}/*.py -rm %{buildroot}%{_libdir}/pkgconfig/libproxy-1.0.pc -rm %{buildroot}%{_datadir}/cmake/Modules/Findlibproxy.cmake -rm %{buildroot}%{_datadir}/vala/vapi/libproxy-1.0.vapi -rm %{buildroot}%{perl_vendorarch}/Net/Libproxy.pm -rm %{buildroot}%{perl_vendorarch}/auto/Net/Libproxy/Libproxy.so -%endif -%if %build_core_not_modules - -%post -n libproxy1 -p /sbin/ldconfig - -%post -n libmodman0_0_0 -p /sbin/ldconfig - -%postun -n libproxy1 -p /sbin/ldconfig - -%postun -n libmodman0_0_0 -p /sbin/ldconfig - -%files tools -%defattr(-, root, root) -%{_bindir}/proxy - -%files -n libproxy1 -%defattr(-, root, root) -%{_libdir}/libproxy.so.* -%dir %{_libexecdir}/libproxy -%dir %{_libdir}/libproxy -%dir %{_libdir}/libproxy/%{version} -%dir %{_libdir}/libproxy/%{version}/modules -#%{_libdir}/libproxy/%{version}/modules/config_envvar.so -#%{_libdir}/libproxy/%{version}/modules/config_file.so -#%{_libdir}/libproxy/%{version}/modules/config_direct.so -#%{_libdir}/libproxy/%{version}/modules/ignore_*.so - -%files -n libmodman0_0_0 -%defattr(-, root, root) -%{_libdir}/libmodman.so.* - -%files devel -%defattr(-, root, root) -%{_includedir}/*.h -%{_libdir}/*.so -%{_libdir}/pkgconfig/libproxy-1.0.pc -%{_datadir}/cmake/Modules/Findlibproxy.cmake -%dir %{_datadir}/vala -%dir %{_datadir}/vala/vapi -%{_datadir}/vala/vapi/libproxy-1.0.vapi - -%files -n python-libproxy -%defattr(-, root, root) -%{python_sitelib}/*.py - -%files -n perl-Net-Libproxy -%defattr(-,root,root) -%dir %{perl_vendorarch}/Net -%dir %{perl_vendorarch}/auto/Net -%dir %{perl_vendorarch}/auto/Net/Libproxy -%{perl_vendorarch}/Net/Libproxy.pm -%{perl_vendorarch}/auto/Net/Libproxy/Libproxy.so -%else - -%files -n libproxy1-config-kde4 -%defattr(-, root, root) -%{_libdir}/libproxy/%{version}/modules/config_kde4.so - -%files -n libproxy1-config-gnome -%defattr(-, root, root) -%{_libdir}/libproxy/%{version}/modules/config_gnome.so -%{_libexecdir}/libproxy/pxgconf - -%files -n libproxy1-networkmanager -%defattr(-, root, root) -%{_libdir}/libproxy/%{version}/modules/network_networkmanager.so - -%files -n libproxy1-pacrunner-webkit -%defattr(-, root, root) -%{_libdir}/libproxy/%{version}/modules/pacrunner_webkit.so - -%files -n libproxy1-pacrunner-mozjs -%defattr(-, root, root) -%{_libdir}/libproxy/%{version}/modules/pacrunner_mozjs.so -%endif - -%changelog diff --git a/libproxy/CMakeLists.txt b/libproxy/CMakeLists.txt deleted file mode 100644 index 0bd7148..0000000 --- a/libproxy/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -### Project info -project(libproxy) -set_project_version(0 4 18) - -### Add a global compilation stuff -if (WIN32) - add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) -else(WIN32) - add_definitions(-D_POSIX_C_SOURCE=200112L) - set(CMAKE_CXX_FLAGS "-fvisibility=hidden ${CMAKE_CXX_FLAGS}") -endif(WIN32) - -### Modules -include(cmake/modules.cmk) - -### Dev files -include(cmake/devfiles.cmk) - -### Main library -include(cmake/libproxy.cmk) - -### Tests -add_testdirectory(test) diff --git a/libproxy/Findlibproxy.cmake.in b/libproxy/Findlibproxy.cmake.in deleted file mode 100644 index ef44489..0000000 --- a/libproxy/Findlibproxy.cmake.in +++ /dev/null @@ -1,26 +0,0 @@ -# - Try to find libproxy -# Once done this will define -# -# LIBPROXY_FOUND - system has libproxy -# LIBPROXY_INCLUDE_DIR - the libproxy include directory -# LIBPROXY_LIBRARIES - libproxy library -# -# Copyright (c) 2010, Dominique Leuenberger -# -# Redistribution and use is allowed according the license terms -# of libproxy, which this file is integrated part of. - -# Find proxy.h and the corresponding library (libproxy.so) -FIND_PATH(LIBPROXY_INCLUDE_DIR proxy.h ) -FIND_LIBRARY(LIBPROXY_LIBRARIES NAMES proxy ) - -# Set library version -SET(LIBPROXY_VERSION @PROJECT_VERSION@) -SET(LIBPROXY_VERSION_MAJOR @PROJECT_VERSION_MAJOR@) -SET(LIBPROXY_VERSION_MINOR @PROJECT_VERSION_MINOR@) -SET(LIBPROXY_VERSION_PATCH @PROJECT_VERSION_PATCH@) - -# Give output, should this be wished (this handles also QUIET and REQUIRED -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(libproxy DEFAULT_MSG LIBPROXY_LIBRARIES LIBPROXY_INCLUDE_DIR) - diff --git a/libproxy/cmake/devfiles.cmk b/libproxy/cmake/devfiles.cmk deleted file mode 100644 index 0301dce..0000000 --- a/libproxy/cmake/devfiles.cmk +++ /dev/null @@ -1,23 +0,0 @@ -if(NOT WIN32 OR MINGW) - # PkgConfig file - set (PKGCONFIG_PREFIX ${CMAKE_INSTALL_PREFIX}) - - if(IS_ABSOLUTE ${LIB_INSTALL_DIR}) - set (PKGCONFIG_LIBDIR ${LIB_INSTALL_DIR}) - else(IS_ABSOLUTE ${LIB_INSTALL_DIR}) - set (PKGCONFIG_LIBDIR "\${prefix}/${LIB_INSTALL_DIR}") - endif (IS_ABSOLUTE ${LIB_INSTALL_DIR}) - - if(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR}) - set (PKGCONFIG_INCLUDEDIR ${INCLUDE_INSTALL_DIR}) - else(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR}) - set (PKGCONFIG_INCLUDEDIR "\${prefix}/${INCLUDE_INSTALL_DIR}") - endif(IS_ABSOLUTE ${INCLUDE_INSTALL_DIR}) - - configure_file(${CMAKE_SOURCE_DIR}/libproxy/libproxy-1.0.pc.in ${CMAKE_BINARY_DIR}/libproxy-1.0.pc @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/libproxy-1.0.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - - # CMake Find helper - configure_file(${CMAKE_SOURCE_DIR}/libproxy/Findlibproxy.cmake.in ${CMAKE_BINARY_DIR}/Findlibproxy.cmake @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/Findlibproxy.cmake DESTINATION ${SHARE_INSTALL_DIR}/cmake/Modules) -endif(NOT WIN32 OR MINGW) diff --git a/libproxy/cmake/libproxy.cmk b/libproxy/cmake/libproxy.cmk deleted file mode 100644 index adc0f2e..0000000 --- a/libproxy/cmake/libproxy.cmk +++ /dev/null @@ -1,34 +0,0 @@ -set(LIBPROXY_SOURCES ${LIBPROXY_SOURCES} extension_config.cpp extension_pacrunner.cpp extension_wpad.cpp proxy.cpp url.cpp) - -if(BUILD_SHARED_LIBS) - add_library(libproxy SHARED ${LIBPROXY_SOURCES}) -else () - add_library(libproxy STATIC ${LIBPROXY_SOURCES}) -endif() - -if(WIN32) - target_link_libraries(libproxy modman;ws2_32;${LIBPROXY_LIBRARIES}) -else() - target_link_libraries(libproxy modman;m;pthread;${CMAKE_DL_LIBS};${LIBPROXY_LIBRARIES}) -endif() -file(TO_NATIVE_PATH ${MODULE_INSTALL_DIR} MODULE_INSTALL_DIR) -if(WIN32) - string(REGEX REPLACE "\\\\" "\\\\\\\\" MODULE_INSTALL_DIR ${MODULE_INSTALL_DIR}) -endif() - -if(IS_ABSOLUTE "${MODULE_INSTALL_DIR}") - set(MODULEDIR "${MODULE_INSTALL_DIR}") -else () - set(MODULEDIR "${CMAKE_INSTALL_PREFIX}/${MODULE_INSTALL_DIR}") -endif() - -set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/proxy.cpp - PROPERTY COMPILE_DEFINITIONS MODULEDIR="${MODULEDIR}";BUILTIN_MODULES=${BUILTIN_MODULES}) -# When changing the SOVERSION here remember to also bump the 'favorite proxy .so' in python bindings. -set_target_properties(libproxy PROPERTIES PREFIX "" VERSION 1.0.0 SOVERSION 1) - -if(NOT APPLE) - set_target_properties(libproxy PROPERTIES LINK_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libproxy.map") -endif() -install(TARGETS libproxy DESTINATION ${LIB_INSTALL_DIR}) -install(FILES proxy.h DESTINATION ${INCLUDE_INSTALL_DIR}) diff --git a/libproxy/cmake/modules.cmk b/libproxy/cmake/modules.cmk deleted file mode 100644 index 6eaaa01..0000000 --- a/libproxy/cmake/modules.cmk +++ /dev/null @@ -1,56 +0,0 @@ -# Setup module path -if(WIN32) - set(MODULE_INSTALL_DIR ${LIB_INSTALL_DIR}/modules CACHE PATH "Module install dir") -else() - set(MODULE_INSTALL_DIR ${LIB_INSTALL_DIR}/${PROJECT_NAME}/${PROJECT_VERSION}/modules CACHE PATH "Module install dir") -endif() - -# Do module determination -include(cmake/pxmodule.cmk) -include(cmake/pkgconfig.cmk) -include(cmake/modules/config_pacrunner.cmk) -include(cmake/modules/config_envvar.cmk) -include(cmake/modules/config_sysconfig.cmk) -include(cmake/modules/config_gnome.cmk) -include(cmake/modules/config_kde.cmk) -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) -include(cmake/modules/pacrunner_duktape.cmk) - -# Build the pacrunner into libproxy unless we are building for multiple engines -set(BIPR 1 CACHE BOOL "Build internal pacrunner? (Always false when building more than one PR") - -math(EXPR NUM_PACRUNNER "${MOZJS_FOUND}+${NATUS_FOUND}+${WEBKIT_FOUND}+${DUKTAPE_FOUND}") -if(NUM_PACRUNNER GREATER 1) - set(BIPR 0) -endif() - -# -## Module definition -# -message("MODULES TO BUILD:") -px_module(config_pacrunner "${DBUS_FOUND}" 0 ${DBUS_LIBRARIES}) -px_module(config_envvar "${ENVVAR_FOUND}" 1) -px_module(config_sysconfig "${SYSCONFIG_FOUND}" 1) -px_module(config_gnome "${GNOME2_FOUND}" 0) -px_module(config_gnome3 "${GNOME3_FOUND}" 0) -px_module(config_kde "${WITH_KDE}" 0) -px_module(config_macosx "${SC_FOUND}" 1 ${SC_LIBRARIES} ${CF_LIBRARIES}) -px_module(config_w32reg "${WIN32}" 1) -px_module(ignore_domain 1 1) -px_module(ignore_hostname 1 1) -px_module(ignore_ip 1 1) -if(NM_FOUND OR NMold_FOUND) - set(NM_BUILD 1) -endif(NM_FOUND OR NMold_FOUND) -px_module(network_networkmanager "${NM_BUILD}" 0 ${NM_LIBRARIES}${NMold_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(pacrunner_duktape "${DUKTAPE_FOUND}" ${BIPR} ${DUKTAPE_LIBRARIES}) -px_module(wpad_dns_alias 1 1) -message("${NUM_PACRUNNER} pacrunner(s) are enabled") -message("") diff --git a/libproxy/cmake/modules/config_envvar.cmk b/libproxy/cmake/modules/config_envvar.cmk deleted file mode 100644 index e9445a4..0000000 --- a/libproxy/cmake/modules/config_envvar.cmk +++ /dev/null @@ -1,3 +0,0 @@ -if (NOT WIN32 AND NOT APPLE) - set(ENVVAR_FOUND 1) -endif()
\ No newline at end of file diff --git a/libproxy/cmake/modules/config_gnome.cmk b/libproxy/cmake/modules/config_gnome.cmk deleted file mode 100644 index 4326972..0000000 --- a/libproxy/cmake/modules/config_gnome.cmk +++ /dev/null @@ -1,22 +0,0 @@ -if (NOT WIN32 AND NOT APPLE) - option(WITH_GNOME2 "Target a GNOME 2 system (gconf)" OFF) - option(WITH_GNOME3 "Target a GNOME 3 system (gsettings)" ON) - if(WITH_GNOME3) - px_check_modules(GNOME3 gio-2.0>=2.26 gobject-2.0) - else(WITH_GNOME3) - px_check_modules(GNOME2 gconf-2.0 gobject-2.0) - endif(WITH_GNOME3) - - # GNOME (gconf) helper - if(GNOME2_FOUND OR GNOME3_FOUND) - if(WITH_GNOME3) - add_executable(pxgsettings modules/pxgsettings.cpp) - target_link_libraries(pxgsettings ${GNOME3_LIBRARIES}) - install(TARGETS pxgsettings RUNTIME DESTINATION ${LIBEXEC_INSTALL_DIR}) - else(WITH_GNOME3) - add_executable(pxgconf modules/pxgconf.cpp) - target_link_libraries(pxgconf ${GNOME2_LIBRARIES}) - install(TARGETS pxgconf RUNTIME DESTINATION ${LIBEXEC_INSTALL_DIR}) - endif(WITH_GNOME3) - endif() -endif() diff --git a/libproxy/cmake/modules/config_kde.cmk b/libproxy/cmake/modules/config_kde.cmk deleted file mode 100644 index ed2f828..0000000 --- a/libproxy/cmake/modules/config_kde.cmk +++ /dev/null @@ -1,4 +0,0 @@ -option(WITH_KDE "Build module to read proxy settings from KDE4/KF5" ON) - -# There are no additional detections; kreadconfig (from KDE4) and kreadconfig5 -# (from KF5) are only needed at runtime. diff --git a/libproxy/cmake/modules/config_macosx.cmk b/libproxy/cmake/modules/config_macosx.cmk deleted file mode 100644 index 110d4b8..0000000 --- a/libproxy/cmake/modules/config_macosx.cmk +++ /dev/null @@ -1,10 +0,0 @@ -if(APPLE) - find_library(SC_LIBRARIES SystemConfiguration) - find_library(CF_LIBRARIES CoreFoundation) - if(SC_LIBRARIES) - set(SC_FOUND 1) - endif() - if(CF_LIBRARIES) - set(CF_FOUND 1) - endif() -endif()
\ No newline at end of file diff --git a/libproxy/cmake/modules/config_pacrunner.cmk b/libproxy/cmake/modules/config_pacrunner.cmk deleted file mode 100644 index 11dde89..0000000 --- a/libproxy/cmake/modules/config_pacrunner.cmk +++ /dev/null @@ -1,3 +0,0 @@ -if (NOT WIN32 AND NOT APPLE) - px_check_modules(DBUS dbus-1) -endif() diff --git a/libproxy/cmake/modules/config_sysconfig.cmk b/libproxy/cmake/modules/config_sysconfig.cmk deleted file mode 100644 index 10e8c5c..0000000 --- a/libproxy/cmake/modules/config_sysconfig.cmk +++ /dev/null @@ -1,8 +0,0 @@ -if (NOT WIN32 AND NOT APPLE) - option(WITH_SYSCONFIG "Build sysconfig module for /etc/sysconfig" ON) - if(WITH_SYSCONFIG) - if (EXISTS "/etc/sysconfig" AND IS_DIRECTORY "/etc/sysconfig") - set(SYSCONFIG_FOUND 1) - endif() - endif() -endif()
\ No newline at end of file diff --git a/libproxy/cmake/modules/network_networkmanager.cmk b/libproxy/cmake/modules/network_networkmanager.cmk deleted file mode 100644 index 6ef6ead..0000000 --- a/libproxy/cmake/modules/network_networkmanager.cmk +++ /dev/null @@ -1,6 +0,0 @@ -if (NOT WIN32 AND NOT APPLE) - px_check_modules(NM libnm dbus-1) - if (NOT NM_FOUND) - px_check_modules(NMold NetworkManager dbus-1) - endif (NOT NM_FOUND) -endif() diff --git a/libproxy/cmake/modules/pacrunner_duktape.cmk b/libproxy/cmake/modules/pacrunner_duktape.cmk deleted file mode 100644 index 781985d..0000000 --- a/libproxy/cmake/modules/pacrunner_duktape.cmk +++ /dev/null @@ -1,31 +0,0 @@ -option(WITH_DUKTAPE "Search for Duktape package" ON) - -if(WIN32) - set(DUKTAPE_FOUND 0) - if(WITH_DUKTAPE) - find_package(Duktape QUIET) - if(DUKTAPE_FOUND) - include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${DUKTAPE_INCLUDE_DIRS}) - link_libraries(${DUKTAPE_LIBRARY}) - set(DUKTAPE_FOUND 1) # find_package sets DUKTAPE_FOUND to True and not 0 - endif() - endif() -else() - set(DUKTAPE_INCLUDE_DIR "DUKTAPE_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path to Duktape headers") - set(DUKTAPE_LIBRARIES "DUKTAPE_LIBRARIES-NOTFOUND" CACHE FILEPATH "Path to Duktape libraries") - - if(WITH_DUKTAPE) - px_check_modules(DUKTAPE "duktape") - - if(NOT DUKTAPE_FOUND AND DUKTAPE_INCLUDE_DIR AND DUKTAPE_LIBRARIES) - message("Duktape headers: " ${DUKTAPE_INCLUDE_DIR}) - message("Duktape libraries: " ${DUKTAPE_LIBRARIES}) - set(DUKTAPE_FOUND 1) - include_directories(${DUKTAPE_INCLUDE_DIR}) - link_directories(${DUKTAPE_LIBRARIES}) - link_libraries(duktape) - endif() - else() - set(DUKTAPE_FOUND 0) - endif() -endif() diff --git a/libproxy/cmake/modules/pacrunner_mozjs.cmk b/libproxy/cmake/modules/pacrunner_mozjs.cmk deleted file mode 100644 index 117d789..0000000 --- a/libproxy/cmake/modules/pacrunner_mozjs.cmk +++ /dev/null @@ -1,26 +0,0 @@ -if(WIN32) - set(MOZJS_INCLUDE_DIR "MOZJS_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path to the MOZJS include directory") - set(MOZJS_LIBRARIES "MOZJS_LIBRARIES-NOTFOUND" CACHE FILEPATH "Path to the MOZJS .lib file") - if(MOZJS_LIBRARIES AND MOZJS_INCLUDE_DIR) - set(MOZJS_FOUND 1) - link_directories(MOZJS_LIBRARIES) - include_directories("${MOZJS_INCLUDE_DIR}") - endif() -elseif(NOT APPLE) - option(WITH_MOZJS "Search for MOZJS package" OFF) - if (WITH_MOZJS) - pkg_search_module(MOZJS mozjs-68) - if(MOZJS_FOUND) - foreach(OPT ${MOZJS_CFLAGS}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPT}") - endforeach() - message("mozjs is " ${CMAKE_CXX_FLAGS}) - include_directories(${MOZJS_INCLUDE_DIRS}) - link_directories(${MOZJS_LIBRARY_DIRS}) - else() - set(MOZJS_FOUND 0) - endif() - else() - set(MOZJS_FOUND 0) - endif() -endif() diff --git a/libproxy/cmake/modules/pacrunner_natus.cmk b/libproxy/cmake/modules/pacrunner_natus.cmk deleted file mode 100644 index 7b14c93..0000000 --- a/libproxy/cmake/modules/pacrunner_natus.cmk +++ /dev/null @@ -1,7 +0,0 @@ -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 diff --git a/libproxy/cmake/modules/pacrunner_webkit.cmk b/libproxy/cmake/modules/pacrunner_webkit.cmk deleted file mode 100644 index aa34dd0..0000000 --- a/libproxy/cmake/modules/pacrunner_webkit.cmk +++ /dev/null @@ -1,26 +0,0 @@ -if(WIN32) - set(WEBKIT_INCLUDE_DIR "WEBKIT_INCLUDE_DIR-NOTFOUND" CACHE PATH "Path to the WEBKIT include directory") - set(WEBKIT_LIBRARIES "WEBKIT_LIBRARIES-NOTFOUND" CACHE FILEPATH "Path to the WEBKIT .lib file") - if(WEBKIT_LIBRARIES AND WEBKIT_INCLUDE_DIR) - set(WEBKIT_FOUND 1) - link_directories(WEBKIT_LIBRARIES) - include_directories("${WEBKIT_INCLUDE_DIR}") - endif() -elseif(APPLE) - find_library(WEBKIT_LIBRARIES JavaScriptCore) - if(WEBKIT_LIBRARIES) - set(WEBKIT_FOUND 1) - endif() -else() - if(WITH_WEBKIT3) - px_check_modules(WEBKIT "javascriptcoregtk-4.0") - if(NOT WEBKIT_LIBRARIES) - px_check_modules(WEBKIT "javascriptcoregtk-3.0 >= 1.5.0") - if(NOT WEBKIT_LIBRARIES) - px_check_modules(WEBKIT "webkitgtk-3.0 < 1.5.0") - endif(NOT WEBKIT_LIBRARIES) - endif(NOT WEBKIT_LIBRARIES) - else(WITH_WEBKIT) - px_check_modules(WEBKIT webkit-1.0) - endif() -endif() diff --git a/libproxy/cmake/pkgconfig.cmk b/libproxy/cmake/pkgconfig.cmk deleted file mode 100644 index ffa0897..0000000 --- a/libproxy/cmake/pkgconfig.cmk +++ /dev/null @@ -1,23 +0,0 @@ -if(NOT WIN32) - find_package(PkgConfig) - - # Define our magical px_check_modules function - function(px_check_modules name) - if(PKG_CONFIG_EXECUTABLE) - option(WITH_${name} "Search for ${name} package" ON) - if (WITH_${name}) - pkg_check_modules(${name} ${ARGN}) - if(${${name}_FOUND}) - include_directories(${${name}_INCLUDE_DIRS}) - link_directories(${${name}_LIBRARY_DIRS}) - else() - set(${name}_FOUND 0 PARENT_SCOPE) - endif() - else() - set(${name}_FOUND 0 PARENT_SCOPE) - endif() - endif() - endfunction(px_check_modules) -endif() - - diff --git a/libproxy/cmake/pxmodule.cmk b/libproxy/cmake/pxmodule.cmk deleted file mode 100644 index bbbd989..0000000 --- a/libproxy/cmake/pxmodule.cmk +++ /dev/null @@ -1,30 +0,0 @@ -# Module function -function(px_module name build builtin) - if(IS_ABSOLUTE "${LIBEXEC_INSTALL_DIR}") - set(LIBEXECDIR "${LIBEXEC_INSTALL_DIR}") - else () - set(LIBEXECDIR "${CMAKE_INSTALL_PREFIX}/${LIBEXEC_INSTALL_DIR}") - endif() - if(build) - if(builtin) - set(built "*") - set_property(SOURCE modules/${name}.cpp PROPERTY COMPILE_DEFINITIONS LIBEXECDIR="${LIBEXECDIR}";MM_MODULE_BUILTIN=${name}) - set(LIBPROXY_SOURCES ${LIBPROXY_SOURCES} modules/${name}.cpp PARENT_SCOPE) - set(BUILTIN_MODULES "${BUILTIN_MODULES} X\(${name}\)" PARENT_SCOPE) - if(${ARGC} GREATER 3) - set(LIBPROXY_LIBRARIES ${LIBPROXY_LIBRARIES} ${ARGN} PARENT_SCOPE) - endif() - else() - set(built "m") - set_property(SOURCE modules/${name}.cpp PROPERTY COMPILE_DEFINITIONS LIBEXECDIR="${LIBEXECDIR}") - add_library(${name} MODULE modules/${name}.cpp) - target_link_libraries(${name} libproxy) - set_target_properties(${name} PROPERTIES PREFIX "") - install(TARGETS ${name} LIBRARY DESTINATION ${MODULE_INSTALL_DIR}) - if(${ARGC} GREATER 3) - target_link_libraries(${name} ${ARGN}) - endif() - endif() - endif() - message("\t${built}\t${name}") -endfunction(px_module) diff --git a/libproxy/config.hpp b/libproxy/config.hpp deleted file mode 100644 index 4efb08d..0000000 --- a/libproxy/config.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2010 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 - ******************************************************************************/ - -#ifndef CONFIG_HPP_ -#define CONFIG_HPP_ - -#ifdef WIN32 -#pragma warning(disable: 4251) -#pragma warning(disable: 4290) -#pragma warning(disable: 4275) -#define DLL_PUBLIC __declspec(dllexport) -#define PATHSEP '\\' -#define MODULEEXT "dll" -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 -#endif -#include <winsock2.h> -#include <ws2tcpip.h> -#include <windows.h> -typedef unsigned __int64 uint64_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int16 uint16_t; -typedef unsigned __int8 uint8_t; -typedef unsigned short int sa_family_t; -#else -#define DLL_PUBLIC __attribute__ ((visibility("default"))) -#define PATHSEP '/' -#define MODULEEXT "so" -#include <sys/socket.h> -#include <netdb.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <pthread.h> -#endif - -#endif /* CONFIG_HPP_ */ diff --git a/libproxy/extension_config.cpp b/libproxy/extension_config.cpp deleted file mode 100644 index 075b91a..0000000 --- a/libproxy/extension_config.cpp +++ /dev/null @@ -1,41 +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 "extension_config.hpp" -using namespace libproxy; - -string config_extension::get_ignore(const url&) { - return ""; -} - -bool config_extension::set_creds(const url&, const string&, const string&) { - return false; -} - -bool config_extension::operator<(const base_extension&) const { - return true; -} - -bool config_extension::get_valid() { - return this->valid; -} - -void config_extension::set_valid(bool valid) { - this->valid = valid; -} diff --git a/libproxy/extension_config.hpp b/libproxy/extension_config.hpp deleted file mode 100644 index b4c1202..0000000 --- a/libproxy/extension_config.hpp +++ /dev/null @@ -1,51 +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 - ******************************************************************************/ - -#ifndef EXTENSION_CONFIG_HPP_ -#define EXTENSION_CONFIG_HPP_ - -#include <libmodman/module.hpp> -#include "url.hpp" - -namespace libproxy { -using namespace std; -using namespace libmodman; - -// Config module -class DLL_PUBLIC config_extension : public extension<config_extension> { -public: - // Abstract methods - virtual vector<url> get_config(const url &dst) =0; - - // Virtual methods - virtual string get_ignore(const url &dst); - virtual bool set_creds(const url &proxy, const string &username, const string &password); - - // Final methods - bool get_valid(); - void set_valid(bool valid); - virtual bool operator<(const base_extension&) const; - -private: - bool valid; -}; - -} - -#endif /* EXTENSION_CONFIG_HPP_ */ diff --git a/libproxy/extension_ignore.hpp b/libproxy/extension_ignore.hpp deleted file mode 100644 index 63845fe..0000000 --- a/libproxy/extension_ignore.hpp +++ /dev/null @@ -1,38 +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 - ******************************************************************************/ - -#ifndef EXTENSION_IGNORE_HPP_ -#define EXTENSION_IGNORE_HPP_ - -#include <libmodman/module.hpp> - -#include "url.hpp" - -namespace libproxy { -using namespace std; -using namespace libmodman; - -class DLL_PUBLIC ignore_extension : public extension<ignore_extension> { -public: - virtual bool ignore(url& dst, const string &ignorestr)=0; -}; - -} - -#endif /* EXTENSION_IGNORE_HPP_ */ diff --git a/libproxy/extension_pacrunner.hpp b/libproxy/extension_pacrunner.hpp deleted file mode 100644 index 4834eb9..0000000 --- a/libproxy/extension_pacrunner.hpp +++ /dev/null @@ -1,63 +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 - ******************************************************************************/ - -#ifndef EXTENSION_PACRUNNER_HPP_ -#define EXTENSION_PACRUNNER_HPP_ - -#include <libmodman/module.hpp> -#include "url.hpp" - -#define PX_PACRUNNER_MODULE_EZ(name, symb, smod) \ - class name ## _pacrunner_extension : public pacrunner_extension { \ - protected: \ - virtual pacrunner* create(string pac, const url& pacurl) { \ - return new name ## _pacrunner(pac, pacurl); \ - } \ - }; \ - MM_MODULE_INIT_EZ(name ## _pacrunner_extension, true, symb, smod) - -namespace libproxy { -using namespace std; -using namespace libmodman; - -// PACRunner module -class DLL_PUBLIC pacrunner { -public: - pacrunner(const string &pac, const url& pacurl); - virtual ~pacrunner() {}; - virtual string run(const url& url) =0; -}; - -class DLL_PUBLIC pacrunner_extension : public extension<pacrunner_extension, true> { -public: - // Virtual methods - virtual pacrunner* get(const string &pac, const url& pacurl); - virtual ~pacrunner_extension(); - - // Final methods - pacrunner_extension(); - -protected: - // Abstract methods - virtual pacrunner* create(string pac, const url& pacurl) =0; -}; - -} - -#endif /* EXTENSION_PACRUNNER_HPP_ */ diff --git a/libproxy/extension_wpad.cpp b/libproxy/extension_wpad.cpp deleted file mode 100644 index 1f4d9b0..0000000 --- a/libproxy/extension_wpad.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "extension_wpad.hpp" -using namespace libproxy; - -#include <cstring> - -static const char *DEFAULT_WPAD_ORDER[] = { - "dhcp", - "slp", - "dns_srv", - "dns_txt", - "dns_alias", - NULL -}; - -bool wpad_extension::operator<(const wpad_extension& other) const { - for (int i=0 ; DEFAULT_WPAD_ORDER[i] ; i++) { - if (strstr(other.get_base_type(), DEFAULT_WPAD_ORDER[i])) - break; - if (strstr(this->get_base_type(), DEFAULT_WPAD_ORDER[i])) - return true; - } - return false; -} diff --git a/libproxy/extension_wpad.hpp b/libproxy/extension_wpad.hpp deleted file mode 100644 index 6c2f52d..0000000 --- a/libproxy/extension_wpad.hpp +++ /dev/null @@ -1,45 +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 - ******************************************************************************/ - -#ifndef EXTENSION_WPAD_HPP_ -#define EXTENSION_WPAD_HPP_ - -#include <libmodman/module.hpp> -#include "url.hpp" - -namespace libproxy { -using namespace std; -using namespace libmodman; - -// WPAD module -class DLL_PUBLIC wpad_extension : public extension<wpad_extension> { -public: - // Abstract methods - virtual bool found()=0; - virtual url* next(char** pac)=0; - virtual void rewind()=0; - - // Virtual methods - virtual bool operator<(const wpad_extension& module) const; - using extension<wpad_extension>::operator<; -}; - -} - -#endif /* EXTENSION_WPAD_HPP_ */ diff --git a/libproxy/libproxy-1.0.pc.in b/libproxy/libproxy-1.0.pc.in deleted file mode 100644 index bfc031c..0000000 --- a/libproxy/libproxy-1.0.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@PKGCONFIG_PREFIX@ -libdir=@PKGCONFIG_LIBDIR@ -includedir=@PKGCONFIG_INCLUDEDIR@ - -Name: libproxy-1.0 -Description: Proxy Configuration Library -Version: @PROJECT_VERSION@ -Libs: -L${libdir} -lproxy -Libs.private: -lpthread -lm -Cflags: -I${includedir} 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/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); diff --git a/libproxy/proxy.cpp b/libproxy/proxy.cpp deleted file mode 100644 index 5db3033..0000000 --- a/libproxy/proxy.cpp +++ /dev/null @@ -1,500 +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 <vector> -#include <cstring> // For strdup() -#include <iostream> // For cerr -#include <stdexcept> // For exception -#include <typeinfo> // Only for debug messages. - -#include <libmodman/module_manager.hpp> - -#include "extension_config.hpp" -#include "extension_ignore.hpp" -#include "extension_network.hpp" -#include "extension_pacrunner.hpp" -#include "extension_wpad.hpp" - -#ifdef WIN32 -#define strdup _strdup -#endif - -#define X(m) MM_DEF_BUILTIN(m); -BUILTIN_MODULES -#undef X - -#define X(m) &MM_BUILTIN(m), -static struct mm_module* builtin_modules[] = { - BUILTIN_MODULES - NULL -}; -#undef X - -namespace libproxy { -using namespace std; - -class proxy_factory { -public: - proxy_factory(); - ~proxy_factory(); - vector<string> get_proxies(const string &url); - -private: - void lock(); - void unlock(); - - void check_network_topology(); - void get_config(url &realurl, vector<url> &configs, string &ignore); - bool is_ignored(url &realurl, const string &ignore); - bool expand_wpad(const url &confurl); - bool expand_pac(url &configurl); - void run_pac(url &realurl, const url &confurl, vector<string> &response); - void clear_cache(); - -#ifdef WIN32 - HANDLE mutex; -#else - pthread_mutex_t mutex; -#endif - module_manager mm; - char* pac; - url* pacurl; - bool wpad; - bool debug; -}; - -static bool istringcmp(string a, string b) { - transform( a.begin(), a.end(), a.begin(), ::tolower ); - transform( b.begin(), b.end(), b.begin(), ::tolower ); - return ( a == b ); -} - -// Convert the PAC formatted response into our proxy URL array response -static void format_pac_response(string response, vector<string> &retval) -{ - // Skip ahead one character if we start with ';' - if (response[0] == ';') { - format_pac_response(response.substr(1), retval); - return; - } - - // If the string contains a delimiter (';') - if (response.find(';') != string::npos) { - format_pac_response(response.substr(response.find(';') + 1), retval); - response = response.substr(0, response.find(';')); - } - - // Strip whitespace - if (response.size() > 0) - response = response.substr(response.find_first_not_of(" \t\n"), response.find_last_not_of(" \t\n")+1); - - // Get the method and the server - string method = ""; - string server = ""; - if (response.find_first_of(" \t") == string::npos) - method = response; - else { - method = response.substr(0, response.find_first_of(" \t")); - server = response.substr(response.find_first_of(" \t") + 1); - } - - // Insert our url value - if (istringcmp(method, "proxy") && url::is_valid("http://" + server)) - retval.insert(retval.begin(), string("http://") + server); - else if (istringcmp(method, "socks") && url::is_valid("http://" + server)) - retval.insert(retval.begin(), string("socks://") + server); - else if (istringcmp(method, "socks4") && url::is_valid("http://" + server)) - retval.insert(retval.begin(), string("socks4://") + server); - else if (istringcmp(method, "socks4a") && url::is_valid("http://" + server)) - retval.insert(retval.begin(), string("socks4a://") + server); - else if (istringcmp(method, "socks5") && url::is_valid("http://" + server)) - retval.insert(retval.begin(), string("socks5://") + server); - else if (istringcmp(method, "direct")) - retval.insert(retval.begin(), string("direct://")); -} - -proxy_factory::proxy_factory() { - const char *module_dir; - -#ifdef WIN32 - this->mutex = CreateMutex(NULL, false, NULL); - WSADATA wsadata; - WORD vers = MAKEWORD(2, 2); - WSAStartup(vers, &wsadata); -#else - pthread_mutex_init(&this->mutex, NULL); -#endif - - lock(); - - this->pac = NULL; - this->pacurl = NULL; - this->wpad = false; - - // Register our types - this->mm.register_type<config_extension>(); - this->mm.register_type<ignore_extension>(); - this->mm.register_type<network_extension>(); - this->mm.register_type<pacrunner_extension>(); - this->mm.register_type<wpad_extension>(); - - // Load builtin modules - for (int i=0 ; builtin_modules[i] ; i++) - this->mm.load_builtin(builtin_modules[i]); - - // Load all modules - module_dir = getenv("PX_MODULE_PATH"); - if (!module_dir) - module_dir = MODULEDIR; - this->mm.load_dir(module_dir); - this->mm.load_dir(module_dir, false); - - this->debug = (getenv("_PX_DEBUG") != NULL); - - unlock(); -} - -proxy_factory::~proxy_factory() { - lock(); - - if (this->pac) delete[] this->pac; - if (this->pacurl) delete this->pacurl; - - unlock(); - -#ifdef WIN32 - WSACleanup(); - ReleaseMutex(this->mutex); -#else - pthread_mutex_destroy(&this->mutex); -#endif -} - - -vector<string> proxy_factory::get_proxies(const string &realurl) { - vector<string> response; - - // Check to make sure our url is valid - if (!url::is_valid(realurl)) - goto do_return; - - lock(); - - // Let trap and forward exceptions so we don't deadlock - try { - vector<url> configs; - string ignore; - url dst(realurl); - - check_network_topology(); - get_config(dst, configs, ignore); - - if (debug) cerr << "Config is: " << endl; - - for (vector<url>::iterator i=configs.begin() ; i != configs.end() ; i++) { - url confurl(*i); - - if (debug) cerr << "\t" << confurl.to_string() << endl; - - if (expand_wpad(confurl) || expand_pac(confurl)) { - run_pac(dst, confurl, response); - } else { - clear_cache(); - response.push_back(confurl.to_string()); - } - } - - unlock(); - } catch (exception &e) { - unlock(); - throw e; - } - -do_return: - if (response.size() == 0) - response.push_back("direct://"); - return response; -} - -void proxy_factory::check_network_topology() { - vector<network_extension*> networks; - - // Check to see if our network topology has changed... - networks = this->mm.get_extensions<network_extension>(); - for (vector<network_extension*>::iterator i=networks.begin() ; i != networks.end() ; i++) { - // If it has, reset our wpad/pac setup and we'll retry our config - if ((*i)->changed()) { - if (debug) cerr << "Network changed" << endl; - vector<wpad_extension*> wpads = this->mm.get_extensions<wpad_extension>(); - for (vector<wpad_extension*>::iterator j=wpads.begin() ; j != wpads.end() ; j++) - (*j)->rewind(); - if (this->pac) delete[] this->pac; - this->pac = NULL; - break; - } - } -} - -void proxy_factory::get_config(url &realurl, vector<url> &config, string &ignore) { - vector<config_extension*> configs; - - configs = this->mm.get_extensions<config_extension>(); - for (vector<config_extension*>::iterator i=configs.begin() ; i != configs.end() ; i++) { - config_extension *configurator = *i; - - // Try to get the configuration - try { - ignore = configurator->get_ignore(realurl); - if (!is_ignored(realurl, ignore)) - config = configurator->get_config(realurl); - if (debug) { - if (configurator) { - cerr << "Configuration extension is: " << typeid(*configurator).name() << endl; - cerr << "Ignored list is: " << ignore << endl; - } else { - cerr << "No configuration extension found." << endl; - } - } - break; - } - catch (runtime_error e) { - ignore = ""; - } - } -} - -bool proxy_factory::is_ignored(url &realurl, const string &ignore) { - vector<ignore_extension*> ignores; - bool ignored = false, invign = false; - string confign = ignore; - - /* Check our ignore patterns */ - ignores = this->mm.get_extensions<ignore_extension>(); - 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); - if (next == string::npos) next = confign.length(); - if (next > (i+1)) { - string ignorestr = confign.substr (i, next - i); - ignorestr = ignorestr.substr(ignorestr.find_first_not_of(" \t\n"), ignorestr.find_last_not_of(" \t\n")+1); - for (vector<ignore_extension*>::iterator it=ignores.begin() ; it != ignores.end() && !ignored ; it++) - ignored = ((*it)->ignore(realurl, ignorestr)); - } - i = next+1; - } - - if (invign) - return !ignored; - else - return ignored; -} - -bool proxy_factory::expand_wpad(const url &confurl) -{ - bool rtv = false; - if (confurl.get_scheme() == "wpad") { - rtv = true; - /* If the config has just changed from PAC to WPAD, clear the PAC */ - if (!this->wpad) { - if (this->pac) delete[] this->pac; - if (this->pacurl) delete this->pacurl; - this->pac = NULL; - this->pacurl = NULL; - this->wpad = true; - } - - /* If we have no PAC, get one */ - if (!this->pac) { - if (debug) cerr << "Trying to find the PAC using WPAD..." << endl; - vector<wpad_extension*> wpads = this->mm.get_extensions<wpad_extension>(); - for (vector<wpad_extension*>::iterator i=wpads.begin() ; i != wpads.end() ; i++) { - if (debug) cerr << "WPAD search via: " << typeid(**i).name() << endl; - if ((this->pacurl = (*i)->next(&this->pac))) { - if (debug) cerr << "PAC found!" << endl; - break; - } - } - - /* If getting the PAC fails, but the WPAD cycle worked, restart the cycle */ - if (!this->pac) { - if (debug) cerr << "No PAC found..." << endl; - for (vector<wpad_extension*>::iterator i=wpads.begin() ; i != wpads.end() ; i++) { - if ((*i)->found()) { - if (debug) cerr << "Resetting WPAD search..." << endl; - - /* Since a PAC was found at some point, - * rewind all the WPADS to start from the beginning */ - /* Yes, the reuse of 'i' here is intentional... - * This is because if *any* of the wpads have found a pac, - * we need to reset them all to keep consistent state. */ - for (i=wpads.begin() ; i != wpads.end() ; i++) - (*i)->rewind(); - - // Attempt to find a PAC - for (i=wpads.begin() ; i != wpads.end() ; i++) { - if (debug) cerr << "WPAD search via: " << typeid(**i).name() << endl; - if ((this->pacurl = (*i)->next(&this->pac))) { - if (debug) cerr << "PAC found!" << endl; - break; - } - } - break; - } - } - } - } - } - - return rtv; -} - -bool proxy_factory::expand_pac(url &confurl) -{ - bool rtv = false; - - // If we have a PAC config - if (confurl.get_scheme().substr(0, 4) == "pac+") { - rtv = true; - - /* Save the PAC config */ - if (this->wpad) - this->wpad = false; - - /* If a PAC already exists, but came from a different URL than the one specified, remove it */ - if (this->pac) { - if (this->pacurl->to_string() != confurl.to_string()) { - delete this->pacurl; - delete[] this->pac; - this->pacurl = NULL; - this->pac = NULL; - } - } - - /* Try to load the PAC if it is not already loaded */ - if (!this->pac) { - this->pacurl = new url(confurl); - this->pac = confurl.get_pac(); - if (debug) { - if (!this->pac) - cerr << "Unable to download PAC!" << endl; - else - cerr << "PAC received!" << endl; - } - } - } - - return rtv; -} - -void proxy_factory::run_pac(url &realurl, const url &confurl, vector<string> &response) { - /* In case of either PAC or WPAD, we'll run the PAC */ - if (this->pac && (confurl.get_scheme() == "wpad" || confurl.get_scheme().substr(0, 4) == "pac+") ) { - vector<pacrunner_extension*> pacrunners = this->mm.get_extensions<pacrunner_extension>(); - - /* No PAC runner found, fall back to direct */ - if (pacrunners.size() == 0) { - if (debug) cerr << "Unable to find a required pacrunner!" << endl; - return; - } - - /* Run the PAC, but only try one PACRunner */ - if (debug) cerr << "Using pacrunner: " << typeid(*pacrunners[0]).name() << endl; - pacrunner* runner = pacrunners[0]->get(this->pac, this->pacurl->to_string()); - string pacresp = runner->run(realurl); - delete runner; - if (debug) cerr << "Pacrunner returned: " << pacresp << endl; - format_pac_response(pacresp, response); - } -} - -void proxy_factory::clear_cache() { - this->wpad = false; - if (this->pac) { delete[] this->pac; this->pac = NULL; } - if (this->pacurl) { delete this->pacurl; this->pacurl = NULL; } -} - -void proxy_factory::lock() { -#ifdef WIN32 - WaitForSingleObject(this->mutex, INFINITE); -#else - pthread_mutex_lock(&this->mutex); -#endif -} - -void proxy_factory::unlock() { -#ifdef WIN32 - ReleaseMutex(this->mutex); -#else - pthread_mutex_unlock(&this->mutex); -#endif -} - -}; - -struct pxProxyFactory_ { - libproxy::proxy_factory pf; -}; - -extern "C" DLL_PUBLIC struct pxProxyFactory_ *px_proxy_factory_new(void) { - return new struct pxProxyFactory_; -} - -extern "C" DLL_PUBLIC char** px_proxy_factory_get_proxies(struct pxProxyFactory_ *self, const char *url) { - std::vector<std::string> proxies; - char** retval; - - // Call the main method - try { - proxies = self->pf.get_proxies(url); - retval = (char**) malloc(sizeof(char*) * (proxies.size() + 1)); - if (!retval) return NULL; - } catch (std::exception&) { - // Return NULL on any exception - return NULL; - } - - // Copy the results into an array - // Return NULL on memory allocation failure - retval[proxies.size()] = NULL; - for (size_t i=0 ; i < proxies.size() ; i++) { - retval[i] = strdup(proxies[i].c_str()); - if (retval[i] == NULL) { - for (int j=i-1 ; j >= 0 ; j--) - free(retval[j]); - free(retval); - return NULL; - } - } - return retval; -} - -extern "C" DLL_PUBLIC void px_proxy_factory_free_proxies(char ** const proxies) { - if (!proxies) - return; - - for (size_t i = 0; proxies[i]; ++i) - free(proxies[i]); - - free(proxies); -} - -extern "C" DLL_PUBLIC void px_proxy_factory_free(struct pxProxyFactory_ *self) { - delete self; -} diff --git a/libproxy/test/CMakeLists.txt b/libproxy/test/CMakeLists.txt deleted file mode 100644 index 8894425..0000000 --- a/libproxy/test/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -#### -## Libproxy Tests -#### - -include_directories(${PROJECT_SOURCE_DIR}) - -# URL Test -add_executable(url-test ${CMAKE_CURRENT_SOURCE_DIR}/url-test.cpp ${PROJECT_SOURCE_DIR}/url.cpp) -if(WIN32) - target_link_libraries(url-test ws2_32) -endif() -add_test(NAME url-test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/url-test) - -# URL Encode -add_executable(url-encode ${CMAKE_CURRENT_SOURCE_DIR}/url-encode.cpp ${PROJECT_SOURCE_DIR}/url.cpp) -if(WIN32) - target_link_libraries(url-encode ws2_32) -endif() -add_test(NAME url-encode COMMAND ${CMAKE_CURRENT_BINARY_DIR}/url-encode) - -# Get PAC -if (NOT WIN32) -add_executable(get-pac-test ${CMAKE_CURRENT_SOURCE_DIR}/get-pac-test.cpp ${PROJECT_SOURCE_DIR}/url.cpp) -target_link_libraries(get-pac-test pthread) -add_test(NAME get-pac-test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/get-pac-test) -endif() diff --git a/libproxy/test/get-pac-test.cpp b/libproxy/test/get-pac-test.cpp deleted file mode 100644 index 911f296..0000000 --- a/libproxy/test/get-pac-test.cpp +++ /dev/null @@ -1,316 +0,0 @@ -#include <cassert> -#include <iostream> -#include <sstream> -#include <string> - -#include <stdlib.h> // for abort() -#include <errno.h> // for EINTR -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <sys/select.h> -#include <unistd.h> -#include <string.h> -#include <pthread.h> - -#include "url.hpp" - -// macOS does not define MSG_NOSIGNAL, but uses the SO_NOSIGPIPE option instead -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - -using namespace libproxy; - -class TestServer { - public: - TestServer(in_port_t port) - : m_port(port) - ,m_sock(-1) - - { - m_pipe[0] = -1; - m_pipe[1] = -1; - } - - void start() - { - struct sockaddr_in addr = {0}; - int ret; - int i = 1; - - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - addr.sin_port = ntohs(m_port); - - if (m_sock != -1) - return; - - m_sock = socket(AF_INET, SOCK_STREAM, 0); - assert(m_sock > 0); - - setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)); - - ret = ::bind(m_sock, (sockaddr*)&addr, sizeof (struct sockaddr_in)); - assert(!ret); - - ret = listen(m_sock, 1); - assert(!ret); - - ret = pipe(m_pipe); - assert(!ret); - - ret = pthread_create(&m_thread, NULL, TestServer::server_thread, this); - assert(!ret); - } - - void stop() - { - int ret; - do - { - ret = write(m_pipe[1], (void*)"q", 1); - } while (errno == EINTR); - if (ret < 0) abort(); // We could not write to the pipe anymore - pthread_join (m_thread, NULL); - close(m_pipe[1]); - m_pipe[1] = -1; - close(m_sock); - m_sock = -1; - } - - private: - static void * server_thread(void *data) - { - TestServer *server = (TestServer*)data; - while (server->loop()) {} - return NULL; - } - - bool loop() - { - int ret; - fd_set fds; - struct sockaddr_in addr; - int lf_count = 0; - bool done = false; - char buffer[1024]; - char *ptr; - int csock; - socklen_t len = sizeof (struct sockaddr_in); - - FD_ZERO (&fds); - FD_SET (m_pipe[0], &fds); - FD_SET (m_sock, &fds); - - memset(buffer, 0, 1024); - - // Wait for connection - ret = select(max(m_pipe[0], m_sock) + 1, &fds, NULL, NULL, NULL); - assert(ret > 0); - - if (FD_ISSET (m_pipe[0], &fds)) { - close(m_pipe[0]); - m_pipe[0] = -1; - - return false; - } - - csock = accept(m_sock, (sockaddr*) &addr, &len); - assert(csock > 0); - // OSX/BSD may not have MSG_NOSIGNAL, try SO_NOSIGPIPE instead -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#ifdef SO_NOSIGPIPE - int no_sig_pipe = 1; - setsockopt(csock, SOL_SOCKET, SO_NOSIGPIPE, &no_sig_pipe, sizeof(int)); -#endif -#endif - -#ifdef SO_NOSIGPIPE - int i = 1; - setsockopt(csock, SOL_SOCKET, SO_NOSIGPIPE, &i, sizeof(i)); -#endif - - // Read request - ptr = buffer; - do { - ret = recv (csock, ptr, 1, 0); - if (ret <= 0) - goto done; - - if (*ptr == '\n') { - lf_count++; - } else if (*ptr != '\r') { - lf_count = 0; - } - - if (lf_count == 2) - done = true; - - ptr++; - assert((int) (ptr - buffer) < 1024); - } while (!done); - - if (strstr(buffer, "basic")) { - sendBasic(csock); - } else if (strstr(buffer, "truncated")) { - sendTruncated(csock); - } else if (strstr(buffer, "overflow")) { - sendOverflow(csock); - } else if (strstr(buffer, "chunked")) { - sendChunked(csock); - } else if (strstr(buffer, "without_content_length")) { - sendWithoutContentLength(csock); - } else if (strstr(buffer, "parameterized")) { - assert(strstr(buffer, "?arg1=foo&arg2=bar") != NULL); - sendBasic(csock); - } else { - assert(!"Unsupported request"); - } - -done: - close(csock); - return true; - } - - void sendBasic(int csock) - { - int ret; - const char *basic = - "HTTP/1.1 200 OK\n" \ - "Content-Type: text/plain\n" \ - "Content-Length: 10\n" \ - "\n" \ - "0123456789"; - ret = send(csock, (void*)basic, strlen(basic), 0); - assert(ret == strlen(basic)); - shutdown(csock, SHUT_RDWR); - close(csock); - } - - void sendTruncated(int csock) - { - int ret; - const char *basic = - "HTTP/1.1 200 OK\n" \ - "Content-Type: text/plain\n" \ - "Content-Length: 10\n" \ - "\n" \ - "01234"; - ret = send(csock, (void*)basic, strlen(basic), 0); - assert(ret == strlen(basic)); - shutdown(csock, SHUT_RDWR); - close(csock); - } - - void sendOverflow(int csock) - { - int ret; - int size = 50000000; // Must be larger than the kernel TCP receive buffer - char *buf = new char[size]; - memset(buf, 1, size); - - const char *basic = - "HTTP/1.1 200 OK\n" \ - "Content-Type: text/plain\n" \ - "Content-Length: 50000000\n" \ - "\n"; - ret = send(csock, (void*)basic, strlen(basic), MSG_NOSIGNAL); - assert(ret == strlen(basic)); - ret = send(csock, (void*)buf, size, MSG_NOSIGNAL); - if (ret == size) - abort(); // Test failed... the socket should not accept the whole buffer - delete[] buf; - shutdown(csock, SHUT_RDWR); - close(csock); - } - - void sendChunked(int csock) - { - int ret; - const char *chunked = - "HTTP/1.1 200 OK\n" \ - "Content-Type: text/plain\n" \ - "Transfer-Encoding: chunked\n" \ - "\n" \ - "5\n" \ - "01234" \ - "\n" \ - "5\n" \ - "56789" \ - "\n"; - ret = send(csock, (void*)chunked, strlen(chunked), 0); - assert(ret == strlen(chunked)); - shutdown(csock, SHUT_RDWR); - close(csock); - } - - void sendWithoutContentLength(int csock) - { - int ret; - const char *basic = - "HTTP/1.1 200 OK\n" \ - "Content-Type: text/plain\n" \ - "\n" \ - "0123456789"; - ret = send(csock, (void*)basic, strlen(basic), 0); - assert(ret == strlen(basic)); - shutdown(csock, SHUT_RDWR); - close(csock); - } - - in_port_t m_port; - int m_sock; - int m_pipe[2]; - pthread_t m_thread; -}; - - -int main() -{ - TestServer server(1983); - int rtv = 0; - char *pac; - - url basic("http://localhost:1983/basic.js"); - url truncated("http://localhost:1983/truncated.js"); - url overflow("http://localhost:1983/overflow.js"); - url chunked("http://localhost:1983/chunked.js"); - url without_content_length("http://localhost:1983/without_content_length.js"); - url parameterized("http://localhost:1983/parameterized.js?arg1=foo&arg2=bar"); - - server.start(); - - pac = basic.get_pac(); - if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) - return 1; // test failed, exit with error code - delete[] pac; // test succesful, cleanup - - pac = truncated.get_pac(); - if (pac != NULL) - return 2; // Test failed, exit with error code - - pac = overflow.get_pac(); - if (pac != NULL) - return 3; // Test failed, exit with error code - - pac = chunked.get_pac(); - if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) - return 4; // Test failed, exit with error code - - pac = without_content_length.get_pac(); - if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) - return 5; // Test failed, exit with error code - delete[] pac; - - pac = parameterized.get_pac(); - if (!(pac != NULL && strlen(pac) == 10 && !strcmp("0123456789", pac))) - return 5; // Test failed, exit with error code - delete[] pac; - - server.stop(); - - return 0; -} diff --git a/libproxy/test/url-encode.cpp b/libproxy/test/url-encode.cpp deleted file mode 100644 index ef386a3..0000000 --- a/libproxy/test/url-encode.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include <cassert> -#include <iostream> -#include <string> - - -#include "url.hpp" - -using namespace libproxy; - -#define test(cond,rtv) _test(#cond, (cond), (rtv)) -void _test (const string &exp, bool condition, bool &rtv) -{ - if (!condition) { - cerr << "Failed: " << exp << endl; - rtv = false; - } -} - -int main() -{ - bool rtv = true; - string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"; - - test(url::encode(valid) == valid, rtv); - test(url::encode("é") == "%c3%a9", rtv); - test(url::encode("+!@#$^\r%", "!#^") == "%2b!%40#%24^%0d%25", rtv); - - return !rtv; -} diff --git a/libproxy/test/url-test.cpp b/libproxy/test/url-test.cpp deleted file mode 100644 index 6f61859..0000000 --- a/libproxy/test/url-test.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include <cassert> -#include <iostream> -#include <sstream> -#include <string> - - -#include "url.hpp" - -using namespace libproxy; - -void assert_equal_str (const std::string &what, - const std::string &in, - const std::string &value, - const std::string &ref) -{ - if (value != ref) - throw logic_error(what + " in URL " + in + " is '" - + value + "' instead of '" + ref + "'"); -} - -void assert_equal_int (const std::string &what, - const std::string &in, - int value, - int ref) -{ - if (value != ref) { - ostringstream s; - s << what << " in URL " << in << " is " - << value << " instead of " << ref; - throw logic_error(s.str()); - } -} - -void try_url (const std::string &link, bool &rtv, - const std::string &scheme, - const std::string &user, - const std::string &pass, - const std::string &host, - int port, - const std::string &path) -{ - try { - url u(link); - - assert_equal_str ("Scheme", u.to_string(), u.get_scheme(), scheme); - assert_equal_str ("User", u.to_string(), u.get_username(), user); - assert_equal_str ("Pass", u.to_string(), u.get_password(), pass); - assert_equal_str ("Host", u.to_string(), u.get_host(), host); - assert_equal_int ("Port", u.to_string(), u.get_port(), port); - assert_equal_str ("Path", u.to_string(), u.get_path(), path); - } - catch (exception &e) { - std::cerr << e.what() << std::endl; - rtv = false; - } -} - -int main() -{ - bool rtv = true; - -#ifdef WIN32 - WSADATA wsadata; - WORD vers = MAKEWORD(2, 2); - WSAStartup(vers, &wsadata); -#endif - - try_url ("file:///allo", rtv, - "file", - "", "", - "", 0, - "/allo"); - - try_url ("http://test.com", rtv, - "http", - "", "", - "test.com", 80, - ""); - - try_url ("http://test.com/", rtv, - "http", - "", "", - "test.com", 80, - "/"); - - try_url ("http://test.com#", rtv, - "http", - "", "", - "test.com", 80, - ""); - - try_url ("http://test.com?", rtv, - "http", - "", "", - "test.com", 80, - ""); - - try_url ("http://nicolas@test.com", rtv, - "http", - "nicolas", "", - "test.com", 80, - ""); - - try_url ("http://nicolas:@test.com", rtv, - "http", - "nicolas", "", - "test.com", 80, - ""); - - try_url ("http://nicolas:secret@test.com", rtv, - "http", - "nicolas", "secret", - "test.com", 80, - ""); - - try_url ("http://:secret@test.com", rtv, - "http", - "", "secret", - "test.com", 80, - ""); - - try_url ("http+ssh://:secret@test.com", rtv, - "http+ssh", - "", "secret", - "test.com", 22, - ""); - - try_url ("HtTp://TeSt.CoM/ALLO", rtv, - "http", - "", "", - "test.com", 80, - "/ALLO"); - - /* This is a very uncommon but valid case that use to cause crash */ - try_url ("www.google.com:80", rtv, - "www.google.com", - "", "", - "", 0, - "80"); - - /* Handle the case where there is nothing other than the scheme */ - try_url ("http://", rtv, - "http", - "", "", - "", 80, - ""); - - /* Check windows style URL */ - try_url ("file:///E:/dir/file.pac", rtv, - "file", - "", "", - "", 0, -#ifdef WIN32 - "E:\\dir\\file.pac"); -#else - "/E:/dir/file.pac"); -#endif - - /* UNC windows URL */ - try_url ("file://server/dir/file.pac", rtv, - "file", - "", "", - "server", 0, -#ifdef WIN32 - "\\\\server\\dir\\file.pac"); -#else - "/dir/file.pac"); -#endif - -#ifdef WIN32 - WSACleanup(); -#endif - - return !rtv; -} diff --git a/libproxy/url.cpp b/libproxy/url.cpp deleted file mode 100644 index 6925745..0000000 --- a/libproxy/url.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com> - * - * Based on work found in GLib GIO: - * Copyright (C) 2006-2007 Red Hat, 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 <fcntl.h> // For ::open() -#include <cstring> // For memcpy() -#include <sstream> // For int/string conversion (using stringstream) -#include <cstdio> // For sscanf() -#include <cstdlib> // For atoi() -#include <cerrno> // For errno and EINTR -#include <sys/stat.h> // For stat() -#include <algorithm> // For transform() - -#ifdef WIN32 -#include <io.h> -#define open _open -#define O_RDONLY _O_RDONLY -#define close _close -#define read _read -#define SHUT_RDWR SD_BOTH -#else -#include <unistd.h> // For read() close() -#define closesocket close -#endif - -#include "url.hpp" -using namespace libproxy; -using namespace std; - -// This mime type should be reported by the web server -#define PAC_MIME_TYPE "application/x-ns-proxy-autoconfig" -// Fall back to checking for this mime type, which servers often report wrong -#define PAC_MIME_TYPE_FB "text/plain" - -// This is the maximum pac size (to avoid memory attacks) -#define PAC_MAX_SIZE 0x800000 -// This is the default block size to use when receiving via HTTP -#define PAC_HTTP_BLOCK_SIZE 512 - -static inline int get_default_port(string scheme) { - struct servent *serv; - size_t plus = scheme.find('+'); - - if (plus != string::npos) - scheme = scheme.substr(plus + 1); - - if ((serv = getservbyname(scheme.c_str(), NULL))) - return ntohs(serv->s_port); - - return 0; -} - -template <class T> -static inline string to_string_ (const T& t) { - stringstream ss; - ss << t; - return ss.str(); -} - -#define _copyaddr_t(type, addr) (sockaddr*) memcpy(new type, &(addr), sizeof(type)) -static inline sockaddr* copyaddr(const struct sockaddr& addr) { - switch (addr.sa_family) { - case (AF_INET): - return _copyaddr_t(sockaddr_in, addr); - case (AF_INET6): - return _copyaddr_t(sockaddr_in6, addr); - default: - return NULL; - } -} - -bool url::is_valid(const string &url_) { - bool rtv = true; - - try { - url url(url_); - } catch (parse_error&) { - rtv = false; - } - - return rtv; -} - -string url::encode(const string &data, const string &valid_reserved) { - ostringstream encoded; - 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]; - else - encoded << '%' - << ((unsigned char)data[i] < 16 ? "0" : "") - << hex << (((int)data[i]) & 0xff); - } - return encoded.str(); -} - -url::url(const string &url) - : m_orig(url), m_port(0), m_ips(NULL) { - size_t idx = 0; - size_t hier_part_start, hier_part_end; - size_t query_part_start; - size_t path_start, path_end; - string hier_part; - - /* From RFC 3986 Decodes: - * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] - */ - - idx = 0; - - /* Decode scheme: - * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) - */ - - if (!isalpha(url[idx])) - throw parse_error("Invalid URL: " + url); - - while (1) { - char c = url[idx++]; - - if (c == ':') break; - - if (!(isalnum(c) || - c == '+' || - c == '-' || - c == '.')) - throw parse_error("Invalid URL: " + url); - } - - m_scheme = url.substr(0, idx - 1); - transform(m_scheme.begin(), m_scheme.end(), m_scheme.begin(), ::tolower); - - hier_part_start = idx; - hier_part_end = url.find('#', idx); - query_part_start = url.find('?', idx); - if (query_part_start != string::npos) - { - if (hier_part_end == string::npos) - m_query = url.substr(query_part_start); - else { - m_query = url.substr(query_part_start, hier_part_end - query_part_start); - } - hier_part_end = query_part_start; - } - - hier_part = url.substr(hier_part_start, - hier_part_end == string::npos ? - string::npos : hier_part_end - hier_part_start); - - /* 3: - * hier-part = "//" authority path-abempty - * / path-absolute - * / path-rootless - * / path-empty - */ - - if (hier_part.size() >= 2 && hier_part[0] == '/' && hier_part[1] == '/') { - size_t authority_start, authority_end; - size_t userinfo_start, userinfo_end; - size_t host_start, host_end; - - authority_start = 2; - /* authority is always followed by / or nothing */ - authority_end = hier_part.find('/', authority_start); - if (authority_end == string::npos) - authority_end = hier_part.size(); - path_start = authority_end; - - /* 3.2: - * authority = [ userinfo "@" ] host [ ":" port ] - */ - - /* Get user and password */ - userinfo_start = authority_start; - userinfo_end = hier_part.find('@', authority_start); - if (userinfo_end != string::npos) { - size_t user_end; - - user_end = hier_part.rfind(':', userinfo_end); - if (user_end == string::npos) - user_end = userinfo_end; - else - m_pass = hier_part.substr(user_end + 1, userinfo_end - (user_end + 1)); - - m_user = hier_part.substr(userinfo_start, user_end - userinfo_start); - } - - /* Get hostname */ - if (userinfo_end == string::npos) - host_start = authority_start; - else - host_start = userinfo_end + 1; - - /* Check for IPv6 IP */ - 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); - host_end++; - if (hier_part[host_end] == '\0') - host_end = string::npos; - } else { - host_end = hier_part.find(':', host_start); - if (path_start < host_end) - host_end = path_start; - } - - /* If not port, host ends where path starts */ - if (host_end == string::npos) - host_end = path_start; - - m_host = hier_part.substr(host_start, host_end - host_start); - transform(m_host.begin(), m_host.end(), m_host.begin(), ::tolower); - - /* Get port */ - m_port = get_default_port(m_scheme); - - 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); - } - } else { - path_start = 0; - } - - /* Get path */ - if (path_start != string::npos) - { - path_end = hier_part_end; - if (path_end == string::npos) - m_path = hier_part.substr(path_start); - else - m_path = hier_part.substr(path_start, path_end - path_start); - } -} - -url::url(const url &url) : m_ips(NULL) { - *this = url; -} - -url::~url() { - empty_cache(); -} - -bool url::operator==(const url& url) const { - return m_orig == url.to_string(); -} - -url& url::operator=(const url& url) { - // Ensure these aren't the same objects - if (&url == this) - return *this; - - m_host = url.m_host; - m_orig = url.m_orig; - m_pass = url.m_pass; - m_path = url.m_path; - m_query = url.m_query; - m_port = url.m_port; - m_scheme = url.m_scheme; - m_user = url.m_user; - - empty_cache(); - - if (url.m_ips) { - int i; - - // Copy the new ip cache - for (i=0 ; url.m_ips[i] ; i++) {}; - m_ips = new sockaddr*[i]; - for (i=0 ; url.m_ips[i] ; i++) - m_ips[i] = copyaddr(*url.m_ips[i]); - } - - return *this; -} - -url& url::operator=(const string &strurl) { - url tmp(strurl); - *this = tmp; - return *this; -} - -string url::get_host() const { - return m_host; -} - -sockaddr const* const* url::get_ips(bool usedns) { - // Check the cache - if (m_ips) - return m_ips; - - // Check without DNS first - if (usedns && get_ips(false)) - return m_ips; - - // Check DNS for IPs - struct addrinfo* info; - struct addrinfo flags; - memset(&flags, '\0', sizeof(addrinfo)); - flags.ai_family = AF_UNSPEC; - flags.ai_socktype = 0; - flags.ai_protocol = 0; - flags.ai_flags = AI_NUMERICHOST; - if (!getaddrinfo(m_host.c_str(), NULL, usedns ? NULL : &flags, &info)) { - struct addrinfo* first = info; - unsigned int i = 0; - - // Get the size of our array - for (info = first ; info ; info = info->ai_next) - i++; - - // Return NULL if no IPs found - if (i == 0) - return m_ips = NULL; - - // Create our array since we actually have a result - m_ips = new sockaddr*[++i]; - memset(m_ips, '\0', sizeof(sockaddr*)*i); - - // Copy the sockaddr's into m_ips - for (i = 0, info = first ; info ; info = info->ai_next) { - if (info->ai_addr->sa_family == AF_INET || info->ai_addr->sa_family == AF_INET6) { - m_ips[i] = copyaddr(*(info->ai_addr)); - if (!m_ips[i]) break; - ((sockaddr_in **) m_ips)[i++]->sin_port = htons(m_port); - } - } - - freeaddrinfo(first); - return m_ips; - } - - // No addresses found - return NULL; -} - -string url::get_password() const { - return m_pass; -} - -string url::get_path() const { - return m_path; -} - -string url::get_query() const { - return m_query; -} - -uint16_t url::get_port() const { - return m_port; -} - -string url::get_scheme() const { - return m_scheme; -} - -string url::get_username() const { - return m_user; -} - -string url::to_string() const { - return m_orig; -} - -static string recvline(int fd) { - string line; - int ret; - - // Reserve arbitrary amount of space to avoid small memory reallocations. - line.reserve(128); - - do { - char c; - ret = recv(fd, &c, 1, 0); - if (ret == 1) { - if (c == '\n') - return line; - line += c; - } - } while (ret == 1 || (ret == -1 && errno == EINTR)); - - return line; -} - -char* url::get_pac() { - int sock = -1; - bool chunked = false; - unsigned long int content_length = 0, status = 0; - char* buffer = NULL; - string request; - - // In case of a file:// url we open the file and read it - if (m_scheme == "file" || m_scheme == "pac+file") { - struct stat st; - if ((sock = ::open(m_path.c_str(), O_RDONLY)) < 0) - return NULL; - - 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; - } - } - close(sock); - return buffer; - } - - // DNS lookup of host - if (!get_ips(true)) - return NULL; - - // Iterate through each IP trying to make a connection - // Stop at the first one - for (int i=0 ; m_ips[i] ; i++) { - sock = socket(m_ips[i]->sa_family, SOCK_STREAM, 0); - if (sock < 0) continue; - - if (m_ips[i]->sa_family == AF_INET && - !connect(sock, m_ips[i], sizeof(struct sockaddr_in))) - break; - else if (m_ips[i]->sa_family == AF_INET6 && - !connect(sock, m_ips[i], sizeof(struct sockaddr_in6))) - break; - - closesocket(sock); - sock = -1; - } - - // Test our socket - if (sock < 0) return NULL; - - // Build the request string - request = "GET " + (m_path.size() > 0 ? m_path : "/") + m_query + " HTTP/1.1\r\n"; - request += "Host: " + m_host + (m_port != 80 ? ":" + std::to_string(m_port) : "") + "\r\n"; - request += "Accept: " + string(PAC_MIME_TYPE) + "\r\n"; - request += "Connection: close\r\n"; - request += "\r\n"; - - // Send HTTP request - if ((size_t) send(sock, request.c_str(), request.size(), 0) != request.size()) { - closesocket(sock); - return NULL; - } - - /* Verify status line */ - string line = recvline(sock); - if (sscanf(line.c_str(), "HTTP/1.%*d %lu", &status) == 1 && status == 200) { - /* Check for correct mime type and content length */ - content_length = 0; - for (line = recvline(sock) ; line != "\r" && line != "" ; line = recvline(sock)) { - // Check for chunked encoding - if (line.find("Content-Transfer-Encoding: chunked") == 0 || line.find("Transfer-Encoding: chunked") == 0) - chunked = true; - - // Check for content length - else if (content_length == 0) - sscanf(line.c_str(), "Content-Length: %lu", &content_length); - } - - // Get content - std::vector<char> dynamic_buffer; - do { - unsigned int chunk_length; - - if (chunked) { - // Discard the empty line if we received a previous chunk - if (!dynamic_buffer.empty()) recvline(sock); - - // Get the chunk-length line as an integer - if (sscanf(recvline(sock).c_str(), "%x", &chunk_length) != 1 || chunk_length == 0) break; - - // Add this chunk to our content length, - // ensuring that we aren't over our max size - content_length += chunk_length; - } - - if (content_length >= PAC_MAX_SIZE) break; - - while (content_length == 0 || dynamic_buffer.size() != content_length) { - // Calculate length to recv - unsigned int length_to_read = PAC_HTTP_BLOCK_SIZE; - if (content_length > 0) - length_to_read = content_length - dynamic_buffer.size(); - - // Prepare buffer - dynamic_buffer.resize(dynamic_buffer.size() + length_to_read); - - int r = recv(sock, dynamic_buffer.data() + dynamic_buffer.size() - length_to_read, length_to_read, 0); - - // Shrink buffer to fit - if (r >= 0) - dynamic_buffer.resize(dynamic_buffer.size() - length_to_read + r); - - // PAC size too large, discard - if (dynamic_buffer.size() >= PAC_MAX_SIZE) { - chunked = false; - dynamic_buffer.clear(); - break; - } - - if (r <= 0) { - chunked = false; - break; - } - } - } while (chunked); - - if (content_length == 0 || content_length == dynamic_buffer.size()) { - buffer = new char[dynamic_buffer.size() + 1]; - if (!dynamic_buffer.empty()) { - memcpy(buffer, dynamic_buffer.data(), dynamic_buffer.size()); - } - buffer[dynamic_buffer.size()] = '\0'; - } - } - - // Clean up - shutdown(sock, SHUT_RDWR); - closesocket(sock); - return buffer; -} - -void url::empty_cache() -{ - if (m_ips) { - // Free any existing ip cache - for (int i=0 ; m_ips[i] ; i++) - delete m_ips[i]; - delete[] m_ips; - m_ips = NULL; - } -} diff --git a/libproxy/url.hpp b/libproxy/url.hpp deleted file mode 100644 index 44b44af..0000000 --- a/libproxy/url.hpp +++ /dev/null @@ -1,85 +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 - ******************************************************************************/ - -#ifndef URL_HPP_ -#define URL_HPP_ - -#include <map> -#include <stdexcept> -#include <string> -#include <vector> - -#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; - -class DLL_PUBLIC parse_error : public runtime_error { -public: - parse_error(const string& arg): runtime_error(arg) {} -}; - -class DLL_PUBLIC url { -public: - static bool is_valid(const string &url); - static string encode(const string &data, const string &valid_reserved = ""); - - ~url(); - url(const url& url); - url(const string& url); - bool operator==(const url& url) const; - url& operator=(const url& url); - url& operator=(const string &url); - - string get_host() const; - sockaddr const* const* get_ips(bool usedns); - string get_password() const; - string get_path() const; - string get_query() const; - uint16_t get_port() const; - string get_scheme() const; - string get_username() const; - string to_string() const; - char* get_pac(); // Allocated, must free. NULL on error. - -private: - void empty_cache(); - - string m_orig; - string m_scheme; - string m_user; - string m_pass; - string m_host; - uint16_t m_port; - string m_path; - string m_query; - sockaddr** m_ips; -}; - -} - -#endif /*URL_HPP_*/ diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..f209f60 --- /dev/null +++ b/meson.build @@ -0,0 +1,138 @@ +project('libproxy', 'c', + version: '0.5.0', + meson_version: '>= 0.59.0', + default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu11', ], +) + +version_arr = meson.project_version().split('-')[0].split('.') +libproxy_version_major = version_arr[0].to_int() +libproxy_version_minor = version_arr[1].to_int() + +root_dir = include_directories('.') + +px_prefix = get_option('prefix') +datadir = get_option('datadir') +px_libdir = join_paths(px_prefix, get_option('libdir')) +girdir = get_option('datadir') / 'gir-1.0' +typelibdir = get_option('libdir') / 'girepository-1.0' +vapidir = get_option('datadir') / 'vala' / 'vapi' + +add_project_arguments(['-I' + meson.project_build_root()], language: 'c') + +# The major api version as encoded in the libraries name +api_version = '1.0' +package_api_name = '@0@-@1@'.format(meson.project_name(), api_version) + +cc = meson.get_compiler('c') + +project_c_args = [] +test_c_args = [ + '-Wcast-align', + '-Wdeclaration-after-statement', + '-Werror=address', + '-Werror=array-bounds', + '-Werror=empty-body', + '-Werror=implicit', + '-Werror=implicit-function-declaration', + '-Werror=incompatible-pointer-types', + '-Werror=init-self', + '-Werror=int-conversion', + '-Werror=int-to-pointer-cast', + '-Werror=main', + '-Werror=misleading-indentation', + '-Werror=missing-braces', + '-Werror=missing-include-dirs', + '-Werror=nonnull', + '-Werror=overflow', + '-Werror=parenthesis', + '-Werror=pointer-arith', + '-Werror=pointer-to-int-cast', + '-Werror=redundant-decls', + '-Werror=return-type', + '-Werror=sequence-point', + '-Werror=shadow', + '-Werror=strict-prototypes', + '-Werror=trigraphs', + '-Werror=undef', + '-Werror=write-strings', + '-Wformat-nonliteral', + '-Wignored-qualifiers', + '-Wimplicit-function-declaration', + '-Wlogical-op', + '-Wmissing-declarations', + '-Wmissing-format-attribute', + '-Wmissing-include-dirs', + '-Wmissing-noreturn', + '-Wnested-externs', + '-Wno-cast-function-type', + '-Wno-dangling-pointer', + '-Wno-missing-field-initializers', + '-Wno-sign-compare', + '-Wno-unused-parameter', + '-Wold-style-definition', + '-Wpointer-arith', + '-Wredundant-decls', + '-Wstrict-prototypes', + '-Wswitch-default', + '-Wswitch-enum', + '-Wundef', + '-Wuninitialized', + '-Wunused', + '-fno-strict-aliasing', + ['-Werror=format-security', '-Werror=format=2'], +] + +foreach arg: test_c_args + if cc.has_multi_arguments(arg) + project_c_args += arg + endif +endforeach +add_project_arguments(project_c_args, language: 'c') + +_platforms = [] +host_system = host_machine.system() +if host_machine.system() == 'windows' + _platforms = ['windows'] +endif +with_platform_windows = _platforms.contains('windows') +with_platform_darwin = ['darwin', 'ios'].contains(host_system) + +module_suffix = [] +# Keep the autotools convention for shared module suffix because GModule +# depends on it. +if with_platform_darwin + module_suffix = 'so' +endif + +glib_dep = dependency('glib-2.0', version: '>= 2.71.3') +gio_dep = dependency('gio-2.0', version: '>= 2.71.3') +soup_dep = dependency('libsoup-3.0', required: get_option('tests')) +curl_dep = dependency('libcurl', required: get_option('curl')) +ws2_32_dep = cc.find_library('ws2_32', required : with_platform_windows) +gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get_option('config-gnome')) + +config_h = configuration_data() +config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) +config_h.set('HAVE_CURL', get_option('curl')) +configure_file(output: 'config.h', configuration: config_h) + +subdir('src') +subdir('tests') +subdir('docs') + +summary({ + 'host cpu' : host_machine.cpu_family(), + 'host endian' : host_machine.endian(), + 'host system' : host_system, + 'C Compiler' : cc.get_id(), +}, section: 'Build environment') + +summary({ + 'Vapi' : get_option('vapi'), +}, section: 'Options') + +# Install pre-commit hook +hook = run_command(join_paths(meson.project_source_root(), 'data/install-git-hook.sh'), check: false) +if hook.returncode() == 0 + message(hook.stdout().strip()) +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..9e3e9bd --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,83 @@ +option( + 'docs', + type: 'boolean', + value: true, + description: 'Whether to generate the API reference for libproxy' +) + +option( + 'tests', + type: 'boolean', + value: true, + description: 'Whether to compile test cases for libproxy' +) + +option( + 'config-env', + type: 'boolean', + value: true, + description: 'Whether to build support for environment configuration' +) + +option( + 'config-gnome', + type: 'boolean', + value: true, + description: 'Whether to build support for GNOME configuration' +) + +option( + 'config-windows', + type: 'boolean', + value: true, + description: 'Whether to build support for Windows configuration' +) + +option( + 'config-sysconfig', + type: 'boolean', + value: true, + description: 'Whether to build support for sysconfig configuration' +) + +option( + 'config-osx', + type: 'boolean', + value: true, + description: 'Whether to build support for OS X configuration' +) + +option( + 'config-kde', + type: 'boolean', + value: true, + description: 'Whether to build support for KDE System Settings' +) + +option( + 'pacrunner-duktape', + type: 'boolean', + value: true, + description: 'Whether to build support for PAC Runner Duktape' +) + +option( + 'vapi', + type: 'boolean', + value: true, + description: 'Whether to build vapi support' +) + +option( + 'curl', + type: 'boolean', + value: true, + description: 'Whether to build cURL support' +) + +option( + 'introspection', + type: 'boolean', + value: true, + description: 'Whether to build introspection support' +) diff --git a/src/backend/meson.build b/src/backend/meson.build new file mode 100644 index 0000000..c8be5da --- /dev/null +++ b/src/backend/meson.build @@ -0,0 +1,47 @@ +backend_config_h = configuration_data() +backend_config_h.set('HAVE_CONFIG_ENV', get_option('config-env')) +backend_config_h.set('HAVE_CONFIG_GNOME', get_option('config-gnome')) +backend_config_h.set('HAVE_CONFIG_KDE', get_option('config-kde')) +backend_config_h.set('HAVE_CONFIG_OSX', get_option('config-osx') and with_platform_darwin) +backend_config_h.set('HAVE_CONFIG_SYSCONFIG', get_option('config-sysconfig')) +backend_config_h.set('HAVE_CONFIG_WINDOWS', get_option('config-windows') and with_platform_windows) +backend_config_h.set('HAVE_PACRUNNER_DUKTAPE', get_option('pacrunner-duktape')) +configure_file(output: 'px-backend-config.h', configuration: backend_config_h) + +px_backend_sources = [ + 'px-manager.c', + 'px-manager.h', + 'px-plugin-config.c', + 'px-plugin-config.h', + 'px-plugin-pacrunner.c', + 'px-plugin-pacrunner.h', +] + +px_backend_deps = [ + curl_dep, + gio_dep, + glib_dep, + ws2_32_dep, +] + +px_backend_c_args = [ + '-DG_LOG_DOMAIN="pxbackend"', +] + +px_backend_inc = include_directories('.') + +subdir('plugins') + +px_backend = shared_library( + 'pxbackend-@0@'.format(api_version), + px_backend_sources, + dependencies: px_backend_deps, + c_args: px_backend_c_args, + install: true +) + +px_backend_dep = declare_dependency( + include_directories: px_backend_inc, + link_with: px_backend, + dependencies: px_backend_deps +) diff --git a/libproxy/modules/pacutils.h b/src/backend/pacutils.h index 3826014..3826014 100644 --- a/libproxy/modules/pacutils.h +++ b/src/backend/pacutils.h diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c new file mode 100644 index 0000000..6a326e0 --- /dev/null +++ b/src/backend/plugins/config-env/config-env.c @@ -0,0 +1,167 @@ +/* config-env.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gio/gio.h> + +#include "config-env.h" + +#include "px-manager.h" +#include "px-plugin-config.h" + +static void px_config_iface_init (PxConfigInterface *iface); + +struct _PxConfigEnv { + GObject parent_instance; + + GStrv no_proxy; + const char *ftp_proxy; + const char *http_proxy; + const char *https_proxy; +}; + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigEnv, + px_config_env, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +static void +px_config_env_init (PxConfigEnv *self) +{ + const char *no_proxy; + + /* Collect data in init() to speed up get_config() calls */ + no_proxy = g_getenv ("no_proxy"); + if (!no_proxy) + no_proxy = g_getenv ("NO_PROXY"); + + if (no_proxy) + self->no_proxy = g_strsplit (no_proxy, ",", -1); + + self->ftp_proxy = g_getenv ("ftp_proxy"); + if (!self->ftp_proxy) + self->ftp_proxy = g_getenv ("FTP_PROXY"); + + self->https_proxy = g_getenv ("https_proxy"); + if (!self->https_proxy) + self->https_proxy = g_getenv ("HTTPS_PROXY"); + + self->http_proxy = g_getenv ("http_proxy"); + if (!self->http_proxy) + self->http_proxy = g_getenv ("HTTP_PROXY"); +} + +static void +px_config_env_dispose (GObject *object) +{ + PxConfigEnv *self = PX_CONFIG_ENV (object); + + g_clear_pointer (&self->no_proxy, g_strfreev); + + G_OBJECT_CLASS (px_config_env_parent_class)->dispose (object); +} + +static void +px_config_env_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_OPTION: + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_env_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_OPTION: + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_env_class_init (PxConfigEnvClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = px_config_env_dispose; + object_class->set_property = px_config_env_set_property; + object_class->get_property = px_config_env_get_property; + + g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option"); +} + +static gboolean +px_config_env_is_available (PxConfig *self) +{ + return TRUE; +} + +static void +px_config_env_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder) +{ + PxConfigEnv *self = PX_CONFIG_ENV (config); + const char *proxy = NULL; + const char *scheme = g_uri_get_scheme (uri); + + if (px_manager_is_ignore (uri, self->no_proxy)) + return; + + if (g_strcmp0 (scheme, "ftp") == 0) + proxy = self->ftp_proxy; + else if (g_strcmp0 (scheme, "https") == 0) + proxy = self->https_proxy; + + if (!proxy) + proxy = self->http_proxy; + + if (proxy) + px_strv_builder_add_proxy (builder, proxy); +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->name = "config-env"; + iface->priority = PX_CONFIG_PRIORITY_FIRST; + iface->is_available = px_config_env_is_available; + iface->get_config = px_config_env_get_config; +} diff --git a/libmodman/test/module.cpp.in b/src/backend/plugins/config-env/config-env.h index 3390ead..6b654bd 100644 --- a/libmodman/test/module.cpp.in +++ b/src/backend/plugins/config-env/config-env.h @@ -1,6 +1,6 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * Copyright (C) 2009 Nathaniel McCallum <nathaniel@natemccallum.com> +/* config-env.h + * + * Copyright 2022-2023 The Libproxy Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -14,11 +14,21 @@ * * 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 - ******************************************************************************/ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib.h> + +G_BEGIN_DECLS + +#define PX_CONFIG_TYPE_ENV (px_config_env_get_type ()) + +G_DECLARE_FINAL_TYPE (PxConfigEnv, px_config_env, PX, CONFIG_ENV, GObject) + +G_END_DECLS -#include <libmodman/module.hpp> -#include <libmodman/test/main.hpp> -class @MODNAME@ : public @MODTYPE@_extension {}; -MM_MODULE_INIT_EZ(@MODNAME@, @MODCOND@, @MODSYMB@, @MODSMOD@); diff --git a/src/backend/plugins/config-env/meson.build b/src/backend/plugins/config-env/meson.build new file mode 100644 index 0000000..00f3cc3 --- /dev/null +++ b/src/backend/plugins/config-env/meson.build @@ -0,0 +1,9 @@ +plugin_name = 'config-env' + +if get_option(plugin_name) + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +endif
\ No newline at end of file diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c new file mode 100644 index 0000000..9d6fd68 --- /dev/null +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -0,0 +1,246 @@ +/* config-gnome.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gio/gio.h> + +#include "config-gnome.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +struct _PxConfigGnome { + GObject parent_instance; + GSettings *proxy_settings; + GSettings *http_proxy_settings; + GSettings *https_proxy_settings; + GSettings *ftp_proxy_settings; + GSettings *socks_proxy_settings; + gboolean available; +}; + +typedef enum { + GNOME_PROXY_MODE_NONE, + GNOME_PROXY_MODE_MANUAL, + GNOME_PROXY_MODE_AUTO +} GnomeProxyMode; + +static void px_config_iface_init (PxConfigInterface *iface); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigGnome, + px_config_gnome, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +static void +px_config_gnome_init (PxConfigGnome *self) +{ + GSettingsSchemaSource *source; + GSettingsSchema *proxy_schema; + const char *desktops; + + self->available = FALSE; + + desktops = getenv ("XDG_CURRENT_DESKTOP"); + if (!desktops) + return; + + /* Remember that XDG_CURRENT_DESKTOP is a list of strings. */ + if (strstr (desktops, "GNOME") == NULL) + return; + + source = g_settings_schema_source_get_default (); + if (!source) { + g_warning ("GNOME desktop detected but no schemes installed, aborting."); + return; + } + + proxy_schema = g_settings_schema_source_lookup (source, "org.gnome.system.proxy", TRUE); + + self->available = proxy_schema != NULL; + g_clear_pointer (&proxy_schema, g_settings_schema_unref); + + if (!self->available) + return; + + self->proxy_settings = g_settings_new ("org.gnome.system.proxy"); + self->http_proxy_settings = g_settings_new ("org.gnome.system.proxy.http"); + self->https_proxy_settings = g_settings_new ("org.gnome.system.proxy.https"); + self->ftp_proxy_settings = g_settings_new ("org.gnome.system.proxy.ftp"); + self->socks_proxy_settings = g_settings_new ("org.gnome.system.proxy.socks"); +} + +static void +px_config_gnome_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_OPTION: + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_gnome_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_OPTION: + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_gnome_class_init (PxConfigGnomeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = px_config_gnome_set_property; + object_class->get_property = px_config_gnome_get_property; + + g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option"); +} + +static gboolean +px_config_gnome_is_available (PxConfig *config) +{ + PxConfigGnome *self = PX_CONFIG_GNOME (config); + + return self->available; +} + +static void +store_response (GStrvBuilder *builder, + const char *type, + char *host, + int port, + gboolean auth, + char *username, + char *password) +{ + if (type && host && strlen (type) > 0 && strlen (host) > 0 && port != 0) { + g_autoptr (GString) tmp = g_string_new (type); + + g_string_append (tmp, "://"); + if (auth) + g_string_append_printf (tmp, "%s:%s@", username, password); + + g_string_append_printf (tmp, "%s:%d", host, port); + + px_strv_builder_add_proxy (builder, tmp->str); + } +} + +static void +px_config_gnome_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder) +{ + PxConfigGnome *self = PX_CONFIG_GNOME (config); + g_autofree char *proxy = NULL; + GnomeProxyMode mode; + + if (!self->available) + return; + + if (px_manager_is_ignore (uri, g_settings_get_strv (self->proxy_settings, "ignore-hosts"))) + return; + + mode = g_settings_get_enum (self->proxy_settings, "mode"); + if (mode == GNOME_PROXY_MODE_AUTO) { + char *autoconfig_url = g_settings_get_string (self->proxy_settings, "autoconfig-url"); + + if (strlen (autoconfig_url) != 0) + proxy = g_strdup_printf ("pac+%s", autoconfig_url); + else + proxy = g_strdup ("wpad://"); + + px_strv_builder_add_proxy (builder, proxy); + } else if (mode == GNOME_PROXY_MODE_MANUAL) { + g_autofree char *username = g_settings_get_string (self->http_proxy_settings, "authentication-user"); + g_autofree char *password = g_settings_get_string (self->http_proxy_settings, "authentication-password"); + const char *scheme = g_uri_get_scheme (uri); + gboolean auth = g_settings_get_boolean (self->http_proxy_settings, "use-authentication"); + + if (g_strcmp0 (scheme, "http") == 0) { + g_autofree char *host = g_settings_get_string (self->http_proxy_settings, "host"); + store_response (builder, + "http", + host, + g_settings_get_int (self->http_proxy_settings, "port"), + auth, + username, + password); + } else if (g_strcmp0 (scheme, "https") == 0) { + g_autofree char *host = g_settings_get_string (self->https_proxy_settings, "host"); + store_response (builder, + "http", + host, + g_settings_get_int (self->https_proxy_settings, "port"), + auth, + username, + password); + } else if (g_strcmp0 (scheme, "ftp") == 0) { + g_autofree char *host = g_settings_get_string (self->ftp_proxy_settings, "host"); + store_response (builder, + "http", + host, + g_settings_get_int (self->ftp_proxy_settings, "port"), + auth, + username, + password); + } else { + g_autofree char *host = g_settings_get_string (self->socks_proxy_settings, "host"); + store_response (builder, + "socks", + host, + g_settings_get_int (self->socks_proxy_settings, "port"), + auth, + username, + password); + } + } +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->name = "config-gnome"; + iface->priority = PX_CONFIG_PRIORITY_DEFAULT; + iface->is_available = px_config_gnome_is_available; + iface->get_config = px_config_gnome_get_config; +} diff --git a/libproxy/extension_pacrunner.cpp b/src/backend/plugins/config-gnome/config-gnome.h index 698f25f..c5e8c6e 100644 --- a/libproxy/extension_pacrunner.cpp +++ b/src/backend/plugins/config-gnome/config-gnome.h @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2009 Nathaniel McCallum <nathaniel@natemccallum.com> +/* config-gnome.h + * + * Copyright 2022-2023 The Libproxy Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -14,20 +14,21 @@ * * 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 - ******************************************************************************/ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib-object.h> + +G_BEGIN_DECLS -#include "extension_pacrunner.hpp" -using namespace libproxy; +#define PX_CONFIG_TYPE_GNOME (px_config_gnome_get_type ()) -pacrunner::pacrunner(const string &, const url&) {} +G_DECLARE_FINAL_TYPE (PxConfigGnome, px_config_gnome, PX, CONFIG_GNOME, GObject) -pacrunner_extension::pacrunner_extension() { -} +G_END_DECLS -pacrunner_extension::~pacrunner_extension() { -} -pacrunner* pacrunner_extension::get(const string &pac, const url& pacurl) { - return this->create(pac, pacurl); -} diff --git a/src/backend/plugins/config-gnome/meson.build b/src/backend/plugins/config-gnome/meson.build new file mode 100644 index 0000000..e6a9b20 --- /dev/null +++ b/src/backend/plugins/config-gnome/meson.build @@ -0,0 +1,9 @@ +plugin_name = 'config-gnome' + +if get_option(plugin_name) + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +endif
\ No newline at end of file diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c new file mode 100644 index 0000000..ccec002 --- /dev/null +++ b/src/backend/plugins/config-kde/config-kde.c @@ -0,0 +1,303 @@ +/* config-kde.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gio/gio.h> + +#include "config-kde.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +static void px_config_iface_init (PxConfigInterface *iface); + +typedef enum { + KDE_PROXY_TYPE_NONE = 0, + KDE_PROXY_TYPE_MANUAL, + KDE_PROXY_TYPE_PAC, + KDE_PROXY_TYPE_WPAD, + KDE_PROXY_TYPE_SYSTEM, +} KdeProxyType; + +struct _PxConfigKde { + GObject parent_instance; + + char *config_file; + gboolean available; + GFileMonitor *monitor; + + GStrv no_proxy; + char *http_proxy; + char *https_proxy; + char *ftp_proxy; + char *socks_proxy; + KdeProxyType proxy_type; + char *pac_script; +}; + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigKde, + px_config_kde, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +static void px_config_kde_set_config_file (PxConfigKde *self, + char *proxy_file); + +static void +on_file_changed (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data) +{ + PxConfigKde *self = PX_CONFIG_KDE (user_data); + + g_debug ("%s: Reloading configuration\n", __FUNCTION__); + px_config_kde_set_config_file (self, g_file_get_path (file)); +} + +static void +px_config_kde_set_config_file (PxConfigKde *self, + char *proxy_file) +{ + g_autoptr (GError) error = NULL; + g_autofree char *line = NULL; + g_autoptr (GFile) file = NULL; + g_autoptr (GFileInputStream) istr = NULL; + g_autoptr (GDataInputStream) dstr = NULL; + const char *desktops; + + self->available = FALSE; + + desktops = getenv ("XDG_CURRENT_DESKTOP"); + if (!desktops) + return; + + /* Remember that XDG_CURRENT_DESKTOP is a list of strings. */ + if (strstr (desktops, "KDE") == NULL) + return; + + g_clear_pointer (&self->config_file, g_free); + self->config_file = proxy_file ? g_strdup (proxy_file) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL); + + file = g_file_new_for_path (self->config_file); + if (!file) { + g_debug ("%s: Could not create file for %s", __FUNCTION__, self->config_file); + return; + } + + istr = g_file_read (file, NULL, NULL); + if (!istr) { + g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file); + return; + } + + dstr = g_data_input_stream_new (G_INPUT_STREAM (istr)); + if (!dstr) + return; + + g_clear_object (&self->monitor); + self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error); + if (!self->monitor) + g_warning ("Could not add a file monitor for %s, error: %s", g_file_get_uri (file), error->message); + else + g_signal_connect_object (G_OBJECT (self->monitor), "changed", G_CALLBACK (on_file_changed), self, 0); + + do { + g_clear_pointer (&line, g_free); + + line = g_data_input_stream_read_line (dstr, NULL, NULL, &error); + if (line) { + g_auto (GStrv) kv = NULL; + g_autoptr (GString) value = NULL; + kv = g_strsplit (line, "=", 2); + + if (g_strv_length (kv) != 2) + continue; + + value = g_string_new (kv[1]); + g_string_replace (value, "\"", "", 0); + g_string_replace (value, " ", ":", 0); + + if (strcmp (kv[0], "httpsProxy") == 0) { + self->https_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "httpProxy") == 0) { + self->http_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "ftpProxy") == 0) { + self->ftp_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "socksProxy") == 0) { + self->socks_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "NoProxyFor") == 0) { + self->no_proxy = g_strsplit (value->str, ",", -1); + } else if (strcmp (kv[0], "Proxy Config Script") == 0) { + self->pac_script = g_strdup (value->str); + } else if (strcmp (kv[0], "ProxyType") == 0) { + self->proxy_type = atoi (value->str); + } + } + } while (line); + + self->available = TRUE; +} + + +static void +px_config_kde_init (PxConfigKde *self) +{ + px_config_kde_set_config_file (self, NULL); +} + +static void +px_config_kde_dispose (GObject *object) +{ + PxConfigKde *self = PX_CONFIG_KDE (object); + + g_clear_pointer (&self->config_file, g_free); + g_clear_object (&self->monitor); + g_clear_pointer (&self->no_proxy, g_strfreev); + g_clear_pointer (&self->http_proxy, g_free); + g_clear_pointer (&self->https_proxy, g_free); + g_clear_pointer (&self->ftp_proxy, g_free); + g_clear_pointer (&self->socks_proxy, g_free); + g_clear_pointer (&self->pac_script, g_free); + + G_OBJECT_CLASS (px_config_kde_parent_class)->dispose (object); +} + +static void +px_config_kde_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PxConfigKde *config = PX_CONFIG_KDE (object); + + switch (prop_id) { + case PROP_CONFIG_OPTION: + px_config_kde_set_config_file (config, g_value_dup_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_kde_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PxConfigKde *config = PX_CONFIG_KDE (object); + + switch (prop_id) { + case PROP_CONFIG_OPTION: + g_value_set_string (value, config->config_file); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_kde_class_init (PxConfigKdeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = px_config_kde_dispose; + object_class->set_property = px_config_kde_set_property; + object_class->get_property = px_config_kde_get_property; + + g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option"); +} + +static gboolean +px_config_kde_is_available (PxConfig *config) +{ + PxConfigKde *self = PX_CONFIG_KDE (config); + + return self->available; +} + +static void +px_config_kde_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder) +{ + PxConfigKde *self = PX_CONFIG_KDE (config); + const char *scheme = g_uri_get_scheme (uri); + g_autofree char *proxy = NULL; + + if (!self->available) + return; + + if (!self->proxy_type) + return; + + if (px_manager_is_ignore (uri, self->no_proxy)) + return; + + switch (self->proxy_type) { + case KDE_PROXY_TYPE_MANUAL: + case KDE_PROXY_TYPE_SYSTEM: + /* System is the same as manual, except that a button for auto dection + * is shown. Based on this manual fields are set. + */ + if (g_strcmp0 (scheme, "ftp") == 0) { + proxy = g_strdup (self->ftp_proxy); + } else if (g_strcmp0 (scheme, "https") == 0) { + proxy = g_strdup (self->https_proxy); + } else if (g_strcmp0 (scheme, "http") == 0) { + proxy = g_strdup (self->http_proxy); + } else if (self->socks_proxy && strlen (self->socks_proxy) > 0) { + proxy = g_strdup (self->socks_proxy); + } + break; + case KDE_PROXY_TYPE_WPAD: + proxy = g_strdup ("wpad://"); + break; + case KDE_PROXY_TYPE_PAC: + proxy = g_strdup_printf ("pac+%s", self->pac_script); + break; + case KDE_PROXY_TYPE_NONE: + default: + break; + } + + if (proxy) + px_strv_builder_add_proxy (builder, proxy); +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->name = "config-kde"; + iface->priority = PX_CONFIG_PRIORITY_DEFAULT; + iface->is_available = px_config_kde_is_available; + iface->get_config = px_config_kde_get_config; +} diff --git a/src/backend/plugins/config-kde/config-kde.h b/src/backend/plugins/config-kde/config-kde.h new file mode 100644 index 0000000..892c45a --- /dev/null +++ b/src/backend/plugins/config-kde/config-kde.h @@ -0,0 +1,34 @@ +/* config-kde.h + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib.h> + +G_BEGIN_DECLS + +#define PX_CONFIG_TYPE_KDE (px_config_kde_get_type ()) + +G_DECLARE_FINAL_TYPE (PxConfigKde, px_config_kde, PX, CONFIG_KDE, GObject) + +G_END_DECLS + + diff --git a/src/backend/plugins/config-kde/meson.build b/src/backend/plugins/config-kde/meson.build new file mode 100644 index 0000000..b34d78d --- /dev/null +++ b/src/backend/plugins/config-kde/meson.build @@ -0,0 +1,9 @@ +plugin_name = 'config-kde' + +if get_option(plugin_name) + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +endif
\ No newline at end of file diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c new file mode 100644 index 0000000..16813a0 --- /dev/null +++ b/src/backend/plugins/config-osx/config-osx.c @@ -0,0 +1,341 @@ +/* config-osx.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <SystemConfiguration/SystemConfiguration.h> + +#include <gio/gio.h> + +#include "config-osx.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +static void px_config_iface_init (PxConfigInterface *iface); + +struct _PxConfigOsX { + GObject parent_instance; +}; + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigOsX, + px_config_osx, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +static void +px_config_osx_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_OPTION: + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_osx_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_osx_init (PxConfigOsX *self) +{ +} + +static void +px_config_osx_class_init (PxConfigOsXClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = px_config_osx_set_property; + object_class->get_property = px_config_osx_get_property; + + g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option"); +} + +static gboolean +px_config_osx_is_available (PxConfig *self) +{ + return TRUE; +} + +static CFNumberRef +getobj (CFDictionaryRef settings, + char *key) +{ + CFStringRef k; + CFNumberRef retval; + + if (!settings) + return NULL; + + k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman); + if (!k) + return NULL; + + retval = (CFNumberRef)CFDictionaryGetValue (settings, k); + + CFRelease (k); + return retval; +} + +static CFStringRef +getobj_str (CFDictionaryRef settings, + char *key) +{ + CFStringRef k; + CFStringRef retval; + + if (!settings) + return NULL; + + k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman); + if (!k) + return NULL; + + retval = (CFStringRef)CFDictionaryGetValue (settings, k); + + CFRelease (k); + return retval; +} + +static CFArrayRef +getobj_array (CFDictionaryRef settings, + char *key) +{ + CFStringRef k; + CFArrayRef retval; + + if (!settings) + return NULL; + + k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman); + if (!k) + return NULL; + + retval = (CFArrayRef)CFDictionaryGetValue (settings, k); + + CFRelease (k); + return retval; +} + +static char * +str (CFStringRef ref) +{ + CFIndex size = CFStringGetLength (ref) + 1; + char *ret = g_malloc0 (size); + + CFStringGetCString (ref, ret, size, kCFStringEncodingUTF8); + + return ret; +} + +static gboolean +getint (CFDictionaryRef settings, + char *key, + int64_t *answer) +{ + CFNumberRef n = getobj (settings, key); + + if (!n) + return FALSE; + + if (!CFNumberGetValue (n, kCFNumberSInt64Type, answer)) + return FALSE; + + return TRUE; +} + +static gboolean +getbool (CFDictionaryRef settings, + char *key) +{ + int64_t i = 0; + + if (!getint (settings, key, &i)) + return FALSE; + + return i != 0; +} + +static char * +str_to_upper (const char *str) +{ + char *ret = NULL; + int idx; + + if (!str) + return NULL; + + ret = g_malloc0 (strlen (str) + 1); + + for (idx = 0; idx < strlen (str); idx++) + ret[idx] = g_ascii_toupper (str[idx]); + + return ret; +} + +static char * +protocol_url (CFDictionaryRef settings, + char *protocol) +{ + g_autofree char *tmp = NULL; + g_autoptr (GString) ret = NULL; + g_autofree char *host = NULL; + int64_t port; + CFStringRef ref; + + /* Check ProtocolEnabled */ + tmp = g_strconcat (protocol, "Enable", NULL); + if (!getbool (settings, tmp)) { + g_debug ("%s: %s not set", __FUNCTION__, tmp); + return NULL; + } + g_clear_pointer (&tmp, g_free); + + /* Get ProtocolPort */ + tmp = g_strconcat (protocol, "Port", NULL); + getint (settings, tmp, &port); + if (!port) { + g_debug ("%s: %s not set", __FUNCTION__, tmp); + return NULL; + } + g_clear_pointer (&tmp, g_free); + + /* Get ProtocolProxy */ + tmp = g_strconcat (protocol, "Proxy", NULL); + ref = getobj_str (settings, tmp); + g_clear_pointer (&tmp, g_free); + + host = str (ref); + if (!host || strlen (host) == 0) + return NULL; + + if (strcmp (protocol, "HTTP") == 0 || strcmp (protocol, "HTTPS") == 0 || strcmp (protocol, "FTP") == 0 || strcmp (protocol, "Gopher") == 0) + ret = g_string_new ("http://"); + else if (strcmp (protocol, "RTSP") == 0) + ret = g_string_new ("rtsp://"); + else if (strcmp (protocol, "SOCKS") == 0) + ret = g_string_new ("socks://"); + else + return NULL; + + g_string_append_printf (ret, "%s:%lld", host, port); + + return g_strdup (ret->str); +} + +static GStrv +get_ignore_list (CFDictionaryRef proxies) +{ + CFArrayRef ref = getobj_array (proxies, "ExceptionsList"); + g_autoptr (GStrvBuilder) ret = g_strv_builder_new (); + + if (!ref) + return g_strv_builder_end (ret); + + for (int idx = 0; idx < CFArrayGetCount (ref); idx++) { + CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex (ref, idx); + + px_strv_builder_add_proxy (ret, str (s)); + } + + if (getbool (proxies, "ExcludeSimpleHostnames")) + px_strv_builder_add_proxy (ret, "127.0.0.1"); + + return g_strv_builder_end (ret); +} + +static void +px_config_osx_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder) +{ + const char *proxy = NULL; + CFDictionaryRef proxies = SCDynamicStoreCopyProxies (NULL); + g_auto (GStrv) ignore_list = NULL; + + if (!proxies) { + g_warning ("Unable to fetch proxy configuration"); + return; + } + + ignore_list = get_ignore_list (proxies); + + if (px_manager_is_ignore (uri, ignore_list)) + return; + + if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { + CFRelease (proxies); + px_strv_builder_add_proxy (builder, "wpad://"); + return; + } + + if (getbool (proxies, "ProxyAutoConfigEnable")) { + CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString"); + g_autofree char *tmp = str (ref); + GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL); + + if (tmp_uri) { + g_autofree char *ret = g_strdup_printf ("pac+%s", g_uri_to_string (tmp_uri)); + CFRelease (proxies); + px_strv_builder_add_proxy (builder, ret); + return; + } + } else { + const char *scheme = g_uri_get_scheme (uri); + g_autofree char *capital_scheme = str_to_upper (scheme); + + proxy = protocol_url (proxies, capital_scheme); + + if (!proxy) + proxy = protocol_url (proxies, "SOCKS"); + } + + if (proxy) + px_strv_builder_add_proxy (builder, proxy); +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->name = "config-osx"; + iface->priority = PX_CONFIG_PRIORITY_DEFAULT; + iface->is_available = px_config_osx_is_available; + iface->get_config = px_config_osx_get_config; +} diff --git a/src/backend/plugins/config-osx/config-osx.h b/src/backend/plugins/config-osx/config-osx.h new file mode 100644 index 0000000..797b51e --- /dev/null +++ b/src/backend/plugins/config-osx/config-osx.h @@ -0,0 +1,34 @@ +/* config-osx.h + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib.h> + +G_BEGIN_DECLS + +#define PX_CONFIG_TYPE_OSX (px_config_osx_get_type ()) + +G_DECLARE_FINAL_TYPE (PxConfigOsX, px_config_osx, PX, CONFIG_OSX, GObject) + +G_END_DECLS + + diff --git a/src/backend/plugins/config-osx/meson.build b/src/backend/plugins/config-osx/meson.build new file mode 100644 index 0000000..f801d90 --- /dev/null +++ b/src/backend/plugins/config-osx/meson.build @@ -0,0 +1,16 @@ +plugin_name = 'config-osx' + +if get_option(plugin_name) and with_platform_darwin + +foundation_dep = dependency('Foundation') +system_configuration_dep = dependency('SystemConfiguration') +px_backend_deps += [ + foundation_dep, + system_configuration_dep, +] + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +endif diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c new file mode 100644 index 0000000..c640f1c --- /dev/null +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -0,0 +1,252 @@ +/* config-sysconfig.c + * + * Copyright 2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gio/gio.h> + +#include "config-sysconfig.h" + +#include "px-manager.h" +#include "px-plugin-config.h" + +struct _PxConfigSysConfig { + GObject parent_instance; + GFileMonitor *monitor; + + char *config_file; + gboolean available; + + gboolean proxy_enabled; + char *https_proxy; + char *http_proxy; + char *ftp_proxy; + GStrv no_proxy; +}; + +static void px_config_iface_init (PxConfigInterface *iface); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigSysConfig, + px_config_sysconfig, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +static void px_config_sysconfig_set_config_file (PxConfigSysConfig *self, + const char *config_file); + +static void +on_file_changed (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + gpointer user_data) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (user_data); + + g_debug ("%s: Reloading configuration", __FUNCTION__); + px_config_sysconfig_set_config_file (self, g_file_get_path (file)); +} + +static +void +px_config_sysconfig_set_config_file (PxConfigSysConfig *self, + const char *config_file) +{ + g_autofree char *config = NULL; + g_autoptr (GFile) file = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GFileInputStream) istr = NULL; + g_autoptr (GDataInputStream) dstr = NULL; + char *line = NULL; + + g_clear_pointer (&self->config_file, g_free); + self->config_file = g_strdup (config_file ? config_file : "/etc/sysconfig/proxy"); + self->available = FALSE; + + file = g_file_new_for_path (self->config_file); + if (!file) { + g_debug ("%s: Could not create file for %s", __FUNCTION__, self->config_file); + return; + } + + istr = g_file_read (file, NULL, NULL); + if (!istr) { + g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file); + return; + } + + dstr = g_data_input_stream_new (G_INPUT_STREAM (istr)); + if (!dstr) + return; + + g_clear_object (&self->monitor); + self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error); + if (!self->monitor) + g_warning ("Could not add a file monitor for %s, error: %s", g_file_get_uri (file), error->message); + else + g_signal_connect_object (G_OBJECT (self->monitor), "changed", G_CALLBACK (on_file_changed), self, 0); + + do { + g_clear_pointer (&line, g_free); + + line = g_data_input_stream_read_line (dstr, NULL, NULL, &error); + if (line) { + g_auto (GStrv) kv = NULL; + g_autoptr (GString) value = NULL; + kv = g_strsplit (line, "=", -1); + + if (g_strv_length (kv) != 2) + continue; + + value = g_string_new (kv[1]); + g_string_replace (value, "\"", "", 0); + g_string_replace (value, "\r", "", 0); + + if (strcmp (kv[0], "PROXY_ENABLED") == 0) { + self->proxy_enabled = g_ascii_strncasecmp (value->str, "yes", 3) == 0; + } else if (strcmp (kv[0], "HTTPS_PROXY") == 0) { + self->https_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "HTTP_PROXY") == 0) { + self->http_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "FTP_PROXY") == 0) { + self->ftp_proxy = g_strdup (value->str); + } else if (strcmp (kv[0], "NO_PROXY") == 0) { + g_autofree char *tmp = g_strdup (value->str); + self->no_proxy = g_strsplit (tmp, ",", -1); + } + } + } while (line); + + self->available = TRUE; +} + +static void +px_config_sysconfig_init (PxConfigSysConfig *self) +{ +} + +static void +px_config_sysconfig_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PxConfigSysConfig *config = PX_CONFIG_SYSCONFIG (object); + + switch (prop_id) { + case PROP_CONFIG_OPTION: + px_config_sysconfig_set_config_file (config, g_value_dup_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_sysconfig_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PxConfigSysConfig *config = PX_CONFIG_SYSCONFIG (object); + + switch (prop_id) { + case PROP_CONFIG_OPTION: + g_value_set_string (value, config->config_file); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_sysconfig_dispose (GObject *object) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (object); + + g_clear_object (&self->monitor); + g_clear_pointer (&self->no_proxy, g_strfreev); + + G_OBJECT_CLASS (px_config_sysconfig_parent_class)->dispose (object); +} + +static void +px_config_sysconfig_class_init (PxConfigSysConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = px_config_sysconfig_dispose; + object_class->set_property = px_config_sysconfig_set_property; + object_class->get_property = px_config_sysconfig_get_property; + + g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option"); +} + +static gboolean +px_config_sysconfig_is_available (PxConfig *config) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (config); + + return self->available; +} + +static void +px_config_sysconfig_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (config); + const char *scheme = g_uri_get_scheme (uri); + g_autofree char *proxy = NULL; + + if (!self->proxy_enabled) + return; + + if (px_manager_is_ignore (uri, self->no_proxy)) + return; + + if (g_strcmp0 (scheme, "ftp") == 0) { + proxy = g_strdup (self->ftp_proxy); + } else if (g_strcmp0 (scheme, "https") == 0) { + proxy = g_strdup (self->https_proxy); + } else if (g_strcmp0 (scheme, "http") == 0) { + proxy = g_strdup (self->http_proxy); + } + + if (proxy) + px_strv_builder_add_proxy (builder, proxy); +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->name = "config-sysconfig"; + iface->priority = PX_CONFIG_PRIORITY_LAST; + iface->is_available = px_config_sysconfig_is_available; + iface->get_config = px_config_sysconfig_get_config; +} diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.h b/src/backend/plugins/config-sysconfig/config-sysconfig.h new file mode 100644 index 0000000..daa4672 --- /dev/null +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.h @@ -0,0 +1,34 @@ +/* config-sysconfig.h + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib.h> + +G_BEGIN_DECLS + +#define PX_CONFIG_TYPE_SYSCONFIG (px_config_sysconfig_get_type ()) + +G_DECLARE_FINAL_TYPE (PxConfigSysConfig, px_config_sysconfig, PX, CONFIG_SYSCONFIG, GObject) + +G_END_DECLS + + diff --git a/src/backend/plugins/config-sysconfig/meson.build b/src/backend/plugins/config-sysconfig/meson.build new file mode 100644 index 0000000..6d6789b --- /dev/null +++ b/src/backend/plugins/config-sysconfig/meson.build @@ -0,0 +1,9 @@ +plugin_name = 'config-sysconfig' + +if get_option(plugin_name) + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +endif diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c new file mode 100644 index 0000000..cc9c92d --- /dev/null +++ b/src/backend/plugins/config-windows/config-windows.c @@ -0,0 +1,252 @@ +/* config-windows.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <windows.h> +#include <winreg.h> + +#include <gio/gio.h> + +#include "config-windows.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +#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 + +struct _PxConfigWindows { + GObject parent_instance; +}; + +static void px_config_iface_init (PxConfigInterface *iface); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigWindows, + px_config_windows, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +static void +px_config_windows_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_OPTION: + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_windows_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_config_windows_init (PxConfigWindows *self) +{ +} + +static void +px_config_windows_class_init (PxConfigWindowsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = px_config_windows_set_property; + object_class->get_property = px_config_windows_get_property; + + g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option"); +} + +static gboolean +px_config_windows_is_available (PxConfig *self) +{ + return TRUE; +} + +static gboolean +get_registry (const char *key, + const char *name, + char **sval, + guint32 *slen, + guint32 *ival) +{ + HKEY hkey; + LONG result; + DWORD type; + DWORD buflen = W32REG_BUFFLEN; + BYTE buffer[W32REG_BUFFLEN]; + + if (sval && ival) + return FALSE; + + if (RegOpenKeyExA (HKEY_CURRENT_USER, key, 0, KEY_READ, &hkey) != ERROR_SUCCESS) + return FALSE; + + result = RegQueryValueExA (hkey, name, NULL, &type, buffer, &buflen); + RegCloseKey (hkey); + + 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 = g_malloc0 (buflen); + return memcpy (*sval, buffer, buflen) != NULL; + case REG_DWORD: + if (ival) + return memcpy (ival, buffer, buflen < sizeof (guint32) ? buflen : sizeof (guint32)) != NULL; + default: + break; + } + + return FALSE; +} + +static GHashTable * +parse_manual (char *manual) +{ + g_auto (GStrv) split = NULL; + GHashTable *ret = g_hash_table_new (g_str_hash, g_str_equal); + + /* We have to check for two formats: + * - 1.2.3.4:8080 + * - ftp=1.2.4.5:8080;https=1.2.3.4:8080 + */ + + split = g_strsplit (manual, ";", -1); + for (int idx = 0; idx < g_strv_length (split); idx++) { + if (!strchr (split[idx], '=')) { + g_hash_table_insert (ret, (char *)"http", g_strdup_printf ("http://%s", split[idx])); + } else { + g_auto (GStrv) split_kv = g_strsplit (split[idx], "=", -1); + + if (g_strv_length (split_kv) == 2) { + g_hash_table_insert (ret, g_strdup (split_kv[0]), g_strdup_printf ("%s://%s", split_kv[0], split_kv[1])); + } + } + } + + return ret; +} + +static gboolean +is_enabled (char type) +{ + g_autofree char *data = NULL; + guint32 dlen = 0; + gboolean result = FALSE; + + if (!get_registry (W32REG_BASEKEY "\\Connections", "DefaultConnectionSettings", &data, &dlen, NULL)) + return FALSE; + + if (dlen >= 9) + result = (data[8] & type) == type; + + return result; +} + +static void +px_config_windows_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder) +{ + char *tmp = NULL; + guint32 enabled = 0; + + if (get_registry (W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) { + g_auto (GStrv) no_proxy = g_strsplit (tmp, ",", -1); + + if (px_manager_is_ignore (uri, no_proxy)) + return; + } + + /* WPAD */ + if (is_enabled (W32REG_OFFSET_WPAD)) { + px_strv_builder_add_proxy (builder, "wpad://"); + return; + } + + /* PAC */ + if (is_enabled (W32REG_OFFSET_PAC) && get_registry (W32REG_BASEKEY, "AutoConfigURL", &tmp, NULL, NULL)) { + g_autofree char *pac_uri = g_strconcat ("pac+", tmp, NULL); + GUri *ac_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL); + + if (ac_uri) { + px_strv_builder_add_proxy (builder, pac_uri); + return; + } + } + + /* Manual proxy */ + if (get_registry (W32REG_BASEKEY, "ProxyEnable", NULL, NULL, &enabled) && enabled && get_registry (W32REG_BASEKEY, "ProxyServer", &tmp, NULL, NULL)) { + g_autoptr (GHashTable) table = parse_manual (tmp); + const char *scheme = g_uri_get_scheme (uri); + + if (table) { + char *ret = g_hash_table_lookup (table, scheme); + if (ret) { + px_strv_builder_add_proxy (builder, ret); + return; + } + + ret = g_hash_table_lookup (table, "socks"); + if (ret) { + px_strv_builder_add_proxy (builder, ret); + return; + } + } + } +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->name = "config-windows"; + iface->priority = PX_CONFIG_PRIORITY_DEFAULT; + iface->is_available = px_config_windows_is_available; + iface->get_config = px_config_windows_get_config; +} diff --git a/src/backend/plugins/config-windows/config-windows.h b/src/backend/plugins/config-windows/config-windows.h new file mode 100644 index 0000000..7c2afcf --- /dev/null +++ b/src/backend/plugins/config-windows/config-windows.h @@ -0,0 +1,34 @@ +/* config-windows.h + * + * Copyright 2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib.h> + +G_BEGIN_DECLS + +#define PX_CONFIG_TYPE_WINDOWS (px_config_windows_get_type ()) + +G_DECLARE_FINAL_TYPE (PxConfigWindows, px_config_windows, PX, CONFIG_WINDOWS, GObject) + +G_END_DECLS + + diff --git a/src/backend/plugins/config-windows/meson.build b/src/backend/plugins/config-windows/meson.build new file mode 100644 index 0000000..302a33e --- /dev/null +++ b/src/backend/plugins/config-windows/meson.build @@ -0,0 +1,9 @@ +plugin_name = 'config-windows' + +if get_option(plugin_name) and with_platform_windows + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +endif
\ No newline at end of file diff --git a/src/backend/plugins/meson.build b/src/backend/plugins/meson.build new file mode 100644 index 0000000..c7943d2 --- /dev/null +++ b/src/backend/plugins/meson.build @@ -0,0 +1,18 @@ +subdir('config-env') +subdir('config-gnome') +subdir('config-kde') +subdir('config-osx') +subdir('config-sysconfig') +subdir('config-windows') + +subdir('pacrunner-duktape') + +summary({ + 'Configuration Environment' : get_option('config-env'), + 'Configuration GNOME ' : get_option('config-gnome'), + 'Configuration KDE ' : get_option('config-kde'), + 'Configuration Windows ' : get_option('config-windows'), + 'Configuration sysconfig ' : get_option('config-sysconfig'), + 'Configuration OS X ' : get_option('config-osx'), + 'PAC Runner Duktape ' : get_option('pacrunner-duktape'), +}, section: 'Plugins')
\ No newline at end of file diff --git a/src/backend/plugins/pacrunner-duktape/meson.build b/src/backend/plugins/pacrunner-duktape/meson.build new file mode 100644 index 0000000..f391b6d --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/meson.build @@ -0,0 +1,17 @@ +plugin_name = 'pacrunner-duktape' + +if get_option(plugin_name) + +duktape_dep = dependency('duktape') +m_dep = cc.find_library('m', required : false) + +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), +] + +px_backend_deps += [ + duktape_dep, + m_dep +] + +endif
\ No newline at end of file diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c new file mode 100644 index 0000000..3676e48 --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -0,0 +1,201 @@ +/* pacrunner-duktape.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gio/gio.h> + +#include <unistd.h> +#ifdef __WIN32__ +#include <ws2tcpip.h> +#else +#include <netdb.h> +#endif + +#include "pacrunner-duktape.h" +#include "pacutils.h" +#include "px-plugin-pacrunner.h" + +#include "duktape.h" + +struct _PxPacRunnerDuktape { + GObject parent_instance; + duk_context *ctx; +}; + +static void px_pacrunner_iface_init (PxPacRunnerInterface *iface); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxPacRunnerDuktape, + px_pacrunner_duktape, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_PACRUNNER, px_pacrunner_iface_init)) + + +static duk_ret_t +dns_resolve (duk_context *ctx) +{ + const char *hostname = NULL; + struct addrinfo *info; + char tmp[INET6_ADDRSTRLEN + 1]; + + 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. */ + hostname = duk_get_string (ctx, 0); + if (!hostname) + return 0; + + /* Look it up */ + if (getaddrinfo (hostname, NULL, NULL, &info)) + return 0; + + /* Try for IPv4 */ + 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 +my_ip_address (duk_context *ctx) +{ + char hostname[1024]; + + hostname[sizeof (hostname) - 1] = '\0'; + + if (!gethostname (hostname, sizeof (hostname) - 1)) { + duk_push_string (ctx, hostname); + return dns_resolve (ctx); + } + + return duk_error (ctx, DUK_ERR_ERROR, "Unable to find hostname!"); +} + +static void +px_pacrunner_duktape_init (PxPacRunnerDuktape *self) +{ + self->ctx = duk_create_heap_default (); + if (!self->ctx) + return; + + duk_push_c_function (self->ctx, dns_resolve, 1); + duk_put_global_string (self->ctx, "dnsResolve"); + + duk_push_c_function (self->ctx, my_ip_address, 1); + duk_put_global_string (self->ctx, "myIpAddress"); + + duk_push_string (self->ctx, JAVASCRIPT_ROUTINES); + if (duk_peval_noresult (self->ctx)) + goto error; + + return; + +error: + duk_destroy_heap (self->ctx); +} + +static void +px_pacrunner_duktape_dispose (GObject *object) +{ + PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (object); + + g_clear_pointer (&self->ctx, duk_destroy_heap); + + G_OBJECT_CLASS (px_pacrunner_duktape_parent_class)->dispose (object); +} + +static void +px_pacrunner_duktape_class_init (PxPacRunnerDuktapeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = px_pacrunner_duktape_dispose; +} + +static gboolean +px_pacrunner_duktape_set_pac (PxPacRunner *pacrunner, + GBytes *pac_data) +{ + PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (pacrunner); + gsize len; + gconstpointer content = g_bytes_get_data (pac_data, &len); + + duk_push_lstring (self->ctx, content, len); + + if (duk_peval_noresult (self->ctx)) { + return FALSE; + } + + return TRUE; +} + +static char * +px_pacrunner_duktape_run (PxPacRunner *pacrunner, + GUri *uri) +{ + PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (pacrunner); + duk_int_t result; + + duk_get_global_string (self->ctx, "FindProxyForURL"); + duk_push_string (self->ctx, g_uri_to_string (uri)); + duk_push_string (self->ctx, g_uri_get_host (uri)); + result = duk_pcall (self->ctx, 2); + + if (result == 0) { + const char *proxy = duk_get_string (self->ctx, 0); + char *proxy_string; + + if (!proxy) { + duk_pop (self->ctx); + return g_strdup (""); + } + + proxy_string = g_strdup (proxy); + + duk_pop (self->ctx); + + return proxy_string; + } + + duk_pop (self->ctx); + return g_strdup (""); +} + +static void +px_pacrunner_iface_init (PxPacRunnerInterface *iface) +{ + iface->set_pac = px_pacrunner_duktape_set_pac; + iface->run = px_pacrunner_duktape_run; +} diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h new file mode 100644 index 0000000..8721a62 --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h @@ -0,0 +1,32 @@ +/* pacrunner-duktape.h + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define PX_PACRUNNER_TYPE_DUKTAPE (px_pacrunner_duktape_get_type ()) + +G_DECLARE_FINAL_TYPE (PxPacRunnerDuktape, px_pacrunner_duktape, PX, PACRUNNER_DUKTAPE, GObject) + +G_END_DECLS diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c new file mode 100644 index 0000000..1eab303 --- /dev/null +++ b/src/backend/px-manager.c @@ -0,0 +1,724 @@ +/* px-manager.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "config.h" +#include "px-backend-config.h" + +#include <glib.h> +#include <glib-object.h> +#include <gio/gio.h> + +#include "px-manager.h" +#include "px-plugin-config.h" +#include "px-plugin-pacrunner.h" + +#ifdef HAVE_CONFIG_ENV +#include <plugins/config-env/config-env.h> +#endif + +#ifdef HAVE_CONFIG_GNOME +#include <plugins/config-gnome/config-gnome.h> +#endif + +#ifdef HAVE_CONFIG_KDE +#include <plugins/config-kde/config-kde.h> +#endif + +#ifdef HAVE_CONFIG_OSX +#include <plugins/config-osx/config-osx.h> +#endif + +#ifdef HAVE_CONFIG_SYSCONFIG +#include <plugins/config-sysconfig/config-sysconfig.h> +#endif + +#ifdef HAVE_CONFIG_WINDOWS +#include <plugins/config-windows/config-windows.h> +#endif + +#ifdef HAVE_PACRUNNER_DUKTAPE +#include <plugins/pacrunner-duktape/pacrunner-duktape.h> +#endif + +#ifdef HAVE_CURL +#include <curl/curl.h> +#endif + +enum { + PROP_0, + PROP_CONFIG_PLUGIN, + PROP_CONFIG_OPTION, + LAST_PROP +}; + +static GParamSpec *obj_properties[LAST_PROP]; + +/** + * PxManager: + * + * Manage libproxy modules + */ + +struct _PxManager { + GObject parent_instance; + GList *config_plugins; + GList *pacrunner_plugins; + GNetworkMonitor *network_monitor; +#ifdef HAVE_CURL + CURL *curl; +#endif + + char *config_plugin; + char *config_option; + + gboolean online; + gboolean wpad; + GBytes *pac_data; + char *pac_url; +}; + +G_DEFINE_TYPE (PxManager, px_manager, G_TYPE_OBJECT) + +G_DEFINE_QUARK (px - manager - error - quark, px_manager_error) + +static void +px_manager_on_network_changed (GNetworkMonitor *monitor, + gboolean network_available, + gpointer user_data) +{ + PxManager *self = PX_MANAGER (user_data); + + g_debug ("%s: Network connection changed, clearing pac data", __FUNCTION__); + + self->wpad = FALSE; + self->online = network_available; + g_clear_pointer (&self->pac_url, g_free); + g_clear_pointer (&self->pac_data, g_bytes_unref); +} + +static gint +config_order_compare (gconstpointer a, + gconstpointer b) +{ + PxConfig *config_a = (PxConfig *)a; + PxConfig *config_b = (PxConfig *)b; + PxConfigInterface *ifc_a = PX_CONFIG_GET_IFACE (config_a); + PxConfigInterface *ifc_b = PX_CONFIG_GET_IFACE (config_b); + + if (ifc_a->priority < ifc_b->priority) + return -1; + + if (ifc_a->priority == ifc_b->priority) + return 0; + + return 1; +} + +static void +px_manager_add_config_plugin (PxManager *self, + GType type) +{ + PxConfig *config = g_object_new (type, "config-option", self->config_option, NULL); + PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (config); + + if (!self->config_plugin || g_strcmp0 (ifc->name, self->config_plugin) == 0) + self->config_plugins = g_list_insert_sorted (self->config_plugins, config, config_order_compare); +} + +static void +px_manager_add_pacrunner_plugin (PxManager *self, + GType type) +{ + PxPacRunner *pacrunner = g_object_new (type, NULL); + + self->pacrunner_plugins = g_list_append (self->pacrunner_plugins, pacrunner); +} + +static void +px_manager_constructed (GObject *object) +{ + PxManager *self = PX_MANAGER (object); + + if (g_getenv ("PX_DEBUG")) { + const gchar *g_messages_debug; + + g_messages_debug = g_getenv ("G_MESSAGES_DEBUG"); + + if (!g_messages_debug) { + g_setenv ("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE); + } else { + g_autofree char *new_g_messages_debug = NULL; + + new_g_messages_debug = g_strconcat (g_messages_debug, " ", G_LOG_DOMAIN, NULL); + if (new_g_messages_debug) + g_setenv ("G_MESSAGES_DEBUG", new_g_messages_debug, TRUE); + } + } + +#ifdef HAVE_CONFIG_ENV + px_manager_add_config_plugin (self, PX_CONFIG_TYPE_ENV); +#endif +#ifdef HAVE_CONFIG_GNOME + px_manager_add_config_plugin (self, PX_CONFIG_TYPE_GNOME); +#endif +#ifdef HAVE_CONFIG_KDE + px_manager_add_config_plugin (self, PX_CONFIG_TYPE_KDE); +#endif +#ifdef HAVE_CONFIG_OSX + px_manager_add_config_plugin (self, PX_CONFIG_TYPE_OSX); +#endif +#ifdef HAVE_CONFIG_SYSCONFIG + px_manager_add_config_plugin (self, PX_CONFIG_TYPE_SYSCONFIG); +#endif +#ifdef HAVE_CONFIG_WINDOWS + px_manager_add_config_plugin (self, PX_CONFIG_TYPE_WINDOWS); +#endif + + g_debug ("Active config plugins:\n"); + for (GList *list = self->config_plugins; list && list->data; list = list->next) { + PxConfig *config = list->data; + PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (config); + + g_debug (" - %s\n", ifc->name); + } + +#ifdef HAVE_PACRUNNER_DUKTAPE + px_manager_add_pacrunner_plugin (self, PX_PACRUNNER_TYPE_DUKTAPE); +#endif + + self->pac_data = NULL; + + self->network_monitor = g_network_monitor_get_default (); + g_signal_connect_object (G_OBJECT (self->network_monitor), "network-changed", G_CALLBACK (px_manager_on_network_changed), self, 0); + px_manager_on_network_changed (self->network_monitor, g_network_monitor_get_network_available (self->network_monitor), self); + g_debug ("%s: Up and running", __FUNCTION__); +} + +static void +px_manager_dispose (GObject *object) +{ + PxManager *self = PX_MANAGER (object); + + for (GList *list = self->config_plugins; list && list->data; list = list->next) + g_clear_object (&list->data); + + for (GList *list = self->pacrunner_plugins; list && list->data; list = list->next) + g_clear_object (&list->data); + + g_clear_pointer (&self->config_plugin, g_free); + + G_OBJECT_CLASS (px_manager_parent_class)->dispose (object); +} + +static void +px_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PxManager *self = PX_MANAGER (object); + + switch (prop_id) { + case PROP_CONFIG_PLUGIN: + self->config_plugin = g_strdup (g_value_get_string (value)); + break; + case PROP_CONFIG_OPTION: + self->config_option = g_strdup (g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +px_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { + case PROP_CONFIG_PLUGIN: + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +px_manager_class_init (PxManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = px_manager_constructed; + object_class->dispose = px_manager_dispose; + object_class->set_property = px_manager_set_property; + object_class->get_property = px_manager_get_property; + + obj_properties[PROP_CONFIG_PLUGIN] = g_param_spec_string ("config-plugin", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + obj_properties[PROP_CONFIG_OPTION] = g_param_spec_string ("config-option", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, LAST_PROP, obj_properties); +} + +static void +px_manager_init (PxManager *self) +{ +} + +/** + * px_manager_new_with_options: + * @optname1: name of first property to set + * @...: value of @optname1, followed by additional property/value pairs + * + * Create a new `PxManager` with the specified options. + * + * Returns: the newly created `PxManager` + */ +PxManager * +px_manager_new_with_options (const char *optname1, + ...) +{ + PxManager *self; + va_list ap; + + va_start (ap, optname1); + self = (PxManager *)g_object_new_valist (PX_TYPE_MANAGER, optname1, ap); + va_end (ap); + + return self; +} + +/** + * px_manager_new: + * + * Create a new `PxManager`. + * + * Returns: the newly created `PxManager` + */ +PxManager * +px_manager_new (void) +{ + return px_manager_new_with_options (NULL); +} + +#ifdef HAVE_CURL +static size_t +store_data (void *contents, + size_t size, + size_t nmemb, + void *user_pointer) +{ + GByteArray *byte_array = user_pointer; + size_t real_size = size * nmemb; + + g_byte_array_append (byte_array, contents, real_size); + + return real_size; +} +#endif + +/** + * px_manager_pac_download: + * @self: a px manager + * @uri: PAC uri + * + * Downloads a PAC file from provided @url. + * + * Returns: (nullable): a newly created `GBytes` containing PAC data, or %NULL on error. + */ +GBytes * +px_manager_pac_download (PxManager *self, + const char *uri) +{ +#ifdef HAVE_CURL + GByteArray *byte_array = g_byte_array_new (); + CURLcode res; + const char *url = uri; + + if (!self->curl) + self->curl = curl_easy_init (); + + if (!self->curl) + return NULL; + + if (g_str_has_prefix (url, "pac+")) + url += 4; + + curl_easy_setopt (self->curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt (self->curl, CURLOPT_FOLLOWLOCATION, 1); + curl_easy_setopt (self->curl, CURLOPT_NOPROXY, "*"); + curl_easy_setopt (self->curl, CURLOPT_CONNECTTIMEOUT, 30); + curl_easy_setopt (self->curl, CURLOPT_USERAGENT, "libproxy"); + + curl_easy_setopt (self->curl, CURLOPT_URL, url); + curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data); + curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, byte_array); + + res = curl_easy_perform (self->curl); + if (res != CURLE_OK) { + g_debug ("%s: Could not download data: %s", __FUNCTION__, curl_easy_strerror (res)); + return NULL; + } + + return g_byte_array_free_to_bytes (byte_array); +#else + return NULL; +#endif +} + +/** + * px_manager_get_configuration: + * @self: a px manager + * @uri: PAC uri + * @error: a #GError + * + * Get raw proxy configuration for gien @uri. + * + * Returns: (transfer full) (nullable): a newly created `GStrv` containing configuration data for @uri. + */ +char ** +px_manager_get_configuration (PxManager *self, + GUri *uri, + GError **error) +{ + g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); + + for (GList *list = self->config_plugins; list && list->data; list = list->next) { + PxConfig *config = PX_CONFIG (list->data); + PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (config); + + ifc->get_config (config, uri, builder); + } + + return g_strv_builder_end (builder); +} + +static void +px_manager_run_pac (PxPacRunner *pacrunner, + GBytes *pac, + GUri *uri, + GStrvBuilder *builder) +{ + PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (pacrunner); + g_auto (GStrv) proxies_split = NULL; + char *pac_response; + + if (!ifc->set_pac (PX_PAC_RUNNER (pacrunner), pac)) + return; + + pac_response = ifc->run (PX_PAC_RUNNER (pacrunner), uri); + + /* Split line to handle multiple proxies */ + proxies_split = g_strsplit (pac_response, ";", -1); + + for (int idx = 0; idx < g_strv_length (proxies_split); idx++) { + char *line = g_strstrip (proxies_split[idx]); + g_auto (GStrv) word_split = g_strsplit (line, " ", -1); + g_autoptr (GUri) proxy_uri = NULL; + char *method; + char *server; + + /* Check for syntax "METHOD SERVER" */ + if (g_strv_length (word_split) == 2) { + g_autofree char *uri_string = NULL; + g_autofree char *proxy_string = NULL; + + method = word_split[0]; + server = word_split[1]; + + uri_string = g_strconcat ("http://", server, NULL); + proxy_uri = g_uri_parse (uri_string, G_URI_FLAGS_PARSE_RELAXED, NULL); + if (!proxy_uri) + continue; + + if (g_ascii_strncasecmp (method, "proxy", 5) == 0) { + proxy_string = g_uri_to_string (proxy_uri); + } else if (g_ascii_strncasecmp (method, "socks4a", 7) == 0) { + proxy_string = g_strconcat ("socks4a://", server, NULL); + } else if (g_ascii_strncasecmp (method, "socks4", 6) == 0) { + proxy_string = g_strconcat ("socks4://", server, NULL); + } else if (g_ascii_strncasecmp (method, "socks5", 6) == 0) { + proxy_string = g_strconcat ("socks5://", server, NULL); + } else if (g_ascii_strncasecmp (method, "socks", 5) == 0) { + proxy_string = g_strconcat ("socks://", server, NULL); + } + + px_strv_builder_add_proxy (builder, proxy_string); + } else { + /* Syntax not found, returning direct */ + px_strv_builder_add_proxy (builder, "direct://"); + } + } +} + +static gboolean +px_manager_expand_wpad (PxManager *self, + GUri *uri) +{ + const char *scheme = g_uri_get_scheme (uri); + gboolean ret = FALSE; + + if (g_strcmp0 (scheme, "wpad") == 0) { + ret = TRUE; + + if (!self->wpad) { + g_clear_pointer (&self->pac_data, g_bytes_unref); + g_clear_pointer (&self->pac_url, g_free); + self->wpad = TRUE; + } + + if (!self->pac_data) { + GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_PARSE_RELAXED, NULL); + + g_debug ("%s: Trying to find the PAC using WPAD...", __FUNCTION__); + self->pac_url = g_uri_to_string (wpad_url); + self->pac_data = px_manager_pac_download (self, self->pac_url); + if (!self->pac_data) { + g_clear_pointer (&self->pac_url, g_free); + ret = FALSE; + } + } + } + + return ret; +} + +static gboolean +px_manager_expand_pac (PxManager *self, + GUri *uri) +{ + gboolean ret = FALSE; + const char *scheme = g_uri_get_scheme (uri); + + if (g_str_has_prefix (scheme, "pac+")) { + ret = TRUE; + + if (self->wpad) + self->wpad = FALSE; + + if (self->pac_data) { + g_autofree char *uri_str = g_uri_to_string (uri); + + if (g_strcmp0 (self->pac_url, uri_str) != 0) { + g_clear_pointer (&self->pac_url, g_free); + g_clear_pointer (&self->pac_data, g_bytes_unref); + } + } + + if (!self->pac_data) { + self->pac_url = g_uri_to_string (uri); + self->pac_data = px_manager_pac_download (self, self->pac_url); + + if (!self->pac_data) { + g_warning ("%s: Unable to download PAC from %s while online = %d!", __FUNCTION__, self->pac_url, self->online); + g_clear_pointer (&self->pac_url, g_free); + ret = FALSE; + } else { + g_debug ("%s: PAC recevied!", __FUNCTION__); + } + } + } + + return ret; +} + +/** + * px_manager_get_proxies_sync: + * @self: a px manager + * @url: a url + * + * Get proxies for giben @url. + * + * Returns: (transfer full) (nullable): a newly created `GStrv` containing proxy related information. + */ +char ** +px_manager_get_proxies_sync (PxManager *self, + const char *url, + GError **error) +{ + g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); + g_autoptr (GUri) uri = g_uri_parse (url, G_URI_FLAGS_PARSE_RELAXED, error); + g_auto (GStrv) config = NULL; + + g_debug ("%s: url=%s online=%d", __FUNCTION__, url ? url : "?", self->online); + if (!uri || !self->online) { + px_strv_builder_add_proxy (builder, "direct://"); + return g_strv_builder_end (builder); + } + + config = px_manager_get_configuration (self, uri, error); + + for (int idx = 0; idx < g_strv_length (config); idx++) { + GUri *conf_url = g_uri_parse (config[idx], G_URI_FLAGS_PARSE_RELAXED, NULL); + + g_debug ("%s: Config[%d] = %s", __FUNCTION__, idx, config[idx]); + + if (px_manager_expand_wpad (self, conf_url) || px_manager_expand_pac (self, conf_url)) { + GList *list; + + for (list = self->pacrunner_plugins; list && list->data; list = list->next) { + PxPacRunner *pacrunner = PX_PAC_RUNNER (list->data); + + px_manager_run_pac (pacrunner, self->pac_data, uri, builder); + } + } else if (!g_str_has_prefix (g_uri_get_scheme (conf_url), "wpad") && !g_str_has_prefix (g_uri_get_scheme (conf_url), "pac+")) { + px_strv_builder_add_proxy (builder, g_uri_to_string (conf_url)); + } + } + + /* In case no proxy could be found, assume direct connection */ + if (((GPtrArray *)builder)->len == 0) + px_strv_builder_add_proxy (builder, "direct://"); + + for (int idx = 0; idx < ((GPtrArray *)builder)->len; idx++) + g_debug ("%s: Proxy[%d] = %s", __FUNCTION__, idx, (char *)((GPtrArray *)builder)->pdata[idx]); + + return g_strv_builder_end (builder); +} + +void +px_strv_builder_add_proxy (GStrvBuilder *builder, + const char *value) +{ + for (int idx = 0; idx < ((GPtrArray *)builder)->len; idx++) { + if (g_strcmp0 ((char *)((GPtrArray *)builder)->pdata[idx], value) == 0) + return; + } + + g_strv_builder_add (builder, value); +} + +static gboolean +ignore_domain (GUri *uri, + char *ignore) +{ + g_auto (GStrv) ignore_split = g_strsplit (ignore, ":", -1); + const char *host = g_uri_get_host (uri); + char *ig_host; + int ig_port = -1; + int port = g_uri_get_port (uri); + + /* Get our ignore pattern's hostname and port */ + ig_host = ignore_split[0]; + if (g_strv_length (ignore_split) == 2) + ig_port = atoi (ignore_split[1]); + + /* Hostname match (domain.com or domain.com:80) */ + if (g_strcmp0 (host, ig_host) == 0) + return (ig_port == -1 || port == ig_port); + + /* Endswith (.domain.com or .domain.com:80) */ + if (ig_host[0] == '.' && g_str_has_suffix (host, ig_host)) + return (ig_port == -1 || port == ig_port); + + /* Glob (*.domain.com or *.domain.com:80) */ + if (ig_host[0] == '*' && g_str_has_suffix (host, ig_host + 1)) + return (ig_port == -1 || port == ig_port); + + /* No match was found */ + return FALSE; +} + +static gboolean +ignore_hostname (GUri *uri, + char *ignore) +{ + const char *host = g_uri_get_host (uri); + + if (g_strcmp0 (ignore, "<local>") == 0 && strchr (host, ':') == NULL && strchr (host, '.') == NULL) + return TRUE; + + return FALSE; +} + +static gboolean +ignore_ip (GUri *uri, + char *ignore) +{ + GInetAddress *inet_address1; + GInetAddress *inet_address2; + g_auto (GStrv) ignore_split = NULL; + gboolean is_ip1 = g_hostname_is_ip_address (g_uri_get_host (uri)); + gboolean is_ip2 = g_hostname_is_ip_address (ignore); + int port = g_uri_get_port (uri); + int ig_port = -1; + gboolean result; + + /* + * IPv4 + * IPv6 + */ + if (!is_ip1 || !is_ip2) + return FALSE; + + /* + * IPv4/CIDR + * IPv4/IPv4 + * IPv6/CIDR + * IPv6/IPv6 + */ + + /* MISSING */ + + /* + * IPv4:port + * [IPv6]:port + */ + ignore_split = g_strsplit (ignore, ":", -1); + if (g_strv_length (ignore_split) == 2) + ig_port = atoi (ignore_split[1]); + + inet_address1 = g_inet_address_new_from_string (g_uri_get_host (uri)); + inet_address2 = g_inet_address_new_from_string (ignore); + result = g_inet_address_equal (inet_address1, inet_address2); + + return port != -1 ? ((port == ig_port) && result) : result; +} +gboolean +px_manager_is_ignore (GUri *uri, + GStrv ignores) +{ + if (!ignores) + return FALSE; + + for (int idx = 0; idx < g_strv_length (ignores); idx++) { + if (ignore_hostname (uri, ignores[idx])) + return TRUE; + + if (ignore_domain (uri, ignores[idx])) + return TRUE; + + if (ignore_ip (uri, ignores[idx])) + return TRUE; + } + + return FALSE; +} diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h new file mode 100644 index 0000000..558ddba --- /dev/null +++ b/src/backend/px-manager.h @@ -0,0 +1,59 @@ +/* px-manager.h + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define PX_TYPE_MANAGER (px_manager_get_type()) + +G_DECLARE_FINAL_TYPE (PxManager, px_manager, PX, MANAGER, GObject) + +extern GQuark px_manager_error_quark (void); +#define PX_MANAGER_ERROR px_manager_error_quark () + +typedef enum { + PX_MANAGER_ERROR_UNKNOWN_METHOD = 1001, +} PxManagerErrorCode; + + +PxManager *px_manager_new (void); +PxManager *px_manager_new_with_options (const char *optname1, ...); + +char **px_manager_get_proxies_sync (PxManager *self, + const char *url, + GError **error); + +GBytes *px_manager_pac_download (PxManager *self, + const char *uri); + +char **px_manager_get_configuration (PxManager *self, + GUri *uri, + GError **error); + +void px_strv_builder_add_proxy (GStrvBuilder *builder, + const char *value); + +gboolean px_manager_is_ignore (GUri *uri, GStrv ignores); + +G_END_DECLS diff --git a/src/backend/px-plugin-config.c b/src/backend/px-plugin-config.c new file mode 100644 index 0000000..22f369a --- /dev/null +++ b/src/backend/px-plugin-config.c @@ -0,0 +1,37 @@ +/* px-plugin-config.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-plugin-config.h" + +G_DEFINE_INTERFACE (PxConfig, px_config, G_TYPE_OBJECT) + +static void +px_config_default_init (PxConfigInterface *iface) +{ + g_object_interface_install_property (iface, + g_param_spec_string ("config-option", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); +} diff --git a/libproxy/extension_network.hpp b/src/backend/px-plugin-config.h index 1a8fc46..6958df6 100644 --- a/libproxy/extension_network.hpp +++ b/src/backend/px-plugin-config.h @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2009 Nathaniel McCallum <nathaniel@natemccallum.com> +/* px-plugin-config.h + * + * Copyright 2023 The Libproxy Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -14,24 +14,35 @@ * * 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 - ******************************************************************************/ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once -#ifndef EXTENSION_NETWORK_HPP_ -#define EXTENSION_NETWORK_HPP_ +#include <glib-object.h> -#include <libmodman/module.hpp> -#include "config.hpp" +G_BEGIN_DECLS -namespace libproxy { -using namespace libmodman; +#define PX_TYPE_CONFIG (px_config_get_type ()) -// Network module -class DLL_PUBLIC network_extension : public extension<network_extension> { -public: - virtual bool changed()=0; +G_DECLARE_INTERFACE (PxConfig, px_config, PX, CONFIG, GObject) + +enum { + PX_CONFIG_PRIORITY_FIRST, + PX_CONFIG_PRIORITY_DEFAULT, + PX_CONFIG_PRIORITY_LAST, }; -} +struct _PxConfigInterface +{ + GTypeInterface parent_iface; + const char *name; + gint priority; + + gboolean (*is_available) (PxConfig *self); + void (*get_config) (PxConfig *self, GUri *uri, GStrvBuilder *builder); +}; -#endif /* EXTENSION_NETWORK_HPP_ */ +G_END_DECLS diff --git a/libmodman/test/builtin.cpp b/src/backend/px-plugin-pacrunner.c index 8a3f328..bf5dc6a 100644 --- a/libmodman/test/builtin.cpp +++ b/src/backend/px-plugin-pacrunner.c @@ -1,6 +1,6 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * Copyright (C) 2009 Nathaniel McCallum <nathaniel@natemccallum.com> +/* px-plugin-pacrunner.c + * + * Copyright 2022-2023 The Libproxy Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -14,15 +14,16 @@ * * 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 - ******************************************************************************/ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ -#include "main.hpp" +#include "px-plugin-pacrunner.h" -MM_DEF_BUILTIN(BUILTIN_MODULE); +G_DEFINE_INTERFACE (PxPacRunner, px_pacrunner, G_TYPE_OBJECT) -int main() { - module_manager mm; - mm.register_type<EXTTYPE>(); - return !mm.load_builtin(& MM_BUILTIN(BUILTIN_MODULE)); +static void +px_pacrunner_default_init (PxPacRunnerInterface *iface) +{ } diff --git a/src/backend/px-plugin-pacrunner.h b/src/backend/px-plugin-pacrunner.h new file mode 100644 index 0000000..4b03a24 --- /dev/null +++ b/src/backend/px-plugin-pacrunner.h @@ -0,0 +1,40 @@ +/* px-plugin-pacrunner.h + * + * Copyright 2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define PX_TYPE_PACRUNNER (px_pacrunner_get_type ()) + +G_DECLARE_INTERFACE (PxPacRunner, px_pacrunner, PX, PAC_RUNNER, GObject) + +struct _PxPacRunnerInterface +{ + GTypeInterface parent_iface; + + gboolean (*set_pac) (PxPacRunner *pacrunner, GBytes *pac_data); + char *(*run) (PxPacRunner *self, GUri *uri); +}; + +G_END_DECLS diff --git a/libproxy/libproxy.map b/src/libproxy/libproxy.map index 511c7f2..32f0db3 100644 --- a/libproxy/libproxy.map +++ b/src/libproxy/libproxy.map @@ -5,3 +5,4 @@ LIBPROXY_0.4.16 { px_proxy_factory_free_proxies; px_proxy_factory_free; }; + diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build new file mode 100644 index 0000000..3a9aa87 --- /dev/null +++ b/src/libproxy/meson.build @@ -0,0 +1,88 @@ +libproxy_inc = include_directories('.') + +libproxy_sources = [] + +libproxy_sources = [ + 'proxy.c', +] + +libproxy_headers = [ + 'proxy.h', +] + +libproxy_deps = [ + px_backend_dep, +] + +mapfile = 'libproxy.map' +vscript = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) +vflag = [] +if cc.has_multi_link_arguments(vscript) + vflag += vscript +endif + +libproxy = shared_library( + 'proxy', + libproxy_sources, + include_directories: px_backend_inc, + dependencies: libproxy_deps, + link_args : vflag, + link_depends : mapfile, + soversion: '1', + install: true, +) + +libproxy_dep = declare_dependency ( + include_directories: libproxy_inc, + link_with: libproxy, + dependencies: libproxy_deps +) + +install_headers(libproxy_headers, subdir: 'libproxy') + +pkg = import('pkgconfig') +pkg.generate( + libraries: [libproxy], + subdirs: 'libproxy', + version: meson.project_version(), + name: 'libproxy', + filebase: package_api_name, + description: 'libproxy', + requires: 'gio-2.0', + install_dir: join_paths(get_option('libdir'), 'pkgconfig') +) + +if get_option('introspection') + gnome = import('gnome') + + libproxy_gir_extra_args = [ + '--c-include=proxy.h', + '--quiet', + ] + + libproxy_gir = gnome.generate_gir( + libproxy, + sources: libproxy_headers + libproxy_sources, + nsversion: api_version, + namespace: 'Libproxy', + export_packages: package_api_name, + symbol_prefix: 'px', + identifier_prefix: 'px', + link_with: libproxy, + includes: [ 'Gio-2.0' ], + install: true, + install_dir_gir: girdir, + install_dir_typelib: typelibdir, + extra_args: libproxy_gir_extra_args, + ) + + if get_option('vapi') + libproxy_vapi = gnome.generate_vapi(package_api_name, + sources: libproxy_gir[0], + packages: [ 'gio-2.0' ], + install: true, + install_dir: vapidir, + metadata_dirs: [ meson.current_source_dir() ], + ) + endif +endif
\ No newline at end of file diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c new file mode 100644 index 0000000..6cf7974 --- /dev/null +++ b/src/libproxy/proxy.c @@ -0,0 +1,79 @@ +/* proxy.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <gio/gio.h> + +#include "px-manager.h" +#include "proxy.h" + +struct _pxProxyFactory { + PxManager *manager; +}; + +pxProxyFactory *px_proxy_factory_copy (pxProxyFactory *self); + +G_DEFINE_BOXED_TYPE (pxProxyFactory, + px_proxy_factory, + (GBoxedCopyFunc)px_proxy_factory_copy, + (GFreeFunc)px_proxy_factory_new); + +pxProxyFactory * +px_proxy_factory_new (void) +{ + pxProxyFactory *self = g_new0 (pxProxyFactory, 1); + + self->manager = px_manager_new (); + + return self; +} + +pxProxyFactory * +px_proxy_factory_copy (pxProxyFactory *self) +{ + return g_memdup2 (self, sizeof (pxProxyFactory)); +} + +char ** +px_proxy_factory_get_proxies (pxProxyFactory *self, + const char *url) +{ + g_auto (GStrv) result = NULL; + g_autoptr (GError) error = NULL; + + result = px_manager_get_proxies_sync (self->manager, url, &error); + if (error) + g_warning ("Could not query proxy: %s", error->message); + + return g_steal_pointer (&result); +} + +void +px_proxy_factory_free_proxies (char **proxies) +{ + g_clear_pointer (&proxies, g_strfreev); +} + +void +px_proxy_factory_free (pxProxyFactory *self) +{ + g_clear_object (&self->manager); + g_clear_pointer (&self, g_free); +} diff --git a/libproxy/proxy.h b/src/libproxy/proxy.h index c620a80..cf4fc34 100644 --- a/libproxy/proxy.h +++ b/src/libproxy/proxy.h @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com> +/* proxy.h + * + * Copyright 2022-2023 The Libproxy Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -14,36 +14,55 @@ * * 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 - ******************************************************************************/ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + -#ifndef PROXY_H_ -#define PROXY_H_ +#pragma once #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif -typedef struct pxProxyFactory_ pxProxyFactory; +#include <gio/gio.h> /** - * Creates a new pxProxyFactory instance. This instance should be kept - * around as long as possible as it contains cached data to increase - * performance. Memory usage should be minimal (cache is small) and the - * cache lifespan is handled automatically. + * SECTION:px-proxy + * @short_description: A convient helper for using proxy servers + */ + +typedef struct _pxProxyFactory pxProxyFactory; + +#define PX_TYPE_PROXY_FACTORY (px_proxy_factory_get_type ()) + +/** + * px_proxy_factory_new: + * + * Creates a new `pxProxyFactory` instance. * - * @return A new pxProxyFactory instance or NULL on error + * This instance should be kept around as long as possible as it contains + * cached data to increase performance. Memory usage should be minimal + * (cache is small) and the cache lifespan is handled automatically. + * + * Returns: The newly created `pxProxyFactory` */ -pxProxyFactory *px_proxy_factory_new(void); +pxProxyFactory *px_proxy_factory_new (void); + +GType px_proxy_factory_get_type (void) G_GNUC_CONST; /** - * Get which proxies to use for the specified URL. + * px_proxy_factory_get_proxies: + * @self: a #pxProxyFactory + * @url: Get proxxies for specificed URL + * + * Get which proxies to use for the specified @URL. * - * A NULL-terminated array of proxy strings is returned. + * A %NULL-terminated array of proxy strings is returned. * If the first proxy fails, the second should be tried, etc... * Don't forget to free the strings/array when you are done. - * If an unrecoverable error occurs, this function returns NULL. + * If an unrecoverable error occurs, this function returns %NULL. * * Regarding performance: this method always blocks and may be called * in a separate thread (is thread-safe). In most cases, the time @@ -64,12 +83,19 @@ pxProxyFactory *px_proxy_factory_new(void); * performance (described above) applies. * * The format of the returned proxy strings are as follows: + * * - http://[username:password@]proxy:port + * * - socks://[username:password@]proxy:port + * * - socks5://[username:password@]proxy:port + * * - socks4://[username:password@]proxy:port + * * - <procotol>://[username:password@]proxy:port + * * - direct:// + * * Please note that the username and password in the above URLs are optional * and should be use to authenticate the connection if present. * @@ -83,29 +109,34 @@ pxProxyFactory *px_proxy_factory_new(void); * proxy protocol or the service name of the protocol being proxied if the * previous does not exist. As an example, on Mac OS X you can configure a * RTSP streaming proxy. The expected returned configuration would be: + * * - rtsp://[username:password@]proxy:port * - * To free the returned value, call px_proxy_factory_free_proxies. - * - * @url The URL we are trying to reach - * @return A NULL-terminated array of proxy strings to use + * To free the returned value, call @px_proxy_factory_free_proxies. + * + * Returns: (transfer full): a list of proxies */ -char **px_proxy_factory_get_proxies(pxProxyFactory *self, const char *url); +char **px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url); /** - * Frees the proxy array returned by px_proxy_factory_get_proxies when no + * px_proxy_factory_free_proxies + * @proxies: (array zero-terminated=1): a %NULL-terminated array of proxies + * + * Frees the proxy array returned by @px_proxy_factory_get_proxies when no * longer used. + * * @since 0.4.16 */ -void px_proxy_factory_free_proxies(char **proxies); +void px_proxy_factory_free_proxies (char **proxies); /** - * Frees the pxProxyFactory instance when no longer used. + * px_proxy_factory_free: + * @self: a #pxProxyFactory + * + * Frees the `pxProxyFactory`. */ -void px_proxy_factory_free(pxProxyFactory *self); +void px_proxy_factory_free (pxProxyFactory *self); #ifdef __cplusplus } #endif - -#endif /*PROXY_H_*/ diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..6aaf2f6 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,3 @@ +subdir('backend') +subdir('libproxy') +subdir('tools') diff --git a/src/tools/meson.build b/src/tools/meson.build new file mode 100644 index 0000000..0c0b816 --- /dev/null +++ b/src/tools/meson.build @@ -0,0 +1,11 @@ +proxy_sources = [ + 'proxy.c' +] + +executable( + 'proxy', + sources: proxy_sources, + dependencies: libproxy_dep, + install: true, + include_directories: libproxy_inc +)
\ No newline at end of file diff --git a/src/tools/proxy.c b/src/tools/proxy.c new file mode 100644 index 0000000..9a599ca --- /dev/null +++ b/src/tools/proxy.c @@ -0,0 +1,96 @@ +/* proxy.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#include "proxy.h" + +void print_proxies (char **proxies); + +/** + * Prints an array of proxies. Proxies are space separated. + * @proxies an array containing the proxies returned by libproxy. + */ +void +print_proxies (char **proxies) +{ + int j; + + if (!proxies) { + printf ("\n"); + return; + } + + for (j = 0; proxies[j]; j++) + printf ("%s%s", proxies[j], proxies[j + 1] ? " " : "\n"); +} + +int +main (int argc, + char **argv) +{ + int i; + char url[102400]; /* Should be plently long for most URLs */ + char **proxies; + + /* Create the proxy factory object */ + pxProxyFactory *pf = px_proxy_factory_new (); + if (!pf) { + fprintf (stderr, "An unknown error occurred!\n"); + return 1; + } + + /* User entered some arguments on startup. skip interactive */ + if (argc > 1) { + for (i = 1; i < argc; i++) { + /* + * Get an array of proxies to use. These should be used + * in the order returned. Only move on to the next proxy + * if the first one fails (etc). + */ + proxies = px_proxy_factory_get_proxies (pf, argv[i]); + print_proxies (proxies); + px_proxy_factory_free_proxies (proxies); + } + } + /* Interactive mode */ + else { + /* For each URL we read on STDIN, get the proxies to use */ + for (url[0] = '\0'; fgets (url, 102400, stdin) != NULL;) { + if (url[strlen (url) - 1] == '\n') url[strlen (url) - 1] = '\0'; + + /* + * Get an array of proxies to use. These should be used + * in the order returned. Only move on to the next proxy + * if the first one fails (etc). + */ + proxies = px_proxy_factory_get_proxies (pf, url); + print_proxies (proxies); + px_proxy_factory_free_proxies (proxies); + } + } + /* Destroy the proxy factory object */ + px_proxy_factory_free (pf); + return 0; +} diff --git a/subprojects/gi-docgen.wrap b/subprojects/gi-docgen.wrap new file mode 100644 index 0000000..d4796d4 --- /dev/null +++ b/subprojects/gi-docgen.wrap @@ -0,0 +1,10 @@ +[wrap-git] +directory = gi-docgen +url = https://gitlab.gnome.org/GNOME/gi-docgen.git +push-url = ssh://git@ssh.gitlab.gnome.org:GNOME/gi-docgen.git +revision = main +depth = 1 + +[provide] +program_names = gi-docgen + diff --git a/tests/config-env-test.c b/tests/config-env-test.c new file mode 100644 index 0000000..2cfc3cb --- /dev/null +++ b/tests/config-env-test.c @@ -0,0 +1,105 @@ +/* config-env-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" + +#include "px-manager-helper.h" + + +typedef struct { + const char *env; + const char *proxy; + const char *no_proxy; + const char *url; + gboolean config_is_proxy; +} ConfigEnvTest; + +static const ConfigEnvTest config_env_test_set[] = { + { "HTTP_PROXY", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE}, + { "HTTP_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", TRUE}, + { "HTTP_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE}, + { "HTTP_PROXY", "http://127.0.0.1:8080", "www.example.com", "https://www.example.com", FALSE}, + { "HTTP_PROXY", "http://127.0.0.1:8080", "www.test.com", "https://www.example.com", TRUE}, + { "HTTP_PROXY", "http://127.0.0.1:8080", "*", "https://www.example.com", FALSE}, + { "http_proxy", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE}, + { "HTTPS_PROXY", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE}, + { "HTTPS_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", FALSE}, + { "HTTPS_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", FALSE}, + { "https_proxy", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", FALSE}, + { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "https://www.example.com", FALSE}, + { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", FALSE}, + { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE}, + { "ftp_proxy", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE}, +}; + +static void +test_config_env (void) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_env_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigEnvTest test = config_env_test_set[idx]; + + /* Set proxy environment variable. Must be done before px_test_manager_new()! */ + if (!g_setenv (test.env, test.proxy, TRUE)) { + g_warning ("Could not set environment"); + continue; + } + + if (test.no_proxy) { + if (test.config_is_proxy) + g_setenv ("NO_PROXY", test.no_proxy, TRUE); + else + g_setenv ("no_proxy", test.no_proxy, TRUE); + } + + manager = px_test_manager_new ("config-env", NULL); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + config = px_manager_get_configuration (manager, uri, &error); + if (test.config_is_proxy) + g_assert_cmpstr (config[0], ==, test.proxy); + else + g_assert_cmpstr (config[0], !=, test.proxy); + + g_unsetenv (test.env); + g_unsetenv ("NO_PROXY"); + g_unsetenv ("no_proxy"); + + g_clear_object (&manager); + } +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/config/env", test_config_env); + + return g_test_run (); +} diff --git a/tests/config-gnome-test.c b/tests/config-gnome-test.c new file mode 100644 index 0000000..f80914a --- /dev/null +++ b/tests/config-gnome-test.c @@ -0,0 +1,201 @@ +/* config-gnome-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" + +#include "px-manager-helper.h" + +#include <gio/gio.h> + +typedef struct { + GSettings *proxy_settings; + GSettings *http_proxy_settings; + GSettings *https_proxy_settings; + GSettings *ftp_proxy_settings; + GSettings *socks_proxy_settings; +} Fixture; + +enum { + GNOME_PROXY_MODE_NONE = 0, + GNOME_PROXY_MODE_MANUAL, + GNOME_PROXY_MODE_AUTO +}; + +typedef struct { + int mode; + const char *proxy; + int proxy_port; + const char *url; + const char *expected_return; + gboolean success; +} ConfigGnomeTest; + +static const ConfigGnomeTest config_gnome_test_set[] = { + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "https://www.example.com", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://www.example.com", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "ftp://www.example.com", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://localhost:1234", "http://127.0.0.1:8080", TRUE}, + { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "socks://localhost:1234", "socks://127.0.0.1:8080", TRUE}, +}; + +static void +fixture_setup (Fixture *self, + gconstpointer data) +{ + self->proxy_settings = g_settings_new ("org.gnome.system.proxy"); + self->http_proxy_settings = g_settings_new ("org.gnome.system.proxy.http"); + self->https_proxy_settings = g_settings_new ("org.gnome.system.proxy.https"); + self->ftp_proxy_settings = g_settings_new ("org.gnome.system.proxy.ftp"); + self->socks_proxy_settings = g_settings_new ("org.gnome.system.proxy.socks"); +} + +static void +fixture_teardown (Fixture *fixture, + gconstpointer data) +{ +} + +static void +test_config_gnome_manual (Fixture *self, + const void *user_data) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_gnome_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigGnomeTest test = config_gnome_test_set[idx]; + + g_settings_set_strv (self->proxy_settings, "ignore-hosts", NULL); + g_settings_set_enum (self->proxy_settings, "mode", test.mode); + g_settings_set_string (self->http_proxy_settings, "host", test.proxy); + g_settings_set_int (self->http_proxy_settings, "port", test.proxy_port); + g_settings_set_string (self->https_proxy_settings, "host", test.proxy); + g_settings_set_int (self->https_proxy_settings, "port", test.proxy_port); + g_settings_set_string (self->ftp_proxy_settings, "host", test.proxy); + g_settings_set_int (self->ftp_proxy_settings, "port", test.proxy_port); + g_settings_set_string (self->socks_proxy_settings, "host", test.proxy); + g_settings_set_int (self->socks_proxy_settings, "port", test.proxy_port); + + manager = px_test_manager_new ("config-gnome", NULL); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + g_assert_cmpstr (config[0], ==, test.expected_return); + + g_clear_object (&manager); + } +} + +static void +test_config_gnome_manual_auth (Fixture *self, + const void *user_data) +{ + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + + g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_MANUAL); + g_settings_set_string (self->http_proxy_settings, "host", "127.0.0.1"); + g_settings_set_int (self->http_proxy_settings, "port", 9876); + g_settings_set_boolean (self->http_proxy_settings, "use-authentication", TRUE); + g_settings_set_string (self->http_proxy_settings, "authentication-user", "test"); + g_settings_set_string (self->http_proxy_settings, "authentication-password", "pwd"); + + manager = px_test_manager_new ("config-gnome", NULL); + g_clear_error (&error); + + uri = g_uri_parse ("http://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); + + config = px_manager_get_configuration (manager, uri, &error); + g_assert_cmpstr (config[0], ==, "http://test:pwd@127.0.0.1:9876"); +} + +static void +test_config_gnome_auto (Fixture *self, + const void *user_data) +{ + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_auto (GStrv) config = NULL; + g_autoptr (GUri) uri = NULL; + + manager = px_test_manager_new ("config-gnome", NULL); + g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO); + g_settings_set_string (self->proxy_settings, "autoconfig-url", ""); + + uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); + config = px_manager_get_configuration (manager, uri, &error); + g_assert_cmpstr (config[0], ==, "wpad://"); + + g_settings_set_string (self->proxy_settings, "autoconfig-url", "http://127.0.0.1:3435"); + config = px_manager_get_configuration (manager, uri, &error); + g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1:3435"); +} + +static void +test_config_gnome_fail (Fixture *self, + const void *user_data) +{ + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_auto (GStrv) config = NULL; + g_autoptr (GUri) uri = NULL; + + /* Disable GNOME support */ + if (!g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE)) { + g_warning ("Could not set XDG_CURRENT_DESKTOP environment, abort"); + return; + } + + manager = px_test_manager_new ("config-gnome", NULL); + g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO); + g_settings_set_string (self->proxy_settings, "autoconfig-url", ""); + + uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); + config = px_manager_get_configuration (manager, uri, &error); + g_assert_null (config[0]); +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE); + + g_test_add ("/config/gnome/manual", Fixture, NULL, fixture_setup, test_config_gnome_manual, fixture_teardown); + g_test_add ("/config/gnome/manual_auth", Fixture, NULL, fixture_setup, test_config_gnome_manual_auth, fixture_teardown); + g_test_add ("/config/gnome/auto", Fixture, NULL, fixture_setup, test_config_gnome_auto, fixture_teardown); + g_test_add ("/config/gnome/fail", Fixture, NULL, fixture_setup, test_config_gnome_fail, fixture_teardown); + + return g_test_run (); +} diff --git a/tests/config-kde-test.c b/tests/config-kde-test.c new file mode 100644 index 0000000..5129384 --- /dev/null +++ b/tests/config-kde-test.c @@ -0,0 +1,215 @@ +/* config-kde-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" + +#include "px-manager-helper.h" + + +typedef struct { + const char *url; + const char *proxy; + gboolean success; +} ConfigKdeTest; + +static const ConfigKdeTest config_kde_manual_test_set[] = { + { "https://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "http://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "ftp://www.example.com", "ftp://127.0.0.1:8080", TRUE}, + { "socks://www.example.com", "socks://127.0.0.1:8080", TRUE}, + { "http://localhost:1234", "http://127.0.0.1:8080", FALSE}, + { "socks://localhost:1234", "http://127.0.0.1:8080", FALSE}, + { "socks://localhost:1234", "socks://127.0.0.1:8080", FALSE}, +}; + +static const ConfigKdeTest config_kde_wpad_test_set[] = { + { "https://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "http://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "ftp://www.example.com", "ftp://127.0.0.1:8080", TRUE}, + { "http://localhost:1234", "http://127.0.0.1:8080", FALSE}, +}; + +static const ConfigKdeTest config_kde_pac_test_set[] = { + { "https://www.example.com", "http://127.0.0.1:8080", TRUE}, +}; + +static void +test_config_kde_disabled (void) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_kde_manual_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigKdeTest test = config_kde_manual_test_set[idx]; + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-disabled", NULL); + + manager = px_test_manager_new ("config-kde", path); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + g_assert_cmpstr (config[0], !=, test.proxy); + + g_clear_object (&manager); + } +} + +static void +test_config_kde_manual (void) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_kde_manual_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigKdeTest test = config_kde_manual_test_set[idx]; + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-manual", NULL); + + manager = px_test_manager_new ("config-kde", path); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + if (test.success) + g_assert_cmpstr (config[0], ==, test.proxy); + else + g_assert_cmpstr (config[0], !=, test.proxy); + + g_clear_object (&manager); + } +} + +static void +test_config_kde_wpad (void) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_kde_wpad_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigKdeTest test = config_kde_wpad_test_set[idx]; + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-wpad", NULL); + + manager = px_test_manager_new ("config-kde", path); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + if (test.success) + g_assert_cmpstr (config[0], ==, "wpad://"); + else + g_assert_cmpstr (config[0], !=, "wpad://"); + + g_clear_object (&manager); + } +} + +static void +test_config_kde_pac (void) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_kde_pac_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigKdeTest test = config_kde_pac_test_set[idx]; + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL); + + manager = px_test_manager_new ("config-kde", path); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + if (test.success) + g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1/test.pac"); + else + g_assert_cmpstr (config[0], !=, "pac+http://127.0.0.1/test.pac"); + + g_clear_object (&manager); + } +} + +static void +test_config_kde_fail (void) +{ + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL); + + /* Disable KDE support */ + g_setenv ("XDG_CURRENT_DESKTOP", "SOMETHING_ELSE", TRUE); + + manager = px_test_manager_new ("config-kde", path); + + uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); + + config = px_manager_get_configuration (manager, uri, &error); + g_print ("%s", config[0]); + g_assert_null (config[0]); +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_setenv ("XDG_CURRENT_DESKTOP", "KDE", TRUE); + + g_test_add_func ("/config/kde/disabled", test_config_kde_disabled); + g_test_add_func ("/config/kde/manual", test_config_kde_manual); + g_test_add_func ("/config/kde/wpad", test_config_kde_wpad); + g_test_add_func ("/config/kde/pac", test_config_kde_pac); + g_test_add_func ("/config/kde/fail", test_config_kde_fail); + + return g_test_run (); +} diff --git a/tests/config-osx-test.c b/tests/config-osx-test.c new file mode 100644 index 0000000..cdb8a72 --- /dev/null +++ b/tests/config-osx-test.c @@ -0,0 +1,52 @@ +/* config-osx-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" + +#include "px-manager-helper.h" + +static void +test_config_osx (void) +{ + g_autoptr (GError) error = NULL; + g_autoptr (PxManager) manager = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + + manager = px_test_manager_new ("config-osx", NULL); + g_clear_error (&error); + + uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); + config = px_manager_get_configuration (manager, uri, &error); + g_assert_nonnull (config); + g_assert_null (config[0]); +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/config/osx", test_config_osx); + + return g_test_run (); +} diff --git a/tests/config-sysconfig-test.c b/tests/config-sysconfig-test.c new file mode 100644 index 0000000..40c0b92 --- /dev/null +++ b/tests/config-sysconfig-test.c @@ -0,0 +1,80 @@ +/* config-sysconfig-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" + +#include "px-manager-helper.h" + +typedef struct { + const char *url; + const char *proxy; + gboolean success; +} ConfigSysConfigTest; + +static const ConfigSysConfigTest config_sysconfig_test_set[] = { + { "https://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "http://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "ftp://www.example.com", "http://127.0.0.1:8080", TRUE}, + { "http://localhost:1234", "http://127.0.0.1:8080", FALSE}, +}; + +static void +test_config_sysconfig (void) +{ + int idx; + + for (idx = 0; idx < G_N_ELEMENTS (config_sysconfig_test_set); idx++) { + g_autoptr (PxManager) manager = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + ConfigSysConfigTest test = config_sysconfig_test_set[idx]; + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy", NULL); + + manager = px_test_manager_new ("config-sysconfig", path); + g_clear_error (&error); + + uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); + if (!uri) { + g_warning ("Could not parse url '%s': %s", test.url, error ? error->message : ""); + g_assert_not_reached (); + } + + config = px_manager_get_configuration (manager, uri, &error); + if (test.success) + g_assert_cmpstr (config[0], ==, test.proxy); + else + g_assert_cmpstr (config[0], !=, test.proxy); + + g_clear_object (&manager); + } +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/config/sysconfig", test_config_sysconfig); + + return g_test_run (); +} diff --git a/tests/config-windows-test.c b/tests/config-windows-test.c new file mode 100644 index 0000000..10d4b21 --- /dev/null +++ b/tests/config-windows-test.c @@ -0,0 +1,52 @@ +/* config-windows-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" + +#include "px-manager-helper.h" + +static void +test_config_windows (void) +{ + g_autoptr (GError) error = NULL; + g_autoptr (PxManager) manager = NULL; + g_autoptr (GUri) uri = NULL; + g_auto (GStrv) config = NULL; + + manager = px_test_manager_new ("config-windows", NULL); + g_clear_error (&error); + + uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); + config = px_manager_get_configuration (manager, uri, &error); + g_assert_nonnull (config); + g_assert_nonnull (config[0]); +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/config/windows", test_config_windows); + + return g_test_run (); +} diff --git a/tests/data/px-manager-direct b/tests/data/px-manager-direct new file mode 100644 index 0000000..72c4ac8 --- /dev/null +++ b/tests/data/px-manager-direct @@ -0,0 +1 @@ +PROXY_ENABLED="no"
\ No newline at end of file diff --git a/tests/data/px-manager-nonpac b/tests/data/px-manager-nonpac new file mode 100644 index 0000000..7db21d8 --- /dev/null +++ b/tests/data/px-manager-nonpac @@ -0,0 +1,5 @@ +PROXY_ENABLED="yes" +HTTP_PROXY="http://127.0.0.1:1983" +HTTPS_PROXY="http://127.0.0.1:1983" +FTP_PROXY="http://127.0.0.1:1983" +NO_PROXY="localhost, 127.0.0.1" diff --git a/tests/data/px-manager-pac b/tests/data/px-manager-pac new file mode 100644 index 0000000..2ff4000 --- /dev/null +++ b/tests/data/px-manager-pac @@ -0,0 +1,5 @@ +PROXY_ENABLED="yes" +HTTP_PROXY="pac+http://127.0.0.1:1983/test.pac" +HTTPS_PROXY="pac+http://127.0.0.1:1983/test.pac" +FTP_PROXY="pac+http://127.0.0.1:1983/test.pac" +NO_PROXY="localhost, 127.0.0.1" diff --git a/tests/data/px-manager-sample.pac b/tests/data/px-manager-sample.pac new file mode 100644 index 0000000..d623f22 --- /dev/null +++ b/tests/data/px-manager-sample.pac @@ -0,0 +1,27 @@ +function FindProxyForURL(url, host) +{ + var resolved_ip = dnsResolve(host); + var myIP = myIpAddress(); + var privateIP = /^(0|10|127|192\.168|172\.1[6789]|172\.2[0-9]|172\.3[01]|169\.254|192\.88\.99)\.[0-9.]+$/; + + if (shExpMatch(host, "192.168.10.4")) + return "SOCKS 127.0.0.1:1983" + + if (dnsDomainIs(host, "192.168.10.5")) + return "SOCKS4 127.0.0.1:1983" + + if (dnsDomainIs(host, "192.168.10.6")) + return "SOCKS4A 127.0.0.1:1983" + + if (dnsDomainIs(host, "192.168.10.7")) + return "SOCKS5 127.0.0.1:1983" + + /* Don't send non-FQDN or private IP auths to us */ + if (isPlainHostName(host) || isInNet(resolved_ip, "192.0.2.0","255.255.255.0") || privateIP.test(resolved_ip)) + return "DIRECT"; + + if (dnsDomainIs(host, "www.example.com")) + return "PROXY 127.0.0.1:1983" + + return "PROXY 127.0.0.1:1981" +} diff --git a/tests/data/px-manager-wpad b/tests/data/px-manager-wpad new file mode 100644 index 0000000..4ab0f81 --- /dev/null +++ b/tests/data/px-manager-wpad @@ -0,0 +1,5 @@ +PROXY_ENABLED="yes" +HTTP_PROXY="wpad://" +HTTPS_PROXY="wpad://" +FTP_PROXY="wpad://" +NO_PROXY="localhost, 127.0.0.1" diff --git a/tests/data/sample-kde-proxy-disabled b/tests/data/sample-kde-proxy-disabled new file mode 100644 index 0000000..9598abd --- /dev/null +++ b/tests/data/sample-kde-proxy-disabled @@ -0,0 +1,11 @@ +ProxyUrlDisplayFlags=15 + +[Proxy Settings] +NoProxyFor=localhost,127.0.0.1 +Proxy Config Script=http://127.0.0.1/test.pac +ProxyType=0 +ReversedException=false +ftpProxy=ftp://127.0.0.1 8080 +httpProxy=http://127.0.0.1 8080 +httpsProxy=http://127.0.0.1 8080 +socksProxy=socks://127.0.0.1 8080
\ No newline at end of file diff --git a/tests/data/sample-kde-proxy-manual b/tests/data/sample-kde-proxy-manual new file mode 100644 index 0000000..c0a293b --- /dev/null +++ b/tests/data/sample-kde-proxy-manual @@ -0,0 +1,11 @@ +ProxyUrlDisplayFlags=15 + +[Proxy Settings] +NoProxyFor=localhost,127.0.0.1 +Proxy Config Script= +ProxyType=1 +ReversedException=false +ftpProxy=ftp://127.0.0.1 8080 +httpProxy=http://127.0.0.1 8080 +httpsProxy=http://127.0.0.1 8080 +socksProxy=socks://127.0.0.1 8080
\ No newline at end of file diff --git a/tests/data/sample-kde-proxy-pac b/tests/data/sample-kde-proxy-pac new file mode 100644 index 0000000..c0db824 --- /dev/null +++ b/tests/data/sample-kde-proxy-pac @@ -0,0 +1,11 @@ +ProxyUrlDisplayFlags=15 + +[Proxy Settings] +NoProxyFor=localhost,127.0.0.1 +Proxy Config Script=http://127.0.0.1/test.pac +ProxyType=2 +ReversedException=false +ftpProxy=ftp://127.0.0.1 8080 +httpProxy=http://127.0.0.1 8080 +httpsProxy=http://127.0.0.1 8080 +socksProxy=socks://127.0.0.1 8080
\ No newline at end of file diff --git a/tests/data/sample-kde-proxy-wpad b/tests/data/sample-kde-proxy-wpad new file mode 100644 index 0000000..6eb1547 --- /dev/null +++ b/tests/data/sample-kde-proxy-wpad @@ -0,0 +1,11 @@ +ProxyUrlDisplayFlags=15 + +[Proxy Settings] +NoProxyFor=localhost,127.0.0.1 +Proxy Config Script= +ProxyType=3 +ReversedException=false +ftpProxy=ftp://127.0.0.1 8080 +httpProxy=http://127.0.0.1 8080 +httpsProxy=http://127.0.0.1 8080 +socksProxy=socks://127.0.0.1 8080
\ No newline at end of file diff --git a/tests/data/sample-sysconfig-proxy b/tests/data/sample-sysconfig-proxy new file mode 100644 index 0000000..1318f21 --- /dev/null +++ b/tests/data/sample-sysconfig-proxy @@ -0,0 +1,6 @@ +PROXY_ENABLED="yes" +HTTP_PROXY="http://127.0.0.1:8080" +HTTPS_PROXY="http://127.0.0.1:8080" +FTP_PROXY="http://127.0.0.1:8080" +NO_PROXY="localhost, 127.0.0.1" +USELESS_OPTION=""
\ No newline at end of file diff --git a/tests/libproxy-test.c b/tests/libproxy-test.c new file mode 100644 index 0000000..00aac45 --- /dev/null +++ b/tests/libproxy-test.c @@ -0,0 +1,74 @@ +/* libproxy-test.c + * + * Copyright 2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "proxy.h" + +#include <gio/gio.h> + +typedef struct { + pxProxyFactory *pf; +} Fixture; + +static void +fixture_setup (Fixture *self, + gconstpointer data) +{ + self->pf = px_proxy_factory_new (); +} + +static void +fixture_teardown (Fixture *fixture, + gconstpointer data) +{ + px_proxy_factory_free (fixture->pf); +} + +static void +test_libproxy_setup (Fixture *self, + const void *user_data) +{ + char **proxies = NULL; + + proxies = px_proxy_factory_get_proxies (self->pf, "https://www.example.com"); + g_assert_nonnull (proxies); + g_assert_nonnull (proxies[0]); + px_proxy_factory_free_proxies (proxies); + + return; + + /* FIXME: Fails on Windows */ + /* g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Could not query proxy: URI is not absolute, and no base URI was provided"); */ + /* proxies = px_proxy_factory_get_proxies (self->pf, "http_unknown://www.example.com"); */ + /* g_assert_nonnull (proxies); */ + /* g_assert_nonnull (proxies[0]); */ + /* px_proxy_factory_free_proxies (proxies); */ +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add ("/libproxy/setup", Fixture, NULL, fixture_setup, test_libproxy_setup, fixture_teardown); + + return g_test_run (); +} diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..4ae8e7d --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,103 @@ +if get_option('tests') + envs = [ + 'G_TEST_SRCDIR=' + meson.current_source_dir(), + 'G_TEST_BUILDDIR=' + meson.current_build_dir(), + 'GSETTINGS_BACKEND=memory', + ] + + test_cargs = ['-UG_DISABLE_ASSERT'] + + libproxy_test = executable('test-libproxy', + ['libproxy-test.c'], + include_directories: libproxy_inc, + dependencies: [libproxy_dep], + ) + test('Libproxy test', + libproxy_test, + env: envs + ) + + if soup_dep.found() + px_manager_test = executable('test-px-manager', + ['px-manager-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [soup_dep, glib_dep, px_backend_dep], + ) + test('PX Manager test', + px_manager_test, + env: envs + ) + endif + + if get_option('config-env') + config_env_test = executable('test-config-env', + ['config-env-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config Environment test', + config_env_test, + env: envs + ) + endif + + if get_option('config-sysconfig') + config_sysconfig_test = executable('test-config-sysconfig', + ['config-sysconfig-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config sysconfig test', + config_sysconfig_test, + env: envs + ) + endif + + if get_option('config-gnome') + config_gnome_test = executable('test-config-gnome', + ['config-gnome-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config GNOME test', + config_gnome_test, + env: [envs, 'XDG_CURRENT_DESKTOP=GNOME'], + ) + endif + + if get_option('config-kde') + config_kde_test = executable('test-config-kde', + ['config-kde-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config KDE test', + config_kde_test, + env: [envs, 'XDG_CURRENT_DESKTOP=KDE'], + ) + endif + + if get_option('config-osx') and with_platform_darwin + config_osx_test = executable('test-config-osx', + ['config-osx-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config OSX test', + config_osx_test, + env: [envs], + ) + endif + + if get_option('config-windows') and with_platform_windows + config_windows_test = executable('test-config-windows', + ['config-windows-test.c', 'px-manager-helper.c'], + include_directories: px_backend_inc, + dependencies: [glib_dep, px_backend_dep], + ) + test('Config Windows test', + config_windows_test, + env: [envs], + ) + endif +endif diff --git a/tests/px-manager-helper.c b/tests/px-manager-helper.c new file mode 100644 index 0000000..e3129a2 --- /dev/null +++ b/tests/px-manager-helper.c @@ -0,0 +1,31 @@ +/* px-manager-helper.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" +#include "px-manager-helper.h" + +PxManager * +px_test_manager_new (const char *config_plugin, const char *config_option) +{ + return px_manager_new_with_options ("config-plugin", config_plugin, + "config-option", config_option, + NULL); +} diff --git a/tests/px-manager-helper.h b/tests/px-manager-helper.h new file mode 100644 index 0000000..2717448 --- /dev/null +++ b/tests/px-manager-helper.h @@ -0,0 +1,24 @@ +/* px-manager-helper.h + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +PxManager *px_test_manager_new (const char *config_plugin, const char *config_option); diff --git a/tests/px-manager-test.c b/tests/px-manager-test.c new file mode 100644 index 0000000..bfd3112 --- /dev/null +++ b/tests/px-manager-test.c @@ -0,0 +1,314 @@ +/* px-manager-test.c + * + * Copyright 2022-2023 The Libproxy Team + * + * 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 + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "px-manager.h" +#include "px-manager-helper.h" + +#include <libsoup/soup.h> + +#define SERVER_PORT 1983 + +typedef struct { + GMainLoop *loop; + PxManager *manager; +} Fixture; + +static void +server_callback (SoupServer *server, + SoupServerMessage *msg, + const char *path, + GHashTable *query, + gpointer data) +{ + g_print ("%s: path %s\n", __FUNCTION__, path); + soup_server_message_set_status (SOUP_SERVER_MESSAGE (msg), SOUP_STATUS_OK, NULL); + + if (g_strcmp0 (path, "/test.pac") == 0) { + g_autofree char *pac = g_test_build_filename (G_TEST_DIST, "data", "px-manager-sample.pac", NULL); + g_autofree char *pac_data = NULL; + g_autoptr (GError) error = NULL; + gsize len; + + if (!g_file_get_contents (pac, &pac_data, &len, &error)) { + g_warning ("Could not read pac file: %s", error ? error->message : ""); + return; + } + soup_server_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY, pac_data, len); + } +} + +static void +fixture_setup (Fixture *fixture, + gconstpointer data) +{ + g_autofree char *path = NULL; + + fixture->loop = g_main_loop_new (NULL, FALSE); + + if (data) + path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); + + fixture->manager = px_test_manager_new ("config-sysconfig", path); +} + +static void +fixture_teardown (Fixture *fixture, + gconstpointer data) +{ + g_clear_object (&fixture->manager); +} + +static gpointer +download_pac (gpointer data) +{ + Fixture *self = data; + GBytes *pac; + + pac = px_manager_pac_download (self->manager, "http://127.0.0.1:1983/test.pac"); + g_assert_nonnull (pac); + + g_main_loop_quit (self->loop); + + return NULL; +} + +static void +test_pac_download (Fixture *self, + const void *user_data) +{ + g_autoptr (GThread) thread = NULL; + + thread = g_thread_new ("test", (GThreadFunc)download_pac, self); + g_main_loop_run (self->loop); +} + +static void +test_get_proxies_direct (Fixture *self, + const void *user_data) +{ + g_auto (GStrv) config = NULL; + + config = px_manager_get_proxies_sync (self->manager, "", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "direct://"); + + config = px_manager_get_proxies_sync (self->manager, "nonsense", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "direct://"); + + config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "direct://"); +} + +static void +test_get_proxies_nonpac (Fixture *self, + const void *user_data) +{ + g_auto (GStrv) config = NULL; + + config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "http://127.0.0.1:1983"); +} + +static gpointer +get_proxies_pac (gpointer data) +{ + Fixture *self = data; + g_auto (GStrv) config = NULL; + + config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "http://127.0.0.1:1983"); + + config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.4", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "socks://127.0.0.1:1983"); + + config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.5", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "socks4://127.0.0.1:1983"); + + config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.6", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "socks4a://127.0.0.1:1983"); + + config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.7", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "socks5://127.0.0.1:1983"); + + g_main_loop_quit (self->loop); + + return NULL; +} + +static void +test_get_proxies_pac (Fixture *self, + const void *user_data) +{ + g_autoptr (GThread) thread = NULL; + + thread = g_thread_new ("test", (GThreadFunc)get_proxies_pac, self); + g_main_loop_run (self->loop); +} + +static gpointer +get_wpad (gpointer data) +{ + Fixture *self = data; + g_auto (GStrv) config = NULL; + + config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "direct://"); + + g_main_loop_quit (self->loop); + + return NULL; +} + +static void +test_get_wpad (Fixture *self, + const void *user_data) +{ + g_autoptr (GThread) thread = NULL; + + thread = g_thread_new ("test", (GThreadFunc)get_wpad, self); + g_main_loop_run (self->loop); +} + +static void +test_ignore_domain (Fixture *self, + const void *user_data) +{ + g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12", G_URI_FLAGS_PARSE_RELAXED, NULL); + char **ignore_list = g_malloc0 (sizeof (char *) * 2); + gboolean ret; + + /* Invalid test */ + ignore_list[0] = g_strdup ("10.10.1.13"); + ignore_list[1] = NULL; + + ret = px_manager_is_ignore (uri, ignore_list); + g_assert_false (ret); + + /* Valid test */ + ignore_list[0] = g_strdup ("10.10.1.12"); + ignore_list[1] = NULL; + + ret = px_manager_is_ignore (uri, ignore_list); + g_assert_true (ret); + + g_free (ignore_list[0]); + g_free (ignore_list); +} + +static void +test_ignore_domain_port (Fixture *self, + const void *user_data) +{ + g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12:22", G_URI_FLAGS_PARSE_RELAXED, NULL); + char **ignore_list = g_malloc0 (sizeof (char *) * 2); + gboolean ret; + + /* Invalid test */ + ignore_list[0] = g_strdup ("10.10.1.13"); + ignore_list[1] = NULL; + + ret = px_manager_is_ignore (uri, ignore_list); + g_free (ignore_list[0]); + g_assert_false (ret); + + /* Invalid test */ + ignore_list[0] = g_strdup ("10.10.1.12:24"); + ignore_list[1] = NULL; + + ret = px_manager_is_ignore (uri, ignore_list); + g_free (ignore_list[0]); + g_assert_false (ret); + + /* Valid test */ + ignore_list[0] = g_strdup ("10.10.1.12:22"); + ignore_list[1] = NULL; + + ret = px_manager_is_ignore (uri, ignore_list); + g_assert_true (ret); + + g_free (ignore_list[0]); + g_free (ignore_list); +} + +static void +test_ignore_hostname (Fixture *self, + const void *user_data) +{ + g_autoptr (GUri) uri = g_uri_parse("http://18.10.1.12", G_URI_FLAGS_PARSE_RELAXED, NULL); + char **ignore_list = g_malloc0 (sizeof (char *) * 2); + gboolean ret; + + /* Invalid test */ + ignore_list[0] = g_strdup ("<local>"); + ignore_list[1] = NULL; + + ret = px_manager_is_ignore (uri, ignore_list); + g_assert_false (ret); + g_uri_unref (uri); + + /* Valid test */ + uri = g_uri_parse("http://127.0.0.1", G_URI_FLAGS_PARSE_RELAXED, NULL); + ret = px_manager_is_ignore (uri, ignore_list); + g_assert_false (ret); + + g_free (ignore_list[0]); + g_free (ignore_list); +} + +int +main (int argc, + char **argv) +{ + SoupServer *server = NULL; + g_autoptr (GError) error = NULL; + + g_test_init (&argc, &argv, NULL); + + server = soup_server_new (NULL, NULL); + if (!soup_server_listen_local (server, SERVER_PORT, SOUP_SERVER_LISTEN_IPV4_ONLY, &error)) { + g_warning ("Could not create local server: %s", error ? error->message : ""); + return -1; + } + + soup_server_add_handler (server, NULL, server_callback, NULL, NULL); + + g_test_add ("/pac/download", Fixture, "px-manager-direct", fixture_setup, test_pac_download, fixture_teardown); + g_test_add ("/pac/get_proxies_direct", Fixture, "px-manager-direct", fixture_setup, test_get_proxies_direct, fixture_teardown); + g_test_add ("/pac/get_proxies_nonpac", Fixture, "px-manager-nonpac", fixture_setup, test_get_proxies_nonpac, fixture_teardown); + g_test_add ("/pac/get_proxies_pac", Fixture, "px-manager-pac", fixture_setup, test_get_proxies_pac, fixture_teardown); + g_test_add ("/pac/wpad", Fixture, "px-manager-wpad", fixture_setup, test_get_wpad, fixture_teardown); + + g_test_add ("/ignore/domain", Fixture, "px-manager-ignore", fixture_setup, test_ignore_domain, fixture_teardown); + g_test_add ("/ignore/domain_port", Fixture, "px-manager-ignore", fixture_setup, test_ignore_domain_port, fixture_teardown); + g_test_add ("/ignore/hostname", Fixture, "px-manager-ignore", fixture_setup, test_ignore_hostname, fixture_teardown); + + return g_test_run (); +} + diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt deleted file mode 100644 index 53cf0c0..0000000 --- a/utils/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -include_directories("../libproxy") - -add_executable(proxy proxy.c) -target_link_libraries(proxy libproxy) -install(TARGETS proxy RUNTIME DESTINATION ${BIN_INSTALL_DIR})
\ No newline at end of file diff --git a/utils/proxy.c b/utils/proxy.c deleted file mode 100644 index cfb0f9c..0000000 --- a/utils/proxy.c +++ /dev/null @@ -1,105 +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 <stdio.h> -#include <stdlib.h> -#include <assert.h> -#include <string.h> - -/* Import libproxy API */ -#include <proxy.h> - -void * -malloc0(size_t s) -{ - void *tmp = malloc(s); - if (!tmp) return NULL; - memset(tmp, '\0', s); - return tmp; -} - -/** - * Prints an array of proxies. Proxies are space separated. - * @proxies an array containing the proxies returned by libproxy. - */ -void -print_proxies(char **proxies) -{ - int j; - - if (!proxies) { - printf("\n"); - return; - } - - for (j=0; proxies[j] ; j++) - printf("%s%s", proxies[j], proxies[j+1] ? " " : "\n"); -} - -int -main(int argc, char **argv) -{ - int i; - char url[102400]; // Should be plently long for most URLs - char **proxies; - - /* Create the proxy factory object */ - pxProxyFactory *pf = px_proxy_factory_new(); - if (!pf) - { - fprintf(stderr, "An unknown error occurred!\n"); - return 1; - } - /* User entered some arguments on startup. skip interactive */ - if (argc > 1) - { - for (i=1; i < argc ; i++) - { - /* - * Get an array of proxies to use. These should be used - * in the order returned. Only move on to the next proxy - * if the first one fails (etc). - */ - proxies = px_proxy_factory_get_proxies(pf, argv[i]); - print_proxies(proxies); - px_proxy_factory_free_proxies(proxies); - } - } - /* Interactive mode */ - else - { - /* For each URL we read on STDIN, get the proxies to use */ - for (url[0] = '\0' ; fgets(url, 102400, stdin) != NULL ; ) - { - if (url[strlen(url)-1] == '\n') url[strlen(url)-1] = '\0'; - - /* - * Get an array of proxies to use. These should be used - * in the order returned. Only move on to the next proxy - * if the first one fails (etc). - */ - proxies = px_proxy_factory_get_proxies(pf, url); - print_proxies(proxies); - px_proxy_factory_free_proxies(proxies); - } - } - /* Destroy the proxy factory object */ - px_proxy_factory_free(pf); - return 0; -} |