From 3e06882f03afd7020da050902169b9e81fa23163 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 27 Mar 2023 16:27:37 +0200 Subject: Remove all existing code --- .cproject | 1307 --------------------- .gitignore | 23 - .project | 111 -- .travis.yml | 46 - AUTHORS | 5 - CMakeLists.txt | 56 - COPYING | 502 -------- ChangeLog | 162 --- INSTALL | 158 --- NEWS | 233 ---- README | 4 - autogen.sh | 3 - bindings/CMakeLists.txt | 30 - bindings/csharp/AssemblyInfo.cs | 33 - bindings/csharp/CMakeLists.txt | 14 - bindings/csharp/libproxy-sharp-1.0.pc.cmake | 5 - bindings/csharp/libproxy.cs | 81 -- bindings/csharp/libproxy.snk | Bin 596 -> 0 bytes bindings/perl/CMakeLists.txt | 49 - bindings/perl/lib/CMakeLists.txt | 2 - bindings/perl/lib/Libproxy.pm | 75 -- bindings/perl/src/CMakeLists.txt | 25 - bindings/perl/src/Libproxy.xs | 98 -- bindings/perl/src/doxsubpp.pl | 23 - bindings/perl/src/typemap | 2 - bindings/perl/t/CMakeLists.txt | 2 - bindings/perl/t/Libproxy.t | 15 - bindings/python/libproxy.py | 145 --- bindings/python/python2/CMakeLists.txt | 25 - bindings/python/python3/CMakeLists.txt | 25 - bindings/ruby/Libproxy.i | 21 - bindings/ruby/extconf.rb | 3 - bindings/ruby/test.rb | 7 - bindings/vala/libproxy-1.0.vapi | 10 - cmake/CMakeCSharpCompiler.cmake.in | 10 - cmake/CMakeCSharpInformation.cmake | 379 ------ cmake/CMakeDetermineCSharpCompiler.cmake | 102 -- cmake/CMakeTestCSharpCompiler.cmake | 2 - cmake/FindMono.cmake | 37 - cmake/FindPython2Interp.cmake | 162 --- cmake/FindPython3Interp.cmake | 162 --- cmake/cpack.cmk | 21 - cmake/ctest.cmk | 8 - cmake/mingw32.cmake | 19 - cmake/paths.cmk | 17 - doc/libproxy_files.dia | Bin 5192 -> 0 bytes libmodman/CMakeLists.txt | 19 - libmodman/module.hpp | 113 -- libmodman/module_manager.cpp | 330 ------ libmodman/module_manager.hpp | 86 -- libmodman/test/CMakeLists.txt | 79 -- libmodman/test/builtin.cpp | 28 - libmodman/test/main.cpp | 72 -- libmodman/test/main.hpp | 43 - libmodman/test/module.cpp.in | 24 - libproxy.spec.in | 398 ------- libproxy/CMakeLists.txt | 23 - libproxy/Findlibproxy.cmake.in | 26 - libproxy/cmake/devfiles.cmk | 23 - libproxy/cmake/libproxy.cmk | 34 - libproxy/cmake/modules.cmk | 56 - libproxy/cmake/modules/config_envvar.cmk | 3 - libproxy/cmake/modules/config_gnome.cmk | 22 - libproxy/cmake/modules/config_kde.cmk | 4 - libproxy/cmake/modules/config_macosx.cmk | 10 - libproxy/cmake/modules/config_pacrunner.cmk | 3 - libproxy/cmake/modules/config_sysconfig.cmk | 8 - libproxy/cmake/modules/network_networkmanager.cmk | 6 - libproxy/cmake/modules/pacrunner_duktape.cmk | 31 - libproxy/cmake/modules/pacrunner_mozjs.cmk | 26 - libproxy/cmake/modules/pacrunner_natus.cmk | 7 - libproxy/cmake/modules/pacrunner_webkit.cmk | 26 - libproxy/cmake/pkgconfig.cmk | 23 - libproxy/cmake/pxmodule.cmk | 30 - libproxy/config.hpp | 52 - libproxy/extension_config.cpp | 41 - libproxy/extension_config.hpp | 51 - libproxy/extension_ignore.hpp | 38 - libproxy/extension_network.hpp | 37 - libproxy/extension_pacrunner.cpp | 33 - libproxy/extension_pacrunner.hpp | 63 - libproxy/extension_wpad.cpp | 23 - libproxy/extension_wpad.hpp | 45 - libproxy/libproxy-1.0.pc.in | 10 - libproxy/libproxy.map | 7 - libproxy/modules/config_envvar.cpp | 74 -- libproxy/modules/config_gnome.cpp | 307 ----- libproxy/modules/config_gnome3.cpp | 311 ----- libproxy/modules/config_kde.cpp | 266 ----- libproxy/modules/config_macosx.cpp | 171 --- libproxy/modules/config_pacrunner.cpp | 172 --- libproxy/modules/config_sysconfig.cpp | 173 --- libproxy/modules/config_w32reg.cpp | 174 --- libproxy/modules/ignore_domain.cpp | 59 - libproxy/modules/ignore_hostname.cpp | 36 - libproxy/modules/ignore_ip.cpp | 188 --- libproxy/modules/network_networkmanager.cpp | 98 -- libproxy/modules/pacrunner_duktape.cpp | 149 --- libproxy/modules/pacrunner_mozjs.cpp | 208 ---- libproxy/modules/pacrunner_natus.cpp | 114 -- libproxy/modules/pacrunner_webkit.cpp | 182 --- libproxy/modules/pacutils.h | 242 ---- libproxy/modules/pxgconf.cpp | 194 --- libproxy/modules/pxgsettings.cpp | 178 --- libproxy/modules/wpad_dns_alias.cpp | 54 - libproxy/proxy.cpp | 500 -------- libproxy/proxy.h | 111 -- libproxy/test/CMakeLists.txt | 26 - libproxy/test/get-pac-test.cpp | 316 ----- libproxy/test/url-encode.cpp | 29 - libproxy/test/url-test.cpp | 175 --- libproxy/url.cpp | 558 --------- libproxy/url.hpp | 85 -- samples/dotnet/Makefile | 8 - samples/dotnet/proxy.cs | 38 - samples/libcurl/Makefile | 9 - samples/libcurl/curlget.c | 108 -- samples/perl/sample.pl | 7 - samples/vala/Makefile | 7 - samples/vala/sample.vala | 9 - utils/CMakeLists.txt | 5 - utils/proxy.c | 105 -- 122 files changed, 11618 deletions(-) delete mode 100644 .cproject delete mode 100644 .gitignore delete mode 100644 .project delete mode 100644 .travis.yml delete mode 100644 AUTHORS delete mode 100644 CMakeLists.txt delete mode 100644 COPYING delete mode 100644 ChangeLog delete mode 100644 INSTALL delete mode 100644 NEWS delete mode 100644 README delete mode 100755 autogen.sh delete mode 100644 bindings/CMakeLists.txt delete mode 100644 bindings/csharp/AssemblyInfo.cs delete mode 100644 bindings/csharp/CMakeLists.txt delete mode 100644 bindings/csharp/libproxy-sharp-1.0.pc.cmake delete mode 100644 bindings/csharp/libproxy.cs delete mode 100644 bindings/csharp/libproxy.snk delete mode 100644 bindings/perl/CMakeLists.txt delete mode 100644 bindings/perl/lib/CMakeLists.txt delete mode 100644 bindings/perl/lib/Libproxy.pm delete mode 100644 bindings/perl/src/CMakeLists.txt delete mode 100644 bindings/perl/src/Libproxy.xs delete mode 100644 bindings/perl/src/doxsubpp.pl delete mode 100644 bindings/perl/src/typemap delete mode 100644 bindings/perl/t/CMakeLists.txt delete mode 100644 bindings/perl/t/Libproxy.t delete mode 100644 bindings/python/libproxy.py delete mode 100644 bindings/python/python2/CMakeLists.txt delete mode 100644 bindings/python/python3/CMakeLists.txt delete mode 100644 bindings/ruby/Libproxy.i delete mode 100644 bindings/ruby/extconf.rb delete mode 100644 bindings/ruby/test.rb delete mode 100644 bindings/vala/libproxy-1.0.vapi delete mode 100644 cmake/CMakeCSharpCompiler.cmake.in delete mode 100644 cmake/CMakeCSharpInformation.cmake delete mode 100644 cmake/CMakeDetermineCSharpCompiler.cmake delete mode 100644 cmake/CMakeTestCSharpCompiler.cmake delete mode 100644 cmake/FindMono.cmake delete mode 100644 cmake/FindPython2Interp.cmake delete mode 100644 cmake/FindPython3Interp.cmake delete mode 100644 cmake/cpack.cmk delete mode 100644 cmake/ctest.cmk delete mode 100644 cmake/mingw32.cmake delete mode 100644 cmake/paths.cmk delete mode 100644 doc/libproxy_files.dia delete mode 100644 libmodman/CMakeLists.txt delete mode 100644 libmodman/module.hpp delete mode 100644 libmodman/module_manager.cpp delete mode 100644 libmodman/module_manager.hpp delete mode 100644 libmodman/test/CMakeLists.txt delete mode 100644 libmodman/test/builtin.cpp delete mode 100644 libmodman/test/main.cpp delete mode 100644 libmodman/test/main.hpp delete mode 100644 libmodman/test/module.cpp.in delete mode 100644 libproxy.spec.in delete mode 100644 libproxy/CMakeLists.txt delete mode 100644 libproxy/Findlibproxy.cmake.in delete mode 100644 libproxy/cmake/devfiles.cmk delete mode 100644 libproxy/cmake/libproxy.cmk delete mode 100644 libproxy/cmake/modules.cmk delete mode 100644 libproxy/cmake/modules/config_envvar.cmk delete mode 100644 libproxy/cmake/modules/config_gnome.cmk delete mode 100644 libproxy/cmake/modules/config_kde.cmk delete mode 100644 libproxy/cmake/modules/config_macosx.cmk delete mode 100644 libproxy/cmake/modules/config_pacrunner.cmk delete mode 100644 libproxy/cmake/modules/config_sysconfig.cmk delete mode 100644 libproxy/cmake/modules/network_networkmanager.cmk delete mode 100644 libproxy/cmake/modules/pacrunner_duktape.cmk delete mode 100644 libproxy/cmake/modules/pacrunner_mozjs.cmk delete mode 100644 libproxy/cmake/modules/pacrunner_natus.cmk delete mode 100644 libproxy/cmake/modules/pacrunner_webkit.cmk delete mode 100644 libproxy/cmake/pkgconfig.cmk delete mode 100644 libproxy/cmake/pxmodule.cmk delete mode 100644 libproxy/config.hpp delete mode 100644 libproxy/extension_config.cpp delete mode 100644 libproxy/extension_config.hpp delete mode 100644 libproxy/extension_ignore.hpp delete mode 100644 libproxy/extension_network.hpp delete mode 100644 libproxy/extension_pacrunner.cpp delete mode 100644 libproxy/extension_pacrunner.hpp delete mode 100644 libproxy/extension_wpad.cpp delete mode 100644 libproxy/extension_wpad.hpp delete mode 100644 libproxy/libproxy-1.0.pc.in delete mode 100644 libproxy/libproxy.map delete mode 100644 libproxy/modules/config_envvar.cpp delete mode 100644 libproxy/modules/config_gnome.cpp delete mode 100644 libproxy/modules/config_gnome3.cpp delete mode 100644 libproxy/modules/config_kde.cpp delete mode 100644 libproxy/modules/config_macosx.cpp delete mode 100644 libproxy/modules/config_pacrunner.cpp delete mode 100644 libproxy/modules/config_sysconfig.cpp delete mode 100644 libproxy/modules/config_w32reg.cpp delete mode 100644 libproxy/modules/ignore_domain.cpp delete mode 100644 libproxy/modules/ignore_hostname.cpp delete mode 100644 libproxy/modules/ignore_ip.cpp delete mode 100644 libproxy/modules/network_networkmanager.cpp delete mode 100644 libproxy/modules/pacrunner_duktape.cpp delete mode 100644 libproxy/modules/pacrunner_mozjs.cpp delete mode 100644 libproxy/modules/pacrunner_natus.cpp delete mode 100644 libproxy/modules/pacrunner_webkit.cpp delete mode 100644 libproxy/modules/pacutils.h delete mode 100644 libproxy/modules/pxgconf.cpp delete mode 100644 libproxy/modules/pxgsettings.cpp delete mode 100644 libproxy/modules/wpad_dns_alias.cpp delete mode 100644 libproxy/proxy.cpp delete mode 100644 libproxy/proxy.h delete mode 100644 libproxy/test/CMakeLists.txt delete mode 100644 libproxy/test/get-pac-test.cpp delete mode 100644 libproxy/test/url-encode.cpp delete mode 100644 libproxy/test/url-test.cpp delete mode 100644 libproxy/url.cpp delete mode 100644 libproxy/url.hpp delete mode 100644 samples/dotnet/Makefile delete mode 100644 samples/dotnet/proxy.cs delete mode 100644 samples/libcurl/Makefile delete mode 100644 samples/libcurl/curlget.c delete mode 100644 samples/perl/sample.pl delete mode 100644 samples/vala/Makefile delete mode 100644 samples/vala/sample.vala delete mode 100644 utils/CMakeLists.txt delete mode 100644 utils/proxy.c diff --git a/.cproject b/.cproject deleted file mode 100644 index 7bf7857..0000000 --- a/.cproject +++ /dev/null @@ -1,1307 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/usr/bin/gmake - -install -true -false - - -/usr/bin/gmake - -install/local -true -false - - -/usr/bin/gmake - -install/strip -true -false - - -/usr/bin/gmake - -list_install_components -true -false - - -/usr/bin/gmake - -rebuild_cache -true -false - - -/usr/bin/gmake - -test -true -false - - -/usr/bin/gmake - -all -true -false - - -/usr/bin/gmake - -clean -true -false - - -/usr/bin/gmake - -libmodman -true -false - - -/usr/bin/gmake - -libmodman/fast -true -false - - -/usr/bin/gmake - -all -true -false - - -/usr/bin/gmake - -clean -true -false - - -/usr/bin/gmake - -module_manager.cpp.o -true -false - - -/usr/bin/gmake - -module_manager.cpp.i -true -false - - -/usr/bin/gmake - -module_manager.cpp.s -true -false - - -/usr/bin/gmake - -condition -true -false - - -/usr/bin/gmake - -condition/fast -true -false - - -/usr/bin/gmake - -condition_one -true -false - - -/usr/bin/gmake - -condition_one/fast -true -false - - -/usr/bin/gmake - -condition_two -true -false - - -/usr/bin/gmake - -condition_two/fast -true -false - - -/usr/bin/gmake - -singleton -true -false - - -/usr/bin/gmake - -singleton/fast -true -false - - -/usr/bin/gmake - -singleton_one -true -false - - -/usr/bin/gmake - -singleton_one/fast -true -false - - -/usr/bin/gmake - -singleton_two -true -false - - -/usr/bin/gmake - -singleton_two/fast -true -false - - -/usr/bin/gmake - -sorted -true -false - - -/usr/bin/gmake - -sorted/fast -true -false - - -/usr/bin/gmake - -sorted_one -true -false - - -/usr/bin/gmake - -sorted_one/fast -true -false - - -/usr/bin/gmake - -sorted_two -true -false - - -/usr/bin/gmake - -sorted_two/fast -true -false - - -/usr/bin/gmake - -symbol -true -false - - -/usr/bin/gmake - -symbol/fast -true -false - - -/usr/bin/gmake - -symbol_one -true -false - - -/usr/bin/gmake - -symbol_one/fast -true -false - - -/usr/bin/gmake - -symbol_two -true -false - - -/usr/bin/gmake - -symbol_two/fast -true -false - - -/usr/bin/gmake - -symbollnk -true -false - - -/usr/bin/gmake - -symbollnk/fast -true -false - - -/usr/bin/gmake - -all -true -false - - -/usr/bin/gmake - -clean -true -false - - -/usr/bin/gmake - -libmodman/test/condition_one.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/condition_one.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/condition_one.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/condition_two.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/condition_two.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/condition_two.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/singleton_one.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/singleton_one.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/singleton_one.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/singleton_two.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/singleton_two.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/singleton_two.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/sorted_one.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/sorted_one.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/sorted_one.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/sorted_two.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/sorted_two.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/sorted_two.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/symbol_one.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/symbol_one.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/symbol_one.cpp.s -true -false - - -/usr/bin/gmake - -libmodman/test/symbol_two.cpp.o -true -false - - -/usr/bin/gmake - -libmodman/test/symbol_two.cpp.i -true -false - - -/usr/bin/gmake - -libmodman/test/symbol_two.cpp.s -true -false - - -/usr/bin/gmake - -main.cpp.o -true -false - - -/usr/bin/gmake - -main.cpp.i -true -false - - -/usr/bin/gmake - -main.cpp.s -true -false - - -/usr/bin/gmake - -config_envvar -true -false - - -/usr/bin/gmake - -config_envvar/fast -true -false - - -/usr/bin/gmake - -config_gnome -true -false - - -/usr/bin/gmake - -config_gnome/fast -true -false - - -/usr/bin/gmake - -config_kde4 -true -false - - -/usr/bin/gmake - -config_kde4/fast -true -false - - -/usr/bin/gmake - -ignore_domain -true -false - - -/usr/bin/gmake - -ignore_domain/fast -true -false - - -/usr/bin/gmake - -ignore_hostname -true -false - - -/usr/bin/gmake - -ignore_hostname/fast -true -false - - -/usr/bin/gmake - -ignore_ip -true -false - - -/usr/bin/gmake - -ignore_ip/fast -true -false - - -/usr/bin/gmake - -libproxy -true -false - - -/usr/bin/gmake - -libproxy/fast -true -false - - -/usr/bin/gmake - -network_networkmanager -true -false - - -/usr/bin/gmake - -network_networkmanager/fast -true -false - - -/usr/bin/gmake - -pacrunner_mozjs -true -false - - -/usr/bin/gmake - -pacrunner_mozjs/fast -true -false - - -/usr/bin/gmake - -pacrunner_webkit -true -false - - -/usr/bin/gmake - -pacrunner_webkit/fast -true -false - - -/usr/bin/gmake - -pxgconf -true -false - - -/usr/bin/gmake - -pxgconf/fast -true -false - - -/usr/bin/gmake - -uninstall -true -false - - -/usr/bin/gmake - -wpad_dns_alias -true -false - - -/usr/bin/gmake - -wpad_dns_alias/fast -true -false - - -/usr/bin/gmake - -all -true -false - - -/usr/bin/gmake - -clean -true -false - - -/usr/bin/gmake - -extension_config.cpp.o -true -false - - -/usr/bin/gmake - -extension_config.cpp.i -true -false - - -/usr/bin/gmake - -extension_config.cpp.s -true -false - - -/usr/bin/gmake - -extension_pacrunner.cpp.o -true -false - - -/usr/bin/gmake - -extension_pacrunner.cpp.i -true -false - - -/usr/bin/gmake - -extension_pacrunner.cpp.s -true -false - - -/usr/bin/gmake - -extension_wpad.cpp.o -true -false - - -/usr/bin/gmake - -extension_wpad.cpp.i -true -false - - -/usr/bin/gmake - -extension_wpad.cpp.s -true -false - - -/usr/bin/gmake - -modules/config_envvar.cpp.o -true -false - - -/usr/bin/gmake - -modules/config_envvar.cpp.i -true -false - - -/usr/bin/gmake - -modules/config_envvar.cpp.s -true -false - - -/usr/bin/gmake - -modules/config_gnome.cpp.o -true -false - - -/usr/bin/gmake - -modules/config_gnome.cpp.i -true -false - - -/usr/bin/gmake - -modules/config_gnome.cpp.s -true -false - - -/usr/bin/gmake - -modules/config_kde4.cpp.o -true -false - - -/usr/bin/gmake - -modules/config_kde4.cpp.i -true -false - - -/usr/bin/gmake - -modules/config_kde4.cpp.s -true -false - - -/usr/bin/gmake - -modules/ignore_domain.cpp.o -true -false - - -/usr/bin/gmake - -modules/ignore_domain.cpp.i -true -false - - -/usr/bin/gmake - -modules/ignore_domain.cpp.s -true -false - - -/usr/bin/gmake - -modules/ignore_hostname.cpp.o -true -false - - -/usr/bin/gmake - -modules/ignore_hostname.cpp.i -true -false - - -/usr/bin/gmake - -modules/ignore_hostname.cpp.s -true -false - - -/usr/bin/gmake - -modules/ignore_ip.cpp.o -true -false - - -/usr/bin/gmake - -modules/ignore_ip.cpp.i -true -false - - -/usr/bin/gmake - -modules/ignore_ip.cpp.s -true -false - - -/usr/bin/gmake - -modules/network_networkmanager.cpp.o -true -false - - -/usr/bin/gmake - -modules/network_networkmanager.cpp.i -true -false - - -/usr/bin/gmake - -modules/network_networkmanager.cpp.s -true -false - - -/usr/bin/gmake - -modules/pacrunner_mozjs.cpp.o -true -false - - -/usr/bin/gmake - -modules/pacrunner_mozjs.cpp.i -true -false - - -/usr/bin/gmake - -modules/pacrunner_mozjs.cpp.s -true -false - - -/usr/bin/gmake - -modules/pacrunner_webkit.cpp.o -true -false - - -/usr/bin/gmake - -modules/pacrunner_webkit.cpp.i -true -false - - -/usr/bin/gmake - -modules/pacrunner_webkit.cpp.s -true -false - - -/usr/bin/gmake - -modules/pxgconf.cpp.o -true -false - - -/usr/bin/gmake - -modules/pxgconf.cpp.i -true -false - - -/usr/bin/gmake - -modules/pxgconf.cpp.s -true -false - - -/usr/bin/gmake - -modules/wpad_dns_alias.cpp.o -true -false - - -/usr/bin/gmake - -modules/wpad_dns_alias.cpp.i -true -false - - -/usr/bin/gmake - -modules/wpad_dns_alias.cpp.s -true -false - - -/usr/bin/gmake - -proxy.cpp.o -true -false - - -/usr/bin/gmake - -proxy.cpp.i -true -false - - -/usr/bin/gmake - -proxy.cpp.s -true -false - - -/usr/bin/gmake - -url.cpp.o -true -false - - -/usr/bin/gmake - -url.cpp.i -true -false - - -/usr/bin/gmake - -url.cpp.s -true -false - - -/usr/bin/gmake - -all -true -false - - -/usr/bin/gmake - -clean -true -false - - -/usr/bin/gmake - -proxy -true -false - - -/usr/bin/gmake - -proxy/fast -true -false - - -/usr/bin/gmake - -all -true -false - - -/usr/bin/gmake - -clean -true -false - - -/usr/bin/gmake - -proxy.c.o -true -false - - -/usr/bin/gmake - -proxy.c.i -true -false - - -/usr/bin/gmake - -proxy.c.s -true -false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3808cd7..0000000 --- a/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -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 diff --git a/.project b/.project deleted file mode 100644 index 0cbd4af..0000000 --- a/.project +++ /dev/null @@ -1,111 +0,0 @@ - - - libproxy@libproxy - - - - - - org.eclipse.cdt.make.core.makeBuilder - clean,full,incremental, - - - org.eclipse.cdt.make.core.cleanBuildTarget - clean - - - org.eclipse.cdt.make.core.enableCleanBuild - true - - - org.eclipse.cdt.make.core.append_environment - true - - - org.eclipse.cdt.make.core.stopOnError - true - - - org.eclipse.cdt.make.core.enabledIncrementalBuild - true - - - org.eclipse.cdt.make.core.build.command - /usr/bin/gmake - - - org.eclipse.cdt.make.core.contents - org.eclipse.cdt.make.core.activeConfigSettings - - - org.eclipse.cdt.make.core.build.target.inc - all - - - org.eclipse.cdt.make.core.build.arguments - - - - org.eclipse.cdt.make.core.buildLocation - /home/nathaniel/Projects/libproxy - - - org.eclipse.cdt.make.core.useDefaultBuildCmd - false - - - org.eclipse.cdt.make.core.environment - VERBOSE=1| - - - - org.eclipse.cdt.make.core.enableFullBuild - true - - - org.eclipse.cdt.make.core.build.target.auto - all - - - org.eclipse.cdt.make.core.enableAutoBuild - false - - - org.eclipse.cdt.make.core.build.target.clean - clean - - - org.eclipse.cdt.make.core.fullBuildTarget - all - - - org.eclipse.cdt.make.core.buildArguments - - - - org.eclipse.cdt.make.core.build.location - /home/nathaniel/Projects/libproxy - - - org.eclipse.cdt.make.core.autoBuildTarget - all - - - org.eclipse.cdt.core.errorOutputParser - org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser; - - - - - org.eclipse.cdt.make.core.ScannerConfigBuilder - - - - - - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.make.core.makeNature - org.eclipse.cdt.make.core.ScannerConfigNature - org.eclipse.cdt.core.cnature - - 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 -Alex Panait -Dominique Leuenberger -Gonéri Le Bouder - Perl bindings -Nicolas Dufresne 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$<$: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/COPYING b/COPYING deleted file mode 100644 index 4362b49..0000000 --- a/COPYING +++ /dev/null @@ -1,502 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! 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 - * == 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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 - * === 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. - diff --git a/NEWS b/NEWS deleted file mode 100644 index 78dc577..0000000 --- a/NEWS +++ /dev/null @@ -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 diff --git a/README b/README deleted file mode 100644 index 85d2d6e..0000000 --- a/README +++ /dev/null @@ -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/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 - * - * 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 "") - -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 - * - * 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 deleted file mode 100644 index 3dc1731..0000000 Binary files a/bindings/csharp/libproxy.snk and /dev/null differ 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, Egoneri@rulezlan.orgE - -=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 - - -void XS_pack_charPtrPtr( SV * arg, char ** array, int count) { - int i; - AV * avref; - avref = (AV*)sv_2mortal((SV*)newAV()); - for (i=0; inew( { - 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 -# -# 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 ( [UNSAFE] [WINEXE] [REFERENCES ] -# [COMPILE_FLAGS ] -# [COMPILE_DEFINITIONS ] ) -# -# csharp_add_library ( [UNSAFE] [REFERENCES ] -# [COMPILE_FLAGS ] -# [COMPILE_DEFINITIONS ] ) -# -# install_assembly ( [NO_GAC] DESTINATION -# [PACKAGE ] ) -# 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 .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 .pc file will be installed to -# /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 -# Copyright 2012 Rolf Eike Beer -# Copyright 2016 Dominique Leuenberger -# -# 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 -# Copyright 2012 Rolf Eike Beer -# Copyright 2016 Dominique Leuenberger -# -# 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/doc/libproxy_files.dia b/doc/libproxy_files.dia deleted file mode 100644 index ba61fa6..0000000 Binary files a/doc/libproxy_files.dia and /dev/null differ 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 - * - * 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 // 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 __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 - * - * 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 // For sort() -#include // For stat() -#include -#include - -#ifdef WIN32 -#include -#else -#include // For dlopen(), etc... -#include // For opendir(), readdir(), closedir() -#endif - -#include "module_manager.hpp" -using namespace libmodman; - -#include - -#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 = " >::iterator i=this->extensions.begin() ; i != this->extensions.end() ; i++) { - for (vector::iterator j=i->second.begin() ; j != i->second.end() ; j++) - delete *j; - i->second.clear(); - } - this->extensions.clear(); - - // Free all modules - for (set::iterator i=this->modules.begin() ; i != this->modules.end() ; i++) - pdlclose(*i); - this->modules.clear(); -} - -static int load(map >& extensions, - set& 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 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::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 - * - * 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 -#include -#include -#include -#include -#include - -#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 vector get_extensions() const { - struct pcmp { - static bool cmp(T* x, T* y) { return *x < *y; } - }; - - map >::const_iterator it = this->extensions.find(T::base_type()); - vector retlist; - - if (it != this->extensions.end()) { - vector extlist = it->second; - - for (size_t i=0 ; i < extlist.size() ; i++) { - T* obj = dynamic_cast(extlist[i]); - if (obj) - retlist.push_back(obj); - else - assert (obj != NULL); - } - - sort(retlist.begin(), retlist.end(), &pcmp::cmp); - } - - return retlist; - } - - template 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 modules; - set singletons; - map > 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 $ two) -add_test(NAME singleton COMMAND singleton $ one) -add_test(NAME sorted COMMAND sorted $ two one) -add_test(NAME symbol COMMAND symbollnk $ two) -add_test(NAME nosymbol COMMAND symbol $) -add_test(NAME nosymreq COMMAND symbol $ one) -add_test(NAME builtin COMMAND builtin) - diff --git a/libmodman/test/builtin.cpp b/libmodman/test/builtin.cpp deleted file mode 100644 index 8a3f328..0000000 --- a/libmodman/test/builtin.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * Copyright (C) 2009 Nathaniel McCallum - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#include "main.hpp" - -MM_DEF_BUILTIN(BUILTIN_MODULE); - -int main() { - module_manager mm; - mm.register_type(); - return !mm.load_builtin(& MM_BUILTIN(BUILTIN_MODULE)); -} 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 - * - * 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 -#include -#include -#ifdef WIN32 -#ifdef SYMB -#include -#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()) { - 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 exts = mm.get_extensions(); - 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 - * - * 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 - -#include "../module_manager.hpp" - -using namespace std; -using namespace libmodman; - -class __MM_DLL_EXPORT singleton_extension : public extension {}; - -class __MM_DLL_EXPORT sorted_extension : public 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 {}; -class __MM_DLL_EXPORT condition_extension : public extension {}; -class __MM_DLL_EXPORT builtin_extension : public extension {}; - -#endif /* MAIN_HPP_ */ diff --git a/libmodman/test/module.cpp.in b/libmodman/test/module.cpp.in deleted file mode 100644 index 3390ead..0000000 --- a/libmodman/test/module.cpp.in +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * libmodman - A library for extending applications - * Copyright (C) 2009 Nathaniel McCallum - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#include -#include - -class @MODNAME@ : public @MODTYPE@_extension {}; -MM_MODULE_INIT_EZ(@MODNAME@, @MODCOND@, @MODSYMB@, @MODSMOD@); 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 - * - * 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 -#include -#include -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 -#include -#include -#include -#include -#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 - * - * 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 - * - * 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 -#include "url.hpp" - -namespace libproxy { -using namespace std; -using namespace libmodman; - -// Config module -class DLL_PUBLIC config_extension : public extension { -public: - // Abstract methods - virtual vector 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 - * - * 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 - -#include "url.hpp" - -namespace libproxy { -using namespace std; -using namespace libmodman; - -class DLL_PUBLIC ignore_extension : public extension { -public: - virtual bool ignore(url& dst, const string &ignorestr)=0; -}; - -} - -#endif /* EXTENSION_IGNORE_HPP_ */ diff --git a/libproxy/extension_network.hpp b/libproxy/extension_network.hpp deleted file mode 100644 index 1a8fc46..0000000 --- a/libproxy/extension_network.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2009 Nathaniel McCallum - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#ifndef EXTENSION_NETWORK_HPP_ -#define EXTENSION_NETWORK_HPP_ - -#include -#include "config.hpp" - -namespace libproxy { -using namespace libmodman; - -// Network module -class DLL_PUBLIC network_extension : public extension { -public: - virtual bool changed()=0; -}; - -} - -#endif /* EXTENSION_NETWORK_HPP_ */ diff --git a/libproxy/extension_pacrunner.cpp b/libproxy/extension_pacrunner.cpp deleted file mode 100644 index 698f25f..0000000 --- a/libproxy/extension_pacrunner.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2009 Nathaniel McCallum - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#include "extension_pacrunner.hpp" -using namespace libproxy; - -pacrunner::pacrunner(const string &, const url&) {} - -pacrunner_extension::pacrunner_extension() { -} - -pacrunner_extension::~pacrunner_extension() { -} - -pacrunner* pacrunner_extension::get(const string &pac, const url& pacurl) { - return this->create(pac, pacurl); -} 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 - * - * 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 -#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 { -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 - -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 - * - * 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 -#include "url.hpp" - -namespace libproxy { -using namespace std; -using namespace libmodman; - -// WPAD module -class DLL_PUBLIC wpad_extension : public 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::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/libproxy.map b/libproxy/libproxy.map deleted file mode 100644 index 511c7f2..0000000 --- a/libproxy/libproxy.map +++ /dev/null @@ -1,7 +0,0 @@ -LIBPROXY_0.4.16 { - global: - px_proxy_factory_new; - px_proxy_factory_get_proxies; - px_proxy_factory_free_proxies; - px_proxy_factory_free; -}; 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 - * - * 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 - -#include "../extension_config.hpp" -using namespace libproxy; - -class envvar_config_extension : public config_extension { -public: - vector get_config(const url &dst) { - const char *proxy = NULL; - vector 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 - * - * 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 // For fileno(), fread(), pclose(), popen(), sscanf() -#include // For select() -#include // For fcntl() -#include // For errno stuff -#include // For stat() -#include // For stat() -#include // For pipe(), close(), vfork(), dup(), execl(), _exit() -#include // 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 &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 get_config(const url &dest) { - // Check for changes in the config - fd_set rfds; - struct timeval timeout = { 0, 0 }; - vector 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 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 - * - * 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 // For fileno(), fread(), pclose(), popen(), sscanf() -#include // For select() -#include // For fcntl() -#include // For errno stuff -#include // For stat() -#include // For stat() -#include // For pipe(), close(), vfork(), dup(), execl(), _exit() -#include // For waitpid() -#include // For kill() -#include // 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 &response) { - if (host != "" && get_port(port) != 0) { - string tmp = type + "://"; - if (auth) - tmp += username + ":" + password + "@"; - tmp += host + ":" + port; - response.push_back(url(tmp)); - } - } - - vector get_config(const url &dest) { - // Check for changes in the config - fd_set rfds; - struct timeval timeout = { 0, 0 }; - vector 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 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 - * Copyright (C) 2021 Fabian Vogt - * - * 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 -#include - -#include -#include -#include -#include - -#ifdef WIN32 -#define popen _popen -#define pclose _pclose -#else -#include -#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 get_config(const url &dst) { - // See constructor - if(command.empty()) - throw runtime_error("Unable to read configuration"); - - vector 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::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 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 cache; - // State of the config files at the time of the last cache flush - vector 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 - * - * 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 - -#include "../extension_config.hpp" -using namespace libproxy; - -#include - -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 -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(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(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 get_config(const url &the_url) { - string tmp; - CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL); - vector 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(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(proxies, "ExceptionsList")); - if (getbool(proxies, "ExcludeSimpleHostnames")) - tmp += (tmp == "" ? string("") : string(",")) + ""; - - 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 -#include - -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 get_config(const url &dest) { - // Make sure we have a valid connection with a proper match - DBusConnection *conn = this->conn; - vector 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 -#include -#include -#include -#include -#include - - -#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 sysconfig_read(const string &_path) { - - map 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 _data; - -public: - sysconfig_config_extension() - : _data(sysconfig_read("/etc/sysconfig/proxy")) { - - } - - ~sysconfig_config_extension() { - } - - vector get_config(const url &dst) { - map::const_iterator it = _data.find("PROXY_ENABLED"); - vector 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::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 - * - * 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 -#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 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 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 get_config(const url &dst) { - char *tmp = NULL; - uint32_t enabled = 0; - vector 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 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 - * - * 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 - -#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 - * - * 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 - -#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 == "" && - 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 - * - * 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 -#include - -#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 - * - * 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 // For uint32_t - -#include "../extension_network.hpp" -using namespace libproxy; - -#include -#include - -// 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 - * Copyright (C) 2021 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 // gethostname -#endif - -using namespace libproxy; - -#include -#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 - * - * 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 // ? -#include // 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 -#pragma GCC diagnostic error "-Winvalid-offsetof" -#include -#include -#include -#include -#include - -#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(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 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 *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 - * - * 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 // gethostname -using namespace libproxy; - -#define I_ACKNOWLEDGE_THAT_NATUS_IS_NOT_STABLE -#include -#include "pacutils.h" - -using namespace natus; - -static Value dnsResolve(Value& ths, Value& fnc, vector& arg) { - Value exc = checkArguments(ths, arg, "s"); - if (exc.isException()) return exc; - - // Look it up - struct addrinfo *info; - if (getaddrinfo(arg[0].toString().c_str(), NULL, NULL, &info)) - return NULL; - - // Try for IPv4 - char* tmp = new char[INET6_ADDRSTRLEN+1]; - if (getnameinfo(info->ai_addr, info->ai_addrlen, - tmp, INET6_ADDRSTRLEN+1, - NULL, 0, - NI_NUMERICHOST)) { - freeaddrinfo(info); - delete[] tmp; - return NULL; - } - freeaddrinfo(info); - - // Create the return value - Value ret = ths.newString(tmp); - delete[] tmp; - return ret; -} - -static Value myIpAddress(Value& ths, Value& fnc, vector& arg) { - char hostname[1024]; - hostname[sizeof(hostname) - 1] = '\0'; - - if (!gethostname(hostname, sizeof(hostname) - 1)) { - vector dnsargs; - dnsargs.push_back(ths.newString(hostname)); - return dnsResolve(ths, fnc, dnsargs); - } - return ths.newString("Unable to find hostname!").toException(); -} - -class natus_pacrunner : public pacrunner { -public: - natus_pacrunner(string pac, const url& pacurl) : 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 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 - * - * 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 // gethostname -using namespace libproxy; - -#ifdef __APPLE__ -// JavaScriptCore.h requires CoreFoundation -// This is only found on Mac OS X -#include -#else -#include -#endif -#include "pacutils.h" - -#ifndef INET_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#endif - -#ifndef INET6_ADDRSTRLEN -#define INET6_ADDRSTRLEN 46 -#endif - -static char *jstr2str(JSStringRef str, bool release) -{ - char *tmp = new char[JSStringGetMaximumUTF8CStringSize(str)+1]; - JSStringGetUTF8CString(str, tmp, JSStringGetMaximumUTF8CStringSize(str)+1); - if (release) JSStringRelease(str); - return tmp; -} - -static JSValueRef dnsResolve(JSContextRef ctx, JSObjectRef /*func*/, JSObjectRef /*self*/, size_t argc, const JSValueRef argv[], JSValueRef* /*exception*/) -{ - if (argc != 1) return NULL; - if (!JSValueIsString(ctx, argv[0])) return NULL; - - // Get hostname argument - char *tmp = jstr2str(JSValueToStringCopy(ctx, argv[0], NULL), true); - - // Look it up - struct addrinfo *info; - if (getaddrinfo(tmp, NULL, NULL, &info)) { - if (tmp) delete[] tmp; - return NULL; - } - delete[] tmp; - - // Try for IPv4 - tmp = new char[INET6_ADDRSTRLEN+1]; - if (getnameinfo(info->ai_addr, info->ai_addrlen, - tmp, INET6_ADDRSTRLEN+1, - NULL, 0, - NI_NUMERICHOST)) { - freeaddrinfo(info); - delete[] tmp; - return NULL; - } - freeaddrinfo(info); - - // Create the return value - JSStringRef str = JSStringCreateWithUTF8CString(tmp); - JSValueRef ret = JSValueMakeString(ctx, str); - JSStringRelease(str); - delete[] tmp; - - return ret; -} - -static JSValueRef myIpAddress(JSContextRef ctx, JSObjectRef func, JSObjectRef self, size_t /*argc*/, const JSValueRef[] /*argv*/, JSValueRef* /*exception*/) -{ - char hostname[1024]; - hostname[sizeof(hostname) - 1] = '\0'; - - if (!gethostname(hostname, sizeof(hostname) - 1)) { - JSStringRef str = JSStringCreateWithUTF8CString(hostname); - JSValueRef val = JSValueMakeString(ctx, str); - JSStringRelease(str); - JSValueRef ip = dnsResolve(ctx, func, self, 1, &val, NULL); - return ip; - } - return NULL; -} - -class webkit_pacrunner : public pacrunner { -public: - ~webkit_pacrunner() { - JSGarbageCollect(this->jsctx); - JSGlobalContextRelease(this->jsctx); - } - - webkit_pacrunner(string pac, const url& pacurl) : pacrunner(pac, pacurl) { - JSStringRef str = NULL; - JSObjectRef func = NULL; - - // Create the basic context - if (!(this->jsctx = JSGlobalContextCreate(NULL))) goto error; - - // Add dnsResolve into the context - str = JSStringCreateWithUTF8CString("dnsResolve"); - func = JSObjectMakeFunctionWithCallback(this->jsctx, str, dnsResolve); - JSObjectSetProperty(this->jsctx, JSContextGetGlobalObject(this->jsctx), str, func, kJSPropertyAttributeNone, NULL); - JSStringRelease(str); - - // Add myIpAddress into the context - str = JSStringCreateWithUTF8CString("myIpAddress"); - func = JSObjectMakeFunctionWithCallback(this->jsctx, str, myIpAddress); - JSObjectSetProperty(this->jsctx, JSContextGetGlobalObject(this->jsctx), str, func, kJSPropertyAttributeNone, NULL); - JSStringRelease(str); - - // Add all other routines into the context - str = JSStringCreateWithUTF8CString(JAVASCRIPT_ROUTINES); - if (!JSCheckScriptSyntax(this->jsctx, str, NULL, 0, NULL)) goto error; - JSEvaluateScript(this->jsctx, str, NULL, NULL, 1, NULL); - JSStringRelease(str); - - // Add the PAC into the context - str = JSStringCreateWithUTF8CString(pac.c_str()); - if (!JSCheckScriptSyntax(this->jsctx, str, NULL, 0, NULL)) goto error; - JSEvaluateScript(this->jsctx, str, NULL, NULL, 1, NULL); - JSStringRelease(str); - return; - - error: - if (str) JSStringRelease(str); - if (this->jsctx) { - JSGarbageCollect(this->jsctx); - JSGlobalContextRelease(this->jsctx); - } - throw bad_alloc(); - } - - string run(const url& url_) { - JSStringRef str = NULL; - JSValueRef val = NULL; - string tmp; - char *retChar = NULL; - string retStr = ""; - - // Run the PAC - tmp = string("FindProxyForURL(\"") + url_.to_string() + string("\", \"") + url_.get_host() + "\");"; - str = JSStringCreateWithUTF8CString(tmp.c_str()); - if (!str) throw bad_alloc(); - if (!JSCheckScriptSyntax(this->jsctx, str, NULL, 0, NULL)) goto error; - if (!(val = JSEvaluateScript(this->jsctx, str, NULL, NULL, 1, NULL))) goto error; - if (!JSValueIsString(this->jsctx, val)) goto error; - JSStringRelease(str); - - // Convert the return value to a string - retChar = jstr2str(JSValueToStringCopy(this->jsctx, val, NULL), true); - if (retChar) { - retStr = retChar; - delete[] retChar; - } - return retStr; - - error: - JSStringRelease(str); - return ""; - } - -private: - JSGlobalContextRef jsctx; -}; - -PX_PACRUNNER_MODULE_EZ(webkit, "JSObjectMakeFunctionWithCallback", "webkit"); diff --git a/libproxy/modules/pacutils.h b/libproxy/modules/pacutils.h deleted file mode 100644 index 3826014..0000000 --- a/libproxy/modules/pacutils.h +++ /dev/null @@ -1,242 +0,0 @@ -/* - * The following Javascript code was taken from Mozilla (http://www.mozilla.org) - * and is licensed according to the LGPLv2.1+. Below is the original copyright - * header as contained in the source file (nsProxyAutoConfig.js) - */ - -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Akhil Arora - * Tomi Leppikangas - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#define JAVASCRIPT_ROUTINES \ -"function dnsDomainIs(host, domain) {\n" \ -" return (host.length >= domain.length &&\n" \ -" host.substring(host.length - domain.length) == domain);\n" \ -"}\n" \ -"function dnsDomainLevels(host) {\n" \ -" return host.split('.').length-1;\n" \ -"}\n" \ -"function convert_addr(ipchars) {\n" \ -" var bytes = ipchars.split('.');\n" \ -" var result = ((bytes[0] & 0xff) << 24) |\n" \ -" ((bytes[1] & 0xff) << 16) |\n" \ -" ((bytes[2] & 0xff) << 8) |\n" \ -" (bytes[3] & 0xff);\n" \ -" return result;\n" \ -"}\n" \ -"function isInNet(ipaddr, pattern, maskstr) {\n"\ -" var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(ipaddr);\n"\ -" if (test == null) {\n"\ -" ipaddr = dnsResolve(ipaddr);\n"\ -" if (ipaddr == null)\n"\ -" return false;\n"\ -" } else if (test[1] > 255 || test[2] > 255 || \n"\ -" test[3] > 255 || test[4] > 255) {\n"\ -" return false; // not an IP address\n"\ -" }\n"\ -" var host = convert_addr(ipaddr);\n"\ -" var pat = convert_addr(pattern);\n"\ -" var mask = convert_addr(maskstr);\n"\ -" return ((host & mask) == (pat & mask));\n"\ -" \n"\ -"}\n"\ -"function isPlainHostName(host) {\n" \ -" return (host.search('\\\\.') == -1);\n" \ -"}\n" \ -"function isResolvable(host) {\n" \ -" var ip = dnsResolve(host);\n" \ -" return (ip != null);\n" \ -"}\n" \ -"function localHostOrDomainIs(host, hostdom) {\n" \ -" if (isPlainHostName(host)) {\n" \ -" return (hostdom.search('/^' + host + '/') != -1);\n" \ -" }\n" \ -" else {\n" \ -" return (host == hostdom);\n" \ -" }\n" \ -"}\n" \ -"function shExpMatch(url, pattern) {\n" \ -" pattern = pattern.replace(/\\./g, '\\\\.');\n" \ -" pattern = pattern.replace(/\\*/g, '.*');\n" \ -" pattern = pattern.replace(/\\?/g, '.');\n" \ -" var newRe = new RegExp('^'+pattern+'$');\n" \ -" return newRe.test(url);\n" \ -"}\n" \ -"var wdays = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};\n" \ -"var months = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};\n"\ -"function weekdayRange() {\n" \ -" function getDay(weekday) {\n" \ -" if (weekday in wdays) {\n" \ -" return wdays[weekday];\n" \ -" }\n" \ -" return -1;\n" \ -" }\n" \ -" var date = new Date();\n" \ -" var argc = arguments.length;\n" \ -" var wday;\n" \ -" if (argc < 1)\n" \ -" return false;\n" \ -" if (arguments[argc - 1] == 'GMT') {\n" \ -" argc--;\n" \ -" wday = date.getUTCDay();\n" \ -" } else {\n" \ -" wday = date.getDay();\n" \ -" }\n" \ -" var wd1 = getDay(arguments[0]);\n" \ -" var wd2 = (argc == 2) ? getDay(arguments[1]) : wd1;\n" \ -" return (wd1 == -1 || wd2 == -1) ? false\n" \ -" : (wd1 <= wday && wday <= wd2);\n" \ -"}\n" \ -"function dateRange() {\n" \ -" function getMonth(name) {\n" \ -" if (name in months) {\n" \ -" return months[name];\n" \ -" }\n" \ -" return -1;\n" \ -" }\n" \ -" var date = new Date();\n" \ -" var argc = arguments.length;\n" \ -" if (argc < 1) {\n" \ -" return false;\n" \ -" }\n" \ -" var isGMT = (arguments[argc - 1] == 'GMT');\n" \ -" if (isGMT) {\n" \ -" argc--;\n" \ -" }\n" \ -" if (argc == 1) {\n" \ -" var tmp = parseInt(arguments[0]);\n" \ -" if (isNaN(tmp)) {\n" \ -" return ((isGMT ? date.getUTCMonth() : date.getMonth()) == getMonth(arguments[0]));\n" \ -" } else if (tmp < 32) {\n" \ -" return ((isGMT ? date.getUTCDate() : date.getDate()) == tmp);\n" \ -" } else {\n" \ -" return ((isGMT ? date.getUTCFullYear() : date.getFullYear()) == tmp);\n" \ -" }\n" \ -" }\n" \ -" var year = date.getFullYear();\n" \ -" var date1, date2;\n" \ -" date1 = new Date(year, 0, 1, 0, 0, 0);\n" \ -" date2 = new Date(year, 11, 31, 23, 59, 59);\n" \ -" var adjustMonth = false;\n" \ -" for (var i = 0; i < (argc >> 1); i++) {\n" \ -" var tmp = parseInt(arguments[i]);\n" \ -" if (isNaN(tmp)) {\n" \ -" var mon = getMonth(arguments[i]);\n" \ -" date1.setMonth(mon);\n" \ -" } else if (tmp < 32) {\n" \ -" adjustMonth = (argc <= 2);\n" \ -" date1.setDate(tmp);\n" \ -" } else {\n" \ -" date1.setFullYear(tmp);\n" \ -" }\n" \ -" }\n" \ -" for (var i = (argc >> 1); i < argc; i++) {\n" \ -" var tmp = parseInt(arguments[i]);\n" \ -" if (isNaN(tmp)) {\n" \ -" var mon = getMonth(arguments[i]);\n" \ -" date2.setMonth(mon);\n" \ -" } else if (tmp < 32) {\n" \ -" date2.setDate(tmp);\n" \ -" } else {\n" \ -" date2.setFullYear(tmp);\n" \ -" }\n" \ -" }\n" \ -" if (adjustMonth) {\n" \ -" date1.setMonth(date.getMonth());\n" \ -" date2.setMonth(date.getMonth());\n" \ -" }\n" \ -" if (isGMT) {\n" \ -" var tmp = date;\n" \ -" tmp.setFullYear(date.getUTCFullYear());\n" \ -" tmp.setMonth(date.getUTCMonth());\n" \ -" tmp.setDate(date.getUTCDate());\n" \ -" tmp.setHours(date.getUTCHours());\n" \ -" tmp.setMinutes(date.getUTCMinutes());\n" \ -" tmp.setSeconds(date.getUTCSeconds());\n" \ -" date = tmp;\n" \ -" }\n" \ -" return ((date1 <= date) && (date <= date2));\n" \ -"}\n" \ -"function timeRange() {\n" \ -" var argc = arguments.length;\n" \ -" var date = new Date();\n" \ -" var isGMT= false;\n" \ -" if (argc < 1) {\n" \ -" return false;\n" \ -" }\n" \ -" if (arguments[argc - 1] == 'GMT') {\n" \ -" isGMT = true;\n" \ -" argc--;\n" \ -" }\n" \ -" var hour = isGMT ? date.getUTCHours() : date.getHours();\n" \ -" var date1, date2;\n" \ -" date1 = new Date();\n" \ -" date2 = new Date();\n" \ -" if (argc == 1) {\n" \ -" return (hour == arguments[0]);\n" \ -" } else if (argc == 2) {\n" \ -" return ((arguments[0] <= hour) && (hour <= arguments[1]));\n" \ -" } else {\n" \ -" switch (argc) {\n" \ -" case 6:\n" \ -" date1.setSeconds(arguments[2]);\n" \ -" date2.setSeconds(arguments[5]);\n" \ -" case 4:\n" \ -" var middle = argc >> 1;\n" \ -" date1.setHours(arguments[0]);\n" \ -" date1.setMinutes(arguments[1]);\n" \ -" date2.setHours(arguments[middle]);\n" \ -" date2.setMinutes(arguments[middle + 1]);\n" \ -" if (middle == 2) {\n" \ -" date2.setSeconds(59);\n" \ -" }\n" \ -" break;\n" \ -" default:\n" \ -" throw 'timeRange: bad number of arguments'\n" \ -" }\n" \ -" }\n" \ -" if (isGMT) {\n" \ -" date.setFullYear(date.getUTCFullYear());\n" \ -" date.setMonth(date.getUTCMonth());\n" \ -" date.setDate(date.getUTCDate());\n" \ -" date.setHours(date.getUTCHours());\n" \ -" date.setMinutes(date.getUTCMinutes());\n" \ -" date.setSeconds(date.getUTCSeconds());\n" \ -" }\n" \ -" return ((date1 <= date) && (date <= date2));\n" \ -"}\n" \ -"" diff --git a/libproxy/modules/pxgconf.cpp b/libproxy/modules/pxgconf.cpp deleted file mode 100644 index ff7890f..0000000 --- a/libproxy/modules/pxgconf.cpp +++ /dev/null @@ -1,194 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include - -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 - * Copyright (C) 2011 Dominique Leuenberger - * - * 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 -#include -#include -#include - -#include -#include -#include - -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 - * - * 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 - * - * 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 -#include // For strdup() -#include // For cerr -#include // For exception -#include // Only for debug messages. - -#include - -#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 get_proxies(const string &url); - -private: - void lock(); - void unlock(); - - void check_network_topology(); - void get_config(url &realurl, vector &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 &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 &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(); - this->mm.register_type(); - this->mm.register_type(); - this->mm.register_type(); - this->mm.register_type(); - - // 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 proxy_factory::get_proxies(const string &realurl) { - vector 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 configs; - string ignore; - url dst(realurl); - - check_network_topology(); - get_config(dst, configs, ignore); - - if (debug) cerr << "Config is: " << endl; - - for (vector::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 networks; - - // Check to see if our network topology has changed... - networks = this->mm.get_extensions(); - for (vector::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 wpads = this->mm.get_extensions(); - for (vector::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 &config, string &ignore) { - vector configs; - - configs = this->mm.get_extensions(); - for (vector::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 ignores; - bool ignored = false, invign = false; - string confign = ignore; - - /* Check our ignore patterns */ - ignores = this->mm.get_extensions(); - 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::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 wpads = this->mm.get_extensions(); - for (vector::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::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 &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 pacrunners = this->mm.get_extensions(); - - /* 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 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/proxy.h b/libproxy/proxy.h deleted file mode 100644 index c620a80..0000000 --- a/libproxy/proxy.h +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - ******************************************************************************/ - -#ifndef PROXY_H_ -#define PROXY_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef struct pxProxyFactory_ pxProxyFactory; - -/** - * 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. - * - * @return A new pxProxyFactory instance or NULL on error - */ -pxProxyFactory *px_proxy_factory_new(void); - -/** - * Get which proxies to use for the specified URL. - * - * 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. - * - * 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 (i.e. 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. - * - * 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 - * - ://[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. - * - * For SOCKS proxies, when the protocol version is specified (socks4:// or - * socks5://), it is expected that only this version is used. When only - * socks:// is set, the client MUST try SOCKS version 5 protocol and, on - * connection failure, fallback to SOCKS version 4. - * - * Other proxying protocols may exist. It is expected that the returned - * configuration scheme shall match the network service name of the - * 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 - */ -char **px_proxy_factory_get_proxies(pxProxyFactory *self, const char *url); - -/** - * 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); - -/** - * Frees the pxProxyFactory instance when no longer used. - */ -void px_proxy_factory_free(pxProxyFactory *self); - -#ifdef __cplusplus -} -#endif - -#endif /*PROXY_H_*/ 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 -#include -#include -#include - -#include // for abort() -#include // for EINTR -#include -#include -#include -#include -#include -#include -#include -#include - -#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 -#include -#include - - -#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 -#include -#include -#include - - -#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 - * - * 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 // For ::open() -#include // For memcpy() -#include // For int/string conversion (using stringstream) -#include // For sscanf() -#include // For atoi() -#include // For errno and EINTR -#include // For stat() -#include // For transform() - -#ifdef WIN32 -#include -#define open _open -#define O_RDONLY _O_RDONLY -#define close _close -#define read _read -#define SHUT_RDWR SD_BOTH -#else -#include // 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 -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 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 - * - * 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 -#include -#include -#include - -#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/samples/dotnet/Makefile b/samples/dotnet/Makefile deleted file mode 100644 index 587f83b..0000000 --- a/samples/dotnet/Makefile +++ /dev/null @@ -1,8 +0,0 @@ - -all: proxy.exe - -proxy.exe: proxy.cs - gmcs -pkg:libproxy-sharp-1.0 proxy.cs - -clean: - rm proxy.exe diff --git a/samples/dotnet/proxy.cs b/samples/dotnet/proxy.cs deleted file mode 100644 index a8ce5e4..0000000 --- a/samples/dotnet/proxy.cs +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2009 Dominique Leuenberger - * - * 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 libproxy; - -public class proxy { - public static int Main (string[] args) - { - if (args.Length > 0) { - ProxyFactory pf = new ProxyFactory(); - string[] Proxies = pf.GetProxies(args[0]); - Console.WriteLine(Proxies[0]); - pf = null; - return 0; - } else { - Console.WriteLine("Please start the program with one parameter"); - Console.WriteLine("Example: proxy.exe http://libproxy.googlecode.com/"); - return 1; - } - } -} diff --git a/samples/libcurl/Makefile b/samples/libcurl/Makefile deleted file mode 100644 index 35b4597..0000000 --- a/samples/libcurl/Makefile +++ /dev/null @@ -1,9 +0,0 @@ - - -all: curlget - -curlget: curlget.c - gcc curlget.c -o curlget -Wall -lcurl -std=c99 $(shell pkg-config --libs libproxy-1.0) - -clean: - rm curlget diff --git a/samples/libcurl/curlget.c b/samples/libcurl/curlget.c deleted file mode 100644 index 00954e9..0000000 --- a/samples/libcurl/curlget.c +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum - * Copyright (C) 2008 Dominique Leuenberger - * - * 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 "proxy.h" -#include "curl/curl.h" -#include -#include - -int main(int argc, char * argv[]) { - pxProxyFactory *pf = NULL; - CURL *curl = NULL; - CURLcode result = 1; - - /* Check if we have a parameter passed, otherwise bail out... I need one */ - if (argc < 2) - { - printf("libcurl / libproxy example implementation\n"); - printf("=========================================\n"); - printf("The program has to be started with one parameter\n"); - printf("Defining the URL that should be downloaded\n\n"); - printf("Example: %s http://code.google.com/p/libproxy/\n", argv[0]); - return -1; - } - - /* Initializing curl... has to happen exactly once in the program */ - if (curl_global_init( CURL_GLOBAL_ALL )) return -4; - - /* Create pxProxyFactory object */ - if (!(pf = px_proxy_factory_new())) - { - printf("Unable to create pxProxyFactory object!\n"); - curl_global_cleanup(); - return -2; - } - - /* Create curl handle */ - if (!(curl = curl_easy_init())) - { - printf("Unable to get libcurl handle!\n"); - px_proxy_factory_free(pf); - curl_global_cleanup(); - return -3; - } - - /* Get the array of proxies to try */ - char **proxies = px_proxy_factory_get_proxies(pf, argv[1]); - - /* Set the URL into the curl handle */ - curl_easy_setopt(curl, CURLOPT_URL, argv[1]); - - /* Try to fetch our url using each proxy */ - for (int i=0 ; proxies[i] ; i++) - { - if (result != 0) - { - /* Setup our proxy's config into curl */ - curl_easy_setopt(curl, CURLOPT_PROXY, proxies[i]); - - /* HTTP Proxy */ - if (!strncmp("http", proxies[i], 4)) - curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); - - /* SOCKS Proxy, is this correct??? */ - /* What about SOCKS 4A, 5 and 5_HOSTNAME??? */ - else if (!strncmp("socks", proxies[i], 4)) - curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - - /* Attempt to fetch the page */ - result = curl_easy_perform(curl); - } - - /* If we reached the end of the proxies array and still did not - succeed to conntect, let's inform the user that we failed. */ - if (proxies[i+1] == NULL && result != 0) - printf ("The requested URL (%s) could not be retrieved using the current setup\n", argv[1]); - - } - - /* Free the proxy array */ - px_proxy_factory_free_proxies(proxies); - - /* Free the curl and libproxy handles */ - px_proxy_factory_free(pf); - curl_easy_cleanup(curl); - - /* Cleanup the libcurl library */ - curl_global_cleanup(); - return 0; - -} - diff --git a/samples/perl/sample.pl b/samples/perl/sample.pl deleted file mode 100644 index e8850fc..0000000 --- a/samples/perl/sample.pl +++ /dev/null @@ -1,7 +0,0 @@ -use Net::Libproxy; - -$p = new Net::Libproxy; -$proxies = $p->getProxies('http://www.google.com'); -foreach my $proxy (@$proxies) { - print $proxy."\n"; -} diff --git a/samples/vala/Makefile b/samples/vala/Makefile deleted file mode 100644 index 3e42a34..0000000 --- a/samples/vala/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: sample - -sample: sample.vala - valac --pkg libproxy-1.0 sample.vala - -clean: - rm sample diff --git a/samples/vala/sample.vala b/samples/vala/sample.vala deleted file mode 100644 index 1cec8cf..0000000 --- a/samples/vala/sample.vala +++ /dev/null @@ -1,9 +0,0 @@ -using Libproxy; - -void main () { - var pf = new ProxyFactory (); - string[] proxies = pf.get_proxies ("http://www.google.com"); - foreach (string proxy in proxies) { - stdout.printf ("%s\n", proxy); - } -} 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 - * - * 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 -#include -#include -#include - -/* Import libproxy API */ -#include - -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; -} -- cgit v1.2.1 From eda593d7f1537c9b19680e485d46764db7924682 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 12 Dec 2022 09:32:01 +0000 Subject: Initial commit --- .github/coverity.sh | 62 +++ .github/workflows/build.yml | 109 ++++ .github/workflows/coverity.yml | 39 ++ .gitignore | 2 + COPYING | 502 ++++++++++++++++++ README.md | 37 ++ TODO.md | 43 ++ copyfile.py | 15 + data/check-code-style | 60 +++ data/lineup-parameters | 210 ++++++++ data/uncrustify.cfg | 111 ++++ docs/build-howto.md | 123 +++++ docs/libproxy.svg | 561 +++++++++++++++++++++ docs/meson.build | 40 ++ docs/px.toml.in | 34 ++ docs/samples.md | 4 + docs/samples/dotnet/Makefile | 8 + docs/samples/dotnet/proxy.cs | 38 ++ docs/samples/libcurl/Makefile | 9 + docs/samples/libcurl/curlget.c | 108 ++++ docs/samples/perl/sample.pl | 7 + docs/samples/vala/Makefile | 7 + docs/samples/vala/sample.vala | 9 + docs/version.xml.in | 1 + meson.build | 124 +++++ meson_options.txt | 62 +++ src/backend/dbus/dbus.c | 151 ++++++ src/backend/dbus/meson.build | 48 ++ src/backend/dbus/org.libproxy.proxy.xml | 16 + src/backend/meson.build | 47 ++ src/backend/pacutils.h | 242 +++++++++ src/backend/plugins/config-env/config-env.c | 105 ++++ src/backend/plugins/config-env/config-env.h | 39 ++ src/backend/plugins/config-env/config-env.plugin | 7 + src/backend/plugins/config-env/meson.build | 33 ++ src/backend/plugins/config-gnome/config-gnome.c | 201 ++++++++ src/backend/plugins/config-gnome/config-gnome.h | 34 ++ .../plugins/config-gnome/config-gnome.plugin | 6 + src/backend/plugins/config-gnome/meson.build | 33 ++ src/backend/plugins/config-osx/config-osx.c | 175 +++++++ src/backend/plugins/config-osx/config-osx.h | 39 ++ src/backend/plugins/config-osx/config-osx.plugin | 6 + src/backend/plugins/config-osx/meson.build | 38 ++ .../plugins/config-sysconfig/config-sysconfig.c | 167 ++++++ .../plugins/config-sysconfig/config-sysconfig.h | 35 ++ .../config-sysconfig/config-sysconfig.plugin | 6 + src/backend/plugins/config-sysconfig/meson.build | 34 ++ .../plugins/config-windows/config-windows.c | 180 +++++++ .../plugins/config-windows/config-windows.h | 34 ++ .../plugins/config-windows/config-windows.plugin | 6 + src/backend/plugins/config-windows/meson.build | 38 ++ src/backend/plugins/meson.build | 16 + src/backend/plugins/pacrunner-duktape/meson.build | 36 ++ .../plugins/pacrunner-duktape/pacrunner-duktape.c | 209 ++++++++ .../plugins/pacrunner-duktape/pacrunner-duktape.h | 32 ++ .../pacrunner-duktape/pacrunner-duktape.plugin | 6 + src/backend/px-manager.c | 403 +++++++++++++++ src/backend/px-manager.h | 63 +++ src/backend/px-plugin-config.c | 30 ++ src/backend/px-plugin-config.h | 40 ++ src/backend/px-plugin-pacrunner.c | 29 ++ src/backend/px-plugin-pacrunner.h | 41 ++ src/libproxy/meson.build | 64 +++ src/libproxy/proxy-dbus.c | 130 +++++ src/libproxy/proxy.c | 90 ++++ src/libproxy/proxy.h | 121 +++++ src/meson.build | 4 + src/tests/config-env-test.c | 98 ++++ src/tests/config-sysconfig-test.c | 85 ++++ src/tests/data/sample-sysconfig-proxy | 5 + src/tests/meson.build | 42 ++ src/tests/px-manager-helper.c | 10 + src/tests/px-manager-helper.h | 3 + src/tests/px-manager-test.c | 118 +++++ src/tools/meson.build | 11 + src/tools/proxy.c | 86 ++++ 76 files changed, 5817 insertions(+) create mode 100755 .github/coverity.sh create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/coverity.yml create mode 100644 .gitignore create mode 100644 COPYING create mode 100644 README.md create mode 100644 TODO.md create mode 100644 copyfile.py create mode 100755 data/check-code-style create mode 100755 data/lineup-parameters create mode 100644 data/uncrustify.cfg create mode 100644 docs/build-howto.md create mode 100644 docs/libproxy.svg create mode 100644 docs/meson.build create mode 100644 docs/px.toml.in create mode 100644 docs/samples.md create mode 100644 docs/samples/dotnet/Makefile create mode 100644 docs/samples/dotnet/proxy.cs create mode 100644 docs/samples/libcurl/Makefile create mode 100644 docs/samples/libcurl/curlget.c create mode 100644 docs/samples/perl/sample.pl create mode 100644 docs/samples/vala/Makefile create mode 100644 docs/samples/vala/sample.vala create mode 100644 docs/version.xml.in create mode 100644 meson.build create mode 100644 meson_options.txt create mode 100644 src/backend/dbus/dbus.c create mode 100644 src/backend/dbus/meson.build create mode 100644 src/backend/dbus/org.libproxy.proxy.xml create mode 100644 src/backend/meson.build create mode 100644 src/backend/pacutils.h create mode 100644 src/backend/plugins/config-env/config-env.c create mode 100644 src/backend/plugins/config-env/config-env.h create mode 100644 src/backend/plugins/config-env/config-env.plugin create mode 100644 src/backend/plugins/config-env/meson.build create mode 100644 src/backend/plugins/config-gnome/config-gnome.c create mode 100644 src/backend/plugins/config-gnome/config-gnome.h create mode 100644 src/backend/plugins/config-gnome/config-gnome.plugin create mode 100644 src/backend/plugins/config-gnome/meson.build create mode 100644 src/backend/plugins/config-osx/config-osx.c create mode 100644 src/backend/plugins/config-osx/config-osx.h create mode 100644 src/backend/plugins/config-osx/config-osx.plugin create mode 100644 src/backend/plugins/config-osx/meson.build create mode 100644 src/backend/plugins/config-sysconfig/config-sysconfig.c create mode 100644 src/backend/plugins/config-sysconfig/config-sysconfig.h create mode 100644 src/backend/plugins/config-sysconfig/config-sysconfig.plugin create mode 100644 src/backend/plugins/config-sysconfig/meson.build create mode 100644 src/backend/plugins/config-windows/config-windows.c create mode 100644 src/backend/plugins/config-windows/config-windows.h create mode 100644 src/backend/plugins/config-windows/config-windows.plugin create mode 100644 src/backend/plugins/config-windows/meson.build create mode 100644 src/backend/plugins/meson.build create mode 100644 src/backend/plugins/pacrunner-duktape/meson.build create mode 100644 src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c create mode 100644 src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h create mode 100644 src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin create mode 100644 src/backend/px-manager.c create mode 100644 src/backend/px-manager.h create mode 100644 src/backend/px-plugin-config.c create mode 100644 src/backend/px-plugin-config.h create mode 100644 src/backend/px-plugin-pacrunner.c create mode 100644 src/backend/px-plugin-pacrunner.h create mode 100644 src/libproxy/meson.build create mode 100644 src/libproxy/proxy-dbus.c create mode 100644 src/libproxy/proxy.c create mode 100644 src/libproxy/proxy.h create mode 100644 src/meson.build create mode 100644 src/tests/config-env-test.c create mode 100644 src/tests/config-sysconfig-test.c create mode 100644 src/tests/data/sample-sysconfig-proxy create mode 100644 src/tests/meson.build create mode 100644 src/tests/px-manager-helper.c create mode 100644 src/tests/px-manager-helper.h create mode 100644 src/tests/px-manager-test.c create mode 100644 src/tools/meson.build create mode 100644 src/tools/proxy.c 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..6450e78 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,109 @@ +name: Build + +on: [push, pull_request] + +jobs: + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + sudo apt install \ + libglib2.0-dev \ + libgirepository1.0-dev \ + duktape-dev \ + libsoup-3.0-dev \ + meson \ + gcovr \ + gi-docgen \ + libpeas-dev \ + gsettings-desktop-schemas-dev + - 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 + + # ninja coverage-html -C build + # mkdir build/docs/px-0/coverage/ + # cp -r build/meson-logs/coveragereport/* build/docs/px-0/coverage/ + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: ./build/docs/px-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 libpeas + 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-libpeas + - uses: actions/checkout@v3 + - name: Build and Test + # Disable docs for the moment until msys2 gi-docgen update has landed + run: | + meson setup build -Ddocs=false -Dconfig-sysconfig=false + ninja -C build + ninja -C build test + + # Deploy job + deploy: + # needs: [build-linux, build-osx, build-windows] + needs: build-linux + + 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 \ No newline at end of file diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 0000000..25954cd --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,39 @@ +--- +# vi: ts=2 sw=2 et: +# SPDX-License-Identifier: LGPL-2.1-or-later +# +name: Coverity + +on: + schedule: + # Run Coverity daily at midnight + - cron: '0 0 * * *' + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-22.04 + if: github.repository == 'janbrummer/libproxy2' + 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 install \ + libglib2.0-dev \ + libgirepository1.0-dev \ + duktape-dev \ + libsoup-3.0-dev \ + meson \ + gcovr \ + libpeas-dev \ + gsettings-desktop-schemas-dev + - name: Build & upload the results + run: .github/coverity.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae7a2de --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/_build/ +/build/ diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..4362b49 --- /dev/null +++ b/COPYING @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/README.md b/README.md new file mode 100644 index 0000000..b9e39c1 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) [![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://codecov.io/github/janbrummer/libproxy2) +[![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml) + +# 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 +- no external dependencies within libproxy core +- only 3 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 diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..b558645 --- /dev/null +++ b/TODO.md @@ -0,0 +1,43 @@ +# TODO List + +## Step 1 +- Architecture review + - ZSCaler?? + config module + - Session to System Daemon communication? + + - icon? + -> Dom fragt nach + + Windows Plugin: Finish & Test + + SysConfig Plugin: File monitor + +- Check error handling + +- Async API + -> Yes -> Use Case + +- Shutdown handling! + +- Chemnitzer Linux Tage? + -> Yes :) + + - GNOME plugin: + get_config mode extraction... + + - gi-docgen broken in msys2 + Fatal error in launcher: Unable to find an appended archive. + https://github.com/msys2/MINGW-packages/pull/15171 + +## Step 2 +- Add missing modules +- Check Windows +- Check OS X +- Check BSD + +## Step 3 +- Reach out and add patches to: + - wget + - curl + - Python (requests/pip) diff --git a/copyfile.py b/copyfile.py new file mode 100644 index 0000000..b57734f --- /dev/null +++ b/copyfile.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +# Replace calls to 'cp' with Python + +import shutil +import sys + +if len(sys.argv) < 3: + raise ValueError('Usage: %s ' % sys.argv[0]) + +last_arg_index = len(sys.argv) - 1 +destdir = sys.argv[last_arg_index] + +for x in range(1, last_arg_index): + shutil.copy(sys.argv[x], destdir) 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/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 +# +# 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 . + +# Based on original C lineup-parameters by Sébastien Wilmet +# 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(const\s+)?\w+)' + r'\s+(?P\**)' + r'\s*(?P\w+)' + r'\s*(?P,|\))' + 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/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/docs/build-howto.md b/docs/build-howto.md new file mode 100644 index 0000000..53577d9 --- /dev/null +++ b/docs/build-howto.md @@ -0,0 +1,123 @@ +Title: Compiling with Libproxy +Slug: building + +# Compiling with Libproxy + +The current stable API provides a small synchronnous function set which makes it easy to add it to existing application and libraries. + +The following example is written in C but can be translated as well to every other programming language thanks to gobject-introspection. Furthermore there are +several language samples provided in 'docs/samples' and also linked here in this main documentation. + +## Initialization + +First of all libproxy needs to be initialized. This is done with: + +``` +/** + * px_proxy_factory_new: + * + * 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. + * + * @return A new pxProxyFactory instance or NULL on error + */ +pxProxyFactory *px_proxy_factory_new (void); +``` + +## Get proxy information + +Determining whether a proxy server is need to access a given url use `px_proxy_factory_get_proxies`: + +``` +/** + * px_proxy_factory_get_proxies: + * @self: a #pxProxyFactpry + * @url: Get proxxies for specificed URL + * + * Get which proxies to use for the specified URL. + * + * 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. + * + * 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 (i.e. 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. + * + * 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 + * - ://[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. + * + * For SOCKS proxies, when the protocol version is specified (socks4:// or + * socks5://), it is expected that only this version is used. When only + * socks:// is set, the client MUST try SOCKS version 5 protocol and, on + * connection failure, fallback to SOCKS version 4. + * + * Other proxying protocols may exist. It is expected that the returned + * configuration scheme shall match the network service name of the + * 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 + */ +char **px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url); +``` + +## Freeing proxy list + +Ensure unused proxy information is freed after user with `px_proxy_factory_free_proxies`: + +``` +/** + * px_proxy_factory_free_proxies + * @proxies: proxie array + * + * 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); +``` + +## Destruction + +To close and destroy the `pxProxyFactory` make use of: + +``` +/** + * px_proxy_factory_free: + * @self: a #pxProxyFactory + * + * Frees the pxProxyFactory instance when no longer used. + */ +void px_proxy_factory_free (pxProxyFactory *self); +``` diff --git a/docs/libproxy.svg b/docs/libproxy.svg new file mode 100644 index 0000000..414d9d9 --- /dev/null +++ b/docs/libproxy.svg @@ -0,0 +1,561 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/meson.build b/docs/meson.build new file mode 100644 index 0000000..86cf5c1 --- /dev/null +++ b/docs/meson.build @@ -0,0 +1,40 @@ +if get_option('docs') + +expand_content_md_files = [ + 'build-howto.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, px_backend_gir[0] ], + output: 'px-@0@'.format(apiversion), + 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/px.toml.in b/docs/px.toml.in new file mode 100644 index 0000000..6d495f2 --- /dev/null +++ b/docs/px.toml.in @@ -0,0 +1,34 @@ +[library] +version = "@VERSION@" +description = "Simplifyed proxy handling" +authors = "libproxy Team" +license = "LGPL-2.1-or-later" +browse_url = "https://github.com/janbrummer/libproxy2" +repository_url = "https://github.com/janbrummer/libproxy2" +website_url = "https://janbrummer.github.io/libproxy2/" +logo_url = "libproxy.svg" +dependencies = [ + "GObject-2.0", +] +devhelp = true +search_index = true + +[theme] +name = "basic" +show_index_summary = true +show_class_hierarchy = true + +[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 = [ + "build-howto.md", +] + +content_images = [ + "libproxy.svg" +] \ No newline at end of file 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/docs/samples/dotnet/Makefile b/docs/samples/dotnet/Makefile new file mode 100644 index 0000000..587f83b --- /dev/null +++ b/docs/samples/dotnet/Makefile @@ -0,0 +1,8 @@ + +all: proxy.exe + +proxy.exe: proxy.cs + gmcs -pkg:libproxy-sharp-1.0 proxy.cs + +clean: + rm proxy.exe diff --git a/docs/samples/dotnet/proxy.cs b/docs/samples/dotnet/proxy.cs new file mode 100644 index 0000000..a8ce5e4 --- /dev/null +++ b/docs/samples/dotnet/proxy.cs @@ -0,0 +1,38 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2009 Dominique Leuenberger + * + * 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 libproxy; + +public class proxy { + public static int Main (string[] args) + { + if (args.Length > 0) { + ProxyFactory pf = new ProxyFactory(); + string[] Proxies = pf.GetProxies(args[0]); + Console.WriteLine(Proxies[0]); + pf = null; + return 0; + } else { + Console.WriteLine("Please start the program with one parameter"); + Console.WriteLine("Example: proxy.exe http://libproxy.googlecode.com/"); + return 1; + } + } +} diff --git a/docs/samples/libcurl/Makefile b/docs/samples/libcurl/Makefile new file mode 100644 index 0000000..35b4597 --- /dev/null +++ b/docs/samples/libcurl/Makefile @@ -0,0 +1,9 @@ + + +all: curlget + +curlget: curlget.c + gcc curlget.c -o curlget -Wall -lcurl -std=c99 $(shell pkg-config --libs libproxy-1.0) + +clean: + rm curlget diff --git a/docs/samples/libcurl/curlget.c b/docs/samples/libcurl/curlget.c new file mode 100644 index 0000000..00954e9 --- /dev/null +++ b/docs/samples/libcurl/curlget.c @@ -0,0 +1,108 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2006 Nathaniel McCallum + * Copyright (C) 2008 Dominique Leuenberger + * + * 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 "proxy.h" +#include "curl/curl.h" +#include +#include + +int main(int argc, char * argv[]) { + pxProxyFactory *pf = NULL; + CURL *curl = NULL; + CURLcode result = 1; + + /* Check if we have a parameter passed, otherwise bail out... I need one */ + if (argc < 2) + { + printf("libcurl / libproxy example implementation\n"); + printf("=========================================\n"); + printf("The program has to be started with one parameter\n"); + printf("Defining the URL that should be downloaded\n\n"); + printf("Example: %s http://code.google.com/p/libproxy/\n", argv[0]); + return -1; + } + + /* Initializing curl... has to happen exactly once in the program */ + if (curl_global_init( CURL_GLOBAL_ALL )) return -4; + + /* Create pxProxyFactory object */ + if (!(pf = px_proxy_factory_new())) + { + printf("Unable to create pxProxyFactory object!\n"); + curl_global_cleanup(); + return -2; + } + + /* Create curl handle */ + if (!(curl = curl_easy_init())) + { + printf("Unable to get libcurl handle!\n"); + px_proxy_factory_free(pf); + curl_global_cleanup(); + return -3; + } + + /* Get the array of proxies to try */ + char **proxies = px_proxy_factory_get_proxies(pf, argv[1]); + + /* Set the URL into the curl handle */ + curl_easy_setopt(curl, CURLOPT_URL, argv[1]); + + /* Try to fetch our url using each proxy */ + for (int i=0 ; proxies[i] ; i++) + { + if (result != 0) + { + /* Setup our proxy's config into curl */ + curl_easy_setopt(curl, CURLOPT_PROXY, proxies[i]); + + /* HTTP Proxy */ + if (!strncmp("http", proxies[i], 4)) + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); + + /* SOCKS Proxy, is this correct??? */ + /* What about SOCKS 4A, 5 and 5_HOSTNAME??? */ + else if (!strncmp("socks", proxies[i], 4)) + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + + /* Attempt to fetch the page */ + result = curl_easy_perform(curl); + } + + /* If we reached the end of the proxies array and still did not + succeed to conntect, let's inform the user that we failed. */ + if (proxies[i+1] == NULL && result != 0) + printf ("The requested URL (%s) could not be retrieved using the current setup\n", argv[1]); + + } + + /* Free the proxy array */ + px_proxy_factory_free_proxies(proxies); + + /* Free the curl and libproxy handles */ + px_proxy_factory_free(pf); + curl_easy_cleanup(curl); + + /* Cleanup the libcurl library */ + curl_global_cleanup(); + return 0; + +} + diff --git a/docs/samples/perl/sample.pl b/docs/samples/perl/sample.pl new file mode 100644 index 0000000..e8850fc --- /dev/null +++ b/docs/samples/perl/sample.pl @@ -0,0 +1,7 @@ +use Net::Libproxy; + +$p = new Net::Libproxy; +$proxies = $p->getProxies('http://www.google.com'); +foreach my $proxy (@$proxies) { + print $proxy."\n"; +} diff --git a/docs/samples/vala/Makefile b/docs/samples/vala/Makefile new file mode 100644 index 0000000..3e42a34 --- /dev/null +++ b/docs/samples/vala/Makefile @@ -0,0 +1,7 @@ +all: sample + +sample: sample.vala + valac --pkg libproxy-1.0 sample.vala + +clean: + rm sample diff --git a/docs/samples/vala/sample.vala b/docs/samples/vala/sample.vala new file mode 100644 index 0000000..1cec8cf --- /dev/null +++ b/docs/samples/vala/sample.vala @@ -0,0 +1,9 @@ +using Libproxy; + +void main () { + var pf = new ProxyFactory (); + string[] proxies = pf.get_proxies ("http://www.google.com"); + 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/meson.build b/meson.build new file mode 100644 index 0000000..89eff87 --- /dev/null +++ b/meson.build @@ -0,0 +1,124 @@ +project('libproxy', 'c', + version: '0.5.0', + meson_version: '>= 0.59.0', + default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu11', ], +) + +cc = meson.get_compiler('c') + +root_dir = include_directories('.') + +px_prefix = get_option('prefix') +px_libdir = join_paths(px_prefix, get_option('libdir')) +px_plugins_dir = join_paths(px_libdir, meson.project_name().to_lower(), 'plugins') + +config_h = configuration_data() +config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) +config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) +configure_file(output: 'config.h', configuration: config_h) +add_project_arguments(['-I' + meson.project_build_root()], language: 'c') + +version_arr = meson.project_version().split('-')[0].split('.') +libproxy_version_major = version_arr[0].to_int() +libproxy_version_minor = version_arr[1].to_int() +apiversion = libproxy_version_major.to_string() + +libproxy_prefix = get_option('prefix') +datadir = get_option('datadir') + +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'], +] +#if get_option('buildtype') != 'plain' +# test_c_args += '-fstack-protector-strong' +#endif +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') + +module_suffix = [] +# Keep the autotools convention for shared module suffix because GModule +# depends on it. +if ['darwin', 'ios'].contains(host_system) + module_suffix = 'so' +endif + +glib_dep = dependency('glib-2.0', version: '>= 2.71.3') +gio_dep = dependency('gio-2.0', version: '>= 2.71.3') +peas_dep = dependency('libpeas-1.0') +soup_dep = dependency('libsoup-3.0') +ws2_32_dep = cc.find_library('ws2_32', required : with_platform_windows) +gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get_option('config-gnome')) + +subdir('src') +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') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..bfeecb8 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,62 @@ +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( + 'dbus', + type: 'boolean', + value: false, + description: 'Whether to build dbus service' +) + +option( + 'config-env', + type: 'boolean', + value: true, + description: 'Whether to build plugin for environment configuration' +) + +option( + 'config-gnome', + type: 'boolean', + value: true, + description: 'Whether to build plugin for GNOME configuration' +) + +option( + 'config-windows', + type: 'boolean', + value: true, + description: 'Whether to build plugin for Windows configuration' +) + +option( + 'config-sysconfig', + type: 'boolean', + value: true, + description: 'Whether to build plugin for sysconfig configuration' +) + +option( + 'config-osx', + type: 'boolean', + value: true, + description: 'Whether to build plugin for OS X configuration' +) + +option( + 'pacrunner-duktape', + type: 'boolean', + value: true, + description: 'Whether to build plugin for PAC Runner Duktape' +) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c new file mode 100644 index 0000000..0dd7d75 --- /dev/null +++ b/src/backend/dbus/dbus.c @@ -0,0 +1,151 @@ +/* main.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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-interface.h" + +#include + +static void +handle_method_call (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *method_name, + GVariant *parameters, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + PxManager *manager = PX_MANAGER (user_data); + GVariantBuilder *result; + g_auto (GStrv) proxies = NULL; + g_autoptr (GError) error = NULL; + const gchar *url; + int idx; + + if (g_strcmp0 (method_name, "query") != 0) { + g_warning ("Invalid method name '%s', aborting.", method_name); + g_dbus_method_invocation_return_error (invocation, + PX_MANAGER_ERROR, + PX_MANAGER_ERROR_UNKNOWN_METHOD, + "Unknown method"); + return; + } + + g_variant_get (parameters, "(&s)", &url); + + proxies = px_manager_get_proxies_sync (manager, url, &error); + if (error) { + g_warning ("Could not query proxy servers: %s", error->message); + g_dbus_method_invocation_return_gerror (invocation, error); + return; + } + + result = g_variant_builder_new (G_VARIANT_TYPE ("as")); + if (proxies) { + for (idx = 0; proxies[idx]; idx++) { + g_variant_builder_add (result, "s", proxies[idx]); + } + } + + g_dbus_method_invocation_return_value (invocation, + g_variant_new ("(as)", result)); +} + +static GVariant * +handle_get_property (GDBusConnection *connection, + const gchar *sender, + const gchar *object_path, + const gchar *interface_name, + const gchar *property_name, + GError **error, + gpointer user_data) +{ + GVariant *ret = NULL; + + if (g_strcmp0 (property_name, "APIVersion") == 0) + ret = g_variant_new_string ("1.0"); + + return ret; +} + +static const GDBusInterfaceVTable interface_vtable = { + handle_method_call, + handle_get_property +}; + +static void +on_bus_acquired (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + g_autoptr (GError) error = NULL; + PxManager *manager = NULL; + + manager = px_manager_new (); + g_dbus_connection_register_object (connection, + "/org/libproxy/proxy", + (GDBusInterfaceInfo *)&org_libproxy_proxy_interface, + &interface_vtable, + manager, + g_object_unref, + &error); + if (error) { + g_warning ("Could not register dbus object: %s", error->message); + g_main_loop_quit (user_data); + return; + } +} + +static void +on_name_lost (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + if (!connection) { + g_warning ("Can't connect proxy bus"); + g_main_loop_quit (user_data); + } else { + g_warning ("Unknown name lost error"); + } +} + +int +main (int argc, + char **argv) +{ + GMainLoop *loop; + + loop = g_main_loop_new (NULL, FALSE); + + g_bus_own_name (G_BUS_TYPE_SESSION, + "org.libproxy.proxy", + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + NULL, + on_name_lost, + loop, + NULL); + + g_main_loop_run (loop); + + return 0; +} diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build new file mode 100644 index 0000000..5222a5f --- /dev/null +++ b/src/backend/dbus/meson.build @@ -0,0 +1,48 @@ +if get_option('dbus') + gdbus_codegen = find_program('gdbus-codegen') + + px_interface = [ + 'org.libproxy.proxy.xml' + ] + + px_interface_h = custom_target( + 'px-interface.h', + input: px_interface, + output: ['px-interface.h'], + command: [ + gdbus_codegen, + '--interface-info-header', + '--output', '@OUTPUT@', + '@INPUT@' + ] + ) + + px_interface_c = custom_target( + 'libproxy-iface.c', + input: px_interface, + output: ['px-interface.c'], + command: [ + gdbus_codegen, + '--interface-info-body', + '--output', '@OUTPUT@', + '@INPUT@' + ], + ) + + proxyd_sources = [ + px_interface_c, + px_interface_h, + 'dbus.c', + ] + + proxyd_deps = [ + px_backend_dep + ] + + executable( + 'proxyd', + proxyd_sources, + dependencies: proxyd_deps, + install: true, + ) +endif diff --git a/src/backend/dbus/org.libproxy.proxy.xml b/src/backend/dbus/org.libproxy.proxy.xml new file mode 100644 index 0000000..c180df1 --- /dev/null +++ b/src/backend/dbus/org.libproxy.proxy.xml @@ -0,0 +1,16 @@ + + + + + + + + + + Ask for proxy server for given url. + + + + + + diff --git a/src/backend/meson.build b/src/backend/meson.build new file mode 100644 index 0000000..abadcc5 --- /dev/null +++ b/src/backend/meson.build @@ -0,0 +1,47 @@ +api_version = '1.0' + +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 = [ + gio_dep, + glib_dep, + soup_dep, + peas_dep, +] + +px_backend_inc = include_directories('.') + +px_backend_lib = shared_library( + 'pxbackend-@0@'.format(api_version), + px_backend_sources, + dependencies: px_backend_deps, + install: true +) + +gnome = import('gnome') +px_backend_gir = gnome.generate_gir( + px_backend_lib, + sources: px_backend_sources, + nsversion: api_version, + namespace: 'Px', + symbol_prefix: 'px', + identifier_prefix: 'Px', + includes: [ 'Gio-2.0' ], + install: true, +) + +px_backend_dep = declare_dependency( + include_directories: px_backend_inc, + link_with: px_backend_lib, + dependencies: px_backend_deps +) + +subdir('dbus') +subdir('plugins') diff --git a/src/backend/pacutils.h b/src/backend/pacutils.h new file mode 100644 index 0000000..3826014 --- /dev/null +++ b/src/backend/pacutils.h @@ -0,0 +1,242 @@ +/* + * The following Javascript code was taken from Mozilla (http://www.mozilla.org) + * and is licensed according to the LGPLv2.1+. Below is the original copyright + * header as contained in the source file (nsProxyAutoConfig.js) + */ + +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Akhil Arora + * Tomi Leppikangas + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#define JAVASCRIPT_ROUTINES \ +"function dnsDomainIs(host, domain) {\n" \ +" return (host.length >= domain.length &&\n" \ +" host.substring(host.length - domain.length) == domain);\n" \ +"}\n" \ +"function dnsDomainLevels(host) {\n" \ +" return host.split('.').length-1;\n" \ +"}\n" \ +"function convert_addr(ipchars) {\n" \ +" var bytes = ipchars.split('.');\n" \ +" var result = ((bytes[0] & 0xff) << 24) |\n" \ +" ((bytes[1] & 0xff) << 16) |\n" \ +" ((bytes[2] & 0xff) << 8) |\n" \ +" (bytes[3] & 0xff);\n" \ +" return result;\n" \ +"}\n" \ +"function isInNet(ipaddr, pattern, maskstr) {\n"\ +" var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(ipaddr);\n"\ +" if (test == null) {\n"\ +" ipaddr = dnsResolve(ipaddr);\n"\ +" if (ipaddr == null)\n"\ +" return false;\n"\ +" } else if (test[1] > 255 || test[2] > 255 || \n"\ +" test[3] > 255 || test[4] > 255) {\n"\ +" return false; // not an IP address\n"\ +" }\n"\ +" var host = convert_addr(ipaddr);\n"\ +" var pat = convert_addr(pattern);\n"\ +" var mask = convert_addr(maskstr);\n"\ +" return ((host & mask) == (pat & mask));\n"\ +" \n"\ +"}\n"\ +"function isPlainHostName(host) {\n" \ +" return (host.search('\\\\.') == -1);\n" \ +"}\n" \ +"function isResolvable(host) {\n" \ +" var ip = dnsResolve(host);\n" \ +" return (ip != null);\n" \ +"}\n" \ +"function localHostOrDomainIs(host, hostdom) {\n" \ +" if (isPlainHostName(host)) {\n" \ +" return (hostdom.search('/^' + host + '/') != -1);\n" \ +" }\n" \ +" else {\n" \ +" return (host == hostdom);\n" \ +" }\n" \ +"}\n" \ +"function shExpMatch(url, pattern) {\n" \ +" pattern = pattern.replace(/\\./g, '\\\\.');\n" \ +" pattern = pattern.replace(/\\*/g, '.*');\n" \ +" pattern = pattern.replace(/\\?/g, '.');\n" \ +" var newRe = new RegExp('^'+pattern+'$');\n" \ +" return newRe.test(url);\n" \ +"}\n" \ +"var wdays = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};\n" \ +"var months = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};\n"\ +"function weekdayRange() {\n" \ +" function getDay(weekday) {\n" \ +" if (weekday in wdays) {\n" \ +" return wdays[weekday];\n" \ +" }\n" \ +" return -1;\n" \ +" }\n" \ +" var date = new Date();\n" \ +" var argc = arguments.length;\n" \ +" var wday;\n" \ +" if (argc < 1)\n" \ +" return false;\n" \ +" if (arguments[argc - 1] == 'GMT') {\n" \ +" argc--;\n" \ +" wday = date.getUTCDay();\n" \ +" } else {\n" \ +" wday = date.getDay();\n" \ +" }\n" \ +" var wd1 = getDay(arguments[0]);\n" \ +" var wd2 = (argc == 2) ? getDay(arguments[1]) : wd1;\n" \ +" return (wd1 == -1 || wd2 == -1) ? false\n" \ +" : (wd1 <= wday && wday <= wd2);\n" \ +"}\n" \ +"function dateRange() {\n" \ +" function getMonth(name) {\n" \ +" if (name in months) {\n" \ +" return months[name];\n" \ +" }\n" \ +" return -1;\n" \ +" }\n" \ +" var date = new Date();\n" \ +" var argc = arguments.length;\n" \ +" if (argc < 1) {\n" \ +" return false;\n" \ +" }\n" \ +" var isGMT = (arguments[argc - 1] == 'GMT');\n" \ +" if (isGMT) {\n" \ +" argc--;\n" \ +" }\n" \ +" if (argc == 1) {\n" \ +" var tmp = parseInt(arguments[0]);\n" \ +" if (isNaN(tmp)) {\n" \ +" return ((isGMT ? date.getUTCMonth() : date.getMonth()) == getMonth(arguments[0]));\n" \ +" } else if (tmp < 32) {\n" \ +" return ((isGMT ? date.getUTCDate() : date.getDate()) == tmp);\n" \ +" } else {\n" \ +" return ((isGMT ? date.getUTCFullYear() : date.getFullYear()) == tmp);\n" \ +" }\n" \ +" }\n" \ +" var year = date.getFullYear();\n" \ +" var date1, date2;\n" \ +" date1 = new Date(year, 0, 1, 0, 0, 0);\n" \ +" date2 = new Date(year, 11, 31, 23, 59, 59);\n" \ +" var adjustMonth = false;\n" \ +" for (var i = 0; i < (argc >> 1); i++) {\n" \ +" var tmp = parseInt(arguments[i]);\n" \ +" if (isNaN(tmp)) {\n" \ +" var mon = getMonth(arguments[i]);\n" \ +" date1.setMonth(mon);\n" \ +" } else if (tmp < 32) {\n" \ +" adjustMonth = (argc <= 2);\n" \ +" date1.setDate(tmp);\n" \ +" } else {\n" \ +" date1.setFullYear(tmp);\n" \ +" }\n" \ +" }\n" \ +" for (var i = (argc >> 1); i < argc; i++) {\n" \ +" var tmp = parseInt(arguments[i]);\n" \ +" if (isNaN(tmp)) {\n" \ +" var mon = getMonth(arguments[i]);\n" \ +" date2.setMonth(mon);\n" \ +" } else if (tmp < 32) {\n" \ +" date2.setDate(tmp);\n" \ +" } else {\n" \ +" date2.setFullYear(tmp);\n" \ +" }\n" \ +" }\n" \ +" if (adjustMonth) {\n" \ +" date1.setMonth(date.getMonth());\n" \ +" date2.setMonth(date.getMonth());\n" \ +" }\n" \ +" if (isGMT) {\n" \ +" var tmp = date;\n" \ +" tmp.setFullYear(date.getUTCFullYear());\n" \ +" tmp.setMonth(date.getUTCMonth());\n" \ +" tmp.setDate(date.getUTCDate());\n" \ +" tmp.setHours(date.getUTCHours());\n" \ +" tmp.setMinutes(date.getUTCMinutes());\n" \ +" tmp.setSeconds(date.getUTCSeconds());\n" \ +" date = tmp;\n" \ +" }\n" \ +" return ((date1 <= date) && (date <= date2));\n" \ +"}\n" \ +"function timeRange() {\n" \ +" var argc = arguments.length;\n" \ +" var date = new Date();\n" \ +" var isGMT= false;\n" \ +" if (argc < 1) {\n" \ +" return false;\n" \ +" }\n" \ +" if (arguments[argc - 1] == 'GMT') {\n" \ +" isGMT = true;\n" \ +" argc--;\n" \ +" }\n" \ +" var hour = isGMT ? date.getUTCHours() : date.getHours();\n" \ +" var date1, date2;\n" \ +" date1 = new Date();\n" \ +" date2 = new Date();\n" \ +" if (argc == 1) {\n" \ +" return (hour == arguments[0]);\n" \ +" } else if (argc == 2) {\n" \ +" return ((arguments[0] <= hour) && (hour <= arguments[1]));\n" \ +" } else {\n" \ +" switch (argc) {\n" \ +" case 6:\n" \ +" date1.setSeconds(arguments[2]);\n" \ +" date2.setSeconds(arguments[5]);\n" \ +" case 4:\n" \ +" var middle = argc >> 1;\n" \ +" date1.setHours(arguments[0]);\n" \ +" date1.setMinutes(arguments[1]);\n" \ +" date2.setHours(arguments[middle]);\n" \ +" date2.setMinutes(arguments[middle + 1]);\n" \ +" if (middle == 2) {\n" \ +" date2.setSeconds(59);\n" \ +" }\n" \ +" break;\n" \ +" default:\n" \ +" throw 'timeRange: bad number of arguments'\n" \ +" }\n" \ +" }\n" \ +" if (isGMT) {\n" \ +" date.setFullYear(date.getUTCFullYear());\n" \ +" date.setMonth(date.getUTCMonth());\n" \ +" date.setDate(date.getUTCDate());\n" \ +" date.setHours(date.getUTCHours());\n" \ +" date.setMinutes(date.getUTCMinutes());\n" \ +" date.setSeconds(date.getUTCSeconds());\n" \ +" }\n" \ +" return ((date1 <= date) && (date <= date2));\n" \ +"}\n" \ +"" diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c new file mode 100644 index 0000000..aca96da --- /dev/null +++ b/src/backend/plugins/config-env/config-env.c @@ -0,0 +1,105 @@ +/* config-env.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 + +#include "config-env.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +static void px_config_iface_init (PxConfigInterface *iface); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigEnv, + px_config_env, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +static void +px_config_env_init (PxConfigEnv *self) +{ +} + +static void +px_config_env_class_init (PxConfigEnvClass *klass) +{ +} + +static gboolean +px_config_env_is_available (PxConfig *self) +{ + return TRUE; +} + +static gboolean +px_config_env_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder, + GError **error) +{ + const char *proxy = NULL; + const char *scheme = g_uri_get_scheme (uri); + const char *ignore = NULL; + + ignore = g_getenv ("no_proxy"); + if (!ignore) + ignore = g_getenv ("NO_PROXY"); + + if (ignore && strstr (ignore, g_uri_get_host (uri))) + return TRUE; + + if (g_strcmp0 (scheme, "ftp") == 0) { + proxy = g_getenv ("ftp_proxy"); + if (!proxy) + proxy = g_getenv ("FTP_PROXY"); + } else if (g_strcmp0 (scheme, "https") == 0) { + proxy = g_getenv ("https_proxy"); + if (!proxy) + proxy = g_getenv ("HTTPS_PROXY"); + } + + if (!proxy) { + proxy = g_getenv ("http_proxy"); + if (!proxy) + proxy = g_getenv ("HTTP_PROXY"); + } + + if (proxy) + g_strv_builder_add (builder, proxy); + + return TRUE; +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->is_available = px_config_env_is_available; + iface->get_config = px_config_env_get_config; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_CONFIG, + PX_CONFIG_TYPE_ENV); +} diff --git a/src/backend/plugins/config-env/config-env.h b/src/backend/plugins/config-env/config-env.h new file mode 100644 index 0000000..bbe74d4 --- /dev/null +++ b/src/backend/plugins/config-env/config-env.h @@ -0,0 +1,39 @@ +/* config-env.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +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) + +struct _PxConfigEnv { + GObject parent_instance; +}; + +G_END_DECLS + + diff --git a/src/backend/plugins/config-env/config-env.plugin b/src/backend/plugins/config-env/config-env.plugin new file mode 100644 index 0000000..34b3049 --- /dev/null +++ b/src/backend/plugins/config-env/config-env.plugin @@ -0,0 +1,7 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Read proxy configuration from environment variables +Module=config-env +Name=Environment Variables +Builtin=True \ No newline at end of file diff --git a/src/backend/plugins/config-env/meson.build b/src/backend/plugins/config-env/meson.build new file mode 100644 index 0000000..9496775 --- /dev/null +++ b/src/backend/plugins/config-env/meson.build @@ -0,0 +1,33 @@ +plugin_name = 'config-env' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + sources: plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +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..f894498 --- /dev/null +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -0,0 +1,201 @@ +/* config-gnome.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +#include "config-gnome.h" +#include "px-plugin-config.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 settings_found; +}; + +enum { + GNOME_PROXY_MODE_NONE, + GNOME_PROXY_MODE_MANUAL, + GNOME_PROXY_MODE_AUTO +}; + +static void px_config_iface_init (PxConfigInterface *iface); +void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigGnome, + px_config_gnome, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +static void +px_config_gnome_init (PxConfigGnome *self) +{ + GSettingsSchemaSource *source = g_settings_schema_source_get_default (); + GSettingsSchema *proxy_schema; + + if (!source) + return; + + proxy_schema = g_settings_schema_source_lookup (source, "org.gnome.system.proxy", TRUE); + + self->settings_found = proxy_schema != NULL; + g_clear_pointer (&proxy_schema, g_settings_schema_unref); + + if (!self->settings_found) + 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_class_init (PxConfigGnomeClass *klass) +{ +} + +static gboolean +px_config_gnome_is_available (PxConfig *config) +{ + PxConfigGnome *self = PX_CONFIG_GNOME (config); + const char *desktops; + + if (!self->settings_found) + return FALSE; + + desktops = getenv ("XDG_CURRENT_DESKTOP"); + if (!desktops) + return FALSE; + + /* Remember that XDG_CURRENT_DESKTOP is a list of strings. */ + return strstr (desktops, "GNOME") != NULL; +} + +static void +store_response (GStrvBuilder *builder, + const char *type, + char *host, + int port, + gboolean auth, + char *username, + char *password) +{ + if (host && port != 0) { + 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); + + g_strv_builder_add (builder, g_string_free (tmp, TRUE)); + } +} + +static gboolean +px_config_gnome_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder, + GError **error) +{ + PxConfigGnome *self = PX_CONFIG_GNOME (config); + g_autofree char *proxy = NULL; + int mode; + + 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://"); + + g_strv_builder_add (builder, proxy); + } else if (mode == GNOME_PROXY_MODE_MANUAL) { + gboolean auth = g_settings_get_boolean (self->http_proxy_settings, "use-authentication"); + 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); + + 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->ftp_proxy_settings, "port"), + auth, + username, + password); + } + } + + return TRUE; +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->is_available = px_config_gnome_is_available; + iface->get_config = px_config_gnome_get_config; +} + +void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_CONFIG, + PX_CONFIG_TYPE_GNOME); +} diff --git a/src/backend/plugins/config-gnome/config-gnome.h b/src/backend/plugins/config-gnome/config-gnome.h new file mode 100644 index 0000000..53402e9 --- /dev/null +++ b/src/backend/plugins/config-gnome/config-gnome.h @@ -0,0 +1,34 @@ +/* config-gnome.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 + +G_BEGIN_DECLS + +#define PX_CONFIG_TYPE_GNOME (px_config_gnome_get_type ()) + +G_DECLARE_FINAL_TYPE (PxConfigGnome, px_config_gnome, PX, CONFIG_GNOME, GObject) + +G_END_DECLS + + diff --git a/src/backend/plugins/config-gnome/config-gnome.plugin b/src/backend/plugins/config-gnome/config-gnome.plugin new file mode 100644 index 0000000..2b3f442 --- /dev/null +++ b/src/backend/plugins/config-gnome/config-gnome.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Read proxy configuration from GNOME settings +Module=config-gnome +Name=GNOME Settings \ No newline at end of file diff --git a/src/backend/plugins/config-gnome/meson.build b/src/backend/plugins/config-gnome/meson.build new file mode 100644 index 0000000..ba99418 --- /dev/null +++ b/src/backend/plugins/config-gnome/meson.build @@ -0,0 +1,33 @@ +plugin_name = 'config-gnome' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + plugin_src, + include_directories: px_backend_inc, + dependencies: [peas_dep, px_backend_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +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..6ccd298 --- /dev/null +++ b/src/backend/plugins/config-osx/config-osx.c @@ -0,0 +1,175 @@ +/* config-osx.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +#include "config-osx.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +static void px_config_iface_init (PxConfigInterface *iface); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigOsX, + px_config_osx, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +static void +px_config_osx_init (PxConfigOsX *self) +{ +} + +static void +px_config_osx_class_init (PxConfigOsXClass *klass) +{ +} + +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 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 gboolean +px_config_osx_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder, + GError **error) +{ + const char *proxy = NULL; + CFDictionaryRef proxies = SCDynamicStoreCopyProxies (NULL); + + if (!proxies) { + g_warning ("Unable to fetch proxy configuration"); + return FALSE; + } + + if (getbool(proxies, "ProxyAutoDiscoveryEnable")) { + CFRelease (proxies); + g_strv_builder_add (builder, "wpad://"); + return TRUE; + } + + if (getbool (proxies, "ProxyAutoConfigEnable")) { + CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString"); + const char *tmp = CFStringGetCStringPtr (ref, CFStringGetFastestEncoding (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); + g_strv_builder_add (builder, ret); + return TRUE; + } + } + + g_print ("%s: Whatever", __FUNCTION__); + if (proxy) + g_strv_builder_add (builder, proxy); + + return TRUE; +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->is_available = px_config_osx_is_available; + iface->get_config = px_config_osx_get_config; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_CONFIG, + PX_CONFIG_TYPE_OSX); +} 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..62e71ca --- /dev/null +++ b/src/backend/plugins/config-osx/config-osx.h @@ -0,0 +1,39 @@ +/* config-osx.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +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) + +struct _PxConfigOsX { + GObject parent_instance; +}; + +G_END_DECLS + + diff --git a/src/backend/plugins/config-osx/config-osx.plugin b/src/backend/plugins/config-osx/config-osx.plugin new file mode 100644 index 0000000..25e4bdd --- /dev/null +++ b/src/backend/plugins/config-osx/config-osx.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Read proxy configuration from OS X +Module=config-osx +Name=OS X \ No newline at end of file diff --git a/src/backend/plugins/config-osx/meson.build b/src/backend/plugins/config-osx/meson.build new file mode 100644 index 0000000..4435bbf --- /dev/null +++ b/src/backend/plugins/config-osx/meson.build @@ -0,0 +1,38 @@ +plugin_name = 'config-osx' + +if host_machine.system() == 'darwin' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + build_by_default: true, + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +endif + +endif \ No newline at end of file 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..dd19893 --- /dev/null +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -0,0 +1,167 @@ +/* config-sysconfig.c + * + * Copyright 2023 Jan-Michael Brummer + * + * 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 + +#include "config-sysconfig.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +struct _PxConfigSysConfig { + GObject parent_instance; + + char *proxy_file; + gboolean available; + + gboolean proxy_enabled; + char *https_proxy; + char *http_proxy; + char *ftp_proxy; + char *no_proxy; +}; + +static void px_config_iface_init (PxConfigInterface *iface); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigSysConfig, + px_config_sysconfig, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +static void +px_config_sysconfig_init (PxConfigSysConfig *self) +{ + g_autoptr (GFile) file = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GFileInputStream) istr = NULL; + g_autoptr (GDataInputStream) dstr = NULL; + const char *test_file = g_getenv ("PX_CONFIG_SYSCONFIG"); + char *line = NULL; + + self->proxy_file = g_strdup (test_file ? test_file : "/etc/sysconfig/proxy"); + self->available = FALSE; + + file = g_file_new_for_path (self->proxy_file); + if (!file) { + g_debug ("Could not create file\n"); + return; + } + + istr = g_file_read(file, NULL, NULL); + if (!istr) { + g_debug ("Could not read file\n"); + return; + } + + dstr = g_data_input_stream_new(G_INPUT_STREAM(istr)); + if (!dstr) + return; + + 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); + + if (strcmp (kv[0], "PROXY_ENABLED") == 0) { + self->proxy_enabled = g_ascii_strncasecmp (value->str, "yes", 4) == 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) { + self->no_proxy = g_strdup (value->str); + } + } + } while (line); + + self->available = TRUE; +} + +static void +px_config_sysconfig_class_init (PxConfigSysConfigClass *klass) +{ +} + +static gboolean +px_config_sysconfig_is_available (PxConfig *config) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (config); + + return self->available; +} + +static gboolean +px_config_sysconfig_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder, + GError **error) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (config); + const char *scheme = g_uri_get_scheme (uri); + g_autofree char *proxy = NULL; + + if (!self->proxy_enabled) + return TRUE; + + if (self->no_proxy && strstr (self->no_proxy, g_uri_get_host (uri))) + return TRUE; + + 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) + g_strv_builder_add (builder, proxy); + + return TRUE; +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->is_available = px_config_sysconfig_is_available; + iface->get_config = px_config_sysconfig_get_config; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_CONFIG, + PX_CONFIG_TYPE_SYSCONFIG); +} 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..176da94 --- /dev/null +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.h @@ -0,0 +1,35 @@ +/* config-sysconfig.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +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/config-sysconfig.plugin b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin new file mode 100644 index 0000000..d164295 --- /dev/null +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Read proxy configuration from /etc/sysconfig/proxy +Module=config-sysconfig +Name=sysconfig \ No newline at end of file diff --git a/src/backend/plugins/config-sysconfig/meson.build b/src/backend/plugins/config-sysconfig/meson.build new file mode 100644 index 0000000..d5b3613 --- /dev/null +++ b/src/backend/plugins/config-sysconfig/meson.build @@ -0,0 +1,34 @@ +plugin_name = 'config-sysconfig' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + build_by_default: true, + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +endif \ No newline at end of file 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..14ac064 --- /dev/null +++ b/src/backend/plugins/config-windows/config-windows.c @@ -0,0 +1,180 @@ +/* config-windows.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include +#include + +#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); +void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigWindows, + px_config_windows, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) + +static void +px_config_windows_init (PxConfigWindows *self) +{ +} + +static void +px_config_windows_class_init (PxConfigWindowsClass *klass) +{ +} + +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 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 gboolean +px_config_windows_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder, + GError **error) +{ + char *tmp = NULL; + guint32 enabled = 0; + + if (get_registry (W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) { + g_print ("Override: %s\n", tmp); + } + + /* WPAD */ + if (is_enabled (W32REG_OFFSET_WPAD)) { + g_strv_builder_add (builder, "wpad://"); + return TRUE; + } + + /* 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) { + g_strv_builder_add (builder, pac_uri); + return TRUE; + } + } + + /* Manual proxy */ + if (get_registry (W32REG_BASEKEY, "ProxyEnable", NULL, NULL, &enabled) && enabled && get_registry (W32REG_BASEKEY, "ProxyServer", &tmp, NULL, NULL)) { + g_autofree char *http_proxy = g_strconcat ("http://", tmp, NULL); + /* TODO */ + g_strv_builder_add (builder, http_proxy); + return TRUE; + } + + return TRUE; +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->is_available = px_config_windows_is_available; + iface->get_config = px_config_windows_get_config; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_CONFIG, + PX_CONFIG_TYPE_WINDOWS); +} 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..e7706e5 --- /dev/null +++ b/src/backend/plugins/config-windows/config-windows.h @@ -0,0 +1,34 @@ +/* config-windows.h + * + * Copyright 2023 Jan-Michael Brummer + * + * 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 + +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/config-windows.plugin b/src/backend/plugins/config-windows/config-windows.plugin new file mode 100644 index 0000000..e8af810 --- /dev/null +++ b/src/backend/plugins/config-windows/config-windows.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Read proxy configuration from Windows registry +Module=config-windows +Name=Windows \ No newline at end of file diff --git a/src/backend/plugins/config-windows/meson.build b/src/backend/plugins/config-windows/meson.build new file mode 100644 index 0000000..9416e34 --- /dev/null +++ b/src/backend/plugins/config-windows/meson.build @@ -0,0 +1,38 @@ +plugin_name = 'config-windows' + +if host_machine.system() == 'windows' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + build_by_default: true, + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +endif + +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..6a91379 --- /dev/null +++ b/src/backend/plugins/meson.build @@ -0,0 +1,16 @@ +subdir('config-env') +subdir('config-gnome') +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 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..41ab6cc --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/meson.build @@ -0,0 +1,36 @@ +plugin_name = 'pacrunner-duktape' + +if get_option(plugin_name) + +duktape_dep = dependency('duktape') + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep, duktape_dep, ws2_32_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + build_by_default: true, + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +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..86221f3 --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -0,0 +1,209 @@ +/* pacrunner-duktape.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 + +#include +#ifdef __WIN32__ +#include +#else +#include +#endif +#include + +#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); +void peas_register_types (PeasObjectModule *module); + +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->constructed = px_duktape_constructed; */ + object_class->dispose = px_pacrunner_duktape_dispose; +} + +static void +px_pacrunner_duktape_set_pac (PxPacRunner *pacrunner, + GBytes *pac_data) +{ + PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (pacrunner); + + + duk_push_string (self->ctx, g_bytes_get_data (pac_data, NULL)); + + if (duk_peval_noresult (self->ctx)) { + return; + } +} + +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; +} + +void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_PACRUNNER, + PX_PACRUNNER_TYPE_DUKTAPE); +} 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..90fc119 --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h @@ -0,0 +1,32 @@ +/* pacrunner-duktape.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 + +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/plugins/pacrunner-duktape/pacrunner-duktape.plugin b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin new file mode 100644 index 0000000..26dd8b2 --- /dev/null +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Parse PAC files with duktape +Module=pacrunner-duktape +Name=Duktape \ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c new file mode 100644 index 0000000..999af09 --- /dev/null +++ b/src/backend/px-manager.c @@ -0,0 +1,403 @@ +/* px-manager.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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-manager.h" +#include "px-plugin-config.h" +#include "px-plugin-pacrunner.h" + +#include +#include + +enum { + PROP_0, + PROP_PLUGINS_DIR, + LAST_PROP +}; + +static GParamSpec *obj_properties[LAST_PROP]; + +/** + * PxManager: + * + * Manage libproxy modules + */ + +/* TODO: Move to private structure */ +struct _PxManager { + GObject parent_instance; + PeasEngine *engine; + PeasExtensionSet *config_set; + PeasExtensionSet *pacrunner_set; + char *plugins_dir; + GCancellable *cancellable; + SoupSession *session; + + 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_constructed (GObject *object) +{ + PxManager *self = PX_MANAGER (object); + const GList *list; + const char *requested_config_plugin = g_getenv ("PX_CONFIG_PLUGIN"); + + self->session = soup_session_new (); + + self->engine = peas_engine_get_default (); + + peas_engine_add_search_path (self->engine, self->plugins_dir, NULL); + + self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, NULL); + self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); + list = peas_engine_get_plugin_list (self->engine); + for (; list && list->data; list = list->next) { + PeasPluginInfo *info = PEAS_PLUGIN_INFO (list->data); + PeasExtension *extension = peas_extension_set_get_extension (self->config_set, info); + gboolean available = TRUE; + + if (!peas_plugin_info_is_loaded (info)) { + /* In case user requested a specific module, just load that one */ + if (requested_config_plugin) { + if (g_strcmp0 (peas_plugin_info_get_module_name (info), requested_config_plugin) == 0) + peas_engine_load_plugin (self->engine, info); + } else { + peas_engine_load_plugin (self->engine, info); + } + } + + extension = peas_extension_set_get_extension (self->config_set, info); + if (extension) { + PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (extension); + + available = ifc->is_available (PX_CONFIG (extension)); + } + + if (!available) + peas_engine_unload_plugin (self->engine, info); + } +} + +static void +px_manager_dispose (GObject *object) +{ + PxManager *self = PX_MANAGER (object); + + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->cancellable); + g_clear_pointer (&self->plugins_dir, g_free); + g_clear_object (&self->engine); + + 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_PLUGINS_DIR: + self->plugins_dir = 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_PLUGINS_DIR: + 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_PLUGINS_DIR] = g_param_spec_string ("plugins-dir", + "Plugins Dir", + "The directory where plugins are stored.", + 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: + * + * Create a new `PxManager`. + * + * Returns: the newly created `PxManager` + */ +PxManager * +px_manager_new (void) +{ + return g_object_new (PX_TYPE_MANAGER, "plugins-dir", PX_PLUGINS_DIR, NULL); +} + +/** + * 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) +{ + g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); + g_autoptr (GError) error = NULL; + g_autoptr (GBytes) bytes = NULL; + + bytes = soup_session_send_and_read ( + self->session, + msg, + NULL, /* Pass a GCancellable here if you want to cancel a download */ + &error); + if (!bytes || soup_message_get_status (msg) != SOUP_STATUS_OK) { + g_debug ("Failed to download: %s\n", error ? error->message : ""); + return NULL; + } + + return g_steal_pointer (&bytes); +} + +struct ConfigData { + GStrvBuilder *builder; + GUri *uri; + GError **error; +}; + +static void +get_config (PeasExtensionSet *set, + PeasPluginInfo *info, + PeasExtension *extension, + gpointer data) +{ + PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (extension); + struct ConfigData *config_data = data; + + g_print ("%s: Asking plugin '%s' for configuration\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); + ifc->get_config (PX_CONFIG (extension), config_data->uri, config_data->builder, config_data->error); +} + +/** + * px_manager_get_configuration: + * @self: a px manager + * @uri: PAC uri + * @error: a #GError + * + * Get raw proxy configuration for gien @uri. + * + * Returns: (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 (); + struct ConfigData config_data = { + .uri = uri, + .builder = builder, + .error = error, + }; + + peas_extension_set_foreach (self->config_set, get_config, &config_data); + + return g_strv_builder_end (builder); +} + +struct PacData { + GBytes *pac; + GUri *uri; + GStrvBuilder *builder; +}; + +static void +px_manager_run_pac (PeasExtensionSet *set, + PeasPluginInfo *info, + PeasExtension *extension, + gpointer data) +{ + PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (extension); + struct PacData *pac_data = data; + char *ret; + + ifc->set_pac (PX_PAC_RUNNER (extension), pac_data->pac); + ret = ifc->run (PX_PAC_RUNNER (extension), pac_data->uri); + if (ret) + g_strv_builder_add (pac_data->builder, ret); +} + +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_object (&self->pac_data); + g_clear_pointer (&self->pac_url, g_free); + self->wpad = TRUE; + } + + if (!self->pac_data) { + GUri *wpad_url = g_uri_parse ("http://wpad/wpad.data", G_URI_FLAGS_PARSE_RELAXED, NULL); + + g_print ("Trying to find the PAC using WPAD...\n"); + 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_object (&self->pac_url); + } + } + + 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_object (&self->pac_data); + } + } + + 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_error ("Unable to download PAC!"); + else + g_debug ("PAC recevied!\n"); + } + } + + return ret; +} + +/** + * px_manager_get_proxies_sync: + * @self: a px manager + * @url: a url + * + * Get proxies for giben @url. + * + * Returns: (nullable): a newly created `GStrv` containing proxy related information. + */ +char ** +px_manager_get_proxies_sync (PxManager *self, + const char *url, + GError **error) +{ + /* GList *list; */ + 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; + + if (!uri) { + g_strv_builder_add (builder, "direct://"); + return g_strv_builder_end (builder); + } + + /* TODO: Check topology */ + config = px_manager_get_configuration (self, uri, error); + + g_print ("Config is:\n"); + 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_print ("\t- %s\n", config[idx]); + + if (px_manager_expand_wpad (self, conf_url) || px_manager_expand_pac (self, conf_url)) { + struct PacData pac_data = { + .pac = self->pac_data, + .uri = uri, + .builder = builder, + }; + peas_extension_set_foreach (self->pacrunner_set, px_manager_run_pac, &pac_data); + } else { + g_strv_builder_add (builder, g_uri_to_string (conf_url)); + } + } + + /* In case no proxy could be found, assume direct connection */ + if (((GPtrArray *)builder)->len == 0) + g_strv_builder_add (builder, "direct://"); + + return g_strv_builder_end (builder); +} diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h new file mode 100644 index 0000000..17dcb1c --- /dev/null +++ b/src/backend/px-manager.h @@ -0,0 +1,63 @@ +/* px-manager.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 + +G_BEGIN_DECLS + +#define PX_TYPE_MANAGER (px_manager_get_type()) +// #define PX_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PX_TYPE_MANAGER, PxManager)) + +// typedef struct _PxManager PxManager; +// typedef struct _PxManagerClass PxManagerClass; + +// struct _PxManagerClass +// { +// GObjectClass parent_class; + +// gboolean (*get_config) (PxManager *self, GUri *uri); +// }; + +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); +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); + +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..d9ee9c6 --- /dev/null +++ b/src/backend/px-plugin-config.c @@ -0,0 +1,30 @@ +/* px-plugin-config.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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) +{ +} diff --git a/src/backend/px-plugin-config.h b/src/backend/px-plugin-config.h new file mode 100644 index 0000000..279479f --- /dev/null +++ b/src/backend/px-plugin-config.h @@ -0,0 +1,40 @@ +/* px-plugin-config.h + * + * Copyright 2023 Jan-Michael Brummer + * + * 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 + +G_BEGIN_DECLS + +#define PX_TYPE_CONFIG (px_config_get_type ()) + +G_DECLARE_INTERFACE (PxConfig, px_config, PX, CONFIG, GObject) + +struct _PxConfigInterface +{ + GTypeInterface parent_iface; + + gboolean (*is_available) (PxConfig *self); + gboolean (*get_config) (PxConfig *self, GUri *uri, GStrvBuilder *builder, GError **error); +}; + +G_END_DECLS diff --git a/src/backend/px-plugin-pacrunner.c b/src/backend/px-plugin-pacrunner.c new file mode 100644 index 0000000..d529c14 --- /dev/null +++ b/src/backend/px-plugin-pacrunner.c @@ -0,0 +1,29 @@ +/* px-plugin-pacrunner.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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-pacrunner.h" + +G_DEFINE_INTERFACE (PxPacRunner, px_pacrunner, G_TYPE_OBJECT) + +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..2b38c40 --- /dev/null +++ b/src/backend/px-plugin-pacrunner.h @@ -0,0 +1,41 @@ +/* px-plugin-pacrunner.h + * + * Copyright 2023 Jan-Michael Brummer + * + * 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 + +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; + + void (*set_pac) (PxPacRunner *pacrunner, GBytes *pac_data); + char *(*run) (PxPacRunner *self, GUri *uri); +}; + +G_END_DECLS diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build new file mode 100644 index 0000000..a657cb9 --- /dev/null +++ b/src/libproxy/meson.build @@ -0,0 +1,64 @@ +api_version = '1.0' + +libproxy_inc = include_directories('.') + +libproxy_sources = [] + +if get_option('dbus') +libproxy_sources += [ + 'proxy-dbus.c', +] + +else +libproxy_sources += [ + 'proxy.c', +] +endif + +libproxy_headers = [ + 'proxy.h', +] + +libproxy_deps = [ + px_backend_dep, +] + +libproxy_lib = shared_library( + 'proxy-@0@'.format(api_version), + libproxy_sources, + include_directories: px_backend_inc, + dependencies: libproxy_deps, + install: true, +) + +libproxy_dep = declare_dependency ( + include_directories: libproxy_inc, + link_with: libproxy_lib, + dependencies: libproxy_deps +) + +install_headers(libproxy_headers, subdir: 'libproxy') + +pkg = import('pkgconfig') +pkg.generate( + description: 'A shared library for libproxy', + libraries: libproxy_lib, + name: 'libproxy', + filebase: 'libproxy-' + api_version, + version: meson.project_version(), + subdirs: 'libproxy', + requires: 'gio-2.0', + install_dir: join_paths(get_option('libdir'), 'pkgconfig') +) + +gnome = import('gnome') +libproxy_gir = gnome.generate_gir( + libproxy_lib, + sources: libproxy_headers + libproxy_sources, + nsversion: api_version, + namespace: 'Libproxy', + symbol_prefix: 'libproxy', + identifier_prefix: 'Libproxy', + includes: [ 'Gio-2.0' ], + install: true, +) diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c new file mode 100644 index 0000000..8fc1ca2 --- /dev/null +++ b/src/libproxy/proxy-dbus.c @@ -0,0 +1,130 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2006 Nathaniel McCallum + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 + +#include "proxy.h" + +/** + * SECTION:px-proxy + * @short_description: A convient helper for using proxy servers + */ + +struct px_proxy_factory { + GDBusProxy *proxy; + GCancellable *cancellable; +}; + +/** + * px_proxy_factory_new: + * Creates a new proxy factory. + * + * Returns: pointer to #px_proxy_factory + */ +struct px_proxy_factory * +px_proxy_factory_new (void) +{ + g_autoptr (GError) error = NULL; + struct px_proxy_factory *self = g_malloc0 (sizeof (struct px_proxy_factory)); + + self->cancellable = g_cancellable_new (); + self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.libproxy.proxy", + "/org/libproxy/proxy", + "org.libproxy.proxy", + self->cancellable, /* GCancellable */ + &error); + if (!self->proxy) + g_warning ("Could not create libproxy dbus proxy: %s", error->message); + + return self; +} + +char ** +px_proxy_factory_get_proxies (struct px_proxy_factory *self, + const char *url) +{ + g_autoptr (GVariant) result = NULL; + g_autoptr (GError) error = NULL; + g_autoptr (GVariantIter) iter = NULL; + g_autoptr (GList) list = NULL; + GList *tmp; + char *str; + char **retval; + gsize len; + gsize idx; + + result = g_dbus_proxy_call_sync (self->proxy, + "query", + g_variant_new ("(s)", url), + G_DBUS_CALL_FLAGS_NONE, + -1, + self->cancellable, + &error); + if (!result) { + g_warning ("Could not query proxy dbus: %s", error->message); + return NULL; + } + + g_variant_get (result, "(as)", &iter); + + while (g_variant_iter_loop (iter, "&s", &str)) { + list = g_list_prepend (list, g_strdup (str)); + } + + len = g_list_length (list); + if (len == 0) { + retval = g_malloc0 (sizeof (char *) * 2); + retval[0] = g_strdup ("direct://"); + + return retval; + } + + retval = g_malloc0 (sizeof (char *) * (len + 1)); + for (tmp = list, idx = 0; tmp && tmp->data; tmp = tmp->next, idx++) { + char *value = tmp->data; + retval[idx] = g_strdup (value); + } + + return retval; +} + +void +px_proxy_factory_free_proxies (char **proxies) +{ + g_clear_pointer (&proxies, g_strfreev); +} + +/** + * px_proxy_factory_free: + * @self: a px_proxy_factory + * + * Free px_proxy_factory + */ +void +px_proxy_factory_free (struct px_proxy_factory *self) +{ + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->cancellable); + g_clear_object (&self->proxy); + g_clear_pointer (&self, g_free); +} diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c new file mode 100644 index 0000000..e4f4d01 --- /dev/null +++ b/src/libproxy/proxy.c @@ -0,0 +1,90 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2006 Nathaniel McCallum + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 + +#include "px-manager.h" +#include "proxy.h" + +/** + * SECTION:px-proxy + * @short_description: A convient helper for using proxy servers + * + * Test 123 + */ + +struct px_proxy_factory { + PxManager *manager; + GCancellable *cancellable; +}; + +/** + * px_proxy_factory_new: + * Creates a new proxy factory. + * + * Returns: pointer to #px_proxy_factory + */ +struct px_proxy_factory * +px_proxy_factory_new (void) +{ + struct px_proxy_factory *self = g_malloc0 (sizeof (struct px_proxy_factory)); + + self->cancellable = g_cancellable_new (); + self->manager = px_manager_new (); + + return self; +} + +char ** +px_proxy_factory_get_proxies (struct px_proxy_factory *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 (!result) { + g_warning ("Could not query proxy: %s", error ? error->message : ""); + return NULL; + } + + return g_steal_pointer (&result); +} + +void +px_proxy_factory_free_proxies (char **proxies) +{ + g_clear_pointer (&proxies, g_strfreev); +} + +/** + * px_proxy_factory_free: + * @self: a px_proxy_factory + * + * Free px_proxy_factory + */ +void +px_proxy_factory_free (struct px_proxy_factory *self) +{ + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->cancellable); + g_clear_object (&self->manager); + g_clear_pointer (&self, g_free); +} diff --git a/src/libproxy/proxy.h b/src/libproxy/proxy.h new file mode 100644 index 0000000..a5a4eae --- /dev/null +++ b/src/libproxy/proxy.h @@ -0,0 +1,121 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2006 Nathaniel McCallum + * Copyright (C) 2022 Jan-Michael Brummer + * + * 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 + ******************************************************************************/ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct px_proxy_factory pxProxyFactory; + +/** + * px_proxy_factory_new: + * + * 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. + * + * @return A new pxProxyFactory instance or NULL on error + */ +pxProxyFactory *px_proxy_factory_new (void); + +/** + * px_proxy_factory_get_proxies: + * @self: a #pxProxyFactpry + * @url: Get proxxies for specificed URL + * + * Get which proxies to use for the specified URL. + * + * 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. + * + * 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 (i.e. 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. + * + * 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 + * - ://[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. + * + * For SOCKS proxies, when the protocol version is specified (socks4:// or + * socks5://), it is expected that only this version is used. When only + * socks:// is set, the client MUST try SOCKS version 5 protocol and, on + * connection failure, fallback to SOCKS version 4. + * + * Other proxying protocols may exist. It is expected that the returned + * configuration scheme shall match the network service name of the + * 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 + */ +char **px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url); + +/** + * px_proxy_factory_free_proxies + * @proxies: proxie array + * + * 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); + +/** + * px_proxy_factory_free: + * @self: a #pxProxyFactory + * + * Frees the pxProxyFactory instance when no longer used. + */ +void px_proxy_factory_free (pxProxyFactory *self); + +#ifdef __cplusplus +} +#endif diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..fc61997 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,4 @@ +subdir('backend') +subdir('libproxy') +subdir('tests') +subdir('tools') diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c new file mode 100644 index 0000000..bec0951 --- /dev/null +++ b/src/tests/config-env-test.c @@ -0,0 +1,98 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 "px-manager.h" + +#include "px-manager-helper.h" + +#include + +typedef struct { + const char *env; + const char *proxy; + const char *no_proxy; + const char *url; + gboolean success; +} 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}, + { "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}, + { "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}, +}; + +static void +test_config_env (void) +{ + int idx; + + /* Overwrite libproxy configuration plugin */ + g_setenv ("PX_CONFIG_PLUGIN", "config-env", TRUE); + + 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()! */ + g_setenv (test.env, test.proxy, TRUE); + if (test.no_proxy) + g_setenv ("NO_PROXY", test.no_proxy, TRUE); + + manager = px_test_manager_new (); + 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_unsetenv (test.env); + 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/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c new file mode 100644 index 0000000..1f3d2a3 --- /dev/null +++ b/src/tests/config-sysconfig-test.c @@ -0,0 +1,85 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 "px-manager.h" + +#include "px-manager-helper.h" + +#include + +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; + + /* Overwrite libproxy configuration plugin */ + g_setenv ("PX_CONFIG_PLUGIN", "config-sysconfig", TRUE); + + 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_build_filename (g_getenv ("G_TEST_SRCDIR"), "data", "sample-sysconfig-proxy", NULL); + + g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE); + + manager = px_test_manager_new (); + 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/src/tests/data/sample-sysconfig-proxy b/src/tests/data/sample-sysconfig-proxy new file mode 100644 index 0000000..08aba65 --- /dev/null +++ b/src/tests/data/sample-sysconfig-proxy @@ -0,0 +1,5 @@ +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" diff --git a/src/tests/meson.build b/src/tests/meson.build new file mode 100644 index 0000000..c03e0e4 --- /dev/null +++ b/src/tests/meson.build @@ -0,0 +1,42 @@ +if get_option('tests') + envs = [ + 'G_TEST_SRCDIR=' + meson.current_source_dir(), + 'G_TEST_BUILDDIR=' + meson.current_build_dir(), + ] + + test_cargs = ['-UG_DISABLE_ASSERT'] + + 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 + ) + + 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 +endif diff --git a/src/tests/px-manager-helper.c b/src/tests/px-manager-helper.c new file mode 100644 index 0000000..d513677 --- /dev/null +++ b/src/tests/px-manager-helper.c @@ -0,0 +1,10 @@ +#include "px-manager.h" +#include "px-manager-helper.h" + +PxManager * +px_test_manager_new (void) +{ + g_autofree char *path = g_strdup_printf ("%s/../backend/plugins", g_getenv ("G_TEST_BUILDDIR")); + + return g_object_new (PX_TYPE_MANAGER, "plugins-dir", path, NULL); +} diff --git a/src/tests/px-manager-helper.h b/src/tests/px-manager-helper.h new file mode 100644 index 0000000..9749628 --- /dev/null +++ b/src/tests/px-manager-helper.h @@ -0,0 +1,3 @@ +#pragma once + +PxManager *px_test_manager_new (void); diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c new file mode 100644 index 0000000..4dbb6c1 --- /dev/null +++ b/src/tests/px-manager-test.c @@ -0,0 +1,118 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 "px-manager.h" +#include "px-manager-helper.h" + +#include + +#include + +#define SERVER_PORT 1983 + +typedef struct { + GMainLoop *loop; + PxManager *manager; +} Fixture; + +static void +server_callback (SoupServer *server, +#if SOUP_CHECK_VERSION(2, \ + 99, \ + 4) + SoupServerMessage *msg, +#else + SoupMessage *msg, +#endif + const char *path, + GHashTable *query, +#if !SOUP_CHECK_VERSION(2, \ + 99, \ + 4) + SoupClientContext *old, +#endif + gpointer data) +{ +#if SOUP_CHECK_VERSION (2, 99, 4) + soup_server_message_set_status (SOUP_SERVER_MESSAGE (msg), SOUP_STATUS_OK, NULL); +#else + soup_message_set_status (SOUP_MESSAGE (msg), SOUP_STATUS_OK); +#endif +} + +static void +fixture_setup (Fixture *fixture, + gconstpointer data) +{ + fixture->loop = g_main_loop_new (NULL, FALSE); + fixture->manager = px_test_manager_new (); +} + +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"); + g_assert_nonnull (pac); + + g_main_loop_quit (self->loop); + + return NULL; +} + +static void +test_pac_download (Fixture *self, + const void *user_data) +{ + g_thread_new ("test", (GThreadFunc)download_pac, self); + /* pac = px_manager_pac_download (self->manager, "http://127.0.0.1:1983"); */ + /* g_assert_nonnull (pac); */ + g_main_loop_run (self->loop); +} + +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, NULL, fixture_setup, test_pac_download, fixture_teardown); + + return g_test_run (); +} 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..80b0983 --- /dev/null +++ b/src/tools/proxy.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +#include "proxy.h" + +void * +malloc0 (size_t s); +void +print_proxies (char **proxies); + +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; +} -- cgit v1.2.1 From 2a5335eb12c85235dd9acc6b03cba4b08d667adf Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sat, 21 Jan 2023 16:34:08 +0100 Subject: Update coverity.yml --- .github/workflows/coverity.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 25954cd..c2d9a50 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -5,6 +5,7 @@ name: Coverity on: + workflow_dispatch: schedule: # Run Coverity daily at midnight - cron: '0 0 * * *' -- cgit v1.2.1 From 52a7e92312fa69d94aeea8b3ffa128f84afaede6 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sat, 21 Jan 2023 16:40:51 +0100 Subject: Update coverity.yml --- .github/workflows/coverity.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index c2d9a50..c8ef80d 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -34,6 +34,7 @@ jobs: libsoup-3.0-dev \ meson \ gcovr \ + gi-docgen \ libpeas-dev \ gsettings-desktop-schemas-dev - name: Build & upload the results -- cgit v1.2.1 From 04d5a255fb00c95132b9b3b758e4cad8a1a7b500 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 22 Jan 2023 16:16:03 +0100 Subject: Fix review findings Relates: https://github.com/janbrummer/libproxy2/issues/2 --- .github/workflows/build.yml | 29 ++++++++++++++++++++++---- TODO.md | 43 --------------------------------------- copyfile.py | 15 -------------- src/backend/px-manager.c | 30 ++++++++++++++++++++------- src/libproxy/proxy-dbus.c | 4 ++-- src/tests/config-env-test.c | 5 +---- src/tests/config-sysconfig-test.c | 5 +---- src/tests/px-manager-helper.c | 7 +++++-- src/tests/px-manager-helper.h | 2 +- src/tests/px-manager-test.c | 17 +--------------- 10 files changed, 59 insertions(+), 98 deletions(-) delete mode 100644 TODO.md delete mode 100644 copyfile.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6450e78..f9194cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,10 +27,6 @@ jobs: run: | ninja test -C build ninja coverage -C build - - # ninja coverage-html -C build - # mkdir build/docs/px-0/coverage/ - # cp -r build/meson-logs/coveragereport/* build/docs/px-0/coverage/ - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: @@ -38,6 +34,30 @@ jobs: - name: CodeCov uses: codecov/codecov-action@v3 + build-linux-dbus: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Dependencies + run: | + sudo apt install \ + libglib2.0-dev \ + libgirepository1.0-dev \ + duktape-dev \ + libsoup-3.0-dev \ + meson \ + gcovr \ + gi-docgen \ + libpeas-dev \ + gsettings-desktop-schemas-dev + - name: Build setup + run: meson setup build -Db_coverage=true -Ddbus=true + - name: Build + run: ninja -C build + - name: Tests + run: | + ninja test -C build + build-osx: runs-on: macos-latest steps: @@ -93,6 +113,7 @@ jobs: deploy: # needs: [build-linux, build-osx, build-windows] needs: build-linux + if: github.ref == 'refs/heads/main' permissions: pages: write # to deploy to Pages diff --git a/TODO.md b/TODO.md deleted file mode 100644 index b558645..0000000 --- a/TODO.md +++ /dev/null @@ -1,43 +0,0 @@ -# TODO List - -## Step 1 -- Architecture review - - ZSCaler?? - config module - - Session to System Daemon communication? - - - icon? - -> Dom fragt nach - - Windows Plugin: Finish & Test - - SysConfig Plugin: File monitor - -- Check error handling - -- Async API - -> Yes -> Use Case - -- Shutdown handling! - -- Chemnitzer Linux Tage? - -> Yes :) - - - GNOME plugin: - get_config mode extraction... - - - gi-docgen broken in msys2 - Fatal error in launcher: Unable to find an appended archive. - https://github.com/msys2/MINGW-packages/pull/15171 - -## Step 2 -- Add missing modules -- Check Windows -- Check OS X -- Check BSD - -## Step 3 -- Reach out and add patches to: - - wget - - curl - - Python (requests/pip) diff --git a/copyfile.py b/copyfile.py deleted file mode 100644 index b57734f..0000000 --- a/copyfile.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python3 - -# Replace calls to 'cp' with Python - -import shutil -import sys - -if len(sys.argv) < 3: - raise ValueError('Usage: %s ' % sys.argv[0]) - -last_arg_index = len(sys.argv) - 1 -destdir = sys.argv[last_arg_index] - -for x in range(1, last_arg_index): - shutil.copy(sys.argv[x], destdir) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 999af09..436ed93 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -31,6 +31,7 @@ enum { PROP_0, PROP_PLUGINS_DIR, + PROP_CONFIG_PLUGIN, LAST_PROP }; @@ -52,6 +53,8 @@ struct _PxManager { GCancellable *cancellable; SoupSession *session; + char *config_plugin; + gboolean wpad; GBytes *pac_data; char *pac_url; @@ -66,7 +69,6 @@ px_manager_constructed (GObject *object) { PxManager *self = PX_MANAGER (object); const GList *list; - const char *requested_config_plugin = g_getenv ("PX_CONFIG_PLUGIN"); self->session = soup_session_new (); @@ -84,8 +86,8 @@ px_manager_constructed (GObject *object) if (!peas_plugin_info_is_loaded (info)) { /* In case user requested a specific module, just load that one */ - if (requested_config_plugin) { - if (g_strcmp0 (peas_plugin_info_get_module_name (info), requested_config_plugin) == 0) + if (self->config_plugin) { + if (g_strcmp0 (peas_plugin_info_get_module_name (info), self->config_plugin) == 0) peas_engine_load_plugin (self->engine, info); } else { peas_engine_load_plugin (self->engine, info); @@ -109,8 +111,11 @@ px_manager_dispose (GObject *object) { PxManager *self = PX_MANAGER (object); - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); + if (self->cancellable) { + g_cancellable_cancel (self->cancellable); + g_clear_object (&self->cancellable); + } + g_clear_pointer (&self->plugins_dir, g_free); g_clear_object (&self->engine); @@ -129,6 +134,9 @@ px_manager_set_property (GObject *object, case PROP_PLUGINS_DIR: self->plugins_dir = g_strdup (g_value_get_string (value)); break; + case PROP_CONFIG_PLUGIN: + self->config_plugin = g_strdup (g_value_get_string (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -143,6 +151,8 @@ px_manager_get_property (GObject *object, switch (prop_id) { case PROP_PLUGINS_DIR: break; + case PROP_CONFIG_PLUGIN: + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -160,8 +170,14 @@ px_manager_class_init (PxManagerClass *klass) object_class->get_property = px_manager_get_property; obj_properties[PROP_PLUGINS_DIR] = g_param_spec_string ("plugins-dir", - "Plugins Dir", - "The directory where plugins are stored.", + NULL, + NULL, + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + + 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); diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 8fc1ca2..ef62384 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -88,7 +88,7 @@ px_proxy_factory_get_proxies (struct px_proxy_factory *self, g_variant_get (result, "(as)", &iter); while (g_variant_iter_loop (iter, "&s", &str)) { - list = g_list_prepend (list, g_strdup (str)); + list = g_list_prepend (list, str); } len = g_list_length (list); @@ -99,7 +99,7 @@ px_proxy_factory_get_proxies (struct px_proxy_factory *self, return retval; } - retval = g_malloc0 (sizeof (char *) * (len + 1)); + retval = g_malloc0_n (len + 1, sizeof (char *)); for (tmp = list, idx = 0; tmp && tmp->data; tmp = tmp->next, idx++) { char *value = tmp->data; retval[idx] = g_strdup (value); diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c index bec0951..86c7551 100644 --- a/src/tests/config-env-test.c +++ b/src/tests/config-env-test.c @@ -50,9 +50,6 @@ test_config_env (void) { int idx; - /* Overwrite libproxy configuration plugin */ - g_setenv ("PX_CONFIG_PLUGIN", "config-env", TRUE); - for (idx = 0; idx < G_N_ELEMENTS (config_env_test_set); idx++) { g_autoptr (PxManager) manager = NULL; g_autoptr (GError) error = NULL; @@ -65,7 +62,7 @@ test_config_env (void) if (test.no_proxy) g_setenv ("NO_PROXY", test.no_proxy, TRUE); - manager = px_test_manager_new (); + manager = px_test_manager_new ("config-env"); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); diff --git a/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c index 1f3d2a3..d33545e 100644 --- a/src/tests/config-sysconfig-test.c +++ b/src/tests/config-sysconfig-test.c @@ -41,9 +41,6 @@ test_config_sysconfig (void) { int idx; - /* Overwrite libproxy configuration plugin */ - g_setenv ("PX_CONFIG_PLUGIN", "config-sysconfig", TRUE); - for (idx = 0; idx < G_N_ELEMENTS (config_sysconfig_test_set); idx++) { g_autoptr (PxManager) manager = NULL; g_autoptr (GError) error = NULL; @@ -54,7 +51,7 @@ test_config_sysconfig (void) g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE); - manager = px_test_manager_new (); + manager = px_test_manager_new ("config-sysconfig"); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); diff --git a/src/tests/px-manager-helper.c b/src/tests/px-manager-helper.c index d513677..2e12371 100644 --- a/src/tests/px-manager-helper.c +++ b/src/tests/px-manager-helper.c @@ -2,9 +2,12 @@ #include "px-manager-helper.h" PxManager * -px_test_manager_new (void) +px_test_manager_new (const char *config_plugin) { g_autofree char *path = g_strdup_printf ("%s/../backend/plugins", g_getenv ("G_TEST_BUILDDIR")); - return g_object_new (PX_TYPE_MANAGER, "plugins-dir", path, NULL); + return g_object_new (PX_TYPE_MANAGER, + "plugins-dir", path, + "config-plugin", config_plugin, + NULL); } diff --git a/src/tests/px-manager-helper.h b/src/tests/px-manager-helper.h index 9749628..fb486df 100644 --- a/src/tests/px-manager-helper.h +++ b/src/tests/px-manager-helper.h @@ -1,3 +1,3 @@ #pragma once -PxManager *px_test_manager_new (void); +PxManager *px_test_manager_new (const char *config_plugin); diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index 4dbb6c1..80279ea 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -33,27 +33,12 @@ typedef struct { static void server_callback (SoupServer *server, -#if SOUP_CHECK_VERSION(2, \ - 99, \ - 4) SoupServerMessage *msg, -#else - SoupMessage *msg, -#endif const char *path, GHashTable *query, -#if !SOUP_CHECK_VERSION(2, \ - 99, \ - 4) - SoupClientContext *old, -#endif gpointer data) { -#if SOUP_CHECK_VERSION (2, 99, 4) soup_server_message_set_status (SOUP_SERVER_MESSAGE (msg), SOUP_STATUS_OK, NULL); -#else - soup_message_set_status (SOUP_MESSAGE (msg), SOUP_STATUS_OK); -#endif } static void @@ -61,7 +46,7 @@ fixture_setup (Fixture *fixture, gconstpointer data) { fixture->loop = g_main_loop_new (NULL, FALSE); - fixture->manager = px_test_manager_new (); + fixture->manager = px_test_manager_new (NULL); } static void -- cgit v1.2.1 From 4d40e2c59e66112b97fb3a06c3989036ce5b03ce Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 22 Jan 2023 17:26:33 +0100 Subject: Fix memory leak in PxManager Recently introduced config_plugin property has a mem leak. Fix it. --- src/backend/px-manager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 436ed93..1fa0ccf 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -116,6 +116,7 @@ px_manager_dispose (GObject *object) g_clear_object (&self->cancellable); } + g_clear_pointer (&self->config_plugin, g_free); g_clear_pointer (&self->plugins_dir, g_free); g_clear_object (&self->engine); -- cgit v1.2.1 From b1b6f88294bfbdee3d46436c29f8b118cccb90d0 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 23 Jan 2023 14:53:44 +0100 Subject: Fix msys pipeline (#7) Force Python 3.9 to avoid pipeline errors with recent Python --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9194cc..47cafa1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,6 +102,9 @@ jobs: mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-libpeas - 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: | -- cgit v1.2.1 From b25c66dd33a4edea617530f4029c5d256a1d186f Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 23 Jan 2023 15:13:35 +0100 Subject: Improve config_env (#6) - Move environment reading to init - Treat no_proxy as a list with asterisk handling --- src/backend/plugins/config-env/config-env.c | 81 +++++++++++++++++++++-------- src/backend/plugins/config-env/config-env.h | 4 -- src/backend/px-manager.c | 14 +++++ src/tests/config-env-test.c | 14 ++--- 4 files changed, 81 insertions(+), 32 deletions(-) diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index aca96da..5b3a686 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -29,6 +29,15 @@ static void px_config_iface_init (PxConfigInterface *iface); G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); +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, @@ -37,11 +46,46 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigEnv, 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_class_init (PxConfigEnvClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = px_config_env_dispose; } static gboolean @@ -51,38 +95,33 @@ px_config_env_is_available (PxConfig *self) } static gboolean -px_config_env_get_config (PxConfig *self, +px_config_env_get_config (PxConfig *config, GUri *uri, GStrvBuilder *builder, GError **error) { + PxConfigEnv *self = PX_CONFIG_ENV (config); const char *proxy = NULL; const char *scheme = g_uri_get_scheme (uri); - const char *ignore = NULL; - ignore = g_getenv ("no_proxy"); - if (!ignore) - ignore = g_getenv ("NO_PROXY"); - - if (ignore && strstr (ignore, g_uri_get_host (uri))) + /* TODO: + * - Are host names resolved to IPs?? + * - case insensitive check? + */ + if (self->no_proxy && (g_strv_contains ((const char * const *)self->no_proxy, g_uri_get_host (uri)) || g_strv_contains ((const char * const *)self->no_proxy, "*"))) { return TRUE; - - if (g_strcmp0 (scheme, "ftp") == 0) { - proxy = g_getenv ("ftp_proxy"); - if (!proxy) - proxy = g_getenv ("FTP_PROXY"); - } else if (g_strcmp0 (scheme, "https") == 0) { - proxy = g_getenv ("https_proxy"); - if (!proxy) - proxy = g_getenv ("HTTPS_PROXY"); } - if (!proxy) { - proxy = g_getenv ("http_proxy"); - if (!proxy) - proxy = g_getenv ("HTTP_PROXY"); - } + if (g_strcmp0 (scheme, "ftp") == 0) + proxy = self->ftp_proxy; + else if (g_strcmp0 (scheme, "https") == 0) + proxy = self->https_proxy; + + /* TODO: Is this what we want as a fallback? What about ALL_PROXY? */ + if (!proxy) + proxy = self->http_proxy; + /* TODO: Where should we add proxy url validation ? */ if (proxy) g_strv_builder_add (builder, proxy); diff --git a/src/backend/plugins/config-env/config-env.h b/src/backend/plugins/config-env/config-env.h index bbe74d4..7d31d4e 100644 --- a/src/backend/plugins/config-env/config-env.h +++ b/src/backend/plugins/config-env/config-env.h @@ -30,10 +30,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (PxConfigEnv, px_config_env, PX, CONFIG_ENV, GObject) -struct _PxConfigEnv { - GObject parent_instance; -}; - G_END_DECLS diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 1fa0ccf..01f2697 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -110,12 +110,21 @@ static void px_manager_dispose (GObject *object) { PxManager *self = PX_MANAGER (object); + const GList *list; if (self->cancellable) { g_cancellable_cancel (self->cancellable); g_clear_object (&self->cancellable); } + list = peas_engine_get_plugin_list (self->engine); + for (; list && list->data; list = list->next) { + PeasPluginInfo *info = PEAS_PLUGIN_INFO (list->data); + + if (peas_plugin_info_is_loaded (info)) + peas_engine_unload_plugin (self->engine, info); + } + g_clear_pointer (&self->config_plugin, g_free); g_clear_pointer (&self->plugins_dir, g_free); g_clear_object (&self->engine); @@ -239,6 +248,11 @@ struct ConfigData { GError **error; }; +/** + * Strategy: + * - Traverse through all plugins in extension set and ask for configuration data. + * - A plugin can either return the proxy server for given uri OR nothing! for direc access. + */ static void get_config (PeasExtensionSet *set, PeasPluginInfo *info, diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c index 86c7551..91edeb4 100644 --- a/src/tests/config-env-test.c +++ b/src/tests/config-env-test.c @@ -28,7 +28,7 @@ typedef struct { const char *proxy; const char *no_proxy; const char *url; - gboolean success; + gboolean config_is_proxy; } ConfigEnvTest; static const ConfigEnvTest config_env_test_set[] = { @@ -37,12 +37,16 @@ static const ConfigEnvTest config_env_test_set[] = { { "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 @@ -66,19 +70,15 @@ test_config_env (void) 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) + 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_clear_object (&manager); } } -- cgit v1.2.1 From fde57945c2209224cfd34861658d219f539d8a69 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 23 Jan 2023 15:47:09 +0100 Subject: Add px_manager_get_proxies_sync test (#8) --- src/tests/px-manager-test.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index 80279ea..01c3162 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -46,7 +46,7 @@ fixture_setup (Fixture *fixture, gconstpointer data) { fixture->loop = g_main_loop_new (NULL, FALSE); - fixture->manager = px_test_manager_new (NULL); + fixture->manager = px_test_manager_new ("config-env"); } static void @@ -80,6 +80,25 @@ test_pac_download (Fixture *self, g_main_loop_run (self->loop); } +static void +test_get_proxies (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, "http://www.example.com", NULL); + g_assert_nonnull (config); + g_assert_cmpstr (config[0], ==, "direct://"); +} + int main (int argc, char **argv) @@ -98,6 +117,7 @@ main (int argc, soup_server_add_handler (server, NULL, server_callback, NULL, NULL); g_test_add ("/pac/download", Fixture, NULL, fixture_setup, test_pac_download, fixture_teardown); + g_test_add ("/pac/get_proxies", Fixture, NULL, fixture_setup, test_get_proxies, fixture_teardown); return g_test_run (); } -- cgit v1.2.1 From 00aa2047580d5afba06769bdd89c9f631859a51e Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 23 Jan 2023 18:22:19 +0100 Subject: Fix sysconfig test on msys2 (#10) Remove trailing \r and fix length check for proxy enable. --- .github/workflows/build.yml | 2 +- src/backend/plugins/config-sysconfig/config-sysconfig.c | 7 ++++--- src/tests/config-sysconfig-test.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 47cafa1..4f40a08 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -108,7 +108,7 @@ jobs: - name: Build and Test # Disable docs for the moment until msys2 gi-docgen update has landed run: | - meson setup build -Ddocs=false -Dconfig-sysconfig=false + meson setup build -Ddocs=false ninja -C build ninja -C build test diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index dd19893..22f536f 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -62,13 +62,13 @@ px_config_sysconfig_init (PxConfigSysConfig *self) file = g_file_new_for_path (self->proxy_file); if (!file) { - g_debug ("Could not create file\n"); + g_print ("Could not create file\n"); return; } istr = g_file_read(file, NULL, NULL); if (!istr) { - g_debug ("Could not read file\n"); + g_print ("Could not read file\n"); return; } @@ -90,9 +90,10 @@ px_config_sysconfig_init (PxConfigSysConfig *self) 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", 4) == 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) { diff --git a/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c index d33545e..099f7a8 100644 --- a/src/tests/config-sysconfig-test.c +++ b/src/tests/config-sysconfig-test.c @@ -47,7 +47,7 @@ test_config_sysconfig (void) g_autoptr (GUri) uri = NULL; g_auto (GStrv) config = NULL; ConfigSysConfigTest test = config_sysconfig_test_set[idx]; - g_autofree char *path = g_build_filename (g_getenv ("G_TEST_SRCDIR"), "data", "sample-sysconfig-proxy", NULL); + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy", NULL); g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE); -- cgit v1.2.1 From 21dd5679dd642aa6cb9e120de2304ba19146d2c4 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 23 Jan 2023 22:00:59 +0100 Subject: Filter config-plugins only (#11) --- src/backend/px-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 01f2697..bf945f0 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -86,7 +86,7 @@ px_manager_constructed (GObject *object) if (!peas_plugin_info_is_loaded (info)) { /* In case user requested a specific module, just load that one */ - if (self->config_plugin) { + if (self->config_plugin && g_str_has_prefix (peas_plugin_info_get_module_name (info), "config-")) { if (g_strcmp0 (peas_plugin_info_get_module_name (info), self->config_plugin) == 0) peas_engine_load_plugin (self->engine, info); } else { -- cgit v1.2.1 From d875586bab506b7fdb4b2e0ce12c4c7f307cc6bd Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 23 Jan 2023 22:57:02 +0100 Subject: Add PAC configuration tests (#9) --- src/backend/px-manager.c | 1 + src/tests/data/px-manager-direct | 1 + src/tests/data/px-manager-nonpac | 5 +++ src/tests/data/px-manager-pac | 5 +++ src/tests/data/px-manager-sample.pac | 6 ++++ src/tests/px-manager-test.c | 66 +++++++++++++++++++++++++++++++----- 6 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 src/tests/data/px-manager-direct create mode 100644 src/tests/data/px-manager-nonpac create mode 100644 src/tests/data/px-manager-pac create mode 100644 src/tests/data/px-manager-sample.pac diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index bf945f0..66a0a35 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -78,6 +78,7 @@ px_manager_constructed (GObject *object) self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, NULL); self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); + list = peas_engine_get_plugin_list (self->engine); for (; list && list->data; list = list->next) { PeasPluginInfo *info = PEAS_PLUGIN_INFO (list->data); diff --git a/src/tests/data/px-manager-direct b/src/tests/data/px-manager-direct new file mode 100644 index 0000000..72c4ac8 --- /dev/null +++ b/src/tests/data/px-manager-direct @@ -0,0 +1 @@ +PROXY_ENABLED="no" \ No newline at end of file diff --git a/src/tests/data/px-manager-nonpac b/src/tests/data/px-manager-nonpac new file mode 100644 index 0000000..7db21d8 --- /dev/null +++ b/src/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/src/tests/data/px-manager-pac b/src/tests/data/px-manager-pac new file mode 100644 index 0000000..2ff4000 --- /dev/null +++ b/src/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/src/tests/data/px-manager-sample.pac b/src/tests/data/px-manager-sample.pac new file mode 100644 index 0000000..48d01f0 --- /dev/null +++ b/src/tests/data/px-manager-sample.pac @@ -0,0 +1,6 @@ +function FindProxyForURL(url, host) +{ + var myIP = myIpAddress(); + + return "PROXY 127.0.0.1:1983" +} \ No newline at end of file diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index 01c3162..20db7c6 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -39,6 +39,15 @@ server_callback (SoupServer *server, gpointer data) { 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; + gsize len; + + g_file_get_contents (pac, &pac_data, &len, NULL); + soup_server_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY, pac_data, len); + } } static void @@ -46,13 +55,20 @@ fixture_setup (Fixture *fixture, gconstpointer data) { fixture->loop = g_main_loop_new (NULL, FALSE); - fixture->manager = px_test_manager_new ("config-env"); + + if (data) { + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); + g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE); + } + + fixture->manager = px_test_manager_new ("config-sysconfig"); } static void fixture_teardown (Fixture *fixture, gconstpointer data) { + g_unsetenv ("PX_CONFIG_SYSCONFIG"); g_clear_object (&fixture->manager); } @@ -75,14 +91,12 @@ test_pac_download (Fixture *self, const void *user_data) { g_thread_new ("test", (GThreadFunc)download_pac, self); - /* pac = px_manager_pac_download (self->manager, "http://127.0.0.1:1983"); */ - /* g_assert_nonnull (pac); */ g_main_loop_run (self->loop); } static void -test_get_proxies (Fixture *self, - const void *user_data) +test_get_proxies_direct (Fixture *self, + const void *user_data) { g_auto (GStrv) config = NULL; @@ -94,11 +108,45 @@ test_get_proxies (Fixture *self, g_assert_nonnull (config); g_assert_cmpstr (config[0], ==, "direct://"); - config = px_manager_get_proxies_sync (self->manager, "http://www.example.com", NULL); + 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], ==, "PROXY 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_thread_new ("test", (GThreadFunc)get_proxies_pac, self); + g_main_loop_run (self->loop); +} + int main (int argc, char **argv) @@ -116,8 +164,10 @@ main (int argc, soup_server_add_handler (server, NULL, server_callback, NULL, NULL); - g_test_add ("/pac/download", Fixture, NULL, fixture_setup, test_pac_download, fixture_teardown); - g_test_add ("/pac/get_proxies", Fixture, NULL, fixture_setup, test_get_proxies, fixture_teardown); + 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); return g_test_run (); } -- cgit v1.2.1 From 4cf5a0ce431a28732c453340ccf17e4f5dc46857 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 24 Jan 2023 08:03:26 +0100 Subject: Add initial config GNOME test (#12) --- src/backend/plugins/config-gnome/config-gnome.c | 2 +- src/tests/config-gnome-test.c | 121 ++++++++++++++++++++++++ src/tests/meson.build | 13 +++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/tests/config-gnome-test.c diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index f894498..0416d2e 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -113,7 +113,7 @@ store_response (GStrvBuilder *builder, g_string_append_printf (tmp, "%s:%d", host, port); - g_strv_builder_add (builder, g_string_free (tmp, TRUE)); + g_strv_builder_add (builder, g_string_free (tmp, FALSE)); } } diff --git a/src/tests/config-gnome-test.c b/src/tests/config-gnome-test.c new file mode 100644 index 0000000..2f4bb8c --- /dev/null +++ b/src/tests/config-gnome-test.c @@ -0,0 +1,121 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 "px-manager.h" + +#include "px-manager-helper.h" + +#include +#include + +typedef struct { + GSettings *proxy_settings; + GSettings *http_proxy_settings; + GSettings *https_proxy_settings; + GSettings *ftp_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}, +}; + +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"); +} + +static void +fixture_teardown (Fixture *fixture, + gconstpointer data) +{ +} + +static void +test_config_gnome (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_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); + + manager = px_test_manager_new ("config-gnome"); + 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.expected_return); + else + g_assert_cmpstr (config[0], !=, test.expected_return); + + g_clear_object (&manager); + } +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + g_test_add ("/config/gnome", Fixture, NULL, fixture_setup, test_config_gnome, fixture_teardown); + + return g_test_run (); +} diff --git a/src/tests/meson.build b/src/tests/meson.build index c03e0e4..d745d7e 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -2,6 +2,7 @@ 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'] @@ -39,4 +40,16 @@ if get_option('tests') 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 GNOMEtest', + config_gnome_test, + env: [envs, 'XDG_CURRENT_DESKTOP=GNOME'], + ) + endif endif -- cgit v1.2.1 From 043da6e2ca85f3eb073e8d777233a3de1678a2db Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 25 Jan 2023 10:28:24 +0100 Subject: Add download plugin (#4) Move PAC downloading into an own plugin so that CURL does not depend on soup. Relates: https://github.com/janbrummer/libproxy2/issues/2 --- meson.build | 2 +- meson_options.txt | 7 ++ src/backend/meson.build | 3 +- src/backend/plugins/download-soup/download-soup.c | 82 ++++++++++++++++++++++ src/backend/plugins/download-soup/download-soup.h | 41 +++++++++++ .../plugins/download-soup/download-soup.plugin | 6 ++ src/backend/plugins/download-soup/meson.build | 33 +++++++++ src/backend/plugins/meson.build | 3 + src/backend/px-manager.c | 49 ++++++++----- src/backend/px-plugin-download.c | 30 ++++++++ src/backend/px-plugin-download.h | 39 ++++++++++ 11 files changed, 274 insertions(+), 21 deletions(-) create mode 100644 src/backend/plugins/download-soup/download-soup.c create mode 100644 src/backend/plugins/download-soup/download-soup.h create mode 100644 src/backend/plugins/download-soup/download-soup.plugin create mode 100644 src/backend/plugins/download-soup/meson.build create mode 100644 src/backend/px-plugin-download.c create mode 100644 src/backend/px-plugin-download.h diff --git a/meson.build b/meson.build index 89eff87..27b99ff 100644 --- a/meson.build +++ b/meson.build @@ -109,7 +109,7 @@ endif glib_dep = dependency('glib-2.0', version: '>= 2.71.3') gio_dep = dependency('gio-2.0', version: '>= 2.71.3') peas_dep = dependency('libpeas-1.0') -soup_dep = dependency('libsoup-3.0') +soup_dep = dependency('libsoup-3.0', required: get_option('download-soup')) ws2_32_dep = cc.find_library('ws2_32', required : with_platform_windows) gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get_option('config-gnome')) diff --git a/meson_options.txt b/meson_options.txt index bfeecb8..dcd8e5d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -60,3 +60,10 @@ option( value: true, description: 'Whether to build plugin for PAC Runner Duktape' ) + +option( + 'download-soup', + type: 'boolean', + value: true, + description: 'Whether to build plugin for downloading with SOUP' +) diff --git a/src/backend/meson.build b/src/backend/meson.build index abadcc5..29caf42 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -7,12 +7,13 @@ px_backend_sources = [ 'px-plugin-config.h', 'px-plugin-pacrunner.c', 'px-plugin-pacrunner.h', + 'px-plugin-download.c', + 'px-plugin-download.h', ] px_backend_deps = [ gio_dep, glib_dep, - soup_dep, peas_dep, ] diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c new file mode 100644 index 0000000..de338d1 --- /dev/null +++ b/src/backend/plugins/download-soup/download-soup.c @@ -0,0 +1,82 @@ +/* download-soup.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +#include "download-soup.h" + +#include "px-plugin-download.h" +#include "px-manager.h" + +static void px_download_iface_init (PxDownloadInterface *iface); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadSoup, + px_download_soup, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_DOWNLOAD, px_download_iface_init)) + +static void +px_download_soup_init (PxDownloadSoup *self) +{ + self->session = soup_session_new (); +} + +static void +px_download_soup_class_init (PxDownloadSoupClass *klass) +{ +} + +static GBytes * +px_download_soup_download (PxDownload *download, const char *uri) +{ + PxDownloadSoup *self = PX_DOWNLOAD_SOUP (download); + g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); + g_autoptr (GError) error = NULL; + g_autoptr (GBytes) bytes = NULL; + + bytes = soup_session_send_and_read ( + self->session, + msg, + NULL, /* Pass a GCancellable here if you want to cancel a download */ + &error); + if (!bytes || soup_message_get_status (msg) != SOUP_STATUS_OK) { + g_debug ("Failed to download: %s\n", error ? error->message : ""); + return NULL; + } + + return g_steal_pointer (&bytes); +} + +static void +px_download_iface_init (PxDownloadInterface *iface) +{ + iface->download = px_download_soup_download; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_DOWNLOAD, + PX_DOWNLOAD_TYPE_SOUP); +} diff --git a/src/backend/plugins/download-soup/download-soup.h b/src/backend/plugins/download-soup/download-soup.h new file mode 100644 index 0000000..26afd9e --- /dev/null +++ b/src/backend/plugins/download-soup/download-soup.h @@ -0,0 +1,41 @@ +/* download-soup.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +G_BEGIN_DECLS + +#define PX_DOWNLOAD_TYPE_SOUP (px_download_soup_get_type ()) + +G_DECLARE_FINAL_TYPE (PxDownloadSoup, px_download_soup, PX, DOWNLOAD_SOUP, GObject) + +struct _PxDownloadSoup { + GObject parent_instance; + + SoupSession *session; +}; + +G_END_DECLS + + diff --git a/src/backend/plugins/download-soup/download-soup.plugin b/src/backend/plugins/download-soup/download-soup.plugin new file mode 100644 index 0000000..6e9cbb1 --- /dev/null +++ b/src/backend/plugins/download-soup/download-soup.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Donwload data using SOUP +Module=download-soup +Name=SOUP \ No newline at end of file diff --git a/src/backend/plugins/download-soup/meson.build b/src/backend/plugins/download-soup/meson.build new file mode 100644 index 0000000..68cc288 --- /dev/null +++ b/src/backend/plugins/download-soup/meson.build @@ -0,0 +1,33 @@ +plugin_name = 'download-soup' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + sources: plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep, soup_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +endif \ No newline at end of file diff --git a/src/backend/plugins/meson.build b/src/backend/plugins/meson.build index 6a91379..8a14739 100644 --- a/src/backend/plugins/meson.build +++ b/src/backend/plugins/meson.build @@ -4,6 +4,8 @@ subdir('config-osx') subdir('config-sysconfig') subdir('config-windows') +subdir('download-soup') + subdir('pacrunner-duktape') summary({ @@ -12,5 +14,6 @@ summary({ 'Configuration Windows ' : get_option('config-windows'), 'Configuration sysconfig ' : get_option('config-sysconfig'), 'Configuration OS X ' : get_option('config-osx'), + 'Download Soup ' : get_option('download-soup'), 'PAC Runner Duktape ' : get_option('pacrunner-duktape'), }, section: 'Plugins') \ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 66a0a35..af4a119 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -24,8 +24,8 @@ #include "px-manager.h" #include "px-plugin-config.h" #include "px-plugin-pacrunner.h" +#include "px-plugin-download.h" -#include #include enum { @@ -49,9 +49,9 @@ struct _PxManager { PeasEngine *engine; PeasExtensionSet *config_set; PeasExtensionSet *pacrunner_set; + PeasExtensionSet *download_set; char *plugins_dir; GCancellable *cancellable; - SoupSession *session; char *config_plugin; @@ -70,14 +70,13 @@ px_manager_constructed (GObject *object) PxManager *self = PX_MANAGER (object); const GList *list; - self->session = soup_session_new (); - self->engine = peas_engine_get_default (); peas_engine_add_search_path (self->engine, self->plugins_dir, NULL); self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, NULL); self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); + self->download_set = peas_extension_set_new (self->engine, PX_TYPE_DOWNLOAD, NULL); list = peas_engine_get_plugin_list (self->engine); for (; list && list->data; list = list->next) { @@ -213,6 +212,26 @@ px_manager_new (void) return g_object_new (PX_TYPE_MANAGER, "plugins-dir", PX_PLUGINS_DIR, NULL); } +struct DownloadData { + const char *uri; + GBytes *bytes; + GError **error; +}; + +static void +download_pac (PeasExtensionSet *set, + PeasPluginInfo *info, + PeasExtension *extension, + gpointer data) +{ + PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension); + struct DownloadData *download_data = data; + + g_print ("%s: Download PAC using plugin '%s'\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); + if (!download_data->bytes) + download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri); +} + /** * px_manager_pac_download: * @self: a px manager @@ -226,21 +245,13 @@ GBytes * px_manager_pac_download (PxManager *self, const char *uri) { - g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); - g_autoptr (GError) error = NULL; - g_autoptr (GBytes) bytes = NULL; - - bytes = soup_session_send_and_read ( - self->session, - msg, - NULL, /* Pass a GCancellable here if you want to cancel a download */ - &error); - if (!bytes || soup_message_get_status (msg) != SOUP_STATUS_OK) { - g_debug ("Failed to download: %s\n", error ? error->message : ""); - return NULL; - } + struct DownloadData download_data = { + .uri = uri, + .bytes = NULL, + }; - return g_steal_pointer (&bytes); + peas_extension_set_foreach (self->download_set, download_pac, &download_data); + return download_data.bytes; } struct ConfigData { @@ -333,7 +344,7 @@ px_manager_expand_wpad (PxManager *self, } if (!self->pac_data) { - GUri *wpad_url = g_uri_parse ("http://wpad/wpad.data", G_URI_FLAGS_PARSE_RELAXED, NULL); + GUri *wpad_url = g_uri_parse ("download://wpad/wpad.data", G_URI_FLAGS_PARSE_RELAXED, NULL); g_print ("Trying to find the PAC using WPAD...\n"); self->pac_url = g_uri_to_string (wpad_url); diff --git a/src/backend/px-plugin-download.c b/src/backend/px-plugin-download.c new file mode 100644 index 0000000..bc7d6d2 --- /dev/null +++ b/src/backend/px-plugin-download.c @@ -0,0 +1,30 @@ +/* px-plugin-download.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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-download.h" + +G_DEFINE_INTERFACE (PxDownload, px_download, G_TYPE_OBJECT) + +static void +px_download_default_init (PxDownloadInterface *iface) +{ +} diff --git a/src/backend/px-plugin-download.h b/src/backend/px-plugin-download.h new file mode 100644 index 0000000..e618de7 --- /dev/null +++ b/src/backend/px-plugin-download.h @@ -0,0 +1,39 @@ +/* px-plugin-download.h + * + * Copyright 2023 Jan-Michael Brummer + * + * 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 + +G_BEGIN_DECLS + +#define PX_TYPE_DOWNLOAD (px_download_get_type ()) + +G_DECLARE_INTERFACE (PxDownload, px_download, PX, DOWNLOAD, GObject) + +struct _PxDownloadInterface +{ + GTypeInterface parent_iface; + + GBytes *(*download)(PxDownload *download, const char *uri); +}; + +G_END_DECLS -- cgit v1.2.1 From 77c6515d6b9d7078a1cac0a0e1abdf714f7d3e3f Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 25 Jan 2023 10:48:39 +0100 Subject: Fix Coverity findings (#13) --- src/tests/config-env-test.c | 6 +++++- src/tests/config-sysconfig-test.c | 5 ++++- src/tests/meson.build | 2 +- src/tests/px-manager-test.c | 19 +++++++++++++++---- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c index 91edeb4..2c780d2 100644 --- a/src/tests/config-env-test.c +++ b/src/tests/config-env-test.c @@ -62,7 +62,11 @@ test_config_env (void) ConfigEnvTest test = config_env_test_set[idx]; /* Set proxy environment variable. Must be done before px_test_manager_new()! */ - g_setenv (test.env, test.proxy, TRUE); + if (!g_setenv (test.env, test.proxy, TRUE)) { + g_warning ("Could not set environment"); + continue; + } + if (test.no_proxy) g_setenv ("NO_PROXY", test.no_proxy, TRUE); diff --git a/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c index 099f7a8..1a2d3ec 100644 --- a/src/tests/config-sysconfig-test.c +++ b/src/tests/config-sysconfig-test.c @@ -49,7 +49,10 @@ test_config_sysconfig (void) ConfigSysConfigTest test = config_sysconfig_test_set[idx]; g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy", NULL); - g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE); + if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { + g_warning ("Failed to set sysconfig environment"); + continue; + } manager = px_test_manager_new ("config-sysconfig"); g_clear_error (&error); diff --git a/src/tests/meson.build b/src/tests/meson.build index d745d7e..fcdd75c 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -47,7 +47,7 @@ if get_option('tests') include_directories: px_backend_inc, dependencies: [glib_dep, px_backend_dep], ) - test('Config GNOMEtest', + test('Config GNOME test', config_gnome_test, env: [envs, 'XDG_CURRENT_DESKTOP=GNOME'], ) diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index 20db7c6..5cb16c3 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -43,9 +43,13 @@ server_callback (SoupServer *server, 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; - g_file_get_contents (pac, &pac_data, &len, NULL); + 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); } } @@ -58,7 +62,10 @@ fixture_setup (Fixture *fixture, if (data) { g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); - g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE); + if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { + g_warning ("Failed to set environment"); + return; + } } fixture->manager = px_test_manager_new ("config-sysconfig"); @@ -90,7 +97,9 @@ static void test_pac_download (Fixture *self, const void *user_data) { - g_thread_new ("test", (GThreadFunc)download_pac, self); + g_autoptr (GThread) thread = NULL; + + thread = g_thread_new ("test", (GThreadFunc)download_pac, self); g_main_loop_run (self->loop); } @@ -143,7 +152,9 @@ static void test_get_proxies_pac (Fixture *self, const void *user_data) { - g_thread_new ("test", (GThreadFunc)get_proxies_pac, self); + g_autoptr (GThread) thread = NULL; + + thread = g_thread_new ("test", (GThreadFunc)get_proxies_pac, self); g_main_loop_run (self->loop); } -- cgit v1.2.1 From f5a84456c07fe1e3d8647c8a17aacb05cdaa2996 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 25 Jan 2023 14:57:07 +0100 Subject: Add initial wpad test (#15) --- src/backend/px-manager.c | 10 ++++++---- src/tests/data/px-manager-wpad | 5 +++++ src/tests/px-manager-test.c | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/tests/data/px-manager-wpad diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index af4a119..097f020 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -344,13 +344,15 @@ px_manager_expand_wpad (PxManager *self, } if (!self->pac_data) { - GUri *wpad_url = g_uri_parse ("download://wpad/wpad.data", G_URI_FLAGS_PARSE_RELAXED, NULL); + GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_PARSE_RELAXED, NULL); g_print ("Trying to find the PAC using WPAD...\n"); 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_object (&self->pac_url); + if (!self->pac_data) { + g_clear_pointer (&self->pac_url, g_free); + ret = FALSE; + } } } @@ -433,7 +435,7 @@ px_manager_get_proxies_sync (PxManager *self, .builder = builder, }; peas_extension_set_foreach (self->pacrunner_set, px_manager_run_pac, &pac_data); - } else { + } else if (!g_str_has_prefix (g_uri_get_scheme (conf_url), "wpad")) { g_strv_builder_add (builder, g_uri_to_string (conf_url)); } } diff --git a/src/tests/data/px-manager-wpad b/src/tests/data/px-manager-wpad new file mode 100644 index 0000000..4ab0f81 --- /dev/null +++ b/src/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/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index 5cb16c3..ba1c6b7 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -158,6 +158,31 @@ test_get_proxies_pac (Fixture *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); +} + int main (int argc, char **argv) @@ -179,6 +204,7 @@ main (int argc, 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); return g_test_run (); } -- cgit v1.2.1 From c5c9ffa3623562740908486af42a35c038fd7b23 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 25 Jan 2023 16:06:02 +0100 Subject: Add download curl plugin (#14) --- .github/workflows/build.yml | 9 +- meson.build | 1 + meson_options.txt | 7 ++ src/backend/plugins/download-curl/download-curl.c | 99 ++++++++++++++++++++++ src/backend/plugins/download-curl/download-curl.h | 40 +++++++++ .../plugins/download-curl/download-curl.plugin | 6 ++ src/backend/plugins/download-curl/meson.build | 33 ++++++++ src/backend/plugins/meson.build | 2 + 8 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 src/backend/plugins/download-curl/download-curl.c create mode 100644 src/backend/plugins/download-curl/download-curl.h create mode 100644 src/backend/plugins/download-curl/download-curl.plugin create mode 100644 src/backend/plugins/download-curl/meson.build diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f40a08..f3a1bb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,8 @@ jobs: gcovr \ gi-docgen \ libpeas-dev \ - gsettings-desktop-schemas-dev + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev - name: Build setup run: meson setup build -Db_coverage=true - name: Build @@ -49,7 +50,8 @@ jobs: gcovr \ gi-docgen \ libpeas-dev \ - gsettings-desktop-schemas-dev + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev - name: Build setup run: meson setup build -Db_coverage=true -Ddbus=true - name: Build @@ -69,7 +71,7 @@ jobs: - name: Setup run: | pip install meson ninja - brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas + brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas curl echo 'PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/gi-docgen/lib/pkgconfig' >> $GITHUB_ENV - name: Build and Test run: | @@ -101,6 +103,7 @@ jobs: mingw-w64-x86_64-gi-docgen mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-libpeas + mingw-w64-x86_64-curl - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: diff --git a/meson.build b/meson.build index 27b99ff..0b28bba 100644 --- a/meson.build +++ b/meson.build @@ -110,6 +110,7 @@ glib_dep = dependency('glib-2.0', version: '>= 2.71.3') gio_dep = dependency('gio-2.0', version: '>= 2.71.3') peas_dep = dependency('libpeas-1.0') soup_dep = dependency('libsoup-3.0', required: get_option('download-soup')) +curl_dep = dependency('libcurl', required: get_option('download-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')) diff --git a/meson_options.txt b/meson_options.txt index dcd8e5d..f35387a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -67,3 +67,10 @@ option( value: true, description: 'Whether to build plugin for downloading with SOUP' ) + +option( + 'download-curl', + type: 'boolean', + value: true, + description: 'Whether to build plugin for downloading with cURL' +) \ No newline at end of file diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c new file mode 100644 index 0000000..5a531cb --- /dev/null +++ b/src/backend/plugins/download-curl/download-curl.c @@ -0,0 +1,99 @@ +/* download-curl.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +#include "download-curl.h" + +#include "px-plugin-download.h" +#include "px-manager.h" + +static void px_download_iface_init (PxDownloadInterface *iface); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadCurl, + px_download_curl, + G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (PX_TYPE_DOWNLOAD, px_download_iface_init)) + +static void +px_download_curl_init (PxDownloadCurl *self) +{ + self->curl = curl_easy_init (); +} + +static void +px_download_curl_class_init (PxDownloadCurlClass *klass) +{ +} + +static size_t +store_data (void *contents, + size_t size, + size_t nmemb, + void *user_pointer) +{ + GString *string = user_pointer; + size_t real_size = size * nmemb; + + g_string_append_len (string, contents, real_size); + return real_size; +} + +static GBytes * +px_download_curl_download (PxDownload *download, const char *uri) +{ + PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); + g_autoptr (GBytes) bytes = NULL; + CURLcode res; + g_autoptr (GString) data = g_string_new (""); + const char *url = uri; + + if (g_str_has_prefix (url, "pac+")) + url += 4; + + curl_easy_setopt (self->curl, CURLOPT_URL, url); + curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data); + curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, data); + + res = curl_easy_perform (self->curl); + if (res != CURLE_OK) { + g_warning ("Could not download data: %s", curl_easy_strerror (res)); + return NULL; + } + + return g_steal_pointer (&bytes); +} + +static void +px_download_iface_init (PxDownloadInterface *iface) +{ + iface->download = px_download_curl_download; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_DOWNLOAD, + PX_DOWNLOAD_TYPE_CURL); +} diff --git a/src/backend/plugins/download-curl/download-curl.h b/src/backend/plugins/download-curl/download-curl.h new file mode 100644 index 0000000..4b95140 --- /dev/null +++ b/src/backend/plugins/download-curl/download-curl.h @@ -0,0 +1,40 @@ +/* download-curl.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +G_BEGIN_DECLS + +#define PX_DOWNLOAD_TYPE_CURL (px_download_curl_get_type ()) + +G_DECLARE_FINAL_TYPE (PxDownloadCurl, px_download_curl, PX, DOWNLOAD_CURL, GObject) + +struct _PxDownloadCurl { + GObject parent_instance; + CURL *curl; +}; + +G_END_DECLS + + diff --git a/src/backend/plugins/download-curl/download-curl.plugin b/src/backend/plugins/download-curl/download-curl.plugin new file mode 100644 index 0000000..7aa75d6 --- /dev/null +++ b/src/backend/plugins/download-curl/download-curl.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Donwload data using cURL +Module=download-curl +Name=cURL \ No newline at end of file diff --git a/src/backend/plugins/download-curl/meson.build b/src/backend/plugins/download-curl/meson.build new file mode 100644 index 0000000..29da33e --- /dev/null +++ b/src/backend/plugins/download-curl/meson.build @@ -0,0 +1,33 @@ +plugin_name = 'download-curl' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + sources: plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep, curl_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +endif \ No newline at end of file diff --git a/src/backend/plugins/meson.build b/src/backend/plugins/meson.build index 8a14739..d7d7c4c 100644 --- a/src/backend/plugins/meson.build +++ b/src/backend/plugins/meson.build @@ -4,6 +4,7 @@ subdir('config-osx') subdir('config-sysconfig') subdir('config-windows') +subdir('download-curl') subdir('download-soup') subdir('pacrunner-duktape') @@ -14,6 +15,7 @@ summary({ 'Configuration Windows ' : get_option('config-windows'), 'Configuration sysconfig ' : get_option('config-sysconfig'), 'Configuration OS X ' : get_option('config-osx'), + 'Download cURL ' : get_option('download-curl'), 'Download Soup ' : get_option('download-soup'), 'PAC Runner Duktape ' : get_option('pacrunner-duktape'), }, section: 'Plugins') \ No newline at end of file -- cgit v1.2.1 From 4c160a9374cbef664d0eec034a7d86fd78543f03 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 25 Jan 2023 16:24:03 +0100 Subject: Fix CI pipeline (#17) --- src/backend/plugins/download-curl/download-curl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 5a531cb..7bde950 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -77,7 +77,7 @@ px_download_curl_download (PxDownload *download, const char *uri) res = curl_easy_perform (self->curl); if (res != CURLE_OK) { - g_warning ("Could not download data: %s", curl_easy_strerror (res)); + g_debug ("Could not download data: %s", curl_easy_strerror (res)); return NULL; } -- cgit v1.2.1 From 14227ab516d4e7226b007fc6d9f5e80e9297c890 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 25 Jan 2023 17:36:11 +0100 Subject: Enforce check-code-style as pre-commit-hook (#16) --- data/canonicalize_filename.sh | 48 ++++++++++++++++++++++ data/install-git-hook.sh | 12 ++++++ data/pre-commit-hook | 17 ++++++++ meson.build | 4 ++ src/backend/plugins/config-env/config-env.c | 3 +- src/backend/plugins/config-osx/config-osx.c | 12 +++--- .../plugins/config-sysconfig/config-sysconfig.c | 4 +- src/backend/plugins/download-curl/download-curl.c | 3 +- src/backend/plugins/download-soup/download-soup.c | 3 +- src/backend/px-manager.c | 8 ++-- src/tests/px-manager-test.c | 6 +-- 11 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 data/canonicalize_filename.sh create mode 100644 data/install-git-hook.sh create mode 100644 data/pre-commit-hook 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/install-git-hook.sh b/data/install-git-hook.sh new file mode 100644 index 0000000..7fd5550 --- /dev/null +++ b/data/install-git-hook.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +cd "$MESON_SOURCE_ROOT" + +[ -d .git ] || exit 0 # not a git repo +[ ! -f .git/hooks/pre-commit ] || exit 0 # already installed + +echo "Copying pre commit hook" +cp data/pre-commit-hook .git/hooks/pre-commit +echo "Copying helper" +cp data/canonicalize_filename.sh .git/hooks/canonicalize_filename.sh +echo "Done" \ No newline at end of file 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/meson.build b/meson.build index 0b28bba..402a724 100644 --- a/meson.build +++ b/meson.build @@ -123,3 +123,7 @@ summary({ 'host system' : host_system, 'C Compiler' : cc.get_id(), }, section: 'Build environment') + +# Install pre-commit hook +git_hook_installer = find_program('data/install-git-hook.sh') +run_command(git_hook_installer) \ No newline at end of file diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index 5b3a686..cbc4de5 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -57,7 +57,7 @@ px_config_env_init (PxConfigEnv *self) self->no_proxy = g_strsplit (no_proxy, ",", -1); self->ftp_proxy = g_getenv ("ftp_proxy"); - if (!self->ftp_proxy ) + if (!self->ftp_proxy) self->ftp_proxy = g_getenv ("FTP_PROXY"); self->https_proxy = g_getenv ("https_proxy"); @@ -67,7 +67,6 @@ px_config_env_init (PxConfigEnv *self) self->http_proxy = g_getenv ("http_proxy"); if (!self->http_proxy) self->http_proxy = g_getenv ("HTTP_PROXY"); - } static void diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index 6ccd298..a4041eb 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -65,7 +65,7 @@ getobj (CFDictionaryRef settings, if (!k) return NULL; - retval = (CFNumberRef) CFDictionaryGetValue(settings, k); + retval = (CFNumberRef)CFDictionaryGetValue (settings, k); CFRelease (k); return retval; @@ -73,7 +73,7 @@ getobj (CFDictionaryRef settings, static CFStringRef getobj_str (CFDictionaryRef settings, - char *key) + char *key) { CFStringRef k; CFStringRef retval; @@ -85,7 +85,7 @@ getobj_str (CFDictionaryRef settings, if (!k) return NULL; - retval = (CFStringRef) CFDictionaryGetValue(settings, k); + retval = (CFStringRef)CFDictionaryGetValue (settings, k); CFRelease (k); return retval; @@ -113,7 +113,7 @@ getbool (CFDictionaryRef settings, { int64_t i = 0; - if (!getint(settings, key, &i)) + if (!getint (settings, key, &i)) return FALSE; return i != 0; @@ -133,7 +133,7 @@ px_config_osx_get_config (PxConfig *self, return FALSE; } - if (getbool(proxies, "ProxyAutoDiscoveryEnable")) { + if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { CFRelease (proxies); g_strv_builder_add (builder, "wpad://"); return TRUE; @@ -143,7 +143,7 @@ px_config_osx_get_config (PxConfig *self, CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString"); const char *tmp = CFStringGetCStringPtr (ref, CFStringGetFastestEncoding (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); diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index 22f536f..29e8420 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -66,13 +66,13 @@ px_config_sysconfig_init (PxConfigSysConfig *self) return; } - istr = g_file_read(file, NULL, NULL); + istr = g_file_read (file, NULL, NULL); if (!istr) { g_print ("Could not read file\n"); return; } - dstr = g_data_input_stream_new(G_INPUT_STREAM(istr)); + dstr = g_data_input_stream_new (G_INPUT_STREAM (istr)); if (!dstr) return; diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 7bde950..06a91b8 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -60,7 +60,8 @@ store_data (void *contents, } static GBytes * -px_download_curl_download (PxDownload *download, const char *uri) +px_download_curl_download (PxDownload *download, + const char *uri) { PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); g_autoptr (GBytes) bytes = NULL; diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c index de338d1..905f173 100644 --- a/src/backend/plugins/download-soup/download-soup.c +++ b/src/backend/plugins/download-soup/download-soup.c @@ -47,7 +47,8 @@ px_download_soup_class_init (PxDownloadSoupClass *klass) } static GBytes * -px_download_soup_download (PxDownload *download, const char *uri) +px_download_soup_download (PxDownload *download, + const char *uri) { PxDownloadSoup *self = PX_DOWNLOAD_SOUP (download); g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 097f020..ca80eab 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -186,10 +186,10 @@ px_manager_class_init (PxManagerClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); 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); + 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); } diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index ba1c6b7..428f5d2 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -32,7 +32,7 @@ typedef struct { } Fixture; static void -server_callback (SoupServer *server, +server_callback (SoupServer *server, SoupServerMessage *msg, const char *path, GHashTable *query, @@ -47,8 +47,8 @@ server_callback (SoupServer *server, gsize len; if (!g_file_get_contents (pac, &pac_data, &len, &error)) { - g_warning ("Could not read pac file: %s", error ? error->message : ""); - return; + 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); } -- cgit v1.2.1 From d96426ff1f6f676587a8f05e29c84057f7996f58 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 26 Jan 2023 16:11:41 +0100 Subject: Add network monitor support (#18) --- src/backend/px-manager.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ca80eab..be86830 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -50,6 +50,7 @@ struct _PxManager { PeasExtensionSet *config_set; PeasExtensionSet *pacrunner_set; PeasExtensionSet *download_set; + GNetworkMonitor *network_monitor; char *plugins_dir; GCancellable *cancellable; @@ -64,6 +65,20 @@ 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\n", __FUNCTION__); + + self->wpad = FALSE; + g_clear_pointer (&self->pac_url, g_free); + g_clear_object (&self->pac_data); +} + static void px_manager_constructed (GObject *object) { @@ -104,6 +119,9 @@ px_manager_constructed (GObject *object) if (!available) peas_engine_unload_plugin (self->engine, info); } + + 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); } static void -- cgit v1.2.1 From f2ff89e8bc5960feff174bd1f26b97bd72998e21 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 27 Jan 2023 18:15:49 +0100 Subject: Add curl dev to coverity workflow (#20) --- .github/workflows/coverity.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index c8ef80d..e077a61 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -36,6 +36,7 @@ jobs: gcovr \ gi-docgen \ libpeas-dev \ - gsettings-desktop-schemas-dev + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev - name: Build & upload the results run: .github/coverity.sh -- cgit v1.2.1 From 7c3ab7b3ab2afde645c1eb135f2ef8dbae5774d3 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 11:09:15 +0100 Subject: Add dbus service files (#21) Add proxyd service file and install it to systemd user dir. --- src/backend/dbus/meson.build | 20 ++++++++++++++++++++ src/backend/dbus/proxyd.service.in | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/backend/dbus/proxyd.service.in diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build index 5222a5f..8ab3bfe 100644 --- a/src/backend/dbus/meson.build +++ b/src/backend/dbus/meson.build @@ -1,6 +1,12 @@ if get_option('dbus') gdbus_codegen = find_program('gdbus-codegen') + unitdir = '' + systemd = dependency('systemd', required: false) + if systemd.found() + unitdir = systemd.get_variable(pkgconfig: 'systemduserunitdir') + endif + px_interface = [ 'org.libproxy.proxy.xml' ] @@ -43,6 +49,20 @@ if get_option('dbus') 'proxyd', proxyd_sources, dependencies: proxyd_deps, + install_dir: join_paths(px_prefix, get_option('libexecdir')), install: true, ) + + service_data = configuration_data() + service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + + service = configure_file( + input: 'proxyd.service.in', + output: 'proxyd.service', + configuration: service_data + ) + + if unitdir != '' + install_data(service, install_dir: unitdir) + endif endif diff --git a/src/backend/dbus/proxyd.service.in b/src/backend/dbus/proxyd.service.in new file mode 100644 index 0000000..2e2a7cc --- /dev/null +++ b/src/backend/dbus/proxyd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Libproxy user service + +[Service] +Type=dbus +BusName=org.libproxy.proxy +ExecStart=@LIBEXECDIR@/proxyd +#Environment="G_MESSAGES_DEBUG=all" +Restart=on-failure + +MemoryDenyWriteExecute=yes +PrivateTmp=yes +ProtectHome=yes +ProtectSystem=full +RestrictRealtime=yes + +[Install] +WantedBy=default.target \ No newline at end of file -- cgit v1.2.1 From 6118d7947b9463783cfadbb08acc77ad67d19379 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 11:29:18 +0100 Subject: Add initial KDE plugin (#19) --- meson_options.txt | 7 + src/backend/plugins/config-kde/config-kde.c | 214 +++++++++++++++++++++++ src/backend/plugins/config-kde/config-kde.h | 35 ++++ src/backend/plugins/config-kde/config-kde.plugin | 6 + src/backend/plugins/config-kde/meson.build | 33 ++++ src/backend/plugins/meson.build | 2 + src/tests/config-kde-test.c | 209 ++++++++++++++++++++++ src/tests/data/sample-kde-proxy-disabled | 11 ++ src/tests/data/sample-kde-proxy-manual | 11 ++ src/tests/data/sample-kde-proxy-pac | 11 ++ src/tests/data/sample-kde-proxy-wpad | 11 ++ src/tests/meson.build | 12 ++ 12 files changed, 562 insertions(+) create mode 100644 src/backend/plugins/config-kde/config-kde.c create mode 100644 src/backend/plugins/config-kde/config-kde.h create mode 100644 src/backend/plugins/config-kde/config-kde.plugin create mode 100644 src/backend/plugins/config-kde/meson.build create mode 100644 src/tests/config-kde-test.c create mode 100644 src/tests/data/sample-kde-proxy-disabled create mode 100644 src/tests/data/sample-kde-proxy-manual create mode 100644 src/tests/data/sample-kde-proxy-pac create mode 100644 src/tests/data/sample-kde-proxy-wpad diff --git a/meson_options.txt b/meson_options.txt index f35387a..a82890c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -54,6 +54,13 @@ option( description: 'Whether to build plugin for OS X configuration' ) +option( + 'config-kde', + type: 'boolean', + value: true, + description: 'Whether to build plugin for KDE System Settings' +) + option( 'pacrunner-duktape', type: 'boolean', 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..519a2d5 --- /dev/null +++ b/src/backend/plugins/config-kde/config-kde.c @@ -0,0 +1,214 @@ +/* config-kde.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 + +#include "config-kde.h" + +#include "px-plugin-config.h" +#include "px-manager.h" + +static void px_config_iface_init (PxConfigInterface *iface); +G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +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; + + gboolean available; + + char *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)) + +static void +px_config_kde_read_config (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; + + + file = g_file_new_for_path (proxy_file); + if (!file) { + g_print ("Could not create file\n"); + return; + } + + istr = g_file_read (file, NULL, NULL); + if (!istr) { + g_print ("Could not read file\n"); + return; + } + + dstr = g_data_input_stream_new (G_INPUT_STREAM (istr)); + if (!dstr) + return; + + 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); + 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_strdup (value->str); + } 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); +} + +static void +px_config_kde_init (PxConfigKde *self) +{ + const char *test_file = g_getenv ("PX_CONFIG_KDE"); + g_autofree char *config = test_file ? g_strdup (test_file) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL); + + self->available = g_file_test (config, G_FILE_TEST_EXISTS); + if (self->available) + px_config_kde_read_config (self, config); +} + +static void +px_config_kde_dispose (GObject *object) +{ + G_OBJECT_CLASS (px_config_kde_parent_class)->dispose (object); +} + +static void +px_config_kde_class_init (PxConfigKdeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = px_config_kde_dispose; +} + +static gboolean +px_config_kde_is_available (PxConfig *config) +{ + PxConfigKde *self = PX_CONFIG_KDE (config); + + return self->available && g_getenv ("KDE_FULL_SESSION") != NULL; +} + +static gboolean +px_config_kde_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder, + GError **error) +{ + PxConfigKde *self = PX_CONFIG_KDE (config); + const char *scheme = g_uri_get_scheme (uri); + g_autofree char *proxy = NULL; + + if (!self->proxy_type) + return TRUE; + + if (self->no_proxy && strstr (self->no_proxy, g_uri_get_host (uri))) + return TRUE; + + switch (self->proxy_type) { + case KDE_PROXY_TYPE_MANUAL: + case KDE_PROXY_TYPE_SYSTEM: + 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 (g_strcmp0 (scheme, "socks") == 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) + g_strv_builder_add (builder, proxy); + + return TRUE; +} + +static void +px_config_iface_init (PxConfigInterface *iface) +{ + iface->is_available = px_config_kde_is_available; + iface->get_config = px_config_kde_get_config; +} + +G_MODULE_EXPORT void +peas_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, + PX_TYPE_CONFIG, + PX_CONFIG_TYPE_KDE); +} 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..408b28a --- /dev/null +++ b/src/backend/plugins/config-kde/config-kde.h @@ -0,0 +1,35 @@ +/* config-kde.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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 +#include + +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/config-kde.plugin b/src/backend/plugins/config-kde/config-kde.plugin new file mode 100644 index 0000000..b8aabab --- /dev/null +++ b/src/backend/plugins/config-kde/config-kde.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Read proxy configuration from KDE System Settings +Module=config-kde +Name=KDE \ No newline at end of file diff --git a/src/backend/plugins/config-kde/meson.build b/src/backend/plugins/config-kde/meson.build new file mode 100644 index 0000000..109e5db --- /dev/null +++ b/src/backend/plugins/config-kde/meson.build @@ -0,0 +1,33 @@ +plugin_name = 'config-kde' + +if get_option(plugin_name) + +plugin_src = [ + '@0@.c'.format(plugin_name), +] + +plugin_data = [ + '@0@.plugin'.format(plugin_name), +] + +plugin_lib = shared_module( + plugin_name, + sources: plugin_src, + include_directories: px_backend_inc, + dependencies: [px_backend_dep], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, + name_suffix: module_suffix, +) + +# Starting with Meson 0.64 this can be replaced with fs.copyfile +custom_target( + '@0@-data'.format(plugin_name), + input: plugin_data, + output: plugin_data, + command: ['cp', '@INPUT@', '@OUTDIR@'], + install_dir: join_paths(px_plugins_dir, plugin_name), + install: true, +) + +endif \ No newline at end of file diff --git a/src/backend/plugins/meson.build b/src/backend/plugins/meson.build index d7d7c4c..09344f0 100644 --- a/src/backend/plugins/meson.build +++ b/src/backend/plugins/meson.build @@ -1,5 +1,6 @@ subdir('config-env') subdir('config-gnome') +subdir('config-kde') subdir('config-osx') subdir('config-sysconfig') subdir('config-windows') @@ -12,6 +13,7 @@ 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'), diff --git a/src/tests/config-kde-test.c b/src/tests/config-kde-test.c new file mode 100644 index 0000000..08b950b --- /dev/null +++ b/src/tests/config-kde-test.c @@ -0,0 +1,209 @@ +/******************************************************************************* + * libproxy - A library for proxy configuration + * Copyright (C) 2022-2023 Jan-Michael Brummer + * + * 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 "px-manager.h" + +#include "px-manager-helper.h" + +#include + +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}, + { "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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + } +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + + 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); + + return g_test_run (); +} diff --git a/src/tests/data/sample-kde-proxy-disabled b/src/tests/data/sample-kde-proxy-disabled new file mode 100644 index 0000000..9598abd --- /dev/null +++ b/src/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/src/tests/data/sample-kde-proxy-manual b/src/tests/data/sample-kde-proxy-manual new file mode 100644 index 0000000..c0a293b --- /dev/null +++ b/src/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/src/tests/data/sample-kde-proxy-pac b/src/tests/data/sample-kde-proxy-pac new file mode 100644 index 0000000..c0db824 --- /dev/null +++ b/src/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/src/tests/data/sample-kde-proxy-wpad b/src/tests/data/sample-kde-proxy-wpad new file mode 100644 index 0000000..6eb1547 --- /dev/null +++ b/src/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/src/tests/meson.build b/src/tests/meson.build index fcdd75c..151905f 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -52,4 +52,16 @@ if get_option('tests') 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, 'KDE_FULL_SESSION=1'], + ) + endif endif -- cgit v1.2.1 From 7f14bd477b55cd40b0b227248040453462db8f20 Mon Sep 17 00:00:00 2001 From: Dominique Leuenberger Date: Mon, 30 Jan 2023 15:21:44 +0100 Subject: Keep the client library abi compatible to version 0.4.x (#25) * libproxy: maintain 0.4.x compatible client library name/version * Abi compat to 0.4.x: retain libprexy.map symbol versioning --- src/libproxy/libproxy.map | 8 ++++++++ src/libproxy/meson.build | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/libproxy/libproxy.map diff --git a/src/libproxy/libproxy.map b/src/libproxy/libproxy.map new file mode 100644 index 0000000..32f0db3 --- /dev/null +++ b/src/libproxy/libproxy.map @@ -0,0 +1,8 @@ +LIBPROXY_0.4.16 { + global: + px_proxy_factory_new; + px_proxy_factory_get_proxies; + px_proxy_factory_free_proxies; + px_proxy_factory_free; +}; + diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index a657cb9..3ee67b6 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -23,11 +23,21 @@ 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_lib = shared_library( - 'proxy-@0@'.format(api_version), + 'proxy', libproxy_sources, include_directories: px_backend_inc, dependencies: libproxy_deps, + link_args : vflag, + link_depends : mapfile, + soversion: '1', install: true, ) -- cgit v1.2.1 From 81a64821f43dcd7051579ebbe67792b2bb41eae6 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 15:47:55 +0100 Subject: Disable px-manager-test if soup is not found (#26) Fixes: https://github.com/janbrummer/libproxy2/issues/24 --- src/tests/meson.build | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/tests/meson.build b/src/tests/meson.build index 151905f..23a7e91 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -7,15 +7,17 @@ if get_option('tests') test_cargs = ['-UG_DISABLE_ASSERT'] - 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 - ) + 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', -- cgit v1.2.1 From 6b7ead10ee19141ba0a5f7efb403ea74bb69878d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 16:23:30 +0100 Subject: Make pac parsing more robust (#27) Ensure that the pac data is NULL-terminated and handle pac parser error. --- src/backend/plugins/download-curl/download-curl.c | 12 ++++++------ src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c | 12 ++++++++---- src/backend/px-manager.c | 5 ++++- src/backend/px-plugin-pacrunner.h | 2 +- src/tests/data/px-manager-sample.pac | 2 +- src/tests/px-manager-test.c | 3 ++- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 06a91b8..25228bf 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -52,10 +52,11 @@ store_data (void *contents, size_t nmemb, void *user_pointer) { - GString *string = user_pointer; + GByteArray *byte_array = user_pointer; size_t real_size = size * nmemb; - g_string_append_len (string, contents, real_size); + g_byte_array_append (byte_array, contents, real_size); + return real_size; } @@ -64,9 +65,8 @@ px_download_curl_download (PxDownload *download, const char *uri) { PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); - g_autoptr (GBytes) bytes = NULL; + GByteArray *byte_array = g_byte_array_new (); CURLcode res; - g_autoptr (GString) data = g_string_new (""); const char *url = uri; if (g_str_has_prefix (url, "pac+")) @@ -74,7 +74,7 @@ px_download_curl_download (PxDownload *download, curl_easy_setopt (self->curl, CURLOPT_URL, url); curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data); - curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, data); + curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, byte_array); res = curl_easy_perform (self->curl); if (res != CURLE_OK) { @@ -82,7 +82,7 @@ px_download_curl_download (PxDownload *download, return NULL; } - return g_steal_pointer (&bytes); + return g_byte_array_free_to_bytes (byte_array); } static void diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c index 86221f3..72f4b2b 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -147,18 +147,22 @@ px_pacrunner_duktape_class_init (PxPacRunnerDuktapeClass *klass) object_class->dispose = px_pacrunner_duktape_dispose; } -static void +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); + g_autoptr (GString) pac = g_string_new_len (content, len); - - duk_push_string (self->ctx, g_bytes_get_data (pac_data, NULL)); + duk_push_string (self->ctx, pac->str); if (duk_peval_noresult (self->ctx)) { - return; + return FALSE; } + + return TRUE; } static char * diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index be86830..ea4411e 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -339,7 +339,10 @@ px_manager_run_pac (PeasExtensionSet *set, struct PacData *pac_data = data; char *ret; - ifc->set_pac (PX_PAC_RUNNER (extension), pac_data->pac); + if (!ifc->set_pac (PX_PAC_RUNNER (extension), pac_data->pac)) { + return; + } + ret = ifc->run (PX_PAC_RUNNER (extension), pac_data->uri); if (ret) g_strv_builder_add (pac_data->builder, ret); diff --git a/src/backend/px-plugin-pacrunner.h b/src/backend/px-plugin-pacrunner.h index 2b38c40..0226dc0 100644 --- a/src/backend/px-plugin-pacrunner.h +++ b/src/backend/px-plugin-pacrunner.h @@ -34,7 +34,7 @@ struct _PxPacRunnerInterface { GTypeInterface parent_iface; - void (*set_pac) (PxPacRunner *pacrunner, GBytes *pac_data); + gboolean (*set_pac) (PxPacRunner *pacrunner, GBytes *pac_data); char *(*run) (PxPacRunner *self, GUri *uri); }; diff --git a/src/tests/data/px-manager-sample.pac b/src/tests/data/px-manager-sample.pac index 48d01f0..b86c555 100644 --- a/src/tests/data/px-manager-sample.pac +++ b/src/tests/data/px-manager-sample.pac @@ -3,4 +3,4 @@ function FindProxyForURL(url, host) var myIP = myIpAddress(); return "PROXY 127.0.0.1:1983" -} \ No newline at end of file +} diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index 428f5d2..afab118 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -38,6 +38,7 @@ server_callback (SoupServer *server, 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) { @@ -85,7 +86,7 @@ download_pac (gpointer data) Fixture *self = data; GBytes *pac; - pac = px_manager_pac_download (self->manager, "http://127.0.0.1:1983"); + 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); -- cgit v1.2.1 From 62ff0c708344e33863ed1cd48ad1e5fe88c86d14 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 17:08:36 +0100 Subject: Filesystem cleanups - Name documentation libproxy-1.0 - Do not install pxbackend gir file Fixes: https://github.com/janbrummer/libproxy2/issues/28 --- docs/meson.build | 2 +- meson.build | 2 +- src/backend/meson.build | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/meson.build b/docs/meson.build index 86cf5c1..3981133 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -19,7 +19,7 @@ docs_dir = datadir / 'doc' custom_target('px-doc', input: [ px_toml, px_backend_gir[0] ], - output: 'px-@0@'.format(apiversion), + output: 'libproxy-@0@'.format(apiversion), command: [ gidocgen, 'generate', diff --git a/meson.build b/meson.build index 402a724..12cf963 100644 --- a/meson.build +++ b/meson.build @@ -21,7 +21,7 @@ add_project_arguments(['-I' + meson.project_build_root()], language: 'c') version_arr = meson.project_version().split('-')[0].split('.') libproxy_version_major = version_arr[0].to_int() libproxy_version_minor = version_arr[1].to_int() -apiversion = libproxy_version_major.to_string() +apiversion = '1.0' libproxy_prefix = get_option('prefix') datadir = get_option('datadir') diff --git a/src/backend/meson.build b/src/backend/meson.build index 29caf42..d83a41b 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -35,7 +35,7 @@ px_backend_gir = gnome.generate_gir( symbol_prefix: 'px', identifier_prefix: 'Px', includes: [ 'Gio-2.0' ], - install: true, + install: false, ) px_backend_dep = declare_dependency( -- cgit v1.2.1 From a27e2115bd58c89b2ec743426744b6b4b161c09d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 17:11:52 +0100 Subject: Use gcovr for coverage (#29) --- .github/workflows/build.yml | 21 +++++++++++++++++++++ README.md | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3a1bb9..a1d2428 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,6 +28,27 @@ jobs: run: | ninja test -C build ninja coverage -C build + - name: Extract Coverage Percentage + run: | + RATE=$(grep -o -m 1 -P '(?<=line-rate=").*?(?=")' ./build/meson-logs/coverage.xml | head -1) + PERCENT="$(echo "($RATE * 100)/1" | bc)" + + BADGE_COLOR=red + if [ $PERCENT -ge 60 ]; then BADGE_COLOR=orange; fi + if [ $PERCENT -ge 80 ]; then BADGE_COLOR=yellow; fi + if [ $PERCENT -ge 95 ]; then BADGE_COLOR=brightgreen; fi + echo "$RATE -> $PERCENT : $BADGE_COLOR" + echo "COVERAGE_PERCENT=$PERCENT" >> $GITHUB_ENV + echo "COVERAGE_COLOR=$BADGE_COLOR" >> $GITHUB_ENV + - name: Create Coverage Badge + uses: schneegans/dynamic-badges-action@v1.1.0 + with: + auth: ${{ secrets.GIST_TOKEN }} + gistID: 713fa369e20d1c0fdb5896b9a167c3b4 + filename: greeter-coverage.json + label: Coverage + message: ${{ env.COVERAGE_PERCENT }} + color: ${{ env.COVERAGE_COLOR }} - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: diff --git a/README.md b/README.md index b9e39c1..4456ae8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) [![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://codecov.io/github/janbrummer/libproxy2) +![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) +[![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://codecov.io/github/janbrummer/libproxy2) +[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/janbrummer/713fa369e20d1c0fdb5896b9a167c3b4/raw/greeter-coverage.json)](https://github.com/janbrummer/repo/actions/workflows/build.yaml) [![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml) # Libproxy -- cgit v1.2.1 From 79b7c5fff8af78dd460e62dd255a6f6ac2bbdbc5 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 30 Jan 2023 18:24:09 +0100 Subject: Fix page generation (#31) --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a1d2428..e831167 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: - path: ./build/docs/px-0/ + path: ./build/docs/libproxy-1.0/ - name: CodeCov uses: codecov/codecov-action@v3 -- cgit v1.2.1 From ebb3ce6c5934933e3115fba6d3ddebff0ce9f92c Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 31 Jan 2023 16:14:10 +0100 Subject: Parse and format PAC response (#36) Fixes: https://github.com/janbrummer/libproxy2/issues/32 --- src/backend/px-manager.c | 54 ++++++++++++++++++++++++++++++++++++++++----- src/tests/px-manager-test.c | 2 +- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ea4411e..9fe2682 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -120,6 +120,8 @@ px_manager_constructed (GObject *object) peas_engine_unload_plugin (self->engine, info); } + 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); } @@ -337,15 +339,55 @@ px_manager_run_pac (PeasExtensionSet *set, { PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (extension); struct PacData *pac_data = data; - char *ret; + g_auto (GStrv) proxies_split = NULL; + char *pac_response; - if (!ifc->set_pac (PX_PAC_RUNNER (extension), pac_data->pac)) { + if (!ifc->set_pac (PX_PAC_RUNNER (extension), pac_data->pac)) return; - } - ret = ifc->run (PX_PAC_RUNNER (extension), pac_data->uri); - if (ret) - g_strv_builder_add (pac_data->builder, ret); + pac_response = ifc->run (PX_PAC_RUNNER (extension), pac_data->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) 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); + uri = g_uri_parse (uri_string, G_URI_FLAGS_PARSE_RELAXED, NULL); + if (!uri) + continue; + + if (g_ascii_strncasecmp (method, "proxy", 5) == 0) { + proxy_string = g_uri_to_string (uri); + } else if (g_ascii_strncasecmp (method, "socks", 5) == 0) { + proxy_string = g_strconcat ("socks://", server, NULL); + } else if (g_ascii_strncasecmp (method, "socks4", 6) == 0) { + proxy_string = g_strconcat ("socks4://", server, NULL); + } else if (g_ascii_strncasecmp (method, "socks4a", 7) == 0) { + proxy_string = g_strconcat ("socks4a://", server, NULL); + } else if (g_ascii_strncasecmp (method, "socks5", 6) == 0) { + proxy_string = g_strconcat ("socks5://", server, NULL); + } + + g_strv_builder_add (pac_data->builder, proxy_string); + } else { + /* Syntax not found, returning direct */ + g_strv_builder_add (pac_data->builder, "direct://"); + } + } } static gboolean diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index afab118..b62c408 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -142,7 +142,7 @@ get_proxies_pac (gpointer data) config = px_manager_get_proxies_sync (self->manager, "https://www.example.com", NULL); g_assert_nonnull (config); - g_assert_cmpstr (config[0], ==, "PROXY 127.0.0.1:1983"); + g_assert_cmpstr (config[0], ==, "http://127.0.0.1:1983"); g_main_loop_quit (self->loop); -- cgit v1.2.1 From 1a9626fa773bd3052b1e9a23094f3f6b2d18b8d5 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 31 Jan 2023 16:27:28 +0100 Subject: Take care of dbus problems (#37) In case proxy dbus service is not working, just return NULL for proxy query. --- src/libproxy/proxy-dbus.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index ef62384..3669280 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -73,6 +73,9 @@ px_proxy_factory_get_proxies (struct px_proxy_factory *self, gsize len; gsize idx; + if (!self->proxy) + return NULL; + result = g_dbus_proxy_call_sync (self->proxy, "query", g_variant_new ("(s)", url), -- cgit v1.2.1 From c26d04860318008f7b55f00676bd417670d272bb Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 1 Feb 2023 08:50:47 +0100 Subject: Always run apt update on CI (#39) --- .github/workflows/build.yml | 2 ++ .github/workflows/coverity.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e831167..5dd6034 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,7 @@ jobs: - uses: actions/checkout@v3 - name: Dependencies run: | + sudo apt-get update sudo apt install \ libglib2.0-dev \ libgirepository1.0-dev \ @@ -62,6 +63,7 @@ jobs: - uses: actions/checkout@v3 - name: Dependencies run: | + sudo apt-get update sudo apt install \ libglib2.0-dev \ libgirepository1.0-dev \ diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index e077a61..20ba216 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -27,6 +27,7 @@ jobs: - name: Ubuntu Setup if: runner.os == 'Linux' run: | + sudo apt-get update sudo apt install \ libglib2.0-dev \ libgirepository1.0-dev \ -- cgit v1.2.1 From f4cf89c63cd6f421b59d4eac7039b20f350a09dc Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 1 Feb 2023 17:29:43 +0100 Subject: Small fixes (#40) * Throw an error for dbus errors * Move curl setup to download function Move curl initialization to download function to workaround a dbus cycle error. * Move to debug output and fix pac data freeing --- src/backend/dbus/dbus.c | 2 +- src/backend/plugins/download-curl/download-curl.c | 4 +++- src/backend/px-manager.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 0dd7d75..4352082 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -124,7 +124,7 @@ on_name_lost (GDBusConnection *connection, g_warning ("Can't connect proxy bus"); g_main_loop_quit (user_data); } else { - g_warning ("Unknown name lost error"); + g_error ("Unknown name lost error"); } } diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 25228bf..9396076 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -38,7 +38,6 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadCurl, static void px_download_curl_init (PxDownloadCurl *self) { - self->curl = curl_easy_init (); } static void @@ -69,6 +68,9 @@ px_download_curl_download (PxDownload *download, CURLcode res; const char *url = uri; + if (!self->curl) + self->curl = curl_easy_init (); + if (g_str_has_prefix (url, "pac+")) url += 4; diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 9fe2682..7ef2675 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -76,7 +76,7 @@ px_manager_on_network_changed (GNetworkMonitor *monitor, self->wpad = FALSE; g_clear_pointer (&self->pac_url, g_free); - g_clear_object (&self->pac_data); + g_clear_pointer (&self->pac_data, g_bytes_unref); } static void @@ -247,7 +247,7 @@ download_pac (PeasExtensionSet *set, PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension); struct DownloadData *download_data = data; - g_print ("%s: Download PAC using plugin '%s'\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); + g_debug ("%s: Download PAC using plugin '%s'\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); if (!download_data->bytes) download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri); } @@ -294,7 +294,7 @@ get_config (PeasExtensionSet *set, PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (extension); struct ConfigData *config_data = data; - g_print ("%s: Asking plugin '%s' for configuration\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); + g_debug ("%s: Asking plugin '%s' for configuration\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); ifc->get_config (PX_CONFIG (extension), config_data->uri, config_data->builder, config_data->error); } @@ -401,7 +401,7 @@ px_manager_expand_wpad (PxManager *self, ret = TRUE; if (!self->wpad) { - g_clear_object (&self->pac_data); + g_clear_pointer (&self->pac_data, g_bytes_unref); g_clear_pointer (&self->pac_url, g_free); self->wpad = TRUE; } @@ -409,7 +409,7 @@ px_manager_expand_wpad (PxManager *self, if (!self->pac_data) { GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_PARSE_RELAXED, NULL); - g_print ("Trying to find the PAC using WPAD...\n"); + g_debug ("Trying to find the PAC using WPAD...\n"); self->pac_url = g_uri_to_string (wpad_url); self->pac_data = px_manager_pac_download (self, self->pac_url); if (!self->pac_data) { @@ -440,7 +440,7 @@ px_manager_expand_pac (PxManager *self, if (g_strcmp0 (self->pac_url, uri_str) != 0) { g_clear_pointer (&self->pac_url, g_free); - g_clear_object (&self->pac_data); + g_clear_pointer (&self->pac_data, g_bytes_unref); } } @@ -485,11 +485,11 @@ px_manager_get_proxies_sync (PxManager *self, /* TODO: Check topology */ config = px_manager_get_configuration (self, uri, error); - g_print ("Config is:\n"); + g_debug ("Config is:\n"); 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_print ("\t- %s\n", config[idx]); + g_debug ("\t- %s\n", config[idx]); if (px_manager_expand_wpad (self, conf_url) || px_manager_expand_pac (self, conf_url)) { struct PacData pac_data = { -- cgit v1.2.1 From 7826d578664bf87b1d975346979327cd514302c9 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Feb 2023 08:23:14 +0100 Subject: Improve debug output (#43) Add enabling debug output using PX_DEBUG=1 and align debug output messages. --- src/backend/dbus/dbus.c | 4 +++ src/backend/dbus/meson.build | 1 + src/backend/meson.build | 5 ++++ .../plugins/config-sysconfig/config-sysconfig.c | 4 +-- src/backend/plugins/download-curl/download-curl.c | 2 +- src/backend/plugins/download-soup/download-soup.c | 2 +- src/backend/px-manager.c | 32 ++++++++++++++++------ 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 4352082..0e5b704 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -61,9 +61,13 @@ handle_method_call (GDBusConnection *connection, result = g_variant_builder_new (G_VARIANT_TYPE ("as")); if (proxies) { + g_debug ("%s: Proxies:", __FUNCTION__); for (idx = 0; proxies[idx]; idx++) { + g_debug ("%s: \t- Proxy[%d] = %s", __FUNCTION__, idx, proxies[idx]); g_variant_builder_add (result, "s", proxies[idx]); } + } else { + g_debug ("%s: No Proxy required", __FUNCTION__); } g_dbus_method_invocation_return_value (invocation, diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build index 8ab3bfe..866d0b8 100644 --- a/src/backend/dbus/meson.build +++ b/src/backend/dbus/meson.build @@ -48,6 +48,7 @@ if get_option('dbus') executable( 'proxyd', proxyd_sources, + c_args: px_backend_c_args, dependencies: proxyd_deps, install_dir: join_paths(px_prefix, get_option('libexecdir')), install: true, diff --git a/src/backend/meson.build b/src/backend/meson.build index d83a41b..24f3d88 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -17,12 +17,17 @@ px_backend_deps = [ peas_dep, ] +px_backend_c_args = [ + '-DG_LOG_DOMAIN="libpxbackend"', +] + px_backend_inc = include_directories('.') px_backend_lib = shared_library( 'pxbackend-@0@'.format(api_version), px_backend_sources, dependencies: px_backend_deps, + c_args: px_backend_c_args, install: true ) diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index 29e8420..f6bf583 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -62,13 +62,13 @@ px_config_sysconfig_init (PxConfigSysConfig *self) file = g_file_new_for_path (self->proxy_file); if (!file) { - g_print ("Could not create file\n"); + g_debug ("%s: Could not create file", __FUNCTION__); return; } istr = g_file_read (file, NULL, NULL); if (!istr) { - g_print ("Could not read file\n"); + g_debug ("%s: Could not read file", __FUNCTION__); return; } diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 9396076..924153f 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -80,7 +80,7 @@ px_download_curl_download (PxDownload *download, res = curl_easy_perform (self->curl); if (res != CURLE_OK) { - g_debug ("Could not download data: %s", curl_easy_strerror (res)); + g_debug ("%s: Could not download data: %s", __FUNCTION__, curl_easy_strerror (res)); return NULL; } diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c index 905f173..b1a7384 100644 --- a/src/backend/plugins/download-soup/download-soup.c +++ b/src/backend/plugins/download-soup/download-soup.c @@ -61,7 +61,7 @@ px_download_soup_download (PxDownload *download, NULL, /* Pass a GCancellable here if you want to cancel a download */ &error); if (!bytes || soup_message_get_status (msg) != SOUP_STATUS_OK) { - g_debug ("Failed to download: %s\n", error ? error->message : ""); + g_debug ("%s: Failed to download: %s", __FUNCTION__, error ? error->message : ""); return NULL; } diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 7ef2675..958ffbb 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -72,7 +72,7 @@ px_manager_on_network_changed (GNetworkMonitor *monitor, { PxManager *self = PX_MANAGER (user_data); - g_debug ("%s: Network connection changed, clearing pac data\n", __FUNCTION__); + g_debug ("%s: Network connection changed, clearing pac data", __FUNCTION__); self->wpad = FALSE; g_clear_pointer (&self->pac_url, g_free); @@ -85,6 +85,21 @@ px_manager_constructed (GObject *object) PxManager *self = PX_MANAGER (object); const GList *list; + 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); + g_setenv ("G_MESSAGES_DEBUG", new_g_messages_debug, TRUE); + } + } + self->engine = peas_engine_get_default (); peas_engine_add_search_path (self->engine, self->plugins_dir, NULL); @@ -247,7 +262,7 @@ download_pac (PeasExtensionSet *set, PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension); struct DownloadData *download_data = data; - g_debug ("%s: Download PAC using plugin '%s'\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); + g_debug ("%s: Download PAC using plugin '%s'", __FUNCTION__, peas_plugin_info_get_module_name (info)); if (!download_data->bytes) download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri); } @@ -294,7 +309,7 @@ get_config (PeasExtensionSet *set, PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (extension); struct ConfigData *config_data = data; - g_debug ("%s: Asking plugin '%s' for configuration\n", __FUNCTION__, peas_plugin_info_get_module_name (info)); + g_debug ("%s: Asking plugin '%s' for configuration", __FUNCTION__, peas_plugin_info_get_module_name (info)); ifc->get_config (PX_CONFIG (extension), config_data->uri, config_data->builder, config_data->error); } @@ -409,7 +424,7 @@ px_manager_expand_wpad (PxManager *self, if (!self->pac_data) { GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_PARSE_RELAXED, NULL); - g_debug ("Trying to find the PAC using WPAD...\n"); + 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) { @@ -449,9 +464,9 @@ px_manager_expand_pac (PxManager *self, self->pac_data = px_manager_pac_download (self, self->pac_url); if (!self->pac_data) - g_error ("Unable to download PAC!"); + g_warning ("%s: Unable to download PAC from %s!", __FUNCTION__, self->pac_url); else - g_debug ("PAC recevied!\n"); + g_debug ("%s: PAC recevied!", __FUNCTION__); } } @@ -477,6 +492,7 @@ px_manager_get_proxies_sync (PxManager *self, g_autoptr (GUri) uri = g_uri_parse (url, G_URI_FLAGS_PARSE_RELAXED, error); g_auto (GStrv) config = NULL; + g_debug ("%s: url=%s", __FUNCTION__, url ? url : "?"); if (!uri) { g_strv_builder_add (builder, "direct://"); return g_strv_builder_end (builder); @@ -485,11 +501,11 @@ px_manager_get_proxies_sync (PxManager *self, /* TODO: Check topology */ config = px_manager_get_configuration (self, uri, error); - g_debug ("Config is:\n"); + g_debug ("%s: Config is:", __FUNCTION__); 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 ("\t- %s\n", config[idx]); + g_debug ("%s:\t- Config[%d] = %s\n", __FUNCTION__, idx, config[idx]); if (px_manager_expand_wpad (self, conf_url) || px_manager_expand_pac (self, conf_url)) { struct PacData pac_data = { -- cgit v1.2.1 From 89fecc5a95ed64dc590e203f3dc3bef70313345d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Feb 2023 08:44:44 +0100 Subject: Fix PAC download error (#44) In case PAC file cannot be download, clear pac_url and treat as a non pac case. --- src/backend/px-manager.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 958ffbb..ad60ea8 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -463,10 +463,13 @@ px_manager_expand_pac (PxManager *self, self->pac_url = g_uri_to_string (uri); self->pac_data = px_manager_pac_download (self, self->pac_url); - if (!self->pac_data) + if (!self->pac_data) { g_warning ("%s: Unable to download PAC from %s!", __FUNCTION__, self->pac_url); - else + g_clear_pointer (&self->pac_url, g_free); + ret = FALSE; + } else { g_debug ("%s: PAC recevied!", __FUNCTION__); + } } } -- cgit v1.2.1 From 09587d08d2f0013adcfe0026cc37c74e9e1b628b Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Feb 2023 08:54:31 +0100 Subject: Set curl options to fix recursive calls (#45) Set various curl options to ensure we are not calling back to libproxy and also improve timeout handling and identification. --- src/backend/plugins/download-curl/download-curl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index 924153f..d848795 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -71,9 +71,18 @@ px_download_curl_download (PxDownload *download, 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); -- cgit v1.2.1 From 42aeea8f26b8a9c8341ab37a82d8060673a220ab Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Feb 2023 09:32:10 +0100 Subject: Handle network available status (#46) --- src/backend/px-manager.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ad60ea8..a39cdca 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -56,6 +56,7 @@ struct _PxManager { char *config_plugin; + gboolean online; gboolean wpad; GBytes *pac_data; char *pac_url; @@ -75,6 +76,7 @@ px_manager_on_network_changed (GNetworkMonitor *monitor, 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); } @@ -138,6 +140,7 @@ px_manager_constructed (GObject *object) self->pac_data = NULL; self->network_monitor = g_network_monitor_get_default (); + self->online = g_network_monitor_get_network_available (self->network_monitor); g_signal_connect_object (G_OBJECT (self->network_monitor), "network-changed", G_CALLBACK (px_manager_on_network_changed), self, 0); } @@ -464,7 +467,7 @@ px_manager_expand_pac (PxManager *self, self->pac_data = px_manager_pac_download (self, self->pac_url); if (!self->pac_data) { - g_warning ("%s: Unable to download PAC from %s!", __FUNCTION__, self->pac_url); + 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 { @@ -495,13 +498,12 @@ px_manager_get_proxies_sync (PxManager *self, g_autoptr (GUri) uri = g_uri_parse (url, G_URI_FLAGS_PARSE_RELAXED, error); g_auto (GStrv) config = NULL; - g_debug ("%s: url=%s", __FUNCTION__, url ? url : "?"); - if (!uri) { + g_debug ("%s: url=%s online=%d", __FUNCTION__, url ? url : "?", self->online); + if (!uri || !self->online) { g_strv_builder_add (builder, "direct://"); return g_strv_builder_end (builder); } - /* TODO: Check topology */ config = px_manager_get_configuration (self, uri, error); g_debug ("%s: Config is:", __FUNCTION__); -- cgit v1.2.1 From cf685beba5c782d4171e058eebeb2b9145bff6f5 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Feb 2023 14:15:09 +0100 Subject: Remove load check in pxmanager (#48) This check does nothing and can be removed. --- src/backend/px-manager.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index a39cdca..4981c30 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -116,14 +116,12 @@ px_manager_constructed (GObject *object) PeasExtension *extension = peas_extension_set_get_extension (self->config_set, info); gboolean available = TRUE; - if (!peas_plugin_info_is_loaded (info)) { - /* In case user requested a specific module, just load that one */ - if (self->config_plugin && g_str_has_prefix (peas_plugin_info_get_module_name (info), "config-")) { - if (g_strcmp0 (peas_plugin_info_get_module_name (info), self->config_plugin) == 0) - peas_engine_load_plugin (self->engine, info); - } else { + /* In case user requested a specific module, just load that one */ + if (self->config_plugin && g_str_has_prefix (peas_plugin_info_get_module_name (info), "config-")) { + if (g_strcmp0 (peas_plugin_info_get_module_name (info), self->config_plugin) == 0) peas_engine_load_plugin (self->engine, info); - } + } else { + peas_engine_load_plugin (self->engine, info); } extension = peas_extension_set_get_extension (self->config_set, info); -- cgit v1.2.1 From de336fbccf6a1b617cbfae20f66ed85a3dcf8a45 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Feb 2023 14:46:57 +0100 Subject: Simplify get_config API (#47) Remove return value as it was unused, as well as GError. In case an error occures we can dump it into debug. There is no user benefit. --- src/backend/plugins/config-env/config-env.c | 13 +++++-------- src/backend/plugins/config-gnome/config-gnome.c | 11 ++++------- src/backend/plugins/config-kde/config-kde.c | 15 ++++++--------- src/backend/plugins/config-osx/config-osx.c | 17 +++++++---------- src/backend/plugins/config-sysconfig/config-sysconfig.c | 15 ++++++--------- src/backend/plugins/config-windows/config-windows.c | 17 +++++++---------- src/backend/px-manager.c | 4 +--- src/backend/px-plugin-config.h | 2 +- 8 files changed, 37 insertions(+), 57 deletions(-) diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index cbc4de5..e98ad52 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -93,11 +93,10 @@ px_config_env_is_available (PxConfig *self) return TRUE; } -static gboolean -px_config_env_get_config (PxConfig *config, - GUri *uri, - GStrvBuilder *builder, - GError **error) +static void +px_config_env_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder) { PxConfigEnv *self = PX_CONFIG_ENV (config); const char *proxy = NULL; @@ -108,7 +107,7 @@ px_config_env_get_config (PxConfig *config, * - case insensitive check? */ if (self->no_proxy && (g_strv_contains ((const char * const *)self->no_proxy, g_uri_get_host (uri)) || g_strv_contains ((const char * const *)self->no_proxy, "*"))) { - return TRUE; + return; } if (g_strcmp0 (scheme, "ftp") == 0) @@ -123,8 +122,6 @@ px_config_env_get_config (PxConfig *config, /* TODO: Where should we add proxy url validation ? */ if (proxy) g_strv_builder_add (builder, proxy); - - return TRUE; } static void diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index 0416d2e..053544d 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -117,11 +117,10 @@ store_response (GStrvBuilder *builder, } } -static gboolean -px_config_gnome_get_config (PxConfig *config, - GUri *uri, - GStrvBuilder *builder, - GError **error) +static void +px_config_gnome_get_config (PxConfig *config, + GUri *uri, + GStrvBuilder *builder) { PxConfigGnome *self = PX_CONFIG_GNOME (config); g_autofree char *proxy = NULL; @@ -181,8 +180,6 @@ px_config_gnome_get_config (PxConfig *config, password); } } - - return TRUE; } static void diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 519a2d5..917ccd2 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -152,21 +152,20 @@ px_config_kde_is_available (PxConfig *config) return self->available && g_getenv ("KDE_FULL_SESSION") != NULL; } -static gboolean -px_config_kde_get_config (PxConfig *config, - GUri *uri, - GStrvBuilder *builder, - GError **error) +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->proxy_type) - return TRUE; + return; if (self->no_proxy && strstr (self->no_proxy, g_uri_get_host (uri))) - return TRUE; + return; switch (self->proxy_type) { case KDE_PROXY_TYPE_MANUAL: @@ -194,8 +193,6 @@ px_config_kde_get_config (PxConfig *config, if (proxy) g_strv_builder_add (builder, proxy); - - return TRUE; } static void diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index a4041eb..e6192e9 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -119,24 +119,23 @@ getbool (CFDictionaryRef settings, return i != 0; } -static gboolean -px_config_osx_get_config (PxConfig *self, - GUri *uri, - GStrvBuilder *builder, - GError **error) +static void +px_config_osx_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder) { const char *proxy = NULL; CFDictionaryRef proxies = SCDynamicStoreCopyProxies (NULL); if (!proxies) { g_warning ("Unable to fetch proxy configuration"); - return FALSE; + return; } if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { CFRelease (proxies); g_strv_builder_add (builder, "wpad://"); - return TRUE; + return; } if (getbool (proxies, "ProxyAutoConfigEnable")) { @@ -148,15 +147,13 @@ px_config_osx_get_config (PxConfig *self, g_autofree char *ret = g_strdup_printf ("pac+%s", g_uri_to_string (tmp_uri)); CFRelease (proxies); g_strv_builder_add (builder, ret); - return TRUE; + return; } } g_print ("%s: Whatever", __FUNCTION__); if (proxy) g_strv_builder_add (builder, proxy); - - return TRUE; } static void diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index f6bf583..d05eb39 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -122,21 +122,20 @@ px_config_sysconfig_is_available (PxConfig *config) return self->available; } -static gboolean -px_config_sysconfig_get_config (PxConfig *config, - GUri *uri, - GStrvBuilder *builder, - GError **error) +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 TRUE; + return; if (self->no_proxy && strstr (self->no_proxy, g_uri_get_host (uri))) - return TRUE; + return; if (g_strcmp0 (scheme, "ftp") == 0) { proxy = g_strdup (self->ftp_proxy); @@ -148,8 +147,6 @@ px_config_sysconfig_get_config (PxConfig *config, if (proxy) g_strv_builder_add (builder, proxy); - - return TRUE; } static void diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index 14ac064..903c332 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -123,11 +123,10 @@ is_enabled (char type) return result; } -static gboolean -px_config_windows_get_config (PxConfig *self, - GUri *uri, - GStrvBuilder *builder, - GError **error) +static void +px_config_windows_get_config (PxConfig *self, + GUri *uri, + GStrvBuilder *builder) { char *tmp = NULL; guint32 enabled = 0; @@ -139,7 +138,7 @@ px_config_windows_get_config (PxConfig *self, /* WPAD */ if (is_enabled (W32REG_OFFSET_WPAD)) { g_strv_builder_add (builder, "wpad://"); - return TRUE; + return; } /* PAC */ @@ -149,7 +148,7 @@ px_config_windows_get_config (PxConfig *self, if (ac_uri) { g_strv_builder_add (builder, pac_uri); - return TRUE; + return; } } @@ -158,10 +157,8 @@ px_config_windows_get_config (PxConfig *self, g_autofree char *http_proxy = g_strconcat ("http://", tmp, NULL); /* TODO */ g_strv_builder_add (builder, http_proxy); - return TRUE; + return; } - - return TRUE; } static void diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 4981c30..f54791c 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -293,7 +293,6 @@ px_manager_pac_download (PxManager *self, struct ConfigData { GStrvBuilder *builder; GUri *uri; - GError **error; }; /** @@ -311,7 +310,7 @@ get_config (PeasExtensionSet *set, struct ConfigData *config_data = data; g_debug ("%s: Asking plugin '%s' for configuration", __FUNCTION__, peas_plugin_info_get_module_name (info)); - ifc->get_config (PX_CONFIG (extension), config_data->uri, config_data->builder, config_data->error); + ifc->get_config (PX_CONFIG (extension), config_data->uri, config_data->builder); } /** @@ -333,7 +332,6 @@ px_manager_get_configuration (PxManager *self, struct ConfigData config_data = { .uri = uri, .builder = builder, - .error = error, }; peas_extension_set_foreach (self->config_set, get_config, &config_data); diff --git a/src/backend/px-plugin-config.h b/src/backend/px-plugin-config.h index 279479f..93cdc5b 100644 --- a/src/backend/px-plugin-config.h +++ b/src/backend/px-plugin-config.h @@ -34,7 +34,7 @@ struct _PxConfigInterface GTypeInterface parent_iface; gboolean (*is_available) (PxConfig *self); - gboolean (*get_config) (PxConfig *self, GUri *uri, GStrvBuilder *builder, GError **error); + void (*get_config) (PxConfig *self, GUri *uri, GStrvBuilder *builder); }; G_END_DECLS -- cgit v1.2.1 From 9376b17ba95e0e592719e23bf6a350c8205c0172 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 7 Feb 2023 08:23:06 +0100 Subject: Cleanup config plugins (#50) --- src/backend/plugins/config-env/config-env.c | 10 +- src/backend/plugins/config-env/config-env.h | 3 +- src/backend/plugins/config-env/config-env.plugin | 6 +- src/backend/plugins/config-env/meson.build | 1 + src/backend/plugins/config-gnome/config-gnome.c | 20 +-- src/backend/plugins/config-gnome/config-gnome.h | 2 +- .../plugins/config-gnome/config-gnome.plugin | 3 - src/backend/plugins/config-gnome/meson.build | 1 + src/backend/plugins/config-kde/config-kde.c | 7 +- src/backend/plugins/config-kde/config-kde.h | 3 +- src/backend/plugins/config-kde/config-kde.plugin | 3 - src/backend/plugins/config-kde/meson.build | 1 + src/backend/plugins/config-osx/config-osx.c | 141 ++++++++++++++++++++- src/backend/plugins/config-osx/config-osx.h | 2 +- src/backend/plugins/config-osx/config-osx.plugin | 3 - src/backend/plugins/config-osx/meson.build | 3 +- .../plugins/config-sysconfig/config-sysconfig.c | 4 +- .../plugins/config-sysconfig/config-sysconfig.h | 3 +- .../config-sysconfig/config-sysconfig.plugin | 3 - src/backend/plugins/config-sysconfig/meson.build | 1 + .../plugins/config-windows/config-windows.c | 60 ++++++++- .../plugins/config-windows/config-windows.h | 2 +- .../plugins/config-windows/config-windows.plugin | 3 - src/backend/plugins/config-windows/meson.build | 1 + src/backend/px-manager.c | 2 +- src/tests/config-env-test.c | 21 ++- src/tests/config-gnome-test.c | 99 +++++++++++++-- src/tests/config-kde-test.c | 38 +++++- src/tests/config-sysconfig-test.c | 12 +- src/tests/data/sample-sysconfig-proxy | 1 + 30 files changed, 366 insertions(+), 93 deletions(-) diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index e98ad52..bec1d72 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -1,6 +1,6 @@ /* config-env.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -23,8 +23,8 @@ #include "config-env.h" -#include "px-plugin-config.h" #include "px-manager.h" +#include "px-plugin-config.h" static void px_config_iface_init (PxConfigInterface *iface); G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); @@ -102,10 +102,6 @@ px_config_env_get_config (PxConfig *config, const char *proxy = NULL; const char *scheme = g_uri_get_scheme (uri); - /* TODO: - * - Are host names resolved to IPs?? - * - case insensitive check? - */ if (self->no_proxy && (g_strv_contains ((const char * const *)self->no_proxy, g_uri_get_host (uri)) || g_strv_contains ((const char * const *)self->no_proxy, "*"))) { return; } @@ -115,11 +111,9 @@ px_config_env_get_config (PxConfig *config, else if (g_strcmp0 (scheme, "https") == 0) proxy = self->https_proxy; - /* TODO: Is this what we want as a fallback? What about ALL_PROXY? */ if (!proxy) proxy = self->http_proxy; - /* TODO: Where should we add proxy url validation ? */ if (proxy) g_strv_builder_add (builder, proxy); } diff --git a/src/backend/plugins/config-env/config-env.h b/src/backend/plugins/config-env/config-env.h index 7d31d4e..6b654bd 100644 --- a/src/backend/plugins/config-env/config-env.h +++ b/src/backend/plugins/config-env/config-env.h @@ -1,6 +1,6 @@ /* config-env.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -22,7 +22,6 @@ #pragma once #include -#include G_BEGIN_DECLS diff --git a/src/backend/plugins/config-env/config-env.plugin b/src/backend/plugins/config-env/config-env.plugin index 34b3049..2dfbdf3 100644 --- a/src/backend/plugins/config-env/config-env.plugin +++ b/src/backend/plugins/config-env/config-env.plugin @@ -1,7 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Read proxy configuration from environment variables Module=config-env -Name=Environment Variables -Builtin=True \ No newline at end of file +Name=Environment Variables \ No newline at end of file diff --git a/src/backend/plugins/config-env/meson.build b/src/backend/plugins/config-env/meson.build index 9496775..471ecc0 100644 --- a/src/backend/plugins/config-env/meson.build +++ b/src/backend/plugins/config-env/meson.build @@ -14,6 +14,7 @@ plugin_lib = shared_module( plugin_name, sources: plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index 053544d..f5c8008 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -1,6 +1,6 @@ /* config-gnome.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -20,9 +20,9 @@ */ #include -#include #include "config-gnome.h" + #include "px-plugin-config.h" struct _PxConfigGnome { @@ -35,11 +35,11 @@ struct _PxConfigGnome { gboolean settings_found; }; -enum { +typedef enum { GNOME_PROXY_MODE_NONE, GNOME_PROXY_MODE_MANUAL, GNOME_PROXY_MODE_AUTO -}; +} GnomeProxyMode; static void px_config_iface_init (PxConfigInterface *iface); void peas_register_types (PeasObjectModule *module); @@ -104,8 +104,8 @@ store_response (GStrvBuilder *builder, char *username, char *password) { - if (host && port != 0) { - GString *tmp = g_string_new (type); + if (type && host && port != 0) { + g_autoptr (GString) tmp = g_string_new (type); g_string_append (tmp, "://"); if (auth) @@ -113,7 +113,7 @@ store_response (GStrvBuilder *builder, g_string_append_printf (tmp, "%s:%d", host, port); - g_strv_builder_add (builder, g_string_free (tmp, FALSE)); + g_strv_builder_add (builder, tmp->str); } } @@ -124,7 +124,7 @@ px_config_gnome_get_config (PxConfig *config, { PxConfigGnome *self = PX_CONFIG_GNOME (config); g_autofree char *proxy = NULL; - int mode; + GnomeProxyMode mode; mode = g_settings_get_enum (self->proxy_settings, "mode"); if (mode == GNOME_PROXY_MODE_AUTO) { @@ -137,10 +137,10 @@ px_config_gnome_get_config (PxConfig *config, g_strv_builder_add (builder, proxy); } else if (mode == GNOME_PROXY_MODE_MANUAL) { - gboolean auth = g_settings_get_boolean (self->http_proxy_settings, "use-authentication"); 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"); @@ -174,7 +174,7 @@ px_config_gnome_get_config (PxConfig *config, store_response (builder, "socks", host, - g_settings_get_int (self->ftp_proxy_settings, "port"), + g_settings_get_int (self->socks_proxy_settings, "port"), auth, username, password); diff --git a/src/backend/plugins/config-gnome/config-gnome.h b/src/backend/plugins/config-gnome/config-gnome.h index 53402e9..c5e8c6e 100644 --- a/src/backend/plugins/config-gnome/config-gnome.h +++ b/src/backend/plugins/config-gnome/config-gnome.h @@ -1,6 +1,6 @@ /* config-gnome.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/plugins/config-gnome/config-gnome.plugin b/src/backend/plugins/config-gnome/config-gnome.plugin index 2b3f442..5121ceb 100644 --- a/src/backend/plugins/config-gnome/config-gnome.plugin +++ b/src/backend/plugins/config-gnome/config-gnome.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Read proxy configuration from GNOME settings Module=config-gnome Name=GNOME Settings \ No newline at end of file diff --git a/src/backend/plugins/config-gnome/meson.build b/src/backend/plugins/config-gnome/meson.build index ba99418..08acc1c 100644 --- a/src/backend/plugins/config-gnome/meson.build +++ b/src/backend/plugins/config-gnome/meson.build @@ -14,6 +14,7 @@ plugin_lib = shared_module( plugin_name, plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [peas_dep, px_backend_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 917ccd2..3fb6d1c 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -1,6 +1,6 @@ /* config-kde.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -66,16 +66,15 @@ px_config_kde_read_config (PxConfigKde *self, g_autoptr (GFileInputStream) istr = NULL; g_autoptr (GDataInputStream) dstr = NULL; - file = g_file_new_for_path (proxy_file); if (!file) { - g_print ("Could not create file\n"); + g_debug ("%s: Could not create file", __FUNCTION__); return; } istr = g_file_read (file, NULL, NULL); if (!istr) { - g_print ("Could not read file\n"); + g_debug ("%s: Could not read file", __FUNCTION__); return; } diff --git a/src/backend/plugins/config-kde/config-kde.h b/src/backend/plugins/config-kde/config-kde.h index 408b28a..892c45a 100644 --- a/src/backend/plugins/config-kde/config-kde.h +++ b/src/backend/plugins/config-kde/config-kde.h @@ -1,6 +1,6 @@ /* config-kde.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -22,7 +22,6 @@ #pragma once #include -#include G_BEGIN_DECLS diff --git a/src/backend/plugins/config-kde/config-kde.plugin b/src/backend/plugins/config-kde/config-kde.plugin index b8aabab..d03d2a8 100644 --- a/src/backend/plugins/config-kde/config-kde.plugin +++ b/src/backend/plugins/config-kde/config-kde.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Read proxy configuration from KDE System Settings Module=config-kde Name=KDE \ No newline at end of file diff --git a/src/backend/plugins/config-kde/meson.build b/src/backend/plugins/config-kde/meson.build index 109e5db..ef4adfe 100644 --- a/src/backend/plugins/config-kde/meson.build +++ b/src/backend/plugins/config-kde/meson.build @@ -14,6 +14,7 @@ plugin_lib = shared_module( plugin_name, sources: plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index e6192e9..08b87c3 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -1,6 +1,6 @@ /* config-osx.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -91,6 +91,37 @@ getobj_str (CFDictionaryRef settings, 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, @@ -119,6 +150,94 @@ getbool (CFDictionaryRef settings, 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); + + g_strv_builder_add (ret, str (s)); + } + + if (getbool (proxies, "ExcludeSimpleHostnames")) + g_strv_builder_add (ret, "127.0.0.1"); + + return g_strv_builder_end (ret); +} + static void px_config_osx_get_config (PxConfig *self, GUri *uri, @@ -126,12 +245,18 @@ px_config_osx_get_config (PxConfig *self, { 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 (ignore_list && g_strv_contains ((const char * const *)ignore_list, g_uri_get_host (uri))) + return; + if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { CFRelease (proxies); g_strv_builder_add (builder, "wpad://"); @@ -140,7 +265,7 @@ px_config_osx_get_config (PxConfig *self, if (getbool (proxies, "ProxyAutoConfigEnable")) { CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString"); - const char *tmp = CFStringGetCStringPtr (ref, CFStringGetFastestEncoding (ref)); + g_autofree char *tmp = str (ref); GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL); if (tmp_uri) { @@ -149,9 +274,19 @@ px_config_osx_get_config (PxConfig *self, g_strv_builder_add (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, "HTTP"); + + if (!proxy) + proxy = protocol_url (proxies, "SOCKS"); } - g_print ("%s: Whatever", __FUNCTION__); if (proxy) g_strv_builder_add (builder, proxy); } diff --git a/src/backend/plugins/config-osx/config-osx.h b/src/backend/plugins/config-osx/config-osx.h index 62e71ca..544329f 100644 --- a/src/backend/plugins/config-osx/config-osx.h +++ b/src/backend/plugins/config-osx/config-osx.h @@ -1,6 +1,6 @@ /* config-osx.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/plugins/config-osx/config-osx.plugin b/src/backend/plugins/config-osx/config-osx.plugin index 25e4bdd..61c4a2a 100644 --- a/src/backend/plugins/config-osx/config-osx.plugin +++ b/src/backend/plugins/config-osx/config-osx.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Read proxy configuration from OS X Module=config-osx Name=OS X \ No newline at end of file diff --git a/src/backend/plugins/config-osx/meson.build b/src/backend/plugins/config-osx/meson.build index 4435bbf..eac98e8 100644 --- a/src/backend/plugins/config-osx/meson.build +++ b/src/backend/plugins/config-osx/meson.build @@ -16,6 +16,7 @@ plugin_lib = shared_module( plugin_name, plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, @@ -35,4 +36,4 @@ custom_target( endif -endif \ No newline at end of file +endif diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index d05eb39..77c7fe1 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -1,6 +1,6 @@ /* config-sysconfig.c * - * Copyright 2023 Jan-Michael Brummer + * 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 @@ -23,8 +23,8 @@ #include "config-sysconfig.h" -#include "px-plugin-config.h" #include "px-manager.h" +#include "px-plugin-config.h" struct _PxConfigSysConfig { GObject parent_instance; diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.h b/src/backend/plugins/config-sysconfig/config-sysconfig.h index 176da94..daa4672 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.h +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.h @@ -1,6 +1,6 @@ /* config-sysconfig.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -22,7 +22,6 @@ #pragma once #include -#include G_BEGIN_DECLS diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.plugin b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin index d164295..0697fa2 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.plugin +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Read proxy configuration from /etc/sysconfig/proxy Module=config-sysconfig Name=sysconfig \ No newline at end of file diff --git a/src/backend/plugins/config-sysconfig/meson.build b/src/backend/plugins/config-sysconfig/meson.build index d5b3613..2ac17fb 100644 --- a/src/backend/plugins/config-sysconfig/meson.build +++ b/src/backend/plugins/config-sysconfig/meson.build @@ -14,6 +14,7 @@ plugin_lib = shared_module( plugin_name, plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index 903c332..c8bc94d 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -1,6 +1,6 @@ /* config-windows.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -107,6 +107,33 @@ get_registry (const char *key, 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) { @@ -132,7 +159,10 @@ px_config_windows_get_config (PxConfig *self, guint32 enabled = 0; if (get_registry (W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) { - g_print ("Override: %s\n", tmp); + const char *host = g_uri_get_host (uri); + + if (g_strcmp0 (tmp, "") == 0 && g_strcmp0 (host, "127.0.0.1") == 0) + return; } /* WPAD */ @@ -154,10 +184,28 @@ px_config_windows_get_config (PxConfig *self, /* Manual proxy */ if (get_registry (W32REG_BASEKEY, "ProxyEnable", NULL, NULL, &enabled) && enabled && get_registry (W32REG_BASEKEY, "ProxyServer", &tmp, NULL, NULL)) { - g_autofree char *http_proxy = g_strconcat ("http://", tmp, NULL); - /* TODO */ - g_strv_builder_add (builder, http_proxy); - return; + 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) { + g_strv_builder_add (builder, ret); + return; + } + + ret = g_hash_table_lookup (table, "http"); + if (ret) { + g_strv_builder_add (builder, ret); + return; + } + + ret = g_hash_table_lookup (table, "socks"); + if (ret) { + g_strv_builder_add (builder, ret); + return; + } + } } } diff --git a/src/backend/plugins/config-windows/config-windows.h b/src/backend/plugins/config-windows/config-windows.h index e7706e5..7c2afcf 100644 --- a/src/backend/plugins/config-windows/config-windows.h +++ b/src/backend/plugins/config-windows/config-windows.h @@ -1,6 +1,6 @@ /* config-windows.h * - * Copyright 2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/plugins/config-windows/config-windows.plugin b/src/backend/plugins/config-windows/config-windows.plugin index e8af810..04a589b 100644 --- a/src/backend/plugins/config-windows/config-windows.plugin +++ b/src/backend/plugins/config-windows/config-windows.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Read proxy configuration from Windows registry Module=config-windows Name=Windows \ No newline at end of file diff --git a/src/backend/plugins/config-windows/meson.build b/src/backend/plugins/config-windows/meson.build index 9416e34..2e592b5 100644 --- a/src/backend/plugins/config-windows/meson.build +++ b/src/backend/plugins/config-windows/meson.build @@ -16,6 +16,7 @@ plugin_lib = shared_module( plugin_name, plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index f54791c..be6b5f5 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -263,7 +263,7 @@ download_pac (PeasExtensionSet *set, PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension); struct DownloadData *download_data = data; - g_debug ("%s: Download PAC using plugin '%s'", __FUNCTION__, peas_plugin_info_get_module_name (info)); + g_debug ("%s: Download PAC '%s' using plugin '%s'", __FUNCTION__, download_data->uri, peas_plugin_info_get_module_name (info)); if (!download_data->bytes) download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri); } diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c index 2c780d2..34d3218 100644 --- a/src/tests/config-env-test.c +++ b/src/tests/config-env-test.c @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* 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 @@ -14,8 +14,10 @@ * * 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 "px-manager.h" @@ -67,8 +69,12 @@ test_config_env (void) continue; } - if (test.no_proxy) - g_setenv ("NO_PROXY", test.no_proxy, TRUE); + 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"); g_clear_error (&error); @@ -82,6 +88,7 @@ test_config_env (void) g_unsetenv (test.env); g_unsetenv ("NO_PROXY"); + g_unsetenv ("no_proxy"); g_clear_object (&manager); } diff --git a/src/tests/config-gnome-test.c b/src/tests/config-gnome-test.c index 2f4bb8c..7d8223d 100644 --- a/src/tests/config-gnome-test.c +++ b/src/tests/config-gnome-test.c @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* 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 @@ -14,8 +14,10 @@ * * 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 "px-manager.h" @@ -29,6 +31,7 @@ typedef struct { GSettings *http_proxy_settings; GSettings *https_proxy_settings; GSettings *ftp_proxy_settings; + GSettings *socks_proxy_settings; } Fixture; enum { @@ -51,6 +54,7 @@ static const ConfigGnomeTest config_gnome_test_set[] = { { 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 @@ -61,6 +65,7 @@ fixture_setup (Fixture *self, 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 @@ -70,8 +75,8 @@ fixture_teardown (Fixture *fixture, } static void -test_config_gnome (Fixture *self, - const void *user_data) +test_config_gnome_manual (Fixture *self, + const void *user_data) { int idx; @@ -89,6 +94,8 @@ test_config_gnome (Fixture *self, 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"); g_clear_error (&error); @@ -100,22 +107,90 @@ test_config_gnome (Fixture *self, } config = px_manager_get_configuration (manager, uri, &error); - if (test.success) - g_assert_cmpstr (config[0], ==, test.expected_return); - else - g_assert_cmpstr (config[0], !=, test.expected_return); + 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"); + 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"); + 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 */ + g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE); + + manager = px_test_manager_new ("config-gnome"); + 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_test_add ("/config/gnome", Fixture, NULL, fixture_setup, test_config_gnome, fixture_teardown); + 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/src/tests/config-kde-test.c b/src/tests/config-kde-test.c index 08b950b..9aba2d5 100644 --- a/src/tests/config-kde-test.c +++ b/src/tests/config-kde-test.c @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* 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 @@ -14,8 +14,10 @@ * * 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 "px-manager.h" @@ -33,6 +35,7 @@ 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}, @@ -194,6 +197,30 @@ test_config_kde_pac (void) } } +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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + } + + /* Disable KDE support */ + g_unsetenv ("KDE_FULL_SESSION"); + + manager = px_test_manager_new ("config-kde"); + + 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) @@ -204,6 +231,7 @@ main (int argc, 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/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c index 1a2d3ec..4cc0989 100644 --- a/src/tests/config-sysconfig-test.c +++ b/src/tests/config-sysconfig-test.c @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* 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 @@ -14,8 +14,10 @@ * * 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 "px-manager.h" diff --git a/src/tests/data/sample-sysconfig-proxy b/src/tests/data/sample-sysconfig-proxy index 08aba65..1318f21 100644 --- a/src/tests/data/sample-sysconfig-proxy +++ b/src/tests/data/sample-sysconfig-proxy @@ -3,3 +3,4 @@ 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 -- cgit v1.2.1 From 3d2ae29f664dfe9312664e3c1abf9b38d01a3005 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 7 Feb 2023 08:30:21 +0100 Subject: Remove temporary string variable (#49) This can be safely replaced by duk_push_lstring. --- src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c index 72f4b2b..4425d8e 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -154,9 +154,8 @@ px_pacrunner_duktape_set_pac (PxPacRunner *pacrunner, PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (pacrunner); gsize len; gconstpointer content = g_bytes_get_data (pac_data, &len); - g_autoptr (GString) pac = g_string_new_len (content, len); - duk_push_string (self->ctx, pac->str); + duk_push_lstring (self->ctx, content, len); if (duk_peval_noresult (self->ctx)) { return FALSE; -- cgit v1.2.1 From 0bd5a16259bb5274d0642aa98ae4c10d68b2479e Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 7 Feb 2023 09:49:59 +0100 Subject: Code cleanup (#51) Update header and minor cleanup --- src/backend/dbus/dbus.c | 2 +- src/backend/plugins/download-curl/download-curl.c | 7 ++++++- src/backend/plugins/download-curl/download-curl.h | 8 +------- .../plugins/download-curl/download-curl.plugin | 3 --- src/backend/plugins/download-curl/meson.build | 1 + src/backend/plugins/download-soup/download-soup.c | 8 +++++++- src/backend/plugins/download-soup/download-soup.h | 9 +-------- .../plugins/download-soup/download-soup.plugin | 3 --- src/backend/plugins/download-soup/meson.build | 1 + src/backend/plugins/pacrunner-duktape/meson.build | 1 + .../plugins/pacrunner-duktape/pacrunner-duktape.c | 2 +- .../plugins/pacrunner-duktape/pacrunner-duktape.h | 2 +- .../pacrunner-duktape/pacrunner-duktape.plugin | 3 --- src/backend/px-manager.c | 2 +- src/backend/px-manager.h | 2 +- src/backend/px-plugin-config.c | 2 +- src/backend/px-plugin-config.h | 2 +- src/backend/px-plugin-download.c | 2 +- src/backend/px-plugin-download.h | 2 +- src/backend/px-plugin-pacrunner.c | 2 +- src/backend/px-plugin-pacrunner.h | 2 +- src/libproxy/proxy-dbus.c | 13 +++++++------ src/libproxy/proxy.c | 13 +++++++------ src/libproxy/proxy.h | 14 ++++++++------ src/tests/px-manager-helper.c | 21 +++++++++++++++++++++ src/tests/px-manager-helper.h | 21 +++++++++++++++++++++ src/tests/px-manager-test.c | 12 +++++++----- src/tools/proxy.c | 21 +++++++++++++++++++++ 28 files changed, 121 insertions(+), 60 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 0e5b704..031f905 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -1,6 +1,6 @@ /* main.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c index d848795..d26d62b 100644 --- a/src/backend/plugins/download-curl/download-curl.c +++ b/src/backend/plugins/download-curl/download-curl.c @@ -1,6 +1,6 @@ /* download-curl.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -30,6 +30,11 @@ static void px_download_iface_init (PxDownloadInterface *iface); G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); +struct _PxDownloadCurl { + GObject parent_instance; + CURL *curl; +}; + G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadCurl, px_download_curl, G_TYPE_OBJECT, diff --git a/src/backend/plugins/download-curl/download-curl.h b/src/backend/plugins/download-curl/download-curl.h index 4b95140..545222c 100644 --- a/src/backend/plugins/download-curl/download-curl.h +++ b/src/backend/plugins/download-curl/download-curl.h @@ -1,6 +1,6 @@ /* download-curl.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -22,7 +22,6 @@ #pragma once #include -#include G_BEGIN_DECLS @@ -30,11 +29,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (PxDownloadCurl, px_download_curl, PX, DOWNLOAD_CURL, GObject) -struct _PxDownloadCurl { - GObject parent_instance; - CURL *curl; -}; - G_END_DECLS diff --git a/src/backend/plugins/download-curl/download-curl.plugin b/src/backend/plugins/download-curl/download-curl.plugin index 7aa75d6..1b10a83 100644 --- a/src/backend/plugins/download-curl/download-curl.plugin +++ b/src/backend/plugins/download-curl/download-curl.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Donwload data using cURL Module=download-curl Name=cURL \ No newline at end of file diff --git a/src/backend/plugins/download-curl/meson.build b/src/backend/plugins/download-curl/meson.build index 29da33e..a1d8736 100644 --- a/src/backend/plugins/download-curl/meson.build +++ b/src/backend/plugins/download-curl/meson.build @@ -14,6 +14,7 @@ plugin_lib = shared_module( plugin_name, sources: plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep, curl_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c index b1a7384..4b4aa42 100644 --- a/src/backend/plugins/download-soup/download-soup.c +++ b/src/backend/plugins/download-soup/download-soup.c @@ -1,6 +1,6 @@ /* download-soup.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -30,6 +30,12 @@ static void px_download_iface_init (PxDownloadInterface *iface); G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); +struct _PxDownloadSoup { + GObject parent_instance; + + SoupSession *session; +}; + G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadSoup, px_download_soup, G_TYPE_OBJECT, diff --git a/src/backend/plugins/download-soup/download-soup.h b/src/backend/plugins/download-soup/download-soup.h index 26afd9e..fa95c46 100644 --- a/src/backend/plugins/download-soup/download-soup.h +++ b/src/backend/plugins/download-soup/download-soup.h @@ -1,6 +1,6 @@ /* download-soup.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 @@ -22,7 +22,6 @@ #pragma once #include -#include G_BEGIN_DECLS @@ -30,12 +29,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (PxDownloadSoup, px_download_soup, PX, DOWNLOAD_SOUP, GObject) -struct _PxDownloadSoup { - GObject parent_instance; - - SoupSession *session; -}; - G_END_DECLS diff --git a/src/backend/plugins/download-soup/download-soup.plugin b/src/backend/plugins/download-soup/download-soup.plugin index 6e9cbb1..294b957 100644 --- a/src/backend/plugins/download-soup/download-soup.plugin +++ b/src/backend/plugins/download-soup/download-soup.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Donwload data using SOUP Module=download-soup Name=SOUP \ No newline at end of file diff --git a/src/backend/plugins/download-soup/meson.build b/src/backend/plugins/download-soup/meson.build index 68cc288..db61aba 100644 --- a/src/backend/plugins/download-soup/meson.build +++ b/src/backend/plugins/download-soup/meson.build @@ -14,6 +14,7 @@ plugin_lib = shared_module( plugin_name, sources: plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep, soup_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/pacrunner-duktape/meson.build b/src/backend/plugins/pacrunner-duktape/meson.build index 41ab6cc..ef4a470 100644 --- a/src/backend/plugins/pacrunner-duktape/meson.build +++ b/src/backend/plugins/pacrunner-duktape/meson.build @@ -16,6 +16,7 @@ plugin_lib = shared_module( plugin_name, plugin_src, include_directories: px_backend_inc, + c_args: px_backend_c_args, dependencies: [px_backend_dep, duktape_dep, ws2_32_dep], install_dir: join_paths(px_plugins_dir, plugin_name), install: true, diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c index 4425d8e..5196740 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -1,6 +1,6 @@ /* pacrunner-duktape.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h index 90fc119..8721a62 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h @@ -1,6 +1,6 @@ /* pacrunner-duktape.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin index 26dd8b2..efb10f0 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin @@ -1,6 +1,3 @@ [Plugin] -Authors=Jan-Michael Brummer -Copyright=Copyright © 2023 Jan-Michael Brummer -Description=Parse PAC files with duktape Module=pacrunner-duktape Name=Duktape \ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index be6b5f5..ece6983 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -1,6 +1,6 @@ /* px-manager.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h index 17dcb1c..ca3c2fe 100644 --- a/src/backend/px-manager.h +++ b/src/backend/px-manager.h @@ -1,6 +1,6 @@ /* px-manager.h * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-plugin-config.c b/src/backend/px-plugin-config.c index d9ee9c6..6f8c803 100644 --- a/src/backend/px-plugin-config.c +++ b/src/backend/px-plugin-config.c @@ -1,6 +1,6 @@ /* px-plugin-config.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-plugin-config.h b/src/backend/px-plugin-config.h index 93cdc5b..aac62a0 100644 --- a/src/backend/px-plugin-config.h +++ b/src/backend/px-plugin-config.h @@ -1,6 +1,6 @@ /* px-plugin-config.h * - * Copyright 2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-plugin-download.c b/src/backend/px-plugin-download.c index bc7d6d2..c552217 100644 --- a/src/backend/px-plugin-download.c +++ b/src/backend/px-plugin-download.c @@ -1,6 +1,6 @@ /* px-plugin-download.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-plugin-download.h b/src/backend/px-plugin-download.h index e618de7..f37c565 100644 --- a/src/backend/px-plugin-download.h +++ b/src/backend/px-plugin-download.h @@ -1,6 +1,6 @@ /* px-plugin-download.h * - * Copyright 2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-plugin-pacrunner.c b/src/backend/px-plugin-pacrunner.c index d529c14..bf5dc6a 100644 --- a/src/backend/px-plugin-pacrunner.c +++ b/src/backend/px-plugin-pacrunner.c @@ -1,6 +1,6 @@ /* px-plugin-pacrunner.c * - * Copyright 2022-2023 Jan-Michael Brummer + * 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 diff --git a/src/backend/px-plugin-pacrunner.h b/src/backend/px-plugin-pacrunner.h index 0226dc0..f7251ce 100644 --- a/src/backend/px-plugin-pacrunner.h +++ b/src/backend/px-plugin-pacrunner.h @@ -1,6 +1,6 @@ /* px-plugin-pacrunner.h * - * Copyright 2023 Jan-Michael Brummer + * 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 diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 3669280..8646ed5 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -1,7 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* proxy-dbus.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 @@ -15,8 +14,10 @@ * * 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 diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c index e4f4d01..eeb2308 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -1,7 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* 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 @@ -15,8 +14,10 @@ * * 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 diff --git a/src/libproxy/proxy.h b/src/libproxy/proxy.h index a5a4eae..be35d3c 100644 --- a/src/libproxy/proxy.h +++ b/src/libproxy/proxy.h @@ -1,7 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2006 Nathaniel McCallum - * Copyright (C) 2022 Jan-Michael Brummer +/* 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 @@ -15,8 +14,11 @@ * * 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 diff --git a/src/tests/px-manager-helper.c b/src/tests/px-manager-helper.c index 2e12371..725a312 100644 --- a/src/tests/px-manager-helper.c +++ b/src/tests/px-manager-helper.c @@ -1,3 +1,24 @@ +/* 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" diff --git a/src/tests/px-manager-helper.h b/src/tests/px-manager-helper.h index fb486df..ad5d662 100644 --- a/src/tests/px-manager-helper.h +++ b/src/tests/px-manager-helper.h @@ -1,3 +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); diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c index b62c408..8e3865f 100644 --- a/src/tests/px-manager-test.c +++ b/src/tests/px-manager-test.c @@ -1,6 +1,6 @@ -/******************************************************************************* - * libproxy - A library for proxy configuration - * Copyright (C) 2022-2023 Jan-Michael Brummer +/* 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 @@ -14,8 +14,10 @@ * * 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 "px-manager.h" #include "px-manager-helper.h" diff --git a/src/tools/proxy.c b/src/tools/proxy.c index 80b0983..2d46578 100644 --- a/src/tools/proxy.c +++ b/src/tools/proxy.c @@ -1,3 +1,24 @@ +/* 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 #include #include -- cgit v1.2.1 From 6b59dd19f667135482de2a70f8a219c35af0eaa7 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 7 Feb 2023 10:56:37 +0100 Subject: Add D-Bus service files (#38) --- .github/workflows/build.yml | 4 ++-- meson.build | 2 ++ meson_options.txt | 4 ++-- src/backend/dbus/meson.build | 20 +++++++++++++++++++- src/backend/dbus/org.libproxy.proxy.conf | 21 +++++++++++++++++++++ src/backend/dbus/org.libproxy.proxy.service.in | 3 +++ src/backend/dbus/proxyd.service.in | 6 +----- src/backend/meson.build | 4 ++++ src/libproxy/meson.build | 2 +- 9 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 src/backend/dbus/org.libproxy.proxy.conf create mode 100644 src/backend/dbus/org.libproxy.proxy.service.in diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5dd6034..13eaddd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: gsettings-desktop-schemas-dev \ libcurl4-openssl-dev - name: Build setup - run: meson setup build -Db_coverage=true + run: meson setup build -Db_coverage=true -Ddbus=disabled - name: Build run: ninja -C build - name: Tests and Coverage @@ -76,7 +76,7 @@ jobs: gsettings-desktop-schemas-dev \ libcurl4-openssl-dev - name: Build setup - run: meson setup build -Db_coverage=true -Ddbus=true + run: meson setup build -Db_coverage=true -Ddbus=enabled - name: Build run: ninja -C build - name: Tests diff --git a/meson.build b/meson.build index 12cf963..a7be8a7 100644 --- a/meson.build +++ b/meson.build @@ -114,6 +114,8 @@ curl_dep = dependency('libcurl', required: get_option('download-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')) +build_dbus = get_option('dbus').disable_auto_if(['window', 'darwin'].contains(host_system)).allowed() + subdir('src') subdir('docs') diff --git a/meson_options.txt b/meson_options.txt index a82890c..89d05e1 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -14,8 +14,8 @@ option( option( 'dbus', - type: 'boolean', - value: false, + type: 'feature', + value: 'auto', description: 'Whether to build dbus service' ) diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build index 866d0b8..eb64fcd 100644 --- a/src/backend/dbus/meson.build +++ b/src/backend/dbus/meson.build @@ -1,7 +1,12 @@ -if get_option('dbus') +if build_dbus gdbus_codegen = find_program('gdbus-codegen') unitdir = '' + dbus_data_dir = join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1') + dbus_interfaces_dir = join_paths(dbus_data_dir, 'interfaces') + dbus_services_dir = join_paths(dbus_data_dir, 'services') + dbus_sysconf_dir = join_paths(dbus_data_dir, 'session.d') + systemd = dependency('systemd', required: false) if systemd.found() unitdir = systemd.get_variable(pkgconfig: 'systemduserunitdir') @@ -57,6 +62,19 @@ if get_option('dbus') service_data = configuration_data() service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + dbus_service = configure_file( + input: 'org.libproxy.proxy.service.in', + output: 'org.libproxy.proxy.service', + configuration: service_data + ) + + install_data('org.libproxy.proxy.conf', install_dir : dbus_sysconf_dir) + install_data(dbus_service, install_dir : dbus_services_dir) + install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) + + service_data = configuration_data() + service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + service = configure_file( input: 'proxyd.service.in', output: 'proxyd.service', diff --git a/src/backend/dbus/org.libproxy.proxy.conf b/src/backend/dbus/org.libproxy.proxy.conf new file mode 100644 index 0000000..f9232a1 --- /dev/null +++ b/src/backend/dbus/org.libproxy.proxy.conf @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/backend/dbus/org.libproxy.proxy.service.in b/src/backend/dbus/org.libproxy.proxy.service.in new file mode 100644 index 0000000..e958cd2 --- /dev/null +++ b/src/backend/dbus/org.libproxy.proxy.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.libproxy.proxy +Exec=@LIBEXECDIR@/proxyd \ No newline at end of file diff --git a/src/backend/dbus/proxyd.service.in b/src/backend/dbus/proxyd.service.in index 2e2a7cc..038e86d 100644 --- a/src/backend/dbus/proxyd.service.in +++ b/src/backend/dbus/proxyd.service.in @@ -6,13 +6,9 @@ Type=dbus BusName=org.libproxy.proxy ExecStart=@LIBEXECDIR@/proxyd #Environment="G_MESSAGES_DEBUG=all" -Restart=on-failure MemoryDenyWriteExecute=yes PrivateTmp=yes ProtectHome=yes ProtectSystem=full -RestrictRealtime=yes - -[Install] -WantedBy=default.target \ No newline at end of file +RestrictRealtime=yes \ No newline at end of file diff --git a/src/backend/meson.build b/src/backend/meson.build index 24f3d88..bdca0f1 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -51,3 +51,7 @@ px_backend_dep = declare_dependency( subdir('dbus') subdir('plugins') + +summary({ + 'D-Bus Service' : build_dbus, +}, section: 'Architecture') \ No newline at end of file diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index 3ee67b6..0368e77 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -4,7 +4,7 @@ libproxy_inc = include_directories('.') libproxy_sources = [] -if get_option('dbus') +if build_dbus libproxy_sources += [ 'proxy-dbus.c', ] -- cgit v1.2.1 From bd9d58b9bdc7fc7ca9a7caa4b590d6c9f0b6fc06 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 7 Feb 2023 12:15:00 +0100 Subject: Rework pre-commit hook installation (#52) Ensure that it runs on all supported systems. --- data/install-git-hook.sh | 9 ++++----- meson.build | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/data/install-git-hook.sh b/data/install-git-hook.sh index 7fd5550..355867b 100644 --- a/data/install-git-hook.sh +++ b/data/install-git-hook.sh @@ -2,11 +2,10 @@ cd "$MESON_SOURCE_ROOT" -[ -d .git ] || exit 0 # not a git repo -[ ! -f .git/hooks/pre-commit ] || exit 0 # already installed +[ -d .git ] || exit 2 # not a git repo +[ ! -f .git/hooks/pre-commit ] || exit 2 # already installed -echo "Copying pre commit hook" cp data/pre-commit-hook .git/hooks/pre-commit -echo "Copying helper" cp data/canonicalize_filename.sh .git/hooks/canonicalize_filename.sh -echo "Done" \ No newline at end of file +chmod +x .git/hooks/pre-commit +echo "Activated pre-commit hook" \ No newline at end of file diff --git a/meson.build b/meson.build index a7be8a7..4a17bfe 100644 --- a/meson.build +++ b/meson.build @@ -127,5 +127,7 @@ summary({ }, section: 'Build environment') # Install pre-commit hook -git_hook_installer = find_program('data/install-git-hook.sh') -run_command(git_hook_installer) \ No newline at end of file +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 \ No newline at end of file -- cgit v1.2.1 From d7974aa73fe21a3f79ce715ca038e13c06d4bd58 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 9 Feb 2023 15:12:52 +0100 Subject: Improve debug output (#53) --- src/backend/dbus/dbus.c | 4 ---- src/backend/px-manager.c | 7 +++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 031f905..2495257 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -61,13 +61,9 @@ handle_method_call (GDBusConnection *connection, result = g_variant_builder_new (G_VARIANT_TYPE ("as")); if (proxies) { - g_debug ("%s: Proxies:", __FUNCTION__); for (idx = 0; proxies[idx]; idx++) { - g_debug ("%s: \t- Proxy[%d] = %s", __FUNCTION__, idx, proxies[idx]); g_variant_builder_add (result, "s", proxies[idx]); } - } else { - g_debug ("%s: No Proxy required", __FUNCTION__); } g_dbus_method_invocation_return_value (invocation, diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ece6983..6c63e93 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -140,6 +140,7 @@ px_manager_constructed (GObject *object) self->network_monitor = g_network_monitor_get_default (); self->online = g_network_monitor_get_network_available (self->network_monitor); g_signal_connect_object (G_OBJECT (self->network_monitor), "network-changed", G_CALLBACK (px_manager_on_network_changed), self, 0); + g_debug ("%s: Up and running", __FUNCTION__); } static void @@ -502,11 +503,10 @@ px_manager_get_proxies_sync (PxManager *self, config = px_manager_get_configuration (self, uri, error); - g_debug ("%s: Config is:", __FUNCTION__); 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:\t- Config[%d] = %s\n", __FUNCTION__, idx, config[idx]); + 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)) { struct PacData pac_data = { @@ -524,5 +524,8 @@ px_manager_get_proxies_sync (PxManager *self, if (((GPtrArray *)builder)->len == 0) g_strv_builder_add (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); } -- cgit v1.2.1 From 50464aa1d159e1804dbbb3891f206f8b84713c5f Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 9 Feb 2023 16:18:55 +0100 Subject: Make use of curl only (#54) Simplify libproxy and allow only one download lib: curl. --- meson.build | 4 +- meson_options.txt | 14 --- src/backend/meson.build | 3 +- src/backend/plugins/download-curl/download-curl.c | 116 --------------------- src/backend/plugins/download-curl/download-curl.h | 34 ------ .../plugins/download-curl/download-curl.plugin | 3 - src/backend/plugins/download-curl/meson.build | 34 ------ src/backend/plugins/download-soup/download-soup.c | 89 ---------------- src/backend/plugins/download-soup/download-soup.h | 34 ------ .../plugins/download-soup/download-soup.plugin | 3 - src/backend/plugins/download-soup/meson.build | 34 ------ src/backend/plugins/meson.build | 5 - src/backend/px-manager.c | 66 +++++++----- src/backend/px-plugin-download.c | 30 ------ src/backend/px-plugin-download.h | 39 ------- 15 files changed, 44 insertions(+), 464 deletions(-) delete mode 100644 src/backend/plugins/download-curl/download-curl.c delete mode 100644 src/backend/plugins/download-curl/download-curl.h delete mode 100644 src/backend/plugins/download-curl/download-curl.plugin delete mode 100644 src/backend/plugins/download-curl/meson.build delete mode 100644 src/backend/plugins/download-soup/download-soup.c delete mode 100644 src/backend/plugins/download-soup/download-soup.h delete mode 100644 src/backend/plugins/download-soup/download-soup.plugin delete mode 100644 src/backend/plugins/download-soup/meson.build delete mode 100644 src/backend/px-plugin-download.c delete mode 100644 src/backend/px-plugin-download.h diff --git a/meson.build b/meson.build index 4a17bfe..52510a8 100644 --- a/meson.build +++ b/meson.build @@ -109,8 +109,8 @@ endif glib_dep = dependency('glib-2.0', version: '>= 2.71.3') gio_dep = dependency('gio-2.0', version: '>= 2.71.3') peas_dep = dependency('libpeas-1.0') -soup_dep = dependency('libsoup-3.0', required: get_option('download-soup')) -curl_dep = dependency('libcurl', required: get_option('download-curl')) +soup_dep = dependency('libsoup-3.0', required: get_option('tests')) +curl_dep = dependency('libcurl') ws2_32_dep = cc.find_library('ws2_32', required : with_platform_windows) gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get_option('config-gnome')) diff --git a/meson_options.txt b/meson_options.txt index 89d05e1..8e703d7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -66,18 +66,4 @@ option( type: 'boolean', value: true, description: 'Whether to build plugin for PAC Runner Duktape' -) - -option( - 'download-soup', - type: 'boolean', - value: true, - description: 'Whether to build plugin for downloading with SOUP' -) - -option( - 'download-curl', - type: 'boolean', - value: true, - description: 'Whether to build plugin for downloading with cURL' ) \ No newline at end of file diff --git a/src/backend/meson.build b/src/backend/meson.build index bdca0f1..4a9a1ab 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -7,11 +7,10 @@ px_backend_sources = [ 'px-plugin-config.h', 'px-plugin-pacrunner.c', 'px-plugin-pacrunner.h', - 'px-plugin-download.c', - 'px-plugin-download.h', ] px_backend_deps = [ + curl_dep, gio_dep, glib_dep, peas_dep, diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c deleted file mode 100644 index d26d62b..0000000 --- a/src/backend/plugins/download-curl/download-curl.c +++ /dev/null @@ -1,116 +0,0 @@ -/* download-curl.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 -#include - -#include "download-curl.h" - -#include "px-plugin-download.h" -#include "px-manager.h" - -static void px_download_iface_init (PxDownloadInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); - -struct _PxDownloadCurl { - GObject parent_instance; - CURL *curl; -}; - -G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadCurl, - px_download_curl, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (PX_TYPE_DOWNLOAD, px_download_iface_init)) - -static void -px_download_curl_init (PxDownloadCurl *self) -{ -} - -static void -px_download_curl_class_init (PxDownloadCurlClass *klass) -{ -} - -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; -} - -static GBytes * -px_download_curl_download (PxDownload *download, - const char *uri) -{ - PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); - 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); -} - -static void -px_download_iface_init (PxDownloadInterface *iface) -{ - iface->download = px_download_curl_download; -} - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_DOWNLOAD, - PX_DOWNLOAD_TYPE_CURL); -} diff --git a/src/backend/plugins/download-curl/download-curl.h b/src/backend/plugins/download-curl/download-curl.h deleted file mode 100644 index 545222c..0000000 --- a/src/backend/plugins/download-curl/download-curl.h +++ /dev/null @@ -1,34 +0,0 @@ -/* download-curl.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 - -G_BEGIN_DECLS - -#define PX_DOWNLOAD_TYPE_CURL (px_download_curl_get_type ()) - -G_DECLARE_FINAL_TYPE (PxDownloadCurl, px_download_curl, PX, DOWNLOAD_CURL, GObject) - -G_END_DECLS - - diff --git a/src/backend/plugins/download-curl/download-curl.plugin b/src/backend/plugins/download-curl/download-curl.plugin deleted file mode 100644 index 1b10a83..0000000 --- a/src/backend/plugins/download-curl/download-curl.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=download-curl -Name=cURL \ No newline at end of file diff --git a/src/backend/plugins/download-curl/meson.build b/src/backend/plugins/download-curl/meson.build deleted file mode 100644 index a1d8736..0000000 --- a/src/backend/plugins/download-curl/meson.build +++ /dev/null @@ -1,34 +0,0 @@ -plugin_name = 'download-curl' - -if get_option(plugin_name) - -plugin_src = [ - '@0@.c'.format(plugin_name), -] - -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - sources: plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep, curl_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - -endif \ No newline at end of file diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c deleted file mode 100644 index 4b4aa42..0000000 --- a/src/backend/plugins/download-soup/download-soup.c +++ /dev/null @@ -1,89 +0,0 @@ -/* download-soup.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 -#include - -#include "download-soup.h" - -#include "px-plugin-download.h" -#include "px-manager.h" - -static void px_download_iface_init (PxDownloadInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); - -struct _PxDownloadSoup { - GObject parent_instance; - - SoupSession *session; -}; - -G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadSoup, - px_download_soup, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (PX_TYPE_DOWNLOAD, px_download_iface_init)) - -static void -px_download_soup_init (PxDownloadSoup *self) -{ - self->session = soup_session_new (); -} - -static void -px_download_soup_class_init (PxDownloadSoupClass *klass) -{ -} - -static GBytes * -px_download_soup_download (PxDownload *download, - const char *uri) -{ - PxDownloadSoup *self = PX_DOWNLOAD_SOUP (download); - g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); - g_autoptr (GError) error = NULL; - g_autoptr (GBytes) bytes = NULL; - - bytes = soup_session_send_and_read ( - self->session, - msg, - NULL, /* Pass a GCancellable here if you want to cancel a download */ - &error); - if (!bytes || soup_message_get_status (msg) != SOUP_STATUS_OK) { - g_debug ("%s: Failed to download: %s", __FUNCTION__, error ? error->message : ""); - return NULL; - } - - return g_steal_pointer (&bytes); -} - -static void -px_download_iface_init (PxDownloadInterface *iface) -{ - iface->download = px_download_soup_download; -} - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_DOWNLOAD, - PX_DOWNLOAD_TYPE_SOUP); -} diff --git a/src/backend/plugins/download-soup/download-soup.h b/src/backend/plugins/download-soup/download-soup.h deleted file mode 100644 index fa95c46..0000000 --- a/src/backend/plugins/download-soup/download-soup.h +++ /dev/null @@ -1,34 +0,0 @@ -/* download-soup.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 - -G_BEGIN_DECLS - -#define PX_DOWNLOAD_TYPE_SOUP (px_download_soup_get_type ()) - -G_DECLARE_FINAL_TYPE (PxDownloadSoup, px_download_soup, PX, DOWNLOAD_SOUP, GObject) - -G_END_DECLS - - diff --git a/src/backend/plugins/download-soup/download-soup.plugin b/src/backend/plugins/download-soup/download-soup.plugin deleted file mode 100644 index 294b957..0000000 --- a/src/backend/plugins/download-soup/download-soup.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=download-soup -Name=SOUP \ No newline at end of file diff --git a/src/backend/plugins/download-soup/meson.build b/src/backend/plugins/download-soup/meson.build deleted file mode 100644 index db61aba..0000000 --- a/src/backend/plugins/download-soup/meson.build +++ /dev/null @@ -1,34 +0,0 @@ -plugin_name = 'download-soup' - -if get_option(plugin_name) - -plugin_src = [ - '@0@.c'.format(plugin_name), -] - -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - sources: plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep, soup_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - -endif \ No newline at end of file diff --git a/src/backend/plugins/meson.build b/src/backend/plugins/meson.build index 09344f0..c7943d2 100644 --- a/src/backend/plugins/meson.build +++ b/src/backend/plugins/meson.build @@ -5,9 +5,6 @@ subdir('config-osx') subdir('config-sysconfig') subdir('config-windows') -subdir('download-curl') -subdir('download-soup') - subdir('pacrunner-duktape') summary({ @@ -17,7 +14,5 @@ summary({ 'Configuration Windows ' : get_option('config-windows'), 'Configuration sysconfig ' : get_option('config-sysconfig'), 'Configuration OS X ' : get_option('config-osx'), - 'Download cURL ' : get_option('download-curl'), - 'Download Soup ' : get_option('download-soup'), 'PAC Runner Duktape ' : get_option('pacrunner-duktape'), }, section: 'Plugins') \ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 6c63e93..223cf88 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -24,8 +24,8 @@ #include "px-manager.h" #include "px-plugin-config.h" #include "px-plugin-pacrunner.h" -#include "px-plugin-download.h" +#include #include enum { @@ -49,8 +49,8 @@ struct _PxManager { PeasEngine *engine; PeasExtensionSet *config_set; PeasExtensionSet *pacrunner_set; - PeasExtensionSet *download_set; GNetworkMonitor *network_monitor; + CURL *curl; char *plugins_dir; GCancellable *cancellable; @@ -108,7 +108,6 @@ px_manager_constructed (GObject *object) self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, NULL); self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); - self->download_set = peas_extension_set_new (self->engine, PX_TYPE_DOWNLOAD, NULL); list = peas_engine_get_plugin_list (self->engine); for (; list && list->data; list = list->next) { @@ -249,24 +248,18 @@ px_manager_new (void) return g_object_new (PX_TYPE_MANAGER, "plugins-dir", PX_PLUGINS_DIR, NULL); } -struct DownloadData { - const char *uri; - GBytes *bytes; - GError **error; -}; - -static void -download_pac (PeasExtensionSet *set, - PeasPluginInfo *info, - PeasExtension *extension, - gpointer data) +static size_t +store_data (void *contents, + size_t size, + size_t nmemb, + void *user_pointer) { - PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension); - struct DownloadData *download_data = data; + GByteArray *byte_array = user_pointer; + size_t real_size = size * nmemb; + + g_byte_array_append (byte_array, contents, real_size); - g_debug ("%s: Download PAC '%s' using plugin '%s'", __FUNCTION__, download_data->uri, peas_plugin_info_get_module_name (info)); - if (!download_data->bytes) - download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri); + return real_size; } /** @@ -282,13 +275,36 @@ GBytes * px_manager_pac_download (PxManager *self, const char *uri) { - struct DownloadData download_data = { - .uri = uri, - .bytes = NULL, - }; + 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; + } - peas_extension_set_foreach (self->download_set, download_pac, &download_data); - return download_data.bytes; + return g_byte_array_free_to_bytes (byte_array); } struct ConfigData { diff --git a/src/backend/px-plugin-download.c b/src/backend/px-plugin-download.c deleted file mode 100644 index c552217..0000000 --- a/src/backend/px-plugin-download.c +++ /dev/null @@ -1,30 +0,0 @@ -/* px-plugin-download.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-download.h" - -G_DEFINE_INTERFACE (PxDownload, px_download, G_TYPE_OBJECT) - -static void -px_download_default_init (PxDownloadInterface *iface) -{ -} diff --git a/src/backend/px-plugin-download.h b/src/backend/px-plugin-download.h deleted file mode 100644 index f37c565..0000000 --- a/src/backend/px-plugin-download.h +++ /dev/null @@ -1,39 +0,0 @@ -/* px-plugin-download.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 - -G_BEGIN_DECLS - -#define PX_TYPE_DOWNLOAD (px_download_get_type ()) - -G_DECLARE_INTERFACE (PxDownload, px_download, PX, DOWNLOAD, GObject) - -struct _PxDownloadInterface -{ - GTypeInterface parent_iface; - - GBytes *(*download)(PxDownload *download, const char *uri); -}; - -G_END_DECLS -- cgit v1.2.1 From f0dd1f6265dbc6c7bfc53227b419b4b9c04d2ac0 Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Thu, 9 Feb 2023 14:11:24 -0600 Subject: Fix typo (#56) --- docs/build-howto.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build-howto.md b/docs/build-howto.md index 53577d9..7ce0ef5 100644 --- a/docs/build-howto.md +++ b/docs/build-howto.md @@ -3,7 +3,7 @@ Slug: building # Compiling with Libproxy -The current stable API provides a small synchronnous function set which makes it easy to add it to existing application and libraries. +The current stable API provides a small synchronous function set which makes it easy to add it to existing application and libraries. The following example is written in C but can be translated as well to every other programming language thanks to gobject-introspection. Furthermore there are several language samples provided in 'docs/samples' and also linked here in this main documentation. -- cgit v1.2.1 From 597408052666438d5a0c8f70f5c5eb37eb6f8694 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 3 Mar 2023 17:40:12 +0100 Subject: Move tests a level higher (#58) --- meson.build | 1 + src/meson.build | 1 - src/tests/config-env-test.c | 106 -------------- src/tests/config-gnome-test.c | 196 ------------------------- src/tests/config-kde-test.c | 237 ------------------------------- src/tests/config-sysconfig-test.c | 87 ------------ src/tests/data/px-manager-direct | 1 - src/tests/data/px-manager-nonpac | 5 - src/tests/data/px-manager-pac | 5 - src/tests/data/px-manager-sample.pac | 6 - src/tests/data/px-manager-wpad | 5 - src/tests/data/sample-kde-proxy-disabled | 11 -- src/tests/data/sample-kde-proxy-manual | 11 -- src/tests/data/sample-kde-proxy-pac | 11 -- src/tests/data/sample-kde-proxy-wpad | 11 -- src/tests/data/sample-sysconfig-proxy | 6 - src/tests/meson.build | 69 --------- src/tests/px-manager-helper.c | 34 ----- src/tests/px-manager-helper.h | 24 ---- src/tests/px-manager-test.c | 213 --------------------------- tests/config-env-test.c | 106 ++++++++++++++ tests/config-gnome-test.c | 196 +++++++++++++++++++++++++ tests/config-kde-test.c | 237 +++++++++++++++++++++++++++++++ tests/config-sysconfig-test.c | 87 ++++++++++++ tests/data/px-manager-direct | 1 + tests/data/px-manager-nonpac | 5 + tests/data/px-manager-pac | 5 + tests/data/px-manager-sample.pac | 6 + tests/data/px-manager-wpad | 5 + tests/data/sample-kde-proxy-disabled | 11 ++ tests/data/sample-kde-proxy-manual | 11 ++ tests/data/sample-kde-proxy-pac | 11 ++ tests/data/sample-kde-proxy-wpad | 11 ++ tests/data/sample-sysconfig-proxy | 6 + tests/meson.build | 69 +++++++++ tests/px-manager-helper.c | 34 +++++ tests/px-manager-helper.h | 24 ++++ tests/px-manager-test.c | 213 +++++++++++++++++++++++++++ 38 files changed, 1039 insertions(+), 1039 deletions(-) delete mode 100644 src/tests/config-env-test.c delete mode 100644 src/tests/config-gnome-test.c delete mode 100644 src/tests/config-kde-test.c delete mode 100644 src/tests/config-sysconfig-test.c delete mode 100644 src/tests/data/px-manager-direct delete mode 100644 src/tests/data/px-manager-nonpac delete mode 100644 src/tests/data/px-manager-pac delete mode 100644 src/tests/data/px-manager-sample.pac delete mode 100644 src/tests/data/px-manager-wpad delete mode 100644 src/tests/data/sample-kde-proxy-disabled delete mode 100644 src/tests/data/sample-kde-proxy-manual delete mode 100644 src/tests/data/sample-kde-proxy-pac delete mode 100644 src/tests/data/sample-kde-proxy-wpad delete mode 100644 src/tests/data/sample-sysconfig-proxy delete mode 100644 src/tests/meson.build delete mode 100644 src/tests/px-manager-helper.c delete mode 100644 src/tests/px-manager-helper.h delete mode 100644 src/tests/px-manager-test.c create mode 100644 tests/config-env-test.c create mode 100644 tests/config-gnome-test.c create mode 100644 tests/config-kde-test.c create mode 100644 tests/config-sysconfig-test.c create mode 100644 tests/data/px-manager-direct create mode 100644 tests/data/px-manager-nonpac create mode 100644 tests/data/px-manager-pac create mode 100644 tests/data/px-manager-sample.pac create mode 100644 tests/data/px-manager-wpad create mode 100644 tests/data/sample-kde-proxy-disabled create mode 100644 tests/data/sample-kde-proxy-manual create mode 100644 tests/data/sample-kde-proxy-pac create mode 100644 tests/data/sample-kde-proxy-wpad create mode 100644 tests/data/sample-sysconfig-proxy create mode 100644 tests/meson.build create mode 100644 tests/px-manager-helper.c create mode 100644 tests/px-manager-helper.h create mode 100644 tests/px-manager-test.c diff --git a/meson.build b/meson.build index 52510a8..925acbd 100644 --- a/meson.build +++ b/meson.build @@ -117,6 +117,7 @@ gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get build_dbus = get_option('dbus').disable_auto_if(['window', 'darwin'].contains(host_system)).allowed() subdir('src') +subdir('tests') subdir('docs') summary({ diff --git a/src/meson.build b/src/meson.build index fc61997..6aaf2f6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,4 +1,3 @@ subdir('backend') subdir('libproxy') -subdir('tests') subdir('tools') diff --git a/src/tests/config-env-test.c b/src/tests/config-env-test.c deleted file mode 100644 index 34d3218..0000000 --- a/src/tests/config-env-test.c +++ /dev/null @@ -1,106 +0,0 @@ -/* 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" - -#include - -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"); - 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/src/tests/config-gnome-test.c b/src/tests/config-gnome-test.c deleted file mode 100644 index 7d8223d..0000000 --- a/src/tests/config-gnome-test.c +++ /dev/null @@ -1,196 +0,0 @@ -/* 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 -#include - -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_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"); - 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"); - 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"); - 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 */ - g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE); - - manager = px_test_manager_new ("config-gnome"); - 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_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/src/tests/config-kde-test.c b/src/tests/config-kde-test.c deleted file mode 100644 index 9aba2d5..0000000 --- a/src/tests/config-kde-test.c +++ /dev/null @@ -1,237 +0,0 @@ -/* 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" - -#include - -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); - - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); - 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); - - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); - 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); - - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); - 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); - - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); - 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); - - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - } - - /* Disable KDE support */ - g_unsetenv ("KDE_FULL_SESSION"); - - manager = px_test_manager_new ("config-kde"); - - 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_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/src/tests/config-sysconfig-test.c b/src/tests/config-sysconfig-test.c deleted file mode 100644 index 4cc0989..0000000 --- a/src/tests/config-sysconfig-test.c +++ /dev/null @@ -1,87 +0,0 @@ -/* 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" - -#include - -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); - - if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { - g_warning ("Failed to set sysconfig environment"); - continue; - } - - manager = px_test_manager_new ("config-sysconfig"); - 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/src/tests/data/px-manager-direct b/src/tests/data/px-manager-direct deleted file mode 100644 index 72c4ac8..0000000 --- a/src/tests/data/px-manager-direct +++ /dev/null @@ -1 +0,0 @@ -PROXY_ENABLED="no" \ No newline at end of file diff --git a/src/tests/data/px-manager-nonpac b/src/tests/data/px-manager-nonpac deleted file mode 100644 index 7db21d8..0000000 --- a/src/tests/data/px-manager-nonpac +++ /dev/null @@ -1,5 +0,0 @@ -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/src/tests/data/px-manager-pac b/src/tests/data/px-manager-pac deleted file mode 100644 index 2ff4000..0000000 --- a/src/tests/data/px-manager-pac +++ /dev/null @@ -1,5 +0,0 @@ -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/src/tests/data/px-manager-sample.pac b/src/tests/data/px-manager-sample.pac deleted file mode 100644 index b86c555..0000000 --- a/src/tests/data/px-manager-sample.pac +++ /dev/null @@ -1,6 +0,0 @@ -function FindProxyForURL(url, host) -{ - var myIP = myIpAddress(); - - return "PROXY 127.0.0.1:1983" -} diff --git a/src/tests/data/px-manager-wpad b/src/tests/data/px-manager-wpad deleted file mode 100644 index 4ab0f81..0000000 --- a/src/tests/data/px-manager-wpad +++ /dev/null @@ -1,5 +0,0 @@ -PROXY_ENABLED="yes" -HTTP_PROXY="wpad://" -HTTPS_PROXY="wpad://" -FTP_PROXY="wpad://" -NO_PROXY="localhost, 127.0.0.1" diff --git a/src/tests/data/sample-kde-proxy-disabled b/src/tests/data/sample-kde-proxy-disabled deleted file mode 100644 index 9598abd..0000000 --- a/src/tests/data/sample-kde-proxy-disabled +++ /dev/null @@ -1,11 +0,0 @@ -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/src/tests/data/sample-kde-proxy-manual b/src/tests/data/sample-kde-proxy-manual deleted file mode 100644 index c0a293b..0000000 --- a/src/tests/data/sample-kde-proxy-manual +++ /dev/null @@ -1,11 +0,0 @@ -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/src/tests/data/sample-kde-proxy-pac b/src/tests/data/sample-kde-proxy-pac deleted file mode 100644 index c0db824..0000000 --- a/src/tests/data/sample-kde-proxy-pac +++ /dev/null @@ -1,11 +0,0 @@ -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/src/tests/data/sample-kde-proxy-wpad b/src/tests/data/sample-kde-proxy-wpad deleted file mode 100644 index 6eb1547..0000000 --- a/src/tests/data/sample-kde-proxy-wpad +++ /dev/null @@ -1,11 +0,0 @@ -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/src/tests/data/sample-sysconfig-proxy b/src/tests/data/sample-sysconfig-proxy deleted file mode 100644 index 1318f21..0000000 --- a/src/tests/data/sample-sysconfig-proxy +++ /dev/null @@ -1,6 +0,0 @@ -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/src/tests/meson.build b/src/tests/meson.build deleted file mode 100644 index 23a7e91..0000000 --- a/src/tests/meson.build +++ /dev/null @@ -1,69 +0,0 @@ -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'] - - 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, 'KDE_FULL_SESSION=1'], - ) - endif -endif diff --git a/src/tests/px-manager-helper.c b/src/tests/px-manager-helper.c deleted file mode 100644 index 725a312..0000000 --- a/src/tests/px-manager-helper.c +++ /dev/null @@ -1,34 +0,0 @@ -/* 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) -{ - g_autofree char *path = g_strdup_printf ("%s/../backend/plugins", g_getenv ("G_TEST_BUILDDIR")); - - return g_object_new (PX_TYPE_MANAGER, - "plugins-dir", path, - "config-plugin", config_plugin, - NULL); -} diff --git a/src/tests/px-manager-helper.h b/src/tests/px-manager-helper.h deleted file mode 100644 index ad5d662..0000000 --- a/src/tests/px-manager-helper.h +++ /dev/null @@ -1,24 +0,0 @@ -/* 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); diff --git a/src/tests/px-manager-test.c b/src/tests/px-manager-test.c deleted file mode 100644 index 8e3865f..0000000 --- a/src/tests/px-manager-test.c +++ /dev/null @@ -1,213 +0,0 @@ -/* 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 - -#include - -#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) -{ - fixture->loop = g_main_loop_new (NULL, FALSE); - - if (data) { - g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); - if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { - g_warning ("Failed to set environment"); - return; - } - } - - fixture->manager = px_test_manager_new ("config-sysconfig"); -} - -static void -fixture_teardown (Fixture *fixture, - gconstpointer data) -{ - g_unsetenv ("PX_CONFIG_SYSCONFIG"); - 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"); - - 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); -} - -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); - - return g_test_run (); -} diff --git a/tests/config-env-test.c b/tests/config-env-test.c new file mode 100644 index 0000000..34d3218 --- /dev/null +++ b/tests/config-env-test.c @@ -0,0 +1,106 @@ +/* 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" + +#include + +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"); + 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..7d8223d --- /dev/null +++ b/tests/config-gnome-test.c @@ -0,0 +1,196 @@ +/* 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 +#include + +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_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"); + 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"); + 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"); + 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 */ + g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE); + + manager = px_test_manager_new ("config-gnome"); + 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_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..9aba2d5 --- /dev/null +++ b/tests/config-kde-test.c @@ -0,0 +1,237 @@ +/* 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" + +#include + +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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + continue; + } + + manager = px_test_manager_new ("config-kde"); + 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); + + if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { + g_warning ("Failed to set kde environment"); + } + + /* Disable KDE support */ + g_unsetenv ("KDE_FULL_SESSION"); + + manager = px_test_manager_new ("config-kde"); + + 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_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-sysconfig-test.c b/tests/config-sysconfig-test.c new file mode 100644 index 0000000..4cc0989 --- /dev/null +++ b/tests/config-sysconfig-test.c @@ -0,0 +1,87 @@ +/* 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" + +#include + +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); + + if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { + g_warning ("Failed to set sysconfig environment"); + continue; + } + + manager = px_test_manager_new ("config-sysconfig"); + 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/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..b86c555 --- /dev/null +++ b/tests/data/px-manager-sample.pac @@ -0,0 +1,6 @@ +function FindProxyForURL(url, host) +{ + var myIP = myIpAddress(); + + return "PROXY 127.0.0.1:1983" +} 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/meson.build b/tests/meson.build new file mode 100644 index 0000000..23a7e91 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,69 @@ +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'] + + 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, 'KDE_FULL_SESSION=1'], + ) + endif +endif diff --git a/tests/px-manager-helper.c b/tests/px-manager-helper.c new file mode 100644 index 0000000..223ad62 --- /dev/null +++ b/tests/px-manager-helper.c @@ -0,0 +1,34 @@ +/* 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) +{ + g_autofree char *path = g_test_build_filename (G_TEST_BUILT, "../src/backend/plugins", NULL); + + return g_object_new (PX_TYPE_MANAGER, + "plugins-dir", path, + "config-plugin", config_plugin, + NULL); +} diff --git a/tests/px-manager-helper.h b/tests/px-manager-helper.h new file mode 100644 index 0000000..ad5d662 --- /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); diff --git a/tests/px-manager-test.c b/tests/px-manager-test.c new file mode 100644 index 0000000..8e3865f --- /dev/null +++ b/tests/px-manager-test.c @@ -0,0 +1,213 @@ +/* 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 + +#include + +#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) +{ + fixture->loop = g_main_loop_new (NULL, FALSE); + + if (data) { + g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); + if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { + g_warning ("Failed to set environment"); + return; + } + } + + fixture->manager = px_test_manager_new ("config-sysconfig"); +} + +static void +fixture_teardown (Fixture *fixture, + gconstpointer data) +{ + g_unsetenv ("PX_CONFIG_SYSCONFIG"); + 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"); + + 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); +} + +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); + + return g_test_run (); +} -- cgit v1.2.1 From 0c23d7d71102b23ac9fcc98d8933a7b8756dc30d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 3 Mar 2023 17:44:06 +0100 Subject: Add doap file (#59) --- libproxy.doap | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 libproxy.doap diff --git a/libproxy.doap b/libproxy.doap new file mode 100644 index 0000000..a297e7a --- /dev/null +++ b/libproxy.doap @@ -0,0 +1,21 @@ + + + libproxy + libproxy is a library that provides automatic proxy configuration management. + + + + + C + + + + Jan-Michael Brummer + + + + -- cgit v1.2.1 From ab0b3357580ae01a0ec313f45ff174502a777856 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sat, 4 Mar 2023 17:13:33 +0100 Subject: Make use of G_DEFINE_BOXED_TYPE (#60) --- .github/workflows/build.yml | 9 +- .github/workflows/coverity.yml | 3 +- docs/libproxy.svg | 562 +-------------------- docs/meson.build | 4 +- docs/px.toml.in | 12 +- meson.build | 9 + meson_options.txt | 7 + .../plugins/pacrunner-duktape/pacrunner-duktape.c | 1 - src/backend/px-manager.c | 4 +- src/libproxy/meson.build | 37 +- src/libproxy/proxy-dbus.c | 109 +++- src/libproxy/proxy.c | 25 +- src/libproxy/proxy.h | 91 +--- tests/config-env-test.c | 1 - tests/config-gnome-test.c | 1 - tests/config-kde-test.c | 1 - tests/config-sysconfig-test.c | 2 - tests/px-manager-test.c | 2 - 18 files changed, 188 insertions(+), 692 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13eaddd..9943727 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,8 @@ jobs: gi-docgen \ libpeas-dev \ gsettings-desktop-schemas-dev \ - libcurl4-openssl-dev + libcurl4-openssl-dev \ + valac - name: Build setup run: meson setup build -Db_coverage=true -Ddbus=disabled - name: Build @@ -74,7 +75,8 @@ jobs: gi-docgen \ libpeas-dev \ gsettings-desktop-schemas-dev \ - libcurl4-openssl-dev + libcurl4-openssl-dev \ + valac - name: Build setup run: meson setup build -Db_coverage=true -Ddbus=enabled - name: Build @@ -94,7 +96,7 @@ jobs: - name: Setup run: | pip install meson ninja - brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas curl + brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas 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: | @@ -127,6 +129,7 @@ jobs: mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-libpeas mingw-w64-x86_64-curl + mingw-w64-x86_64-vala - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 20ba216..a87d066 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -38,6 +38,7 @@ jobs: gi-docgen \ libpeas-dev \ gsettings-desktop-schemas-dev \ - libcurl4-openssl-dev + libcurl4-openssl-dev \ + valac - name: Build & upload the results run: .github/coverity.sh diff --git a/docs/libproxy.svg b/docs/libproxy.svg index 414d9d9..70d3793 100644 --- a/docs/libproxy.svg +++ b/docs/libproxy.svg @@ -1,561 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/docs/meson.build b/docs/meson.build index 3981133..868743d 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -18,7 +18,7 @@ gidocgen = find_program('gi-docgen') docs_dir = datadir / 'doc' custom_target('px-doc', - input: [ px_toml, px_backend_gir[0] ], + input: [ px_toml, libproxy_gir[0] ], output: 'libproxy-@0@'.format(apiversion), command: [ gidocgen, @@ -31,7 +31,7 @@ custom_target('px-doc', '--content-dir=@0@'.format(meson.current_source_dir()), '@INPUT1@', ], - depend_files: [ expand_content_md_files ], + #depend_files: [ expand_content_md_files ], build_by_default: true, install: true, install_dir: docs_dir, diff --git a/docs/px.toml.in b/docs/px.toml.in index 6d495f2..356bedf 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -8,15 +8,21 @@ repository_url = "https://github.com/janbrummer/libproxy2" website_url = "https://janbrummer.github.io/libproxy2/" logo_url = "libproxy.svg" dependencies = [ - "GObject-2.0", + "Gio-2.0", ] devhelp = true search_index = true + +[dependencies."Gio-2.0"] +name = "Gio" +description = "The base type system library" +docs_url = "https://developer.gnome.org/gio/stable" + [theme] name = "basic" -show_index_summary = true -show_class_hierarchy = true +show_index_summary = false +show_class_hierarchy = false [source-location] # The base URL for the web UI diff --git a/meson.build b/meson.build index 925acbd..baf668e 100644 --- a/meson.build +++ b/meson.build @@ -11,6 +11,9 @@ root_dir = include_directories('.') px_prefix = get_option('prefix') px_libdir = join_paths(px_prefix, get_option('libdir')) px_plugins_dir = join_paths(px_libdir, meson.project_name().to_lower(), 'plugins') +girdir = get_option('datadir') / 'gir-1.0' +typelibdir = get_option('libdir') / 'girepository-1.0' +vapidir = get_option('datadir') / 'vala' / 'vapi' config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) @@ -21,7 +24,9 @@ add_project_arguments(['-I' + meson.project_build_root()], language: 'c') version_arr = meson.project_version().split('-')[0].split('.') libproxy_version_major = version_arr[0].to_int() libproxy_version_minor = version_arr[1].to_int() + apiversion = '1.0' +package_api_name = '@0@-@1@'.format(meson.project_name(), apiversion) libproxy_prefix = get_option('prefix') datadir = get_option('datadir') @@ -127,6 +132,10 @@ summary({ '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 diff --git a/meson_options.txt b/meson_options.txt index 8e703d7..4a212d8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -66,4 +66,11 @@ option( type: 'boolean', value: true, description: 'Whether to build plugin for PAC Runner Duktape' +) + +option( + 'vapi', + type: 'boolean', + value: true, + description: 'Whether to build vapi support' ) \ 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 index 5196740..5818156 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -27,7 +27,6 @@ #else #include #endif -#include #include "pacrunner-duktape.h" #include "pacutils.h" diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 223cf88..0eabf1b 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -338,7 +338,7 @@ get_config (PeasExtensionSet *set, * * Get raw proxy configuration for gien @uri. * - * Returns: (nullable): a newly created `GStrv` containing configuration data for @uri. + * Returns: (transfer full) (nullable): a newly created `GStrv` containing configuration data for @uri. */ char ** px_manager_get_configuration (PxManager *self, @@ -499,7 +499,7 @@ px_manager_expand_pac (PxManager *self, * * Get proxies for giben @url. * - * Returns: (nullable): a newly created `GStrv` containing proxy related information. + * Returns: (transfer full) (nullable): a newly created `GStrv` containing proxy related information. */ char ** px_manager_get_proxies_sync (PxManager *self, diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index 0368e77..e088f0c 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -51,24 +51,45 @@ install_headers(libproxy_headers, subdir: 'libproxy') pkg = import('pkgconfig') pkg.generate( - description: 'A shared library for libproxy', - libraries: libproxy_lib, - name: 'libproxy', - filebase: 'libproxy-' + api_version, - version: meson.project_version(), + libraries: [libproxy_lib], 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') ) gnome = import('gnome') + +libproxy_gir_extra_args = [ + '--c-include=proxy.h', + '--quiet', +] + libproxy_gir = gnome.generate_gir( libproxy_lib, sources: libproxy_headers + libproxy_sources, nsversion: api_version, - namespace: 'Libproxy', - symbol_prefix: 'libproxy', - identifier_prefix: 'Libproxy', + namespace: 'Px', + export_packages: package_api_name, + symbol_prefix: 'px', + identifier_prefix: 'px', + link_with: libproxy_lib, 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 diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 8646ed5..f83e65e 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -23,27 +23,45 @@ #include "proxy.h" +struct _pxProxyFactory { + GDBusProxy *proxy; + GCancellable *cancellable; +}; + /** * SECTION:px-proxy * @short_description: A convient helper for using proxy servers */ -struct px_proxy_factory { - GDBusProxy *proxy; - GCancellable *cancellable; -}; +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_copy (pxProxyFactory *self) +{ + return g_slice_dup (pxProxyFactory, self); +} /** * px_proxy_factory_new: - * Creates a new proxy factory. * - * Returns: pointer to #px_proxy_factory + * 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. + * + * Returns: (transfer full): A new #pxProxyFactory instance or %NULL on error */ -struct px_proxy_factory * +pxProxyFactory * px_proxy_factory_new (void) { g_autoptr (GError) error = NULL; - struct px_proxy_factory *self = g_malloc0 (sizeof (struct px_proxy_factory)); + pxProxyFactory *self = g_slice_new0 (pxProxyFactory); self->cancellable = g_cancellable_new (); self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, @@ -60,9 +78,65 @@ px_proxy_factory_new (void) return self; } +/** + * 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. + * 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. + * + * 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 (i.e. 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. + * + * 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 + * - ://[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. + * + * For SOCKS proxies, when the protocol version is specified (socks4:// or + * socks5://), it is expected that only this version is used. When only + * socks:// is set, the client MUST try SOCKS version 5 protocol and, on + * connection failure, fallback to SOCKS version 4. + * + * Other proxying protocols may exist. It is expected that the returned + * configuration scheme shall match the network service name of the + * 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. + * + * Returns: (transfer full): a list of proxies + */ char ** -px_proxy_factory_get_proxies (struct px_proxy_factory *self, - const char *url) +px_proxy_factory_get_proxies (pxProxyFactory *self, + const char *url) { g_autoptr (GVariant) result = NULL; g_autoptr (GError) error = NULL; @@ -112,6 +186,15 @@ px_proxy_factory_get_proxies (struct px_proxy_factory *self, return retval; } +/** + * px_proxy_factory_free_proxies + * @proxies: proxy array + * + * 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) { @@ -120,12 +203,12 @@ px_proxy_factory_free_proxies (char **proxies) /** * px_proxy_factory_free: - * @self: a px_proxy_factory + * @self: a #pxProxyFactory * - * Free px_proxy_factory + * Frees the pxProxyFactory instance when no longer used. */ void -px_proxy_factory_free (struct px_proxy_factory *self) +px_proxy_factory_free (pxProxyFactory *self) { g_cancellable_cancel (self->cancellable); g_clear_object (&self->cancellable); diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c index eeb2308..2a73667 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -31,21 +31,28 @@ * Test 123 */ -struct px_proxy_factory { +struct _pxProxyFactory { PxManager *manager; GCancellable *cancellable; }; +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); + /** * px_proxy_factory_new: * Creates a new proxy factory. * * Returns: pointer to #px_proxy_factory */ -struct px_proxy_factory * +pxProxyFactory * px_proxy_factory_new (void) { - struct px_proxy_factory *self = g_malloc0 (sizeof (struct px_proxy_factory)); + pxProxyFactory *self = g_slice_new0 (pxProxyFactory); self->cancellable = g_cancellable_new (); self->manager = px_manager_new (); @@ -53,9 +60,15 @@ px_proxy_factory_new (void) return self; } +pxProxyFactory * +px_proxy_factory_copy (pxProxyFactory *self) +{ + return g_slice_dup (pxProxyFactory, self); +} + char ** -px_proxy_factory_get_proxies (struct px_proxy_factory *self, - const char *url) +px_proxy_factory_get_proxies (pxProxyFactory *self, + const char *url) { g_auto (GStrv) result = NULL; g_autoptr (GError) error = NULL; @@ -82,7 +95,7 @@ px_proxy_factory_free_proxies (char **proxies) * Free px_proxy_factory */ void -px_proxy_factory_free (struct px_proxy_factory *self) +px_proxy_factory_free (pxProxyFactory *self) { g_cancellable_cancel (self->cancellable); g_clear_object (&self->cancellable); diff --git a/src/libproxy/proxy.h b/src/libproxy/proxy.h index be35d3c..50f9944 100644 --- a/src/libproxy/proxy.h +++ b/src/libproxy/proxy.h @@ -26,96 +26,17 @@ extern "C" { #endif -typedef struct px_proxy_factory pxProxyFactory; +#include + +typedef struct _pxProxyFactory pxProxyFactory; + +#define PX_TYPE_PROXY_FACTORY (px_proxy_factory_get_type ()) -/** - * px_proxy_factory_new: - * - * 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. - * - * @return A new pxProxyFactory instance or NULL on error - */ pxProxyFactory *px_proxy_factory_new (void); +GType px_proxy_factory_get_type (void) G_GNUC_CONST; -/** - * px_proxy_factory_get_proxies: - * @self: a #pxProxyFactpry - * @url: Get proxxies for specificed URL - * - * Get which proxies to use for the specified URL. - * - * 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. - * - * 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 (i.e. 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. - * - * 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 - * - ://[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. - * - * For SOCKS proxies, when the protocol version is specified (socks4:// or - * socks5://), it is expected that only this version is used. When only - * socks:// is set, the client MUST try SOCKS version 5 protocol and, on - * connection failure, fallback to SOCKS version 4. - * - * Other proxying protocols may exist. It is expected that the returned - * configuration scheme shall match the network service name of the - * 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 - */ char **px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url); - -/** - * px_proxy_factory_free_proxies - * @proxies: proxie array - * - * 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); - -/** - * px_proxy_factory_free: - * @self: a #pxProxyFactory - * - * Frees the pxProxyFactory instance when no longer used. - */ void px_proxy_factory_free (pxProxyFactory *self); #ifdef __cplusplus diff --git a/tests/config-env-test.c b/tests/config-env-test.c index 34d3218..074f51b 100644 --- a/tests/config-env-test.c +++ b/tests/config-env-test.c @@ -23,7 +23,6 @@ #include "px-manager-helper.h" -#include typedef struct { const char *env; diff --git a/tests/config-gnome-test.c b/tests/config-gnome-test.c index 7d8223d..a7940d9 100644 --- a/tests/config-gnome-test.c +++ b/tests/config-gnome-test.c @@ -23,7 +23,6 @@ #include "px-manager-helper.h" -#include #include typedef struct { diff --git a/tests/config-kde-test.c b/tests/config-kde-test.c index 9aba2d5..371907d 100644 --- a/tests/config-kde-test.c +++ b/tests/config-kde-test.c @@ -23,7 +23,6 @@ #include "px-manager-helper.h" -#include typedef struct { const char *url; diff --git a/tests/config-sysconfig-test.c b/tests/config-sysconfig-test.c index 4cc0989..e2d0571 100644 --- a/tests/config-sysconfig-test.c +++ b/tests/config-sysconfig-test.c @@ -23,8 +23,6 @@ #include "px-manager-helper.h" -#include - typedef struct { const char *url; const char *proxy; diff --git a/tests/px-manager-test.c b/tests/px-manager-test.c index 8e3865f..ced1fbf 100644 --- a/tests/px-manager-test.c +++ b/tests/px-manager-test.c @@ -22,8 +22,6 @@ #include "px-manager.h" #include "px-manager-helper.h" -#include - #include #define SERVER_PORT 1983 -- cgit v1.2.1 From d557d3bf1fc8211a0096de267351adf57a4a1d47 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sat, 4 Mar 2023 17:34:14 +0100 Subject: Remove gcovr badge (#61) --- .github/workflows/build.yml | 21 --------------------- README.md | 1 - 2 files changed, 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9943727..6ab87c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,27 +30,6 @@ jobs: run: | ninja test -C build ninja coverage -C build - - name: Extract Coverage Percentage - run: | - RATE=$(grep -o -m 1 -P '(?<=line-rate=").*?(?=")' ./build/meson-logs/coverage.xml | head -1) - PERCENT="$(echo "($RATE * 100)/1" | bc)" - - BADGE_COLOR=red - if [ $PERCENT -ge 60 ]; then BADGE_COLOR=orange; fi - if [ $PERCENT -ge 80 ]; then BADGE_COLOR=yellow; fi - if [ $PERCENT -ge 95 ]; then BADGE_COLOR=brightgreen; fi - echo "$RATE -> $PERCENT : $BADGE_COLOR" - echo "COVERAGE_PERCENT=$PERCENT" >> $GITHUB_ENV - echo "COVERAGE_COLOR=$BADGE_COLOR" >> $GITHUB_ENV - - name: Create Coverage Badge - uses: schneegans/dynamic-badges-action@v1.1.0 - with: - auth: ${{ secrets.GIST_TOKEN }} - gistID: 713fa369e20d1c0fdb5896b9a167c3b4 - filename: greeter-coverage.json - label: Coverage - message: ${{ env.COVERAGE_PERCENT }} - color: ${{ env.COVERAGE_COLOR }} - name: Upload artifact uses: actions/upload-pages-artifact@v1 with: diff --git a/README.md b/README.md index 4456ae8..a8ad509 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ ![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) [![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://codecov.io/github/janbrummer/libproxy2) -[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/janbrummer/713fa369e20d1c0fdb5896b9a167c3b4/raw/greeter-coverage.json)](https://github.com/janbrummer/repo/actions/workflows/build.yaml) [![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml) # Libproxy -- cgit v1.2.1 From 674422df277dea0c4409de00e1aa3e40c5208af2 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Mar 2023 07:28:11 +0100 Subject: Fix minor issues in documentation (#62) --- src/libproxy/proxy-dbus.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index f83e65e..b60a823 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -50,12 +50,13 @@ px_proxy_factory_copy (pxProxyFactory *self) /** * px_proxy_factory_new: * - * 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. + * Creates a new `pxProxyFactory` instance. * - * Returns: (transfer full): 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) @@ -83,12 +84,12 @@ px_proxy_factory_new (void) * @self: a #pxProxyFactory * @url: Get proxxies for specificed URL * - * Get which proxies to use for the specified 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 @@ -109,12 +110,19 @@ 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 + * * - ://[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. * @@ -128,9 +136,10 @@ 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. + * To free the returned value, call @px_proxy_factory_free_proxies. * * Returns: (transfer full): a list of proxies */ @@ -190,7 +199,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, * px_proxy_factory_free_proxies * @proxies: proxy array * - * Frees the proxy array returned by #px_proxy_factory_get_proxies when no + * Frees the proxy array returned by @px_proxy_factory_get_proxies when no * longer used. * * @since 0.4.16 @@ -205,7 +214,7 @@ px_proxy_factory_free_proxies (char **proxies) * px_proxy_factory_free: * @self: a #pxProxyFactory * - * Frees the pxProxyFactory instance when no longer used. + * Frees the `pxProxyFactory`. */ void px_proxy_factory_free (pxProxyFactory *self) -- cgit v1.2.1 From 498bf5b31543c9be9feedc7740e854590e4da2df Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Mar 2023 10:50:55 +0100 Subject: Fix crash in free function (#63) --- src/libproxy/proxy-dbus.c | 4 ++-- src/libproxy/proxy.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index b60a823..e9d935b 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -44,7 +44,7 @@ G_DEFINE_BOXED_TYPE (pxProxyFactory, pxProxyFactory * px_proxy_factory_copy (pxProxyFactory *self) { - return g_slice_dup (pxProxyFactory, self); + return g_memdup2 (self, sizeof (pxProxyFactory)); } /** @@ -62,7 +62,7 @@ pxProxyFactory * px_proxy_factory_new (void) { g_autoptr (GError) error = NULL; - pxProxyFactory *self = g_slice_new0 (pxProxyFactory); + pxProxyFactory *self = g_new0 (pxProxyFactory, 1); self->cancellable = g_cancellable_new (); self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c index 2a73667..2ae6041 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -52,7 +52,7 @@ G_DEFINE_BOXED_TYPE (pxProxyFactory, pxProxyFactory * px_proxy_factory_new (void) { - pxProxyFactory *self = g_slice_new0 (pxProxyFactory); + pxProxyFactory *self = g_new0 (pxProxyFactory, 1); self->cancellable = g_cancellable_new (); self->manager = px_manager_new (); @@ -63,7 +63,7 @@ px_proxy_factory_new (void) pxProxyFactory * px_proxy_factory_copy (pxProxyFactory *self) { - return g_slice_dup (pxProxyFactory, self); + return g_memdup2 (self, sizeof (pxProxyFactory)); } char ** -- cgit v1.2.1 From d8b5bba8a80595b0a46dc00127c4a095026feab9 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Mar 2023 15:26:34 +0100 Subject: Add dependencies to documentation (#67) --- docs/px.toml.in | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/px.toml.in b/docs/px.toml.in index 356bedf..71c88f8 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -8,17 +8,46 @@ repository_url = "https://github.com/janbrummer/libproxy2" website_url = "https://janbrummer.github.io/libproxy2/" logo_url = "libproxy.svg" dependencies = [ + "GObject-2.0", "Gio-2.0", + "GLib-2.0", + "Peas-1.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 = "The base type system library" +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."Peas-1.0"] +name = "Peas" +description = "GObject-based plugins engine" +docs_url = "https://gnome.pages.gitlab.gnome.org/libpeas/libpeas-1.0/" + +[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 -- cgit v1.2.1 From a8ec41a5f13593db3ca16dc0d64a1d6e40590e81 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 6 Mar 2023 15:27:08 +0100 Subject: Add Configuration Logic page (#66) --- docs/configuration-logic.md | 93 +++++++++++++++++++++++++++++++++++++++++++++ docs/meson.build | 3 +- docs/px.toml.in | 1 + 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 docs/configuration-logic.md diff --git a/docs/configuration-logic.md b/docs/configuration-logic.md new file mode 100644 index 0000000..342ef38 --- /dev/null +++ b/docs/configuration-logic.md @@ -0,0 +1,93 @@ +Title: Configuration Logic +Slug: Design + +# Configuration Logic +Source: https://code.google.com/archive/p/libproxy/wikis/ConfigurationLogic.wiki + +## 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 +``` + +### Konqueror + +This is the default browser in the KDE desktop environment. This browser only +support protocol specific proxy (no SOCKS), thus logic is very basic. + +## 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/meson.build b/docs/meson.build index 868743d..a468de9 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -1,6 +1,7 @@ if get_option('docs') expand_content_md_files = [ + 'configuration-logic.md', 'build-howto.md', ] @@ -31,7 +32,7 @@ custom_target('px-doc', '--content-dir=@0@'.format(meson.current_source_dir()), '@INPUT1@', ], - #depend_files: [ expand_content_md_files ], + depend_files: [ expand_content_md_files ], build_by_default: true, install: true, install_dir: docs_dir, diff --git a/docs/px.toml.in b/docs/px.toml.in index 71c88f8..1c91b0a 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -61,6 +61,7 @@ file_format = "{filename}#L{line}" [extra] content_files = [ + "configuration-logic.md", "build-howto.md", ] -- cgit v1.2.1 From 1752685aa329e434d0410a8d865722c294efe137 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 7 Mar 2023 15:21:02 +0100 Subject: Add samples (#64) * Change Namespace to Libproxy * Add samples Fixes: https://github.com/janbrummer/libproxy2/issues/33 --- docs/build-howto.md | 123 ---------------------------------------------- docs/meson.build | 5 +- docs/perl.md | 21 ++++++++ docs/px.toml.in | 5 +- docs/python.md | 30 +++++++++++ docs/ruby.md | 20 ++++++++ docs/vala.md | 32 ++++++++++++ src/libproxy/meson.build | 2 +- src/libproxy/proxy-dbus.c | 2 +- 9 files changed, 113 insertions(+), 127 deletions(-) delete mode 100644 docs/build-howto.md create mode 100644 docs/perl.md create mode 100644 docs/python.md create mode 100644 docs/ruby.md create mode 100644 docs/vala.md diff --git a/docs/build-howto.md b/docs/build-howto.md deleted file mode 100644 index 7ce0ef5..0000000 --- a/docs/build-howto.md +++ /dev/null @@ -1,123 +0,0 @@ -Title: Compiling with Libproxy -Slug: building - -# Compiling with Libproxy - -The current stable API provides a small synchronous function set which makes it easy to add it to existing application and libraries. - -The following example is written in C but can be translated as well to every other programming language thanks to gobject-introspection. Furthermore there are -several language samples provided in 'docs/samples' and also linked here in this main documentation. - -## Initialization - -First of all libproxy needs to be initialized. This is done with: - -``` -/** - * px_proxy_factory_new: - * - * 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. - * - * @return A new pxProxyFactory instance or NULL on error - */ -pxProxyFactory *px_proxy_factory_new (void); -``` - -## Get proxy information - -Determining whether a proxy server is need to access a given url use `px_proxy_factory_get_proxies`: - -``` -/** - * px_proxy_factory_get_proxies: - * @self: a #pxProxyFactpry - * @url: Get proxxies for specificed URL - * - * Get which proxies to use for the specified URL. - * - * 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. - * - * 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 (i.e. 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. - * - * 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 - * - ://[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. - * - * For SOCKS proxies, when the protocol version is specified (socks4:// or - * socks5://), it is expected that only this version is used. When only - * socks:// is set, the client MUST try SOCKS version 5 protocol and, on - * connection failure, fallback to SOCKS version 4. - * - * Other proxying protocols may exist. It is expected that the returned - * configuration scheme shall match the network service name of the - * 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 - */ -char **px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url); -``` - -## Freeing proxy list - -Ensure unused proxy information is freed after user with `px_proxy_factory_free_proxies`: - -``` -/** - * px_proxy_factory_free_proxies - * @proxies: proxie array - * - * 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); -``` - -## Destruction - -To close and destroy the `pxProxyFactory` make use of: - -``` -/** - * px_proxy_factory_free: - * @self: a #pxProxyFactory - * - * Frees the pxProxyFactory instance when no longer used. - */ -void px_proxy_factory_free (pxProxyFactory *self); -``` diff --git a/docs/meson.build b/docs/meson.build index a468de9..556a13d 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -2,7 +2,10 @@ if get_option('docs') expand_content_md_files = [ 'configuration-logic.md', - 'build-howto.md', + 'perl.md', + 'python.md', + 'ruby.md', + 'vala.md', ] toml_data = configuration_data() 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/px.toml.in b/docs/px.toml.in index 1c91b0a..5bc08c9 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -62,7 +62,10 @@ file_format = "{filename}#L{line}" [extra] content_files = [ "configuration-logic.md", - "build-howto.md", + "perl.md", + "python.md", + "ruby.md", + "vala.md", ] content_images = [ 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/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/src/libproxy/meson.build b/src/libproxy/meson.build index e088f0c..8fdd880 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -72,7 +72,7 @@ libproxy_gir = gnome.generate_gir( libproxy_lib, sources: libproxy_headers + libproxy_sources, nsversion: api_version, - namespace: 'Px', + namespace: 'Libproxy', export_packages: package_api_name, symbol_prefix: 'px', identifier_prefix: 'px', diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index e9d935b..1587c73 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -197,7 +197,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, /** * px_proxy_factory_free_proxies - * @proxies: proxy array + * @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. -- cgit v1.2.1 From e7713214c85ded42112aefdd05bf7af37a80fd6e Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 9 Mar 2023 14:52:52 +0100 Subject: Add config-option property (#68) In order to reduce the number of environment manipulation for testing purpose, introduce a new config-option property to set config files for tests. --- src/backend/plugins/config-env/config-env.c | 41 +++++++++++++ src/backend/plugins/config-gnome/config-gnome.c | 43 ++++++++++++++ src/backend/plugins/config-kde/config-kde.c | 68 +++++++++++++++++++-- .../plugins/config-sysconfig/config-sysconfig.c | 69 ++++++++++++++++++++-- src/backend/px-manager.c | 38 +++++++++++- src/backend/px-manager.h | 2 + src/backend/px-plugin-config.c | 8 +++ tests/config-env-test.c | 2 +- tests/config-gnome-test.c | 8 +-- tests/config-kde-test.c | 34 ++--------- tests/config-sysconfig-test.c | 7 +-- tests/px-manager-helper.c | 10 ++-- tests/px-manager-helper.h | 2 +- tests/px-manager-test.c | 14 ++--- 14 files changed, 281 insertions(+), 65 deletions(-) diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index bec1d72..af13de6 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -43,6 +43,11 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigEnv, 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) { @@ -79,12 +84,48 @@ px_config_env_dispose (GObject *object) 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 diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index f5c8008..0041c1b 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -49,6 +49,11 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigGnome, 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) { @@ -73,9 +78,47 @@ px_config_gnome_init (PxConfigGnome *self) 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 diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 3fb6d1c..24fb9e1 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -40,6 +40,7 @@ typedef enum { struct _PxConfigKde { GObject parent_instance; + char *config_option; gboolean available; char *no_proxy; @@ -56,6 +57,11 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigKde, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + static void px_config_kde_read_config (PxConfigKde *self, char *proxy_file) @@ -118,29 +124,83 @@ px_config_kde_read_config (PxConfigKde *self, } while (line); } -static void -px_config_kde_init (PxConfigKde *self) +static +void +px_config_kde_set_config_file (PxConfigKde *self, + const char *file) { - const char *test_file = g_getenv ("PX_CONFIG_KDE"); - g_autofree char *config = test_file ? g_strdup (test_file) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL); + g_autofree char *config = NULL; + + g_clear_pointer (&self->config_option, g_free); + self->config_option = file ? g_strdup (file) : NULL; + + config = self->config_option ? g_strdup (self->config_option) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL); self->available = g_file_test (config, G_FILE_TEST_EXISTS); if (self->available) px_config_kde_read_config (self, config); } +static void +px_config_kde_init (PxConfigKde *self) +{ + px_config_kde_set_config_file (self, NULL); +} + static void px_config_kde_dispose (GObject *object) { 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_option); + 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 diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index 77c7fe1..d7a1fa1 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -30,6 +30,7 @@ struct _PxConfigSysConfig { GObject parent_instance; char *proxy_file; + char *config_option; gboolean available; gboolean proxy_enabled; @@ -47,17 +48,27 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigSysConfig, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init)) -static void -px_config_sysconfig_init (PxConfigSysConfig *self) +enum { + PROP_0, + PROP_CONFIG_OPTION +}; + +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; - const char *test_file = g_getenv ("PX_CONFIG_SYSCONFIG"); char *line = NULL; - self->proxy_file = g_strdup (test_file ? test_file : "/etc/sysconfig/proxy"); + g_clear_pointer (&self->config_option, g_free); + self->config_option = config_file ? g_strdup (config_file) : NULL; + + self->proxy_file = g_strdup (self->config_option ? self->config_option : "/etc/sysconfig/proxy"); self->available = FALSE; file = g_file_new_for_path (self->proxy_file); @@ -109,9 +120,59 @@ px_config_sysconfig_init (PxConfigSysConfig *self) self->available = TRUE; } +static void +px_config_sysconfig_init (PxConfigSysConfig *self) +{ + px_config_sysconfig_set_config_file (self, NULL); +} + +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_option); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void px_config_sysconfig_class_init (PxConfigSysConfigClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + 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 diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 0eabf1b..f69dab3 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -32,6 +32,7 @@ enum { PROP_0, PROP_PLUGINS_DIR, PROP_CONFIG_PLUGIN, + PROP_CONFIG_OPTION, LAST_PROP }; @@ -55,6 +56,7 @@ struct _PxManager { GCancellable *cancellable; char *config_plugin; + char *config_option; gboolean online; gboolean wpad; @@ -106,7 +108,7 @@ px_manager_constructed (GObject *object) peas_engine_add_search_path (self->engine, self->plugins_dir, NULL); - self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, NULL); + self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, "config-option", self->config_option, NULL); self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); list = peas_engine_get_plugin_list (self->engine); @@ -183,6 +185,9 @@ px_manager_set_property (GObject *object, 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); } @@ -227,6 +232,12 @@ px_manager_class_init (PxManagerClass *klass) 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); } @@ -235,6 +246,29 @@ 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: * @@ -245,7 +279,7 @@ px_manager_init (PxManager *self) PxManager * px_manager_new (void) { - return g_object_new (PX_TYPE_MANAGER, "plugins-dir", PX_PLUGINS_DIR, NULL); + return px_manager_new_with_options ("plugins-dir", PX_PLUGINS_DIR, NULL); } static size_t diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h index ca3c2fe..74c0584 100644 --- a/src/backend/px-manager.h +++ b/src/backend/px-manager.h @@ -49,6 +49,8 @@ typedef enum { 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); diff --git a/src/backend/px-plugin-config.c b/src/backend/px-plugin-config.c index 6f8c803..d71d49a 100644 --- a/src/backend/px-plugin-config.c +++ b/src/backend/px-plugin-config.c @@ -27,4 +27,12 @@ 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/tests/config-env-test.c b/tests/config-env-test.c index 074f51b..2cfc3cb 100644 --- a/tests/config-env-test.c +++ b/tests/config-env-test.c @@ -75,7 +75,7 @@ test_config_env (void) g_setenv ("no_proxy", test.no_proxy, TRUE); } - manager = px_test_manager_new ("config-env"); + manager = px_test_manager_new ("config-env", NULL); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); diff --git a/tests/config-gnome-test.c b/tests/config-gnome-test.c index a7940d9..73602ad 100644 --- a/tests/config-gnome-test.c +++ b/tests/config-gnome-test.c @@ -96,7 +96,7 @@ test_config_gnome_manual (Fixture *self, 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"); + manager = px_test_manager_new ("config-gnome", NULL); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); @@ -128,7 +128,7 @@ test_config_gnome_manual_auth (Fixture *self, 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"); + 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); @@ -146,7 +146,7 @@ test_config_gnome_auto (Fixture *self, g_auto (GStrv) config = NULL; g_autoptr (GUri) uri = NULL; - manager = px_test_manager_new ("config-gnome"); + 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", ""); @@ -171,7 +171,7 @@ test_config_gnome_fail (Fixture *self, /* Disable GNOME support */ g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE); - manager = px_test_manager_new ("config-gnome"); + 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", ""); diff --git a/tests/config-kde-test.c b/tests/config-kde-test.c index 371907d..c918afd 100644 --- a/tests/config-kde-test.c +++ b/tests/config-kde-test.c @@ -64,12 +64,7 @@ test_config_kde_disabled (void) 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); - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); + manager = px_test_manager_new ("config-kde", path); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); @@ -98,12 +93,7 @@ test_config_kde_manual (void) 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); - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); + manager = px_test_manager_new ("config-kde", path); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); @@ -135,12 +125,7 @@ test_config_kde_wpad (void) 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); - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); + manager = px_test_manager_new ("config-kde", path); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); @@ -172,12 +157,7 @@ test_config_kde_pac (void) 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); - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - continue; - } - - manager = px_test_manager_new ("config-kde"); + manager = px_test_manager_new ("config-kde", path); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); @@ -205,14 +185,10 @@ test_config_kde_fail (void) g_auto (GStrv) config = NULL; g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL); - if (!g_setenv ("PX_CONFIG_KDE", path, TRUE)) { - g_warning ("Failed to set kde environment"); - } - /* Disable KDE support */ g_unsetenv ("KDE_FULL_SESSION"); - manager = px_test_manager_new ("config-kde"); + manager = px_test_manager_new ("config-kde", path); uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_PARSE_RELAXED, &error); diff --git a/tests/config-sysconfig-test.c b/tests/config-sysconfig-test.c index e2d0571..40c0b92 100644 --- a/tests/config-sysconfig-test.c +++ b/tests/config-sysconfig-test.c @@ -49,12 +49,7 @@ test_config_sysconfig (void) ConfigSysConfigTest test = config_sysconfig_test_set[idx]; g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy", NULL); - if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { - g_warning ("Failed to set sysconfig environment"); - continue; - } - - manager = px_test_manager_new ("config-sysconfig"); + manager = px_test_manager_new ("config-sysconfig", path); g_clear_error (&error); uri = g_uri_parse (test.url, G_URI_FLAGS_PARSE_RELAXED, &error); diff --git a/tests/px-manager-helper.c b/tests/px-manager-helper.c index 223ad62..c5e0b87 100644 --- a/tests/px-manager-helper.c +++ b/tests/px-manager-helper.c @@ -23,12 +23,12 @@ #include "px-manager-helper.h" PxManager * -px_test_manager_new (const char *config_plugin) +px_test_manager_new (const char *config_plugin, const char *config_option) { g_autofree char *path = g_test_build_filename (G_TEST_BUILT, "../src/backend/plugins", NULL); - return g_object_new (PX_TYPE_MANAGER, - "plugins-dir", path, - "config-plugin", config_plugin, - NULL); + return px_manager_new_with_options ("plugins-dir", path, + "config-plugin", config_plugin, + "config-option", config_option, + NULL); } diff --git a/tests/px-manager-helper.h b/tests/px-manager-helper.h index ad5d662..2717448 100644 --- a/tests/px-manager-helper.h +++ b/tests/px-manager-helper.h @@ -21,4 +21,4 @@ #pragma once -PxManager *px_test_manager_new (const char *config_plugin); +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 index ced1fbf..85936c8 100644 --- a/tests/px-manager-test.c +++ b/tests/px-manager-test.c @@ -59,24 +59,20 @@ static void fixture_setup (Fixture *fixture, gconstpointer data) { + g_autofree char *path = NULL; + fixture->loop = g_main_loop_new (NULL, FALSE); - if (data) { - g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); - if (!g_setenv ("PX_CONFIG_SYSCONFIG", path, TRUE)) { - g_warning ("Failed to set environment"); - return; - } - } + if (data) + path = g_test_build_filename (G_TEST_DIST, "data", data, NULL); - fixture->manager = px_test_manager_new ("config-sysconfig"); + fixture->manager = px_test_manager_new ("config-sysconfig", path); } static void fixture_teardown (Fixture *fixture, gconstpointer data) { - g_unsetenv ("PX_CONFIG_SYSCONFIG"); g_clear_object (&fixture->manager); } -- cgit v1.2.1 From c23a1345e9c75a0e1ae7d5d5affcc6af5df24d38 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 9 Mar 2023 17:34:02 +0100 Subject: Add flag to toggle curl integration (#65) In order to fix a possible build cycle between libproxy and curl add a toggle to switch off curl if necessary. Fixes: https://github.com/janbrummer/libproxy2/issues/57 --- meson.build | 12 +++++++----- meson_options.txt | 7 +++++++ src/backend/px-manager.c | 8 ++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index baf668e..96f22fe 100644 --- a/meson.build +++ b/meson.build @@ -15,10 +15,6 @@ girdir = get_option('datadir') / 'gir-1.0' typelibdir = get_option('libdir') / 'girepository-1.0' vapidir = get_option('datadir') / 'vala' / 'vapi' -config_h = configuration_data() -config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) -config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) -configure_file(output: 'config.h', configuration: config_h) add_project_arguments(['-I' + meson.project_build_root()], language: 'c') version_arr = meson.project_version().split('-')[0].split('.') @@ -115,12 +111,18 @@ glib_dep = dependency('glib-2.0', version: '>= 2.71.3') gio_dep = dependency('gio-2.0', version: '>= 2.71.3') peas_dep = dependency('libpeas-1.0') soup_dep = dependency('libsoup-3.0', required: get_option('tests')) -curl_dep = dependency('libcurl') +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')) build_dbus = get_option('dbus').disable_auto_if(['window', 'darwin'].contains(host_system)).allowed() +config_h = configuration_data() +config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) +config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) +config_h.set10('HAVE_CURL', get_option('curl')) +configure_file(output: 'config.h', configuration: config_h) + subdir('src') subdir('tests') subdir('docs') diff --git a/meson_options.txt b/meson_options.txt index 4a212d8..1c530b8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -73,4 +73,11 @@ option( type: 'boolean', value: true, description: 'Whether to build vapi support' +) + +option( + 'curl', + type: 'boolean', + value: true, + description: 'Whether to build cURL support' ) \ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index f69dab3..ad230ac 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -25,7 +25,9 @@ #include "px-plugin-config.h" #include "px-plugin-pacrunner.h" +#ifdef HAVE_CURL #include +#endif #include enum { @@ -51,7 +53,9 @@ struct _PxManager { PeasExtensionSet *config_set; PeasExtensionSet *pacrunner_set; GNetworkMonitor *network_monitor; +#ifdef HAVE_CURL CURL *curl; +#endif char *plugins_dir; GCancellable *cancellable; @@ -309,6 +313,7 @@ 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; @@ -339,6 +344,9 @@ px_manager_pac_download (PxManager *self, } return g_byte_array_free_to_bytes (byte_array); +#else + return NULL; +#endif } struct ConfigData { -- cgit v1.2.1 From 4b883bf6dde14b655b251f3d1db9dce6f2f32f56 Mon Sep 17 00:00:00 2001 From: Dominique Leuenberger Date: Fri, 10 Mar 2023 18:02:40 +0100 Subject: build: fix build without curl (#70) config.set10(HAVE_CURL, boolean) always defines HAVE_CURL, with values 0/1. This is incompatible with #ifdef HAVE_CURL, as even a value of 0 is defined. Rather use config.set(HAVE_CURL, boolean) which results in #define/#undefine based on the boolean. --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 96f22fe..695c3df 100644 --- a/meson.build +++ b/meson.build @@ -120,7 +120,7 @@ build_dbus = get_option('dbus').disable_auto_if(['window', 'darwin'].contains(ho config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) -config_h.set10('HAVE_CURL', get_option('curl')) +config_h.set('HAVE_CURL', get_option('curl')) configure_file(output: 'config.h', configuration: config_h) subdir('src') @@ -142,4 +142,4 @@ summary({ 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 \ No newline at end of file +endif -- cgit v1.2.1 From e0424607df081c88b0c4531c9b2a3da6bfb506c0 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sat, 11 Mar 2023 23:01:23 +0100 Subject: Various cleanups (#69) --- docs/meson.build | 2 +- docs/px.toml.in | 2 +- meson.build | 21 ++++++------ meson_options.txt | 7 ++++ src/backend/dbus/dbus.c | 2 +- src/backend/meson.build | 20 ++---------- src/backend/px-manager.c | 4 +-- src/backend/px-manager.h | 11 ------- src/backend/px-plugin-config.c | 1 - src/backend/px-plugin-pacrunner.h | 1 - src/libproxy/meson.build | 68 +++++++++++++++++++-------------------- src/libproxy/proxy.c | 2 -- 12 files changed, 58 insertions(+), 83 deletions(-) diff --git a/docs/meson.build b/docs/meson.build index 556a13d..09263c5 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -23,7 +23,7 @@ docs_dir = datadir / 'doc' custom_target('px-doc', input: [ px_toml, libproxy_gir[0] ], - output: 'libproxy-@0@'.format(apiversion), + output: 'libproxy-@0@'.format(api_version), command: [ gidocgen, 'generate', diff --git a/docs/px.toml.in b/docs/px.toml.in index 5bc08c9..740419b 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -6,7 +6,7 @@ license = "LGPL-2.1-or-later" browse_url = "https://github.com/janbrummer/libproxy2" repository_url = "https://github.com/janbrummer/libproxy2" website_url = "https://janbrummer.github.io/libproxy2/" -logo_url = "libproxy.svg" +# logo_url = "libproxy.svg" dependencies = [ "GObject-2.0", "Gio-2.0", diff --git a/meson.build b/meson.build index 695c3df..924a0c7 100644 --- a/meson.build +++ b/meson.build @@ -4,11 +4,14 @@ project('libproxy', 'c', default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu11', ], ) -cc = meson.get_compiler('c') +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')) px_plugins_dir = join_paths(px_libdir, meson.project_name().to_lower(), 'plugins') girdir = get_option('datadir') / 'gir-1.0' @@ -17,15 +20,11 @@ vapidir = get_option('datadir') / 'vala' / 'vapi' add_project_arguments(['-I' + meson.project_build_root()], language: 'c') -version_arr = meson.project_version().split('-')[0].split('.') -libproxy_version_major = version_arr[0].to_int() -libproxy_version_minor = version_arr[1].to_int() - -apiversion = '1.0' -package_api_name = '@0@-@1@'.format(meson.project_name(), apiversion) +# 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) -libproxy_prefix = get_option('prefix') -datadir = get_option('datadir') +cc = meson.get_compiler('c') project_c_args = [] test_c_args = [ @@ -83,9 +82,7 @@ test_c_args = [ '-fno-strict-aliasing', ['-Werror=format-security', '-Werror=format=2'], ] -#if get_option('buildtype') != 'plain' -# test_c_args += '-fstack-protector-strong' -#endif + foreach arg: test_c_args if cc.has_multi_arguments(arg) project_c_args += arg diff --git a/meson_options.txt b/meson_options.txt index 1c530b8..04389b9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -80,4 +80,11 @@ option( type: 'boolean', value: true, description: 'Whether to build cURL support' +) + +option( + 'introspection', + type: 'boolean', + value: true, + description: 'Whether to build introspection support' ) \ No newline at end of file diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 2495257..a04c0f9 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -1,4 +1,4 @@ -/* main.c +/* dbus.c * * Copyright 2022-2023 The Libproxy Team * diff --git a/src/backend/meson.build b/src/backend/meson.build index 4a9a1ab..b0b8de9 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -1,5 +1,3 @@ -api_version = '1.0' - px_backend_sources = [ 'px-manager.c', 'px-manager.h', @@ -17,12 +15,12 @@ px_backend_deps = [ ] px_backend_c_args = [ - '-DG_LOG_DOMAIN="libpxbackend"', + '-DG_LOG_DOMAIN="pxbackend"', ] px_backend_inc = include_directories('.') -px_backend_lib = shared_library( +px_backend = shared_library( 'pxbackend-@0@'.format(api_version), px_backend_sources, dependencies: px_backend_deps, @@ -30,21 +28,9 @@ px_backend_lib = shared_library( install: true ) -gnome = import('gnome') -px_backend_gir = gnome.generate_gir( - px_backend_lib, - sources: px_backend_sources, - nsversion: api_version, - namespace: 'Px', - symbol_prefix: 'px', - identifier_prefix: 'Px', - includes: [ 'Gio-2.0' ], - install: false, -) - px_backend_dep = declare_dependency( include_directories: px_backend_inc, - link_with: px_backend_lib, + link_with: px_backend, dependencies: px_backend_deps ) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ad230ac..51669cb 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -46,7 +46,6 @@ static GParamSpec *obj_properties[LAST_PROP]; * Manage libproxy modules */ -/* TODO: Move to private structure */ struct _PxManager { GObject parent_instance; PeasEngine *engine; @@ -286,6 +285,7 @@ px_manager_new (void) return px_manager_new_with_options ("plugins-dir", PX_PLUGINS_DIR, NULL); } +#ifdef HAVE_CURL static size_t store_data (void *contents, size_t size, @@ -299,6 +299,7 @@ store_data (void *contents, return real_size; } +#endif /** * px_manager_pac_download: @@ -548,7 +549,6 @@ px_manager_get_proxies_sync (PxManager *self, const char *url, GError **error) { - /* GList *list; */ 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; diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h index 74c0584..486fb51 100644 --- a/src/backend/px-manager.h +++ b/src/backend/px-manager.h @@ -26,17 +26,6 @@ G_BEGIN_DECLS #define PX_TYPE_MANAGER (px_manager_get_type()) -// #define PX_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PX_TYPE_MANAGER, PxManager)) - -// typedef struct _PxManager PxManager; -// typedef struct _PxManagerClass PxManagerClass; - -// struct _PxManagerClass -// { -// GObjectClass parent_class; - -// gboolean (*get_config) (PxManager *self, GUri *uri); -// }; G_DECLARE_FINAL_TYPE (PxManager, px_manager, PX, MANAGER, GObject) diff --git a/src/backend/px-plugin-config.c b/src/backend/px-plugin-config.c index d71d49a..22f369a 100644 --- a/src/backend/px-plugin-config.c +++ b/src/backend/px-plugin-config.c @@ -19,7 +19,6 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ - #include "px-plugin-config.h" G_DEFINE_INTERFACE (PxConfig, px_config, G_TYPE_OBJECT) diff --git a/src/backend/px-plugin-pacrunner.h b/src/backend/px-plugin-pacrunner.h index f7251ce..4b03a24 100644 --- a/src/backend/px-plugin-pacrunner.h +++ b/src/backend/px-plugin-pacrunner.h @@ -19,7 +19,6 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ - #pragma once #include diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index 8fdd880..873b184 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -1,5 +1,3 @@ -api_version = '1.0' - libproxy_inc = include_directories('.') libproxy_sources = [] @@ -30,7 +28,7 @@ if cc.has_multi_link_arguments(vscript) vflag += vscript endif -libproxy_lib = shared_library( +libproxy = shared_library( 'proxy', libproxy_sources, include_directories: px_backend_inc, @@ -43,7 +41,7 @@ libproxy_lib = shared_library( libproxy_dep = declare_dependency ( include_directories: libproxy_inc, - link_with: libproxy_lib, + link_with: libproxy, dependencies: libproxy_deps ) @@ -51,7 +49,7 @@ install_headers(libproxy_headers, subdir: 'libproxy') pkg = import('pkgconfig') pkg.generate( - libraries: [libproxy_lib], + libraries: [libproxy], subdirs: 'libproxy', version: meson.project_version(), name: 'libproxy', @@ -61,35 +59,37 @@ pkg.generate( install_dir: join_paths(get_option('libdir'), 'pkgconfig') ) -gnome = import('gnome') +if get_option('introspection') + gnome = import('gnome') -libproxy_gir_extra_args = [ - '--c-include=proxy.h', - '--quiet', -] + libproxy_gir_extra_args = [ + '--c-include=proxy.h', + '--quiet', + ] -libproxy_gir = gnome.generate_gir( - libproxy_lib, - sources: libproxy_headers + libproxy_sources, - nsversion: api_version, - namespace: 'Libproxy', - export_packages: package_api_name, - symbol_prefix: 'px', - identifier_prefix: 'px', - link_with: libproxy_lib, - 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() ], + 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, ) -endif + + 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 index 2ae6041..5c910a1 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -27,8 +27,6 @@ /** * SECTION:px-proxy * @short_description: A convient helper for using proxy servers - * - * Test 123 */ struct _pxProxyFactory { -- cgit v1.2.1 From f3c0d55c5964696937cc3281de22a7a2f9aa65c8 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 12 Mar 2023 00:02:31 +0100 Subject: Improve non http proxy tests (#72) --- src/backend/px-manager.c | 16 +++++----------- tests/data/px-manager-sample.pac | 12 ++++++++++++ tests/px-manager-test.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 51669cb..f2c0a2c 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -56,7 +56,6 @@ struct _PxManager { CURL *curl; #endif char *plugins_dir; - GCancellable *cancellable; char *config_plugin; char *config_option; @@ -142,8 +141,8 @@ px_manager_constructed (GObject *object) self->pac_data = NULL; self->network_monitor = g_network_monitor_get_default (); - self->online = g_network_monitor_get_network_available (self->network_monitor); 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__); } @@ -153,11 +152,6 @@ px_manager_dispose (GObject *object) PxManager *self = PX_MANAGER (object); const GList *list; - if (self->cancellable) { - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); - } - list = peas_engine_get_plugin_list (self->engine); for (; list && list->data; list = list->next) { PeasPluginInfo *info = PEAS_PLUGIN_INFO (list->data); @@ -446,14 +440,14 @@ px_manager_run_pac (PeasExtensionSet *set, if (g_ascii_strncasecmp (method, "proxy", 5) == 0) { proxy_string = g_uri_to_string (uri); - } else if (g_ascii_strncasecmp (method, "socks", 5) == 0) { - proxy_string = g_strconcat ("socks://", server, NULL); - } else if (g_ascii_strncasecmp (method, "socks4", 6) == 0) { - proxy_string = g_strconcat ("socks4://", server, NULL); } 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); } g_strv_builder_add (pac_data->builder, proxy_string); diff --git a/tests/data/px-manager-sample.pac b/tests/data/px-manager-sample.pac index b86c555..335c6b8 100644 --- a/tests/data/px-manager-sample.pac +++ b/tests/data/px-manager-sample.pac @@ -2,5 +2,17 @@ function FindProxyForURL(url, host) { var myIP = myIpAddress(); + if(shExpMatch(host,"192.168.10.4")) + return "SOCKS 127.0.0.1:1983" + + if(shExpMatch(host,"192.168.10.5")) + return "SOCKS4 127.0.0.1:1983" + + if(shExpMatch(host,"192.168.10.6")) + return "SOCKS4A 127.0.0.1:1983" + + if(shExpMatch(host,"192.168.10.7")) + return "SOCKS5 127.0.0.1:1983" + return "PROXY 127.0.0.1:1983" } diff --git a/tests/px-manager-test.c b/tests/px-manager-test.c index 85936c8..c5d0bf3 100644 --- a/tests/px-manager-test.c +++ b/tests/px-manager-test.c @@ -140,6 +140,22 @@ get_proxies_pac (gpointer data) 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; -- cgit v1.2.1 From 5de6dc8ff556e61ba23cfd21a6e5dca74a9fbaa1 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 12 Mar 2023 09:44:51 +0100 Subject: Fix codecov link (#74) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8ad509..85b65cb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) -[![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://codecov.io/github/janbrummer/libproxy2) +[![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://app.codecov.io/github/janbrummer/libproxy2) [![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml) # Libproxy -- cgit v1.2.1 From 8aed359ca37c0fbdc020b144428222bffa7de4ac Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 12 Mar 2023 10:28:45 +0100 Subject: Add initial libproxy test (#75) --- src/libproxy/meson.build | 28 ++++++++++++++++--- src/libproxy/proxy.c | 8 +----- tests/libproxy-test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 10 +++++++ 4 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 tests/libproxy-test.c diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index 873b184..ce50e85 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -2,15 +2,18 @@ libproxy_inc = include_directories('.') libproxy_sources = [] -if build_dbus -libproxy_sources += [ +libproxy_dbus_sources = [ 'proxy-dbus.c', ] -else -libproxy_sources += [ +libproxy_non_dbus_sources = [ 'proxy.c', ] + +if build_dbus + libproxy_sources += libproxy_dbus_sources +else + libproxy_sources += libproxy_non_dbus_sources endif libproxy_headers = [ @@ -45,6 +48,23 @@ libproxy_dep = declare_dependency ( dependencies: libproxy_deps ) +libproxy_test = shared_library( + 'proxy_test', + libproxy_non_dbus_sources, + include_directories: px_backend_inc, + dependencies: libproxy_deps, + link_args : vflag, + link_depends : mapfile, + soversion: '1', + install: false, +) + +libproxy_test_dep = declare_dependency ( + include_directories: libproxy_inc, + link_with: libproxy_test, + dependencies: libproxy_deps +) + install_headers(libproxy_headers, subdir: 'libproxy') pkg = import('pkgconfig') diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c index 5c910a1..6a60d6b 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -31,7 +31,6 @@ struct _pxProxyFactory { PxManager *manager; - GCancellable *cancellable; }; pxProxyFactory *px_proxy_factory_copy (pxProxyFactory *self); @@ -52,7 +51,6 @@ px_proxy_factory_new (void) { pxProxyFactory *self = g_new0 (pxProxyFactory, 1); - self->cancellable = g_cancellable_new (); self->manager = px_manager_new (); return self; @@ -72,10 +70,8 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, g_autoptr (GError) error = NULL; result = px_manager_get_proxies_sync (self->manager, url, &error); - if (!result) { + if (error) g_warning ("Could not query proxy: %s", error ? error->message : ""); - return NULL; - } return g_steal_pointer (&result); } @@ -95,8 +91,6 @@ px_proxy_factory_free_proxies (char **proxies) void px_proxy_factory_free (pxProxyFactory *self) { - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); g_clear_object (&self->manager); g_clear_pointer (&self, g_free); } diff --git a/tests/libproxy-test.c b/tests/libproxy-test.c new file mode 100644 index 0000000..05e05b3 --- /dev/null +++ b/tests/libproxy-test.c @@ -0,0 +1,71 @@ +/* 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 + +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); + + 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 index 23a7e91..3fa6e5a 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -7,6 +7,16 @@ if get_option('tests') test_cargs = ['-UG_DISABLE_ASSERT'] + libproxy_test = executable('test-libproxy', + ['libproxy-test.c'], + include_directories: libproxy_inc, + dependencies: [libproxy_test_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'], -- cgit v1.2.1 From 0a5e434eaf81dfdd9d4d3895de71a70efa4f5687 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Sun, 12 Mar 2023 10:39:51 +0100 Subject: Use names in test pac file (#73) --- tests/data/px-manager-sample.pac | 19 ++++++++++++++----- tests/px-manager-test.c | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/data/px-manager-sample.pac b/tests/data/px-manager-sample.pac index 335c6b8..d623f22 100644 --- a/tests/data/px-manager-sample.pac +++ b/tests/data/px-manager-sample.pac @@ -1,18 +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")) + if (shExpMatch(host, "192.168.10.4")) return "SOCKS 127.0.0.1:1983" - if(shExpMatch(host,"192.168.10.5")) + if (dnsDomainIs(host, "192.168.10.5")) return "SOCKS4 127.0.0.1:1983" - if(shExpMatch(host,"192.168.10.6")) + if (dnsDomainIs(host, "192.168.10.6")) return "SOCKS4A 127.0.0.1:1983" - if(shExpMatch(host,"192.168.10.7")) + if (dnsDomainIs(host, "192.168.10.7")) return "SOCKS5 127.0.0.1:1983" - return "PROXY 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/px-manager-test.c b/tests/px-manager-test.c index c5d0bf3..1b1eb06 100644 --- a/tests/px-manager-test.c +++ b/tests/px-manager-test.c @@ -221,3 +221,4 @@ main (int argc, return g_test_run (); } + -- cgit v1.2.1 From b240563f1beabf394461b135809059f24bcba285 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 13 Mar 2023 09:57:08 +0100 Subject: Coverage: Ignore tests and tools (#76) --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6ab87c2..4712fbe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,9 @@ jobs: path: ./build/docs/libproxy-1.0/ - name: CodeCov uses: codecov/codecov-action@v3 + ignore: + - tests + - src/tools build-linux-dbus: runs-on: ubuntu-latest -- cgit v1.2.1 From a47e6612490173493e1aceed0876f7ebc8c73bcf Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 13 Mar 2023 10:17:35 +0100 Subject: Update build.yml (#77) --- .github/workflows/build.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4712fbe..236a783 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,9 +36,6 @@ jobs: path: ./build/docs/libproxy-1.0/ - name: CodeCov uses: codecov/codecov-action@v3 - ignore: - - tests - - src/tools build-linux-dbus: runs-on: ubuntu-latest @@ -141,4 +138,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1 \ No newline at end of file + uses: actions/deploy-pages@v1 -- cgit v1.2.1 From 051fc8b6124486d1f589bc5feca1e207bc9c4cfc Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 13 Mar 2023 11:34:54 +0100 Subject: Add codecov.yml (#78) --- codecov.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 codecov.yml 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 -- cgit v1.2.1 From d196bd7418dfe9437871fa44d9418dd7fd57de07 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 13 Mar 2023 18:37:57 +0100 Subject: Fix return value for invalid pac file (#82) Return direct:// in case there is an issue with pac/wpad instead of returning config url. Fixes: https://github.com/janbrummer/libproxy2/issues/80 --- src/backend/px-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index f2c0a2c..618d9fe 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -567,7 +567,7 @@ px_manager_get_proxies_sync (PxManager *self, .builder = builder, }; peas_extension_set_foreach (self->pacrunner_set, px_manager_run_pac, &pac_data); - } else if (!g_str_has_prefix (g_uri_get_scheme (conf_url), "wpad")) { + } else if (!g_str_has_prefix (g_uri_get_scheme (conf_url), "wpad") && !g_str_has_prefix (g_uri_get_scheme (conf_url), "pac+")) { g_strv_builder_add (builder, g_uri_to_string (conf_url)); } } -- cgit v1.2.1 From cbf54f9f938323c1695a19a8cb81f82342008e5b Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 03:02:01 -0400 Subject: Add dbus system service (#83) In cases where we are switchting users which are not allowed or are using a non graphical shell dbus user session will not work. User session are bound to xauthority and display environment variables. In those cases fallback to a system session running as specified user (default=root). Fixes: https://github.com/janbrummer/libproxy2/issues/79 Co-authored-by: Jan-Michael Brummer --- meson_options.txt | 11 ++++- src/backend/dbus/dbus.c | 38 +++++++++++++++-- src/backend/dbus/meson.build | 49 ++++++++++------------ .../dbus/org.libproxy.proxy-system.service.in | 4 ++ src/backend/dbus/org.libproxy.proxy.service.in | 2 +- src/backend/dbus/proxyd.service.in | 14 ------- src/libproxy/proxy-dbus.c | 14 +++++++ src/tools/proxy.c | 6 +-- 8 files changed, 89 insertions(+), 49 deletions(-) create mode 100644 src/backend/dbus/org.libproxy.proxy-system.service.in delete mode 100644 src/backend/dbus/proxyd.service.in diff --git a/meson_options.txt b/meson_options.txt index 04389b9..2927b76 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -16,7 +16,14 @@ option( 'dbus', type: 'feature', value: 'auto', - description: 'Whether to build dbus service' + description: 'Whether to build D-Bus service' +) + +option( + 'dbus-system-user', + type: 'string', + value: 'root', + description: 'Which user should be used on D-Bus system session' ) option( @@ -87,4 +94,4 @@ option( type: 'boolean', value: true, description: 'Whether to build introspection support' -) \ No newline at end of file +) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index a04c0f9..645b5e9 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -124,7 +124,8 @@ on_name_lost (GDBusConnection *connection, g_warning ("Can't connect proxy bus"); g_main_loop_quit (user_data); } else { - g_error ("Unknown name lost error"); + g_warning ("Unknown name lost error"); + g_main_loop_quit (user_data); } } @@ -133,12 +134,43 @@ main (int argc, char **argv) { GMainLoop *loop; + GBusNameOwnerFlags flags; + gboolean replace; + gboolean use_system; + GOptionContext *context; + g_autoptr (GError) error = NULL; + const GOptionEntry options[] = { + { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, + { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system session.", NULL }, + { NULL } + }; + + replace = FALSE; + use_system = FALSE; + + context = g_option_context_new (""); + g_option_context_set_summary (context, "Libproxy D-Bus Service"); + g_option_context_add_main_entries (context, options, "libproxy"); + + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_printerr ("%s: %s", g_get_application_name (), error->message); + g_printerr ("\n"); + g_printerr ("Try \"%s --help\" for more information.", + g_get_prgname ()); + g_printerr ("\n"); + g_option_context_free (context); + return 1; + } loop = g_main_loop_new (NULL, FALSE); - g_bus_own_name (G_BUS_TYPE_SESSION, + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; + if (replace) + flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; + + g_bus_own_name (use_system ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, "org.libproxy.proxy", - G_BUS_NAME_OWNER_FLAGS_NONE, + flags, on_bus_acquired, NULL, on_name_lost, diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build index eb64fcd..250a105 100644 --- a/src/backend/dbus/meson.build +++ b/src/backend/dbus/meson.build @@ -4,13 +4,10 @@ if build_dbus unitdir = '' dbus_data_dir = join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1') dbus_interfaces_dir = join_paths(dbus_data_dir, 'interfaces') - dbus_services_dir = join_paths(dbus_data_dir, 'services') - dbus_sysconf_dir = join_paths(dbus_data_dir, 'session.d') - - systemd = dependency('systemd', required: false) - if systemd.found() - unitdir = systemd.get_variable(pkgconfig: 'systemduserunitdir') - endif + dbus_user_services_dir = join_paths(dbus_data_dir, 'services') + dbus_system_services_dir = join_paths(dbus_data_dir, 'system-services') + dbus_user_conf_dir = join_paths(dbus_data_dir, 'session.d') + dbus_system_conf_dir = join_paths(dbus_data_dir, 'system.d') px_interface = [ 'org.libproxy.proxy.xml' @@ -59,29 +56,29 @@ if build_dbus install: true, ) - service_data = configuration_data() - service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + # D-Bus Interface + install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) - dbus_service = configure_file( + # D-Bus User Service + user_service_data = configuration_data() + user_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + dbus_user_service = configure_file( input: 'org.libproxy.proxy.service.in', output: 'org.libproxy.proxy.service', - configuration: service_data + configuration: user_service_data ) + install_data(dbus_user_service, install_dir : dbus_user_services_dir) + install_data('org.libproxy.proxy.conf', install_dir : dbus_user_conf_dir) - install_data('org.libproxy.proxy.conf', install_dir : dbus_sysconf_dir) - install_data(dbus_service, install_dir : dbus_services_dir) - install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) - - service_data = configuration_data() - service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - - service = configure_file( - input: 'proxyd.service.in', - output: 'proxyd.service', - configuration: service_data + # D-Bus System Service + system_service_data = configuration_data() + system_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + system_service_data.set('USER', get_option('dbus-system-user')) + dbus_system_service = configure_file( + input: 'org.libproxy.proxy-system.service.in', + output: 'org.libproxy.proxy-system.service', + configuration: system_service_data ) - - if unitdir != '' - install_data(service, install_dir: unitdir) - endif + install_data(dbus_system_service, rename : 'org.libproxy.proxy.service', install_dir : dbus_system_services_dir) + install_data('org.libproxy.proxy.conf', install_dir : dbus_system_conf_dir) endif diff --git a/src/backend/dbus/org.libproxy.proxy-system.service.in b/src/backend/dbus/org.libproxy.proxy-system.service.in new file mode 100644 index 0000000..2af960b --- /dev/null +++ b/src/backend/dbus/org.libproxy.proxy-system.service.in @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.libproxy.proxy +Exec=@LIBEXECDIR@/proxyd --system +User=@USER@ diff --git a/src/backend/dbus/org.libproxy.proxy.service.in b/src/backend/dbus/org.libproxy.proxy.service.in index e958cd2..d1ac5f4 100644 --- a/src/backend/dbus/org.libproxy.proxy.service.in +++ b/src/backend/dbus/org.libproxy.proxy.service.in @@ -1,3 +1,3 @@ [D-BUS Service] Name=org.libproxy.proxy -Exec=@LIBEXECDIR@/proxyd \ No newline at end of file +Exec=@LIBEXECDIR@/proxyd diff --git a/src/backend/dbus/proxyd.service.in b/src/backend/dbus/proxyd.service.in deleted file mode 100644 index 038e86d..0000000 --- a/src/backend/dbus/proxyd.service.in +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Libproxy user service - -[Service] -Type=dbus -BusName=org.libproxy.proxy -ExecStart=@LIBEXECDIR@/proxyd -#Environment="G_MESSAGES_DEBUG=all" - -MemoryDenyWriteExecute=yes -PrivateTmp=yes -ProtectHome=yes -ProtectSystem=full -RestrictRealtime=yes \ No newline at end of file diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 1587c73..6b594e3 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -73,6 +73,20 @@ px_proxy_factory_new (void) "org.libproxy.proxy", self->cancellable, /* GCancellable */ &error); + + if (!self->proxy) { + g_clear_error (&error); + + self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.libproxy.proxy", + "/org/libproxy/proxy", + "org.libproxy.proxy", + self->cancellable, /* GCancellable */ + &error); + } + if (!self->proxy) g_warning ("Could not create libproxy dbus proxy: %s", error->message); diff --git a/src/tools/proxy.c b/src/tools/proxy.c index 2d46578..2561265 100644 --- a/src/tools/proxy.c +++ b/src/tools/proxy.c @@ -54,7 +54,7 @@ print_proxies (char **proxies) return; } - for (j = 0; proxies[j] ; j++) + for (j = 0; proxies[j]; j++) printf ("%s%s", proxies[j], proxies[j + 1] ? " " : "\n"); } @@ -74,7 +74,7 @@ main (int argc, } /* User entered some arguments on startup. skip interactive */ if (argc > 1) { - for (i = 1; i < argc ; i++) { + 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 @@ -88,7 +88,7 @@ main (int argc, /* Interactive mode */ else { /* For each URL we read on STDIN, get the proxies to use */ - for (url[0] = '\0' ; fgets (url, 102400, stdin) != NULL ; ) { + for (url[0] = '\0'; fgets (url, 102400, stdin) != NULL;) { if (url[strlen (url) - 1] == '\n') url[strlen (url) - 1] = '\0'; /* -- cgit v1.2.1 From 98187d7567e333b4b0f8fbb199b39bb5eb096dda Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 05:04:34 -0400 Subject: Add architecture documentation (#85) Fixes: https://github.com/janbrummer/libproxy2/issues/34 Co-authored-by: Jan-Michael Brummer --- docs/architecture.md | 33 +++++++++++++++++++++++++++++++++ docs/meson.build | 1 + docs/px.toml.in | 3 ++- subprojects/gi-docgen.wrap | 10 ++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 docs/architecture.md create mode 100644 subprojects/gi-docgen.wrap diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..9da4938 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,33 @@ +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 +- D-Bus Service + +Using D-Bus as a service on Linux we can elimnate the previous ABI clashes we +have had in the past. mozjs in different versions on one system could lead to +crashes in cases where the application using libproxy favours a different mozjs +version. + +## Building Libproxy as simple library + +On non D-Bus system you still have the option to build Libproxy as a self +contained library using `-Ddbus=disabled`. In this case you can still run into +an ABI issue, but with it's current plugins it is unlikely at the moment. + +## Building Libproxy as D-Bus Service +On D-Bus system Libproxy will be build using a D-Bus service and a simple +helper library. The main logic part (previous simple library) is done in the +D-Bus service and so can never crash an application. +The application itself will be linked with the helper library which does the +necessary D-Bus calls and wait's for answer. diff --git a/docs/meson.build b/docs/meson.build index 09263c5..3aac92a 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -1,6 +1,7 @@ if get_option('docs') expand_content_md_files = [ + 'architecture.md', 'configuration-logic.md', 'perl.md', 'python.md', diff --git a/docs/px.toml.in b/docs/px.toml.in index 740419b..79ed69b 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -61,6 +61,7 @@ file_format = "{filename}#L{line}" [extra] content_files = [ + "architecture.md", "configuration-logic.md", "perl.md", "python.md", @@ -70,4 +71,4 @@ content_files = [ content_images = [ "libproxy.svg" -] \ No newline at end of file +] 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 + -- cgit v1.2.1 From f20a56d73694ffcf37eccb6c8c31070def74aaba Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 08:57:25 -0400 Subject: Add file monitor support (#81) --- src/backend/plugins/config-kde/config-kde.c | 64 ++++++++++++++-------- .../plugins/config-sysconfig/config-sysconfig.c | 53 ++++++++++++++---- src/backend/plugins/config-sysconfig/meson.build | 2 +- 3 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 24fb9e1..1079c19 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -40,8 +40,9 @@ typedef enum { struct _PxConfigKde { GObject parent_instance; - char *config_option; + char *config_file; gboolean available; + GFileMonitor *monitor; char *no_proxy; char *http_proxy; @@ -62,9 +63,25 @@ enum { PROP_CONFIG_OPTION }; +static void px_config_kde_set_config_file (PxConfigKde *self, + char *proxy_file); + static void -px_config_kde_read_config (PxConfigKde *self, - char *proxy_file) +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; @@ -72,15 +89,19 @@ px_config_kde_read_config (PxConfigKde *self, g_autoptr (GFileInputStream) istr = NULL; g_autoptr (GDataInputStream) dstr = NULL; - file = g_file_new_for_path (proxy_file); + 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); + self->available = FALSE; + + file = g_file_new_for_path (self->config_file); if (!file) { - g_debug ("%s: Could not create file", __FUNCTION__); + 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", __FUNCTION__); + g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file); return; } @@ -88,6 +109,13 @@ px_config_kde_read_config (PxConfigKde *self, 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); @@ -122,25 +150,11 @@ px_config_kde_read_config (PxConfigKde *self, } } } while (line); -} - -static -void -px_config_kde_set_config_file (PxConfigKde *self, - const char *file) -{ - g_autofree char *config = NULL; - - g_clear_pointer (&self->config_option, g_free); - self->config_option = file ? g_strdup (file) : NULL; - config = self->config_option ? g_strdup (self->config_option) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL); - - self->available = g_file_test (config, G_FILE_TEST_EXISTS); - if (self->available) - px_config_kde_read_config (self, config); + self->available = TRUE; } + static void px_config_kde_init (PxConfigKde *self) { @@ -150,6 +164,10 @@ px_config_kde_init (PxConfigKde *self) static void px_config_kde_dispose (GObject *object) { + PxConfigKde *self = PX_CONFIG_KDE (object); + + g_clear_object (&self->monitor); + G_OBJECT_CLASS (px_config_kde_parent_class)->dispose (object); } @@ -182,7 +200,7 @@ px_config_kde_get_property (GObject *object, switch (prop_id) { case PROP_CONFIG_OPTION: - g_value_set_string (value, config->config_option); + g_value_set_string (value, config->config_file); break; default: diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index d7a1fa1..a7e7d47 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -28,9 +28,9 @@ struct _PxConfigSysConfig { GObject parent_instance; + GFileMonitor *monitor; - char *proxy_file; - char *config_option; + char *config_file; gboolean available; gboolean proxy_enabled; @@ -53,6 +53,22 @@ enum { 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, @@ -65,21 +81,19 @@ px_config_sysconfig_set_config_file (PxConfigSysConfig *self, g_autoptr (GDataInputStream) dstr = NULL; char *line = NULL; - g_clear_pointer (&self->config_option, g_free); - self->config_option = config_file ? g_strdup (config_file) : NULL; - - self->proxy_file = g_strdup (self->config_option ? self->config_option : "/etc/sysconfig/proxy"); + 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->proxy_file); + file = g_file_new_for_path (self->config_file); if (!file) { - g_debug ("%s: Could not create file", __FUNCTION__); + 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", __FUNCTION__); + g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file); return; } @@ -87,6 +101,13 @@ px_config_sysconfig_set_config_file (PxConfigSysConfig *self, 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); @@ -123,7 +144,6 @@ px_config_sysconfig_set_config_file (PxConfigSysConfig *self, static void px_config_sysconfig_init (PxConfigSysConfig *self) { - px_config_sysconfig_set_config_file (self, NULL); } static void @@ -155,7 +175,7 @@ px_config_sysconfig_get_property (GObject *object, switch (prop_id) { case PROP_CONFIG_OPTION: - g_value_set_string (value, config->config_option); + g_value_set_string (value, config->config_file); break; default: @@ -164,11 +184,22 @@ px_config_sysconfig_get_property (GObject *object, } } +static void +px_config_sysconfig_dispose (GObject *object) +{ + PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (object); + + g_clear_object (&self->monitor); + + 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; diff --git a/src/backend/plugins/config-sysconfig/meson.build b/src/backend/plugins/config-sysconfig/meson.build index 2ac17fb..1aef00b 100644 --- a/src/backend/plugins/config-sysconfig/meson.build +++ b/src/backend/plugins/config-sysconfig/meson.build @@ -32,4 +32,4 @@ custom_target( install: true, ) -endif \ No newline at end of file +endif -- cgit v1.2.1 From 1684613c6126da710d8ed439f87b595f1ac31917 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 09:05:37 -0400 Subject: Add a duplicate check for proxy arrays (#87) Co-authored-by: Jan-Michael Brummer --- src/backend/plugins/config-env/config-env.c | 2 +- src/backend/plugins/config-gnome/config-gnome.c | 5 +++-- src/backend/plugins/config-kde/config-kde.c | 2 +- src/backend/plugins/config-osx/config-osx.c | 10 +++++----- .../plugins/config-sysconfig/config-sysconfig.c | 2 +- .../plugins/config-windows/config-windows.c | 10 +++++----- src/backend/px-manager.c | 22 +++++++++++++++++----- src/backend/px-manager.h | 3 +++ 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index af13de6..397fdd9 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -156,7 +156,7 @@ px_config_env_get_config (PxConfig *config, proxy = self->http_proxy; if (proxy) - g_strv_builder_add (builder, proxy); + px_strv_builder_add_proxy (builder, proxy); } static void diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index 0041c1b..e8a58ab 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -24,6 +24,7 @@ #include "config-gnome.h" #include "px-plugin-config.h" +#include "px-manager.h" struct _PxConfigGnome { GObject parent_instance; @@ -156,7 +157,7 @@ store_response (GStrvBuilder *builder, g_string_append_printf (tmp, "%s:%d", host, port); - g_strv_builder_add (builder, tmp->str); + px_strv_builder_add_proxy (builder, tmp->str); } } @@ -178,7 +179,7 @@ px_config_gnome_get_config (PxConfig *config, else proxy = g_strdup ("wpad://"); - g_strv_builder_add (builder, proxy); + 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"); diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 1079c19..f30a130 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -269,7 +269,7 @@ px_config_kde_get_config (PxConfig *config, } if (proxy) - g_strv_builder_add (builder, proxy); + px_strv_builder_add_proxy (builder, proxy); } static void diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index 08b87c3..f733c93 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -229,11 +229,11 @@ get_ignore_list (CFDictionaryRef proxies) for (int idx = 0; idx < CFArrayGetCount (ref); idx++) { CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex (ref, idx); - g_strv_builder_add (ret, str (s)); + px_strv_builder_add_proxy (ret, str (s)); } if (getbool (proxies, "ExcludeSimpleHostnames")) - g_strv_builder_add (ret, "127.0.0.1"); + px_strv_builder_add_proxy (ret, "127.0.0.1"); return g_strv_builder_end (ret); } @@ -259,7 +259,7 @@ px_config_osx_get_config (PxConfig *self, if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { CFRelease (proxies); - g_strv_builder_add (builder, "wpad://"); + px_strv_builder_add_proxy (builder, "wpad://"); return; } @@ -271,7 +271,7 @@ px_config_osx_get_config (PxConfig *self, if (tmp_uri) { g_autofree char *ret = g_strdup_printf ("pac+%s", g_uri_to_string (tmp_uri)); CFRelease (proxies); - g_strv_builder_add (builder, ret); + px_strv_builder_add_proxy (builder, ret); return; } } else { @@ -288,7 +288,7 @@ px_config_osx_get_config (PxConfig *self, } if (proxy) - g_strv_builder_add (builder, proxy); + px_strv_builder_add_proxy (builder, proxy); } static void diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index a7e7d47..1f90a44 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -238,7 +238,7 @@ px_config_sysconfig_get_config (PxConfig *config, } if (proxy) - g_strv_builder_add (builder, proxy); + px_strv_builder_add_proxy (builder, proxy); } static void diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index c8bc94d..b623c2d 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -167,7 +167,7 @@ px_config_windows_get_config (PxConfig *self, /* WPAD */ if (is_enabled (W32REG_OFFSET_WPAD)) { - g_strv_builder_add (builder, "wpad://"); + px_strv_builder_add_proxy (builder, "wpad://"); return; } @@ -177,7 +177,7 @@ px_config_windows_get_config (PxConfig *self, GUri *ac_uri = g_uri_parse (tmp, G_URI_FLAGS_PARSE_RELAXED, NULL); if (ac_uri) { - g_strv_builder_add (builder, pac_uri); + px_strv_builder_add_proxy (builder, pac_uri); return; } } @@ -190,19 +190,19 @@ px_config_windows_get_config (PxConfig *self, if (table) { char *ret = g_hash_table_lookup (table, scheme); if (ret) { - g_strv_builder_add (builder, ret); + px_strv_builder_add_proxy (builder, ret); return; } ret = g_hash_table_lookup (table, "http"); if (ret) { - g_strv_builder_add (builder, ret); + px_strv_builder_add_proxy (builder, ret); return; } ret = g_hash_table_lookup (table, "socks"); if (ret) { - g_strv_builder_add (builder, ret); + px_strv_builder_add_proxy (builder, ret); return; } } diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 618d9fe..1e3bcb0 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -450,10 +450,10 @@ px_manager_run_pac (PeasExtensionSet *set, proxy_string = g_strconcat ("socks://", server, NULL); } - g_strv_builder_add (pac_data->builder, proxy_string); + px_strv_builder_add_proxy (pac_data->builder, proxy_string); } else { /* Syntax not found, returning direct */ - g_strv_builder_add (pac_data->builder, "direct://"); + px_strv_builder_add_proxy (pac_data->builder, "direct://"); } } } @@ -549,7 +549,7 @@ px_manager_get_proxies_sync (PxManager *self, g_debug ("%s: url=%s online=%d", __FUNCTION__, url ? url : "?", self->online); if (!uri || !self->online) { - g_strv_builder_add (builder, "direct://"); + px_strv_builder_add_proxy (builder, "direct://"); return g_strv_builder_end (builder); } @@ -568,16 +568,28 @@ px_manager_get_proxies_sync (PxManager *self, }; peas_extension_set_foreach (self->pacrunner_set, px_manager_run_pac, &pac_data); } else if (!g_str_has_prefix (g_uri_get_scheme (conf_url), "wpad") && !g_str_has_prefix (g_uri_get_scheme (conf_url), "pac+")) { - g_strv_builder_add (builder, g_uri_to_string (conf_url)); + 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) - g_strv_builder_add (builder, "direct://"); + 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 (strcmp ((char *)((GPtrArray *)builder)->pdata[idx], value) == 0) + return; + } + + g_strv_builder_add (builder, value); +} diff --git a/src/backend/px-manager.h b/src/backend/px-manager.h index 486fb51..2bb816b 100644 --- a/src/backend/px-manager.h +++ b/src/backend/px-manager.h @@ -51,4 +51,7 @@ char **px_manager_get_configuration (PxManager *self, GUri *uri, GError **error); +void px_strv_builder_add_proxy (GStrvBuilder *builder, + const char *value); + G_END_DECLS -- cgit v1.2.1 From f5d530c0badcce82b718b66e7ef0cfe251350b54 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 09:24:25 -0400 Subject: Add inactivity timeout to d-bus service (#86) Switch to GApplication and set an inactivity timer so that the service will be cancelled after a timeout period of 60s. Co-authored-by: Jan-Michael Brummer --- src/backend/dbus/dbus.c | 79 +++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 645b5e9..200e5c0 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -24,6 +24,17 @@ #include +static gboolean replace; +static gboolean use_system; + +static GApplication *app; + +const GOptionEntry options[] = { + { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, + { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system session.", NULL }, + { NULL } +}; + static void handle_method_call (GDBusConnection *connection, const gchar *sender, @@ -41,12 +52,14 @@ handle_method_call (GDBusConnection *connection, const gchar *url; int idx; + g_application_hold (app); if (g_strcmp0 (method_name, "query") != 0) { g_warning ("Invalid method name '%s', aborting.", method_name); g_dbus_method_invocation_return_error (invocation, PX_MANAGER_ERROR, PX_MANAGER_ERROR_UNKNOWN_METHOD, "Unknown method"); + g_application_release (app); return; } @@ -56,6 +69,7 @@ handle_method_call (GDBusConnection *connection, if (error) { g_warning ("Could not query proxy servers: %s", error->message); g_dbus_method_invocation_return_gerror (invocation, error); + g_application_release (app); return; } @@ -68,6 +82,7 @@ handle_method_call (GDBusConnection *connection, g_dbus_method_invocation_return_value (invocation, g_variant_new ("(as)", result)); + g_application_release (app); } static GVariant * @@ -108,9 +123,11 @@ on_bus_acquired (GDBusConnection *connection, manager, g_object_unref, &error); + g_application_release (user_data); + if (error) { g_warning ("Could not register dbus object: %s", error->message); - g_main_loop_quit (user_data); + g_application_quit (user_data); return; } } @@ -122,28 +139,40 @@ on_name_lost (GDBusConnection *connection, { if (!connection) { g_warning ("Can't connect proxy bus"); - g_main_loop_quit (user_data); + g_application_quit (user_data); } else { g_warning ("Unknown name lost error"); - g_main_loop_quit (user_data); + g_application_quit (user_data); } } +static void +activate (GApplication *application) +{ + GBusNameOwnerFlags flags; + + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; + if (replace) + flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; + + g_bus_own_name (use_system ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, + "org.libproxy.proxy", + flags, + on_bus_acquired, + NULL, + on_name_lost, + app, + NULL); + + g_application_hold (app); +} + int main (int argc, char **argv) { - GMainLoop *loop; - GBusNameOwnerFlags flags; - gboolean replace; - gboolean use_system; GOptionContext *context; g_autoptr (GError) error = NULL; - const GOptionEntry options[] = { - { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, - { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system session.", NULL }, - { NULL } - }; replace = FALSE; use_system = FALSE; @@ -162,22 +191,16 @@ main (int argc, return 1; } - loop = g_main_loop_new (NULL, FALSE); - - flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; - if (replace) - flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; - - g_bus_own_name (use_system ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, - "org.libproxy.proxy", - flags, - on_bus_acquired, - NULL, - on_name_lost, - loop, - NULL); + app = g_application_new ("org.libproxy.proxy-service", +#if GLIB_CHECK_VERSION (2, 73, 0) + G_APPLICATION_DEFAULT_FLAGS +#else + G_APPLICATION_FLAGS_NONE +#endif + ); - g_main_loop_run (loop); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + g_application_set_inactivity_timeout (app, 60000); - return 0; + return g_application_run (app, argc, argv); } -- cgit v1.2.1 From 7f19836b39ab8b14da1b2e2d2bbae9b357090741 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 10:33:11 -0400 Subject: Handle invalid GNOME configuration (#89) Fixes: https://github.com/janbrummer/libproxy2/issues/88 Co-authored-by: Jan-Michael Brummer --- src/backend/plugins/config-gnome/config-gnome.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index e8a58ab..a41f54d 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -148,7 +148,7 @@ store_response (GStrvBuilder *builder, char *username, char *password) { - if (type && host && port != 0) { + if (type && host && strlen (type) > 0 && strlen (host) > 0 && port != 0) { g_autoptr (GString) tmp = g_string_new (type); g_string_append (tmp, "://"); @@ -223,6 +223,17 @@ px_config_gnome_get_config (PxConfig *config, username, password); } + + if ((((GPtrArray *)builder)->len == 0) && (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); + } } } -- cgit v1.2.1 From 5114d4714254d47c7ab32559c4a480e101609a5d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 10:46:04 -0400 Subject: Add repology badges (#90) Co-authored-by: Jan-Michael Brummer --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 85b65cb..0165909 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,19 @@ It doesn't matter! Just ask libproxy what proxy to use: you get simple code and - 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 + +[![Arch package](https://repology.org/badge/version-for-repo/arch/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Debian 12 package](https://repology.org/badge/version-for-repo/debian_12/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Fedora 37 package](https://repology.org/badge/version-for-repo/fedora_37/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Fedora Rawhide package](https://repology.org/badge/version-for-repo/fedora_rawhide/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![FreeBSD port](https://repology.org/badge/version-for-repo/freebsd/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Gentoo package](https://repology.org/badge/version-for-repo/gentoo/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Homebrew package](https://repology.org/badge/version-for-repo/homebrew/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Manjaro Stable package](https://repology.org/badge/version-for-repo/manjaro_stable/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![MSYS2 mingw package](https://repology.org/badge/version-for-repo/msys2_mingw/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![openSUSE Leap 15.5 package](https://repology.org/badge/version-for-repo/opensuse_leap_15_5/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![openSUSE Tumbleweed package](https://repology.org/badge/version-for-repo/opensuse_tumbleweed/libproxy.svg)](https://repology.org/project/libproxy/versions) +[![Ubuntu 23.04 package](https://repology.org/badge/version-for-repo/ubuntu_23_04/libproxy.svg)](https://repology.org/project/libproxy/versions) + -- cgit v1.2.1 From f71f6f4d6998ebfd30db4a78cc2843a735d5c059 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 11:06:28 -0400 Subject: Add build step tutorial (#91) Co-authored-by: Jan-Michael Brummer --- docs/build-steps.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ docs/meson.build | 1 + docs/px.toml.in | 1 + 3 files changed, 86 insertions(+) create mode 100644 docs/build-steps.md diff --git a/docs/build-steps.md b/docs/build-steps.md new file mode 100644 index 0000000..fa3f187 --- /dev/null +++ b/docs/build-steps.md @@ -0,0 +1,84 @@ +Title: How to compile libproxy +Slug: building + +# How to compile libproxy + +## Fedora + +### Dependencies + +``` +sudo dnf install glib2-devel duktape-devel libsoup3-devel meson gcovr gi-docgen libpeas-devel 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 libpeas 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-libpeas 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/meson.build b/docs/meson.build index 3aac92a..cc5d1ad 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -2,6 +2,7 @@ if get_option('docs') expand_content_md_files = [ 'architecture.md', + 'build-steps.md', 'configuration-logic.md', 'perl.md', 'python.md', diff --git a/docs/px.toml.in b/docs/px.toml.in index 79ed69b..b70f23b 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -62,6 +62,7 @@ file_format = "{filename}#L{line}" [extra] content_files = [ "architecture.md", + "build-steps.md", "configuration-logic.md", "perl.md", "python.md", -- cgit v1.2.1 From 572119488620826b0cdb5619cc64c67d4eba5f56 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 11:08:13 -0400 Subject: Add proxy authentication page (#92) Co-authored-by: Jan-Michael Brummer --- docs/proxy-authentication.md | 7 +++++++ docs/px.toml.in | 1 + 2 files changed, 8 insertions(+) create mode 100644 docs/proxy-authentication.md diff --git a/docs/proxy-authentication.md b/docs/proxy-authentication.md new file mode 100644 index 0000000..8b9669d --- /dev/null +++ b/docs/proxy-authentication.md @@ -0,0 +1,7 @@ +Title: What about Proxy Authentication? +Slug: ProxyAuthentication + + +# What about 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 index b70f23b..51bdbec 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -65,6 +65,7 @@ content_files = [ "build-steps.md", "configuration-logic.md", "perl.md", + "proxy-authentication.md", "python.md", "ruby.md", "vala.md", -- cgit v1.2.1 From 1bac2d2480c04f92265e7e90f6793a20370cdedf Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 11:32:23 -0400 Subject: Create release workflow (#94) --- .github/workflows/release.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/release.yml 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); + } -- cgit v1.2.1 From f7c0dcf17d8ff40c7f583825fc1e31c9987369ca Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Fri, 17 Mar 2023 12:26:15 -0400 Subject: Add application matrix (#93) Co-authored-by: Jan-Michael Brummer --- docs/applications.md | 26 ++++++++++++++++++++++++++ docs/meson.build | 1 + docs/px.toml.in | 1 + 3 files changed, 28 insertions(+) create mode 100644 docs/applications.md diff --git a/docs/applications.md b/docs/applications.md new file mode 100644 index 0000000..732e25d --- /dev/null +++ b/docs/applications.md @@ -0,0 +1,26 @@ +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 | - | +| hexchat | YES | - | +| libQt5Network | YES | - | +| libzypp | YES | - | +| Mozilla Firefox | YES | - | +| neon | YES | - | +| openconnect | YES | - | +| python-requests | NO | AVAILABLE | +| seamonkey | YES | - | +| signond | YES | - | +| signond_ui | YES | - | +| transmission-remote-gtk | YES | - | +| vagalume | YES | - | +| wget | NO | [Patch](https://build.opensuse.org/package/show/openSUSE:Factory/wget) | + diff --git a/docs/meson.build b/docs/meson.build index cc5d1ad..3c2fae9 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -2,6 +2,7 @@ if get_option('docs') expand_content_md_files = [ 'architecture.md', + 'applications.md', 'build-steps.md', 'configuration-logic.md', 'perl.md', diff --git a/docs/px.toml.in b/docs/px.toml.in index 51bdbec..c08c679 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -62,6 +62,7 @@ file_format = "{filename}#L{line}" [extra] content_files = [ "architecture.md", + "applications.md", "build-steps.md", "configuration-logic.md", "perl.md", -- cgit v1.2.1 From 8991f653f704b9236b94e640afed3ef0a882c1f3 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 20 Mar 2023 02:48:28 -0400 Subject: Update README.md (#95) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0165909..398994a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) [![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://app.codecov.io/github/janbrummer/libproxy2) -[![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml) +[![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://scan.coverity.com/projects/libproxy) # Libproxy libproxy is a library that provides automatic proxy configuration management. -- cgit v1.2.1 From 1c571b255b31119be8c000448c26e3b62a9e3ceb Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 20 Mar 2023 05:18:44 -0400 Subject: Fix coverity findings (#96) Co-authored-by: Jan-Michael Brummer --- src/backend/px-manager.c | 5 +++-- src/libproxy/proxy.c | 2 +- tests/config-gnome-test.c | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 1e3bcb0..69d94fd 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -102,7 +102,8 @@ px_manager_constructed (GObject *object) g_autofree char *new_g_messages_debug = NULL; new_g_messages_debug = g_strconcat (g_messages_debug, " ", G_LOG_DOMAIN, NULL); - g_setenv ("G_MESSAGES_DEBUG", new_g_messages_debug, TRUE); + if (new_g_messages_debug) + g_setenv ("G_MESSAGES_DEBUG", new_g_messages_debug, TRUE); } } @@ -587,7 +588,7 @@ px_strv_builder_add_proxy (GStrvBuilder *builder, const char *value) { for (int idx = 0; idx < ((GPtrArray *)builder)->len; idx++) { - if (strcmp ((char *)((GPtrArray *)builder)->pdata[idx], value) == 0) + if (g_strcmp0 ((char *)((GPtrArray *)builder)->pdata[idx], value) == 0) return; } diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c index 6a60d6b..278c0af 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -71,7 +71,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, result = px_manager_get_proxies_sync (self->manager, url, &error); if (error) - g_warning ("Could not query proxy: %s", error ? error->message : ""); + g_warning ("Could not query proxy: %s", error->message); return g_steal_pointer (&result); } diff --git a/tests/config-gnome-test.c b/tests/config-gnome-test.c index 73602ad..fc688bd 100644 --- a/tests/config-gnome-test.c +++ b/tests/config-gnome-test.c @@ -169,7 +169,10 @@ test_config_gnome_fail (Fixture *self, g_autoptr (GUri) uri = NULL; /* Disable GNOME support */ - g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE); + 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); -- cgit v1.2.1 From 5f5e1b80366945c596d6e4145292671b37890bc3 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 20 Mar 2023 05:34:49 -0400 Subject: Update Application matrix (#97) Co-authored-by: Jan-Michael Brummer --- docs/applications.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/applications.md b/docs/applications.md index 732e25d..79fe046 100644 --- a/docs/applications.md +++ b/docs/applications.md @@ -10,7 +10,6 @@ Slug: ApplicationMatrix | cURL | NO | AVAILABLE | | eid-viewer | YES | - | | glib-networking | YES | - | -| hexchat | YES | - | | libQt5Network | YES | - | | libzypp | YES | - | | Mozilla Firefox | YES | - | @@ -20,7 +19,6 @@ Slug: ApplicationMatrix | seamonkey | YES | - | | signond | YES | - | | signond_ui | YES | - | -| transmission-remote-gtk | YES | - | | vagalume | YES | - | | wget | NO | [Patch](https://build.opensuse.org/package/show/openSUSE:Factory/wget) | -- cgit v1.2.1 From c4f502756ebe286fba3f9aa50f17c421d0eed9c0 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 20 Mar 2023 06:15:54 -0400 Subject: Fix Libproxy documentation for non-dbus generation (#98) Co-authored-by: Jan-Michael Brummer --- src/libproxy/proxy-dbus.c | 96 ---------------------------------------------- src/libproxy/proxy.c | 17 -------- src/libproxy/proxy.h | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 113 deletions(-) diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 6b594e3..57acbd9 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -28,11 +28,6 @@ struct _pxProxyFactory { GCancellable *cancellable; }; -/** - * SECTION:px-proxy - * @short_description: A convient helper for using proxy servers - */ - pxProxyFactory *px_proxy_factory_copy (pxProxyFactory *self); G_DEFINE_BOXED_TYPE (pxProxyFactory, @@ -40,24 +35,12 @@ G_DEFINE_BOXED_TYPE (pxProxyFactory, (GBoxedCopyFunc)px_proxy_factory_copy, (GFreeFunc)px_proxy_factory_new); - pxProxyFactory * px_proxy_factory_copy (pxProxyFactory *self) { return g_memdup2 (self, sizeof (pxProxyFactory)); } -/** - * px_proxy_factory_new: - * - * 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. - * - * Returns: The newly created `pxProxyFactory` - */ pxProxyFactory * px_proxy_factory_new (void) { @@ -93,70 +76,6 @@ px_proxy_factory_new (void) return self; } -/** - * 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. - * 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. - * - * 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 (i.e. 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. - * - * 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 - * - * - ://[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. - * - * For SOCKS proxies, when the protocol version is specified (socks4:// or - * socks5://), it is expected that only this version is used. When only - * socks:// is set, the client MUST try SOCKS version 5 protocol and, on - * connection failure, fallback to SOCKS version 4. - * - * Other proxying protocols may exist. It is expected that the returned - * configuration scheme shall match the network service name of the - * 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. - * - * Returns: (transfer full): a list of proxies - */ char ** px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url) @@ -209,27 +128,12 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, return retval; } -/** - * 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) { g_clear_pointer (&proxies, g_strfreev); } -/** - * px_proxy_factory_free: - * @self: a #pxProxyFactory - * - * Frees the `pxProxyFactory`. - */ void px_proxy_factory_free (pxProxyFactory *self) { diff --git a/src/libproxy/proxy.c b/src/libproxy/proxy.c index 278c0af..6cf7974 100644 --- a/src/libproxy/proxy.c +++ b/src/libproxy/proxy.c @@ -24,11 +24,6 @@ #include "px-manager.h" #include "proxy.h" -/** - * SECTION:px-proxy - * @short_description: A convient helper for using proxy servers - */ - struct _pxProxyFactory { PxManager *manager; }; @@ -40,12 +35,6 @@ G_DEFINE_BOXED_TYPE (pxProxyFactory, (GBoxedCopyFunc)px_proxy_factory_copy, (GFreeFunc)px_proxy_factory_new); -/** - * px_proxy_factory_new: - * Creates a new proxy factory. - * - * Returns: pointer to #px_proxy_factory - */ pxProxyFactory * px_proxy_factory_new (void) { @@ -82,12 +71,6 @@ px_proxy_factory_free_proxies (char **proxies) g_clear_pointer (&proxies, g_strfreev); } -/** - * px_proxy_factory_free: - * @self: a px_proxy_factory - * - * Free px_proxy_factory - */ void px_proxy_factory_free (pxProxyFactory *self) { diff --git a/src/libproxy/proxy.h b/src/libproxy/proxy.h index 50f9944..cf4fc34 100644 --- a/src/libproxy/proxy.h +++ b/src/libproxy/proxy.h @@ -28,15 +28,113 @@ extern "C" { #include +/** + * 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. + * + * 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); + GType px_proxy_factory_get_type (void) G_GNUC_CONST; +/** + * 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. + * 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. + * + * 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 (i.e. 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. + * + * 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 + * + * - ://[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. + * + * For SOCKS proxies, when the protocol version is specified (socks4:// or + * socks5://), it is expected that only this version is used. When only + * socks:// is set, the client MUST try SOCKS version 5 protocol and, on + * connection failure, fallback to SOCKS version 4. + * + * Other proxying protocols may exist. It is expected that the returned + * configuration scheme shall match the network service name of the + * 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. + * + * Returns: (transfer full): a list of proxies + */ char **px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url); + +/** + * 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); + +/** + * px_proxy_factory_free: + * @self: a #pxProxyFactory + * + * Frees the `pxProxyFactory`. + */ void px_proxy_factory_free (pxProxyFactory *self); #ifdef __cplusplus -- cgit v1.2.1 From b365acbff1b8f01ae56e760470264cb66b39375a Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Mar 2023 02:07:05 -0400 Subject: Update README.md (#100) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 398994a..227bde4 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ It doesn't matter! Just ask libproxy what proxy to use: you get simple code and ## libproxy offers the following features: - support for all major platforms: Windows, Mac and Linux/UNIX - extremely small core footprint -- no external dependencies within libproxy core -- only 3 functions in the stable-ish external API +- 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 -- cgit v1.2.1 From 580fc41f58d1128f5c53ec276c28bad96ba03491 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Mar 2023 02:37:38 -0400 Subject: Update documentation (#102) Co-authored-by: Jan-Michael Brummer --- docs/build-steps.md | 4 ++-- docs/configuration-logic.md | 27 +++++++++++++-------------- docs/proxy-authentication.md | 4 ++-- docs/px.toml.in | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/build-steps.md b/docs/build-steps.md index fa3f187..f0ac5df 100644 --- a/docs/build-steps.md +++ b/docs/build-steps.md @@ -1,7 +1,7 @@ -Title: How to compile libproxy +Title: Build steps - How to compile libproxy Slug: building -# How to compile libproxy +# Build steps - How to compile libproxy ## Fedora diff --git a/docs/configuration-logic.md b/docs/configuration-logic.md index 342ef38..2229646 100644 --- a/docs/configuration-logic.md +++ b/docs/configuration-logic.md @@ -2,7 +2,6 @@ Title: Configuration Logic Slug: Design # Configuration Logic -Source: https://code.google.com/archive/p/libproxy/wikis/ConfigurationLogic.wiki ## Introduction As the proxy configuration predates libproxy, we need to consider previous @@ -38,11 +37,11 @@ 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 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 ``` @@ -64,14 +63,14 @@ 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 + 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 diff --git a/docs/proxy-authentication.md b/docs/proxy-authentication.md index 8b9669d..de7a905 100644 --- a/docs/proxy-authentication.md +++ b/docs/proxy-authentication.md @@ -1,7 +1,7 @@ -Title: What about Proxy Authentication? +Title: Proxy Authentication Slug: ProxyAuthentication -# What about Proxy Authentication? +# 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 index c08c679..1e7f88a 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -65,8 +65,8 @@ content_files = [ "applications.md", "build-steps.md", "configuration-logic.md", - "perl.md", "proxy-authentication.md", + "perl.md", "python.md", "ruby.md", "vala.md", -- cgit v1.2.1 From c82feb2cbeabc5bac70e2b5d65d2e58652bba9c0 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Mar 2023 02:38:15 -0400 Subject: Update D-Bus service (#101) - Remove property handling as it is unused - Rename query to GetProxiesFor Co-authored-by: Jan-Michael Brummer --- src/backend/dbus/dbus.c | 20 +------------------- src/backend/dbus/org.libproxy.proxy.xml | 4 ++-- src/libproxy/proxy-dbus.c | 2 +- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 200e5c0..7515865 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -53,7 +53,7 @@ handle_method_call (GDBusConnection *connection, int idx; g_application_hold (app); - if (g_strcmp0 (method_name, "query") != 0) { + if (g_strcmp0 (method_name, "GetProxiesFor") != 0) { g_warning ("Invalid method name '%s', aborting.", method_name); g_dbus_method_invocation_return_error (invocation, PX_MANAGER_ERROR, @@ -85,26 +85,8 @@ handle_method_call (GDBusConnection *connection, g_application_release (app); } -static GVariant * -handle_get_property (GDBusConnection *connection, - const gchar *sender, - const gchar *object_path, - const gchar *interface_name, - const gchar *property_name, - GError **error, - gpointer user_data) -{ - GVariant *ret = NULL; - - if (g_strcmp0 (property_name, "APIVersion") == 0) - ret = g_variant_new_string ("1.0"); - - return ret; -} - static const GDBusInterfaceVTable interface_vtable = { handle_method_call, - handle_get_property }; static void diff --git a/src/backend/dbus/org.libproxy.proxy.xml b/src/backend/dbus/org.libproxy.proxy.xml index c180df1..bba9251 100644 --- a/src/backend/dbus/org.libproxy.proxy.xml +++ b/src/backend/dbus/org.libproxy.proxy.xml @@ -1,13 +1,13 @@ - + - Ask for proxy server for given url. + Get proxy servers for given url. diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 57acbd9..d2b90ed 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -94,7 +94,7 @@ px_proxy_factory_get_proxies (pxProxyFactory *self, return NULL; result = g_dbus_proxy_call_sync (self->proxy, - "query", + "GetProxiesFor", g_variant_new ("(s)", url), G_DBUS_CALL_FLAGS_NONE, -1, -- cgit v1.2.1 From 595451331b1e91907d987ca4b0b2ebb7e8f538bd Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Mar 2023 02:50:57 -0400 Subject: Add common ignore handling (#99) Co-authored-by: Jan-Michael Brummer --- src/backend/plugins/config-env/config-env.c | 3 +- src/backend/plugins/config-gnome/config-gnome.c | 3 + src/backend/plugins/config-kde/config-kde.c | 14 ++- src/backend/plugins/config-osx/config-osx.c | 2 +- .../plugins/config-sysconfig/config-sysconfig.c | 8 +- .../plugins/config-windows/config-windows.c | 4 +- src/backend/px-manager.c | 109 +++++++++++++++++++++ src/backend/px-manager.h | 2 + tests/config-gnome-test.c | 1 + tests/px-manager-test.c | 90 +++++++++++++++++ 10 files changed, 225 insertions(+), 11 deletions(-) diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index 397fdd9..d7f5a73 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -143,9 +143,8 @@ px_config_env_get_config (PxConfig *config, const char *proxy = NULL; const char *scheme = g_uri_get_scheme (uri); - if (self->no_proxy && (g_strv_contains ((const char * const *)self->no_proxy, g_uri_get_host (uri)) || g_strv_contains ((const char * const *)self->no_proxy, "*"))) { + if (px_manager_is_ignore (uri, self->no_proxy)) return; - } if (g_strcmp0 (scheme, "ftp") == 0) proxy = self->ftp_proxy; diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index a41f54d..1d4f182 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -170,6 +170,9 @@ px_config_gnome_get_config (PxConfig *config, g_autofree char *proxy = NULL; GnomeProxyMode mode; + 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"); diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index f30a130..fba7ed3 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -44,7 +44,7 @@ struct _PxConfigKde { gboolean available; GFileMonitor *monitor; - char *no_proxy; + GStrv no_proxy; char *http_proxy; char *https_proxy; char *ftp_proxy; @@ -142,7 +142,8 @@ px_config_kde_set_config_file (PxConfigKde *self, } 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_strdup (value->str); + g_autofree char *no_proxy_for = g_strdup (value->str); + self->no_proxy = g_strsplit (no_proxy_for, ",", -1); } else if (strcmp (kv[0], "Proxy Config Script") == 0) { self->pac_script = g_strdup (value->str); } else if (strcmp (kv[0], "ProxyType") == 0) { @@ -166,7 +167,14 @@ 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); } @@ -241,7 +249,7 @@ px_config_kde_get_config (PxConfig *config, if (!self->proxy_type) return; - if (self->no_proxy && strstr (self->no_proxy, g_uri_get_host (uri))) + if (px_manager_is_ignore (uri, self->no_proxy)) return; switch (self->proxy_type) { diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index f733c93..68ce0f2 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -254,7 +254,7 @@ px_config_osx_get_config (PxConfig *self, ignore_list = get_ignore_list (proxies); - if (ignore_list && g_strv_contains ((const char * const *)ignore_list, g_uri_get_host (uri))) + if (px_manager_is_ignore (uri, ignore_list)) return; if (getbool (proxies, "ProxyAutoDiscoveryEnable")) { diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index 1f90a44..1adc1e8 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -37,7 +37,7 @@ struct _PxConfigSysConfig { char *https_proxy; char *http_proxy; char *ftp_proxy; - char *no_proxy; + GStrv no_proxy; }; static void px_config_iface_init (PxConfigInterface *iface); @@ -133,7 +133,8 @@ px_config_sysconfig_set_config_file (PxConfigSysConfig *self, } else if (strcmp (kv[0], "FTP_PROXY") == 0) { self->ftp_proxy = g_strdup (value->str); } else if (strcmp (kv[0], "NO_PROXY") == 0) { - self->no_proxy = g_strdup (value->str); + g_autofree char *tmp = g_strdup (value->str); + self->no_proxy = g_strsplit (tmp, ",", -1); } } } while (line); @@ -190,6 +191,7 @@ 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); } @@ -226,7 +228,7 @@ px_config_sysconfig_get_config (PxConfig *config, if (!self->proxy_enabled) return; - if (self->no_proxy && strstr (self->no_proxy, g_uri_get_host (uri))) + if (px_manager_is_ignore (uri, self->no_proxy)) return; if (g_strcmp0 (scheme, "ftp") == 0) { diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index b623c2d..73a889a 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -159,9 +159,9 @@ px_config_windows_get_config (PxConfig *self, guint32 enabled = 0; if (get_registry (W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) { - const char *host = g_uri_get_host (uri); + g_auto (GStrv) no_proxy = g_strsplit (tmp, ",", -1); - if (g_strcmp0 (tmp, "") == 0 && g_strcmp0 (host, "127.0.0.1") == 0) + if (px_manager_is_ignore (uri, no_proxy)) return; } diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 69d94fd..ef81eb1 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -594,3 +594,112 @@ px_strv_builder_add_proxy (GStrvBuilder *builder, 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); + + g_print ("%s %s\n", ignore, host); + + if (g_strcmp0 (ignore, "") == 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 index 2bb816b..558ddba 100644 --- a/src/backend/px-manager.h +++ b/src/backend/px-manager.h @@ -54,4 +54,6 @@ char **px_manager_get_configuration (PxManager *self, 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/tests/config-gnome-test.c b/tests/config-gnome-test.c index fc688bd..71ddb28 100644 --- a/tests/config-gnome-test.c +++ b/tests/config-gnome-test.c @@ -86,6 +86,7 @@ test_config_gnome_manual (Fixture *self, 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); diff --git a/tests/px-manager-test.c b/tests/px-manager-test.c index 1b1eb06..bfd3112 100644 --- a/tests/px-manager-test.c +++ b/tests/px-manager-test.c @@ -196,6 +196,92 @@ test_get_wpad (Fixture *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 (""); + 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) @@ -219,6 +305,10 @@ main (int argc, 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 (); } -- cgit v1.2.1 From 55a184683877c24a2ca9aecc2c618753b273bffb Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Mar 2023 09:25:30 +0100 Subject: Add missing config-option to Windows plugin (#103) --- .../plugins/config-windows/config-windows.c | 39 ++++++++++++++++++++++ tests/libproxy-test.c | 3 ++ 2 files changed, 42 insertions(+) diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index 73a889a..a29c952 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -45,6 +45,39 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigWindows, 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) { @@ -53,6 +86,12 @@ 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 diff --git a/tests/libproxy-test.c b/tests/libproxy-test.c index 05e05b3..fcc60c7 100644 --- a/tests/libproxy-test.c +++ b/tests/libproxy-test.c @@ -52,6 +52,9 @@ test_libproxy_setup (Fixture *self, 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); -- cgit v1.2.1 From bc90ac30fd9dc00fb9b34826c4e4fab73e465827 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 21 Mar 2023 10:33:42 +0100 Subject: Add config-option to osx plugin (#104) Co-authored-by: Jan-Michael Brummer --- src/backend/plugins/config-osx/config-osx.c | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index 68ce0f2..f92d9ee 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -35,6 +35,39 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigOsX, 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) { @@ -43,6 +76,12 @@ 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 -- cgit v1.2.1 From 50e2a3339d0ef4f750881853c1fafa83b82d34ae Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 22 Mar 2023 11:26:22 +0100 Subject: Minor cleanups (#106) Co-authored-by: Jan-Michael Brummer --- src/backend/dbus/dbus.c | 4 +++- src/backend/plugins/config-gnome/config-gnome.c | 11 ----------- src/backend/plugins/config-kde/config-kde.c | 2 +- src/backend/plugins/config-osx/config-osx.c | 3 --- src/backend/plugins/config-windows/config-windows.c | 6 ------ src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c | 1 - src/tools/proxy.c | 15 ++------------- tests/libproxy-test.c | 10 +++++----- 8 files changed, 11 insertions(+), 41 deletions(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index 7515865..e1e97aa 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -31,7 +31,7 @@ static GApplication *app; const GOptionEntry options[] = { { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, - { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system session.", NULL }, + { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system bus.", NULL }, { NULL } }; @@ -182,6 +182,8 @@ main (int argc, ); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + + /* Set application timeout to 60 seconds */ g_application_set_inactivity_timeout (app, 60000); return g_application_run (app, argc, argv); diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index 1d4f182..4c2bc57 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -226,17 +226,6 @@ px_config_gnome_get_config (PxConfig *config, username, password); } - - if ((((GPtrArray *)builder)->len == 0) && (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); - } } } diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index fba7ed3..124c5b9 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -261,7 +261,7 @@ px_config_kde_get_config (PxConfig *config, proxy = g_strdup (self->https_proxy); } else if (g_strcmp0 (scheme, "http") == 0) { proxy = g_strdup (self->http_proxy); - } else if (g_strcmp0 (scheme, "socks") == 0) { + } else if (self->socks_proxy && strlen (self->socks_proxy) > 0) { proxy = g_strdup (self->socks_proxy); } break; diff --git a/src/backend/plugins/config-osx/config-osx.c b/src/backend/plugins/config-osx/config-osx.c index f92d9ee..8a9e6e4 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -319,9 +319,6 @@ px_config_osx_get_config (PxConfig *self, proxy = protocol_url (proxies, capital_scheme); - if (!proxy) - proxy = protocol_url (proxies, "HTTP"); - if (!proxy) proxy = protocol_url (proxies, "SOCKS"); } diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index a29c952..5bffde6 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -233,12 +233,6 @@ px_config_windows_get_config (PxConfig *self, return; } - ret = g_hash_table_lookup (table, "http"); - 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); diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c index 5818156..51c2592 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -142,7 +142,6 @@ px_pacrunner_duktape_class_init (PxPacRunnerDuktapeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - /* object_class->constructed = px_duktape_constructed; */ object_class->dispose = px_pacrunner_duktape_dispose; } diff --git a/src/tools/proxy.c b/src/tools/proxy.c index 2561265..9a599ca 100644 --- a/src/tools/proxy.c +++ b/src/tools/proxy.c @@ -26,19 +26,7 @@ #include "proxy.h" -void * -malloc0 (size_t s); -void -print_proxies (char **proxies); - -void * -malloc0 (size_t s) -{ - void *tmp = malloc (s); - if (!tmp) return NULL; - memset (tmp, '\0', s); - return tmp; -} +void print_proxies (char **proxies); /** * Prints an array of proxies. Proxies are space separated. @@ -72,6 +60,7 @@ main (int argc, 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++) { diff --git a/tests/libproxy-test.c b/tests/libproxy-test.c index fcc60c7..00aac45 100644 --- a/tests/libproxy-test.c +++ b/tests/libproxy-test.c @@ -55,11 +55,11 @@ test_libproxy_setup (Fixture *self, 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); + /* 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 -- cgit v1.2.1 From ca6f1d4f68e47321fded3bf788e88f39f21e23db Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 22 Mar 2023 11:26:40 +0100 Subject: Add CHANGELOG.md (#105) Co-authored-by: Jan-Michael Brummer --- CHANGELOG.md | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 CHANGELOG.md 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 -- cgit v1.2.1 From d25ec573f9c35fd2c31a12af4388a1b30b3cc715 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 22 Mar 2023 15:34:17 +0100 Subject: Drop GDBusProxy and use GDBusConnection directly (#108) Longrunning users of libproxy will stumble upon a missing proxy dbus service after inactivity shuts service down. GDBusProxy is not able to handle stateless services, therefore we need to switch to GDBusConnection. Fixes: https://github.com/janbrummer/libproxy2/issues/107 Co-authored-by: Jan-Michael Brummer --- src/libproxy/proxy-dbus.c | 60 ++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index d2b90ed..fe03789 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -24,7 +24,7 @@ #include "proxy.h" struct _pxProxyFactory { - GDBusProxy *proxy; + GDBusConnection *connection; GCancellable *cancellable; }; @@ -48,30 +48,15 @@ px_proxy_factory_new (void) pxProxyFactory *self = g_new0 (pxProxyFactory, 1); self->cancellable = g_cancellable_new (); - self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_NONE, - NULL, /* GDBusInterfaceInfo */ - "org.libproxy.proxy", - "/org/libproxy/proxy", - "org.libproxy.proxy", - self->cancellable, /* GCancellable */ - &error); - - if (!self->proxy) { - g_clear_error (&error); - self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, /* GDBusInterfaceInfo */ - "org.libproxy.proxy", - "/org/libproxy/proxy", - "org.libproxy.proxy", - self->cancellable, /* GCancellable */ - &error); + self->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, self->cancellable, &error); + if (!self->connection) { + g_clear_error (&error); + self->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, self->cancellable, &error); } - if (!self->proxy) - g_warning ("Could not create libproxy dbus proxy: %s", error->message); + if (!self->connection) + g_warning ("Could not create dbus connection: %s", error->message); return self; } @@ -80,31 +65,38 @@ char ** px_proxy_factory_get_proxies (pxProxyFactory *self, const char *url) { - g_autoptr (GVariant) result = NULL; g_autoptr (GError) error = NULL; g_autoptr (GVariantIter) iter = NULL; g_autoptr (GList) list = NULL; + g_autoptr (GDBusMessage) msg = NULL; + g_autoptr (GDBusMessage) reply = NULL; + GVariant *result; GList *tmp; char *str; char **retval; gsize len; gsize idx; - if (!self->proxy) + if (!self->connection) return NULL; - result = g_dbus_proxy_call_sync (self->proxy, - "GetProxiesFor", - g_variant_new ("(s)", url), - G_DBUS_CALL_FLAGS_NONE, - -1, - self->cancellable, - &error); - if (!result) { - g_warning ("Could not query proxy dbus: %s", error->message); + msg = g_dbus_message_new_method_call ("org.libproxy.proxy", + "/org/libproxy/proxy", + "org.libproxy.proxy", + "GetProxiesFor"); + + g_dbus_message_set_body (msg, g_variant_new ("(s)", url)); + + reply = g_dbus_connection_send_message_with_reply_sync (self->connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, self->cancellable, &error); + if (!reply) { + g_warning ("Could not query proxy: %s", error->message); return NULL; } + if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) + return NULL; + + result = g_dbus_message_get_body (reply); g_variant_get (result, "(as)", &iter); while (g_variant_iter_loop (iter, "&s", &str)) { @@ -139,6 +131,6 @@ px_proxy_factory_free (pxProxyFactory *self) { g_cancellable_cancel (self->cancellable); g_clear_object (&self->cancellable); - g_clear_object (&self->proxy); + g_clear_object (&self->connection); g_clear_pointer (&self, g_free); } -- cgit v1.2.1 From 15927df7c3d4eca3bc8ae9f0fa59343752b75b08 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 22 Mar 2023 17:07:20 +0100 Subject: Remove debug output (#109) Co-authored-by: Jan-Michael Brummer --- src/backend/px-manager.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ef81eb1..ecc477e 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -632,8 +632,6 @@ ignore_hostname (GUri *uri, { const char *host = g_uri_get_host (uri); - g_print ("%s %s\n", ignore, host); - if (g_strcmp0 (ignore, "") == 0 && strchr (host, ':') == NULL && strchr (host, '.') == NULL) return TRUE; -- cgit v1.2.1 From cc1140f1d17aafe4f6ed702b2ff23f1b1341f7c1 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 27 Mar 2023 16:09:19 +0200 Subject: Set dbus bus owner in config file (#110) --- src/backend/dbus/meson.build | 20 ++++++++++++------ src/backend/dbus/org.libproxy.proxy.conf | 21 ------------------- src/backend/dbus/org.libproxy.proxy.conf.in | 32 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 27 deletions(-) delete mode 100644 src/backend/dbus/org.libproxy.proxy.conf create mode 100644 src/backend/dbus/org.libproxy.proxy.conf.in diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build index 250a105..107e401 100644 --- a/src/backend/dbus/meson.build +++ b/src/backend/dbus/meson.build @@ -6,7 +6,6 @@ if build_dbus dbus_interfaces_dir = join_paths(dbus_data_dir, 'interfaces') dbus_user_services_dir = join_paths(dbus_data_dir, 'services') dbus_system_services_dir = join_paths(dbus_data_dir, 'system-services') - dbus_user_conf_dir = join_paths(dbus_data_dir, 'session.d') dbus_system_conf_dir = join_paths(dbus_data_dir, 'system.d') px_interface = [ @@ -62,13 +61,13 @@ if build_dbus # D-Bus User Service user_service_data = configuration_data() user_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - dbus_user_service = configure_file( + configure_file( input: 'org.libproxy.proxy.service.in', output: 'org.libproxy.proxy.service', - configuration: user_service_data + configuration: user_service_data, + install: true, + install_dir: dbus_user_services_dir ) - install_data(dbus_user_service, install_dir : dbus_user_services_dir) - install_data('org.libproxy.proxy.conf', install_dir : dbus_user_conf_dir) # D-Bus System Service system_service_data = configuration_data() @@ -80,5 +79,14 @@ if build_dbus configuration: system_service_data ) install_data(dbus_system_service, rename : 'org.libproxy.proxy.service', install_dir : dbus_system_services_dir) - install_data('org.libproxy.proxy.conf', install_dir : dbus_system_conf_dir) + + dbus_config_data = configuration_data() + dbus_config_data.set('daemon_user', get_option('dbus-system-user')) + configure_file( + input: 'org.libproxy.proxy.conf.in', + output: 'org.libproxy.proxy.conf', + configuration: dbus_config_data, + install: true, + install_dir: dbus_system_conf_dir + ) endif diff --git a/src/backend/dbus/org.libproxy.proxy.conf b/src/backend/dbus/org.libproxy.proxy.conf deleted file mode 100644 index f9232a1..0000000 --- a/src/backend/dbus/org.libproxy.proxy.conf +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/backend/dbus/org.libproxy.proxy.conf.in b/src/backend/dbus/org.libproxy.proxy.conf.in new file mode 100644 index 0000000..7116729 --- /dev/null +++ b/src/backend/dbus/org.libproxy.proxy.conf.in @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.1 From 9dc05df68210f74509ef889b32ff8952ff3aae73 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Mon, 27 Mar 2023 16:39:41 +0200 Subject: Update URLs --- .github/workflows/coverity.yml | 2 +- README.md | 6 +++--- docs/px.toml.in | 6 +++--- libproxy.doap | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index a87d066..15f1570 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -16,7 +16,7 @@ permissions: jobs: build: runs-on: ubuntu-22.04 - if: github.repository == 'janbrummer/libproxy2' + if: github.repository == 'libproxy/libproxy' env: # Set in repo settings -> secrets -> actions COVERITY_SCAN_TOKEN: "${{ secrets.COVERITY_SCAN_TOKEN }}" diff --git a/README.md b/README.md index 227bde4..768248a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -![build](https://github.com/janbrummer/libproxy2/actions/workflows/build.yml/badge.svg) -[![codecov](https://codecov.io/github/janbrummer/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://app.codecov.io/github/janbrummer/libproxy2) -[![Coverity](https://github.com/janbrummer/libproxy2/actions/workflows/coverity.yml/badge.svg)](https://scan.coverity.com/projects/libproxy) +![build](https://github.com/libproxy/libproxy/actions/workflows/build.yml/badge.svg) +[![codecov](https://github.com/libproxy/libproxy/libproxy2/branch/main/graph/badge.svg?token=LS7B1CZKMY)](https://app.codecov.io/github/libproxy/libproxy) +[![Coverity](https://github.com/libproxy/libproxy/actions/workflows/coverity.yml/badge.svg)](https://scan.coverity.com/projects/libproxy) # Libproxy libproxy is a library that provides automatic proxy configuration management. diff --git a/docs/px.toml.in b/docs/px.toml.in index 1e7f88a..2476126 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -3,9 +3,9 @@ version = "@VERSION@" description = "Simplifyed proxy handling" authors = "libproxy Team" license = "LGPL-2.1-or-later" -browse_url = "https://github.com/janbrummer/libproxy2" -repository_url = "https://github.com/janbrummer/libproxy2" -website_url = "https://janbrummer.github.io/libproxy2/" +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", diff --git a/libproxy.doap b/libproxy.doap index a297e7a..e32d37e 100644 --- a/libproxy.doap +++ b/libproxy.doap @@ -6,9 +6,9 @@ libproxy libproxy is a library that provides automatic proxy configuration management. - - - + + + C -- cgit v1.2.1 From 755b771d95f20790c390cf5ddaab5379b738dc8b Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 28 Mar 2023 09:30:36 +0200 Subject: Remove Konqueror section This section is outdated, remove it. --- docs/configuration-logic.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/configuration-logic.md b/docs/configuration-logic.md index 2229646..783a8db 100644 --- a/docs/configuration-logic.md +++ b/docs/configuration-logic.md @@ -45,11 +45,6 @@ contain any special logic. Next is the logic represent as pseudo code: IF no proxy has been set THEN use direct connection ``` -### Konqueror - -This is the default browser in the KDE desktop environment. This browser only -support protocol specific proxy (no SOCKS), thus logic is very basic. - ## 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 -- cgit v1.2.1 From b85a776d60562e40841f6293be27054c6c51e373 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 28 Mar 2023 09:31:42 +0200 Subject: Update replace option description --- src/backend/dbus/dbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index e1e97aa..0b30ccf 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -30,7 +30,7 @@ static gboolean use_system; static GApplication *app; const GOptionEntry options[] = { - { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, + { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace running daemon.", NULL }, { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system bus.", NULL }, { NULL } }; -- cgit v1.2.1 From 2644c741bf0e7fb7e327907a363975b65f47e89c Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 28 Mar 2023 09:35:39 +0200 Subject: Rework GNOME config plugin initialization Move available check to init function to exit early. --- src/backend/plugins/config-gnome/config-gnome.c | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index 4c2bc57..426769c 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -33,7 +33,7 @@ struct _PxConfigGnome { GSettings *https_proxy_settings; GSettings *ftp_proxy_settings; GSettings *socks_proxy_settings; - gboolean settings_found; + gboolean available; }; typedef enum { @@ -58,18 +58,30 @@ enum { static void px_config_gnome_init (PxConfigGnome *self) { - GSettingsSchemaSource *source = g_settings_schema_source_get_default (); + 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) return; proxy_schema = g_settings_schema_source_lookup (source, "org.gnome.system.proxy", TRUE); - self->settings_found = proxy_schema != NULL; + self->available = proxy_schema != NULL; g_clear_pointer (&proxy_schema, g_settings_schema_unref); - if (!self->settings_found) + if (!self->available) return; self->proxy_settings = g_settings_new ("org.gnome.system.proxy"); @@ -126,17 +138,8 @@ static gboolean px_config_gnome_is_available (PxConfig *config) { PxConfigGnome *self = PX_CONFIG_GNOME (config); - const char *desktops; - if (!self->settings_found) - return FALSE; - - desktops = getenv ("XDG_CURRENT_DESKTOP"); - if (!desktops) - return FALSE; - - /* Remember that XDG_CURRENT_DESKTOP is a list of strings. */ - return strstr (desktops, "GNOME") != NULL; + return self->available; } static void -- cgit v1.2.1 From 0f4ce0975e38837d1721ae2a3f5443137c11af30 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 28 Mar 2023 11:06:46 +0200 Subject: Update KDE config plugin available check --- src/backend/plugins/config-kde/config-kde.c | 14 ++++++++++++-- tests/config-kde-test.c | 3 ++- tests/meson.build | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 124c5b9..56c83c0 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -88,10 +88,20 @@ px_config_kde_set_config_file (PxConfigKde *self, 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); - self->available = FALSE; file = g_file_new_for_path (self->config_file); if (!file) { @@ -234,7 +244,7 @@ px_config_kde_is_available (PxConfig *config) { PxConfigKde *self = PX_CONFIG_KDE (config); - return self->available && g_getenv ("KDE_FULL_SESSION") != NULL; + return self->available; } static void diff --git a/tests/config-kde-test.c b/tests/config-kde-test.c index c918afd..c12d1f4 100644 --- a/tests/config-kde-test.c +++ b/tests/config-kde-test.c @@ -186,13 +186,14 @@ test_config_kde_fail (void) g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL); /* Disable KDE support */ - g_unsetenv ("KDE_FULL_SESSION"); + 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]); } diff --git a/tests/meson.build b/tests/meson.build index 3fa6e5a..cd268f2 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -73,7 +73,7 @@ if get_option('tests') ) test('Config KDE test', config_kde_test, - env: [envs, 'KDE_FULL_SESSION=1'], + env: [envs, 'XDG_CURRENT_DESKTOP=KDE'], ) endif endif -- cgit v1.2.1 From 1446412e667538f06bd85f88df946f8b316ca38d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Tue, 28 Mar 2023 11:08:22 +0200 Subject: Remove root as default session owner --- meson_options.txt | 2 +- src/backend/dbus/org.libproxy.proxy.conf.in | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/meson_options.txt b/meson_options.txt index 2927b76..0e7a7e9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -22,7 +22,7 @@ option( option( 'dbus-system-user', type: 'string', - value: 'root', + value: 'libproxy', description: 'Which user should be used on D-Bus system session' ) diff --git a/src/backend/dbus/org.libproxy.proxy.conf.in b/src/backend/dbus/org.libproxy.proxy.conf.in index 7116729..daa79f5 100644 --- a/src/backend/dbus/org.libproxy.proxy.conf.in +++ b/src/backend/dbus/org.libproxy.proxy.conf.in @@ -6,11 +6,7 @@ - - - - - + -- cgit v1.2.1 From 3604dc5aa5d623740263dd077f5b7d209cf1d486 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 29 Mar 2023 17:15:33 +0200 Subject: Remove d-bus support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We tried hard to make the D-Bus service a thing, but we failed. Beside all the advantages we do have problems which couldn't be solved reliable: - Dependency impact in containers (which adds D-Bus) - Environment Variables couldn't be used anymore - Two services had to be created (session/system) for users without a desktop environment - ... Alternatives like using private d-bus connections would lead to additional processes per app/lib using libproxy. Even with a timeout this looks akward. Let's remove it. ¯\_(ツ)_/¯ --- .github/workflows/build.yml | 29 +--- docs/architecture.md | 18 -- meson.build | 2 - meson_options.txt | 14 -- src/backend/dbus/dbus.c | 190 --------------------- src/backend/dbus/meson.build | 92 ---------- .../dbus/org.libproxy.proxy-system.service.in | 4 - src/backend/dbus/org.libproxy.proxy.conf.in | 28 --- src/backend/dbus/org.libproxy.proxy.service.in | 3 - src/backend/dbus/org.libproxy.proxy.xml | 16 -- src/backend/meson.build | 7 +- src/libproxy/meson.build | 29 +--- src/libproxy/proxy-dbus.c | 136 --------------- tests/meson.build | 2 +- 14 files changed, 4 insertions(+), 566 deletions(-) delete mode 100644 src/backend/dbus/dbus.c delete mode 100644 src/backend/dbus/meson.build delete mode 100644 src/backend/dbus/org.libproxy.proxy-system.service.in delete mode 100644 src/backend/dbus/org.libproxy.proxy.conf.in delete mode 100644 src/backend/dbus/org.libproxy.proxy.service.in delete mode 100644 src/backend/dbus/org.libproxy.proxy.xml delete mode 100644 src/libproxy/proxy-dbus.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 236a783..431ff2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: libcurl4-openssl-dev \ valac - name: Build setup - run: meson setup build -Db_coverage=true -Ddbus=disabled + run: meson setup build -Db_coverage=true - name: Build run: ninja -C build - name: Tests and Coverage @@ -37,33 +37,6 @@ jobs: - name: CodeCov uses: codecov/codecov-action@v3 - build-linux-dbus: - 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 \ - libpeas-dev \ - gsettings-desktop-schemas-dev \ - libcurl4-openssl-dev \ - valac - - name: Build setup - run: meson setup build -Db_coverage=true -Ddbus=enabled - - name: Build - run: ninja -C build - - name: Tests - run: | - ninja test -C build - build-osx: runs-on: macos-latest steps: diff --git a/docs/architecture.md b/docs/architecture.md index 9da4938..35c3596 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -12,22 +12,4 @@ previous versions of Libproxy. To name a few advantages: - Make use of existing plugin loader - Automatic documentation out of code - Gobject Introspection bindings for almost every programming language -- D-Bus Service -Using D-Bus as a service on Linux we can elimnate the previous ABI clashes we -have had in the past. mozjs in different versions on one system could lead to -crashes in cases where the application using libproxy favours a different mozjs -version. - -## Building Libproxy as simple library - -On non D-Bus system you still have the option to build Libproxy as a self -contained library using `-Ddbus=disabled`. In this case you can still run into -an ABI issue, but with it's current plugins it is unlikely at the moment. - -## Building Libproxy as D-Bus Service -On D-Bus system Libproxy will be build using a D-Bus service and a simple -helper library. The main logic part (previous simple library) is done in the -D-Bus service and so can never crash an application. -The application itself will be linked with the helper library which does the -necessary D-Bus calls and wait's for answer. diff --git a/meson.build b/meson.build index 924a0c7..3543d12 100644 --- a/meson.build +++ b/meson.build @@ -112,8 +112,6 @@ 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')) -build_dbus = get_option('dbus').disable_auto_if(['window', 'darwin'].contains(host_system)).allowed() - config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) diff --git a/meson_options.txt b/meson_options.txt index 0e7a7e9..b04ed96 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,20 +12,6 @@ option( description: 'Whether to compile test cases for libproxy' ) -option( - 'dbus', - type: 'feature', - value: 'auto', - description: 'Whether to build D-Bus service' -) - -option( - 'dbus-system-user', - type: 'string', - value: 'libproxy', - description: 'Which user should be used on D-Bus system session' -) - option( 'config-env', type: 'boolean', diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c deleted file mode 100644 index 0b30ccf..0000000 --- a/src/backend/dbus/dbus.c +++ /dev/null @@ -1,190 +0,0 @@ -/* dbus.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-interface.h" - -#include - -static gboolean replace; -static gboolean use_system; - -static GApplication *app; - -const GOptionEntry options[] = { - { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace running daemon.", NULL }, - { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system bus.", NULL }, - { NULL } -}; - -static void -handle_method_call (GDBusConnection *connection, - const gchar *sender, - const gchar *object_path, - const gchar *interface_name, - const gchar *method_name, - GVariant *parameters, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - PxManager *manager = PX_MANAGER (user_data); - GVariantBuilder *result; - g_auto (GStrv) proxies = NULL; - g_autoptr (GError) error = NULL; - const gchar *url; - int idx; - - g_application_hold (app); - if (g_strcmp0 (method_name, "GetProxiesFor") != 0) { - g_warning ("Invalid method name '%s', aborting.", method_name); - g_dbus_method_invocation_return_error (invocation, - PX_MANAGER_ERROR, - PX_MANAGER_ERROR_UNKNOWN_METHOD, - "Unknown method"); - g_application_release (app); - return; - } - - g_variant_get (parameters, "(&s)", &url); - - proxies = px_manager_get_proxies_sync (manager, url, &error); - if (error) { - g_warning ("Could not query proxy servers: %s", error->message); - g_dbus_method_invocation_return_gerror (invocation, error); - g_application_release (app); - return; - } - - result = g_variant_builder_new (G_VARIANT_TYPE ("as")); - if (proxies) { - for (idx = 0; proxies[idx]; idx++) { - g_variant_builder_add (result, "s", proxies[idx]); - } - } - - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("(as)", result)); - g_application_release (app); -} - -static const GDBusInterfaceVTable interface_vtable = { - handle_method_call, -}; - -static void -on_bus_acquired (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - g_autoptr (GError) error = NULL; - PxManager *manager = NULL; - - manager = px_manager_new (); - g_dbus_connection_register_object (connection, - "/org/libproxy/proxy", - (GDBusInterfaceInfo *)&org_libproxy_proxy_interface, - &interface_vtable, - manager, - g_object_unref, - &error); - g_application_release (user_data); - - if (error) { - g_warning ("Could not register dbus object: %s", error->message); - g_application_quit (user_data); - return; - } -} - -static void -on_name_lost (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - if (!connection) { - g_warning ("Can't connect proxy bus"); - g_application_quit (user_data); - } else { - g_warning ("Unknown name lost error"); - g_application_quit (user_data); - } -} - -static void -activate (GApplication *application) -{ - GBusNameOwnerFlags flags; - - flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; - if (replace) - flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; - - g_bus_own_name (use_system ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, - "org.libproxy.proxy", - flags, - on_bus_acquired, - NULL, - on_name_lost, - app, - NULL); - - g_application_hold (app); -} - -int -main (int argc, - char **argv) -{ - GOptionContext *context; - g_autoptr (GError) error = NULL; - - replace = FALSE; - use_system = FALSE; - - context = g_option_context_new (""); - g_option_context_set_summary (context, "Libproxy D-Bus Service"); - g_option_context_add_main_entries (context, options, "libproxy"); - - if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_printerr ("%s: %s", g_get_application_name (), error->message); - g_printerr ("\n"); - g_printerr ("Try \"%s --help\" for more information.", - g_get_prgname ()); - g_printerr ("\n"); - g_option_context_free (context); - return 1; - } - - app = g_application_new ("org.libproxy.proxy-service", -#if GLIB_CHECK_VERSION (2, 73, 0) - G_APPLICATION_DEFAULT_FLAGS -#else - G_APPLICATION_FLAGS_NONE -#endif - ); - - g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); - - /* Set application timeout to 60 seconds */ - g_application_set_inactivity_timeout (app, 60000); - - return g_application_run (app, argc, argv); -} diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build deleted file mode 100644 index 107e401..0000000 --- a/src/backend/dbus/meson.build +++ /dev/null @@ -1,92 +0,0 @@ -if build_dbus - gdbus_codegen = find_program('gdbus-codegen') - - unitdir = '' - dbus_data_dir = join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1') - dbus_interfaces_dir = join_paths(dbus_data_dir, 'interfaces') - dbus_user_services_dir = join_paths(dbus_data_dir, 'services') - dbus_system_services_dir = join_paths(dbus_data_dir, 'system-services') - dbus_system_conf_dir = join_paths(dbus_data_dir, 'system.d') - - px_interface = [ - 'org.libproxy.proxy.xml' - ] - - px_interface_h = custom_target( - 'px-interface.h', - input: px_interface, - output: ['px-interface.h'], - command: [ - gdbus_codegen, - '--interface-info-header', - '--output', '@OUTPUT@', - '@INPUT@' - ] - ) - - px_interface_c = custom_target( - 'libproxy-iface.c', - input: px_interface, - output: ['px-interface.c'], - command: [ - gdbus_codegen, - '--interface-info-body', - '--output', '@OUTPUT@', - '@INPUT@' - ], - ) - - proxyd_sources = [ - px_interface_c, - px_interface_h, - 'dbus.c', - ] - - proxyd_deps = [ - px_backend_dep - ] - - executable( - 'proxyd', - proxyd_sources, - c_args: px_backend_c_args, - dependencies: proxyd_deps, - install_dir: join_paths(px_prefix, get_option('libexecdir')), - install: true, - ) - - # D-Bus Interface - install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) - - # D-Bus User Service - user_service_data = configuration_data() - user_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - configure_file( - input: 'org.libproxy.proxy.service.in', - output: 'org.libproxy.proxy.service', - configuration: user_service_data, - install: true, - install_dir: dbus_user_services_dir - ) - - # D-Bus System Service - system_service_data = configuration_data() - system_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - system_service_data.set('USER', get_option('dbus-system-user')) - dbus_system_service = configure_file( - input: 'org.libproxy.proxy-system.service.in', - output: 'org.libproxy.proxy-system.service', - configuration: system_service_data - ) - install_data(dbus_system_service, rename : 'org.libproxy.proxy.service', install_dir : dbus_system_services_dir) - - dbus_config_data = configuration_data() - dbus_config_data.set('daemon_user', get_option('dbus-system-user')) - configure_file( - input: 'org.libproxy.proxy.conf.in', - output: 'org.libproxy.proxy.conf', - configuration: dbus_config_data, - install: true, - install_dir: dbus_system_conf_dir - ) -endif diff --git a/src/backend/dbus/org.libproxy.proxy-system.service.in b/src/backend/dbus/org.libproxy.proxy-system.service.in deleted file mode 100644 index 2af960b..0000000 --- a/src/backend/dbus/org.libproxy.proxy-system.service.in +++ /dev/null @@ -1,4 +0,0 @@ -[D-BUS Service] -Name=org.libproxy.proxy -Exec=@LIBEXECDIR@/proxyd --system -User=@USER@ diff --git a/src/backend/dbus/org.libproxy.proxy.conf.in b/src/backend/dbus/org.libproxy.proxy.conf.in deleted file mode 100644 index daa79f5..0000000 --- a/src/backend/dbus/org.libproxy.proxy.conf.in +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/backend/dbus/org.libproxy.proxy.service.in b/src/backend/dbus/org.libproxy.proxy.service.in deleted file mode 100644 index d1ac5f4..0000000 --- a/src/backend/dbus/org.libproxy.proxy.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.libproxy.proxy -Exec=@LIBEXECDIR@/proxyd diff --git a/src/backend/dbus/org.libproxy.proxy.xml b/src/backend/dbus/org.libproxy.proxy.xml deleted file mode 100644 index bba9251..0000000 --- a/src/backend/dbus/org.libproxy.proxy.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - Get proxy servers for given url. - - - - - - diff --git a/src/backend/meson.build b/src/backend/meson.build index b0b8de9..b25453a 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -34,9 +34,4 @@ px_backend_dep = declare_dependency( dependencies: px_backend_deps ) -subdir('dbus') -subdir('plugins') - -summary({ - 'D-Bus Service' : build_dbus, -}, section: 'Architecture') \ No newline at end of file +subdir('plugins') \ No newline at end of file diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index ce50e85..3a9aa87 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -2,20 +2,10 @@ libproxy_inc = include_directories('.') libproxy_sources = [] -libproxy_dbus_sources = [ - 'proxy-dbus.c', -] - -libproxy_non_dbus_sources = [ +libproxy_sources = [ 'proxy.c', ] -if build_dbus - libproxy_sources += libproxy_dbus_sources -else - libproxy_sources += libproxy_non_dbus_sources -endif - libproxy_headers = [ 'proxy.h', ] @@ -48,23 +38,6 @@ libproxy_dep = declare_dependency ( dependencies: libproxy_deps ) -libproxy_test = shared_library( - 'proxy_test', - libproxy_non_dbus_sources, - include_directories: px_backend_inc, - dependencies: libproxy_deps, - link_args : vflag, - link_depends : mapfile, - soversion: '1', - install: false, -) - -libproxy_test_dep = declare_dependency ( - include_directories: libproxy_inc, - link_with: libproxy_test, - dependencies: libproxy_deps -) - install_headers(libproxy_headers, subdir: 'libproxy') pkg = import('pkgconfig') diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c deleted file mode 100644 index fe03789..0000000 --- a/src/libproxy/proxy-dbus.c +++ /dev/null @@ -1,136 +0,0 @@ -/* proxy-dbus.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 - -#include "proxy.h" - -struct _pxProxyFactory { - GDBusConnection *connection; - GCancellable *cancellable; -}; - -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_copy (pxProxyFactory *self) -{ - return g_memdup2 (self, sizeof (pxProxyFactory)); -} - -pxProxyFactory * -px_proxy_factory_new (void) -{ - g_autoptr (GError) error = NULL; - pxProxyFactory *self = g_new0 (pxProxyFactory, 1); - - self->cancellable = g_cancellable_new (); - - self->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, self->cancellable, &error); - if (!self->connection) { - g_clear_error (&error); - self->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, self->cancellable, &error); - } - - if (!self->connection) - g_warning ("Could not create dbus connection: %s", error->message); - - return self; -} - -char ** -px_proxy_factory_get_proxies (pxProxyFactory *self, - const char *url) -{ - g_autoptr (GError) error = NULL; - g_autoptr (GVariantIter) iter = NULL; - g_autoptr (GList) list = NULL; - g_autoptr (GDBusMessage) msg = NULL; - g_autoptr (GDBusMessage) reply = NULL; - GVariant *result; - GList *tmp; - char *str; - char **retval; - gsize len; - gsize idx; - - if (!self->connection) - return NULL; - - msg = g_dbus_message_new_method_call ("org.libproxy.proxy", - "/org/libproxy/proxy", - "org.libproxy.proxy", - "GetProxiesFor"); - - g_dbus_message_set_body (msg, g_variant_new ("(s)", url)); - - reply = g_dbus_connection_send_message_with_reply_sync (self->connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, self->cancellable, &error); - if (!reply) { - g_warning ("Could not query proxy: %s", error->message); - return NULL; - } - - if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) - return NULL; - - result = g_dbus_message_get_body (reply); - g_variant_get (result, "(as)", &iter); - - while (g_variant_iter_loop (iter, "&s", &str)) { - list = g_list_prepend (list, str); - } - - len = g_list_length (list); - if (len == 0) { - retval = g_malloc0 (sizeof (char *) * 2); - retval[0] = g_strdup ("direct://"); - - return retval; - } - - retval = g_malloc0_n (len + 1, sizeof (char *)); - for (tmp = list, idx = 0; tmp && tmp->data; tmp = tmp->next, idx++) { - char *value = tmp->data; - retval[idx] = g_strdup (value); - } - - return retval; -} - -void -px_proxy_factory_free_proxies (char **proxies) -{ - g_clear_pointer (&proxies, g_strfreev); -} - -void -px_proxy_factory_free (pxProxyFactory *self) -{ - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); - g_clear_object (&self->connection); - g_clear_pointer (&self, g_free); -} diff --git a/tests/meson.build b/tests/meson.build index cd268f2..b5ca084 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -10,7 +10,7 @@ if get_option('tests') libproxy_test = executable('test-libproxy', ['libproxy-test.c'], include_directories: libproxy_inc, - dependencies: [libproxy_test_dep], + dependencies: [libproxy_dep], ) test('Libproxy test', libproxy_test, -- cgit v1.2.1 From d1107667da6da04395ff72a78839cf07a2fe1aa9 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 30 Mar 2023 07:39:53 +0200 Subject: Remove libpeas support As we no longer have further dependencies like glib for accessing the standard linux configurations and the other are platform specific. Let's remove peas all together. Plugins are now built-in. --- .github/workflows/build.yml | 4 +- .github/workflows/coverity.yml | 1 - docs/build-steps.md | 6 +- docs/px.toml.in | 6 - meson.build | 6 +- meson_options.txt | 14 +- src/backend/meson.build | 16 +- src/backend/plugins/config-env/config-env.c | 13 +- src/backend/plugins/config-env/config-env.plugin | 3 - src/backend/plugins/config-env/meson.build | 29 +-- src/backend/plugins/config-gnome/config-gnome.c | 16 +- .../plugins/config-gnome/config-gnome.plugin | 3 - src/backend/plugins/config-gnome/meson.build | 29 +-- src/backend/plugins/config-kde/config-kde.c | 16 +- src/backend/plugins/config-kde/config-kde.plugin | 3 - src/backend/plugins/config-kde/meson.build | 29 +-- src/backend/plugins/config-osx/config-osx.c | 18 +- src/backend/plugins/config-osx/config-osx.h | 5 - src/backend/plugins/config-osx/config-osx.plugin | 3 - src/backend/plugins/config-osx/meson.build | 39 +--- .../plugins/config-sysconfig/config-sysconfig.c | 13 +- .../config-sysconfig/config-sysconfig.plugin | 3 - src/backend/plugins/config-sysconfig/meson.build | 30 +-- .../plugins/config-windows/config-windows.c | 14 +- .../plugins/config-windows/config-windows.plugin | 3 - src/backend/plugins/config-windows/meson.build | 36 +-- src/backend/plugins/pacrunner-duktape/meson.build | 32 +-- .../plugins/pacrunner-duktape/pacrunner-duktape.c | 11 +- .../pacrunner-duktape/pacrunner-duktape.plugin | 3 - src/backend/px-manager.c | 241 +++++++++++---------- src/backend/px-plugin-config.h | 8 + tests/config-gnome-test.c | 2 + tests/config-kde-test.c | 2 + tests/config-osx-test.c | 52 +++++ tests/config-windows-test.c | 52 +++++ tests/meson.build | 24 ++ tests/px-manager-helper.c | 5 +- 37 files changed, 354 insertions(+), 436 deletions(-) delete mode 100644 src/backend/plugins/config-env/config-env.plugin delete mode 100644 src/backend/plugins/config-gnome/config-gnome.plugin delete mode 100644 src/backend/plugins/config-kde/config-kde.plugin delete mode 100644 src/backend/plugins/config-osx/config-osx.plugin delete mode 100644 src/backend/plugins/config-sysconfig/config-sysconfig.plugin delete mode 100644 src/backend/plugins/config-windows/config-windows.plugin delete mode 100644 src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin create mode 100644 tests/config-osx-test.c create mode 100644 tests/config-windows-test.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 431ff2d..f75c17f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,6 @@ jobs: meson \ gcovr \ gi-docgen \ - libpeas-dev \ gsettings-desktop-schemas-dev \ libcurl4-openssl-dev \ valac @@ -48,7 +47,7 @@ jobs: - name: Setup run: | pip install meson ninja - brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas curl vala + 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: | @@ -79,7 +78,6 @@ jobs: mingw-w64-x86_64-duktape mingw-w64-x86_64-gi-docgen mingw-w64-x86_64-libsoup3 - mingw-w64-x86_64-libpeas mingw-w64-x86_64-curl mingw-w64-x86_64-vala - uses: actions/checkout@v3 diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 15f1570..b3a9e9b 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -36,7 +36,6 @@ jobs: meson \ gcovr \ gi-docgen \ - libpeas-dev \ gsettings-desktop-schemas-dev \ libcurl4-openssl-dev \ valac diff --git a/docs/build-steps.md b/docs/build-steps.md index f0ac5df..2590c4e 100644 --- a/docs/build-steps.md +++ b/docs/build-steps.md @@ -8,7 +8,7 @@ Slug: building ### Dependencies ``` -sudo dnf install glib2-devel duktape-devel libsoup3-devel meson gcovr gi-docgen libpeas-devel libcurl-devel vala gsettings-desktop-schemas-devel gobject-introspection-devel +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 @@ -35,7 +35,7 @@ ninja -C build install ``` pip install meson ninja -brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas curl vala +brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen curl vala ``` ### Build Setup @@ -61,7 +61,7 @@ ninja -C build install ### 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-libpeas mingw-w64-x86_64-curl mingw-w64-x86_64-vala +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 diff --git a/docs/px.toml.in b/docs/px.toml.in index 2476126..8cab536 100644 --- a/docs/px.toml.in +++ b/docs/px.toml.in @@ -11,7 +11,6 @@ dependencies = [ "GObject-2.0", "Gio-2.0", "GLib-2.0", - "Peas-1.0", "Soup-3.0", "curl-1.0", ] @@ -33,11 +32,6 @@ name = "GLib" description = "The base utility library" docs_url = "https://developer.gnome.org/glib/stable" -[dependencies."Peas-1.0"] -name = "Peas" -description = "GObject-based plugins engine" -docs_url = "https://gnome.pages.gitlab.gnome.org/libpeas/libpeas-1.0/" - [dependencies."Soup-3.0"] name = "Soup" description = "HTTP client/server library for GNOME" diff --git a/meson.build b/meson.build index 3543d12..f209f60 100644 --- a/meson.build +++ b/meson.build @@ -13,7 +13,6 @@ root_dir = include_directories('.') px_prefix = get_option('prefix') datadir = get_option('datadir') px_libdir = join_paths(px_prefix, get_option('libdir')) -px_plugins_dir = join_paths(px_libdir, meson.project_name().to_lower(), 'plugins') girdir = get_option('datadir') / 'gir-1.0' typelibdir = get_option('libdir') / 'girepository-1.0' vapidir = get_option('datadir') / 'vala' / 'vapi' @@ -96,17 +95,17 @@ 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 ['darwin', 'ios'].contains(host_system) +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') -peas_dep = dependency('libpeas-1.0') 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) @@ -114,7 +113,6 @@ gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) -config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) config_h.set('HAVE_CURL', get_option('curl')) configure_file(output: 'config.h', configuration: config_h) diff --git a/meson_options.txt b/meson_options.txt index b04ed96..9e3e9bd 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -16,49 +16,49 @@ option( 'config-env', type: 'boolean', value: true, - description: 'Whether to build plugin for environment configuration' + description: 'Whether to build support for environment configuration' ) option( 'config-gnome', type: 'boolean', value: true, - description: 'Whether to build plugin for GNOME configuration' + description: 'Whether to build support for GNOME configuration' ) option( 'config-windows', type: 'boolean', value: true, - description: 'Whether to build plugin for Windows configuration' + description: 'Whether to build support for Windows configuration' ) option( 'config-sysconfig', type: 'boolean', value: true, - description: 'Whether to build plugin for sysconfig configuration' + description: 'Whether to build support for sysconfig configuration' ) option( 'config-osx', type: 'boolean', value: true, - description: 'Whether to build plugin for OS X configuration' + description: 'Whether to build support for OS X configuration' ) option( 'config-kde', type: 'boolean', value: true, - description: 'Whether to build plugin for KDE System Settings' + description: 'Whether to build support for KDE System Settings' ) option( 'pacrunner-duktape', type: 'boolean', value: true, - description: 'Whether to build plugin for PAC Runner Duktape' + description: 'Whether to build support for PAC Runner Duktape' ) option( diff --git a/src/backend/meson.build b/src/backend/meson.build index b25453a..c8be5da 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -1,3 +1,13 @@ +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', @@ -11,7 +21,7 @@ px_backend_deps = [ curl_dep, gio_dep, glib_dep, - peas_dep, + ws2_32_dep, ] px_backend_c_args = [ @@ -20,6 +30,8 @@ px_backend_c_args = [ px_backend_inc = include_directories('.') +subdir('plugins') + px_backend = shared_library( 'pxbackend-@0@'.format(api_version), px_backend_sources, @@ -33,5 +45,3 @@ px_backend_dep = declare_dependency( link_with: px_backend, dependencies: px_backend_deps ) - -subdir('plugins') \ No newline at end of file diff --git a/src/backend/plugins/config-env/config-env.c b/src/backend/plugins/config-env/config-env.c index d7f5a73..6a326e0 100644 --- a/src/backend/plugins/config-env/config-env.c +++ b/src/backend/plugins/config-env/config-env.c @@ -19,7 +19,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include "config-env.h" @@ -27,7 +27,6 @@ #include "px-plugin-config.h" static void px_config_iface_init (PxConfigInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); struct _PxConfigEnv { GObject parent_instance; @@ -161,14 +160,8 @@ px_config_env_get_config (PxConfig *config, 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; } - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_CONFIG, - PX_CONFIG_TYPE_ENV); -} diff --git a/src/backend/plugins/config-env/config-env.plugin b/src/backend/plugins/config-env/config-env.plugin deleted file mode 100644 index 2dfbdf3..0000000 --- a/src/backend/plugins/config-env/config-env.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=config-env -Name=Environment Variables \ No newline at end of file diff --git a/src/backend/plugins/config-env/meson.build b/src/backend/plugins/config-env/meson.build index 471ecc0..00f3cc3 100644 --- a/src/backend/plugins/config-env/meson.build +++ b/src/backend/plugins/config-env/meson.build @@ -2,33 +2,8 @@ plugin_name = 'config-env' if get_option(plugin_name) -plugin_src = [ - '@0@.c'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - sources: plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - 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 index 426769c..29cb34a 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -19,7 +19,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include "config-gnome.h" @@ -43,7 +43,6 @@ typedef enum { } GnomeProxyMode; static void px_config_iface_init (PxConfigInterface *iface); -void peas_register_types (PeasObjectModule *module); G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigGnome, px_config_gnome, @@ -173,6 +172,9 @@ px_config_gnome_get_config (PxConfig *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; @@ -235,14 +237,8 @@ px_config_gnome_get_config (PxConfig *config, 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; } - -void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_CONFIG, - PX_CONFIG_TYPE_GNOME); -} diff --git a/src/backend/plugins/config-gnome/config-gnome.plugin b/src/backend/plugins/config-gnome/config-gnome.plugin deleted file mode 100644 index 5121ceb..0000000 --- a/src/backend/plugins/config-gnome/config-gnome.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=config-gnome -Name=GNOME Settings \ No newline at end of file diff --git a/src/backend/plugins/config-gnome/meson.build b/src/backend/plugins/config-gnome/meson.build index 08acc1c..e6a9b20 100644 --- a/src/backend/plugins/config-gnome/meson.build +++ b/src/backend/plugins/config-gnome/meson.build @@ -2,33 +2,8 @@ plugin_name = 'config-gnome' if get_option(plugin_name) -plugin_src = [ - '@0@.c'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [peas_dep, px_backend_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - 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 index 56c83c0..d0e8ad8 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -19,7 +19,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include "config-kde.h" @@ -27,7 +27,6 @@ #include "px-manager.h" static void px_config_iface_init (PxConfigInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); typedef enum { KDE_PROXY_TYPE_NONE = 0, @@ -256,6 +255,9 @@ px_config_kde_get_config (PxConfig *config, const char *scheme = g_uri_get_scheme (uri); g_autofree char *proxy = NULL; + if (!self->available) + return; + if (!self->proxy_type) return; @@ -293,14 +295,8 @@ px_config_kde_get_config (PxConfig *config, 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; } - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_CONFIG, - PX_CONFIG_TYPE_KDE); -} diff --git a/src/backend/plugins/config-kde/config-kde.plugin b/src/backend/plugins/config-kde/config-kde.plugin deleted file mode 100644 index d03d2a8..0000000 --- a/src/backend/plugins/config-kde/config-kde.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=config-kde -Name=KDE \ No newline at end of file diff --git a/src/backend/plugins/config-kde/meson.build b/src/backend/plugins/config-kde/meson.build index ef4adfe..b34d78d 100644 --- a/src/backend/plugins/config-kde/meson.build +++ b/src/backend/plugins/config-kde/meson.build @@ -2,33 +2,8 @@ plugin_name = 'config-kde' if get_option(plugin_name) -plugin_src = [ - '@0@.c'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - sources: plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - 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 index 8a9e6e4..16813a0 100644 --- a/src/backend/plugins/config-osx/config-osx.c +++ b/src/backend/plugins/config-osx/config-osx.c @@ -19,16 +19,20 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include +#include + #include "config-osx.h" #include "px-plugin-config.h" #include "px-manager.h" static void px_config_iface_init (PxConfigInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); + +struct _PxConfigOsX { + GObject parent_instance; +}; G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigOsX, px_config_osx, @@ -330,14 +334,8 @@ px_config_osx_get_config (PxConfig *self, 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; } - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_CONFIG, - PX_CONFIG_TYPE_OSX); -} diff --git a/src/backend/plugins/config-osx/config-osx.h b/src/backend/plugins/config-osx/config-osx.h index 544329f..797b51e 100644 --- a/src/backend/plugins/config-osx/config-osx.h +++ b/src/backend/plugins/config-osx/config-osx.h @@ -22,7 +22,6 @@ #pragma once #include -#include G_BEGIN_DECLS @@ -30,10 +29,6 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (PxConfigOsX, px_config_osx, PX, CONFIG_OSX, GObject) -struct _PxConfigOsX { - GObject parent_instance; -}; - G_END_DECLS diff --git a/src/backend/plugins/config-osx/config-osx.plugin b/src/backend/plugins/config-osx/config-osx.plugin deleted file mode 100644 index 61c4a2a..0000000 --- a/src/backend/plugins/config-osx/config-osx.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=config-osx -Name=OS X \ No newline at end of file diff --git a/src/backend/plugins/config-osx/meson.build b/src/backend/plugins/config-osx/meson.build index eac98e8..f801d90 100644 --- a/src/backend/plugins/config-osx/meson.build +++ b/src/backend/plugins/config-osx/meson.build @@ -1,39 +1,16 @@ plugin_name = 'config-osx' -if host_machine.system() == 'darwin' +if get_option(plugin_name) and with_platform_darwin -if get_option(plugin_name) - -plugin_src = [ - '@0@.c'.format(plugin_name), +foundation_dep = dependency('Foundation') +system_configuration_dep = dependency('SystemConfiguration') +px_backend_deps += [ + foundation_dep, + system_configuration_dep, ] -plugin_data = [ - '@0@.plugin'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_lib = shared_module( - plugin_name, - plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - build_by_default: true, - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - -endif - endif diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.c b/src/backend/plugins/config-sysconfig/config-sysconfig.c index 1adc1e8..c640f1c 100644 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.c +++ b/src/backend/plugins/config-sysconfig/config-sysconfig.c @@ -19,7 +19,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include "config-sysconfig.h" @@ -41,7 +41,6 @@ struct _PxConfigSysConfig { }; static void px_config_iface_init (PxConfigInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigSysConfig, px_config_sysconfig, @@ -246,14 +245,8 @@ px_config_sysconfig_get_config (PxConfig *config, 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; } - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_CONFIG, - PX_CONFIG_TYPE_SYSCONFIG); -} diff --git a/src/backend/plugins/config-sysconfig/config-sysconfig.plugin b/src/backend/plugins/config-sysconfig/config-sysconfig.plugin deleted file mode 100644 index 0697fa2..0000000 --- a/src/backend/plugins/config-sysconfig/config-sysconfig.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=config-sysconfig -Name=sysconfig \ No newline at end of file diff --git a/src/backend/plugins/config-sysconfig/meson.build b/src/backend/plugins/config-sysconfig/meson.build index 1aef00b..6d6789b 100644 --- a/src/backend/plugins/config-sysconfig/meson.build +++ b/src/backend/plugins/config-sysconfig/meson.build @@ -2,34 +2,8 @@ plugin_name = 'config-sysconfig' if get_option(plugin_name) -plugin_src = [ - '@0@.c'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - build_by_default: true, - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - endif diff --git a/src/backend/plugins/config-windows/config-windows.c b/src/backend/plugins/config-windows/config-windows.c index 5bffde6..cc9c92d 100644 --- a/src/backend/plugins/config-windows/config-windows.c +++ b/src/backend/plugins/config-windows/config-windows.c @@ -21,7 +21,8 @@ #include #include -#include + +#include #include "config-windows.h" @@ -38,7 +39,6 @@ struct _PxConfigWindows { }; static void px_config_iface_init (PxConfigInterface *iface); -void peas_register_types (PeasObjectModule *module); G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigWindows, px_config_windows, @@ -245,14 +245,8 @@ px_config_windows_get_config (PxConfig *self, 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; } - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_CONFIG, - PX_CONFIG_TYPE_WINDOWS); -} diff --git a/src/backend/plugins/config-windows/config-windows.plugin b/src/backend/plugins/config-windows/config-windows.plugin deleted file mode 100644 index 04a589b..0000000 --- a/src/backend/plugins/config-windows/config-windows.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=config-windows -Name=Windows \ No newline at end of file diff --git a/src/backend/plugins/config-windows/meson.build b/src/backend/plugins/config-windows/meson.build index 2e592b5..302a33e 100644 --- a/src/backend/plugins/config-windows/meson.build +++ b/src/backend/plugins/config-windows/meson.build @@ -1,39 +1,9 @@ plugin_name = 'config-windows' -if host_machine.system() == 'windows' +if get_option(plugin_name) and with_platform_windows -if get_option(plugin_name) - -plugin_src = [ - '@0@.c'.format(plugin_name), -] - -plugin_data = [ - '@0@.plugin'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_lib = shared_module( - plugin_name, - plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - build_by_default: true, - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - -endif - endif \ No newline at end of file diff --git a/src/backend/plugins/pacrunner-duktape/meson.build b/src/backend/plugins/pacrunner-duktape/meson.build index ef4a470..f391b6d 100644 --- a/src/backend/plugins/pacrunner-duktape/meson.build +++ b/src/backend/plugins/pacrunner-duktape/meson.build @@ -3,35 +3,15 @@ plugin_name = 'pacrunner-duktape' if get_option(plugin_name) duktape_dep = dependency('duktape') +m_dep = cc.find_library('m', required : false) -plugin_src = [ - '@0@.c'.format(plugin_name), +px_backend_sources += [ + 'plugins/@0@/@0@.c'.format(plugin_name), ] -plugin_data = [ - '@0@.plugin'.format(plugin_name), +px_backend_deps += [ + duktape_dep, + m_dep ] -plugin_lib = shared_module( - plugin_name, - plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep, duktape_dep, ws2_32_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - build_by_default: true, - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - 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 index 51c2592..3676e48 100644 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c +++ b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c @@ -19,7 +19,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include #ifdef __WIN32__ @@ -40,7 +40,6 @@ struct _PxPacRunnerDuktape { }; static void px_pacrunner_iface_init (PxPacRunnerInterface *iface); -void peas_register_types (PeasObjectModule *module); G_DEFINE_FINAL_TYPE_WITH_CODE (PxPacRunnerDuktape, px_pacrunner_duktape, @@ -200,11 +199,3 @@ px_pacrunner_iface_init (PxPacRunnerInterface *iface) iface->set_pac = px_pacrunner_duktape_set_pac; iface->run = px_pacrunner_duktape_run; } - -void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_PACRUNNER, - PX_PACRUNNER_TYPE_DUKTAPE); -} diff --git a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin b/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin deleted file mode 100644 index efb10f0..0000000 --- a/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=pacrunner-duktape -Name=Duktape \ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index ecc477e..1eab303 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -20,19 +20,50 @@ */ #include "config.h" +#include "px-backend-config.h" + +#include +#include +#include #include "px-manager.h" #include "px-plugin-config.h" #include "px-plugin-pacrunner.h" +#ifdef HAVE_CONFIG_ENV +#include +#endif + +#ifdef HAVE_CONFIG_GNOME +#include +#endif + +#ifdef HAVE_CONFIG_KDE +#include +#endif + +#ifdef HAVE_CONFIG_OSX +#include +#endif + +#ifdef HAVE_CONFIG_SYSCONFIG +#include +#endif + +#ifdef HAVE_CONFIG_WINDOWS +#include +#endif + +#ifdef HAVE_PACRUNNER_DUKTAPE +#include +#endif + #ifdef HAVE_CURL #include #endif -#include enum { PROP_0, - PROP_PLUGINS_DIR, PROP_CONFIG_PLUGIN, PROP_CONFIG_OPTION, LAST_PROP @@ -48,14 +79,12 @@ static GParamSpec *obj_properties[LAST_PROP]; struct _PxManager { GObject parent_instance; - PeasEngine *engine; - PeasExtensionSet *config_set; - PeasExtensionSet *pacrunner_set; + GList *config_plugins; + GList *pacrunner_plugins; GNetworkMonitor *network_monitor; #ifdef HAVE_CURL CURL *curl; #endif - char *plugins_dir; char *config_plugin; char *config_option; @@ -85,11 +114,48 @@ px_manager_on_network_changed (GNetworkMonitor *monitor, 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); - const GList *list; if (g_getenv ("PX_DEBUG")) { const gchar *g_messages_debug; @@ -107,38 +173,37 @@ px_manager_constructed (GObject *object) } } - self->engine = peas_engine_get_default (); - - peas_engine_add_search_path (self->engine, self->plugins_dir, NULL); - - self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, "config-option", self->config_option, NULL); - self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); - - list = peas_engine_get_plugin_list (self->engine); - for (; list && list->data; list = list->next) { - PeasPluginInfo *info = PEAS_PLUGIN_INFO (list->data); - PeasExtension *extension = peas_extension_set_get_extension (self->config_set, info); - gboolean available = TRUE; - - /* In case user requested a specific module, just load that one */ - if (self->config_plugin && g_str_has_prefix (peas_plugin_info_get_module_name (info), "config-")) { - if (g_strcmp0 (peas_plugin_info_get_module_name (info), self->config_plugin) == 0) - peas_engine_load_plugin (self->engine, info); - } else { - peas_engine_load_plugin (self->engine, info); - } - - extension = peas_extension_set_get_extension (self->config_set, info); - if (extension) { - PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (extension); +#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 - available = ifc->is_available (PX_CONFIG (extension)); - } + 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); - if (!available) - peas_engine_unload_plugin (self->engine, info); + 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 (); @@ -151,19 +216,14 @@ static void px_manager_dispose (GObject *object) { PxManager *self = PX_MANAGER (object); - const GList *list; - list = peas_engine_get_plugin_list (self->engine); - for (; list && list->data; list = list->next) { - PeasPluginInfo *info = PEAS_PLUGIN_INFO (list->data); + for (GList *list = self->config_plugins; list && list->data; list = list->next) + g_clear_object (&list->data); - if (peas_plugin_info_is_loaded (info)) - peas_engine_unload_plugin (self->engine, info); - } + 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_clear_pointer (&self->plugins_dir, g_free); - g_clear_object (&self->engine); G_OBJECT_CLASS (px_manager_parent_class)->dispose (object); } @@ -177,9 +237,6 @@ px_manager_set_property (GObject *object, PxManager *self = PX_MANAGER (object); switch (prop_id) { - case PROP_PLUGINS_DIR: - self->plugins_dir = g_strdup (g_value_get_string (value)); - break; case PROP_CONFIG_PLUGIN: self->config_plugin = g_strdup (g_value_get_string (value)); break; @@ -198,8 +255,6 @@ px_manager_get_property (GObject *object, GParamSpec *pspec) { switch (prop_id) { - case PROP_PLUGINS_DIR: - break; case PROP_CONFIG_PLUGIN: break; default: @@ -218,12 +273,6 @@ px_manager_class_init (PxManagerClass *klass) object_class->set_property = px_manager_set_property; object_class->get_property = px_manager_get_property; - obj_properties[PROP_PLUGINS_DIR] = g_param_spec_string ("plugins-dir", - NULL, - NULL, - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_CONFIG_PLUGIN] = g_param_spec_string ("config-plugin", NULL, NULL, @@ -277,7 +326,7 @@ px_manager_new_with_options (const char *optname1, PxManager * px_manager_new (void) { - return px_manager_new_with_options ("plugins-dir", PX_PLUGINS_DIR, NULL); + return px_manager_new_with_options (NULL); } #ifdef HAVE_CURL @@ -345,29 +394,6 @@ px_manager_pac_download (PxManager *self, #endif } -struct ConfigData { - GStrvBuilder *builder; - GUri *uri; -}; - -/** - * Strategy: - * - Traverse through all plugins in extension set and ask for configuration data. - * - A plugin can either return the proxy server for given uri OR nothing! for direc access. - */ -static void -get_config (PeasExtensionSet *set, - PeasPluginInfo *info, - PeasExtension *extension, - gpointer data) -{ - PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (extension); - struct ConfigData *config_data = data; - - g_debug ("%s: Asking plugin '%s' for configuration", __FUNCTION__, peas_plugin_info_get_module_name (info)); - ifc->get_config (PX_CONFIG (extension), config_data->uri, config_data->builder); -} - /** * px_manager_get_configuration: * @self: a px manager @@ -384,37 +410,31 @@ px_manager_get_configuration (PxManager *self, GError **error) { g_autoptr (GStrvBuilder) builder = g_strv_builder_new (); - struct ConfigData config_data = { - .uri = uri, - .builder = builder, - }; - peas_extension_set_foreach (self->config_set, get_config, &config_data); + 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); } -struct PacData { - GBytes *pac; - GUri *uri; - GStrvBuilder *builder; -}; - static void -px_manager_run_pac (PeasExtensionSet *set, - PeasPluginInfo *info, - PeasExtension *extension, - gpointer data) +px_manager_run_pac (PxPacRunner *pacrunner, + GBytes *pac, + GUri *uri, + GStrvBuilder *builder) { - PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (extension); - struct PacData *pac_data = data; + PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (pacrunner); g_auto (GStrv) proxies_split = NULL; char *pac_response; - if (!ifc->set_pac (PX_PAC_RUNNER (extension), pac_data->pac)) + if (!ifc->set_pac (PX_PAC_RUNNER (pacrunner), pac)) return; - pac_response = ifc->run (PX_PAC_RUNNER (extension), pac_data->uri); + pac_response = ifc->run (PX_PAC_RUNNER (pacrunner), uri); /* Split line to handle multiple proxies */ proxies_split = g_strsplit (pac_response, ";", -1); @@ -422,7 +442,7 @@ px_manager_run_pac (PeasExtensionSet *set, 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) uri = NULL; + g_autoptr (GUri) proxy_uri = NULL; char *method; char *server; @@ -435,12 +455,12 @@ px_manager_run_pac (PeasExtensionSet *set, server = word_split[1]; uri_string = g_strconcat ("http://", server, NULL); - uri = g_uri_parse (uri_string, G_URI_FLAGS_PARSE_RELAXED, NULL); - if (!uri) + 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 (uri); + 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) { @@ -451,10 +471,10 @@ px_manager_run_pac (PeasExtensionSet *set, proxy_string = g_strconcat ("socks://", server, NULL); } - px_strv_builder_add_proxy (pac_data->builder, proxy_string); + px_strv_builder_add_proxy (builder, proxy_string); } else { /* Syntax not found, returning direct */ - px_strv_builder_add_proxy (pac_data->builder, "direct://"); + px_strv_builder_add_proxy (builder, "direct://"); } } } @@ -562,12 +582,13 @@ px_manager_get_proxies_sync (PxManager *self, 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)) { - struct PacData pac_data = { - .pac = self->pac_data, - .uri = uri, - .builder = builder, - }; - peas_extension_set_foreach (self->pacrunner_set, px_manager_run_pac, &pac_data); + 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)); } diff --git a/src/backend/px-plugin-config.h b/src/backend/px-plugin-config.h index aac62a0..6958df6 100644 --- a/src/backend/px-plugin-config.h +++ b/src/backend/px-plugin-config.h @@ -29,9 +29,17 @@ G_BEGIN_DECLS 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); diff --git a/tests/config-gnome-test.c b/tests/config-gnome-test.c index 71ddb28..f80914a 100644 --- a/tests/config-gnome-test.c +++ b/tests/config-gnome-test.c @@ -190,6 +190,8 @@ main (int argc, { 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); diff --git a/tests/config-kde-test.c b/tests/config-kde-test.c index c12d1f4..5129384 100644 --- a/tests/config-kde-test.c +++ b/tests/config-kde-test.c @@ -203,6 +203,8 @@ main (int argc, { 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); 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-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/meson.build b/tests/meson.build index b5ca084..4ae8e7d 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -76,4 +76,28 @@ if get_option('tests') 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 index c5e0b87..e3129a2 100644 --- a/tests/px-manager-helper.c +++ b/tests/px-manager-helper.c @@ -25,10 +25,7 @@ PxManager * px_test_manager_new (const char *config_plugin, const char *config_option) { - g_autofree char *path = g_test_build_filename (G_TEST_BUILT, "../src/backend/plugins", NULL); - - return px_manager_new_with_options ("plugins-dir", path, - "config-plugin", config_plugin, + return px_manager_new_with_options ("config-plugin", config_plugin, "config-option", config_option, NULL); } -- cgit v1.2.1 From fb32549b734845511ac8865f235b27aed31fb5e3 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 30 Mar 2023 13:55:51 +0200 Subject: Add warning in case GNOME settings arent' installed --- src/backend/plugins/config-gnome/config-gnome.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/plugins/config-gnome/config-gnome.c b/src/backend/plugins/config-gnome/config-gnome.c index 29cb34a..9d6fd68 100644 --- a/src/backend/plugins/config-gnome/config-gnome.c +++ b/src/backend/plugins/config-gnome/config-gnome.c @@ -72,8 +72,10 @@ px_config_gnome_init (PxConfigGnome *self) return; source = g_settings_schema_source_get_default (); - if (!source) + 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); -- cgit v1.2.1 From 9f44149e25603e0f34e9c8f6fc9d6d7912a71e83 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 30 Mar 2023 13:56:54 +0200 Subject: Split KDE config lines only twice This ensures that further = settings would still be possible. --- src/backend/plugins/config-kde/config-kde.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index d0e8ad8..3d3a4a7 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -132,7 +132,7 @@ px_config_kde_set_config_file (PxConfigKde *self, if (line) { g_auto (GStrv) kv = NULL; g_autoptr (GString) value = NULL; - kv = g_strsplit (line, "=", -1); + kv = g_strsplit (line, "=", 2); if (g_strv_length (kv) != 2) continue; -- cgit v1.2.1 From ad4447e4cd24847598455930d35d8b94490f6dd5 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 30 Mar 2023 13:58:44 +0200 Subject: Remove unecessary removal of \r in KDE plugin --- src/backend/plugins/config-kde/config-kde.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 3d3a4a7..19dc1ff 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -139,7 +139,6 @@ px_config_kde_set_config_file (PxConfigKde *self, value = g_string_new (kv[1]); g_string_replace (value, "\"", "", 0); - g_string_replace (value, "\r", "", 0); g_string_replace (value, " ", ":", 0); if (strcmp (kv[0], "httpsProxy") == 0) { -- cgit v1.2.1 From ef0e728287f6068177636d22262353ddd0bb5341 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 30 Mar 2023 14:00:12 +0200 Subject: Simplify KDE no_proxy parsing --- src/backend/plugins/config-kde/config-kde.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 19dc1ff..6d82c24 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -150,8 +150,7 @@ px_config_kde_set_config_file (PxConfigKde *self, } else if (strcmp (kv[0], "socksProxy") == 0) { self->socks_proxy = g_strdup (value->str); } else if (strcmp (kv[0], "NoProxyFor") == 0) { - g_autofree char *no_proxy_for = g_strdup (value->str); - self->no_proxy = g_strsplit (no_proxy_for, ",", -1); + 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) { -- cgit v1.2.1 From 5272fb3d114f0d012871380bd429546c73f0226d Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Thu, 30 Mar 2023 14:07:38 +0200 Subject: Add comment explaining KDE_PROXY_TYPE_SYSTEM --- src/backend/plugins/config-kde/config-kde.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/plugins/config-kde/config-kde.c b/src/backend/plugins/config-kde/config-kde.c index 6d82c24..ccec002 100644 --- a/src/backend/plugins/config-kde/config-kde.c +++ b/src/backend/plugins/config-kde/config-kde.c @@ -265,6 +265,9 @@ px_config_kde_get_config (PxConfig *config, 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) { -- cgit v1.2.1