File libproxy-0.5.9.obscpio of Package libproxy

07070100000000000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001700000000libproxy-0.5.9/.github07070100000001000081ED00000000000000000000000166FD5717000008B8000000000000000000000000000000000000002300000000libproxy-0.5.9/.github/coverity.sh#!/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
07070100000002000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002100000000libproxy-0.5.9/.github/workflows07070100000003000081A400000000000000000000000166FD571700000BDC000000000000000000000000000000000000002B00000000libproxy-0.5.9/.github/workflows/build.ymlname: Build

on: [push, pull_request]

jobs:
  build-linux:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Dependencies
      run: |
        sudo apt-get update
        sudo apt install \
          libglib2.0-dev \
          libgirepository1.0-dev \
          duktape-dev \
          meson \
          gcovr \
          gi-docgen \
          gsettings-desktop-schemas-dev \
          libcurl4-openssl-dev \
          valac
    - name: Build setup
      run: meson setup build -Db_coverage=true
    - name: Build
      run: ninja -C build
    - name: Tests and Coverage
      run: |
        ninja test -C build
        ninja coverage -C build
    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3
      with:
        path: ./build/docs/libproxy-1.0/
        if-no-files-found: error
    - name: CodeCov
      uses: codecov/codecov-action@v4
      with:
        token: ${{ secrets.CODECOV_TOKEN }} # required

  build-osx:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: |
          3.12
    - name: Setup
      run: |
        pip install meson ninja
        brew install gobject-introspection duktape gcovr gi-docgen vala gsettings-desktop-schemas
    - name: Build and Test
      run: |
        meson setup build -Ddocs=false
        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-curl
            mingw-w64-x86_64-vala
            mingw-w64-x86_64-gsettings-desktop-schemas
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.9'
      - name: Build and Test
       # Disable docs for the moment until msys2 gi-docgen update has landed
        run: |
          meson setup build -Ddocs=false
          ninja -C build
          ninja -C build test

  # Deploy job
  deploy:
    # needs: [build-linux, build-osx, build-windows]
    needs: build-linux
    if: github.ref == 'refs/heads/main'

    permissions:
      pages: write      # to deploy to Pages
      id-token: write   # to verify the deployment originates from an appropriate source

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    runs-on: ubuntu-latest
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
07070100000004000081A400000000000000000000000166FD571700000421000000000000000000000000000000000000002E00000000libproxy-0.5.9/.github/workflows/coverity.yml---
# vi: ts=2 sw=2 et:
# SPDX-License-Identifier: LGPL-2.1-or-later
#
name: Coverity

on:
  workflow_dispatch:
  schedule:
    # Run Coverity daily at midnight
    - cron:  '0 0 * * *'

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-22.04
    if: github.repository == 'libproxy/libproxy'
    env:
      # Set in repo settings -> secrets -> actions
      COVERITY_SCAN_TOKEN:              "${{ secrets.COVERITY_SCAN_TOKEN }}"
      COVERITY_SCAN_NOTIFICATION_EMAIL: "${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}"
    steps:
      - name: Repository checkout
        uses: actions/checkout@v4
      - name: Ubuntu Setup
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt install \
          libglib2.0-dev \
          libgirepository1.0-dev \
          duktape-dev \
          meson \
          gcovr \
          gi-docgen \
          gsettings-desktop-schemas-dev \
          libcurl4-openssl-dev \
          valac
      - name: Build & upload the results
        run: .github/coverity.sh
07070100000005000081A400000000000000000000000166FD571700000459000000000000000000000000000000000000002D00000000libproxy-0.5.9/.github/workflows/release.yml# 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@v7"
        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);
            }
07070100000006000081A400000000000000000000000166FD571700000011000000000000000000000000000000000000001A00000000libproxy-0.5.9/.gitignore/_build/
/build/
07070100000007000081A400000000000000000000000166FD5717000067A2000000000000000000000000000000000000001700000000libproxy-0.5.9/COPYING                  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.

    <one line to give the library's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    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.

  <signature of Ty Coon>, 1 April 1990
  Ty Coon, President of Vice

That's all there is to it!
07070100000008000081A400000000000000000000000166FD5717000010E0000000000000000000000000000000000000001900000000libproxy-0.5.9/README.md![build](https://github.com/libproxy/libproxy/actions/workflows/build.yml/badge.svg)
[![codecov](https://codecov.io/github/libproxy/libproxy/branch/main/graph/badge.svg?token=UDbFtICyin)](https://codecov.io/github/libproxy/libproxy)
[![Coverity](https://github.com/libproxy/libproxy/actions/workflows/coverity.yml/badge.svg)](https://scan.coverity.com/projects/libproxy)
[![CodeQL](https://github.com/libproxy/libproxy/workflows/CodeQL/badge.svg)](https://github.com/libproxy/libproxy/actions?query=workflow%3ACodeQL)

# Libproxy
libproxy is a library that provides automatic proxy configuration management.

## The Problem
Problem statement: Applications suck at correctly and consistently supporting proxy configuration.

Proxy configuration is problematic for a number of reasons:

- There are a variety of places to get configuration information
- There are a variety of proxy types
- Proxy auto-configuration (PAC) requires Javascript (which most applications don't have)
- Automatically determining PAC location requires an implementation of the WPAD protocol

These issues make programming with support for proxies hard. Application developers only want to answer the question: Given a network resource, how do I reach it? Because this is their concern, most applications just give up and try to read the proxy from an environment variable. This is problematic because:

- Given the increased use of mobile computing, network switching frequently occurs during the lifetime of an application
- Each application is required to implement the (non-trivial) WPAD and PAC protocols, including a Javascript engine
- It prevents a network administrator from locking down settings on a particular host or user
- In most cases, the environmental variable is almost never correct by default

## The Solution
libproxy exists to answer the question: Given a network resource, how do I reach it? It handles all the details, enabling you to get back to programming.

GNOME? KDE? Command line? WPAD? PAC? Network changed? 
It doesn't matter! Just ask libproxy what proxy to use: you get simple code and your users get correct, consistant behavior and broad infrastructure compatibility. Why use libproxy?

## libproxy offers the following features:
- support for all major platforms: Windows, Mac and Linux/UNIX
- extremely small core footprint
- minimal dependencies within libproxy core
- only 4 functions in the stable-ish external API
- dynamic adjustment to changing network topology
- a standard way of dealing with proxy settings across all scenarios
- a sublime sense of joy and accomplishment

## Repology

[![Arch package](https://repology.org/badge/version-for-repo/arch/libproxy.svg)](https://repology.org/project/libproxy/versions)
[![Debian 13 package](https://repology.org/badge/version-for-repo/debian_13/libproxy.svg)](https://repology.org/project/libproxy/versions)
[![Fedora 40 package](https://repology.org/badge/version-for-repo/fedora_40/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.6 package](https://repology.org/badge/version-for-repo/opensuse_leap_15_6/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 24.04 package](https://repology.org/badge/version-for-repo/ubuntu_24_04/libproxy.svg)](https://repology.org/project/libproxy/versions)

07070100000009000081A400000000000000000000000166FD57170000002F000000000000000000000000000000000000001B00000000libproxy-0.5.9/codecov.ymlcoverage:
  ignore:
    - tests
    - src/tools0707010000000A000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001400000000libproxy-0.5.9/data0707010000000B000081A400000000000000000000000166FD57170000067A000000000000000000000000000000000000002D00000000libproxy-0.5.9/data/canonicalize_filename.sh#!/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"
}
0707010000000C000081ED00000000000000000000000166FD57170000059A000000000000000000000000000000000000002500000000libproxy-0.5.9/data/check-code-style#!/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
0707010000000D000081A400000000000000000000000166FD57170000013D000000000000000000000000000000000000002800000000libproxy-0.5.9/data/install-git-hook.sh#!/bin/bash

cd "$MESON_SOURCE_ROOT"

[ -d .git ] || exit 2 # not a git repo
[ ! -f .git/hooks/pre-commit ] || exit 2 # already installed

cp data/pre-commit-hook .git/hooks/pre-commit
cp data/canonicalize_filename.sh .git/hooks/canonicalize_filename.sh
chmod +x .git/hooks/pre-commit
echo "Activated pre-commit hook"0707010000000E000081ED00000000000000000000000166FD571700001AF0000000000000000000000000000000000000002600000000libproxy-0.5.9/data/lineup-parameters#!/usr/bin/env python3
#
# Copyright © 2019 Michael Catanzaro <mcatanzaro@gnome.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Based on original C lineup-parameters by Sébastien Wilmet <swilmet@gnome.org>
# Rewritten in Python to allow simple execution from source directory.
#
# Usage: lineup-parameters [file]
# If the file is not given, stdin is read.
# The result is printed to stdout.
#
# The restrictions:
# - The function name must be at column 0, followed by a space and an opening
#   parenthesis;
# - One parameter per line;
# - A parameter must follow certain rules (see the regex in the code), but it
#   doesn't accept all possibilities of the C language.
# - The opening curly brace ("{") of the function must also be at column 0.
#
# If one restriction is missing, the function declaration is not modified.
#
# Example:
#
# gboolean
# frobnitz (Frobnitz *frobnitz,
#           gint magic_number,
#           GError **error)
# {
#   ...
# }
#
# Becomes:
#
# gboolean
# frobnitz (Frobnitz  *frobnitz,
#           gint       magic_number,
#           GError   **error)
# {
#   ...
# }
#
# TODO: support "..." vararg parameter

import argparse
import re
import sys

from typing import NamedTuple

# https://regexr.com/ is your friend.
functionNameRegex = re.compile(r'^(\w+) ?\(')
parameterRegex = re.compile(
    r'^\s*(?P<type>(const\s+)?\w+)'
    r'\s+(?P<stars>\**)'
    r'\s*(?P<name>\w+)'
    r'\s*(?P<end>,|\))'
    r'\s*$')
openingCurlyBraceRegex = re.compile(r'^{\s*$')


def matchFunctionName(line):
    match = functionNameRegex.match(line)
    if match:
        functionName = match.group(1)
        firstParamPosition = match.end(0)
        return (functionName, firstParamPosition)
    return (None, 0)


class ParameterInfo(NamedTuple):
    paramType: str
    name: str
    numStars: int
    isLastParameter: bool


def matchParameter(line):
    _, firstParamPosition = matchFunctionName(line)
    match = parameterRegex.match(line[firstParamPosition:])
    if match is None:
        return None
    paramType = match.group('type')
    assert(paramType is not None)
    name = match.group('name')
    assert(name is not None)
    stars = match.group('stars')
    numStars = len(stars) if stars is not None else 0
    end = match.group('end')
    isLastParameter = True if end is not None and end == ')' else False
    return ParameterInfo(paramType, name, numStars, isLastParameter)


def matchOpeningCurlyBrace(line):
    return True if openingCurlyBraceRegex.match(line) is not None else False


# Length returned is number of lines the declaration takes up
def getFunctionDeclarationLength(remainingLines):
    for i in range(len(remainingLines)):
        currentLine = remainingLines[i]
        parameterInfo = matchParameter(currentLine)
        if parameterInfo is None:
            return 0
        if parameterInfo.isLastParameter:
            if i + 1 == len(remainingLines):
                return 0
            nextLine = remainingLines[i + 1]
            if not matchOpeningCurlyBrace(nextLine):
                return 0
            return i + 1
    return 0


def getParameterInfos(remainingLines, length):
    parameterInfos = []
    for i in range(length):
        parameterInfos.append(matchParameter(remainingLines[i]))
    return parameterInfos


def computeSpacing(parameterInfos):
    maxTypeLength = 0
    maxStarsLength = 0
    for parameterInfo in parameterInfos:
        maxTypeLength = max(maxTypeLength, len(parameterInfo.paramType))
        maxStarsLength = max(maxStarsLength, parameterInfo.numStars)
    return (maxTypeLength, maxStarsLength)


def printParameter(parameterInfo, maxTypeLength, maxStarsLength, outfile):
    outfile.write(f'{parameterInfo.paramType:<{maxTypeLength + 1}}')
    paramNamePaddedWithStars = f'{parameterInfo.name:*>{parameterInfo.numStars + len(parameterInfo.name)}}'
    outfile.write(f'{paramNamePaddedWithStars:>{maxStarsLength + len(parameterInfo.name)}}')


def printFunctionDeclaration(remainingLines, length, useTabs, outfile):
    functionName, _ = matchFunctionName(remainingLines[0])
    assert(functionName is not None)
    outfile.write(f'{functionName} (')
    numSpacesToParenthesis = len(functionName) + 2
    whitespace = ''
    if useTabs:
        tabs = ''.ljust(numSpacesToParenthesis // 8, '\t')
        spaces = ''.ljust(numSpacesToParenthesis % 8)
        whitespace = tabs + spaces
    else:
        whitespace = ''.ljust(numSpacesToParenthesis)
    parameterInfos = getParameterInfos(remainingLines, length)
    maxTypeLength, maxStarsLength = computeSpacing(parameterInfos)
    numParameters = len(parameterInfos)
    for i in range(numParameters):
        parameterInfo = parameterInfos[i]
        if i != 0:
            outfile.write(whitespace)
        printParameter(parameterInfo, maxTypeLength, maxStarsLength, outfile)
        if i + 1 != numParameters:
            outfile.write(',\n')
    outfile.write(')\n')


def parseContents(infile, useTabs, outfile):
    lines = infile.readlines()
    i = 0
    while i < len(lines):
        line = lines[i]
        functionName, _ = matchFunctionName(line)
        if functionName is None:
            outfile.write(line)
            i += 1
            continue
        remainingLines = lines[i:]
        length = getFunctionDeclarationLength(remainingLines)
        if length == 0:
            outfile.write(line)
            i += 1
            continue
        printFunctionDeclaration(remainingLines, length, useTabs, outfile)
        i += length


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Line up parameters of C functions')
    parser.add_argument('infile', nargs='?',
                        type=argparse.FileType('r'),
                        default=sys.stdin,
                        help='input C source file')
    parser.add_argument('-o', metavar='outfile', nargs='?',
                        type=argparse.FileType('w'),
                        default=sys.stdout,
                        help='where to output modified file')
    parser.add_argument('--tabs', action='store_true',
                        help='whether use tab characters in the output')
    args = parser.parse_args()
    parseContents(args.infile, args.tabs, args.o)
    args.infile.close()
    args.o.close()
0707010000000F000081A400000000000000000000000166FD57170000013C000000000000000000000000000000000000002400000000libproxy-0.5.9/data/pre-commit-hook#!/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 -07070100000010000081A400000000000000000000000166FD5717000015B2000000000000000000000000000000000000002300000000libproxy-0.5.9/data/uncrustify.cfg# 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

07070100000011000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001400000000libproxy-0.5.9/docs07070100000012000081A400000000000000000000000166FD5717000003FB000000000000000000000000000000000000002400000000libproxy-0.5.9/docs/applications.mdTitle: Applications - Who is using Libproxy?
Slug: ApplicationMatrix

# Applications - Who is using Libproxy?


| Application | Upstream | Patches |
| --- | -- | -- |
| apt | NO | [https://salsa.debian.org/apt-team/apt/-/merge_requests/300](https://salsa.debian.org/apt-team/apt/-/merge_requests/300) |
| cURL | NO | [https://github.com/curl/curl/pull/11393](https://github.com/curl/curl/pull/11393) |
| eid-viewer | YES | - |
| glib-networking | YES | - |
| golang | NO | [https://github.com/golang/go/issues/61065](https://github.com/golang/go/issues/61065) |
| libQt5Network | YES | - |
| libzypp | YES | - |
| Mozilla Firefox | YES | - |
| neon | YES | - |
| openconnect | YES | - |
| python-requests | NO | [https://github.com/psf/requests/pull/6479](https://github.com/psf/requests/pull/6479) |
| seamonkey | YES | - |
| signond | YES | - |
| signond_ui | YES | - |
| vagalume | YES | - |
| wget | NO | [https://gitlab.com/gnuwget/wget/-/merge_requests/35](https://gitlab.com/gnuwget/wget/-/merge_requests/35) |

07070100000013000081A400000000000000000000000166FD5717000005A4000000000000000000000000000000000000002400000000libproxy-0.5.9/docs/architecture.mdTitle: Architecture of Libproxy
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

## Plugin types

Libproxy is using internal plugins to extend it's knowledge about different
configuration options and handling of PAC files. Most of those plugins are
configuration plugins:

- config-env
- config-gnome
- config-kde
- config-osx
- config-sysconfig
- config-windows

Then there is only one pacrunner plugin which handles parsing of JS PAC files:

- pacrunner-duktape

## Configuration plugin priority

Configuration plugins are executed in a specific priority:

- PX_CONFIG_PRIORITY_FIRST (highest)
- PX_CONFIG_PRIORITY_DEFAULT
- PX_CONFIG_PRIORITY_LAST (lowest)

Highest priority is used in `config-env` and lowest priority in
`config-sysconfig`. All the other plugins are running on default priority.

### Configuration plugin enforcement

In case you want to use a specific configuration plugin for a given application,
you are able to overwrite the priority. Therefore set a environment variable
`PX_FORCE_CONFIG=config-name` and libproxy will just use this configuration
plugin.
07070100000014000081A400000000000000000000000166FD5717000004CF000000000000000000000000000000000000002300000000libproxy-0.5.9/docs/build-steps.mdTitle: Build steps - How to compile libproxy
Slug: building

# Build steps - How to compile libproxy

## Fedora

### Dependencies

```
sudo dnf install glib2-devel duktape-devel meson gcovr gi-docgen libcurl-devel vala gsettings-desktop-schemas-devel gobject-introspection-devel
```

### Build Setup

```
meson setup build
```

### Compilation

```
ninja -C build
```

### Installation

```
ninja -C build install
```

## OS X

### Dependencies

```
pip install meson ninja
brew install icu4c gobject-introspection duktape gcovr gi-docgen curl vala
```

### Build Setup

```
meson setup build
```

### Compilation

```
ninja -C build
```

### Installation

```
ninja -C build install
```

## Windows (MSYS2)

### Dependencies

```
pacman -S base-devel git mingw-w64-x86_64-toolchain mingw-w64-x86_64-ccache mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gobject-introspection mingw-w64-x86_64-python-gobject mingw-w64-x86_64-meson mingw-w64-x86_64-glib2 mingw-w64-x86_64-duktape mingw-w64-x86_64-gi-docgen mingw-w64-x86_64-curl mingw-w64-x86_64-vala mingw-w64-x86_64-gsettings-desktop-schemas
```

### Build Setup

```
meson setup build
```

### Compilation

```
ninja -C build
```

### Installation

```
ninja -C build install
```

07070100000015000081A400000000000000000000000166FD571700000F04000000000000000000000000000000000000002B00000000libproxy-0.5.9/docs/configuration-logic.mdTitle: Configuration Logic
Slug: Design

# Configuration Logic

## Introduction
As the proxy configuration predates libproxy, we need to consider previous
implementation behavior to ensure consistency with user expectations. This page
presents analyses of well known implementation base on the platform they run on.

## Linux
On Linux the pioneer of proxy support is Mozilla browsers (former Netscape).
But other browsers do support proxy and has it's own proxy configuration
interpretation logic. Current GNOME proxy settings is a copy of Firefox
settings.

### Firefox
When using Firefox internal manual settings, the proxy is selected base on the
most specific proxy (e.g. HTTP before SOCKS). Only one proxy is selected, if
connection to that proxy fails, then connection fails.

```
 IF protocol specific proxy is set THEN use it
 ELSE IF SOCKS proxy is set THEN use it
 ELSE use direct connection.
```

### Firefox and Chromium (with GNOME settings)
After some testing we found that Chromium mimics perfectly Firefox behavior
when using system settings. When using manual proxy configuration mode, those
browsers chooses a proxy base on the most generic solution (SOCKS) to the most
specific (per protocol proxies), with an exception when a single proxy is set
for all protocols. Only one protocol is selected and no fallback will occur in
the case of failures. Those browsers support SOCKS, HTTP, HTTPS, FTP and
Firefox also support Gopher. You can also set the configuration to use a
specific PAC file or to automatically discover one (WPAD) but those does not
contain any special logic. Next is the logic represent as pseudo code:

```
 IF not using same proxy for all protocols THEN
   IF SOCKS is set THEN use it
   ELSE IF protocol specific proxy is set THEN use it
   ELSE IF using same proxy for all protocols THEN
    IF SOCKS is set THEN use it
 IF no proxy has been set THEN use direct connection
```

## OS X
OS X uses it's own way for proxy settings. It supports protocols including
SOCKS, HTTP, HTTPS, FTP, Gopher, RTSP, and automatic configuration through PAC
files. For sake of simplicity, we have tested the logic with the default browser
Safari.

### Safari
Safari interpret proxy logic differently from Firefox. If multiple proxy are
configured, it try each of them until a connection is established. From our
testing the order seems to be from most specific to most generic (starting with
manual configuration). Next is the logic represented as pseudo code:

```
 DEFINE proxy_list as list
 IF protocol specific proxy is set THEN add it to proxy_list
 IF SOCKS proxy is set THEN append it to proxy_list
 IF PAC auto-configuration is set THEN append it to proxy_list
 FOREACH proxy in proxy_list
   connect to proxy
   IF connection failed THEN continue
   ELSE stop
```

## Windows
Windows user most often use Internet Explorer, Firefox or Opera for browsing.
Analyses as shown that Firefox acts exactly the same as on Linux, except that
same logic is applied for internal settings and system setting (IE settings).
Internet explorer also act the same way, and Opera only support protocol
specific proxies (no SOCKS). So essentially, if chooses choose the most
specific proxy, and if that one fails the own connection fails.

## Conclusion
Base on current result, we see that the most common logic is to select a proxy
starting from the most specific (HTTP, FTP, etc.) to the least specific
(SOCKS, PAC then WPAD). OS X pushes a bit further by trying all the configure
proxy that match the protocol. This technique is interesting for libproxy
since it warranty that connection will be possible for all cases covered by
the others. The only difference with the GNOME environment is that OS X may
connect through an HTTP server while Firefox and Chromium (on Gnome) would
connect to a SOCKS server if both are available.
07070100000016000081A400000000000000000000000166FD57170000053D000000000000000000000000000000000000002100000000libproxy-0.5.9/docs/libproxy.svg<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g fill="#2a488c"><path d="M4.96 8.635V11H1.367c-.206 0-.368.205-.368.467v1.058c0 .262.162.467.368.467h10.264c.206 0 .368-.205.368-.467v-1.058c0-.262-.162-.467-.368-.467H7.977V8.635z"/><path d="M3.8 0C2.849 0 2 .793 2 1.746v6.613c0 .953.849 1.746 1.868 1.746h5.264c1.02 0 1.868-.793 1.868-1.746V1.746C11 .793 10.151 0 9.132 0zM4 2h5c0 .317 0-.316 0 0v6H4s0 .044 0 0V2c0-.044 0 0 0 0z" style="line-height:normal;-inkscape-font-specification:'Bitstream Vera Sans';text-indent:0;text-align:start;text-decoration-line:none;text-transform:none;marker:none" color="#fff" font-weight="400" font-family="Bitstream Vera Sans" overflow="visible"/><path d="M5 2.971h3v1.003H5zm2 2.005h1v1.002H7z" style="marker:none" color="#fff" overflow="visible"/><path d="M9.229 3c.07 0 0 .209 0 .476v1.078c0 .267.07.476.16.476h4.451c.09 0 .16-.209.16-.476V3.476c0-.267-.07-.476-.16-.476-.16 0-4.585.063-4.611 0zm-3.256 8.624c.08-.06.253.039.394.223l.573.747c.142.184.191.375.112.435l-3.935 2.954c-.08.059-.253-.039-.395-.224l-.573-.746c-.141-.184-.19-.376-.111-.435 0 0 3.946-2.893 3.935-2.954z"/><path d="M7.027 11.624c-.08-.06-.253.039-.394.223l-.573.747c-.142.184-.191.375-.112.435l3.935 2.954c.08.059.253-.039.395-.224l.573-.746c.141-.184.19-.376.111-.435 0 0-3.946-2.893-3.935-2.954z"/></g></svg>07070100000017000081A400000000000000000000000166FD5717000003CC000000000000000000000000000000000000002000000000libproxy-0.5.9/docs/meson.buildif get_option('docs')

expand_content_md_files = [
  'architecture.md',
  'applications.md',
  'build-steps.md',
  'configuration-logic.md',
  'perl.md',
  'python.md',
  'ruby.md',
  'vala.md',
]

toml_data = configuration_data()
toml_data.set('VERSION', meson.project_version())

px_toml = configure_file(
  input: 'px.toml.in',
  output: 'px.toml',
  configuration: toml_data
)

gidocgen = find_program('gi-docgen')

docs_dir = datadir / 'doc'

custom_target('px-doc',
  input: [ px_toml, libproxy_gir[0] ],
  output: 'libproxy-@0@'.format(api_version),
  command: [
    gidocgen,
    'generate',
    '--quiet',
    '--add-include-path=@0@'.format(meson.current_source_dir() + '/src'),
    '--config=@INPUT0@',
    '--output-dir=@OUTPUT@',
    '--no-namespace-dir',
    '--content-dir=@0@'.format(meson.current_source_dir()),
    '@INPUT1@',
  ],
  depend_files: [ expand_content_md_files ],
  build_by_default: true,
  install: true,
  install_dir: docs_dir,
)

endif
07070100000018000081A400000000000000000000000166FD571700000196000000000000000000000000000000000000001C00000000libproxy-0.5.9/docs/perl.mdTitle: 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";
}
```
07070100000019000081A400000000000000000000000166FD5717000000F6000000000000000000000000000000000000002C00000000libproxy-0.5.9/docs/proxy-authentication.mdTitle: Proxy Authentication
Slug: ProxyAuthentication


# Proxy Authentication
Because proxy authentication is protocol specific, it is outside the scope of this library. libproxy tells you WHICH proxy servers to try to use,
not HOW to use them.
0707010000001A000081A400000000000000000000000166FD571700000660000000000000000000000000000000000000001F00000000libproxy-0.5.9/docs/px.toml.in[library]
version = "@VERSION@"
description = "Simplifyed proxy handling"
authors = "libproxy Team"
license = "LGPL-2.1-or-later"
browse_url = "https://github.com/libproxy/libproxy"
repository_url = "https://github.com/libproxy/libproxy"
website_url = "https://libproxy.github.io/libproxy/"
# logo_url = "libproxy.svg"
dependencies = [
  "GObject-2.0",
  "Gio-2.0",
  "GLib-2.0",
  "curl-1.0",
]
devhelp = true
search_index = true

[dependencies."GObject-2.0"]
name = "GObject"
description = "The base type system library"
docs_url = "https://developer.gnome.org/gobject/stable"

[dependencies."Gio-2.0"]
name = "Gio"
description = "Gio is a library providing useful classes for general purpose I/O, networking, IPC, settings, and other high level application functionality"
docs_url = "https://developer.gnome.org/gio/stable"

[dependencies."GLib-2.0"]
name = "GLib"
description = "The base utility library"
docs_url = "https://developer.gnome.org/glib/stable"

[dependencies."curl-1.0"]
name = "cURL"
description = "Library for transferring data"
docs_url = "https://github.com/curl/curl"

[theme]
name = "basic"
show_index_summary = false
show_class_hierarchy = false

[source-location]
# The base URL for the web UI
base_url = "https://gitlab.gnome.org/jbrummer/libproxy/-/blob/main/"
# The format for links, using "filename" and "line" for the format
file_format = "{filename}#L{line}"

[extra]
content_files = [
  "architecture.md",
  "applications.md",
  "build-steps.md",
  "configuration-logic.md",
  "proxy-authentication.md",
  "perl.md",
  "python.md",
  "ruby.md",
  "vala.md",
]

content_images = [
  "libproxy.svg"
]
0707010000001B000081A400000000000000000000000166FD571700000292000000000000000000000000000000000000001E00000000libproxy-0.5.9/docs/python.mdTitle: 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")
```

0707010000001C000081A400000000000000000000000166FD57170000012D000000000000000000000000000000000000001C00000000libproxy-0.5.9/docs/ruby.mdTitle: 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()
```
0707010000001D000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001C00000000libproxy-0.5.9/docs/samples0707010000001E000081A400000000000000000000000166FD571700000069000000000000000000000000000000000000001F00000000libproxy-0.5.9/docs/samples.mdTitle: How to use libproxy in language X?
Slug: building

# Samples - How to use libproxy in language X?
0707010000001F000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002300000000libproxy-0.5.9/docs/samples/dotnet07070100000020000081A400000000000000000000000166FD571700000062000000000000000000000000000000000000002C00000000libproxy-0.5.9/docs/samples/dotnet/Makefile
all: proxy.exe

proxy.exe: proxy.cs
	gmcs -pkg:libproxy-sharp-1.0 proxy.cs

clean:
	rm proxy.exe
07070100000021000081A400000000000000000000000166FD571700000626000000000000000000000000000000000000002C00000000libproxy-0.5.9/docs/samples/dotnet/proxy.cs/*******************************************************************************
 * libproxy - A library for proxy configuration
 * Copyright (C) 2009 Dominique Leuenberger <dominique@leuenberger.net>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 ******************************************************************************/

using System;
using 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;
        }
    }
}
07070100000022000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002400000000libproxy-0.5.9/docs/samples/libcurl07070100000023000081A400000000000000000000000166FD57170000008F000000000000000000000000000000000000002D00000000libproxy-0.5.9/docs/samples/libcurl/Makefile

all: curlget

curlget: curlget.c
	gcc curlget.c -o curlget -Wall -lcurl -std=c99 $(shell pkg-config --libs libproxy-1.0)

clean:
	rm curlget
07070100000024000081A400000000000000000000000166FD571700000E2C000000000000000000000000000000000000002E00000000libproxy-0.5.9/docs/samples/libcurl/curlget.c/*******************************************************************************
 * libproxy - A library for proxy configuration
 * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
 * Copyright (C) 2008 Dominique Leuenberger <dominique-libproxy@leuenberger.net>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 ******************************************************************************/

#include "proxy.h"
#include "curl/curl.h"
#include <string.h>
#include <stdlib.h>

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;
  
}

07070100000025000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002100000000libproxy-0.5.9/docs/samples/perl07070100000026000081A400000000000000000000000166FD571700000097000000000000000000000000000000000000002B00000000libproxy-0.5.9/docs/samples/perl/sample.pluse Net::Libproxy;

$p = new Net::Libproxy;
$proxies = $p->getProxies('http://www.google.com');
foreach my $proxy (@$proxies) {
  print $proxy."\n";
}
07070100000027000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002100000000libproxy-0.5.9/docs/samples/vala07070100000028000081A400000000000000000000000166FD57170000005A000000000000000000000000000000000000002A00000000libproxy-0.5.9/docs/samples/vala/Makefileall: sample

sample: sample.vala
	valac --pkg libproxy-1.0 sample.vala

clean:
	rm sample
07070100000029000081A400000000000000000000000166FD5717000000C8000000000000000000000000000000000000002D00000000libproxy-0.5.9/docs/samples/vala/sample.valausing 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);
	}
}
0707010000002A000081A400000000000000000000000166FD5717000001AE000000000000000000000000000000000000001C00000000libproxy-0.5.9/docs/vala.mdTitle: 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);
  }
}
```
0707010000002B000081A400000000000000000000000166FD57170000000A000000000000000000000000000000000000002300000000libproxy-0.5.9/docs/version.xml.in@VERSION@
0707010000002C000081A400000000000000000000000166FD5717000003E9000000000000000000000000000000000000001D00000000libproxy-0.5.9/libproxy.doap<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:foaf="http://xmlns.com/foaf/0.1/"
         xmlns:gnome="http://api.gnome.org/doap-extensions#"
         xmlns="http://usefulinc.com/ns/doap#">

  <name xml:lang="en">libproxy</name>
  <shortdesc xml:lang="en">libproxy is a library that provides automatic proxy configuration management.</shortdesc>
  <homepage rdf:resource="https://github.com/libproxy/libproxy/" />
  <download-page rdf:resource="https://github.com/libproxy/libproxy/releases" />
  <bug-database rdf:resource="https://github.com/libproxy/libproxy/issues" />
  <category rdf:resource="http://api.gnome.org/doap-extensions#productivity" />
  <programming-language>C</programming-language>

  <maintainer>
    <foaf:Person>
      <foaf:name>Jan-Michael Brummer</foaf:name>
      <foaf:mbox rdf:resource="mailto:jan-michael.brummer1@volkswagen.de" />
    </foaf:Person>
  </maintainer>
</Project>
0707010000002D000081A400000000000000000000000166FD571700001028000000000000000000000000000000000000001B00000000libproxy-0.5.9/meson.buildproject('libproxy', 'c',
          version: '0.5.9',
    meson_version: '>= 0.59.0',
  default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu11', ],
)

version_arr = meson.project_version().split('-')[0].split('.')
libproxy_version_major = version_arr[0].to_int()
libproxy_version_minor = version_arr[1].to_int()

root_dir = include_directories('.')

px_prefix = get_option('prefix')
datadir = get_option('datadir')
pkglibdir = join_paths(px_prefix, get_option('libdir'), 'libproxy')
girdir     = get_option('datadir') / 'gir-1.0'
typelibdir = get_option('libdir')  / 'girepository-1.0'
vapidir = get_option('datadir') / 'vala' / 'vapi'

add_project_arguments(['-I' + meson.project_build_root()], language: 'c')

# The major api version as encoded in the libraries name
api_version = '1.0'
package_api_name = '@0@-@1@'.format(meson.project_name(), api_version)

cc = meson.get_compiler('c')

project_c_args = []
test_c_args = [
  '-Wcast-align',
  '-Wdeclaration-after-statement',
  '-Werror=address',
  '-Werror=array-bounds',
  '-Werror=empty-body',
  '-Werror=implicit',
  '-Werror=implicit-function-declaration',
  '-Werror=incompatible-pointer-types',
  '-Werror=init-self',
  '-Werror=int-conversion',
  '-Werror=int-to-pointer-cast',
  '-Werror=main',
  '-Werror=misleading-indentation',
  '-Werror=missing-braces',
  '-Werror=missing-include-dirs',
  '-Werror=nonnull',
  '-Werror=overflow',
  '-Werror=parenthesis',
  '-Werror=pointer-arith',
  '-Werror=pointer-to-int-cast',
  '-Werror=redundant-decls',
  '-Werror=return-type',
  '-Werror=sequence-point',
  '-Werror=shadow',
  '-Werror=strict-prototypes',
  '-Werror=trigraphs',
  '-Werror=undef',
  '-Werror=write-strings',
  '-Wformat-nonliteral',
  '-Wignored-qualifiers',
  '-Wimplicit-function-declaration',
  '-Wlogical-op',
  '-Wmissing-declarations',
  '-Wmissing-format-attribute',
  '-Wmissing-include-dirs',
  '-Wmissing-noreturn',
  '-Wnested-externs',
  '-Wno-cast-function-type',
  '-Wno-dangling-pointer',
  '-Wno-missing-field-initializers',
  '-Wno-sign-compare',
  '-Wno-unused-parameter',
  '-Wold-style-definition',
  '-Wpointer-arith',
  '-Wredundant-decls',
  '-Wstrict-prototypes',
  '-Wswitch-default',
  '-Wswitch-enum',
  '-Wundef',
  '-Wuninitialized',
  '-Wunused',
  '-fno-strict-aliasing',
  ['-Werror=format-security', '-Werror=format=2'],
]

foreach arg: test_c_args
  if cc.has_multi_arguments(arg)
    project_c_args += arg
  endif
endforeach
add_project_arguments(project_c_args, language: 'c')

if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
warning_link_args = ['-Wl,-z,nodelete']
else
warning_link_args = []
endif

project_link_args = cc.get_supported_link_arguments(warning_link_args)
add_project_link_arguments (project_link_args, language: 'c')

host_system = host_machine.system()
with_platform_windows = host_system == 'windows'
with_platform_darwin = cc.compiles('''#include <Availability.h>
#include <TargetConditionals.h>
#if !TARGET_OS_OSX || __MAC_OS_X_VERSION_MIN_REQUIRED <= 100100L
#error "Not building for macOS"
#endif''')

module_suffix = []
# Keep the autotools convention for shared module suffix because GModule
# depends on it.
if with_platform_darwin
  module_suffix = 'so'
endif

glib_dep = dependency('glib-2.0', version: '>= 2.71.3')
gio_dep = dependency('gio-2.0', version: '>= 2.71.3')
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'))

subdir('src')
subdir('tests')
subdir('docs')

summary({
  'host cpu' : host_machine.cpu_family(),
  'host endian' : host_machine.endian(),
  'host system' : host_system,
  'C Compiler' : cc.get_id(),
  'Release' : get_option('release'),
}, section: 'Build environment')

summary({
  'Vapi' : get_option('vapi'),
}, section: 'Options')

if not get_option('release')
	# Install pre-commit hook
	hook = run_command(join_paths(meson.project_source_root(), 'data/install-git-hook.sh'), check: false)
	if hook.returncode() == 0
	  message(hook.stdout().strip())
	endif
endif
0707010000002E000081A400000000000000000000000166FD5717000006D4000000000000000000000000000000000000002100000000libproxy-0.5.9/meson_options.txtoption(
  'docs',
  type: 'boolean',
  value: true,
  description: 'Whether to generate the API reference for libproxy (requires introspection)'
)

option(
  'tests',
  type: 'boolean',
  value: true,
  description: 'Whether to compile test cases for libproxy'
)

option(
  'config-env',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for environment configuration'
)

option(
  'config-gnome',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for GNOME configuration'
)

option(
  'config-windows',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for Windows configuration'
)

option(
  'config-sysconfig',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for sysconfig configuration'
)

option(
  'config-osx',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for OS X configuration'
)

option(
  'config-kde',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for KDE System Settings'
)

option(
  'config-xdp',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for XDG Desktop Portal (Flatpak)'
)

option(
  'pacrunner-duktape',
  type: 'boolean',
  value: true,
  description: 'Whether to build support for PAC Runner Duktape'
)

option(
  'vapi',
  type: 'boolean',
  value: true,
  description: 'Whether to build vapi support'
)

option(
  'curl',
  type: 'boolean',
  value: true,
  description: 'Whether to build cURL support'
)

option(
  'introspection',
  type: 'boolean',
  value: true,
  description: 'Whether to build introspection support'
)

option(
  'release',
  type: 'boolean',
  value: false,
  description: 'Whether to compile for release'
)
0707010000002F000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001300000000libproxy-0.5.9/src07070100000030000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001B00000000libproxy-0.5.9/src/backend07070100000031000081A400000000000000000000000166FD5717000005E2000000000000000000000000000000000000002700000000libproxy-0.5.9/src/backend/meson.buildbackend_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_CONFIG_XDP', get_option('config-xdp'))
backend_config_h.set('HAVE_PACRUNNER_DUKTAPE', get_option('pacrunner-duktape'))
backend_config_h.set('HAVE_CURL', get_option('curl'))
configure_file(output: 'px-backend-config.h', configuration: backend_config_h)

px_backend_sources = [
  'px-manager.c',
  'px-manager.h',
  'px-plugin-config.c',
  'px-plugin-config.h',
  'px-plugin-pacrunner.c',
  'px-plugin-pacrunner.h',
]

px_backend_deps = [
  curl_dep,
  gio_dep,
  glib_dep,
  ws2_32_dep,
]

px_backend_c_args = [
  '-DG_LOG_DOMAIN="pxbackend"',
]

px_backend_inc = include_directories('.')

subdir('plugins')

px_backend = shared_library(
  'pxbackend-@0@'.format(api_version),
  px_backend_sources,
  dependencies: px_backend_deps,
  c_args: px_backend_c_args,
  install: true,
  install_dir: pkglibdir,
  install_rpath: pkglibdir
)

px_backend_dep = declare_dependency(
  include_directories: px_backend_inc,
  link_with: px_backend,
  dependencies: px_backend_deps
)
07070100000032000081A400000000000000000000000166FD5717000023F1000000000000000000000000000000000000002600000000libproxy-0.5.9/src/backend/pacutils.h/* 
 * The following Javascript code was taken from Mozilla (http://www.mozilla.org)
 * and is licensed according to the LGPLv2.1+.  Below is the original copyright 
 * header as contained in the source file (nsProxyAutoConfig.js)
 */
 
/* ***** BEGIN LICENSE BLOCK *****
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is mozilla.org code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1998
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Akhil Arora <akhil.arora@sun.com>
 *   Tomi Leppikangas <Tomi.Leppikangas@oulu.fi>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the NPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the NPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#define JAVASCRIPT_ROUTINES \
"function dnsDomainIs(host, domain) {\n" \
"    return (host.length >= domain.length &&\n" \
"            host.substring(host.length - domain.length) == domain);\n" \
"}\n" \
"function dnsDomainLevels(host) {\n" \
"    return host.split('.').length-1;\n" \
"}\n" \
"function convert_addr(ipchars) {\n" \
"    var bytes = ipchars.split('.');\n" \
"    var result = ((bytes[0] & 0xff) << 24) |\n" \
"                 ((bytes[1] & 0xff) << 16) |\n" \
"                 ((bytes[2] & 0xff) << 8) |\n" \
"                  (bytes[3] & 0xff);\n" \
"    return result;\n" \
"}\n" \
"function isInNet(ipaddr, pattern, maskstr) {\n"\
"    var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(ipaddr);\n"\
"    if (test == null) {\n"\
"        ipaddr = dnsResolve(ipaddr);\n"\
"        if (ipaddr == null)\n"\
"            return false;\n"\
"    } else if (test[1] > 255 || test[2] > 255 || \n"\
"               test[3] > 255 || test[4] > 255) {\n"\
"        return false;    // not an IP address\n"\
"    }\n"\
"    var host = convert_addr(ipaddr);\n"\
"    var pat  = convert_addr(pattern);\n"\
"    var mask = convert_addr(maskstr);\n"\
"    return ((host & mask) == (pat & mask));\n"\
"    \n"\
"}\n"\
"function isPlainHostName(host) {\n" \
"    return (host.search('\\\\.') == -1);\n" \
"}\n" \
"function isResolvable(host) {\n" \
"    var ip = dnsResolve(host);\n" \
"    return (ip != null);\n" \
"}\n" \
"function localHostOrDomainIs(host, hostdom) {\n" \
"    if (isPlainHostName(host)) {\n" \
"        return (hostdom.search('/^' + host + '/') != -1);\n" \
"    }\n" \
"    else {\n" \
"        return (host == hostdom);\n" \
"    }\n" \
"}\n" \
"function shExpMatch(url, pattern) {\n" \
"   pattern = pattern.replace(/\\./g, '\\\\.');\n" \
"   pattern = pattern.replace(/\\*/g, '.*');\n" \
"   pattern = pattern.replace(/\\?/g, '.');\n" \
"   var newRe = new RegExp('^'+pattern+'$');\n" \
"   return newRe.test(url);\n" \
"}\n" \
"var wdays = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};\n" \
"var months = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};\n"\
"function weekdayRange() {\n" \
"    function getDay(weekday) {\n" \
"        if (weekday in wdays) {\n" \
"            return wdays[weekday];\n" \
"        }\n" \
"        return -1;\n" \
"    }\n" \
"    var date = new Date();\n" \
"    var argc = arguments.length;\n" \
"    var wday;\n" \
"    if (argc < 1)\n" \
"        return false;\n" \
"    if (arguments[argc - 1] == 'GMT') {\n" \
"        argc--;\n" \
"        wday = date.getUTCDay();\n" \
"    } else {\n" \
"        wday = date.getDay();\n" \
"    }\n" \
"    var wd1 = getDay(arguments[0]);\n" \
"    var wd2 = (argc == 2) ? getDay(arguments[1]) : wd1;\n" \
"    return (wd1 == -1 || wd2 == -1) ? false\n" \
"                                    : (wd1 <= wday && wday <= wd2);\n" \
"}\n" \
"function dateRange() {\n" \
"    function getMonth(name) {\n" \
"        if (name in months) {\n" \
"            return months[name];\n" \
"        }\n" \
"        return -1;\n" \
"    }\n" \
"    var date = new Date();\n" \
"    var argc = arguments.length;\n" \
"    if (argc < 1) {\n" \
"        return false;\n" \
"    }\n" \
"    var isGMT = (arguments[argc - 1] == 'GMT');\n" \
"    if (isGMT) {\n" \
"        argc--;\n" \
"    }\n" \
"    if (argc == 1) {\n" \
"        var tmp = parseInt(arguments[0]);\n" \
"        if (isNaN(tmp)) {\n" \
"            return ((isGMT ? date.getUTCMonth() : date.getMonth()) == getMonth(arguments[0]));\n" \
"        } else if (tmp < 32) {\n" \
"            return ((isGMT ? date.getUTCDate() : date.getDate()) == tmp);\n" \
"        } else {\n" \
"            return ((isGMT ? date.getUTCFullYear() : date.getFullYear()) == tmp);\n" \
"        }\n" \
"    }\n" \
"    var year = date.getFullYear();\n" \
"    var date1, date2;\n" \
"    date1 = new Date(year, 0, 1, 0, 0, 0);\n" \
"    date2 = new Date(year, 11, 31, 23, 59, 59);\n" \
"    var adjustMonth = false;\n" \
"    for (var i = 0; i < (argc >> 1); i++) {\n" \
"        var tmp = parseInt(arguments[i]);\n" \
"        if (isNaN(tmp)) {\n" \
"            var mon = getMonth(arguments[i]);\n" \
"            date1.setMonth(mon);\n" \
"        } else if (tmp < 32) {\n" \
"            adjustMonth = (argc <= 2);\n" \
"            date1.setDate(tmp);\n" \
"        } else {\n" \
"            date1.setFullYear(tmp);\n" \
"        }\n" \
"    }\n" \
"    for (var i = (argc >> 1); i < argc; i++) {\n" \
"        var tmp = parseInt(arguments[i]);\n" \
"        if (isNaN(tmp)) {\n" \
"            var mon = getMonth(arguments[i]);\n" \
"            date2.setMonth(mon);\n" \
"        } else if (tmp < 32) {\n" \
"            date2.setDate(tmp);\n" \
"        } else {\n" \
"            date2.setFullYear(tmp);\n" \
"        }\n" \
"    }\n" \
"    if (adjustMonth) {\n" \
"        date1.setMonth(date.getMonth());\n" \
"        date2.setMonth(date.getMonth());\n" \
"    }\n" \
"    if (isGMT) {\n" \
"    var tmp = date;\n" \
"        tmp.setFullYear(date.getUTCFullYear());\n" \
"        tmp.setMonth(date.getUTCMonth());\n" \
"        tmp.setDate(date.getUTCDate());\n" \
"        tmp.setHours(date.getUTCHours());\n" \
"        tmp.setMinutes(date.getUTCMinutes());\n" \
"        tmp.setSeconds(date.getUTCSeconds());\n" \
"        date = tmp;\n" \
"    }\n" \
"    return ((date1 <= date) && (date <= date2));\n" \
"}\n" \
"function timeRange() {\n" \
"    var argc = arguments.length;\n" \
"    var date = new Date();\n" \
"    var isGMT= false;\n" \
"    if (argc < 1) {\n" \
"        return false;\n" \
"    }\n" \
"    if (arguments[argc - 1] == 'GMT') {\n" \
"        isGMT = true;\n" \
"        argc--;\n" \
"    }\n" \
"    var hour = isGMT ? date.getUTCHours() : date.getHours();\n" \
"    var date1, date2;\n" \
"    date1 = new Date();\n" \
"    date2 = new Date();\n" \
"    if (argc == 1) {\n" \
"        return (hour == arguments[0]);\n" \
"    } else if (argc == 2) {\n" \
"        return ((arguments[0] <= hour) && (hour <= arguments[1]));\n" \
"    } else {\n" \
"        switch (argc) {\n" \
"        case 6:\n" \
"            date1.setSeconds(arguments[2]);\n" \
"            date2.setSeconds(arguments[5]);\n" \
"        case 4:\n" \
"            var middle = argc >> 1;\n" \
"            date1.setHours(arguments[0]);\n" \
"            date1.setMinutes(arguments[1]);\n" \
"            date2.setHours(arguments[middle]);\n" \
"            date2.setMinutes(arguments[middle + 1]);\n" \
"            if (middle == 2) {\n" \
"                date2.setSeconds(59);\n" \
"            }\n" \
"            break;\n" \
"        default:\n" \
"          throw 'timeRange: bad number of arguments'\n" \
"        }\n" \
"    }\n" \
"    if (isGMT) {\n" \
"        date.setFullYear(date.getUTCFullYear());\n" \
"        date.setMonth(date.getUTCMonth());\n" \
"        date.setDate(date.getUTCDate());\n" \
"        date.setHours(date.getUTCHours());\n" \
"        date.setMinutes(date.getUTCMinutes());\n" \
"        date.setSeconds(date.getUTCSeconds());\n" \
"    }\n" \
"    return ((date1 <= date) && (date <= date2));\n" \
"}\n" \
""
07070100000033000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002300000000libproxy-0.5.9/src/backend/plugins07070100000034000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002E00000000libproxy-0.5.9/src/backend/plugins/config-env07070100000035000081A400000000000000000000000166FD571700000E02000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-env/config-env.c/* config-env.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include "config-env.h"

#include "px-manager.h"
#include "px-plugin-config.h"

static void px_config_iface_init (PxConfigInterface *iface);

struct _PxConfigEnv {
  GObject parent_instance;
};

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigEnv,
                               px_config_env,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void
px_config_env_init (PxConfigEnv *self)
{
}

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->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 void
px_config_env_get_config (PxConfig     *config,
                          GUri         *uri,
                          GStrvBuilder *builder)
{
  const char *proxy = NULL;
  const char *scheme = g_uri_get_scheme (uri);

  proxy = g_getenv ("no_proxy");
  if (!proxy)
    proxy = g_getenv ("NO_PROXY");

  if (proxy) {
    g_auto (GStrv) no_proxy = g_strsplit (proxy, ",", -1);

    if (px_manager_is_ignore (uri, no_proxy))
      return;

    proxy = NULL;
  }

  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)
    px_strv_builder_add_proxy (builder, proxy);
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-env";
  iface->priority = PX_CONFIG_PRIORITY_FIRST;
  iface->get_config = px_config_env_get_config;
}
07070100000036000081A400000000000000000000000166FD571700000424000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-env/config-env.h/* config-env.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_ENV         (px_config_env_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigEnv, px_config_env, PX, CONFIG_ENV, GObject)

G_END_DECLS


07070100000037000081A400000000000000000000000166FD571700000083000000000000000000000000000000000000003A00000000libproxy-0.5.9/src/backend/plugins/config-env/meson.buildplugin_name = 'config-env'

if get_option(plugin_name)

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif07070100000038000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000003000000000libproxy-0.5.9/src/backend/plugins/config-gnome07070100000039000081A400000000000000000000000166FD571700001D58000000000000000000000000000000000000003F00000000libproxy-0.5.9/src/backend/plugins/config-gnome/config-gnome.c/* config-gnome.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include "config-gnome.h"

#include "px-plugin-config.h"
#include "px-manager.h"

struct _PxConfigGnome {
  GObject parent_instance;
  GSettings *proxy_settings;
  GSettings *http_proxy_settings;
  GSettings *https_proxy_settings;
  GSettings *ftp_proxy_settings;
  GSettings *socks_proxy_settings;
  gboolean available;
};

typedef enum {
  GNOME_PROXY_MODE_NONE,
  GNOME_PROXY_MODE_MANUAL,
  GNOME_PROXY_MODE_AUTO
} GnomeProxyMode;

static void px_config_iface_init (PxConfigInterface *iface);

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigGnome,
                               px_config_gnome,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void
px_config_gnome_init (PxConfigGnome *self)
{
  GSettingsSchemaSource *source;
  g_autoptr (GSettingsSchema) proxy_schema = 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, "GNOME") == NULL)
    return;

  source = g_settings_schema_source_get_default ();
  if (!source) {
    g_warning ("GNOME desktop detected but no schemes installed, aborting.");
    return;
  }

  proxy_schema = g_settings_schema_source_lookup (source, "org.gnome.system.proxy", TRUE);

  self->available = proxy_schema != NULL;
  if (!self->available)
    return;

  self->proxy_settings = g_settings_new ("org.gnome.system.proxy");
  self->http_proxy_settings = g_settings_new ("org.gnome.system.proxy.http");
  self->https_proxy_settings = g_settings_new ("org.gnome.system.proxy.https");
  self->ftp_proxy_settings = g_settings_new ("org.gnome.system.proxy.ftp");
  self->socks_proxy_settings = g_settings_new ("org.gnome.system.proxy.socks");
}

static void
px_config_gnome_set_property (GObject      *object,
                              guint         prop_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_gnome_get_property (GObject    *object,
                              guint       prop_id,
                              GValue     *value,
                              GParamSpec *pspec)
{
  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_gnome_class_init (PxConfigGnomeClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = px_config_gnome_set_property;
  object_class->get_property = px_config_gnome_get_property;

  g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
}

static void
store_response (GStrvBuilder *builder,
                const char   *type,
                char         *host,
                int           port,
                gboolean      auth,
                char         *username,
                char         *password)
{
  if (type && host && strlen (type) > 0 && strlen (host) > 0 && port != 0) {
    g_autoptr (GString) tmp = g_string_new (type);

    g_string_append (tmp, "://");
    if (auth)
      g_string_append_printf (tmp, "%s:%s@", username, password);

    g_string_append_printf (tmp, "%s:%d", host, port);

    px_strv_builder_add_proxy (builder, tmp->str);
  }
}

static void
px_config_gnome_get_config (PxConfig     *config,
                            GUri         *uri,
                            GStrvBuilder *builder)
{
  PxConfigGnome *self = PX_CONFIG_GNOME (config);
  g_autofree char *proxy = NULL;
  GnomeProxyMode mode;

  if (!self->available)
    return;

  mode = g_settings_get_enum (self->proxy_settings, "mode");
  if (mode == GNOME_PROXY_MODE_NONE)
    return;

  if (px_manager_is_ignore (uri, g_settings_get_strv (self->proxy_settings, "ignore-hosts")))
    return;

  if (mode == GNOME_PROXY_MODE_AUTO) {
    char *autoconfig_url = g_settings_get_string (self->proxy_settings, "autoconfig-url");

    if (strlen (autoconfig_url) != 0)
      proxy = g_strdup_printf ("pac+%s", autoconfig_url);
    else
      proxy = g_strdup ("wpad://");

    px_strv_builder_add_proxy (builder, proxy);
  } else if (mode == GNOME_PROXY_MODE_MANUAL) {
    g_autofree char *username = g_settings_get_string (self->http_proxy_settings, "authentication-user");
    g_autofree char *password = g_settings_get_string (self->http_proxy_settings, "authentication-password");
    const char *scheme = g_uri_get_scheme (uri);
    gboolean auth = g_settings_get_boolean (self->http_proxy_settings, "use-authentication");

    if (g_strcmp0 (scheme, "http") == 0) {
      g_autofree char *host = g_settings_get_string (self->http_proxy_settings, "host");
      store_response (builder,
                      "http",
                      host,
                      g_settings_get_int (self->http_proxy_settings, "port"),
                      auth,
                      username,
                      password);
    } else if (g_strcmp0 (scheme, "https") == 0) {
      g_autofree char *host = g_settings_get_string (self->https_proxy_settings, "host");
      store_response (builder,
                      "http",
                      host,
                      g_settings_get_int (self->https_proxy_settings, "port"),
                      auth,
                      username,
                      password);
    } else if (g_strcmp0 (scheme, "ftp") == 0) {
      g_autofree char *host = g_settings_get_string (self->ftp_proxy_settings, "host");
      store_response (builder,
                      "http",
                      host,
                      g_settings_get_int (self->ftp_proxy_settings, "port"),
                      auth,
                      username,
                      password);
    } else {
      g_autofree char *host = g_settings_get_string (self->socks_proxy_settings, "host");
      store_response (builder,
                      "socks",
                      host,
                      g_settings_get_int (self->socks_proxy_settings, "port"),
                      auth,
                      username,
                      password);
    }
  }
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-gnome";
  iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
  iface->get_config = px_config_gnome_get_config;
}
0707010000003A000081A400000000000000000000000166FD571700000437000000000000000000000000000000000000003F00000000libproxy-0.5.9/src/backend/plugins/config-gnome/config-gnome.h/* config-gnome.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_GNOME         (px_config_gnome_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigGnome, px_config_gnome, PX, CONFIG_GNOME, GObject)

G_END_DECLS


0707010000003B000081A400000000000000000000000166FD571700000085000000000000000000000000000000000000003C00000000libproxy-0.5.9/src/backend/plugins/config-gnome/meson.buildplugin_name = 'config-gnome'

if get_option(plugin_name)

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif0707010000003C000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002E00000000libproxy-0.5.9/src/backend/plugins/config-kde0707010000003D000081A400000000000000000000000166FD571700002262000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-kde/config-kde.c/* config-kde.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include "config-kde.h"

#include "px-plugin-config.h"
#include "px-manager.h"

static void px_config_iface_init (PxConfigInterface *iface);

typedef enum {
  KDE_PROXY_TYPE_NONE = 0,
  KDE_PROXY_TYPE_MANUAL,
  KDE_PROXY_TYPE_PAC,
  KDE_PROXY_TYPE_WPAD,
  KDE_PROXY_TYPE_SYSTEM,
} KdeProxyType;

struct _PxConfigKde {
  GObject parent_instance;

  char *config_file;
  gboolean available;
  GFileMonitor *monitor;

  GStrv no_proxy;
  char *http_proxy;
  char *https_proxy;
  char *ftp_proxy;
  char *socks_proxy;
  KdeProxyType proxy_type;
  char *pac_script;
  gboolean reversed_exception;
};

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigKde,
                               px_config_kde,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void px_config_kde_set_config_file (PxConfigKde *self,
                                           char        *proxy_file);

static void
on_file_changed (GFileMonitor      *monitor,
                 GFile             *file,
                 GFile             *other_file,
                 GFileMonitorEvent  event_type,
                 gpointer           user_data)
{
  PxConfigKde *self = PX_CONFIG_KDE (user_data);

  g_debug ("%s: Reloading configuration\n", __FUNCTION__);
  px_config_kde_set_config_file (self, g_file_get_path (file));
}

static void
px_config_kde_set_config_file (PxConfigKde *self,
                               char        *proxy_file)
{
  g_autoptr (GError) error = NULL;
  g_autofree char *line = NULL;
  g_autoptr (GFile) file = NULL;
  g_autoptr (GFileInputStream) istr = NULL;
  g_autoptr (GDataInputStream) dstr = NULL;
  const char *desktops;

  self->available = FALSE;

  desktops = getenv ("XDG_CURRENT_DESKTOP");
  if (!desktops)
    return;

  /* Remember that XDG_CURRENT_DESKTOP is a list of strings. */
  if (strstr (desktops, "KDE") == NULL)
    return;

  g_clear_pointer (&self->config_file, g_free);
  self->config_file = proxy_file ? g_strdup (proxy_file) : g_build_filename (g_get_user_config_dir (), "kioslaverc", NULL);

  file = g_file_new_for_path (self->config_file);
  istr = g_file_read (file, NULL, NULL);
  if (!istr) {
    g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file);
    return;
  }

  dstr = g_data_input_stream_new (G_INPUT_STREAM (istr));

  g_clear_object (&self->monitor);
  self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error);
  if (!self->monitor)
    g_warning ("Could not add a file monitor for %s, error: %s", g_file_get_uri (file), error->message);
  else
    g_signal_connect_object (G_OBJECT (self->monitor), "changed", G_CALLBACK (on_file_changed), self, 0);

  do {
    g_clear_pointer (&line, g_free);

    line = g_data_input_stream_read_line (dstr, NULL, NULL, &error);
    if (line) {
      g_auto (GStrv) kv = NULL;
      g_autoptr (GString) value = NULL;
      kv = g_strsplit (line, "=", 2);

      if (g_strv_length (kv) != 2)
        continue;

      value = g_string_new (kv[1]);
      g_string_replace (value, "\"", "", 0);
      g_string_replace (value, " ", ":", 0);
      g_string_replace (value, "\r", "", 0);

      if (strcmp (kv[0], "httpsProxy") == 0) {
        self->https_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "httpProxy") == 0) {
        self->http_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "ftpProxy") == 0) {
        self->ftp_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "socksProxy") == 0) {
        self->socks_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "NoProxyFor") == 0) {
        self->no_proxy = g_strsplit (value->str, ",", -1);
      } else if (strcmp (kv[0], "Proxy Config Script") == 0) {
        self->pac_script = g_strdup (value->str);
      } else if (strcmp (kv[0], "ProxyType") == 0) {
        self->proxy_type = atoi (value->str);
      } else if (strcmp (kv[0], "ReversedException") == 0) {
        self->reversed_exception = !!atoi (value->str);
      }
    }
  } while (line);

  self->available = TRUE;
}


static void
px_config_kde_init (PxConfigKde *self)
{
  px_config_kde_set_config_file (self, NULL);
}

static void
px_config_kde_dispose (GObject *object)
{
  PxConfigKde *self = PX_CONFIG_KDE (object);

  g_clear_pointer (&self->config_file, g_free);
  g_clear_object (&self->monitor);
  g_clear_pointer (&self->no_proxy, g_strfreev);
  g_clear_pointer (&self->http_proxy, g_free);
  g_clear_pointer (&self->https_proxy, g_free);
  g_clear_pointer (&self->ftp_proxy, g_free);
  g_clear_pointer (&self->socks_proxy, g_free);
  g_clear_pointer (&self->pac_script, g_free);

  G_OBJECT_CLASS (px_config_kde_parent_class)->dispose (object);
}

static void
px_config_kde_set_property (GObject      *object,
                            guint         prop_id,
                            const GValue *value,
                            GParamSpec   *pspec)
{
  PxConfigKde *config = PX_CONFIG_KDE (object);

  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      px_config_kde_set_config_file (config, g_value_dup_string (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_kde_get_property (GObject    *object,
                            guint       prop_id,
                            GValue     *value,
                            GParamSpec *pspec)
{
  PxConfigKde *config = PX_CONFIG_KDE (object);

  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      g_value_set_string (value, config->config_file);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_kde_class_init (PxConfigKdeClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = px_config_kde_dispose;
  object_class->set_property = px_config_kde_set_property;
  object_class->get_property = px_config_kde_get_property;

  g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
}

static void
px_config_kde_get_config (PxConfig     *config,
                          GUri         *uri,
                          GStrvBuilder *builder)
{
  PxConfigKde *self = PX_CONFIG_KDE (config);
  const char *scheme;
  g_autofree char *proxy = NULL;

  if (!self->available)
    return;

  if (self->proxy_type == KDE_PROXY_TYPE_NONE)
    return;

  if (self->reversed_exception) {
    /* ReversedException flips the meaning of the ignore list */
    if (!px_manager_is_ignore (uri, self->no_proxy))
      return;
  } else {
    if (px_manager_is_ignore (uri, self->no_proxy))
      return;
  }

  scheme = g_uri_get_scheme (uri);

  switch (self->proxy_type) {
    case KDE_PROXY_TYPE_MANUAL:
    case KDE_PROXY_TYPE_SYSTEM:
      /* System is the same as manual, except that a button for auto dection
       * is shown. Based on this manual fields are set.
       */
      if (g_strcmp0 (scheme, "ftp") == 0) {
        proxy = g_strdup (self->ftp_proxy);
      } else if (g_strcmp0 (scheme, "https") == 0) {
        proxy = g_strdup (self->https_proxy);
      } else if (g_strcmp0 (scheme, "http") == 0) {
        proxy = g_strdup (self->http_proxy);
      } else if (self->socks_proxy && strlen (self->socks_proxy) > 0) {
        proxy = g_strdup (self->socks_proxy);
      }
      break;
    case KDE_PROXY_TYPE_WPAD:
      proxy = g_strdup ("wpad://");
      break;
    case KDE_PROXY_TYPE_PAC:
      proxy = g_strdup_printf ("pac+%s", self->pac_script);
      break;
    case KDE_PROXY_TYPE_NONE:
    default:
      break;
  }

  if (proxy)
    px_strv_builder_add_proxy (builder, proxy);
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-kde";
  iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
  iface->get_config = px_config_kde_get_config;
}
0707010000003E000081A400000000000000000000000166FD571700000424000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-kde/config-kde.h/* config-kde.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_KDE         (px_config_kde_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigKde, px_config_kde, PX, CONFIG_KDE, GObject)

G_END_DECLS


0707010000003F000081A400000000000000000000000166FD571700000083000000000000000000000000000000000000003A00000000libproxy-0.5.9/src/backend/plugins/config-kde/meson.buildplugin_name = 'config-kde'

if get_option(plugin_name)

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif07070100000040000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002E00000000libproxy-0.5.9/src/backend/plugins/config-osx07070100000041000081A400000000000000000000000166FD571700001EF5000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-osx/config-osx.c/* config-osx.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <SystemConfiguration/SystemConfiguration.h>

#include <gio/gio.h>

#include "config-osx.h"

#include "px-plugin-config.h"
#include "px-manager.h"

static void px_config_iface_init (PxConfigInterface *iface);

struct _PxConfigOsX {
  GObject parent_instance;
};

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigOsX,
                               px_config_osx,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void
px_config_osx_set_property (GObject      *object,
                            guint         prop_id,
                            const GValue *value,
                            GParamSpec   *pspec)
{
  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_osx_get_property (GObject    *object,
                            guint       prop_id,
                            GValue     *value,
                            GParamSpec *pspec)
{
  switch (prop_id) {
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_osx_init (PxConfigOsX *self)
{
}

static void
px_config_osx_class_init (PxConfigOsXClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = px_config_osx_set_property;
  object_class->get_property = px_config_osx_get_property;

  g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
}

static CFNumberRef
getobj (CFDictionaryRef  settings,
        char            *key)
{
  CFStringRef k;
  CFNumberRef retval;

  if (!settings)
    return NULL;

  k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman);
  if (!k)
    return NULL;

  retval = (CFNumberRef)CFDictionaryGetValue (settings, k);

  CFRelease (k);
  return retval;
}

static CFStringRef
getobj_str (CFDictionaryRef  settings,
            char            *key)
{
  CFStringRef k;
  CFStringRef retval;

  if (!settings)
    return NULL;

  k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman);
  if (!k)
    return NULL;

  retval = (CFStringRef)CFDictionaryGetValue (settings, k);

  CFRelease (k);
  return retval;
}

static CFArrayRef
getobj_array (CFDictionaryRef  settings,
              char            *key)
{
  CFStringRef k;
  CFArrayRef retval;

  if (!settings)
    return NULL;

  k = CFStringCreateWithCString (NULL, key, kCFStringEncodingMacRoman);
  if (!k)
    return NULL;

  retval = (CFArrayRef)CFDictionaryGetValue (settings, k);

  CFRelease (k);
  return retval;
}

static char *
str (CFStringRef ref)
{
  CFIndex size = CFStringGetLength (ref) + 1;
  char *ret = g_malloc0 (size);

  CFStringGetCString (ref, ret, size, kCFStringEncodingUTF8);

  return ret;
}

static gboolean
getint (CFDictionaryRef  settings,
        char            *key,
        int64_t         *answer)
{
  CFNumberRef n = getobj (settings, key);

  if (!n)
    return FALSE;

  if (!CFNumberGetValue (n, kCFNumberSInt64Type, answer))
    return FALSE;

  return TRUE;
}

static gboolean
getbool (CFDictionaryRef  settings,
         char            *key)
{
  int64_t i = 0;

  if (!getint (settings, key, &i))
    return FALSE;

  return i != 0;
}

static char *
str_to_upper (const char *str)
{
  char *ret = NULL;
  int idx;

  if (!str)
    return NULL;

  ret = g_malloc0 (strlen (str) + 1);

  for (idx = 0; idx < strlen (str); idx++)
    ret[idx] = g_ascii_toupper (str[idx]);

  return ret;
}

static char *
protocol_url (CFDictionaryRef  settings,
              char            *protocol)
{
  g_autofree char *tmp = NULL;
  g_autoptr (GString) ret = NULL;
  g_autofree char *host = NULL;
  int64_t port;
  CFStringRef ref;

  /* Check ProtocolEnabled */
  tmp = g_strconcat (protocol, "Enable", NULL);
  if (!getbool (settings, tmp)) {
    g_debug ("%s: %s not set", __FUNCTION__, tmp);
    return NULL;
  }
  g_clear_pointer (&tmp, g_free);

  /* Get ProtocolPort */
  tmp = g_strconcat (protocol, "Port", NULL);
  getint (settings, tmp, &port);
  if (!port) {
    g_debug ("%s: %s not set", __FUNCTION__, tmp);
    return NULL;
  }
  g_clear_pointer (&tmp, g_free);

  /* Get ProtocolProxy */
  tmp = g_strconcat (protocol, "Proxy", NULL);
  ref = getobj_str (settings, tmp);
  g_clear_pointer (&tmp, g_free);

  host = str (ref);
  if (!host || strlen (host) == 0)
    return NULL;

  if (strcmp (protocol, "HTTP") == 0 || strcmp (protocol, "HTTPS") == 0 || strcmp (protocol, "FTP") == 0 || strcmp (protocol, "Gopher") == 0)
    ret = g_string_new ("http://");
  else if (strcmp (protocol, "RTSP") == 0)
    ret = g_string_new ("rtsp://");
  else if (strcmp (protocol, "SOCKS") == 0)
    ret = g_string_new ("socks://");
  else
    return NULL;

  g_string_append_printf (ret, "%s:%lld", host, port);

  return g_strdup (ret->str);
}

static GStrv
get_ignore_list (CFDictionaryRef proxies)
{
  CFArrayRef ref = getobj_array (proxies, "ExceptionsList");
  g_autoptr (GStrvBuilder) ret = g_strv_builder_new ();

  if (!ref)
    return g_strv_builder_end (ret);

  for (int idx = 0; idx < CFArrayGetCount (ref); idx++) {
    CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex (ref, idx);

    px_strv_builder_add_proxy (ret, str (s));
  }

  if (getbool (proxies, "ExcludeSimpleHostnames"))
    px_strv_builder_add_proxy (ret, "127.0.0.1");

  return g_strv_builder_end (ret);
}

static void
px_config_osx_get_config (PxConfig     *self,
                          GUri         *uri,
                          GStrvBuilder *builder)
{
  const char *proxy = NULL;
  CFDictionaryRef proxies = SCDynamicStoreCopyProxies (NULL);
  g_auto (GStrv) ignore_list = NULL;

  if (!proxies) {
    g_warning ("Unable to fetch proxy configuration");
    return;
  }

  ignore_list = get_ignore_list (proxies);

  if (px_manager_is_ignore (uri, ignore_list))
    return;

  if (getbool (proxies, "ProxyAutoDiscoveryEnable")) {
    CFRelease (proxies);
    px_strv_builder_add_proxy (builder, "wpad://");
    return;
  }

  if (getbool (proxies, "ProxyAutoConfigEnable")) {
    CFStringRef ref = getobj_str (proxies, "ProxyAutoConfigURLString");
    g_autofree char *tmp = str (ref);
    GUri *tmp_uri = g_uri_parse (tmp, G_URI_FLAGS_NONE, NULL);

    if (tmp_uri) {
      g_autofree char *ret = g_strdup_printf ("pac+%s", g_uri_to_string (tmp_uri));
      CFRelease (proxies);
      px_strv_builder_add_proxy (builder, ret);
      return;
    }
  } else {
    const char *scheme = g_uri_get_scheme (uri);
    g_autofree char *capital_scheme = str_to_upper (scheme);

    proxy = protocol_url (proxies, capital_scheme);

    if (!proxy)
      proxy = protocol_url (proxies, "SOCKS");
  }

  if (proxy)
    px_strv_builder_add_proxy (builder, proxy);
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-osx";
  iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
  iface->get_config = px_config_osx_get_config;
}
07070100000042000081A400000000000000000000000166FD571700000424000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-osx/config-osx.h/* config-osx.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_OSX         (px_config_osx_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigOsX, px_config_osx, PX, CONFIG_OSX, GObject)

G_END_DECLS


07070100000043000081A400000000000000000000000166FD57170000014A000000000000000000000000000000000000003A00000000libproxy-0.5.9/src/backend/plugins/config-osx/meson.buildplugin_name = 'config-osx'

if get_option(plugin_name) and with_platform_darwin

foundation_dep = dependency('Foundation')
system_configuration_dep = dependency('SystemConfiguration')
px_backend_deps += [
  foundation_dep,
  system_configuration_dep,
]

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif
07070100000044000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000003400000000libproxy-0.5.9/src/backend/plugins/config-sysconfig07070100000045000081A400000000000000000000000166FD571700001BF8000000000000000000000000000000000000004700000000libproxy-0.5.9/src/backend/plugins/config-sysconfig/config-sysconfig.c/* config-sysconfig.c
 *
 * Copyright 2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include "config-sysconfig.h"

#include "px-manager.h"
#include "px-plugin-config.h"

struct _PxConfigSysConfig {
  GObject parent_instance;
  GFileMonitor *monitor;

  char *config_file;
  gboolean available;

  gboolean proxy_enabled;
  char *https_proxy;
  char *http_proxy;
  char *ftp_proxy;
  GStrv no_proxy;
};

static void px_config_iface_init (PxConfigInterface *iface);

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigSysConfig,
                               px_config_sysconfig,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void px_config_sysconfig_set_config_file (PxConfigSysConfig *self,
                                                 const char        *config_file);

static void
on_file_changed (GFileMonitor      *monitor,
                 GFile             *file,
                 GFile             *other_file,
                 GFileMonitorEvent  event_type,
                 gpointer           user_data)
{
  PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (user_data);

  g_debug ("%s: Reloading configuration", __FUNCTION__);
  px_config_sysconfig_set_config_file (self, g_file_get_path (file));
}

static
void
px_config_sysconfig_set_config_file (PxConfigSysConfig *self,
                                     const char        *config_file)
{
  g_autoptr (GFile) file = NULL;
  g_autoptr (GError) error = NULL;
  g_autoptr (GFileInputStream) istr = NULL;
  g_autoptr (GDataInputStream) dstr = NULL;
  char *line = NULL;

  g_clear_pointer (&self->config_file, g_free);
  self->config_file = g_strdup (config_file ? config_file : "/etc/sysconfig/proxy");
  self->available = FALSE;

  file = g_file_new_for_path (self->config_file);
  istr = g_file_read (file, NULL, NULL);
  if (!istr) {
    g_debug ("%s: Could not read file %s", __FUNCTION__, self->config_file);
    return;
  }

  dstr = g_data_input_stream_new (G_INPUT_STREAM (istr));

  g_clear_object (&self->monitor);
  self->monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error);
  if (!self->monitor)
    g_warning ("Could not add a file monitor for %s, error: %s", g_file_get_uri (file), error->message);
  else
    g_signal_connect_object (G_OBJECT (self->monitor), "changed", G_CALLBACK (on_file_changed), self, 0);

  do {
    g_clear_pointer (&line, g_free);

    line = g_data_input_stream_read_line (dstr, NULL, NULL, &error);
    if (line) {
      g_auto (GStrv) kv = NULL;
      g_autoptr (GString) value = NULL;
      kv = g_strsplit (line, "=", -1);

      if (g_strv_length (kv) != 2)
        continue;

      value = g_string_new (kv[1]);
      g_string_replace (value, "\"", "", 0);
      g_string_replace (value, "\r", "", 0);
      g_string_replace (value, " ", "", 0);

      if (strcmp (kv[0], "PROXY_ENABLED") == 0) {
        self->proxy_enabled = g_ascii_strncasecmp (value->str, "yes", 3) == 0;
      } else if (strcmp (kv[0], "HTTPS_PROXY") == 0) {
        self->https_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "HTTP_PROXY") == 0) {
        self->http_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "FTP_PROXY") == 0) {
        self->ftp_proxy = g_strdup (value->str);
      } else if (strcmp (kv[0], "NO_PROXY") == 0) {
        g_autofree char *tmp = g_strdup (value->str);
        self->no_proxy = g_strsplit (tmp, ",", -1);
      }
    }
  } while (line);

  self->available = TRUE;
}

static void
px_config_sysconfig_init (PxConfigSysConfig *self)
{
}

static void
px_config_sysconfig_set_property (GObject      *object,
                                  guint         prop_id,
                                  const GValue *value,
                                  GParamSpec   *pspec)
{
  PxConfigSysConfig *config = PX_CONFIG_SYSCONFIG (object);

  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      px_config_sysconfig_set_config_file (config, g_value_dup_string (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_sysconfig_get_property (GObject    *object,
                                  guint       prop_id,
                                  GValue     *value,
                                  GParamSpec *pspec)
{
  PxConfigSysConfig *config = PX_CONFIG_SYSCONFIG (object);

  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      g_value_set_string (value, config->config_file);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_sysconfig_dispose (GObject *object)
{
  PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (object);

  g_clear_object (&self->monitor);
  g_clear_pointer (&self->no_proxy, g_strfreev);
  g_clear_pointer (&self->config_file, g_free);

  G_OBJECT_CLASS (px_config_sysconfig_parent_class)->dispose (object);
}

static void
px_config_sysconfig_class_init (PxConfigSysConfigClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = px_config_sysconfig_dispose;
  object_class->set_property = px_config_sysconfig_set_property;
  object_class->get_property = px_config_sysconfig_get_property;

  g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
}

static void
px_config_sysconfig_get_config (PxConfig     *config,
                                GUri         *uri,
                                GStrvBuilder *builder)
{
  PxConfigSysConfig *self = PX_CONFIG_SYSCONFIG (config);
  const char *scheme = g_uri_get_scheme (uri);
  g_autofree char *proxy = NULL;

  if (!self->proxy_enabled)
    return;

  if (px_manager_is_ignore (uri, self->no_proxy))
    return;

  if (g_strcmp0 (scheme, "ftp") == 0) {
    proxy = g_strdup (self->ftp_proxy);
  } else if (g_strcmp0 (scheme, "https") == 0) {
    proxy = g_strdup (self->https_proxy);
  } else if (g_strcmp0 (scheme, "http") == 0) {
    proxy = g_strdup (self->http_proxy);
  }

  if (proxy)
    px_strv_builder_add_proxy (builder, proxy);
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-sysconfig";
  iface->priority = PX_CONFIG_PRIORITY_LAST;
  iface->get_config = px_config_sysconfig_get_config;
}
07070100000046000081A400000000000000000000000166FD571700000448000000000000000000000000000000000000004700000000libproxy-0.5.9/src/backend/plugins/config-sysconfig/config-sysconfig.h/* config-sysconfig.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_SYSCONFIG         (px_config_sysconfig_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigSysConfig, px_config_sysconfig, PX, CONFIG_SYSCONFIG, GObject)

G_END_DECLS


07070100000047000081A400000000000000000000000166FD57170000008A000000000000000000000000000000000000004000000000libproxy-0.5.9/src/backend/plugins/config-sysconfig/meson.buildplugin_name = 'config-sysconfig'

if get_option(plugin_name)

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif
07070100000048000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000003200000000libproxy-0.5.9/src/backend/plugins/config-windows07070100000049000081A400000000000000000000000166FD571700001C37000000000000000000000000000000000000004300000000libproxy-0.5.9/src/backend/plugins/config-windows/config-windows.c/* config-windows.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <windows.h>
#include <winreg.h>

#include <gio/gio.h>

#include "config-windows.h"

#include "px-plugin-config.h"
#include "px-manager.h"

#define W32REG_OFFSET_PAC (1 << 2)
#define W32REG_OFFSET_WPAD (1 << 3)
#define W32REG_BASEKEY "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
#define W32REG_BUFFLEN 1024

struct _PxConfigWindows {
  GObject parent_instance;
};

static void px_config_iface_init (PxConfigInterface *iface);

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigWindows,
                               px_config_windows,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void
px_config_windows_set_property (GObject      *object,
                                guint         prop_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  switch (prop_id) {
    case PROP_CONFIG_OPTION:
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_windows_get_property (GObject    *object,
                                guint       prop_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
  switch (prop_id) {
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_config_windows_init (PxConfigWindows *self)
{
}

static void
px_config_windows_class_init (PxConfigWindowsClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = px_config_windows_set_property;
  object_class->get_property = px_config_windows_get_property;

  g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
}

static gboolean
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 char *
build_proxy_uri (const char *uri)
{
  char *proxy_server = NULL;
  if (!g_strstr_len (uri, -1, "://")) {
    proxy_server = g_strdup_printf ("http://%s", uri);
  } else {
    proxy_server = g_strdup (uri);
  }

  return proxy_server;
}

static GHashTable *
parse_manual (char *manual)
{
  g_auto (GStrv) split = NULL;
  GHashTable *ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

  /* We have to check for two formats:
   * - [scheme://]1.2.3.4:8080
   * - ftp=[scheme://]1.2.4.5:8080;https=[scheme://]1.2.3.4:8080
   * where each entry may or may not contain a scheme to use for the proxy host.
   * No scheme implies http://
   */

  split = g_strsplit (manual, ";", -1);
  for (int idx = 0; idx < g_strv_length (split); idx++) {
    if (!strchr (split[idx], '=')) {
      char *proxy_uri = build_proxy_uri (split[idx]);
      /* When a proxy server is provided without any scheme specifier, */
      /* it should be used for all schemes that do not have an explicit entry */
      g_hash_table_insert (ret, g_strdup ("default"), proxy_uri);
    } else {
      g_auto (GStrv) split_kv = g_strsplit (split[idx], "=", -1);

      if (g_strv_length (split_kv) == 2) {
        char *proxy_uri = build_proxy_uri (split_kv[1]);
        g_hash_table_insert (ret, g_strdup (split_kv[0]), proxy_uri);
      }
    }
  }

  return ret;
}

static gboolean
is_enabled (char type)
{
  g_autofree char *data = NULL;
  guint32 dlen = 0;
  gboolean result = FALSE;

  if (!get_registry (W32REG_BASEKEY "\\Connections", "DefaultConnectionSettings", &data, &dlen, NULL))
    return FALSE;

  if (dlen >= 9)
    result = (data[8] & type) == type;

  return result;
}

static void
px_config_windows_get_config (PxConfig     *self,
                              GUri         *uri,
                              GStrvBuilder *builder)
{
  char *tmp = NULL;
  guint32 enabled = 0;

  if (get_registry (W32REG_BASEKEY, "ProxyOverride", &tmp, NULL, NULL)) {
    g_auto (GStrv) no_proxy = g_strsplit (tmp, ";", -1);

    if (px_manager_is_ignore (uri, no_proxy))
      return;
  }

  /* WPAD */
  if (is_enabled (W32REG_OFFSET_WPAD)) {
    px_strv_builder_add_proxy (builder, "wpad://");
  }

  /* 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_NONE, NULL);

    if (ac_uri) {
      px_strv_builder_add_proxy (builder, pac_uri);
    }
  }

  /* Manual proxy */
  if (get_registry (W32REG_BASEKEY, "ProxyEnable", NULL, NULL, &enabled) && enabled && get_registry (W32REG_BASEKEY, "ProxyServer", &tmp, NULL, NULL)) {
    g_autoptr (GHashTable) table = parse_manual (tmp);
    const char *scheme = g_uri_get_scheme (uri);

    if (table) {
      char *ret = g_hash_table_lookup (table, scheme);
      if (ret) {
        px_strv_builder_add_proxy (builder, ret);
        return;
      }

      ret = g_hash_table_lookup (table, "socks");
      if (ret) {
        px_strv_builder_add_proxy (builder, ret);
        return;
      }

      ret = g_hash_table_lookup (table, "default");
      if (ret) {
        px_strv_builder_add_proxy (builder, ret);
        return;
      }
    }
  }
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-windows";
  iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
  iface->get_config = px_config_windows_get_config;
}
0707010000004A000081A400000000000000000000000166FD571700000437000000000000000000000000000000000000004300000000libproxy-0.5.9/src/backend/plugins/config-windows/config-windows.h/* config-windows.h
 *
 * Copyright 2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_WINDOWS         (px_config_windows_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigWindows, px_config_windows, PX, CONFIG_WINDOWS, GObject)

G_END_DECLS


0707010000004B000081A400000000000000000000000166FD5717000000A1000000000000000000000000000000000000003E00000000libproxy-0.5.9/src/backend/plugins/config-windows/meson.buildplugin_name = 'config-windows'

if get_option(plugin_name) and with_platform_windows

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif0707010000004C000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000002E00000000libproxy-0.5.9/src/backend/plugins/config-xdp0707010000004D000081A400000000000000000000000166FD5717000011C8000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-xdp/config-xdp.c/* config-xdp.c
 *
 * Copyright 2024 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include "config-xdp.h"

#include "px-manager.h"
#include "px-plugin-config.h"

static void px_config_iface_init (PxConfigInterface *iface);

struct _PxConfigXdp {
  GObject parent_instance;
  gboolean available;
  GDBusProxy *proxy_resolver;
};

G_DEFINE_FINAL_TYPE_WITH_CODE (PxConfigXdp,
                               px_config_xdp,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_CONFIG, px_config_iface_init))

enum {
  PROP_0,
  PROP_CONFIG_OPTION
};

static void
px_config_xdp_init (PxConfigXdp *self)
{
  g_autoptr (GDBusConnection) connection = NULL;
  g_autoptr (GError) error = NULL;
  g_autofree char *path = g_build_filename (g_get_user_runtime_dir (), "flatpak-info", NULL);

  self->available = FALSE;

  /* Test for Flatpak or Snap Enivronments */
  if (!g_file_test (path, G_FILE_TEST_EXISTS) && !g_getenv ("SNAP_NAME"))
    return;

  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
  if (error) {
    g_warning ("Could not access dbus session: %s", error->message);
    return;
  }

  self->proxy_resolver = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.ProxyResolver", NULL, &error);
  if (error) {
    g_warning ("Could not access proxy resolver: %s", error->message);
    return;
  }

  self->available = TRUE;
}

static void
px_config_xdp_dispose (GObject *object)
{
  PxConfigXdp *self = PX_CONFIG_XDP (object);

  g_clear_object (&self->proxy_resolver);
}

static void
px_config_xdp_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_xdp_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_xdp_class_init (PxConfigXdpClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = px_config_xdp_dispose;
  object_class->set_property = px_config_xdp_set_property;
  object_class->get_property = px_config_xdp_get_property;

  g_object_class_override_property (object_class, PROP_CONFIG_OPTION, "config-option");
}

static void
px_config_xdp_get_config (PxConfig     *config,
                          GUri         *uri,
                          GStrvBuilder *builder)
{
  g_autoptr (GVariant) var = NULL;
  g_autoptr (GError) error = NULL;
  g_autoptr (GVariantIter) iter = NULL;
  PxConfigXdp *self = PX_CONFIG_XDP (config);
  g_autofree char *uri_str = NULL;
  const char *str;

  if (!self->available)
    return;

  uri_str = g_uri_to_string (uri);
  var = g_dbus_proxy_call_sync (self->proxy_resolver, "Lookup", g_variant_new ("(s)", uri_str), 0, -1, NULL, &error);
  if (error) {
    g_warning ("Could not query proxy: %s", error->message);
    return;
  }

  g_variant_get (var, "(as)", &iter);
  while (g_variant_iter_loop (iter, "s", &str)) {
    px_strv_builder_add_proxy (builder, str);
  }
}

static void
px_config_iface_init (PxConfigInterface *iface)
{
  iface->name = "config-xdp";
  iface->priority = PX_CONFIG_PRIORITY_DEFAULT;
  iface->get_config = px_config_xdp_get_config;
}
0707010000004E000081A400000000000000000000000166FD57170000041F000000000000000000000000000000000000003B00000000libproxy-0.5.9/src/backend/plugins/config-xdp/config-xdp.h/* config-xdp.h
 *
 * Copyright 2024 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define PX_CONFIG_TYPE_XDP         (px_config_xdp_get_type ())

G_DECLARE_FINAL_TYPE (PxConfigXdp, px_config_xdp, PX, CONFIG_XDP, GObject)

G_END_DECLS


0707010000004F000081A400000000000000000000000166FD571700000083000000000000000000000000000000000000003A00000000libproxy-0.5.9/src/backend/plugins/config-xdp/meson.buildplugin_name = 'config-xdp'

if get_option(plugin_name)

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

endif07070100000050000081A400000000000000000000000166FD5717000002C0000000000000000000000000000000000000002F00000000libproxy-0.5.9/src/backend/plugins/meson.buildsubdir('config-env')
subdir('config-gnome')
subdir('config-kde')
subdir('config-osx')
subdir('config-sysconfig')
subdir('config-xdp')
subdir('config-windows')

subdir('pacrunner-duktape')

summary({
  'Configuration Environment' : get_option('config-env'),
  'Configuration GNOME      ' : get_option('config-gnome'),
  'Configuration KDE        ' : get_option('config-kde'),
  'Configuration Windows    ' : get_option('config-windows'),
  'Configuration sysconfig  ' : get_option('config-sysconfig'),
  'Configuration OS X       ' : get_option('config-osx'),
  'Configuration XDP        ' : get_option('config-xdp'),
  'PAC Runner Duktape       ' : get_option('pacrunner-duktape'),
}, section: 'Plugins')07070100000051000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000003500000000libproxy-0.5.9/src/backend/plugins/pacrunner-duktape07070100000052000081A400000000000000000000000166FD571700000154000000000000000000000000000000000000004100000000libproxy-0.5.9/src/backend/plugins/pacrunner-duktape/meson.buildplugin_name = 'pacrunner-duktape'

if get_option(plugin_name)

duktape_dep = dependency('duktape')
m_dep = cc.find_library('m', required : false)
socket_dep = cc.find_library('socket', required: false)

px_backend_sources += [
  'plugins/@0@/@0@.c'.format(plugin_name),
]

px_backend_deps += [
  duktape_dep,
  m_dep,
  socket_dep
]

endif
07070100000053000081A400000000000000000000000166FD5717000014F6000000000000000000000000000000000000004900000000libproxy-0.5.9/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.c/* pacrunner-duktape.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include <unistd.h>
#ifdef __WIN32__
#include <ws2tcpip.h>
#else
#include <netdb.h>
#include <netinet/in.h>
#endif

#include "pacrunner-duktape.h"
#include "pacutils.h"
#include "px-plugin-pacrunner.h"

#include "duktape.h"

struct _PxPacRunnerDuktape {
  GObject parent_instance;
  duk_context *ctx;
};

static void px_pacrunner_iface_init (PxPacRunnerInterface *iface);

G_DEFINE_FINAL_TYPE_WITH_CODE (PxPacRunnerDuktape,
                               px_pacrunner_duktape,
                               G_TYPE_OBJECT,
                               G_IMPLEMENT_INTERFACE (PX_TYPE_PACRUNNER, px_pacrunner_iface_init))


static duk_ret_t
dns_resolve (duk_context *ctx)
{
  const char *hostname = NULL;
  struct addrinfo *info;
  char tmp[INET6_ADDRSTRLEN + 1];

  if (duk_get_top (ctx) != 1) {
    /* Invalid number of arguments */
    return 0;
  }

  /* We do not need to free the string - It's managed by Duktape. */
  hostname = duk_get_string (ctx, 0);
  if (!hostname)
    return 0;

  /* Look it up */
  if (getaddrinfo (hostname, NULL, NULL, &info))
    return 0;

  /* Try for IPv4 */
  if (getnameinfo (info->ai_addr,
                   info->ai_addrlen,
                   tmp,
                   INET6_ADDRSTRLEN + 1,
                   NULL,
                   0,
                   NI_NUMERICHOST)) {
    freeaddrinfo (info);
    duk_push_null (ctx);
    return 1;
  }
  freeaddrinfo (info);

  /* Create the return value */
  duk_push_string (ctx, tmp);

  return 1;
}

static duk_ret_t
my_ip_address (duk_context *ctx)
{
  char hostname[1024];

  hostname[sizeof (hostname) - 1] = '\0';

  if (!gethostname (hostname, sizeof (hostname) - 1)) {
    duk_push_string (ctx, hostname);
    return dns_resolve (ctx);
  }

  return duk_error (ctx, DUK_ERR_ERROR, "Unable to find hostname!");
}

static duk_ret_t
alert (duk_context *ctx)
{
  const char *str = NULL;

  /* do nothing if PX_DEBUG_PACALERT environment is not set */
  if (!getenv ("PX_DEBUG_PACALERT"))
    return 0;

  /* only get first argument of alert() as string */
  str = duk_get_string (ctx, 0);
  if (!str)
    return 0;

  fprintf (stderr, "PAC-alert: %s\n", str);
  return 0;
}

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_c_function (self->ctx, alert, 1);
  duk_put_global_string (self->ctx, "alert");

  duk_push_string (self->ctx, JAVASCRIPT_ROUTINES);
  if (duk_peval_noresult (self->ctx))
    goto error;

  return;

error:
  duk_destroy_heap (self->ctx);
}

static void
px_pacrunner_duktape_dispose (GObject *object)
{
  PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (object);

  g_clear_pointer (&self->ctx, duk_destroy_heap);

  G_OBJECT_CLASS (px_pacrunner_duktape_parent_class)->dispose (object);
}

static void
px_pacrunner_duktape_class_init (PxPacRunnerDuktapeClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = px_pacrunner_duktape_dispose;
}

static gboolean
px_pacrunner_duktape_set_pac (PxPacRunner *pacrunner,
                              GBytes      *pac_data)
{
  PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (pacrunner);
  gsize len;
  gconstpointer content = g_bytes_get_data (pac_data, &len);

  duk_push_lstring (self->ctx, content, len);

  if (duk_peval_noresult (self->ctx)) {
    return FALSE;
  }

  return TRUE;
}

static char *
px_pacrunner_duktape_run (PxPacRunner *pacrunner,
                          GUri        *uri)
{
  PxPacRunnerDuktape *self = PX_PACRUNNER_DUKTAPE (pacrunner);
  duk_int_t result;

  duk_get_global_string (self->ctx, "FindProxyForURL");
  duk_push_string (self->ctx, g_uri_to_string (uri));
  duk_push_string (self->ctx, g_uri_get_host (uri));
  result = duk_pcall (self->ctx, 2);

  if (result == 0) {
    const char *proxy = duk_get_string (self->ctx, 0);
    char *proxy_string;

    if (!proxy) {
      duk_pop (self->ctx);
      return g_strdup ("");
    }

    proxy_string = g_strdup (proxy);

    duk_pop (self->ctx);

    return proxy_string;
  }

  duk_pop (self->ctx);
  return g_strdup ("");
}

static void
px_pacrunner_iface_init (PxPacRunnerInterface *iface)
{
  iface->set_pac = px_pacrunner_duktape_set_pac;
  iface->run = px_pacrunner_duktape_run;
}
07070100000054000081A400000000000000000000000166FD571700000453000000000000000000000000000000000000004900000000libproxy-0.5.9/src/backend/plugins/pacrunner-duktape/pacrunner-duktape.h/* pacrunner-duktape.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define PX_PACRUNNER_TYPE_DUKTAPE         (px_pacrunner_duktape_get_type ())

G_DECLARE_FINAL_TYPE (PxPacRunnerDuktape, px_pacrunner_duktape, PX, PACRUNNER_DUKTAPE, GObject)

G_END_DECLS
07070100000055000081A400000000000000000000000166FD571700005E78000000000000000000000000000000000000002800000000libproxy-0.5.9/src/backend/px-manager.c/* px-manager.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-backend-config.h"

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>

#include "px-manager.h"
#include "px-plugin-config.h"
#include "px-plugin-pacrunner.h"

#ifdef HAVE_CONFIG_ENV
#include <plugins/config-env/config-env.h>
#endif

#ifdef HAVE_CONFIG_GNOME
#include <plugins/config-gnome/config-gnome.h>
#endif

#ifdef HAVE_CONFIG_KDE
#include <plugins/config-kde/config-kde.h>
#endif

#ifdef HAVE_CONFIG_OSX
#include <plugins/config-osx/config-osx.h>
#endif

#ifdef HAVE_CONFIG_SYSCONFIG
#include <plugins/config-sysconfig/config-sysconfig.h>
#endif

#ifdef HAVE_CONFIG_WINDOWS
#include <plugins/config-windows/config-windows.h>
#endif

#ifdef HAVE_CONFIG_XDP
#include <plugins/config-xdp/config-xdp.h>
#endif

#ifdef HAVE_PACRUNNER_DUKTAPE
#include <plugins/pacrunner-duktape/pacrunner-duktape.h>
#endif

#ifdef HAVE_CURL
#include <curl/curl.h>
#endif

enum {
  PROP_0,
  PROP_CONFIG_PLUGIN,
  PROP_CONFIG_OPTION,
  PROP_FORCE_ONLINE,
  LAST_PROP
};

static GParamSpec *obj_properties[LAST_PROP];

/**
 * PxManager:
 *
 * Manage libproxy modules
 */

struct _PxManager {
  GObject parent_instance;
  GList *config_plugins;
  GList *pacrunner_plugins;
  GNetworkMonitor *network_monitor;
#ifdef HAVE_CURL
  CURL *curl;
#endif

  char *config_plugin;
  char *config_option;

  gboolean force_online;
  gboolean online;
  gboolean wpad;
  GBytes *pac_data;
  char *pac_url;

  GMutex mutex;
};

G_DEFINE_TYPE (PxManager, px_manager, G_TYPE_OBJECT)

static void
px_manager_on_network_changed (GNetworkMonitor *monitor,
                               gboolean         network_available,
                               gpointer         user_data)
{
  PxManager *self = PX_MANAGER (user_data);

  g_debug ("%s: Network connection changed, clearing pac data", __FUNCTION__);

  self->wpad = FALSE;
  self->online = network_available;
  g_clear_pointer (&self->pac_url, g_free);
  g_clear_pointer (&self->pac_data, g_bytes_unref);
}

static gint
config_order_compare (gconstpointer a,
                      gconstpointer b)
{
  PxConfig *config_a = (PxConfig *)a;
  PxConfig *config_b = (PxConfig *)b;
  PxConfigInterface *ifc_a = PX_CONFIG_GET_IFACE (config_a);
  PxConfigInterface *ifc_b = PX_CONFIG_GET_IFACE (config_b);

  if (ifc_a->priority < ifc_b->priority)
    return -1;

  if (ifc_a->priority == ifc_b->priority)
    return 0;

  return 1;
}

static void
px_manager_add_config_plugin (PxManager *self,
                              GType      type)
{
  g_autoptr (PxConfig) config = g_object_new (type, "config-option", self->config_option, NULL);
  PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (config);
  const char *env = g_getenv ("PX_FORCE_CONFIG");
  const char *force_config = self->config_plugin ? self->config_plugin : env;

  if (!force_config || g_strcmp0 (ifc->name, force_config) == 0)
    self->config_plugins = g_list_insert_sorted (self->config_plugins, g_steal_pointer (&config), config_order_compare);
}

static void
px_manager_add_pacrunner_plugin (PxManager *self,
                                 GType      type)
{
  PxPacRunner *pacrunner = g_object_new (type, NULL);

  self->pacrunner_plugins = g_list_append (self->pacrunner_plugins, pacrunner);
}

static void
px_manager_constructed (GObject *object)
{
  PxManager *self = PX_MANAGER (object);

  if (g_getenv ("PX_DEBUG")) {
    const gchar *g_messages_debug;

    g_messages_debug = g_getenv ("G_MESSAGES_DEBUG");

    if (!g_messages_debug) {
      g_setenv ("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE);
    } else {
      g_autofree char *new_g_messages_debug = NULL;

      new_g_messages_debug = g_strconcat (g_messages_debug, " ", G_LOG_DOMAIN, NULL);
      if (new_g_messages_debug)
        g_setenv ("G_MESSAGES_DEBUG", new_g_messages_debug, TRUE);
    }
  }

#ifdef HAVE_CONFIG_ENV
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_ENV);
#endif
#ifdef HAVE_CONFIG_GNOME
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_GNOME);
#endif
#ifdef HAVE_CONFIG_KDE
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_KDE);
#endif
#ifdef HAVE_CONFIG_OSX
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_OSX);
#endif
#ifdef HAVE_CONFIG_SYSCONFIG
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_SYSCONFIG);
#endif
#ifdef HAVE_CONFIG_WINDOWS
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_WINDOWS);
#endif
#ifdef HAVE_CONFIG_XDP
  px_manager_add_config_plugin (self, PX_CONFIG_TYPE_XDP);
#endif

  g_debug ("Active config plugins:");
  for (GList *list = self->config_plugins; list && list->data; list = list->next) {
    PxConfig *config = list->data;
    PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (config);

    g_debug (" - %s", ifc->name);
  }

#ifdef HAVE_PACRUNNER_DUKTAPE
  px_manager_add_pacrunner_plugin (self, PX_PACRUNNER_TYPE_DUKTAPE);
#endif

  self->pac_data = NULL;

  if (!self->force_online) {
    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);

    /* Expect to be online until network-changed is emitted */
    self->wpad = FALSE;
    self->online = TRUE;
  } else {
    px_manager_on_network_changed (NULL, TRUE, self);
  }

  g_debug ("%s: Up and running", __FUNCTION__);
}

static void
px_manager_dispose (GObject *object)
{
  PxManager *self = PX_MANAGER (object);

  g_clear_list (&self->config_plugins, g_object_unref);
  g_clear_list (&self->pacrunner_plugins, g_object_unref);

  g_clear_pointer (&self->config_plugin, g_free);
#ifdef HAVE_CURL
  g_clear_pointer (&self->curl, curl_easy_cleanup);
#endif

  G_OBJECT_CLASS (px_manager_parent_class)->dispose (object);
}

static void
px_manager_set_property (GObject      *object,
                         guint         prop_id,
                         const GValue *value,
                         GParamSpec   *pspec)
{
  PxManager *self = PX_MANAGER (object);

  switch (prop_id) {
    case PROP_CONFIG_PLUGIN:
      self->config_plugin = g_strdup (g_value_get_string (value));
      break;
    case PROP_CONFIG_OPTION:
      self->config_option = g_strdup (g_value_get_string (value));
      break;
    case PROP_FORCE_ONLINE:
      self->force_online = g_value_get_boolean (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  }
}

static void
px_manager_get_property (GObject    *object,
                         guint       prop_id,
                         GValue     *value,
                         GParamSpec *pspec)
{
  switch (prop_id) {
    case PROP_CONFIG_PLUGIN:
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
px_manager_class_init (PxManagerClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = px_manager_constructed;
  object_class->dispose = px_manager_dispose;
  object_class->set_property = px_manager_set_property;
  object_class->get_property = px_manager_get_property;

  obj_properties[PROP_CONFIG_PLUGIN] = g_param_spec_string ("config-plugin",
                                                            NULL,
                                                            NULL,
                                                            NULL,
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  obj_properties[PROP_CONFIG_OPTION] = g_param_spec_string ("config-option",
                                                            NULL,
                                                            NULL,
                                                            NULL,
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  obj_properties[PROP_FORCE_ONLINE] = g_param_spec_boolean ("force-online",
                                                            NULL,
                                                            NULL,
                                                            FALSE,
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
}

static void
px_manager_init (PxManager *self)
{
}

/**
 * px_manager_new_with_options:
 * @optname1: name of first property to set
 * @...: value of @optname1, followed by additional property/value pairs
 *
 * Create a new `PxManager` with the specified options.
 *
 * Returns: the newly created `PxManager`
 */
PxManager *
px_manager_new_with_options (const char *optname1,
                             ...)
{
  PxManager *self;
  va_list ap;

  va_start (ap, optname1);
  self = (PxManager *)g_object_new_valist (PX_TYPE_MANAGER, optname1, ap);
  va_end (ap);

  return self;
}

/**
 * px_manager_new:
 *
 * Create a new `PxManager`.
 *
 * Returns: the newly created `PxManager`
 */
PxManager *
px_manager_new (void)
{
  return px_manager_new_with_options (NULL);
}

#ifdef HAVE_CURL
static size_t
store_data (void   *contents,
            size_t  size,
            size_t  nmemb,
            void   *user_pointer)
{
  GByteArray *byte_array = user_pointer;
  size_t real_size = size * nmemb;

  g_byte_array_append (byte_array, contents, real_size);

  return real_size;
}
#endif

/**
 * px_manager_pac_download:
 * @self: a px manager
 * @uri: PAC uri
 *
 * Downloads a PAC file from provided @url.
 *
 * Returns: (nullable): a newly created `GBytes` containing PAC data, or %NULL on error.
 */
GBytes *
px_manager_pac_download (PxManager  *self,
                         const char *uri)
{
#ifdef HAVE_CURL
  GByteArray *byte_array = g_byte_array_new ();
  CURLcode res;
  const char *url = uri;

  if (!self->curl)
    self->curl = curl_easy_init ();

  if (!self->curl)
    return NULL;

  if (g_str_has_prefix (url, "pac+"))
    url += 4;

  if (curl_easy_setopt (self->curl, CURLOPT_NOSIGNAL, 1) != CURLE_OK)
    g_debug ("Could not set NOSIGNAL, continue");

  if (curl_easy_setopt (self->curl, CURLOPT_FOLLOWLOCATION, 1) != CURLE_OK)
    g_debug ("Could not set FOLLOWLOCATION, continue");

  if (curl_easy_setopt (self->curl, CURLOPT_NOPROXY, "*") != CURLE_OK) {
    g_warning ("Could not set NOPROXY, ABORT!");
    return NULL;
  }

  if (curl_easy_setopt (self->curl, CURLOPT_CONNECTTIMEOUT, 30) != CURLE_OK)
    g_debug ("Could not set CONENCTIONTIMEOUT, continue");

  if (curl_easy_setopt (self->curl, CURLOPT_USERAGENT, "libproxy") != CURLE_OK)
    g_debug ("Could not set USERAGENT, continue");

  if (curl_easy_setopt (self->curl, CURLOPT_URL, url) != CURLE_OK) {
    g_warning ("Could not set URL, ABORT!");
    return NULL;
  }

  if (curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data) != CURLE_OK) {
    g_warning ("Could not set WRITEFUNCTION, ABORT!");
    return NULL;
  }

  if (curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, byte_array) != CURLE_OK) {
    g_warning ("Could not set WRITEDATA, ABORT!");
    return NULL;
  }

  res = curl_easy_perform (self->curl);
  if (res != CURLE_OK) {
    g_debug ("%s: Could not download data: %s", __FUNCTION__, curl_easy_strerror (res));
    return NULL;
  }

  return g_byte_array_free_to_bytes (byte_array);
#else
  return NULL;
#endif
}

/**
 * px_manager_get_configuration:
 * @self: a px manager
 * @uri: PAC uri
 *
 * Get raw proxy configuration for gien @uri.
 *
 * Returns: (transfer full) (nullable): a newly created `GStrv` containing configuration data for @uri.
 */
char **
px_manager_get_configuration (PxManager *self,
                              GUri      *uri)
{
  g_autoptr (GStrvBuilder) builder = g_strv_builder_new ();

  for (GList *list = self->config_plugins; list && list->data; list = list->next) {
    PxConfig *config = PX_CONFIG (list->data);
    PxConfigInterface *ifc = PX_CONFIG_GET_IFACE (config);

    ifc->get_config (config, uri, builder);
  }

  return g_strv_builder_end (builder);
}

static void
px_manager_run_pac (PxPacRunner  *pacrunner,
                    GBytes       *pac,
                    GUri         *uri,
                    GStrvBuilder *builder)
{
  PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (pacrunner);
  g_auto (GStrv) proxies_split = NULL;
  char *pac_response;

  pac_response = ifc->run (PX_PAC_RUNNER (pacrunner), uri);

  /* Split line to handle multiple proxies */
  proxies_split = g_strsplit (pac_response, ";", -1);

  for (int idx = 0; idx < g_strv_length (proxies_split); idx++) {
    char *line = g_strstrip (proxies_split[idx]);
    g_auto (GStrv) word_split = g_strsplit (line, " ", -1);

    /* Check for syntax "METHOD SERVER" */
    if (g_strv_length (word_split) == 2) {
      g_autoptr (GUri) proxy_uri = NULL;
      g_autofree char *uri_string = NULL;
      g_autofree char *proxy_string = NULL;
      g_autoptr (GUri) test_uri = NULL;
      char *method;
      char *server;

      method = word_split[0];
      server = word_split[1];

      uri_string = g_strconcat ("http://", server, NULL);
      proxy_uri = g_uri_parse (uri_string, G_URI_FLAGS_NONE, NULL);
      if (!proxy_uri)
        continue;

      if (g_ascii_strncasecmp (method, "proxy", 5) == 0) {
        proxy_string = g_uri_to_string (proxy_uri);
      } else if (g_ascii_strncasecmp (method, "socks4a", 7) == 0) {
        proxy_string = g_strconcat ("socks4a://", server, NULL);
      } else if (g_ascii_strncasecmp (method, "socks4", 6) == 0) {
        proxy_string = g_strconcat ("socks4://", server, NULL);
      } else if (g_ascii_strncasecmp (method, "socks5", 6) == 0) {
        proxy_string = g_strconcat ("socks5://", server, NULL);
      } else if (g_ascii_strncasecmp (method, "socks", 5) == 0) {
        proxy_string = g_strconcat ("socks://", server, NULL);
      }

      if (proxy_string) {
        test_uri = g_uri_parse (proxy_string, G_URI_FLAGS_NONE, NULL);

        if (test_uri)
          px_strv_builder_add_proxy (builder, proxy_string);
      }
    } else if (g_strv_length (word_split) == 1 && g_ascii_strncasecmp (word_split[0], "direct", 6) == 0) {
      px_strv_builder_add_proxy (builder, "direct://");
    }
  }
}

static gboolean
px_manager_set_pac (PxManager *self)
{
  GList *list;

  for (list = self->pacrunner_plugins; list && list->data; list = list->next) {
    PxPacRunner *pacrunner = PX_PAC_RUNNER (list->data);
    PxPacRunnerInterface *ifc = PX_PAC_RUNNER_GET_IFACE (pacrunner);

    if (!ifc->set_pac (PX_PAC_RUNNER (pacrunner), self->pac_data))
      return FALSE;
  }

  return TRUE;
}

static gboolean
px_manager_expand_wpad (PxManager *self,
                        GUri      *uri)
{
  const char *scheme = g_uri_get_scheme (uri);
  gboolean ret = FALSE;

  if (g_strcmp0 (scheme, "wpad") == 0) {
    ret = TRUE;

    if (!self->wpad) {
      g_clear_pointer (&self->pac_data, g_bytes_unref);
      g_clear_pointer (&self->pac_url, g_free);
      self->wpad = TRUE;
    }

    if (!self->pac_data) {
      GUri *wpad_url = g_uri_parse ("http://wpad/wpad.dat", G_URI_FLAGS_NONE, NULL);

      g_debug ("%s: Trying to find the PAC using WPAD...", __FUNCTION__);
      self->pac_url = g_uri_to_string (wpad_url);
      self->pac_data = px_manager_pac_download (self, self->pac_url);
      if (!self->pac_data) {
        g_clear_pointer (&self->pac_url, g_free);
        ret = FALSE;
      } else {
        g_debug ("%s: PAC recevied!", __FUNCTION__);
        if (!px_manager_set_pac (self)) {
          g_debug ("%s: Unable to set PAC from %s while online = %d!", __FUNCTION__, self->pac_url, self->online);
          g_clear_pointer (&self->pac_url, g_free);
          g_clear_pointer (&self->pac_data, g_bytes_unref);
          ret = FALSE;
        }
      }
    }
  }

  return ret;
}

static gboolean
px_manager_expand_pac (PxManager *self,
                       GUri      *uri)
{
  gboolean ret = FALSE;
  const char *scheme = g_uri_get_scheme (uri);

  if (g_str_has_prefix (scheme, "pac+")) {
    ret = TRUE;

    if (self->wpad)
      self->wpad = FALSE;

    if (self->pac_data) {
      g_autofree char *uri_str = g_uri_to_string (uri);

      if (g_strcmp0 (self->pac_url, uri_str) != 0) {
        g_clear_pointer (&self->pac_url, g_free);
        g_clear_pointer (&self->pac_data, g_bytes_unref);
      }
    }

    if (!self->pac_data) {
      self->pac_url = g_uri_to_string (uri);
      self->pac_data = px_manager_pac_download (self, self->pac_url);

      if (!self->pac_data) {
        g_warning ("%s: Unable to download PAC from %s while online = %d!", __FUNCTION__, self->pac_url, self->online);
        g_clear_pointer (&self->pac_url, g_free);
        ret = FALSE;
      } else {
        g_debug ("%s: PAC recevied!", __FUNCTION__);
        if (!px_manager_set_pac (self)) {
          g_warning ("%s: Unable to set PAC from %s while online = %d!", __FUNCTION__, self->pac_url, self->online);
          g_clear_pointer (&self->pac_url, g_free);
          g_clear_pointer (&self->pac_data, g_bytes_unref);
          ret = FALSE;
        }
      }
    }
  }

  return ret;
}

/**
 * px_manager_get_proxies_sync:
 * @self: a px manager
 * @url: a url
 *
 * Get proxies for giben @url.
 *
 * Returns: (transfer full) (nullable): a newly created `GStrv` containing proxy related information.
 */
char **
px_manager_get_proxies_sync (PxManager  *self,
                             const char *url)
{
  g_autoptr (GStrvBuilder) builder = NULL;
  g_autoptr (GUri) uri = NULL;
  g_auto (GStrv) config = NULL;
  g_autoptr (GError) error = NULL;

  g_mutex_lock (&self->mutex);

  builder = g_strv_builder_new ();
  uri = g_uri_parse (url, G_URI_FLAGS_NONE, &error);

  g_debug ("%s: url=%s online=%d", __FUNCTION__, url ? url : "?", self->online);
  if (!uri || !self->online) {
    px_strv_builder_add_proxy (builder, "direct://");
    g_mutex_unlock (&self->mutex);
    return g_strv_builder_end (builder);
  }

  config = px_manager_get_configuration (self, uri);

  for (int idx = 0; idx < g_strv_length (config); idx++) {
    GUri *conf_url = g_uri_parse (config[idx], G_URI_FLAGS_NONE, NULL);

    g_debug ("%s: Config[%d] = %s", __FUNCTION__, idx, config[idx]);

    /* Ignore invalid proxy URL, so we won't call GUri API on NULL. */
    if (!conf_url)
      continue;

    if (px_manager_expand_wpad (self, conf_url) || px_manager_expand_pac (self, conf_url)) {
      GList *list;

      for (list = self->pacrunner_plugins; list && list->data; list = list->next) {
        PxPacRunner *pacrunner = PX_PAC_RUNNER (list->data);

        px_manager_run_pac (pacrunner, self->pac_data, uri, builder);
      }
    } else if (!g_str_has_prefix (g_uri_get_scheme (conf_url), "wpad") && !g_str_has_prefix (g_uri_get_scheme (conf_url), "pac+")) {
      px_strv_builder_add_proxy (builder, g_uri_to_string (conf_url));
    }
  }

  /* In case no proxy could be found, assume direct connection */
  if (((GPtrArray *)builder)->len == 0)
    px_strv_builder_add_proxy (builder, "direct://");

  for (int idx = 0; idx < ((GPtrArray *)builder)->len; idx++)
    g_debug ("%s: Proxy[%d] = %s", __FUNCTION__, idx, (char *)((GPtrArray *)builder)->pdata[idx]);

  g_mutex_unlock (&self->mutex);
  return g_strv_builder_end (builder);
}

void
px_strv_builder_add_proxy (GStrvBuilder *builder,
                           const char   *value)
{
  for (int idx = 0; idx < ((GPtrArray *)builder)->len; idx++) {
    if (g_strcmp0 ((char *)((GPtrArray *)builder)->pdata[idx], value) == 0)
      return;
  }

  g_strv_builder_add (builder, value);
}

static gboolean
ignore_domain (GUri *uri,
               char *ignore)
{
  g_auto (GStrv) ignore_split = NULL;
  const char *host = g_uri_get_host (uri);
  char *ignore_host;
  int ignore_port = -1;
  int port;

  if (g_strcmp0 (ignore, "*") == 0)
    return TRUE;

  if (!host || !ignore || strlen (ignore) == 0)
    return FALSE;

  ignore_split = g_strsplit (ignore, ":", -1);
  port = g_uri_get_port (uri);

  /* Get our ignore pattern's hostname and port */
  ignore_host = ignore_split[0];
  if  (g_strv_length (ignore_split) == 2)
    ignore_port = atoi (ignore_split[1]);

  /* Hostname match (domain.com or domain.com:80) */
  if (g_strcmp0 (host, ignore_host) == 0)
    return (ignore_port == -1 || port == ignore_port);

  /**
   * Treat the following three options as a wildcard for a domain:
   *  - .domain.com or .domain.com:80
   *  - *.domain.com or *.domain.com:80
   *  - domain.com or domain.com:80
   */
  if (strlen (ignore_host) > 2) {
    if (ignore_host[0] == '.' && ((g_ascii_strncasecmp (host, ignore_host + 1, strlen (host)) == 0) || g_str_has_suffix (host, ignore_host)))
      return (ignore_port == -1 || port == ignore_port);

    if (ignore_host[0] == '*' && ignore_host[1] == '.' && ((g_ascii_strncasecmp (host, ignore_host + 2, strlen (host)) == 0) || g_str_has_suffix (host, ignore_host + 1)))
      return (ignore_port == -1 || port == ignore_port);

    if (strlen (host) > strlen (ignore_host) && host[strlen (host) - strlen (ignore_host) - 1] == '.' && g_str_has_suffix (host, ignore_host))
      return (ignore_port == -1 || port == ignore_port);
  }

  /* No match was found */
  return FALSE;
}

static gboolean
ignore_hostname (GUri *uri,
                 char *ignore)
{
  const char *host = g_uri_get_host (uri);

  if (!host)
    return FALSE;

  if (g_strcmp0 (ignore, "<local>") == 0 && strchr (host, ':') == NULL && strchr (host, '.') == NULL)
    return TRUE;

  return FALSE;
}

static gboolean
ignore_ip (GUri *uri,
           char *ignore)
{
  g_autoptr (GInetAddress) uri_address = NULL;
  g_autoptr (GInetAddress) ignore_address = NULL;
  g_auto (GStrv) ignore_split = NULL;
  g_autoptr (GError) error = NULL;
  const char *uri_host = g_uri_get_host (uri);
  int port = g_uri_get_port (uri);
  int ignore_port = 0;
  gboolean result;

  if (!uri_host)
    return FALSE;

  uri_address = g_inet_address_new_from_string (uri_host);

  /*
   * IPv4/CIDR
   * IPv4/IPv4
   * IPv6/CIDR
   * IPv6/IPv6
   *
   * uri must be in ip string format, no host name resolution is done
   */
  if (uri_address && strchr (ignore, '/')) {
    GInetAddressMask *address_mask = g_inet_address_mask_new_from_string (ignore, &error);

    if (!address_mask) {
      g_warning ("Could not parse ignore mask: %s", error->message);
      return FALSE;
    }

    if (g_inet_address_mask_matches (address_mask, uri_address))
      return TRUE;
  }

  /*
   * IPv4
   * IPv6
   */
  if (!g_hostname_is_ip_address (uri_host) || !g_hostname_is_ip_address (ignore))
    return FALSE;

  /*
   * IPv4:port
   * [IPv6]:port
   */
  ignore_split = g_strsplit (ignore, ":", -1);
  if  (g_strv_length (ignore_split) == 2)
    ignore_port = atoi (ignore_split[1]);

  ignore_address = g_inet_address_new_from_string (ignore);
  result = g_inet_address_equal (uri_address, ignore_address);

  return ignore_port != 0 ? ((port == ignore_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;
}
07070100000056000081A400000000000000000000000166FD571700000719000000000000000000000000000000000000002800000000libproxy-0.5.9/src/backend/px-manager.h/* px-manager.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define PX_TYPE_MANAGER (px_manager_get_type())

G_DECLARE_FINAL_TYPE (PxManager, px_manager, PX, MANAGER, GObject)

extern GQuark px_manager_error_quark (void);
#define PX_MANAGER_ERROR px_manager_error_quark ()

typedef enum {
  PX_MANAGER_ERROR_UNKNOWN_METHOD = 1001,
} PxManagerErrorCode;


PxManager *px_manager_new (void);
PxManager *px_manager_new_with_options (const char *optname1, ...);

char **px_manager_get_proxies_sync (PxManager   *self,
                                    const char  *url);

GBytes *px_manager_pac_download (PxManager  *self,
                                 const char *uri);

char **px_manager_get_configuration (PxManager  *self,
                                     GUri       *uri);

void px_strv_builder_add_proxy (GStrvBuilder *builder,
                                const char   *value);

gboolean px_manager_is_ignore (GUri *uri, GStrv ignores);

G_END_DECLS
07070100000057000081A400000000000000000000000166FD571700000636000000000000000000000000000000000000002E00000000libproxy-0.5.9/src/backend/px-plugin-config.c/* px-plugin-config.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-plugin-config.h"

G_DEFINE_INTERFACE (PxConfig, px_config, G_TYPE_OBJECT)

static void
px_config_default_init (PxConfigInterface *iface)
{
  g_object_interface_install_property (iface,
                                       g_param_spec_string ("config-option",
                                                            NULL,
                                                            NULL,
                                                            NULL,
                                                            G_PARAM_READWRITE |
                                                            G_PARAM_CONSTRUCT_ONLY |
                                                            G_PARAM_STATIC_STRINGS));
}
07070100000058000081A400000000000000000000000166FD571700000519000000000000000000000000000000000000002E00000000libproxy-0.5.9/src/backend/px-plugin-config.h/* px-plugin-config.h
 *
 * Copyright 2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define PX_TYPE_CONFIG (px_config_get_type ())

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;

  void (*get_config) (PxConfig *self, GUri *uri, GStrvBuilder *builder);
};

G_END_DECLS
07070100000059000081A400000000000000000000000166FD57170000040C000000000000000000000000000000000000003100000000libproxy-0.5.9/src/backend/px-plugin-pacrunner.c/* px-plugin-pacrunner.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * 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)
{
}
0707010000005A000081A400000000000000000000000166FD5717000004D5000000000000000000000000000000000000003100000000libproxy-0.5.9/src/backend/px-plugin-pacrunner.h/* px-plugin-pacrunner.h
 *
 * Copyright 2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define PX_TYPE_PACRUNNER (px_pacrunner_get_type ())

G_DECLARE_INTERFACE (PxPacRunner, px_pacrunner, PX, PAC_RUNNER, GObject)

struct _PxPacRunnerInterface
{
  GTypeInterface parent_iface;

  gboolean (*set_pac) (PxPacRunner *pacrunner, GBytes *pac_data);
  char *(*run) (PxPacRunner *self, GUri *uri);
};

G_END_DECLS
0707010000005B000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001C00000000libproxy-0.5.9/src/libproxy0707010000005C000081A400000000000000000000000166FD571700000103000000000000000000000000000000000000002900000000libproxy-0.5.9/src/libproxy/libproxy.mapLIBPROXY_0.4.16 {
  global:
    px_proxy_factory_new;
    px_proxy_factory_get_proxies;
    px_proxy_factory_free_proxies;
    px_proxy_factory_free;
};

LIBPROXY_0.5.5 {
  global:
    px_proxy_factory_get_type;
    px_proxy_factory_copy;
} LIBPROXY_0.4.16;

0707010000005D000081A400000000000000000000000166FD5717000007E4000000000000000000000000000000000000002800000000libproxy-0.5.9/src/libproxy/meson.buildlibproxy_inc = include_directories('.')

libproxy_sources = []

libproxy_sources = [
  'proxy.c',
]

libproxy_headers = [
  'proxy.h',
]

libproxy_deps = [
  px_backend_dep,
]

mapfile = 'libproxy.map'
vscript = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
vflag = []
if cc.has_multi_link_arguments(vscript)
  vflag += vscript
endif

libproxy = shared_library(
  'proxy',
  libproxy_sources,
  include_directories: px_backend_inc,
  dependencies: libproxy_deps,
  link_args : vflag,
  link_depends : mapfile,
  soversion: '1',
  version: meson.project_version(),
  install: true,
  install_rpath: pkglibdir,
)

libproxy_dep = declare_dependency (
  include_directories: libproxy_inc,
  link_with: libproxy,
  dependencies: libproxy_deps
)

install_headers(libproxy_headers, subdir: 'libproxy')

pkg = import('pkgconfig')
pkg.generate(
  libraries: [libproxy],
  subdirs: 'libproxy',
  version: meson.project_version(),
  name: 'libproxy',
  filebase: package_api_name,
  description: 'libproxy',
  # Needed due to #include <glib-object.h> in proxy.h
  requires_private: 'gobject-2.0',
  install_dir: join_paths(get_option('libdir'), 'pkgconfig')
)

if get_option('introspection')
  gnome = import('gnome')

  libproxy_gir_extra_args = [
    '--c-include=proxy.h',
    '--quiet',
  ]

  libproxy_gir = gnome.generate_gir(
    libproxy,
    sources: libproxy_headers + libproxy_sources,
    nsversion: api_version,
    namespace: 'Libproxy',
    export_packages: package_api_name,
    symbol_prefix: 'px',
    identifier_prefix: 'px',
    link_with: libproxy,
    includes: [ 'Gio-2.0' ],
    install: true,
    install_dir_gir: girdir,
    install_dir_typelib: typelibdir,
    extra_args: libproxy_gir_extra_args,
  )

  if get_option('vapi')
    libproxy_vapi = gnome.generate_vapi(package_api_name,
         sources: libproxy_gir[0],
        packages: [ 'gio-2.0' ],
         install: true,
     install_dir: vapidir,
    metadata_dirs: [ meson.current_source_dir() ],
    )
  endif
endif
0707010000005E000081A400000000000000000000000166FD5717000007D3000000000000000000000000000000000000002400000000libproxy-0.5.9/src/libproxy/proxy.c/* proxy.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <gio/gio.h>

#include "px-manager.h"
#include "proxy.h"

struct _pxProxyFactory {
  PxManager *manager;
};

pxProxyFactory *px_proxy_factory_copy (pxProxyFactory *self);

G_DEFINE_BOXED_TYPE (pxProxyFactory,
                     px_proxy_factory,
                     (GBoxedCopyFunc)px_proxy_factory_copy,
                     (GFreeFunc)px_proxy_factory_free);

pxProxyFactory *
px_proxy_factory_new (void)
{
  pxProxyFactory *self = g_new0 (pxProxyFactory, 1);

  self->manager = px_manager_new ();

  return self;
}

pxProxyFactory *
px_proxy_factory_copy (pxProxyFactory *self)
{
  g_object_ref (self->manager);
  return g_memdup2 (self, sizeof (pxProxyFactory));
}

char **
px_proxy_factory_get_proxies (pxProxyFactory *self,
                              const char     *url)
{
  g_auto (GStrv) result = NULL;

  result = px_manager_get_proxies_sync (self->manager, url);
  return g_steal_pointer (&result);
}

void
px_proxy_factory_free_proxies (char **proxies)
{
  g_clear_pointer (&proxies, g_strfreev);
}

void
px_proxy_factory_free (pxProxyFactory *self)
{
  g_clear_object (&self->manager);
  g_clear_pointer (&self, g_free);
}
0707010000005F000081A400000000000000000000000166FD5717000012D7000000000000000000000000000000000000002400000000libproxy-0.5.9/src/libproxy/proxy.h/* 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
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */


#pragma once

#include <glib-object.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * 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
 *
 *   - <procotol>://[username:password@]proxy:port
 *
 *   - direct://
 *
 * Please note that the username and password in the above URLs are optional
 * and should be use to authenticate the connection if present.
 *
 * 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
}
#endif
07070100000060000081A400000000000000000000000166FD571700000035000000000000000000000000000000000000001F00000000libproxy-0.5.9/src/meson.buildsubdir('backend')
subdir('libproxy')
subdir('tools')
07070100000061000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001900000000libproxy-0.5.9/src/tools07070100000062000081A400000000000000000000000166FD5717000000BE000000000000000000000000000000000000002500000000libproxy-0.5.9/src/tools/meson.buildproxy_sources = [
  'proxy.c'
]

executable(
  'proxy',
  sources: proxy_sources,
  dependencies: libproxy_dep,
  install: true,
  include_directories: libproxy_inc
)

install_man('proxy.8')07070100000063000081A400000000000000000000000166FD571700000374000000000000000000000000000000000000002100000000libproxy-0.5.9/src/tools/proxy.8.TH PROXY 8

.SH NAME

proxy \- Libproxy test tool

.SH SYNOPSIS
.SY proxy
.B [\fIscheme://host\fB][:\fIport\fB]

.SH DESCRIPTION
The program
.B proxy
displays the proxy server that should be used to reach a given network resource.
You can provide a URL as a parameter or start the tool in interactive mode to enter multiple URLs.
As a return value the required proxy will be displayed.

libproxy is a library that provides automatic proxy configuration management using different backends.

.SH EXAMPLE
# proxy http://www.example.com

# http://127.0.0.1:8080


.SH DEBUG OUTPUT
In order to show further debug output you can set the environment variable
.B PX_DEBUG=1

During execution the tool now shows internal library information like existing
plugin modules, which configuration is used and the return values.

.SH AUTHORS
Jan-Michael Brummer <jan-michael.brummer1@volkswagen.de>07070100000064000081A400000000000000000000000166FD571700000AAA000000000000000000000000000000000000002100000000libproxy-0.5.9/src/tools/proxy.c/* proxy.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "proxy.h"

void print_proxies (char **proxies);

/**
 * Prints an array of proxies. Proxies are space separated.
 * @proxies an array containing the proxies returned by libproxy.
 */
void
print_proxies (char **proxies)
{
  int j;

  if (!proxies) {
    printf ("\n");
    return;
  }

  for (j = 0; proxies[j]; j++)
    printf ("%s%s", proxies[j], proxies[j + 1] ? " " : "\n");
}

int
main (int    argc,
      char **argv)
{
  int i;
  char url[102400];       /* Should be plently long for most URLs */
  char **proxies;

  /* Create the proxy factory object */
  pxProxyFactory *pf = px_proxy_factory_new ();
  if (!pf) {
    fprintf (stderr, "An unknown error occurred!\n");
    return 1;
  }

  /* User entered some arguments on startup. skip interactive */
  if (argc > 1) {
    for (i = 1; i < argc; i++) {
      /*
       * Get an array of proxies to use. These should be used
       * in the order returned. Only move on to the next proxy
       * if the first one fails (etc).
       */
      proxies = px_proxy_factory_get_proxies (pf, argv[i]);
      print_proxies (proxies);
      px_proxy_factory_free_proxies (proxies);
    }
  }
  /* Interactive mode */
  else {
    /* For each URL we read on STDIN, get the proxies to use */
    for (url[0] = '\0'; fgets (url, 102400, stdin) != NULL;) {
      if (url[strlen (url) - 1] == '\n') url[strlen (url) - 1] = '\0';

      /*
       * Get an array of proxies to use. These should be used
       * in the order returned. Only move on to the next proxy
       * if the first one fails (etc).
       */
      proxies = px_proxy_factory_get_proxies (pf, url);
      print_proxies (proxies);
      px_proxy_factory_free_proxies (proxies);
    }
  }
  /* Destroy the proxy factory object */
  px_proxy_factory_free (pf);
  return 0;
}
07070100000065000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001B00000000libproxy-0.5.9/subprojects07070100000066000081A400000000000000000000000166FD5717000000D2000000000000000000000000000000000000002A00000000libproxy-0.5.9/subprojects/gi-docgen.wrap[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

07070100000067000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001500000000libproxy-0.5.9/tests07070100000068000081A400000000000000000000000166FD5717000011F8000000000000000000000000000000000000002700000000libproxy-0.5.9/tests/config-env-test.c/* config-env-test.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-manager.h"

#include "px-manager-helper.h"


typedef struct {
  const char *env;
  const char *proxy;
  const char *no_proxy;
  const char *url;
  gboolean config_is_proxy;
} ConfigEnvTest;

static const ConfigEnvTest config_env_test_set[] = {
  { "HTTP_PROXY", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE},
  { "HTTP_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", TRUE},
  { "HTTP_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE},
  { "HTTP_PROXY", "http://127.0.0.1:8080", "www.example.com", "https://www.example.com", FALSE},
  { "HTTP_PROXY", "http://127.0.0.1:8080", "www.test.com", "https://www.example.com", TRUE},
  { "HTTP_PROXY", "http://127.0.0.1:8080", "*", "https://www.example.com", FALSE},
  { "http_proxy", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE},
  { "http_proxy", "http://127.0.0.1:8080", "127.0.0.0/24", "http://127.0.0.1", FALSE},
  { "http_proxy", "http://127.0.0.1:8080", "127.0.0.0/24", "http://127.0.0.2", FALSE},
  { "http_proxy", "http://127.0.0.1:8080", "127.0.0.1", "http://127.0.0.255", TRUE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[::1]/", FALSE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[::1]:80/", FALSE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[::1:1]/", TRUE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[::1:1]:80/", TRUE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[fe80::1]/", TRUE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[fe80::1]:80/", TRUE},
  { "http_proxy", "http://127.0.0.1:8080", "::1", "http://[fec0::1]/", 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},
  { "https_proxy", "http://127.0.0.1:8080", NULL, "https://www.example.com", TRUE},
  { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "https://www.example.com", FALSE},
  { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "http://www.example.com", FALSE},
  { "FTP_PROXY", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE},
  { "ftp_proxy", "http://127.0.0.1:8080", NULL, "ftp://www.example.com", TRUE},
};

static void
test_config_env (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_env_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigEnvTest test = config_env_test_set[idx];

    /* Set proxy environment variable. Must be done before px_test_manager_new()! */
    if (!g_setenv (test.env, test.proxy, TRUE)) {
      g_warning ("Could not set environment");
      continue;
    }

    if (test.no_proxy) {
      if (test.config_is_proxy)
        g_setenv ("NO_PROXY", test.no_proxy, TRUE);
      else
        g_setenv ("no_proxy", test.no_proxy, TRUE);
    }

    manager = px_test_manager_new ("config-env", NULL);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &error);
    config = px_manager_get_configuration (manager, uri);
    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 ();
}
07070100000069000081A400000000000000000000000166FD57170000206D000000000000000000000000000000000000002900000000libproxy-0.5.9/tests/config-gnome-test.c/* config-gnome-test.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-manager.h"

#include "px-manager-helper.h"

#include <gio/gio.h>

typedef struct {
  GSettings *proxy_settings;
  GSettings *http_proxy_settings;
  GSettings *https_proxy_settings;
  GSettings *ftp_proxy_settings;
  GSettings *socks_proxy_settings;
} Fixture;

enum {
  GNOME_PROXY_MODE_NONE = 0,
  GNOME_PROXY_MODE_MANUAL,
  GNOME_PROXY_MODE_AUTO
};

typedef struct {
  int mode;
  const char *proxy;
  int proxy_port;
  const char *url;
  const char *expected_return;
  gboolean success;
} ConfigGnomeTest;

static const ConfigGnomeTest config_gnome_test_set[] = {
  { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "https://www.example.com", "http://127.0.0.1:8080", TRUE},
  { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://www.example.com", "http://127.0.0.1:8080", TRUE},
  { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "ftp://www.example.com", "http://127.0.0.1:8080", TRUE},
  { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "http://localhost:1234", "http://127.0.0.1:8080", TRUE},
  { GNOME_PROXY_MODE_MANUAL, "127.0.0.1", 8080, "socks://localhost:1234", "socks://127.0.0.1:8080", TRUE},
};

static void
fixture_setup (Fixture       *self,
               gconstpointer  data)
{
  self->proxy_settings = g_settings_new ("org.gnome.system.proxy");
  self->http_proxy_settings = g_settings_new ("org.gnome.system.proxy.http");
  self->https_proxy_settings = g_settings_new ("org.gnome.system.proxy.https");
  self->ftp_proxy_settings = g_settings_new ("org.gnome.system.proxy.ftp");
  self->socks_proxy_settings = g_settings_new ("org.gnome.system.proxy.socks");
}

static void
fixture_teardown (Fixture       *fixture,
                  gconstpointer  data)
{
}

static void
test_config_gnome_none (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_strv (self->proxy_settings, "ignore-hosts", NULL);
  g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_NONE);

  manager = px_test_manager_new ("config-gnome", NULL);
  g_clear_error (&error);

  uri = g_uri_parse ("https://127.0.0.1", G_URI_FLAGS_NONE, &error);
  if (!uri) {
    g_warning ("Could not parse url: %s", error ? error->message : "");
    g_assert_not_reached ();
  }

  config = px_manager_get_configuration (manager, uri);
  g_assert_nonnull (config);
  g_assert_null (config[0]);

  g_clear_object (&manager);
}

static void
test_config_gnome_manual (Fixture    *self,
                          const void *user_data)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_gnome_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigGnomeTest test = config_gnome_test_set[idx];

    g_settings_set_strv (self->proxy_settings, "ignore-hosts", NULL);
    g_settings_set_enum (self->proxy_settings, "mode", test.mode);
    g_settings_set_string (self->http_proxy_settings, "host", test.proxy);
    g_settings_set_int (self->http_proxy_settings, "port", test.proxy_port);
    g_settings_set_string (self->https_proxy_settings, "host", test.proxy);
    g_settings_set_int (self->https_proxy_settings, "port", test.proxy_port);
    g_settings_set_string (self->ftp_proxy_settings, "host", test.proxy);
    g_settings_set_int (self->ftp_proxy_settings, "port", test.proxy_port);
    g_settings_set_string (self->socks_proxy_settings, "host", test.proxy);
    g_settings_set_int (self->socks_proxy_settings, "port", test.proxy_port);

    manager = px_test_manager_new ("config-gnome", NULL);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    g_assert_cmpstr (config[0], ==, test.expected_return);

    g_clear_object (&manager);
  }
}

static void
test_config_gnome_manual_auth (Fixture    *self,
                               const void *user_data)
{
  g_autoptr (PxManager) manager = NULL;
  g_autoptr (GError) error = NULL;
  g_autoptr (GUri) uri = NULL;
  g_auto (GStrv) config = NULL;

  g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_MANUAL);
  g_settings_set_string (self->http_proxy_settings, "host", "127.0.0.1");
  g_settings_set_int (self->http_proxy_settings, "port", 9876);
  g_settings_set_boolean (self->http_proxy_settings, "use-authentication", TRUE);
  g_settings_set_string (self->http_proxy_settings, "authentication-user", "test");
  g_settings_set_string (self->http_proxy_settings, "authentication-password", "pwd");

  manager = px_test_manager_new ("config-gnome", NULL);
  g_clear_error (&error);

  uri = g_uri_parse ("http://www.example.com", G_URI_FLAGS_NONE, &error);

  config = px_manager_get_configuration (manager, uri);
  g_assert_cmpstr (config[0], ==, "http://test:pwd@127.0.0.1:9876");
}

static void
test_config_gnome_auto (Fixture    *self,
                        const void *user_data)
{
  g_autoptr (PxManager) manager = NULL;
  g_autoptr (GError) error = NULL;
  g_auto (GStrv) config = NULL;
  g_autoptr (GUri) uri = NULL;

  manager = px_test_manager_new ("config-gnome", NULL);
  g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO);
  g_settings_set_string (self->proxy_settings, "autoconfig-url", "");

  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
  config = px_manager_get_configuration (manager, uri);
  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);
  g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1:3435");
}

static void
test_config_gnome_fail (Fixture    *self,
                        const void *user_data)
{
  g_autoptr (PxManager) manager = NULL;
  g_autoptr (GError) error = NULL;
  g_auto (GStrv) config = NULL;
  g_autoptr (GUri) uri = NULL;

  /* Disable GNOME support */
  if (!g_setenv ("XDG_CURRENT_DESKTOP", "unknown", TRUE)) {
    g_warning ("Could not set XDG_CURRENT_DESKTOP environment, abort");
    return;
  }

  manager = px_test_manager_new ("config-gnome", NULL);
  g_settings_set_enum (self->proxy_settings, "mode", GNOME_PROXY_MODE_AUTO);
  g_settings_set_string (self->proxy_settings, "autoconfig-url", "");

  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);
  config = px_manager_get_configuration (manager, uri);
  g_assert_null (config[0]);
}

int
main (int    argc,
      char **argv)
{
  g_test_init (&argc, &argv, NULL);

  g_setenv ("XDG_CURRENT_DESKTOP", "GNOME", TRUE);

  g_test_add ("/config/gnome/none", Fixture, NULL, fixture_setup, test_config_gnome_none, 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 ();
}
0707010000006A000081A400000000000000000000000166FD571700001AC2000000000000000000000000000000000000002700000000libproxy-0.5.9/tests/config-kde-test.c/* config-kde-test.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-manager.h"

#include "px-manager-helper.h"


typedef struct {
  const char *url;
  const char *proxy;
  gboolean success;
} ConfigKdeTest;

static const ConfigKdeTest config_kde_manual_test_set[] = {
  { "https://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "http://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "ftp://www.example.com", "ftp://127.0.0.1:8080", TRUE},
  { "socks://www.example.com", "socks://127.0.0.1:8080", TRUE},
  { "http://localhost:1234", "http://127.0.0.1:8080", FALSE},
  { "socks://localhost:1234", "http://127.0.0.1:8080", FALSE},
  { "socks://localhost:1234", "socks://127.0.0.1:8080", FALSE},
};

static const ConfigKdeTest config_kde_wpad_test_set[] = {
  { "https://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "http://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "ftp://www.example.com", "ftp://127.0.0.1:8080", TRUE},
  { "http://localhost:1234", "http://127.0.0.1:8080", FALSE},
};

static const ConfigKdeTest config_kde_pac_test_set[] = {
  { "https://www.example.com", "http://127.0.0.1:8080", TRUE},
};

static void
test_config_kde_disabled (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_kde_manual_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigKdeTest test = config_kde_manual_test_set[idx];
    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-disabled", NULL);

    manager = px_test_manager_new ("config-kde", path);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    g_assert_cmpstr (config[0], !=, test.proxy);

    g_clear_object (&manager);
  }
}

static void
test_config_kde_manual (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_kde_manual_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigKdeTest test = config_kde_manual_test_set[idx];
    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-manual", NULL);

    manager = px_test_manager_new ("config-kde", path);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    if (test.success)
      g_assert_cmpstr (config[0], ==, test.proxy);
    else
      g_assert_cmpstr (config[0], !=, test.proxy);

    g_clear_object (&manager);
  }
}

static void
test_config_kde_wpad (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_kde_wpad_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigKdeTest test = config_kde_wpad_test_set[idx];
    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-wpad", NULL);

    manager = px_test_manager_new ("config-kde", path);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    if (test.success)
      g_assert_cmpstr (config[0], ==, "wpad://");
    else
      g_assert_cmpstr (config[0], !=, "wpad://");

    g_clear_object (&manager);
  }
}

static void
test_config_kde_pac (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_kde_pac_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigKdeTest test = config_kde_pac_test_set[idx];
    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL);

    manager = px_test_manager_new ("config-kde", path);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    if (test.success)
      g_assert_cmpstr (config[0], ==, "pac+http://127.0.0.1/px-manager-sample.pac");
    else
      g_assert_cmpstr (config[0], !=, "pac+http://127.0.0.1/px-manager-sample.pac");

    g_clear_object (&manager);
  }
}

static void
test_config_kde_fail (void)
{
  g_autoptr (PxManager) manager = NULL;
  g_autoptr (GError) error = NULL;
  g_autoptr (GUri) uri = NULL;
  g_auto (GStrv) config = NULL;
  g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-kde-proxy-pac", NULL);

  /* Disable KDE support */
  g_setenv ("XDG_CURRENT_DESKTOP", "SOMETHING_ELSE", TRUE);

  manager = px_test_manager_new ("config-kde", path);

  uri = g_uri_parse ("https://www.example.com", G_URI_FLAGS_NONE, &error);

  config = px_manager_get_configuration (manager, uri);
  g_print ("%s", config[0]);
  g_assert_null (config[0]);
}

int
main (int    argc,
      char **argv)
{
  g_test_init (&argc, &argv, NULL);

  g_setenv ("XDG_CURRENT_DESKTOP", "KDE", TRUE);

  g_test_add_func ("/config/kde/disabled", test_config_kde_disabled);
  g_test_add_func ("/config/kde/manual", test_config_kde_manual);
  g_test_add_func ("/config/kde/wpad", test_config_kde_wpad);
  g_test_add_func ("/config/kde/pac", test_config_kde_pac);
  g_test_add_func ("/config/kde/fail", test_config_kde_fail);

  return g_test_run ();
}
0707010000006B000081A400000000000000000000000166FD5717000005F9000000000000000000000000000000000000002700000000libproxy-0.5.9/tests/config-osx-test.c/* 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_NONE, &error);
  config = px_manager_get_configuration (manager, uri);
  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 ();
}
0707010000006C000081A400000000000000000000000166FD571700000EB4000000000000000000000000000000000000002D00000000libproxy-0.5.9/tests/config-sysconfig-test.c/* config-sysconfig-test.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-manager.h"

#include "px-manager-helper.h"

typedef struct {
  const char *url;
  const char *proxy;
  gboolean success;
} ConfigSysConfigTest;

static const ConfigSysConfigTest config_sysconfig_test_set[] = {
  { "https://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "http://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "ftp://www.example.com", "http://127.0.0.1:8080", TRUE},
  { "http://localhost:1234", "http://127.0.0.1:8080", FALSE},
  { "tcp://localhost:1234", "http://127.0.0.1:8080", FALSE},
};

static const ConfigSysConfigTest config_sysconfig_test_invalid_set[] = {
  { "https://www.example.com", "http://127.0.0.1:8080", FALSE},
};

static void
test_config_sysconfig (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_sysconfig_test_set); idx++) {
    g_autoptr (PxManager) manager = NULL;
    g_autoptr (GError) error = NULL;
    g_autoptr (GUri) uri = NULL;
    g_auto (GStrv) config = NULL;
    ConfigSysConfigTest test = config_sysconfig_test_set[idx];
    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy", NULL);

    manager = px_test_manager_new ("config-sysconfig", path);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    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_sysconfig_invalid (void)
{
  int idx;

  for (idx = 0; idx < G_N_ELEMENTS (config_sysconfig_test_invalid_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_invalid_set[idx];
    g_autofree char *path = g_test_build_filename (G_TEST_DIST, "data", "sample-sysconfig-proxy-invalid", NULL);

    manager = px_test_manager_new ("config-sysconfig", path);
    g_clear_error (&error);

    uri = g_uri_parse (test.url, G_URI_FLAGS_NONE, &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);
    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);
  g_test_add_func ("/config/sysconfig/invalid", test_config_sysconfig_invalid);

  return g_test_run ();
}
0707010000006D000081A400000000000000000000000166FD571700000610000000000000000000000000000000000000002B00000000libproxy-0.5.9/tests/config-windows-test.c/* 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_NONE, &error);
  config = px_manager_get_configuration (manager, uri);
  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 ();
}
0707010000006E000041ED00000000000000000000000266FD571700000000000000000000000000000000000000000000001A00000000libproxy-0.5.9/tests/data0707010000006F000081A400000000000000000000000166FD571700000012000000000000000000000000000000000000002C00000000libproxy-0.5.9/tests/data/px-manager-directPROXY_ENABLED="no"07070100000070000081A400000000000000000000000166FD57170000009D000000000000000000000000000000000000002C00000000libproxy-0.5.9/tests/data/px-manager-nonpacPROXY_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"
07070100000071000081A400000000000000000000000166FD5717000000EB000000000000000000000000000000000000002900000000libproxy-0.5.9/tests/data/px-manager-pacPROXY_ENABLED="yes"
HTTP_PROXY="pac+http://127.0.0.1:1983/px-manager-sample.pac"
HTTPS_PROXY="pac+http://127.0.0.1:1983/px-manager-sample.pac"
FTP_PROXY="pac+http://127.0.0.1:1983/px-manager-sample.pac"
NO_PROXY="localhost, 127.0.0.1"
07070100000072000081A400000000000000000000000166FD57170000040D000000000000000000000000000000000000003000000000libproxy-0.5.9/tests/data/px-manager-sample.pacfunction FindProxyForURL(url, host)
{
  var resolved_ip = dnsResolve(host);
  var myIP = myIpAddress();
  var privateIP = /^(0|10|127|192\.168|172\.1[6789]|172\.2[0-9]|172\.3[01]|169\.254|192\.88\.99)\.[0-9.]+$/;

  if (shExpMatch(host, "192.168.10.4"))
    return "SOCKS 127.0.0.1:1983"

  if (dnsDomainIs(host, "192.168.10.5"))
    return "SOCKS4 127.0.0.1:1983"

  if (dnsDomainIs(host, "192.168.10.6"))
    return "SOCKS4A 127.0.0.1:1983"

  if (dnsDomainIs(host, "192.168.10.7"))
    return "SOCKS5 127.0.0.1:1983"

  /* Invalid return */
  if (dnsDomainIs(host, "192.168.10.8"))
    return "PROXY %%"

  /* Invalid return */
  if (dnsDomainIs(host, "192.168.10.9"))
    return "INVALID"

  alert("DEFAULT")

  if (dnsDomainIs(host, "www.example.com"))
    return "PROXY 127.0.0.1:1984; DIRECT"

  /* 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";

  /* Return nothing to check wrong output */
}
07070100000073000081A400000000000000000000000166FD571700000073000000000000000000000000000000000000002A00000000libproxy-0.5.9/tests/data/px-manager-wpadPROXY_ENABLED="yes"
HTTP_PROXY="wpad://"
HTTPS_PROXY="wpad://"
FTP_PROXY="wpad://"
NO_PROXY="localhost, 127.0.0.1"
07070100000074000081A400000000000000000000000166FD571700000128000000000000000000000000000000000000003400000000libproxy-0.5.9/tests/data/sample-kde-proxy-disabledProxyUrlDisplayFlags=15

[Proxy Settings]
NoProxyFor=localhost,127.0.0.1
Proxy Config Script=http://127.0.0.1/px-manager-sample.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 808007070100000075000081A400000000000000000000000166FD571700000102000000000000000000000000000000000000003200000000libproxy-0.5.9/tests/data/sample-kde-proxy-manualProxyUrlDisplayFlags=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 808007070100000076000081A400000000000000000000000166FD571700000128000000000000000000000000000000000000002F00000000libproxy-0.5.9/tests/data/sample-kde-proxy-pacProxyUrlDisplayFlags=15

[Proxy Settings]
NoProxyFor=localhost,127.0.0.1
Proxy Config Script=http://127.0.0.1/px-manager-sample.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 808007070100000077000081A400000000000000000000000166FD571700000102000000000000000000000000000000000000003000000000libproxy-0.5.9/tests/data/sample-kde-proxy-wpadProxyUrlDisplayFlags=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 808007070100000078000081A400000000000000000000000166FD5717000000AE000000000000000000000000000000000000003100000000libproxy-0.5.9/tests/data/sample-sysconfig-proxyPROXY_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=""07070100000079000081A400000000000000000000000166FD571700000013000000000000000000000000000000000000003900000000libproxy-0.5.9/tests/data/sample-sysconfig-proxy-invalidPROXY_ENABLED="yes"0707010000007A000081A400000000000000000000000166FD571700000AB0000000000000000000000000000000000000002500000000libproxy-0.5.9/tests/libproxy-test.c/* libproxy-test.c
 *
 * Copyright 2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "proxy.h"

#include <gio/gio.h>

typedef struct {
  pxProxyFactory *pf;
} Fixture;

static void
fixture_setup (Fixture       *self,
               gconstpointer  data)
{
  self->pf = px_proxy_factory_new ();
}

static void
fixture_teardown (Fixture       *fixture,
                  gconstpointer  data)
{
  px_proxy_factory_free (fixture->pf);
}

static void
test_libproxy_setup (Fixture    *self,
                     const void *user_data)
{
  char **proxies = NULL;

  proxies = px_proxy_factory_get_proxies (self->pf, "https://www.example.com");
  g_assert_nonnull (proxies);
  g_assert_nonnull (proxies[0]);
  px_proxy_factory_free_proxies (proxies);

  return;

  /* FIXME: Fails on Windows */
  /* g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Could not query proxy: URI is not absolute, and no base URI was provided"); */
  /* proxies = px_proxy_factory_get_proxies (self->pf, "http_unknown://www.example.com"); */
  /* g_assert_nonnull (proxies); */
  /* g_assert_nonnull (proxies[0]); */
  /* px_proxy_factory_free_proxies (proxies); */
}

static void
test_libproxy_dup (Fixture    *self,
                   const void *user_data)
{
  pxProxyFactory *dup = g_boxed_copy (PX_TYPE_PROXY_FACTORY, self->pf);

  g_assert_nonnull (dup);
  px_proxy_factory_free (dup);
}

static void
test_libproxy_illegal_free (Fixture    *self,
                            const void *user_data)
{
  px_proxy_factory_free_proxies (NULL);
}

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);
  g_test_add ("/libproxy/dup", Fixture, NULL, fixture_setup, test_libproxy_dup, fixture_teardown);
  g_test_add ("/libproxy/illegal_free", Fixture, NULL, fixture_setup, test_libproxy_illegal_free, fixture_teardown);

  return g_test_run ();
}
0707010000007B000081A400000000000000000000000166FD571700000B39000000000000000000000000000000000000002100000000libproxy-0.5.9/tests/meson.buildif get_option('tests')
  envs = [
    'G_TEST_SRCDIR=' + meson.current_source_dir(),
    'G_TEST_BUILDDIR=' + meson.current_build_dir(),
    'GSETTINGS_BACKEND=memory',
  ]

  test_cargs = ['-UG_DISABLE_ASSERT']

  libproxy_test = executable('test-libproxy',
    ['libproxy-test.c'],
    include_directories: libproxy_inc,
    dependencies: [libproxy_dep],
  )
  test('Libproxy test',
       libproxy_test,
       env: envs
  )

  if get_option('pacrunner-duktape')
    px_manager_test = executable('test-px-manager',
      ['px-manager-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('PX Manager test',
         px_manager_test,
         env: envs
    )
  endif

  if get_option('config-env')
    config_env_test = executable('test-config-env',
      ['config-env-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('Config Environment test',
         config_env_test,
         env: envs
    )
  endif

  if get_option('config-sysconfig')
    config_sysconfig_test = executable('test-config-sysconfig',
      ['config-sysconfig-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('Config sysconfig test',
         config_sysconfig_test,
         env: envs
    )
  endif

  if get_option('config-gnome')
    config_gnome_test = executable('test-config-gnome',
      ['config-gnome-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('Config GNOME test',
         config_gnome_test,
         env: [envs, 'XDG_CURRENT_DESKTOP=GNOME'],
    )
  endif

  if get_option('config-kde')
    config_kde_test = executable('test-config-kde',
      ['config-kde-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('Config KDE test',
         config_kde_test,
         env: [envs, 'XDG_CURRENT_DESKTOP=KDE'],
    )
  endif

  if get_option('config-osx') and with_platform_darwin
    config_osx_test = executable('test-config-osx',
      ['config-osx-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('Config OSX test',
         config_osx_test,
         env: [envs],
    )
  endif

  if get_option('config-windows') and with_platform_windows
    config_windows_test = executable('test-config-windows',
      ['config-windows-test.c', 'px-manager-helper.c'],
      include_directories: px_backend_inc,
      dependencies: [glib_dep, px_backend_dep],
    )
    test('Config Windows test',
         config_windows_test,
         env: [envs],
    )
  endif
endif
0707010000007C000081A400000000000000000000000166FD5717000004E9000000000000000000000000000000000000002900000000libproxy-0.5.9/tests/px-manager-helper.c/* px-manager-helper.c
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "px-manager.h"
#include "px-manager-helper.h"

PxManager *
px_test_manager_new (const char *config_plugin, const char *config_option)
{
  return px_manager_new_with_options ("config-plugin", config_plugin,
                                      "config-option", config_option,
                                      "force-online", TRUE,
                                      NULL);
}
0707010000007D000081A400000000000000000000000166FD5717000003C6000000000000000000000000000000000000002900000000libproxy-0.5.9/tests/px-manager-helper.h/* px-manager-helper.h
 *
 * Copyright 2022-2023 The Libproxy Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#pragma once

PxManager *px_test_manager_new (const char *config_plugin, const char *config_option);
0707010000007E000081A400000000000000000000000166FD57170000320C000000000000000000000000000000000000002700000000libproxy-0.5.9/tests/px-manager-test.c/* 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 <gio/gio.h>

#define SERVER_PORT 1983

typedef struct {
  GMainLoop *loop;
  PxManager *manager;
} Fixture;

static void
send_error (GOutputStream *out,
            int            error_code,
            const char    *reason)
{
  char *res;

  res = g_strdup_printf ("HTTP/1.0 %d %s\r\n\r\n"
			 "<html><head><title>%d %s</title></head>"
			 "<body>%s</body></html>",
			 error_code, reason,
			 error_code, reason,
			 reason);
  g_output_stream_write_all (out, res, strlen (res), NULL, NULL, NULL);
  g_free (res);
}

static gboolean
on_incoming (GSocketService    *service,
             GSocketConnection *connection,
             GObject           *source_object)
{
  GOutputStream *out = NULL;
  GInputStream *in = NULL;
  g_autoptr (GDataInputStream) data = NULL;
  g_autoptr (GFile) f = NULL;
  g_autoptr (GError) error = NULL;
  g_autoptr (GFileInputStream) file_in = NULL;
  g_autoptr (GString) s = NULL;
  g_autoptr (GFileInfo) info = NULL;
  g_autofree char *line = NULL;
  g_autofree char *unescaped = NULL;
  g_autofree char *path = NULL;
  char *escaped;
  char *version;
  char *tmp;

  in = g_io_stream_get_input_stream (G_IO_STREAM (connection));
  out = g_io_stream_get_output_stream (G_IO_STREAM (connection));

  data = g_data_input_stream_new (in);
  /* Be tolerant of input */
  g_data_input_stream_set_newline_type (data, G_DATA_STREAM_NEWLINE_TYPE_ANY);

  line = g_data_input_stream_read_line (data, NULL, NULL, NULL);

  if (line == NULL) {
    send_error (out, 400, "Invalid request");
    goto out;
  }

  if (!g_str_has_prefix (line, "GET ")) {
    send_error (out, 501, "Only GET implemented");
    goto out;
  }

  escaped = line + 4; /* Skip "GET " */

  version = NULL;
  tmp = strchr (escaped, ' ');
  if (tmp == NULL) {
    send_error (out, 400, "Bad Request");
    goto out;
  }
  *tmp = 0;

  version = tmp + 1;
  if (!g_str_has_prefix (version, "HTTP/1.")) {
    send_error(out, 505, "HTTP Version Not Supported");
    goto out;
  }

  unescaped = g_uri_unescape_string (escaped, NULL);
  path = g_test_build_filename (G_TEST_DIST, "data", unescaped, NULL);
  f = g_file_new_for_path (path);

  error = NULL;
  file_in = g_file_read (f, NULL, &error);
  if (file_in == NULL) {
    send_error (out, 404, error->message);
    goto out;
  }

  s = g_string_new ("HTTP/1.0 200 OK\r\n");

  info = g_file_input_stream_query_info (file_in,
					 G_FILE_ATTRIBUTE_STANDARD_SIZE ","
					 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
					 NULL, NULL);
  if (info) {
    const char *content_type;
    char *mime_type;

    if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
      g_string_append_printf (s, "Content-Length: %"G_GINT64_FORMAT"\r\n", g_file_info_get_size (info));

    if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) {
      content_type = g_file_info_get_content_type (info);
      if (content_type) {
        mime_type = g_content_type_get_mime_type (content_type);
        if (mime_type) {
          g_string_append_printf (s, "Content-Type: %s\r\n", mime_type);
          g_free (mime_type);
        }
      }
    }
  }
  g_string_append (s, "\r\n");

  if (g_output_stream_write_all (out, s->str, s->len, NULL, NULL, NULL)) {
    g_output_stream_splice (out, G_INPUT_STREAM (file_in), 0, NULL, NULL);
  }

out:
  return TRUE;
}

static void
fixture_setup (Fixture       *fixture,
               gconstpointer  data)
{
  g_autofree char *path = NULL;

  fixture->loop = g_main_loop_new (NULL, FALSE);

  if (data)
    path = g_test_build_filename (G_TEST_DIST, "data", data, NULL);

  fixture->manager = px_test_manager_new ("config-sysconfig", path);
}

static void
fixture_teardown (Fixture       *fixture,
                  gconstpointer  data)
{
  g_clear_object (&fixture->manager);
}

static gpointer
download_pac (gpointer data)
{
  Fixture *self = data;
  GBytes *pac;

  pac = px_manager_pac_download (self->manager, "http://127.0.0.1:1983/px-manager-sample.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, "");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  config = px_manager_get_proxies_sync (self->manager, "nonsense");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com");
  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");
  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;

  g_setenv("PX_DEBUG_PACALERT", "1", TRUE);

  config = px_manager_get_proxies_sync (self->manager, "https://www.example.com");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "http://127.0.0.1:1984");
  g_assert_cmpstr (config[1], ==, "direct://");

  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.4");
  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");
  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");
  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");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "socks5://127.0.0.1:1983");

  /* Fallback */
  config = px_manager_get_proxies_sync (self->manager, "https://192.168.11.8");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  /* Invalid return URI */
  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.8");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  /* Invalid return URI */
  config = px_manager_get_proxies_sync (self->manager, "https://192.168.10.9");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  /* Invalid input url */
  config = px_manager_get_proxies_sync (self->manager, "invalid");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  g_main_loop_quit (self->loop);
  g_unsetenv("PX_DEBUG_PACALERT");

  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 void
test_get_proxies_pac_debug (Fixture    *self,
                            const void *user_data)
{
  g_autoptr (GThread) thread = NULL;

  g_setenv("PX_DEBUG", "1", TRUE);
  thread = g_thread_new ("test", (GThreadFunc)get_proxies_pac, self);
  g_main_loop_run (self->loop);
  g_unsetenv ("PX_DEBUG");
}

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");
  g_assert_nonnull (config);
  g_assert_cmpstr (config[0], ==, "direct://");

  g_main_loop_quit (self->loop);

  return NULL;
}

static void
test_get_wpad (Fixture    *self,
               const void *user_data)
{
  g_autoptr (GThread) thread = NULL;

  thread = g_thread_new ("test", (GThreadFunc)get_wpad, self);
  g_main_loop_run (self->loop);
}

static void
test_ignore_domain (Fixture    *self,
                    const void *user_data)
{
  g_autoptr (GUri) uri = g_uri_parse("http://10.10.1.12", G_URI_FLAGS_NONE, 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_NONE, 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_NONE, NULL);
  char **ignore_list = g_malloc0 (sizeof (char *) * 2);
  gboolean ret;

  /* Invalid test */
  ignore_list[0] = g_strdup ("<local>");
  ignore_list[1] = NULL;

  ret = px_manager_is_ignore (uri, ignore_list);
  g_assert_false (ret);
  g_uri_unref (uri);

  /* Valid test */
  uri = g_uri_parse("http://127.0.0.1", G_URI_FLAGS_NONE, 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)
{
  g_autoptr (GSocketService) service = NULL;
  g_autoptr (GError) error = NULL;

  g_test_init (&argc, &argv, NULL);

  service = g_socket_service_new ();
  if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (service), SERVER_PORT, NULL, &error)) {
    g_error ("Could not create server socket: %s", error ? error->message : "?");
    return -1;
  }

  g_signal_connect (service, "incoming", G_CALLBACK (on_incoming), NULL);

  g_test_add ("/pac/download", Fixture, "px-manager-direct", fixture_setup, test_pac_download, fixture_teardown);
  g_test_add ("/pac/get_proxies_direct", Fixture, "px-manager-direct", fixture_setup, test_get_proxies_direct, fixture_teardown);
  g_test_add ("/pac/get_proxies_nonpac", Fixture, "px-manager-nonpac", fixture_setup, test_get_proxies_nonpac, fixture_teardown);
  g_test_add ("/pac/get_proxies_pac", Fixture, "px-manager-pac", fixture_setup, test_get_proxies_pac, fixture_teardown);
  g_test_add ("/pac/wpad", Fixture, "px-manager-wpad", fixture_setup, test_get_wpad, fixture_teardown);
  g_test_add ("/pac/get_proxies_pac_debug", Fixture, "px-manager-pac", fixture_setup, test_get_proxies_pac_debug, 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 ();
}

07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!526 blocks
openSUSE Build Service is sponsored by