SERVER-95368 Upgrade c-ares library to 1.27.0 (#31344)
GitOrigin-RevId: 3ce1565a579200b4c4204407cafa2b68c27e7897
This commit is contained in:
parent
3730f4b6d0
commit
2b3a3c7b61
@ -28,7 +28,7 @@ a notice will be included in
|
||||
| [Asio C++ Library] | BSL-1.0 | 1.12.2 | | ✗ |
|
||||
| [benchmark] | Apache-2.0 | v1.5.2 | | |
|
||||
| [Boost C++ Libraries - boost] | BSL-1.0 | 1.79.0 | | ✗ |
|
||||
| [c-ares] | MIT | 1.19.1 | | ✗ |
|
||||
| [c-ares] | MIT | 1.27.0 | | ✗ |
|
||||
| [concurrencytest] | GPL-3.0-or-later | 0.1.2 | unknown | |
|
||||
| [Cyrus SASL] | BSD-Attribution-HPND-disclaimer | 2.1.28 | unknown | |
|
||||
| [dcleblanc/SafeInt] | MIT | 3.0.26 | | ✗ |
|
||||
|
||||
@ -234,7 +234,7 @@
|
||||
"name": "Organization: github"
|
||||
},
|
||||
"name": "c-ares",
|
||||
"version": "1.19.1",
|
||||
"version": "1.27.0",
|
||||
"licenses": [
|
||||
{
|
||||
"license": {
|
||||
@ -242,7 +242,7 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"purl": "pkg:github/c-ares/c-ares@cares-1_19_1",
|
||||
"purl": "pkg:github/c-ares/c-ares@cares-1_27_0",
|
||||
"properties": [
|
||||
{
|
||||
"name": "internal:team_responsible",
|
||||
|
||||
38
src/third_party/cares/BUILD.bazel
vendored
38
src/third_party/cares/BUILD.bazel
vendored
@ -7,18 +7,39 @@ mongo_cc_library(
|
||||
srcs = [
|
||||
"dist/src/lib/ares__addrinfo2hostent.c",
|
||||
"dist/src/lib/ares__addrinfo_localhost.c",
|
||||
"dist/src/lib/ares__buf.c",
|
||||
"dist/src/lib/ares__close_sockets.c",
|
||||
"dist/src/lib/ares__get_hostent.c",
|
||||
"dist/src/lib/ares__hosts_file.c",
|
||||
"dist/src/lib/ares__htable.c",
|
||||
"dist/src/lib/ares__htable_asvp.c",
|
||||
"dist/src/lib/ares__htable_strvp.c",
|
||||
"dist/src/lib/ares__htable_szvp.c",
|
||||
"dist/src/lib/ares__iface_ips.c",
|
||||
"dist/src/lib/ares__llist.c",
|
||||
"dist/src/lib/ares__parse_into_addrinfo.c",
|
||||
"dist/src/lib/ares__read_line.c",
|
||||
"dist/src/lib/ares__readaddrinfo.c",
|
||||
"dist/src/lib/ares__slist.c",
|
||||
"dist/src/lib/ares__socket.c",
|
||||
"dist/src/lib/ares__sortaddrinfo.c",
|
||||
"dist/src/lib/ares__threads.c",
|
||||
"dist/src/lib/ares__timeval.c",
|
||||
"dist/src/lib/ares_android.c",
|
||||
"dist/src/lib/ares_cancel.c",
|
||||
"dist/src/lib/ares_create_query.c",
|
||||
"dist/src/lib/ares_data.c",
|
||||
"dist/src/lib/ares_destroy.c",
|
||||
"dist/src/lib/ares_dns_mapping.c",
|
||||
"dist/src/lib/ares_dns_name.c",
|
||||
"dist/src/lib/ares_dns_parse.c",
|
||||
"dist/src/lib/ares_dns_record.c",
|
||||
"dist/src/lib/ares_dns_write.c",
|
||||
"dist/src/lib/ares_event_epoll.c",
|
||||
"dist/src/lib/ares_event_kqueue.c",
|
||||
"dist/src/lib/ares_event_poll.c",
|
||||
"dist/src/lib/ares_event_select.c",
|
||||
"dist/src/lib/ares_event_thread.c",
|
||||
"dist/src/lib/ares_event_wake_pipe.c",
|
||||
"dist/src/lib/ares_event_win32.c",
|
||||
"dist/src/lib/ares_expand_name.c",
|
||||
"dist/src/lib/ares_expand_string.c",
|
||||
"dist/src/lib/ares_fds.c",
|
||||
@ -33,9 +54,8 @@ mongo_cc_library(
|
||||
"dist/src/lib/ares_getsock.c",
|
||||
"dist/src/lib/ares_init.c",
|
||||
"dist/src/lib/ares_library_init.c",
|
||||
"dist/src/lib/ares_llist.c",
|
||||
"dist/src/lib/ares_math.c",
|
||||
"dist/src/lib/ares_mkquery.c",
|
||||
"dist/src/lib/ares_nowarn.c",
|
||||
"dist/src/lib/ares_options.c",
|
||||
"dist/src/lib/ares_parse_a_reply.c",
|
||||
"dist/src/lib/ares_parse_aaaa_reply.c",
|
||||
@ -47,20 +67,23 @@ mongo_cc_library(
|
||||
"dist/src/lib/ares_parse_soa_reply.c",
|
||||
"dist/src/lib/ares_parse_srv_reply.c",
|
||||
"dist/src/lib/ares_parse_txt_reply.c",
|
||||
"dist/src/lib/ares_parse_uri_reply.c",
|
||||
"dist/src/lib/ares_platform.c",
|
||||
"dist/src/lib/ares_process.c",
|
||||
"dist/src/lib/ares_qcache.c",
|
||||
"dist/src/lib/ares_query.c",
|
||||
"dist/src/lib/ares_rand.c",
|
||||
"dist/src/lib/ares_search.c",
|
||||
"dist/src/lib/ares_send.c",
|
||||
"dist/src/lib/ares_str.c",
|
||||
"dist/src/lib/ares_strcasecmp.c",
|
||||
"dist/src/lib/ares_strdup.c",
|
||||
"dist/src/lib/ares_strerror.c",
|
||||
"dist/src/lib/ares_strsplit.c",
|
||||
"dist/src/lib/ares_sysconfig.c",
|
||||
"dist/src/lib/ares_sysconfig_files.c",
|
||||
"dist/src/lib/ares_timeout.c",
|
||||
"dist/src/lib/ares_update_servers.c",
|
||||
"dist/src/lib/ares_version.c",
|
||||
"dist/src/lib/ares_writev.c",
|
||||
"dist/src/lib/bitncmp.c",
|
||||
"dist/src/lib/inet_net_pton.c",
|
||||
"dist/src/lib/inet_ntop.c",
|
||||
"dist/src/lib/windows_port.c",
|
||||
@ -93,6 +116,7 @@ mongo_cc_library(
|
||||
}) + select({
|
||||
"@//bazel/config:not_windows": [
|
||||
"-Wno-implicit-fallthrough",
|
||||
"-Wno-unused-result",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
|
||||
14
src/third_party/cares/dist/CHANGES.0
vendored
14
src/third_party/cares/dist/CHANGES.0
vendored
@ -250,7 +250,7 @@ Version 1.7.0 (Nov 30, 2009)
|
||||
which are _not_ related with memory tracking. For the c-ares library when
|
||||
--enable-debug is given it does not enable the memory tracking feature. If
|
||||
you wish to enable the curl debug memory tracking you must use configure
|
||||
option --enable-curldebug explicitily to do so.
|
||||
option --enable-curldebug explicitly to do so.
|
||||
|
||||
Internally, definition of preprocessor symbol DEBUGBUILD restricts code
|
||||
which is only compiled for debug enabled builds. And symbol CURLDEBUG is
|
||||
@ -376,7 +376,7 @@ Version 1.6.0 (Dec 9, 2008)
|
||||
buffer to shrink instead of expand if a reply contained 8 or more records.
|
||||
|
||||
* Nov 25 2008 (Yang Tse)
|
||||
- In preparation for the upcomming IPv6 nameservers patch, the internal
|
||||
- In preparation for the upcoming IPv6 nameservers patch, the internal
|
||||
ares_addr union is now changed into an internal struct which also holds
|
||||
the address family.
|
||||
|
||||
@ -533,7 +533,7 @@ Version 1.5.3 (Aug 29, 2008)
|
||||
elsewhere). The define was also somewhat artificially used in the windows
|
||||
port. Now, I instead rewrote the use of gethostbyname to enlarge the host
|
||||
name buffer in case of need and totally avoid the use of the MAXHOSTNAMELEN
|
||||
define. I thus also removed the defien from the namser.h file where it was
|
||||
define. I thus also removed the define from the namser.h file where it was
|
||||
once added for the windows build.
|
||||
|
||||
I also fixed init_by_defaults() function to not leak memory in case if
|
||||
@ -673,7 +673,7 @@ Version 1.5.0 (Nov 21, 2007)
|
||||
|
||||
3. The third problem is that Valgrind assumes that query->qid is not
|
||||
initialised correctly. And it does that because query->qid is set from
|
||||
DNS_HEADER_QID(qbuf); Valgrind says that qbuf has unitialised bytes. And
|
||||
DNS_HEADER_QID(qbuf); Valgrind says that qbuf has uninitialised bytes. And
|
||||
qbuf has uninitialised bytes because of channel->next_id . And next_id is
|
||||
set by ares_init.c:ares__generate_new_id() . I found that putting short r=0
|
||||
in this function (instead of short r) makes all Valgrind warnings go away.
|
||||
@ -681,8 +681,8 @@ Version 1.5.0 (Nov 21, 2007)
|
||||
|
||||
buffer_ptr[counter] ^= state[xorIndex]; (ares_query.c:62)
|
||||
|
||||
This is what triggers Valgrind.. buffer_ptr is unitialised in this function,
|
||||
and by applying ^= on it, it remains unitialised.
|
||||
This is what triggers Valgrind.. buffer_ptr is uninitialised in this function,
|
||||
and by applying ^= on it, it remains uninitialised.
|
||||
|
||||
Version 1.4.0 (June 8, 2007)
|
||||
|
||||
@ -1094,7 +1094,7 @@ Version 1.2.1 (October 20, 2004)
|
||||
from a series of registry branches.
|
||||
|
||||
This can be wrong in the case where DHCP has assigned nameservers, but the
|
||||
user has overridden these servers with other prefered settings. Then it's
|
||||
user has overridden these servers with other preferred settings. Then it's
|
||||
wrong to use the DHCPNAMESERVER setting in registry.
|
||||
|
||||
In the case of no global DHCP-assigned or fixed servers, but DNS server(s)
|
||||
|
||||
52
src/third_party/cares/dist/INSTALL.md
vendored
52
src/third_party/cares/dist/INSTALL.md
vendored
@ -32,7 +32,7 @@ the same for both Git and official release tarballs.
|
||||
AutoTools Build
|
||||
===============
|
||||
|
||||
### General Information, works on most Unix Platforms (Linux, FreeBSD, etc)
|
||||
### General Information, works on most Unix Platforms (Linux, FreeBSD, etc.)
|
||||
|
||||
A normal Unix installation is made in three or four steps (after you've
|
||||
unpacked the source archive):
|
||||
@ -57,7 +57,7 @@ you need to specify that already when running configure:
|
||||
|
||||
If you happen to have write permission in that directory, you can do `make
|
||||
install` without being root. An example of this would be to make a local
|
||||
install in your own home directory:
|
||||
installation in your own home directory:
|
||||
|
||||
./configure --prefix=$HOME
|
||||
make
|
||||
@ -183,7 +183,7 @@ Method using a configure cross-compile (tested with Android NDK r7b):
|
||||
|
||||
./tools/make-standalone-toolchain.sh
|
||||
|
||||
which creates a usual cross-compile toolchain. Lets assume that you put
|
||||
which creates a usual cross-compile toolchain. Let's assume that you put
|
||||
this toolchain below `/opt` then invoke configure with something
|
||||
like:
|
||||
|
||||
@ -213,7 +213,7 @@ CMake builds
|
||||
============
|
||||
|
||||
Current releases of c-ares introduce a CMake v3+ build system that has been
|
||||
tested on most platforms including Windows, Linux, FreeBSD, MacOS, AIX and
|
||||
tested on most platforms including Windows, Linux, FreeBSD, macOS, AIX and
|
||||
Solaris.
|
||||
|
||||
In the most basic form, building with CMake might look like:
|
||||
@ -233,18 +233,23 @@ Options
|
||||
Options to CMake are passed on the command line using "-D${OPTION}=${VALUE}".
|
||||
The values defined are all boolean and take values like On, Off, True, False.
|
||||
|
||||
* CARES_STATIC - Build the static library (off by default)
|
||||
* CARES_SHARED - Build the shared library (on by default)
|
||||
* CARES_INSTALL - Hook in installation, useful to disable if chain building
|
||||
* CARES_STATIC_PIC - Build the static library as position-independent (off by
|
||||
default)
|
||||
|
||||
| Option Name | Description | Default Value |
|
||||
|-----------------------------|-----------------------------------------------------------------------|----------------|
|
||||
| CARES_STATIC | Build the static library | Off |
|
||||
| CARES_SHARED | Build the shared library | On |
|
||||
| CARES_INSTALL | Hook in installation, useful to disable if chain building | On |
|
||||
| CARES_STATIC_PIC | Build the static library as position-independent | Off |
|
||||
| CARES_BUILD_TESTS | Build and run tests | Off |
|
||||
| CARES_BUILD_CONTAINER_TESTS | Build and run container tests (implies CARES_BUILD_TESTS, Linux only) | Off |
|
||||
| CARES_BUILD_TOOLS | Build tools | On |
|
||||
| CARES_SYMBOL_HIDING | Hide private symbols in shared libraries | Off |
|
||||
| CARES_THREADS | Build with thread-safety support | On |
|
||||
|
||||
Ninja
|
||||
-----
|
||||
|
||||
Ninja is the next-generation build system meant for generators like CMake that
|
||||
heavily parallize builds. Its use is very similar to the normal build:
|
||||
heavily parallelize builds. Its use is very similar to the normal build:
|
||||
|
||||
```sh
|
||||
cd /path/to/cmake/source
|
||||
@ -291,16 +296,12 @@ As a general rule, building a DLL with static CRT linkage is highly
|
||||
discouraged, and intermixing CRTs in the same app is something to
|
||||
avoid at any cost.
|
||||
|
||||
Reading and comprehension of Microsoft Knowledge Base articles
|
||||
KB94248 and KB140584 is a must for any Windows developer. Especially
|
||||
Reading and comprehension of the following Microsoft Learn article
|
||||
is a must for any Windows developer. Especially
|
||||
important is full understanding if you are not going to follow the
|
||||
advice given above.
|
||||
|
||||
- [KB94248](http://support.microsoft.com/kb/94248/en-us) - How To Use the C Run-Time
|
||||
|
||||
- [KB140584](http://support.microsoft.com/kb/140584/en-us) - How to link with the correct C Run-Time (CRT) library
|
||||
|
||||
- [KB190799](http://msdn.microsoft.com/en-us/library/ms235460) - Potential Errors Passing CRT Objects Across DLL Boundaries
|
||||
- [Use the C Run-Time](https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/libraries/use-c-run-time)
|
||||
|
||||
If your app is misbehaving in some strange way, or it is suffering
|
||||
from memory corruption, before asking for further help, please try
|
||||
@ -397,6 +398,21 @@ You can build and install c-ares using [vcpkg](https://github.com/Microsoft/vcpk
|
||||
|
||||
The c-ares port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
WATCOM
|
||||
=====
|
||||
|
||||
To build c-ares with OpenWatcom, you need to have at least version 1.9 of OpenWatcom. You can get the latest version from [http://openwatcom.org/ftp/install/](http://openwatcom.org/ftp/install/). Install the version that corresponds to your current host platform.
|
||||
|
||||
After installing OpenWatcom, open a new command prompt and execute the following commands:
|
||||
|
||||
```
|
||||
cd \path\to\cmake\source
|
||||
buildconf.bat
|
||||
wmake -u -f Makefile.Watcom
|
||||
```
|
||||
|
||||
After running wmake, you should get adig.exe, ahost.exe, and the static and dynamic versions of libcares.
|
||||
|
||||
PORTS
|
||||
=====
|
||||
|
||||
|
||||
32
src/third_party/cares/dist/LICENSE.md
vendored
32
src/third_party/cares/dist/LICENSE.md
vendored
@ -1,15 +1,27 @@
|
||||
# c-ares license
|
||||
|
||||
Copyright (c) 2007 - 2018, Daniel Stenberg with many contributors, see AUTHORS
|
||||
MIT License
|
||||
|
||||
|
||||
Copyright (c) 1998 Massachusetts Institute of Technology
|
||||
Copyright (c) 2007 - 2023 Daniel Stenberg with many contributors, see AUTHORS
|
||||
file.
|
||||
|
||||
Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted, provided that
|
||||
the above copyright notice appear in all copies and that both that copyright
|
||||
notice and this permission notice appear in supporting documentation, and that
|
||||
the name of M.I.T. not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior permission.
|
||||
M.I.T. makes no representations about the suitability of this software for any
|
||||
purpose. It is provided "as is" without express or implied warranty.
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
25
src/third_party/cares/dist/LICENSES/Autoconf-exception-3.0.txt
vendored
Normal file
25
src/third_party/cares/dist/LICENSES/Autoconf-exception-3.0.txt
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
AUTOCONF CONFIGURE SCRIPT EXCEPTION
|
||||
|
||||
Version 3.0, 18 August 2009
|
||||
|
||||
Copyright © 2009 Free Software Foundation, Inc. >http://fsf.org/<
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
This Exception is an additional permission under section 7 of the GNU General Public License, version 3 ("GPLv3"). It applies to a given file that bears a notice placed by the copyright holder of the file stating that the file is governed by GPLv3 along with this Exception.
|
||||
|
||||
The purpose of this Exception is to allow distribution of Autoconf's typical output under terms of the recipient's choice (including proprietary).
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"Covered Code" is the source or object code of a version of Autoconf that is a covered work under this License.
|
||||
|
||||
"Normally Copied Code" for a version of Autoconf means all parts of its Covered Code which that version can copy from its code (i.e., not from its input file) into its minimally verbose, non-debugging and non-tracing output.
|
||||
|
||||
"Ineligible Code" is Covered Code that is not Normally Copied Code.
|
||||
1. Grant of Additional Permission.
|
||||
|
||||
You have permission to propagate output of Autoconf, even if such propagation would otherwise violate the terms of GPLv3. However, if by modifying Autoconf you cause any Ineligible Code of the version you received to become Normally Copied Code of your modified version, then you void this Exception for the resulting covered work. If you convey that resulting covered work, you must remove this Exception in accordance with the second paragraph of Section 7 of GPLv3.
|
||||
2. No Weakening of Autoconf Copyleft.
|
||||
|
||||
The availability of this Exception does not imply any general presumption that third-party software is unaffected by the copyleft requirements of the license of Autoconf.
|
||||
11
src/third_party/cares/dist/LICENSES/BSD-3-Clause.txt
vendored
Normal file
11
src/third_party/cares/dist/LICENSES/BSD-3-Clause.txt
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
Copyright (c) <year> <owner>.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
4
src/third_party/cares/dist/LICENSES/FSFAP.txt
vendored
Normal file
4
src/third_party/cares/dist/LICENSES/FSFAP.txt
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
Copying and distribution of this file, with or without modification, are
|
||||
permitted in any medium without royalty provided the copyright notice
|
||||
and this notice are preserved. This file is offered as-is, without any
|
||||
warranty.
|
||||
674
src/third_party/cares/dist/LICENSES/GPL-3.0-or-later.txt
vendored
Normal file
674
src/third_party/cares/dist/LICENSES/GPL-3.0-or-later.txt
vendored
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, 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
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state 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 program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
160
src/third_party/cares/dist/LICENSES/LGPL-2.1-or-later.txt
vendored
Normal file
160
src/third_party/cares/dist/LICENSES/LGPL-2.1-or-later.txt
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
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.
|
||||
|
||||
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 an 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!
|
||||
Standard License Header
|
||||
|
||||
<one line to give the library's name and an 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
|
||||
22
src/third_party/cares/dist/LICENSES/MIT.txt
vendored
Normal file
22
src/third_party/cares/dist/LICENSES/MIT.txt
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
16
src/third_party/cares/dist/README.md
vendored
16
src/third_party/cares/dist/README.md
vendored
@ -1,12 +1,12 @@
|
||||
c-ares
|
||||
======
|
||||
# [](https://c-ares.org/)
|
||||
|
||||
[](https://cirrus-ci.com/github/c-ares/c-ares)
|
||||
[](https://cirrus-ci.com/github/c-ares/c-ares)
|
||||
[](https://ci.appveyor.com/project/c-ares/c-ares/branch/master)
|
||||
[](https://coveralls.io/github/c-ares/c-ares)
|
||||
[](https://bestpractices.coreinfrastructure.org/projects/291)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:c-ares)
|
||||
[](https://coderelease.io/github/repository/c-ares/c-ares)
|
||||
[](https://sonarcloud.io/summary/new_code?id=c-ares_c-ares)
|
||||
[](https://scan.coverity.com/projects/c-ares)
|
||||
|
||||
This is c-ares, an asynchronous resolver library. It is intended for
|
||||
applications which need to perform DNS queries without blocking, or need to
|
||||
@ -22,15 +22,13 @@ If you find bugs, correct flaws, have questions or have comments in general in
|
||||
regard to c-ares (or by all means the original ares too), get in touch with us
|
||||
on the c-ares mailing list: https://lists.haxx.se/listinfo/c-ares
|
||||
|
||||
c-ares is of course distributed under the same MIT-style license as the
|
||||
original ares.
|
||||
c-ares is distributed under the MIT license.
|
||||
|
||||
You'll find all c-ares details and news here:
|
||||
https://c-ares.org/
|
||||
|
||||
|
||||
Notes for c-ares hackers
|
||||
------------------------
|
||||
## Notes for c-ares hackers
|
||||
|
||||
* The distributed `ares_build.h` file is only intended to be used on systems
|
||||
which can not run the also distributed configure script.
|
||||
@ -49,7 +47,7 @@ Notes for c-ares hackers
|
||||
|
||||
* If you intend to distribute an already compiled c-ares library you **MUST**
|
||||
also distribute along with it the generated `ares_build.h` which has been
|
||||
used to compile it. Otherwise the library will be of no use for the users of
|
||||
used to compile it. Otherwise, the library will be of no use for the users of
|
||||
the library that you have built. It is **your** responsibility to provide this
|
||||
file. No one at the c-ares project can know how you have built the library.
|
||||
|
||||
|
||||
2
src/third_party/cares/dist/README.msvc
vendored
2
src/third_party/cares/dist/README.msvc
vendored
@ -28,7 +28,7 @@
|
||||
depends on the MSVC compiler version being used to build c-ares.
|
||||
|
||||
Below the MSVCXX folder there will exist four folders named 'cares',
|
||||
'ahost', 'acountry', and 'adig'. The 'cares' folder is the one that
|
||||
'ahost', and 'adig'. The 'cares' folder is the one that
|
||||
holds the c-ares libraries you have just generated, the other three
|
||||
hold sample programs that use the libraries.
|
||||
|
||||
|
||||
57
src/third_party/cares/dist/RELEASE-NOTES
vendored
57
src/third_party/cares/dist/RELEASE-NOTES
vendored
@ -1,57 +0,0 @@
|
||||
c-ares version 1.19.1
|
||||
|
||||
This is a security and bugfix release.
|
||||
|
||||
A special thanks goes out to the Open Source Technology Improvement Fund
|
||||
(https://ostif.org) for sponsoring a security audit of c-ares performed by X41
|
||||
(https://x41-dsec.de).
|
||||
|
||||
Security:
|
||||
o CVE-2023-32067. High. 0-byte UDP payload causes Denial of Service [12]
|
||||
o CVE-2023-31147. Moderate. Insufficient randomness in generation of DNS
|
||||
query IDs [13]
|
||||
o CVE-2023-31130. Moderate. Buffer Underwrite in ares_inet_net_pton() [14]
|
||||
o CVE-2023-31124. Low. AutoTools does not set CARES_RANDOM_FILE during cross
|
||||
compilation [15]
|
||||
|
||||
Bug fixes:
|
||||
o Fix uninitialized memory warning in test [1]
|
||||
o Turn off IPV6_V6ONLY on Windows to allow IPv4-mapped IPv6 addresses [2]
|
||||
o ares_getaddrinfo() should allow a port of 0 [3]
|
||||
o Fix memory leak in ares_send() on error [4]
|
||||
o Fix comment style in ares_data.h [5]
|
||||
o Remove unneeded ifdef for Windows [6]
|
||||
o Fix typo in ares_init_options.3 [7]
|
||||
o Re-add support for Watcom compiler [8]
|
||||
o Sync ax_pthread.m4 with upstream [9]
|
||||
o Windows: Invalid stack variable used out of scope for HOSTS path [10]
|
||||
o Sync ax_cxx_compile_stdcxx_11.m4 with upstream to fix uclibc support [11]
|
||||
|
||||
Thanks go to these friendly people for their efforts and contributions:
|
||||
Brad House (@bradh352)
|
||||
@Chilledheart
|
||||
Daniel Stenberg (@bagder)
|
||||
Douglas R. Reno (@renodr)
|
||||
Gregor Jasny (@gjasny)
|
||||
Jay Freeman (@saurik)
|
||||
@lifenjoiner
|
||||
Nikolaos Chatzikonstantinou (@createyourpersonalaccount)
|
||||
Yijie Ma (@yijiem)
|
||||
(9 contributors)
|
||||
|
||||
References to bug reports and discussions on issues:
|
||||
[1] = https://github.com/c-ares/c-ares/pull/515
|
||||
[2] = https://github.com/c-ares/c-ares/pull/520
|
||||
[3] = https://github.com/c-ares/c-ares/issues/517
|
||||
[4] = https://github.com/c-ares/c-ares/pull/511
|
||||
[5] = https://github.com/c-ares/c-ares/pull/513
|
||||
[6] = https://github.com/c-ares/c-ares/pull/512
|
||||
[7] = https://github.com/c-ares/c-ares/pull/510
|
||||
[8] = https://github.com/c-ares/c-ares/pull/509
|
||||
[9] = https://github.com/c-ares/c-ares/pull/507
|
||||
[10] = https://github.com/c-ares/c-ares/pull/502
|
||||
[11] = https://github.com/c-ares/c-ares/pull/505
|
||||
[12] = https://github.com/c-ares/c-ares/security/advisories/GHSA-9g78-jv2r-p7vc
|
||||
[13] = https://github.com/c-ares/c-ares/security/advisories/GHSA-8r8p-23f3-64c2
|
||||
[14] = https://github.com/c-ares/c-ares/security/advisories/GHSA-x6mf-cxr9-8q6v
|
||||
[15] = https://github.com/c-ares/c-ares/security/advisories/GHSA-54xr-f67r-4pc4
|
||||
40
src/third_party/cares/dist/RELEASE-NOTES.md
vendored
Normal file
40
src/third_party/cares/dist/RELEASE-NOTES.md
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
## c-ares version 1.27.0 - Feb 23 2024
|
||||
|
||||
This is a security, feature, and bugfix release.
|
||||
|
||||
Security:
|
||||
|
||||
* Moderate. CVE-2024-25629. Reading malformatted `/etc/resolv.conf`,
|
||||
`/etc/nsswitch.conf` or the `HOSTALIASES` file could result in a crash.
|
||||
[GHSA-mg26-v6qh-x48q](https://github.com/c-ares/c-ares/security/advisories/GHSA-mg26-v6qh-x48q)
|
||||
|
||||
Features:
|
||||
|
||||
* New function `ares_queue_active_queries()` to retrieve number of in-flight
|
||||
queries. [PR #712](https://github.com/c-ares/c-ares/pull/712)
|
||||
* New function `ares_queue_wait_empty()` to wait for the number of in-flight
|
||||
queries to reach zero. [PR #710](https://github.com/c-ares/c-ares/pull/710)
|
||||
* New `ARES_FLAG_NO_DEFLT_SVR` for `ares_init_options()` to return a failure if
|
||||
no DNS servers can be found rather than attempting to use `127.0.0.1`. This
|
||||
also introduces a new ares status code of `ARES_ENOSERVER`. [PR #713](https://github.com/c-ares/c-ares/pull/713)
|
||||
|
||||
Changes:
|
||||
|
||||
* EDNS Packet size should be 1232 as per DNS Flag Day. [PR #705](https://github.com/c-ares/c-ares/pull/705)
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* Windows DNS suffix search list memory leak. [PR #711](https://github.com/c-ares/c-ares/pull/711)
|
||||
* Fix warning due to ignoring return code of `write()`. [PR #709](https://github.com/c-ares/c-ares/pull/709)
|
||||
* CMake: don't override target output locations if not top-level. [Issue #708](https://github.com/c-ares/c-ares/issues/708)
|
||||
* Fix building c-ares without thread support. [PR #700](https://github.com/c-ares/c-ares/pull/700)
|
||||
|
||||
Thanks go to these friendly people for their efforts and contributions for this release:
|
||||
|
||||
* Anthony Alayo (@anthonyalayo)
|
||||
* Brad House (@bradh352)
|
||||
* Cheng Zhao (@zcbenz)
|
||||
* Cristian Rodríguez (@crrodriguez)
|
||||
* Daniel Stenberg (@bagder)
|
||||
* Oliver Welsh (@oliverwelsh)
|
||||
* Vojtěch Vobr (@vojtechvobr)
|
||||
@ -10,6 +10,9 @@ in the source code repo
|
||||
`CARES_LIB_VERSIONINFO` set to the same value to denote the current shared
|
||||
object versioning.
|
||||
|
||||
- edit `include/ares_version.h` and set `ARES_VERSION_*` definitions to reflect
|
||||
the current version.
|
||||
|
||||
- make sure all relevant changes are committed on the master branch
|
||||
|
||||
- tag the git repo in this style: `git tag -a cares-1_14_0` -a annotates the
|
||||
@ -26,8 +29,6 @@ in the source code repo
|
||||
|
||||
- upload the resulting files to https://c-ares.org/download/
|
||||
|
||||
- update `ares_version.h` for the next version
|
||||
|
||||
in the c-ares-www repo
|
||||
----------------------
|
||||
|
||||
|
||||
21
src/third_party/cares/dist/TODO
vendored
21
src/third_party/cares/dist/TODO
vendored
@ -1,23 +1,4 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
ares_reinit()
|
||||
|
||||
- To allow an app to force a re-read of /etc/resolv.conf etc, pretty much
|
||||
like the res_init() resolver function offers
|
||||
|
||||
ares_gethostbyname
|
||||
|
||||
- When built to support IPv6, it needs to also support PF_UNSPEC or similar,
|
||||
so that an application can ask for any protocol and then c-ares would return
|
||||
all known resolves and not just explicitly IPv4 _or_ IPv6 resolves.
|
||||
|
||||
ares_process
|
||||
|
||||
- Upon next ABI breakage ares_process() should be changed to return 'int'
|
||||
and return ARES_ENOTINITIALIZED if ares_library_init() has not been called.
|
||||
|
||||
ares_process_fd
|
||||
|
||||
- Upon next ABI breakage ares_process_fd() should be changed to return
|
||||
'int' and return ARES_ENOTINITIALIZED if library has not been initialized.
|
||||
Please see https://github.com/c-ares/c-ares/issues
|
||||
|
||||
1915
src/third_party/cares/dist/acinclude.m4
vendored
1915
src/third_party/cares/dist/acinclude.m4
vendored
File diff suppressed because it is too large
Load Diff
284
src/third_party/cares/dist/aclocal.m4
vendored
284
src/third_party/cares/dist/aclocal.m4
vendored
@ -1,6 +1,6 @@
|
||||
# generated automatically by aclocal 1.15.1 -*- Autoconf -*-
|
||||
# generated automatically by aclocal 1.16.5 -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 1996-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
||||
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -14,13 +14,13 @@
|
||||
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
|
||||
m4_ifndef([AC_AUTOCONF_VERSION],
|
||||
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
|
||||
m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
|
||||
[m4_warning([this file was generated for autoconf 2.69.
|
||||
m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.71],,
|
||||
[m4_warning([this file was generated for autoconf 2.71.
|
||||
You have another version of autoconf. It may work, but is not guaranteed to.
|
||||
If you have problems, you may need to regenerate the build system entirely.
|
||||
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
|
||||
|
||||
# Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2002-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -32,10 +32,10 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
|
||||
# generated from the m4 files accompanying Automake X.Y.
|
||||
# (This private macro should not be called outside this file.)
|
||||
AC_DEFUN([AM_AUTOMAKE_VERSION],
|
||||
[am__api_version='1.15'
|
||||
[am__api_version='1.16'
|
||||
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
|
||||
dnl require some minimum version. Point them to the right macro.
|
||||
m4_if([$1], [1.15.1], [],
|
||||
m4_if([$1], [1.16.5], [],
|
||||
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
|
||||
])
|
||||
|
||||
@ -51,14 +51,14 @@ m4_define([_AM_AUTOCONF_VERSION], [])
|
||||
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
|
||||
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
|
||||
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
|
||||
[AM_AUTOMAKE_VERSION([1.15.1])dnl
|
||||
[AM_AUTOMAKE_VERSION([1.16.5])dnl
|
||||
m4_ifndef([AC_AUTOCONF_VERSION],
|
||||
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
|
||||
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
|
||||
|
||||
# AM_AUX_DIR_EXPAND -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -108,9 +108,46 @@ AC_DEFUN([AM_AUX_DIR_EXPAND],
|
||||
am_aux_dir=`cd "$ac_aux_dir" && pwd`
|
||||
])
|
||||
|
||||
# AM_COND_IF -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 2008-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# _AM_COND_IF
|
||||
# _AM_COND_ELSE
|
||||
# _AM_COND_ENDIF
|
||||
# --------------
|
||||
# These macros are only used for tracing.
|
||||
m4_define([_AM_COND_IF])
|
||||
m4_define([_AM_COND_ELSE])
|
||||
m4_define([_AM_COND_ENDIF])
|
||||
|
||||
# AM_COND_IF(COND, [IF-TRUE], [IF-FALSE])
|
||||
# ---------------------------------------
|
||||
# If the shell condition COND is true, execute IF-TRUE, otherwise execute
|
||||
# IF-FALSE. Allow automake to learn about conditional instantiating macros
|
||||
# (the AC_CONFIG_FOOS).
|
||||
AC_DEFUN([AM_COND_IF],
|
||||
[m4_ifndef([_AM_COND_VALUE_$1],
|
||||
[m4_fatal([$0: no such condition "$1"])])dnl
|
||||
_AM_COND_IF([$1])dnl
|
||||
if test -z "$$1_TRUE"; then :
|
||||
m4_n([$2])[]dnl
|
||||
m4_ifval([$3],
|
||||
[_AM_COND_ELSE([$1])dnl
|
||||
else
|
||||
$3
|
||||
])dnl
|
||||
_AM_COND_ENDIF([$1])dnl
|
||||
fi[]dnl
|
||||
])
|
||||
|
||||
# AM_CONDITIONAL -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 1997-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1997-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -141,7 +178,7 @@ AC_CONFIG_COMMANDS_PRE(
|
||||
Usually this means the macro was only invoked conditionally.]])
|
||||
fi])])
|
||||
|
||||
# Copyright (C) 1999-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -332,13 +369,12 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl
|
||||
|
||||
# Generate code to set up dependency tracking. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 1999-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
|
||||
# _AM_OUTPUT_DEPENDENCY_COMMANDS
|
||||
# ------------------------------
|
||||
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
|
||||
@ -346,49 +382,43 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
|
||||
# Older Autoconf quotes --file arguments for eval, but not when files
|
||||
# are listed without --file. Let's play safe and only enable the eval
|
||||
# if we detect the quoting.
|
||||
case $CONFIG_FILES in
|
||||
*\'*) eval set x "$CONFIG_FILES" ;;
|
||||
*) set x $CONFIG_FILES ;;
|
||||
esac
|
||||
# TODO: see whether this extra hack can be removed once we start
|
||||
# requiring Autoconf 2.70 or later.
|
||||
AS_CASE([$CONFIG_FILES],
|
||||
[*\'*], [eval set x "$CONFIG_FILES"],
|
||||
[*], [set x $CONFIG_FILES])
|
||||
shift
|
||||
for mf
|
||||
# Used to flag and report bootstrapping failures.
|
||||
am_rc=0
|
||||
for am_mf
|
||||
do
|
||||
# Strip MF so we end up with the name of the file.
|
||||
mf=`echo "$mf" | sed -e 's/:.*$//'`
|
||||
# Check whether this is an Automake generated Makefile or not.
|
||||
# We used to match only the files named 'Makefile.in', but
|
||||
# some people rename them; so instead we look at the file content.
|
||||
# Grep'ing the first line is not enough: some people post-process
|
||||
# each Makefile.in and add a new line on top of each file to say so.
|
||||
# Grep'ing the whole file is not good either: AIX grep has a line
|
||||
am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'`
|
||||
# Check whether this is an Automake generated Makefile which includes
|
||||
# dependency-tracking related rules and includes.
|
||||
# Grep'ing the whole file directly is not great: AIX grep has a line
|
||||
# limit of 2048, but all sed's we know have understand at least 4000.
|
||||
if sed -n 's,^#.*generated by automake.*,X,p' "$mf" | grep X >/dev/null 2>&1; then
|
||||
dirpart=`AS_DIRNAME("$mf")`
|
||||
else
|
||||
continue
|
||||
fi
|
||||
# Extract the definition of DEPDIR, am__include, and am__quote
|
||||
# from the Makefile without running 'make'.
|
||||
DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
|
||||
test -z "$DEPDIR" && continue
|
||||
am__include=`sed -n 's/^am__include = //p' < "$mf"`
|
||||
test -z "$am__include" && continue
|
||||
am__quote=`sed -n 's/^am__quote = //p' < "$mf"`
|
||||
# Find all dependency output files, they are included files with
|
||||
# $(DEPDIR) in their names. We invoke sed twice because it is the
|
||||
# simplest approach to changing $(DEPDIR) to its actual value in the
|
||||
# expansion.
|
||||
for file in `sed -n "
|
||||
s/^$am__include $am__quote\(.*(DEPDIR).*\)$am__quote"'$/\1/p' <"$mf" | \
|
||||
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g'`; do
|
||||
# Make sure the directory exists.
|
||||
test -f "$dirpart/$file" && continue
|
||||
fdir=`AS_DIRNAME(["$file"])`
|
||||
AS_MKDIR_P([$dirpart/$fdir])
|
||||
# echo "creating $dirpart/$file"
|
||||
echo '# dummy' > "$dirpart/$file"
|
||||
done
|
||||
sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \
|
||||
|| continue
|
||||
am_dirpart=`AS_DIRNAME(["$am_mf"])`
|
||||
am_filepart=`AS_BASENAME(["$am_mf"])`
|
||||
AM_RUN_LOG([cd "$am_dirpart" \
|
||||
&& sed -e '/# am--include-marker/d' "$am_filepart" \
|
||||
| $MAKE -f - am--depfiles]) || am_rc=$?
|
||||
done
|
||||
if test $am_rc -ne 0; then
|
||||
AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments
|
||||
for automatic dependency tracking. If GNU make was not used, consider
|
||||
re-running the configure script with MAKE="gmake" (or whatever is
|
||||
necessary). You can also try re-running configure with the
|
||||
'--disable-dependency-tracking' option to at least be able to build
|
||||
the package (albeit without support for automatic dependency tracking).])
|
||||
fi
|
||||
AS_UNSET([am_dirpart])
|
||||
AS_UNSET([am_filepart])
|
||||
AS_UNSET([am_mf])
|
||||
AS_UNSET([am_rc])
|
||||
rm -f conftest-deps.mk
|
||||
}
|
||||
])# _AM_OUTPUT_DEPENDENCY_COMMANDS
|
||||
|
||||
@ -397,18 +427,17 @@ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
|
||||
# -----------------------------
|
||||
# This macro should only be invoked once -- use via AC_REQUIRE.
|
||||
#
|
||||
# This code is only required when automatic dependency tracking
|
||||
# is enabled. FIXME. This creates each '.P' file that we will
|
||||
# need in order to bootstrap the dependency handling code.
|
||||
# This code is only required when automatic dependency tracking is enabled.
|
||||
# This creates each '.Po' and '.Plo' makefile fragment that we'll need in
|
||||
# order to bootstrap the dependency handling code.
|
||||
AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
|
||||
[AC_CONFIG_COMMANDS([depfiles],
|
||||
[test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
|
||||
[AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
|
||||
])
|
||||
[AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])])
|
||||
|
||||
# Do all the work for Automake. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 1996-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -436,6 +465,10 @@ m4_defn([AC_PROG_CC])
|
||||
# release and drop the old call support.
|
||||
AC_DEFUN([AM_INIT_AUTOMAKE],
|
||||
[AC_PREREQ([2.65])dnl
|
||||
m4_ifdef([_$0_ALREADY_INIT],
|
||||
[m4_fatal([$0 expanded multiple times
|
||||
]m4_defn([_$0_ALREADY_INIT]))],
|
||||
[m4_define([_$0_ALREADY_INIT], m4_expansion_stack)])dnl
|
||||
dnl Autoconf wants to disallow AM_ names. We explicitly allow
|
||||
dnl the ones we care about.
|
||||
m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
|
||||
@ -472,7 +505,7 @@ m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
|
||||
[_AM_SET_OPTIONS([$1])dnl
|
||||
dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT.
|
||||
m4_if(
|
||||
m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]),
|
||||
m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([AC_PACKAGE_VERSION], [ok]),
|
||||
[ok:ok],,
|
||||
[m4_fatal([AC_INIT should be called with package and version arguments])])dnl
|
||||
AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
|
||||
@ -495,8 +528,8 @@ AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl
|
||||
AC_REQUIRE([AC_PROG_MKDIR_P])dnl
|
||||
# For better backward compatibility. To be removed once Automake 1.9.x
|
||||
# dies out for good. For more background, see:
|
||||
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
|
||||
# <http://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
|
||||
# <https://lists.gnu.org/archive/html/automake/2012-07/msg00001.html>
|
||||
# <https://lists.gnu.org/archive/html/automake/2012-07/msg00014.html>
|
||||
AC_SUBST([mkdir_p], ['$(MKDIR_P)'])
|
||||
# We need awk for the "check" target (and possibly the TAP driver). The
|
||||
# system "awk" is bad on some platforms.
|
||||
@ -524,6 +557,20 @@ AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
|
||||
[m4_define([AC_PROG_OBJCXX],
|
||||
m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl
|
||||
])
|
||||
# Variables for tags utilities; see am/tags.am
|
||||
if test -z "$CTAGS"; then
|
||||
CTAGS=ctags
|
||||
fi
|
||||
AC_SUBST([CTAGS])
|
||||
if test -z "$ETAGS"; then
|
||||
ETAGS=etags
|
||||
fi
|
||||
AC_SUBST([ETAGS])
|
||||
if test -z "$CSCOPE"; then
|
||||
CSCOPE=cscope
|
||||
fi
|
||||
AC_SUBST([CSCOPE])
|
||||
|
||||
AC_REQUIRE([AM_SILENT_RULES])dnl
|
||||
dnl The testsuite driver may need to know about EXEEXT, so add the
|
||||
dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This
|
||||
@ -563,7 +610,7 @@ END
|
||||
Aborting the configuration process, to ensure you take notice of the issue.
|
||||
|
||||
You can download and install GNU coreutils to get an 'rm' implementation
|
||||
that behaves properly: <http://www.gnu.org/software/coreutils/>.
|
||||
that behaves properly: <https://www.gnu.org/software/coreutils/>.
|
||||
|
||||
If you want to complete the configuration process using your problematic
|
||||
'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
|
||||
@ -605,7 +652,7 @@ for _am_header in $config_headers :; do
|
||||
done
|
||||
echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count])
|
||||
|
||||
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -626,7 +673,7 @@ if test x"${install_sh+set}" != xset; then
|
||||
fi
|
||||
AC_SUBST([install_sh])])
|
||||
|
||||
# Copyright (C) 2003-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2003-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -648,7 +695,7 @@ AC_SUBST([am__leading_dot])])
|
||||
# Add --enable-maintainer-mode option to configure. -*- Autoconf -*-
|
||||
# From Jim Meyering
|
||||
|
||||
# Copyright (C) 1996-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -683,7 +730,7 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
|
||||
|
||||
# Check to see how 'make' treats includes. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -691,49 +738,42 @@ AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
|
||||
|
||||
# AM_MAKE_INCLUDE()
|
||||
# -----------------
|
||||
# Check to see how make treats includes.
|
||||
# Check whether make has an 'include' directive that can support all
|
||||
# the idioms we need for our automatic dependency tracking code.
|
||||
AC_DEFUN([AM_MAKE_INCLUDE],
|
||||
[am_make=${MAKE-make}
|
||||
cat > confinc << 'END'
|
||||
[AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive])
|
||||
cat > confinc.mk << 'END'
|
||||
am__doit:
|
||||
@echo this is the am__doit target
|
||||
@echo this is the am__doit target >confinc.out
|
||||
.PHONY: am__doit
|
||||
END
|
||||
# If we don't find an include directive, just comment out the code.
|
||||
AC_MSG_CHECKING([for style of include used by $am_make])
|
||||
am__include="#"
|
||||
am__quote=
|
||||
_am_result=none
|
||||
# First try GNU make style include.
|
||||
echo "include confinc" > confmf
|
||||
# Ignore all kinds of additional output from 'make'.
|
||||
case `$am_make -s -f confmf 2> /dev/null` in #(
|
||||
*the\ am__doit\ target*)
|
||||
am__include=include
|
||||
am__quote=
|
||||
_am_result=GNU
|
||||
;;
|
||||
esac
|
||||
# Now try BSD make style include.
|
||||
if test "$am__include" = "#"; then
|
||||
echo '.include "confinc"' > confmf
|
||||
case `$am_make -s -f confmf 2> /dev/null` in #(
|
||||
*the\ am__doit\ target*)
|
||||
am__include=.include
|
||||
am__quote="\""
|
||||
_am_result=BSD
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
AC_SUBST([am__include])
|
||||
AC_SUBST([am__quote])
|
||||
AC_MSG_RESULT([$_am_result])
|
||||
rm -f confinc confmf
|
||||
])
|
||||
# BSD make does it like this.
|
||||
echo '.include "confinc.mk" # ignored' > confmf.BSD
|
||||
# Other make implementations (GNU, Solaris 10, AIX) do it like this.
|
||||
echo 'include confinc.mk # ignored' > confmf.GNU
|
||||
_am_result=no
|
||||
for s in GNU BSD; do
|
||||
AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out])
|
||||
AS_CASE([$?:`cat confinc.out 2>/dev/null`],
|
||||
['0:this is the am__doit target'],
|
||||
[AS_CASE([$s],
|
||||
[BSD], [am__include='.include' am__quote='"'],
|
||||
[am__include='include' am__quote=''])])
|
||||
if test "$am__include" != "#"; then
|
||||
_am_result="yes ($s style)"
|
||||
break
|
||||
fi
|
||||
done
|
||||
rm -f confinc.* confmf.*
|
||||
AC_MSG_RESULT([${_am_result}])
|
||||
AC_SUBST([am__include])])
|
||||
AC_SUBST([am__quote])])
|
||||
|
||||
# Fake the existence of programs that GNU maintainers use. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 1997-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1997-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -754,12 +794,7 @@ AC_DEFUN([AM_MISSING_HAS_RUN],
|
||||
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
|
||||
AC_REQUIRE_AUX_FILE([missing])dnl
|
||||
if test x"${MISSING+set}" != xset; then
|
||||
case $am_aux_dir in
|
||||
*\ * | *\ *)
|
||||
MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;;
|
||||
*)
|
||||
MISSING="\${SHELL} $am_aux_dir/missing" ;;
|
||||
esac
|
||||
MISSING="\${SHELL} '$am_aux_dir/missing'"
|
||||
fi
|
||||
# Use eval to expand $SHELL
|
||||
if eval "$MISSING --is-lightweight"; then
|
||||
@ -772,7 +807,7 @@ fi
|
||||
|
||||
# Helper functions for option handling. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -801,7 +836,7 @@ AC_DEFUN([_AM_SET_OPTIONS],
|
||||
AC_DEFUN([_AM_IF_OPTION],
|
||||
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
|
||||
|
||||
# Copyright (C) 1999-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -848,7 +883,7 @@ AC_LANG_POP([C])])
|
||||
# For backward compatibility.
|
||||
AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
|
||||
|
||||
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -867,7 +902,7 @@ AC_DEFUN([AM_RUN_LOG],
|
||||
|
||||
# Check to make sure that the build environment is sane. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 1996-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -948,7 +983,7 @@ AC_CONFIG_COMMANDS_PRE(
|
||||
rm -f conftest.file
|
||||
])
|
||||
|
||||
# Copyright (C) 2009-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2009-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -1008,7 +1043,7 @@ AC_SUBST([AM_BACKSLASH])dnl
|
||||
_AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl
|
||||
])
|
||||
|
||||
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -1036,7 +1071,7 @@ fi
|
||||
INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s"
|
||||
AC_SUBST([INSTALL_STRIP_PROGRAM])])
|
||||
|
||||
# Copyright (C) 2006-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2006-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -1055,7 +1090,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
|
||||
|
||||
# Check how to create a tarball. -*- Autoconf -*-
|
||||
|
||||
# Copyright (C) 2004-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 2004-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
@ -1190,25 +1225,24 @@ m4_include([m4/ax_ac_append_to_file.m4])
|
||||
m4_include([m4/ax_ac_print_to_file.m4])
|
||||
m4_include([m4/ax_add_am_macro_static.m4])
|
||||
m4_include([m4/ax_am_macros_static.m4])
|
||||
m4_include([m4/ax_append_compile_flags.m4])
|
||||
m4_include([m4/ax_append_flag.m4])
|
||||
m4_include([m4/ax_append_link_flags.m4])
|
||||
m4_include([m4/ax_check_compile_flag.m4])
|
||||
m4_include([m4/ax_check_gnu_make.m4])
|
||||
m4_include([m4/ax_check_link_flag.m4])
|
||||
m4_include([m4/ax_check_user_namespace.m4])
|
||||
m4_include([m4/ax_check_uts_namespace.m4])
|
||||
m4_include([m4/ax_code_coverage.m4])
|
||||
m4_include([m4/ax_compiler_vendor.m4])
|
||||
m4_include([m4/ax_cxx_compile_stdcxx.m4])
|
||||
m4_include([m4/ax_cxx_compile_stdcxx_11.m4])
|
||||
m4_include([m4/ax_cxx_compile_stdcxx_14.m4])
|
||||
m4_include([m4/ax_file_escapes.m4])
|
||||
m4_include([m4/ax_pthread.m4])
|
||||
m4_include([m4/ax_require_defined.m4])
|
||||
m4_include([m4/cares-compilers.m4])
|
||||
m4_include([m4/cares-confopts.m4])
|
||||
m4_include([m4/cares-functions.m4])
|
||||
m4_include([m4/cares-reentrant.m4])
|
||||
m4_include([m4/libtool.m4])
|
||||
m4_include([m4/ltoptions.m4])
|
||||
m4_include([m4/ltsugar.m4])
|
||||
m4_include([m4/ltversion.m4])
|
||||
m4_include([m4/lt~obsolete.m4])
|
||||
m4_include([m4/xc-am-iface.m4])
|
||||
m4_include([m4/xc-cc-check.m4])
|
||||
m4_include([m4/xc-lt-iface.m4])
|
||||
m4_include([m4/xc-translit.m4])
|
||||
m4_include([m4/xc-val-flgs.m4])
|
||||
m4_include([m4/zz40-xc-ovr.m4])
|
||||
m4_include([acinclude.m4])
|
||||
m4_include([m4/pkg.m4])
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
# aminclude_static.am generated automatically by Autoconf
|
||||
# from AX_AM_MACROS_STATIC on Thu May 25 15:48:26 UTC 2023
|
||||
# from AX_AM_MACROS_STATIC on Sat Jan 18 01:12:10 UTC 2025
|
||||
|
||||
|
||||
# Code coverage
|
||||
|
||||
197
src/third_party/cares/dist/appveyor.yml
vendored
197
src/third_party/cares/dist/appveyor.yml
vendored
@ -1,4 +1,7 @@
|
||||
image: Visual Studio 2015
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
image: Previous Visual Studio 2022
|
||||
|
||||
# Github/Bitbucket only: get source code for one particular commit as zip archive, instead of git clone'ing.
|
||||
shallow_clone: true
|
||||
@ -9,53 +12,128 @@ skip_commits:
|
||||
- .gitignore
|
||||
- '**/*.md'
|
||||
- .travis.yml
|
||||
- .cirrus.yml
|
||||
- '.github/**'
|
||||
|
||||
# List of build configurations to test.
|
||||
configuration:
|
||||
- RelWithDebInfo
|
||||
- DEBUG
|
||||
|
||||
# Note: You can set extra cmake args for a particular matrix entry with CMAKE_EXTRA_OPTIONS. For example:
|
||||
# CMAKE_EXTRA_OPTIONS: -DOPENSSL_ROOT_DIR=C:/OpenSSL-Win32
|
||||
environment:
|
||||
matrix:
|
||||
# MSVC 2015, 32-bit x86 (cmake)
|
||||
# MSVC 2022, 32-bit x86 (cmake)
|
||||
- COMPILER: MSVC
|
||||
BUILDTOOL: CMAKE
|
||||
CONFTOOL: CMAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: no
|
||||
MSVC_SETUP_ARG: x86
|
||||
MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
|
||||
MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat
|
||||
CMAKE_EXTRA_OPTIONS: -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL
|
||||
TOOLSDIR: ./build/bin
|
||||
TESTDIR: ./build/bin
|
||||
BUILD_GOOGLETEST: yes
|
||||
|
||||
# MSVC 2015, 64-bit x86 (cmake)
|
||||
# MSVC 2022, 64-bit x64 (cmake)
|
||||
- COMPILER: MSVC
|
||||
BUILDTOOL: CMAKE
|
||||
CONFTOOL: CMAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: no
|
||||
MSVC_SETUP_ARG: x64
|
||||
MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
|
||||
MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
|
||||
TOOLSDIR: ./build/bin
|
||||
TESTDIR: ./build/bin
|
||||
CMAKE_EXTRA_OPTIONS: -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL
|
||||
BUILD_GOOGLETEST: yes
|
||||
|
||||
# MinGW, 32-bit x86 (cmake)
|
||||
# MinGW gcc via MSYS2 (latest version)
|
||||
- COMPILER: MINGW
|
||||
BUILDTOOL: CMAKE
|
||||
PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
|
||||
CONFTOOL: CMAKE
|
||||
SYSTEM: MSYS2
|
||||
SKIP_TESTS: no
|
||||
MSYSTEM: MINGW64
|
||||
TOOLSDIR: ./build/bin
|
||||
TESTDIR: ./build/bin
|
||||
CMAKE_EXTRA_OPTIONS: -GNinja
|
||||
CHERE_INVOKING: YES
|
||||
|
||||
# MinGW, 32-bit x86 (cmake static only)
|
||||
# MinGW gcc via MSYS2 using autotools
|
||||
- COMPILER: MINGW
|
||||
BUILDTOOL: CMAKESTATIC
|
||||
PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
|
||||
CONFTOOL: AUTOTOOLS
|
||||
SKIP_TESTS: no
|
||||
SYSTEM: MSYS2
|
||||
MSYSTEM: MINGW64
|
||||
TOOLSDIR: ./src/tools
|
||||
TESTDIR: ./test
|
||||
CHERE_INVOKING: YES
|
||||
|
||||
# MSVC 2015, 32-bit x86 (nmake)
|
||||
# MinGW clang UBSAN via MSYS2
|
||||
- COMPILER: MINGW
|
||||
CONFTOOL: CMAKE
|
||||
SKIP_TESTS: no
|
||||
SYSTEM: MSYS2
|
||||
MSYSTEM: CLANG64
|
||||
TOOLSDIR: ./build/bin
|
||||
TESTDIR: ./build/bin
|
||||
CMAKE_EXTRA_OPTIONS: -GNinja -DCMAKE_CXX_FLAGS=-fsanitize=undefined -DCMAKE_C_FLAGS=-fsanitize=undefined -DCMAKE_SHARED_LINKER_FLAGS=-fsanitize=undefined -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=undefined
|
||||
CHERE_INVOKING: YES
|
||||
|
||||
# MinGW clang ASAN via MSYS2 -- doesn't work due to some issue with clang itself
|
||||
# - COMPILER: MINGW
|
||||
# CONFTOOL: CMAKE
|
||||
# SKIP_TESTS: no
|
||||
# SYSTEM: MSYS2
|
||||
# MSYSTEM: CLANG64
|
||||
# TESTDIR: ./cmakebld/bin
|
||||
# CMAKE_EXTRA_OPTIONS: -GNinja -DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_SHARED_LINKER_FLAGS=-fsanitize=address -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address
|
||||
# CHERE_INVOKING: YES
|
||||
|
||||
# MSVC 2022, 64-bit x86 (nmake)
|
||||
- COMPILER: MSVC
|
||||
BUILDTOOL: NMAKE
|
||||
CONFTOOL: NMAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: no
|
||||
MSVC_SETUP_ARG: x64
|
||||
MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
|
||||
BUILD_GOOGLETEST: yes
|
||||
|
||||
# MSVC 2022, 32-bit x86 (nmake)
|
||||
- COMPILER: MSVC
|
||||
CONFTOOL: NMAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: no
|
||||
MSVC_SETUP_ARG: x86
|
||||
MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
|
||||
|
||||
# MSVC 2015, 64-bit x86 (nmake)
|
||||
- COMPILER: MSVC
|
||||
BUILDTOOL: NMAKE
|
||||
MSVC_SETUP_ARG: x64
|
||||
MSVC_SETUP_PATH: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
|
||||
MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat
|
||||
BUILD_GOOGLETEST: yes
|
||||
|
||||
# MinGW, 32-bit x86 (makefiles)
|
||||
- COMPILER: MINGW
|
||||
BUILDTOOL: MAKE
|
||||
PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
|
||||
CONFTOOL: MAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: no
|
||||
PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH%
|
||||
BUILD_GOOGLETEST: yes
|
||||
|
||||
# MinGW, 32-bit x86 (cmake static only)
|
||||
- COMPILER: MINGW
|
||||
CONFTOOL: CMAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: no
|
||||
TOOLSDIR: ./build/bin
|
||||
TESTDIR: ./build/bin
|
||||
PATH: C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin;%PATH%
|
||||
CMAKE_EXTRA_OPTIONS: -DCARES_SHARED=OFF -GNinja -DCARES_BUILD_TESTS=ON -DGTEST_ROOT=C:\projects\googletest
|
||||
BUILD_GOOGLETEST: yes
|
||||
|
||||
# MSVC 2022, UWP (cmake)
|
||||
- COMPILER: MSVC
|
||||
CONFTOOL: CMAKE
|
||||
SYSTEM: CONSOLE
|
||||
SKIP_TESTS: yes
|
||||
MSVC_SETUP_ARG: x64 store
|
||||
MSVC_SETUP_PATH: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
|
||||
CMAKE_EXTRA_OPTIONS: -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -A x64
|
||||
|
||||
install:
|
||||
- if "%COMPILER%" == "MINGW" rename "C:\Program Files\Git\usr\bin\sh.exe" "sh2.exe"
|
||||
@ -64,43 +142,48 @@ before_build:
|
||||
# Setup build environment for the selected compiler (not all compilers need to do anything here).
|
||||
# -- Visual Studio --
|
||||
- if "%COMPILER%" == "MSVC" call "%MSVC_SETUP_PATH%" %MSVC_SETUP_ARG%
|
||||
- if "%SYSTEM%" == "MSYS2" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
|
||||
- if "%SYSTEM%" == "MSYS2" if "%MSYSTEM%" == "MINGW64" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu autoconf autoconf-archive automake libtool make git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-gtest"
|
||||
- if "%SYSTEM%" == "MSYS2" if "%MSYSTEM%" == "CLANG64" C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syu autoconf autoconf-archive automake libtool make git mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-clang-analyzer mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-ninja mingw-w64-clang-x86_64-gtest"
|
||||
- if "%BUILD_GOOGLETEST%" == "yes" git clone --depth=1 https://github.com/google/googletest googletest
|
||||
- if "%BUILD_GOOGLETEST%" == "yes" cd googletest
|
||||
- if "%BUILD_GOOGLETEST%" == "yes" cmake -DCMAKE_INSTALL_PREFIX=C:\projects\googletest -DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL -GNinja -Bbuild
|
||||
- if "%BUILD_GOOGLETEST%" == "yes" cmake --build build --config Debug
|
||||
- if "%BUILD_GOOGLETEST%" == "yes" cmake --install build --config Debug
|
||||
- if "%BUILD_GOOGLETEST%" == "yes" cd ..
|
||||
|
||||
build_script:
|
||||
- if "%BUILDTOOL%" == "NMAKE" copy .\include\ares_build.h.dist .\include\ares_build.h
|
||||
- if "%BUILDTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc
|
||||
- if "%BUILDTOOL%" == "CMAKE" mkdir C:\projects\build-cares
|
||||
- if "%BUILDTOOL%" == "CMAKE" cd C:\projects\build-cares
|
||||
- if "%BUILDTOOL%" == "CMAKE" cmake -GNinja -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=C:\projects\build-cares\test_install -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -DCARES_BUILD_TESTS=ON %CMAKE_EXTRA_OPTIONS% %APPVEYOR_BUILD_FOLDER%
|
||||
- if "%BUILDTOOL%" == "CMAKE" ninja -v install
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" mkdir C:\projects\build-cares
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" cd C:\projects\build-cares
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" cmake -GNinja -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=C:\projects\build-cares\test_install -DCARES_SHARED=OFF -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -DCARES_BUILD_TESTS=ON %CMAKE_EXTRA_OPTIONS% %APPVEYOR_BUILD_FOLDER%
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" ninja -v install
|
||||
- if "%BUILDTOOL%" == "MAKE" copy .\include\ares_build.h.dist .\include\ares_build.h
|
||||
- if "%BUILDTOOL%" == "MAKE" mingw32-make.exe -f Makefile.m32 demos
|
||||
- if "%SYSTEM%" == "MSYS2" if "%CONFTOOL%" == "CMAKE" C:\msys64\usr\bin\bash -lc "%ANALYZE_PREFIX% cmake -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=C:/projects/build-cares/test_install -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON -DCARES_BUILD_TESTS=ON %CMAKE_EXTRA_OPTIONS% -Bbuild ."
|
||||
- if "%SYSTEM%" == "MSYS2" if "%CONFTOOL%" == "CMAKE" C:\msys64\usr\bin\bash -lc "%ANALYZE_PREFIX% cmake --build build"
|
||||
- if "%SYSTEM%" == "MSYS2" if "%CONFTOOL%" == "AUTOTOOLS" C:\msys64\usr\bin\bash -lc "./buildconf"
|
||||
- if "%SYSTEM%" == "MSYS2" if "%CONFTOOL%" == "AUTOTOOLS" C:\msys64\usr\bin\bash -lc "%ANALYZE_PREFIX% ./configure --enable-static --disable-shared --enable-tests"
|
||||
- if "%SYSTEM%" == "MSYS2" if "%CONFTOOL%" == "AUTOTOOLS" C:\msys64\usr\bin\bash -lc "%ANALYZE_PREFIX% make"
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" copy .\include\ares_build.h.dist .\include\ares_build.h
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" cmake -DCMAKE_BUILD_TYPE=%configuration% -DCMAKE_INSTALL_PREFIX=C:\projects\build-cares\test_install -DCARES_STATIC=ON -DCARES_STATIC_PIC=ON %CMAKE_EXTRA_OPTIONS% -Bbuild
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" cmake --build build --config Debug
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" cmake --install build --config Debug
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" copy .\include\ares_build.h.dist .\include\ares_build.h
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" mingw32-make.exe -f Makefile.m32 demos
|
||||
|
||||
test_script:
|
||||
# We can't use powershell for tests due to treating stderr as an error
|
||||
- if "%BUILDTOOL%" == "NMAKE" cd test
|
||||
- if "%BUILDTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc vtest
|
||||
- if "%BUILDTOOL%" == "NMAKE" nmake /NOLOGO /f .\Makefile.msvc aresfuzz aresfuzzname dnsdump
|
||||
- if "%BUILDTOOL%" == "NMAKE" .\msvc\arestest\lib-debug\dnsdump.exe fuzzinput\answer_a fuzzinput\answer_aaaa
|
||||
- if "%BUILDTOOL%" == "MAKE" cd test
|
||||
- if "%BUILDTOOL%" == "MAKE" mingw32-make.exe -f Makefile.m32
|
||||
- if "%BUILDTOOL%" == "MAKE" mingw32-make.exe -f Makefile.m32 aresfuzz.exe aresfuzzname.exe dnsdump.exe
|
||||
- if "%BUILDTOOL%" == "MAKE" .\dnsdump.exe fuzzinput\answer_a fuzzinput\answer_aaaa
|
||||
- if "%BUILDTOOL%" == "CMAKE" cd C:\projects\build-cares\bin
|
||||
- if "%BUILDTOOL%" == "CMAKE" .\adig.exe www.google.com
|
||||
- if "%BUILDTOOL%" == "CMAKE" .\acountry.exe www.google.com
|
||||
- if "%BUILDTOOL%" == "CMAKE" .\ahost.exe www.google.com
|
||||
- if "%BUILDTOOL%" == "CMAKE" .\arestest.exe -4 -v
|
||||
- if "%BUILDTOOL%" == "CMAKE" .\dnsdump.exe "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_a" "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_aaaa"
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" cd C:\projects\build-cares\bin
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" .\adig.exe www.google.com
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" .\acountry.exe www.google.com
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" .\ahost.exe www.google.com
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" .\arestest.exe -4 -v
|
||||
- if "%BUILDTOOL%" == "CMAKESTATIC" .\dnsdump.exe "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_a" "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_aaaa"
|
||||
- if "%SYSTEM%" == "MSYS2" if not "%SKIP_TESTS%" == "yes" C:\msys64\usr\bin\bash -lc "%TOOLSDIR%/adig.exe www.google.com"
|
||||
- if "%SYSTEM%" == "MSYS2" if not "%SKIP_TESTS%" == "yes" C:\msys64\usr\bin\bash -lc "%TOOLSDIR%/ahost.exe www.google.com"
|
||||
- if "%SYSTEM%" == "MSYS2" if not "%SKIP_TESTS%" == "yes" C:\msys64\usr\bin\bash -lc "%TESTDIR%/arestest.exe -4 -v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr*"
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" if not "%SKIP_TESTS%" == "yes" cd test
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" if not "%SKIP_TESTS%" == "yes" nmake GTEST_ROOT=C:\projects\googletest /NOLOGO /f .\Makefile.msvc vtest
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" if not "%SKIP_TESTS%" == "yes" nmake GTEST_ROOT=C:\projects\googletest /NOLOGO /f .\Makefile.msvc aresfuzz aresfuzzname dnsdump
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "NMAKE" if not "%SKIP_TESTS%" == "yes" .\msvc\arestest\lib-debug\dnsdump.exe fuzzinput\answer_a fuzzinput\answer_aaaa
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" cd test
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" mingw32-make.exe GTEST_ROOT=C:\projects\googletest -f Makefile.m32 vtest
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" mingw32-make.exe GTEST_ROOT=C:\projects\googletest -f Makefile.m32 aresfuzz.exe aresfuzzname.exe dnsdump.exe
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "MAKE" if not "%SKIP_TESTS%" == "yes" .\dnsdump.exe fuzzinput\answer_a fuzzinput\answer_aaaa
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" cd %TESTDIR%
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" .\adig.exe www.google.com
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" .\ahost.exe www.google.com
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" .\arestest.exe -4 -v --gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*:*LiveGetLocalhostByAddr*
|
||||
- if "%SYSTEM%" == "CONSOLE" if "%CONFTOOL%" == "CMAKE" if not "%SKIP_TESTS%" == "yes" .\dnsdump.exe "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_a" "%APPVEYOR_BUILD_FOLDER%\test\fuzzinput\answer_aaaa"
|
||||
|
||||
#on_finish:
|
||||
# - cd C:\projects\build-cares\test
|
||||
|
||||
2
src/third_party/cares/dist/buildconf
vendored
2
src/third_party/cares/dist/buildconf
vendored
@ -1,4 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
echo "*** Do not use buildconf. Instead, just use: autoreconf -fi" >&2
|
||||
exec ${AUTORECONF:-autoreconf} -fi "${@}"
|
||||
|
||||
3
src/third_party/cares/dist/buildconf.bat
vendored
3
src/third_party/cares/dist/buildconf.bat
vendored
@ -6,6 +6,9 @@ REM systems where there is no autotools support (i.e. Microsoft).
|
||||
REM
|
||||
REM This file is not included nor needed for c-ares' release
|
||||
REM archives, neither for c-ares' daily snapshot archives.
|
||||
REM
|
||||
REM Copyright (C) The c-ares project and its contributors
|
||||
REM SPDX-License-Identifier: MIT
|
||||
|
||||
if exist GIT-INFO goto start_doing
|
||||
ECHO ERROR: This file shall only be used with a c-ares git checkout.
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set_and_check(c-ares_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
|
||||
|
||||
16
src/third_party/cares/dist/ci/build.sh
vendored
16
src/third_party/cares/dist/ci/build.sh
vendored
@ -1,4 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
set -e
|
||||
|
||||
OS=""
|
||||
@ -13,7 +15,7 @@ if [ "$DIST" = "iOS" ] ; then
|
||||
SYSROOT="${XCODE_PATH}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/"
|
||||
fi
|
||||
|
||||
if [ "$BUILD_TYPE" != "cmake" -a "$BUILD_TYPE" != "valgrind" ]; then
|
||||
if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then
|
||||
autoreconf -fi
|
||||
mkdir atoolsbld
|
||||
cd atoolsbld
|
||||
@ -22,15 +24,15 @@ if [ "$BUILD_TYPE" != "cmake" -a "$BUILD_TYPE" != "valgrind" ]; then
|
||||
export CXXFLAGS="${CXXFLAGS} -isysroot ${SYSROOT}"
|
||||
export LDFLAGS="${LDFLAGS} -isysroot ${SYSROOT}"
|
||||
fi
|
||||
$SCAN_WRAP ../configure --disable-symbol-hiding --enable-expose-statics --enable-maintainer-mode --enable-debug $CONFIG_OPTS
|
||||
export CFLAGS="${CFLAGS} -O0 -g"
|
||||
export CXXFLAGS="${CXXFLAGS} -O0 -g"
|
||||
$SCAN_WRAP ../configure --disable-symbol-hiding --enable-maintainer-mode $CONFIG_OPTS
|
||||
$SCAN_WRAP make
|
||||
else
|
||||
# Use cmake for valgrind to prevent libtool script wrapping of tests that interfere with valgrind
|
||||
mkdir cmakebld
|
||||
cd cmakebld
|
||||
# Use cmake for everything else
|
||||
if [ "$DIST" = "iOS" ] ; then
|
||||
CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_OSX_SYSROOT=${SYSROOT}"
|
||||
fi
|
||||
cmake ${CMAKE_FLAGS} ..
|
||||
make
|
||||
$SCAN_WRAP cmake ${CMAKE_FLAGS} ${CMAKE_TEST_FLAGS} -Bcmakebld .
|
||||
$SCAN_WRAP cmake --build cmakebld
|
||||
fi
|
||||
|
||||
2
src/third_party/cares/dist/ci/covupload.sh
vendored
2
src/third_party/cares/dist/ci/covupload.sh
vendored
@ -1,4 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
set -e
|
||||
if [ "$BUILD_TYPE" = "coverage" ]; then
|
||||
echo "CI_NAME=${CI_NAME}"
|
||||
|
||||
2
src/third_party/cares/dist/ci/distcheck.sh
vendored
2
src/third_party/cares/dist/ci/distcheck.sh
vendored
@ -1,4 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
set -e
|
||||
|
||||
OS=""
|
||||
|
||||
17
src/third_party/cares/dist/ci/test.sh
vendored
17
src/third_party/cares/dist/ci/test.sh
vendored
@ -1,9 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
set -e
|
||||
|
||||
# Travis on MacOS uses CloudFlare's DNS (1.1.1.1/1.0.0.1) which rejects ANY requests
|
||||
# Travis on MacOS uses CloudFlare's DNS (1.1.1.1/1.0.0.1) which rejects ANY requests.
|
||||
# Also, LiveSearchTXT is known to fail on Cirrus-CI on some MacOS hosts, we don't get
|
||||
# a truncated UDP response so we never follow up with TCP.
|
||||
# Note res_ninit() and /etc/resolv.conf actually have different configs, bad Travis
|
||||
[ -z "$TEST_FILTER" ] && export TEST_FILTER="--gtest_filter=-*LiveSearchANY*"
|
||||
[ -z "$TEST_FILTER" ] && export TEST_FILTER="--gtest_filter=-*LiveSearchTXT*:*LiveSearchANY*"
|
||||
|
||||
# No tests for ios as it is a cross-compile
|
||||
if [ "$BUILD_TYPE" = "ios" -o "$BUILD_TYPE" = "ios-cmake" -o "$DIST" = "iOS" ] ; then
|
||||
@ -18,16 +22,15 @@ fi
|
||||
PWD=`pwd`
|
||||
TESTDIR="${PWD}/test"
|
||||
|
||||
if [ "$BUILD_TYPE" = "cmake" -o "$BUILD_TYPE" = "valgrind" ] ; then
|
||||
TOOLSBIN="${PWD}/cmakebld/bin"
|
||||
TESTSBIN="${PWD}/cmakebld/bin"
|
||||
else
|
||||
if [ "$BUILD_TYPE" = "autotools" -o "$BUILD_TYPE" = "coverage" ]; then
|
||||
TOOLSBIN="${PWD}/atoolsbld/src/tools"
|
||||
TESTSBIN="${PWD}/atoolsbld/test"
|
||||
else
|
||||
TOOLSBIN="${PWD}/cmakebld/bin"
|
||||
TESTSBIN="${PWD}/cmakebld/bin"
|
||||
fi
|
||||
|
||||
$TEST_WRAP "${TOOLSBIN}/adig" www.google.com
|
||||
$TEST_WRAP "${TOOLSBIN}/acountry" www.google.com
|
||||
$TEST_WRAP "${TOOLSBIN}/ahost" www.google.com
|
||||
cd "${TESTSBIN}"
|
||||
$TEST_WRAP ./arestest -4 -v $TEST_FILTER
|
||||
|
||||
399
src/third_party/cares/dist/cmake/EnableWarnings.cmake
vendored
Normal file
399
src/third_party/cares/dist/cmake/EnableWarnings.cmake
vendored
Normal file
@ -0,0 +1,399 @@
|
||||
# Copyright (c) Monetra Technologies LLC
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# EnableWarnings.cmake
|
||||
#
|
||||
# Checks for and turns on a large number of warning C flags.
|
||||
#
|
||||
# Adds the following helper functions:
|
||||
#
|
||||
# remove_warnings(... list of warnings ...)
|
||||
# Turn off given list of individual warnings for all targets and subdirectories added after this.
|
||||
#
|
||||
# remove_all_warnings()
|
||||
# Remove all warning flags, add -w to suppress built-in warnings.
|
||||
#
|
||||
# remove_all_warnings_from_targets(... list of targets ...)
|
||||
# Suppress warnings for the given targets only.
|
||||
#
|
||||
# push_warnings()
|
||||
# Save current warning flags by pushing them onto an internal stack. Note that modifications to the internal
|
||||
# stack are only visible in the current CMakeLists.txt file and its children.
|
||||
#
|
||||
# Note: changing warning flags multiple times in the same directory only affects add_subdirectory() calls.
|
||||
# Targets in the directory will always use the warning flags in effect at the end of the CMakeLists.txt
|
||||
# file - this is due to really weird and annoying legacy behavior of CMAKE_C_FLAGS.
|
||||
#
|
||||
# pop_warnings()
|
||||
# Restore the last set of flags that were saved with push_warnings(). Note that modifications to the internal
|
||||
# stack are only visible in the current CMakeLists.txt file and its children.
|
||||
#
|
||||
|
||||
if (_internal_enable_warnings_already_run)
|
||||
return()
|
||||
endif ()
|
||||
set(_internal_enable_warnings_already_run TRUE)
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
|
||||
# internal helper: _int_enable_warnings_set_flags_ex(langs_var configs_var [warnings flags])
|
||||
function(_int_enable_warnings_set_flags_ex langs_var configs_var)
|
||||
if (NOT ARGN)
|
||||
return()
|
||||
endif ()
|
||||
|
||||
if (NOT ${configs_var})
|
||||
set(${configs_var} "NONE")
|
||||
endif ()
|
||||
string(TOUPPER "${${configs_var}}" ${configs_var})
|
||||
|
||||
foreach(_flag ${ARGN})
|
||||
string(MAKE_C_IDENTIFIER "HAVE_${_flag}" varname)
|
||||
|
||||
if ("C" IN_LIST ${langs_var})
|
||||
check_c_compiler_flag(${_flag} ${varname})
|
||||
if (${varname})
|
||||
foreach (config IN LISTS ${configs_var})
|
||||
if (config STREQUAL "NONE")
|
||||
set(config)
|
||||
else ()
|
||||
set(config "_${config}")
|
||||
endif ()
|
||||
string(APPEND CMAKE_C_FLAGS${config} " ${_flag}")
|
||||
endforeach ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if ("CXX" IN_LIST ${langs_var})
|
||||
string(APPEND varname "_CXX")
|
||||
check_cxx_compiler_flag(${_flag} ${varname})
|
||||
if (${varname})
|
||||
foreach (config IN LISTS ${configs_var})
|
||||
if (config STREQUAL "NONE")
|
||||
set(config)
|
||||
else ()
|
||||
set(config "_${config}")
|
||||
endif ()
|
||||
string(APPEND CMAKE_CXX_FLAGS${config} " ${_flag}")
|
||||
endforeach ()
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
foreach(lang C CXX)
|
||||
foreach (config IN LISTS ${configs_var})
|
||||
string(TOUPPER "${config}" config)
|
||||
if (config STREQUAL "NONE")
|
||||
set(config)
|
||||
else ()
|
||||
set(config "_${config}")
|
||||
endif ()
|
||||
string(STRIP "${CMAKE_${lang}_FLAGS${config}}" CMAKE_${lang}_FLAGS${config})
|
||||
set(CMAKE_${lang}_FLAGS${config} "${CMAKE_${lang}_FLAGS${config}}" PARENT_SCOPE)
|
||||
endforeach ()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# internal helper: _int_enable_warnings_set_flags(langs_var [warnings flags])
|
||||
macro(_int_enable_warnings_set_flags langs_var)
|
||||
set(configs "NONE")
|
||||
_int_enable_warnings_set_flags_ex(${langs_var} configs ${ARGN})
|
||||
endmacro()
|
||||
|
||||
set(_flags_C)
|
||||
set(_flags_CXX)
|
||||
set(_debug_flags_C)
|
||||
set(_debug_flags_CXX)
|
||||
|
||||
if (MSVC)
|
||||
# Visual Studio uses a completely different nomenclature for warnings than gcc/mingw/clang, so none of the
|
||||
# "-W[name]" warnings will work.
|
||||
|
||||
# W4 would be better but it produces unnecessary warnings like:
|
||||
# * warning C4706: assignment within conditional expression
|
||||
# Triggered when doing "while(1)"
|
||||
# * warning C4115: 'timeval' : named type definition in parentheses
|
||||
# * warning C4201: nonstandard extension used : nameless struct/union
|
||||
# Triggered by system includes (commctrl.h, shtypes.h, Shlobj.h)
|
||||
set(_flags
|
||||
/W3
|
||||
/we4013 # Treat "function undefined, assuming extern returning int" warning as an error. https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4013
|
||||
)
|
||||
|
||||
list(APPEND _flags_C ${_flags})
|
||||
list(APPEND _flags_CXX ${_flags})
|
||||
|
||||
elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
|
||||
# Intel's compiler warning flags are more like Visual Studio than GCC, though the numbers aren't the same.
|
||||
set(_flags
|
||||
# Use warning level 3, quite wordy.
|
||||
-w3
|
||||
# Disable warnings we don't care about (add more as they are encountered).
|
||||
-wd383 # Spammy warning about initializing from a temporary object in C++ (which is done all the time ...).
|
||||
-wd11074 # Diagnostic related to inlining.
|
||||
-wd11076 # Diagnostic related to inlining.
|
||||
)
|
||||
|
||||
list(APPEND _flags_C ${_flags})
|
||||
list(APPEND _flags_CXX ${_flags})
|
||||
|
||||
elseif (CMAKE_C_COMPILER_ID MATCHES "XL")
|
||||
set (_flags
|
||||
-qwarn64
|
||||
-qformat=all
|
||||
-qflag=i:i
|
||||
)
|
||||
list(APPEND _flags_C ${_flags})
|
||||
list(APPEND _flags_CXX ${_flags})
|
||||
|
||||
else ()
|
||||
# If we're compiling with GCC / Clang / MinGW (or anything else besides Visual Studio or Intel):
|
||||
# C Flags:
|
||||
list(APPEND _flags_C
|
||||
-Wall
|
||||
-Wextra
|
||||
|
||||
# Enable additional warnings not covered by Wall and Wextra.
|
||||
-Wcast-align
|
||||
-Wconversion
|
||||
-Wdeclaration-after-statement
|
||||
-Wdouble-promotion
|
||||
-Wfloat-equal
|
||||
-Wformat-security
|
||||
-Winit-self
|
||||
-Wjump-misses-init
|
||||
-Wlogical-op
|
||||
-Wmissing-braces
|
||||
-Wmissing-declarations
|
||||
-Wmissing-format-attribute
|
||||
-Wmissing-include-dirs
|
||||
-Wmissing-prototypes
|
||||
-Wnested-externs
|
||||
-Wno-coverage-mismatch
|
||||
-Wold-style-definition
|
||||
-Wpacked
|
||||
-Wpointer-arith
|
||||
-Wredundant-decls
|
||||
-Wshadow
|
||||
-Wsign-conversion
|
||||
-Wstrict-overflow
|
||||
-Wstrict-prototypes
|
||||
-Wtrampolines
|
||||
-Wundef
|
||||
-Wunused
|
||||
-Wvariadic-macros
|
||||
-Wvla
|
||||
-Wwrite-strings
|
||||
|
||||
# On Windows MinGW I think implicit fallthrough enabled by -Wextra must not default to 3
|
||||
-Wimplicit-fallthrough=3
|
||||
|
||||
# Treat implicit variable typing and implicit function declarations as errors.
|
||||
-Werror=implicit-int
|
||||
-Werror=implicit-function-declaration
|
||||
|
||||
# Make MacOSX honor -mmacosx-version-min
|
||||
-Werror=partial-availability
|
||||
|
||||
# Some clang versions might warn if an argument like "-I/path/to/headers" is unused,
|
||||
# silence these.
|
||||
-Qunused-arguments
|
||||
)
|
||||
|
||||
# C++ flags:
|
||||
list(APPEND _flags_CXX
|
||||
-Wall
|
||||
-Wextra
|
||||
|
||||
# Enable additional warnings not covered by Wall and Wextra.
|
||||
-Wcast-align
|
||||
-Wformat-security
|
||||
-Wmissing-declarations
|
||||
-Wmissing-format-attribute
|
||||
-Wpacked-bitfield-compat
|
||||
-Wredundant-decls
|
||||
-Wvla
|
||||
|
||||
# Turn off unused parameter warnings with C++ (they happen often in C++ and Qt).
|
||||
-Wno-unused-parameter
|
||||
|
||||
# Some clang versions might warn if an argument like "-I/path/to/headers" is unused,
|
||||
# silence these.
|
||||
-Qunused-arguments
|
||||
)
|
||||
|
||||
# Note: when cross-compiling to Windows from Cygwin, the Qt Mingw packages have a bunch of
|
||||
# noisy type-conversion warnings in headers. So, only enable those warnings if we're
|
||||
# not building that configuration.
|
||||
if (NOT (WIN32 AND (CMAKE_HOST_SYSTEM_NAME MATCHES "CYGWIN")))
|
||||
list(APPEND _flags_CXX
|
||||
-Wconversion
|
||||
-Wfloat-equal
|
||||
-Wsign-conversion
|
||||
)
|
||||
endif ()
|
||||
|
||||
# Add flags to force colored output even when output is redirected via pipe.
|
||||
if (CMAKE_GENERATOR MATCHES "Ninja")
|
||||
set(color_default TRUE)
|
||||
else ()
|
||||
set(color_default FALSE)
|
||||
endif ()
|
||||
option(FORCE_COLOR "Force compiler to always colorize, even when output is redirected." ${color_default})
|
||||
mark_as_advanced(FORCE FORCE_COLOR)
|
||||
if (FORCE_COLOR)
|
||||
set(_flags
|
||||
-fdiagnostics-color=always # GCC
|
||||
-fcolor-diagnostics # Clang
|
||||
)
|
||||
list(APPEND _flags_C ${_flags})
|
||||
list(APPEND _flags_CXX ${_flags})
|
||||
endif ()
|
||||
|
||||
# Add -fno-omit-frame-pointer (and optionally -fno-inline) to make debugging and stack dumps nicer.
|
||||
set(_flags
|
||||
-fno-omit-frame-pointer
|
||||
)
|
||||
option(M_NO_INLINE "Disable function inlining for RelWithDebInfo and Debug configurations?" FALSE)
|
||||
if (M_NO_INLINE)
|
||||
list(APPEND _flags
|
||||
-fno-inline
|
||||
)
|
||||
endif ()
|
||||
list(APPEND _debug_flags_C ${_flags})
|
||||
list(APPEND _debug_flags_CXX ${_flags})
|
||||
endif ()
|
||||
|
||||
# Check and set compiler flags.
|
||||
set(_debug_configs
|
||||
RelWithDebInfo
|
||||
Debug
|
||||
)
|
||||
foreach(_lang ${languages})
|
||||
_int_enable_warnings_set_flags(_lang ${_flags_${_lang}})
|
||||
_int_enable_warnings_set_flags_ex(_lang _debug_configs ${_debug_flags_${_lang}})
|
||||
|
||||
# Ensure pure Debug builds are NOT optimized (not possible on Visual Studio).
|
||||
# Any optimization of a Debug build will prevent debuggers like lldb from
|
||||
# fully displaying backtraces and stepping.
|
||||
if (NOT MSVC)
|
||||
set(_config Debug)
|
||||
_int_enable_warnings_set_flags_ex(_lang _config -O0)
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Helper functions
|
||||
|
||||
|
||||
# This function can be called in subdirectories, to prune out warnings that they don't want.
|
||||
# vararg: warning flags to remove from list of enabled warnings. All "no" flags after EXPLICIT_DISABLE
|
||||
# will be added to C flags.
|
||||
#
|
||||
# Ex.: remove_warnings(-Wall -Wdouble-promotion -Wcomment) prunes those warnings flags from the compile command.
|
||||
function(remove_warnings)
|
||||
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
set(langs C)
|
||||
if ("CXX" IN_LIST languages)
|
||||
list(APPEND langs CXX)
|
||||
endif ()
|
||||
|
||||
foreach(lang ${langs})
|
||||
set(toadd)
|
||||
set(in_explicit_disable FALSE)
|
||||
foreach (flag ${ARGN})
|
||||
if (flag STREQUAL "EXPLICIT_DISABLE")
|
||||
set(in_explicit_disable TRUE)
|
||||
elseif (in_explicit_disable)
|
||||
list(APPEND toadd "${flag}")
|
||||
else ()
|
||||
string(REGEX REPLACE "${flag}([ \t]+|$)" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}")
|
||||
endif ()
|
||||
endforeach ()
|
||||
_int_enable_warnings_set_flags(lang ${toadd})
|
||||
string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS)
|
||||
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
# Explicitly suppress all warnings. As long as this flag is the last warning flag, warnings will be
|
||||
# suppressed even if earlier flags enabled warnings.
|
||||
function(remove_all_warnings)
|
||||
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
set(langs C)
|
||||
if ("CXX" IN_LIST languages)
|
||||
list(APPEND langs CXX)
|
||||
endif ()
|
||||
|
||||
foreach(lang ${langs})
|
||||
string(REGEX REPLACE "[-/][Ww][^ \t]*([ \t]+|$)" "" CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}")
|
||||
if (MSVC)
|
||||
string(APPEND CMAKE_${lang}_FLAGS " /w")
|
||||
else ()
|
||||
string(APPEND CMAKE_${lang}_FLAGS " -w")
|
||||
endif ()
|
||||
string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS)
|
||||
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
function(remove_all_warnings_from_targets)
|
||||
foreach (target ${ARGN})
|
||||
if (MSVC)
|
||||
target_compile_options(${target} PRIVATE "/w")
|
||||
else ()
|
||||
target_compile_options(${target} PRIVATE "-w")
|
||||
endif ()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
# Save the current warning settings to an internal variable.
|
||||
function(push_warnings)
|
||||
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
set(langs C)
|
||||
if ("CXX" IN_LIST languages)
|
||||
list(APPEND langs CXX)
|
||||
endif ()
|
||||
|
||||
foreach(lang ${langs})
|
||||
if (CMAKE_${lang}_FLAGS MATCHES ";")
|
||||
message(AUTHOR_WARNING "Cannot push warnings for ${lang}, CMAKE_${lang}_FLAGS contains semicolons")
|
||||
continue()
|
||||
endif ()
|
||||
# Add current flags to end of internal list.
|
||||
list(APPEND _enable_warnings_internal_${lang}_flags_stack "${CMAKE_${lang}_FLAGS}")
|
||||
# Propagate results up to caller's scope.
|
||||
set(_enable_warnings_internal_${lang}_flags_stack "${_enable_warnings_internal_${lang}_flags_stack}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
# Restore the current warning settings from an internal variable.
|
||||
function(pop_warnings)
|
||||
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
set(langs C)
|
||||
if ("CXX" IN_LIST languages)
|
||||
list(APPEND langs CXX)
|
||||
endif ()
|
||||
|
||||
foreach(lang ${langs})
|
||||
if (NOT _enable_warnings_internal_${lang}_flags_stack)
|
||||
continue()
|
||||
endif ()
|
||||
# Pop flags off of end of list, overwrite current flags with whatever we popped off.
|
||||
list(GET _enable_warnings_internal_${lang}_flags_stack -1 CMAKE_${lang}_FLAGS)
|
||||
list(REMOVE_AT _enable_warnings_internal_${lang}_flags_stack -1)
|
||||
# Propagate results up to caller's scope.
|
||||
set(_enable_warnings_internal_${lang}_flags_stack "${_enable_warnings_internal_${lang}_flags_stack}" PARENT_SCOPE)
|
||||
string(STRIP "${CMAKE_${lang}_FLAGS}" CMAKE_${lang}_FLAGS)
|
||||
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endfunction()
|
||||
1801
src/third_party/cares/dist/config.sub
vendored
1801
src/third_party/cares/dist/config.sub
vendored
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
||||
#! /bin/sh
|
||||
# Wrapper for compilers which do not understand '-c -o'.
|
||||
|
||||
scriptversion=2012-10-14.11; # UTC
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 1999-2014 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
# Written by Tom Tromey <tromey@cygnus.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -17,7 +17,7 @@ scriptversion=2012-10-14.11; # UTC
|
||||
# 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/>.
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
@ -53,7 +53,7 @@ func_file_conv ()
|
||||
MINGW*)
|
||||
file_conv=mingw
|
||||
;;
|
||||
CYGWIN*)
|
||||
CYGWIN* | MSYS*)
|
||||
file_conv=cygwin
|
||||
;;
|
||||
*)
|
||||
@ -67,7 +67,7 @@ func_file_conv ()
|
||||
mingw/*)
|
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||
;;
|
||||
cygwin/*)
|
||||
cygwin/* | msys/*)
|
||||
file=`cygpath -m "$file" || echo "$file"`
|
||||
;;
|
||||
wine/*)
|
||||
@ -255,7 +255,8 @@ EOF
|
||||
echo "compile $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
|
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
|
||||
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
|
||||
func_cl_wrapper "$@" # Doesn't return...
|
||||
;;
|
||||
esac
|
||||
@ -339,9 +340,9 @@ exit $ret
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
File diff suppressed because it is too large
Load Diff
1890
src/third_party/cares/dist/config/config.sub
vendored
Executable file
1890
src/third_party/cares/dist/config/config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
||||
#! /bin/sh
|
||||
# depcomp - compile a program generating dependencies as side-effects
|
||||
|
||||
scriptversion=2016-01-11.22; # UTC
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 1999-2017 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
|
||||
# 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
|
||||
@ -16,7 +16,7 @@ scriptversion=2016-01-11.22; # UTC
|
||||
# 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/>.
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
@ -783,7 +783,7 @@ exit 0
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# install - install a program, script, or datafile
|
||||
|
||||
scriptversion=2014-09-12.12; # UTC
|
||||
scriptversion=2020-11-14.01; # UTC
|
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
@ -69,6 +69,11 @@ posix_mkdir=
|
||||
# Desired mode of installed file.
|
||||
mode=0755
|
||||
|
||||
# Create dirs (including intermediate dirs) using mode 755.
|
||||
# This is like GNU 'install' as of coreutils 8.32 (2020).
|
||||
mkdir_umask=22
|
||||
|
||||
backupsuffix=
|
||||
chgrpcmd=
|
||||
chmodcmd=$chmodprog
|
||||
chowncmd=
|
||||
@ -99,18 +104,28 @@ Options:
|
||||
--version display version info and exit.
|
||||
|
||||
-c (ignored)
|
||||
-C install only if different (preserve the last data modification time)
|
||||
-C install only if different (preserve data modification time)
|
||||
-d create directories instead of installing files.
|
||||
-g GROUP $chgrpprog installed files to GROUP.
|
||||
-m MODE $chmodprog installed files to MODE.
|
||||
-o USER $chownprog installed files to USER.
|
||||
-p pass -p to $cpprog.
|
||||
-s $stripprog installed files.
|
||||
-S SUFFIX attempt to back up existing files, with suffix SUFFIX.
|
||||
-t DIRECTORY install into DIRECTORY.
|
||||
-T report an error if DSTFILE is a directory.
|
||||
|
||||
Environment variables override the default commands:
|
||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||
RMPROG STRIPPROG
|
||||
|
||||
By default, rm is invoked with -f; when overridden with RMPROG,
|
||||
it's up to you to specify -f if you want it.
|
||||
|
||||
If -S is not specified, no backups are attempted.
|
||||
|
||||
Email bug reports to bug-automake@gnu.org.
|
||||
Automake home page: https://www.gnu.org/software/automake/
|
||||
"
|
||||
|
||||
while test $# -ne 0; do
|
||||
@ -137,8 +152,13 @@ while test $# -ne 0; do
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift;;
|
||||
|
||||
-p) cpprog="$cpprog -p";;
|
||||
|
||||
-s) stripcmd=$stripprog;;
|
||||
|
||||
-S) backupsuffix="$2"
|
||||
shift;;
|
||||
|
||||
-t)
|
||||
is_target_a_directory=always
|
||||
dst_arg=$2
|
||||
@ -255,6 +275,10 @@ do
|
||||
dstdir=$dst
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
# Don't chown directories that already exist.
|
||||
if test $dstdir_status = 0; then
|
||||
chowncmd=""
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||
@ -271,15 +295,18 @@ do
|
||||
fi
|
||||
dst=$dst_arg
|
||||
|
||||
# If destination is a directory, append the input filename; won't work
|
||||
# if double slashes aren't ignored.
|
||||
# If destination is a directory, append the input filename.
|
||||
if test -d "$dst"; then
|
||||
if test "$is_target_a_directory" = never; then
|
||||
echo "$0: $dst_arg: Is a directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
dstdir=$dst
|
||||
dst=$dstdir/`basename "$src"`
|
||||
dstbase=`basename "$src"`
|
||||
case $dst in
|
||||
*/) dst=$dst$dstbase;;
|
||||
*) dst=$dst/$dstbase;;
|
||||
esac
|
||||
dstdir_status=0
|
||||
else
|
||||
dstdir=`dirname "$dst"`
|
||||
@ -288,27 +315,16 @@ do
|
||||
fi
|
||||
fi
|
||||
|
||||
case $dstdir in
|
||||
*/) dstdirslash=$dstdir;;
|
||||
*) dstdirslash=$dstdir/;;
|
||||
esac
|
||||
|
||||
obsolete_mkdir_used=false
|
||||
|
||||
if test $dstdir_status != 0; then
|
||||
case $posix_mkdir in
|
||||
'')
|
||||
# Create intermediate dirs using mode 755 as modified by the umask.
|
||||
# This is like FreeBSD 'install' as of 1997-10-28.
|
||||
umask=`umask`
|
||||
case $stripcmd.$umask in
|
||||
# Optimize common cases.
|
||||
*[2367][2367]) mkdir_umask=$umask;;
|
||||
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
mkdir_umask=`expr $umask + 22 \
|
||||
- $umask % 100 % 40 + $umask % 20 \
|
||||
- $umask % 10 % 4 + $umask % 2
|
||||
`;;
|
||||
*) mkdir_umask=$umask,go-w;;
|
||||
esac
|
||||
|
||||
# With -d, create the new directory with the user-specified mode.
|
||||
# Otherwise, rely on $mkdir_umask.
|
||||
if test -n "$dir_arg"; then
|
||||
@ -318,50 +334,49 @@ do
|
||||
fi
|
||||
|
||||
posix_mkdir=false
|
||||
case $umask in
|
||||
*[123567][0-7][0-7])
|
||||
# POSIX mkdir -p sets u+wx bits regardless of umask, which
|
||||
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
|
||||
;;
|
||||
*)
|
||||
# $RANDOM is not portable (e.g. dash); use it when possible to
|
||||
# lower collision chance
|
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||
trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
|
||||
# The $RANDOM variable is not portable (e.g., dash). Use it
|
||||
# here however when possible just to lower collision chance.
|
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||
|
||||
# As "mkdir -p" follows symlinks and we work in /tmp possibly; so
|
||||
# create the $tmpdir first (and fail if unsuccessful) to make sure
|
||||
# that nobody tries to guess the $tmpdir name.
|
||||
if (umask $mkdir_umask &&
|
||||
$mkdirprog $mkdir_mode "$tmpdir" &&
|
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
|
||||
then
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
test_tmpdir="$tmpdir/a"
|
||||
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
d????-?r-*) different_mode=700;;
|
||||
d????-?--*) different_mode=755;;
|
||||
*) false;;
|
||||
esac &&
|
||||
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
|
||||
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
|
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||
}
|
||||
}
|
||||
then posix_mkdir=:
|
||||
fi
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
|
||||
else
|
||||
# Remove any dirs left behind by ancient mkdir implementations.
|
||||
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
|
||||
fi
|
||||
trap '' 0;;
|
||||
esac;;
|
||||
trap '
|
||||
ret=$?
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
|
||||
exit $ret
|
||||
' 0
|
||||
|
||||
# Because "mkdir -p" follows existing symlinks and we likely work
|
||||
# directly in world-writeable /tmp, make sure that the '$tmpdir'
|
||||
# directory is successfully created first before we actually test
|
||||
# 'mkdir -p'.
|
||||
if (umask $mkdir_umask &&
|
||||
$mkdirprog $mkdir_mode "$tmpdir" &&
|
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
|
||||
then
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
test_tmpdir="$tmpdir/a"
|
||||
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
d????-?r-*) different_mode=700;;
|
||||
d????-?--*) different_mode=755;;
|
||||
*) false;;
|
||||
esac &&
|
||||
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
|
||||
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
|
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||
}
|
||||
}
|
||||
then posix_mkdir=:
|
||||
fi
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
|
||||
else
|
||||
# Remove any dirs left behind by ancient mkdir implementations.
|
||||
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
|
||||
fi
|
||||
trap '' 0;;
|
||||
esac
|
||||
|
||||
if
|
||||
@ -372,7 +387,7 @@ do
|
||||
then :
|
||||
else
|
||||
|
||||
# The umask is ridiculous, or mkdir does not conform to POSIX,
|
||||
# mkdir does not conform to POSIX,
|
||||
# or it failed possibly due to a race condition. Create the
|
||||
# directory the slow way, step by step, checking for races as we go.
|
||||
|
||||
@ -401,7 +416,7 @@ do
|
||||
prefixes=
|
||||
else
|
||||
if $posix_mkdir; then
|
||||
(umask=$mkdir_umask &&
|
||||
(umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||
# Don't fail if two instances are running concurrently.
|
||||
test -d "$prefix" || exit 1
|
||||
@ -434,14 +449,25 @@ do
|
||||
else
|
||||
|
||||
# Make a couple of temp file names in the proper directory.
|
||||
dsttmp=$dstdir/_inst.$$_
|
||||
rmtmp=$dstdir/_rm.$$_
|
||||
dsttmp=${dstdirslash}_inst.$$_
|
||||
rmtmp=${dstdirslash}_rm.$$_
|
||||
|
||||
# Trap to clean up those temp files at exit.
|
||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||
|
||||
# Copy the file name to the temp name.
|
||||
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
|
||||
(umask $cp_umask &&
|
||||
{ test -z "$stripcmd" || {
|
||||
# Create $dsttmp read-write so that cp doesn't create it read-only,
|
||||
# which would cause strip to fail.
|
||||
if test -z "$doit"; then
|
||||
: >"$dsttmp" # No need to fork-exec 'touch'.
|
||||
else
|
||||
$doit touch "$dsttmp"
|
||||
fi
|
||||
}
|
||||
} &&
|
||||
$doit_exec $cpprog "$src" "$dsttmp") &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits.
|
||||
#
|
||||
@ -467,6 +493,13 @@ do
|
||||
then
|
||||
rm -f "$dsttmp"
|
||||
else
|
||||
# If $backupsuffix is set, and the file being installed
|
||||
# already exists, attempt a backup. Don't worry if it fails,
|
||||
# e.g., if mv doesn't support -f.
|
||||
if test -n "$backupsuffix" && test -f "$dst"; then
|
||||
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
|
||||
fi
|
||||
|
||||
# Rename the file to the real destination.
|
||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||
|
||||
@ -481,9 +514,9 @@ do
|
||||
# file should still install successfully.
|
||||
{
|
||||
test ! -f "$dst" ||
|
||||
$doit $rmcmd -f "$dst" 2>/dev/null ||
|
||||
$doit $rmcmd "$dst" 2>/dev/null ||
|
||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
|
||||
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
|
||||
} ||
|
||||
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||
(exit 1); exit 1
|
||||
@ -500,9 +533,9 @@ do
|
||||
done
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
217
src/third_party/cares/dist/ltmain.sh → src/third_party/cares/dist/config/ltmain.sh
vendored
Normal file → Executable file
217
src/third_party/cares/dist/ltmain.sh → src/third_party/cares/dist/config/ltmain.sh
vendored
Normal file → Executable file
@ -31,7 +31,7 @@
|
||||
|
||||
PROGRAM=libtool
|
||||
PACKAGE=libtool
|
||||
VERSION="2.4.6 Debian-2.4.6-2"
|
||||
VERSION="2.4.6 Debian-2.4.6-15build2"
|
||||
package_revision=2.4.6
|
||||
|
||||
|
||||
@ -387,7 +387,7 @@ EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake.
|
||||
# putting '$debug_cmd' at the start of all your functions, you can get
|
||||
# bash to show function call trace with:
|
||||
#
|
||||
# debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
|
||||
# debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
|
||||
debug_cmd=${debug_cmd-":"}
|
||||
exit_cmd=:
|
||||
|
||||
@ -1370,7 +1370,7 @@ func_lt_ver ()
|
||||
#! /bin/sh
|
||||
|
||||
# Set a version string for this script.
|
||||
scriptversion=2014-01-07.03; # UTC
|
||||
scriptversion=2015-10-07.11; # UTC
|
||||
|
||||
# A portable, pluggable option parser for Bourne shell.
|
||||
# Written by Gary V. Vaughan, 2010
|
||||
@ -1530,6 +1530,8 @@ func_run_hooks ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_run_hooks=false
|
||||
|
||||
case " $hookable_fns " in
|
||||
*" $1 "*) ;;
|
||||
*) func_fatal_error "'$1' does not support hook funcions.n" ;;
|
||||
@ -1538,16 +1540,16 @@ func_run_hooks ()
|
||||
eval _G_hook_fns=\$$1_hooks; shift
|
||||
|
||||
for _G_hook in $_G_hook_fns; do
|
||||
eval $_G_hook '"$@"'
|
||||
|
||||
# store returned options list back into positional
|
||||
# parameters for next 'cmd' execution.
|
||||
eval _G_hook_result=\$${_G_hook}_result
|
||||
eval set dummy "$_G_hook_result"; shift
|
||||
if eval $_G_hook '"$@"'; then
|
||||
# store returned options list back into positional
|
||||
# parameters for next 'cmd' execution.
|
||||
eval _G_hook_result=\$${_G_hook}_result
|
||||
eval set dummy "$_G_hook_result"; shift
|
||||
_G_rc_run_hooks=:
|
||||
fi
|
||||
done
|
||||
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_run_hooks_result=$func_quote_for_eval_result
|
||||
$_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result
|
||||
}
|
||||
|
||||
|
||||
@ -1557,10 +1559,16 @@ func_run_hooks ()
|
||||
## --------------- ##
|
||||
|
||||
# In order to add your own option parsing hooks, you must accept the
|
||||
# full positional parameter list in your hook function, remove any
|
||||
# options that you action, and then pass back the remaining unprocessed
|
||||
# full positional parameter list in your hook function, you may remove/edit
|
||||
# any options that you action, and then pass back the remaining unprocessed
|
||||
# options in '<hooked_function_name>_result', escaped suitably for
|
||||
# 'eval'. Like this:
|
||||
# 'eval'. In this case you also must return $EXIT_SUCCESS to let the
|
||||
# hook's caller know that it should pay attention to
|
||||
# '<hooked_function_name>_result'. Returning $EXIT_FAILURE signalizes that
|
||||
# arguments are left untouched by the hook and therefore caller will ignore the
|
||||
# result variable.
|
||||
#
|
||||
# Like this:
|
||||
#
|
||||
# my_options_prep ()
|
||||
# {
|
||||
@ -1570,9 +1578,11 @@ func_run_hooks ()
|
||||
# usage_message=$usage_message'
|
||||
# -s, --silent don'\''t print informational messages
|
||||
# '
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_options_prep_result=$func_quote_for_eval_result
|
||||
# # No change in '$@' (ignored completely by this hook). There is
|
||||
# # no need to do the equivalent (but slower) action:
|
||||
# # func_quote_for_eval ${1+"$@"}
|
||||
# # my_options_prep_result=$func_quote_for_eval_result
|
||||
# false
|
||||
# }
|
||||
# func_add_hook func_options_prep my_options_prep
|
||||
#
|
||||
@ -1581,25 +1591,37 @@ func_run_hooks ()
|
||||
# {
|
||||
# $debug_cmd
|
||||
#
|
||||
# args_changed=false
|
||||
#
|
||||
# # Note that for efficiency, we parse as many options as we can
|
||||
# # recognise in a loop before passing the remainder back to the
|
||||
# # caller on the first unrecognised argument we encounter.
|
||||
# while test $# -gt 0; do
|
||||
# opt=$1; shift
|
||||
# case $opt in
|
||||
# --silent|-s) opt_silent=: ;;
|
||||
# --silent|-s) opt_silent=:
|
||||
# args_changed=:
|
||||
# ;;
|
||||
# # Separate non-argument short options:
|
||||
# -s*) func_split_short_opt "$_G_opt"
|
||||
# set dummy "$func_split_short_opt_name" \
|
||||
# "-$func_split_short_opt_arg" ${1+"$@"}
|
||||
# shift
|
||||
# args_changed=:
|
||||
# ;;
|
||||
# *) set dummy "$_G_opt" "$*"; shift; break ;;
|
||||
# *) # Make sure the first unrecognised option "$_G_opt"
|
||||
# # is added back to "$@", we could need that later
|
||||
# # if $args_changed is true.
|
||||
# set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
# esac
|
||||
# done
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_silent_option_result=$func_quote_for_eval_result
|
||||
# if $args_changed; then
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_silent_option_result=$func_quote_for_eval_result
|
||||
# fi
|
||||
#
|
||||
# $args_changed
|
||||
# }
|
||||
# func_add_hook func_parse_options my_silent_option
|
||||
#
|
||||
@ -1611,16 +1633,32 @@ func_run_hooks ()
|
||||
# $opt_silent && $opt_verbose && func_fatal_help "\
|
||||
# '--silent' and '--verbose' options are mutually exclusive."
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_option_validation_result=$func_quote_for_eval_result
|
||||
# false
|
||||
# }
|
||||
# func_add_hook func_validate_options my_option_validation
|
||||
#
|
||||
# You'll alse need to manually amend $usage_message to reflect the extra
|
||||
# You'll also need to manually amend $usage_message to reflect the extra
|
||||
# options you parse. It's preferable to append if you can, so that
|
||||
# multiple option parsing hooks can be added safely.
|
||||
|
||||
|
||||
# func_options_finish [ARG]...
|
||||
# ----------------------------
|
||||
# Finishing the option parse loop (call 'func_options' hooks ATM).
|
||||
func_options_finish ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_func_options_finish_exit=false
|
||||
if func_run_hooks func_options ${1+"$@"}; then
|
||||
func_options_finish_result=$func_run_hooks_result
|
||||
_G_func_options_finish_exit=:
|
||||
fi
|
||||
|
||||
$_G_func_options_finish_exit
|
||||
}
|
||||
|
||||
|
||||
# func_options [ARG]...
|
||||
# ---------------------
|
||||
# All the functions called inside func_options are hookable. See the
|
||||
@ -1630,17 +1668,28 @@ func_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
func_options_prep ${1+"$@"}
|
||||
eval func_parse_options \
|
||||
${func_options_prep_result+"$func_options_prep_result"}
|
||||
eval func_validate_options \
|
||||
${func_parse_options_result+"$func_parse_options_result"}
|
||||
_G_rc_options=false
|
||||
|
||||
eval func_run_hooks func_options \
|
||||
${func_validate_options_result+"$func_validate_options_result"}
|
||||
for my_func in options_prep parse_options validate_options options_finish
|
||||
do
|
||||
if eval func_$my_func '${1+"$@"}'; then
|
||||
eval _G_res_var='$'"func_${my_func}_result"
|
||||
eval set dummy "$_G_res_var" ; shift
|
||||
_G_rc_options=:
|
||||
fi
|
||||
done
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_options_result=$func_run_hooks_result
|
||||
# Save modified positional parameters for caller. As a top-level
|
||||
# options-parser function we always need to set the 'func_options_result'
|
||||
# variable (regardless the $_G_rc_options value).
|
||||
if $_G_rc_options; then
|
||||
func_options_result=$_G_res_var
|
||||
else
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_options
|
||||
}
|
||||
|
||||
|
||||
@ -1649,9 +1698,9 @@ func_options ()
|
||||
# All initialisations required before starting the option parse loop.
|
||||
# Note that when calling hook functions, we pass through the list of
|
||||
# positional parameters. If a hook function modifies that list, and
|
||||
# needs to propogate that back to rest of this script, then the complete
|
||||
# needs to propagate that back to rest of this script, then the complete
|
||||
# modified list must be put in 'func_run_hooks_result' before
|
||||
# returning.
|
||||
# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned).
|
||||
func_hookable func_options_prep
|
||||
func_options_prep ()
|
||||
{
|
||||
@ -1661,10 +1710,14 @@ func_options_prep ()
|
||||
opt_verbose=false
|
||||
opt_warning_types=
|
||||
|
||||
func_run_hooks func_options_prep ${1+"$@"}
|
||||
_G_rc_options_prep=false
|
||||
if func_run_hooks func_options_prep ${1+"$@"}; then
|
||||
_G_rc_options_prep=:
|
||||
# save modified positional parameters for caller
|
||||
func_options_prep_result=$func_run_hooks_result
|
||||
fi
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_options_prep_result=$func_run_hooks_result
|
||||
$_G_rc_options_prep
|
||||
}
|
||||
|
||||
|
||||
@ -1678,18 +1731,20 @@ func_parse_options ()
|
||||
|
||||
func_parse_options_result=
|
||||
|
||||
_G_rc_parse_options=false
|
||||
# this just eases exit handling
|
||||
while test $# -gt 0; do
|
||||
# Defer to hook functions for initial option parsing, so they
|
||||
# get priority in the event of reusing an option name.
|
||||
func_run_hooks func_parse_options ${1+"$@"}
|
||||
|
||||
# Adjust func_parse_options positional parameters to match
|
||||
eval set dummy "$func_run_hooks_result"; shift
|
||||
if func_run_hooks func_parse_options ${1+"$@"}; then
|
||||
eval set dummy "$func_run_hooks_result"; shift
|
||||
_G_rc_parse_options=:
|
||||
fi
|
||||
|
||||
# Break out of the loop if we already parsed every option.
|
||||
test $# -gt 0 || break
|
||||
|
||||
_G_match_parse_options=:
|
||||
_G_opt=$1
|
||||
shift
|
||||
case $_G_opt in
|
||||
@ -1704,7 +1759,10 @@ func_parse_options ()
|
||||
;;
|
||||
|
||||
--warnings|--warning|-W)
|
||||
test $# = 0 && func_missing_arg $_G_opt && break
|
||||
if test $# = 0 && func_missing_arg $_G_opt; then
|
||||
_G_rc_parse_options=:
|
||||
break
|
||||
fi
|
||||
case " $warning_categories $1" in
|
||||
*" $1 "*)
|
||||
# trailing space prevents matching last $1 above
|
||||
@ -1757,15 +1815,25 @@ func_parse_options ()
|
||||
shift
|
||||
;;
|
||||
|
||||
--) break ;;
|
||||
--) _G_rc_parse_options=: ; break ;;
|
||||
-*) func_fatal_help "unrecognised option: '$_G_opt'" ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift
|
||||
_G_match_parse_options=false
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
$_G_match_parse_options && _G_rc_parse_options=:
|
||||
done
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_parse_options_result=$func_quote_for_eval_result
|
||||
|
||||
if $_G_rc_parse_options; then
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_parse_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_parse_options
|
||||
}
|
||||
|
||||
|
||||
@ -1778,16 +1846,21 @@ func_validate_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_validate_options=false
|
||||
|
||||
# Display all warnings if -W was not given.
|
||||
test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
|
||||
|
||||
func_run_hooks func_validate_options ${1+"$@"}
|
||||
if func_run_hooks func_validate_options ${1+"$@"}; then
|
||||
# save modified positional parameters for caller
|
||||
func_validate_options_result=$func_run_hooks_result
|
||||
_G_rc_validate_options=:
|
||||
fi
|
||||
|
||||
# Bail if the options were screwed!
|
||||
$exit_cmd $EXIT_FAILURE
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_validate_options_result=$func_run_hooks_result
|
||||
$_G_rc_validate_options
|
||||
}
|
||||
|
||||
|
||||
@ -2068,7 +2141,7 @@ include the following information:
|
||||
compiler: $LTCC
|
||||
compiler flags: $LTCFLAGS
|
||||
linker: $LD (gnu? $with_gnu_ld)
|
||||
version: $progname $scriptversion Debian-2.4.6-2
|
||||
version: $progname $scriptversion Debian-2.4.6-15build2
|
||||
automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
|
||||
autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q`
|
||||
|
||||
@ -2270,6 +2343,8 @@ libtool_options_prep ()
|
||||
nonopt=
|
||||
preserve_args=
|
||||
|
||||
_G_rc_lt_options_prep=:
|
||||
|
||||
# Shorthand for --mode=foo, only valid as the first argument
|
||||
case $1 in
|
||||
clean|clea|cle|cl)
|
||||
@ -2293,11 +2368,18 @@ libtool_options_prep ()
|
||||
uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
|
||||
shift; set dummy --mode uninstall ${1+"$@"}; shift
|
||||
;;
|
||||
*)
|
||||
_G_rc_lt_options_prep=false
|
||||
;;
|
||||
esac
|
||||
|
||||
# Pass back the list of options.
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_options_prep_result=$func_quote_for_eval_result
|
||||
if $_G_rc_lt_options_prep; then
|
||||
# Pass back the list of options.
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_options_prep_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_lt_options_prep
|
||||
}
|
||||
func_add_hook func_options_prep libtool_options_prep
|
||||
|
||||
@ -2309,9 +2391,12 @@ libtool_parse_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_lt_parse_options=false
|
||||
|
||||
# Perform our own loop to consume as many options as possible in
|
||||
# each iteration.
|
||||
while test $# -gt 0; do
|
||||
_G_match_lt_parse_options=:
|
||||
_G_opt=$1
|
||||
shift
|
||||
case $_G_opt in
|
||||
@ -2386,15 +2471,22 @@ libtool_parse_options ()
|
||||
func_append preserve_args " $_G_opt"
|
||||
;;
|
||||
|
||||
# An option not handled by this hook function:
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
# An option not handled by this hook function:
|
||||
*) set dummy "$_G_opt" ${1+"$@"} ; shift
|
||||
_G_match_lt_parse_options=false
|
||||
break
|
||||
;;
|
||||
esac
|
||||
$_G_match_lt_parse_options && _G_rc_lt_parse_options=:
|
||||
done
|
||||
|
||||
if $_G_rc_lt_parse_options; then
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_parse_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_parse_options_result=$func_quote_for_eval_result
|
||||
$_G_rc_lt_parse_options
|
||||
}
|
||||
func_add_hook func_parse_options libtool_parse_options
|
||||
|
||||
@ -7275,10 +7367,13 @@ func_mode_link ()
|
||||
# -specs=* GCC specs files
|
||||
# -stdlib=* select c++ std lib with clang
|
||||
# -fsanitize=* Clang/GCC memory and address sanitizer
|
||||
# -fuse-ld=* Linker select flags for GCC
|
||||
# -static-* direct GCC to link specific libraries statically
|
||||
# -fcilkplus Cilk Plus language extension features for C/C++
|
||||
-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
|
||||
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
|
||||
-O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
|
||||
-specs=*|-fsanitize=*)
|
||||
-specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus)
|
||||
func_quote_for_eval "$arg"
|
||||
arg=$func_quote_for_eval_result
|
||||
func_append compile_command " $arg"
|
||||
@ -1,9 +1,9 @@
|
||||
#! /bin/sh
|
||||
# Common wrapper for a few potentially missing GNU programs.
|
||||
|
||||
scriptversion=2013-10-28.13; # UTC
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 1996-2014 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
||||
# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@ -17,7 +17,7 @@ scriptversion=2013-10-28.13; # UTC
|
||||
# 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/>.
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
@ -101,9 +101,9 @@ else
|
||||
exit $st
|
||||
fi
|
||||
|
||||
perl_URL=http://www.perl.org/
|
||||
flex_URL=http://flex.sourceforge.net/
|
||||
gnu_software_URL=http://www.gnu.org/software
|
||||
perl_URL=https://www.perl.org/
|
||||
flex_URL=https://github.com/westes/flex
|
||||
gnu_software_URL=https://www.gnu.org/software
|
||||
|
||||
program_details ()
|
||||
{
|
||||
@ -207,9 +207,9 @@ give_advice "$1" | sed -e '1s/^/WARNING: /' \
|
||||
exit $st
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
153
src/third_party/cares/dist/config/test-driver
vendored
Executable file
153
src/third_party/cares/dist/config/test-driver
vendored
Executable file
@ -0,0 +1,153 @@
|
||||
#! /bin/sh
|
||||
# test-driver - basic testsuite driver script.
|
||||
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 2011-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <bug-automake@gnu.org> or send patches to
|
||||
# <automake-patches@gnu.org>.
|
||||
|
||||
# Make unconditional expansion of undefined variables an error. This
|
||||
# helps a lot in preventing typo-related bugs.
|
||||
set -u
|
||||
|
||||
usage_error ()
|
||||
{
|
||||
echo "$0: $*" >&2
|
||||
print_usage >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
print_usage ()
|
||||
{
|
||||
cat <<END
|
||||
Usage:
|
||||
test-driver --test-name NAME --log-file PATH --trs-file PATH
|
||||
[--expect-failure {yes|no}] [--color-tests {yes|no}]
|
||||
[--enable-hard-errors {yes|no}] [--]
|
||||
TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
|
||||
|
||||
The '--test-name', '--log-file' and '--trs-file' options are mandatory.
|
||||
See the GNU Automake documentation for information.
|
||||
END
|
||||
}
|
||||
|
||||
test_name= # Used for reporting.
|
||||
log_file= # Where to save the output of the test script.
|
||||
trs_file= # Where to save the metadata of the test run.
|
||||
expect_failure=no
|
||||
color_tests=no
|
||||
enable_hard_errors=yes
|
||||
while test $# -gt 0; do
|
||||
case $1 in
|
||||
--help) print_usage; exit $?;;
|
||||
--version) echo "test-driver $scriptversion"; exit $?;;
|
||||
--test-name) test_name=$2; shift;;
|
||||
--log-file) log_file=$2; shift;;
|
||||
--trs-file) trs_file=$2; shift;;
|
||||
--color-tests) color_tests=$2; shift;;
|
||||
--expect-failure) expect_failure=$2; shift;;
|
||||
--enable-hard-errors) enable_hard_errors=$2; shift;;
|
||||
--) shift; break;;
|
||||
-*) usage_error "invalid option: '$1'";;
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
missing_opts=
|
||||
test x"$test_name" = x && missing_opts="$missing_opts --test-name"
|
||||
test x"$log_file" = x && missing_opts="$missing_opts --log-file"
|
||||
test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
|
||||
if test x"$missing_opts" != x; then
|
||||
usage_error "the following mandatory options are missing:$missing_opts"
|
||||
fi
|
||||
|
||||
if test $# -eq 0; then
|
||||
usage_error "missing argument"
|
||||
fi
|
||||
|
||||
if test $color_tests = yes; then
|
||||
# Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
|
||||
red='[0;31m' # Red.
|
||||
grn='[0;32m' # Green.
|
||||
lgn='[1;32m' # Light green.
|
||||
blu='[1;34m' # Blue.
|
||||
mgn='[0;35m' # Magenta.
|
||||
std='[m' # No color.
|
||||
else
|
||||
red= grn= lgn= blu= mgn= std=
|
||||
fi
|
||||
|
||||
do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
|
||||
trap "st=129; $do_exit" 1
|
||||
trap "st=130; $do_exit" 2
|
||||
trap "st=141; $do_exit" 13
|
||||
trap "st=143; $do_exit" 15
|
||||
|
||||
# Test script is run here. We create the file first, then append to it,
|
||||
# to ameliorate tests themselves also writing to the log file. Our tests
|
||||
# don't, but others can (automake bug#35762).
|
||||
: >"$log_file"
|
||||
"$@" >>"$log_file" 2>&1
|
||||
estatus=$?
|
||||
|
||||
if test $enable_hard_errors = no && test $estatus -eq 99; then
|
||||
tweaked_estatus=1
|
||||
else
|
||||
tweaked_estatus=$estatus
|
||||
fi
|
||||
|
||||
case $tweaked_estatus:$expect_failure in
|
||||
0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
|
||||
0:*) col=$grn res=PASS recheck=no gcopy=no;;
|
||||
77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
|
||||
99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
|
||||
*:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
|
||||
*:*) col=$red res=FAIL recheck=yes gcopy=yes;;
|
||||
esac
|
||||
|
||||
# Report the test outcome and exit status in the logs, so that one can
|
||||
# know whether the test passed or failed simply by looking at the '.log'
|
||||
# file, without the need of also peaking into the corresponding '.trs'
|
||||
# file (automake bug#11814).
|
||||
echo "$res $test_name (exit status: $estatus)" >>"$log_file"
|
||||
|
||||
# Report outcome to console.
|
||||
echo "${col}${res}${std}: $test_name"
|
||||
|
||||
# Register the test result, and other relevant metadata.
|
||||
echo ":test-result: $res" > $trs_file
|
||||
echo ":global-test-result: $res" >> $trs_file
|
||||
echo ":recheck: $recheck" >> $trs_file
|
||||
echo ":copy-in-global-log: $gcopy" >> $trs_file
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
30277
src/third_party/cares/dist/configure
vendored
30277
src/third_party/cares/dist/configure
vendored
File diff suppressed because it is too large
Load Diff
1433
src/third_party/cares/dist/configure.ac
vendored
1433
src/third_party/cares/dist/configure.ac
vendored
File diff suppressed because it is too large
Load Diff
2
src/third_party/cares/dist/get_ver.awk
vendored
2
src/third_party/cares/dist/get_ver.awk
vendored
@ -1,6 +1,8 @@
|
||||
# ***************************************************************************
|
||||
# * Project: c-ares
|
||||
# *
|
||||
# * Copyright (C) The c-ares project and its contributors
|
||||
# * SPDX-License-Identifier: MIT
|
||||
# ***************************************************************************
|
||||
# awk script which fetches c-ares version number and string from input
|
||||
# file and writes them to STDOUT. Here you can get an awk version for Win32:
|
||||
|
||||
2
src/third_party/cares/dist/git2changes.pl
vendored
2
src/third_party/cares/dist/git2changes.pl
vendored
@ -1,4 +1,6 @@
|
||||
#!/usr/bin/perl
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# git log --pretty=fuller --no-color --date=short --decorate=full
|
||||
|
||||
|
||||
835
src/third_party/cares/dist/include/ares.h
vendored
835
src/third_party/cares/dist/include/ares.h
vendored
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,9 @@
|
||||
#ifndef __CARES_BUILD_H
|
||||
#define __CARES_BUILD_H
|
||||
/*
|
||||
* Copyright (C) The c-ares project and its contributors
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define CARES_TYPEOF_ARES_SOCKLEN_T @CARES_TYPEOF_ARES_SOCKLEN_T@
|
||||
#define CARES_TYPEOF_ARES_SSIZE_T @CARES_TYPEOF_ARES_SSIZE_T@
|
||||
|
||||
@ -1,20 +1,32 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2009 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __CARES_BUILD_H
|
||||
#define __CARES_BUILD_H
|
||||
|
||||
|
||||
/* Copyright (C) 2009 - 2021 by Daniel Stenberg et al
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. M.I.T. makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
|
||||
/* ================================================================ */
|
||||
|
||||
110
src/third_party/cares/dist/include/ares_build.h.in
vendored
110
src/third_party/cares/dist/include/ares_build.h.in
vendored
@ -1,103 +1,47 @@
|
||||
#ifndef __CARES_BUILD_H
|
||||
#define __CARES_BUILD_H
|
||||
|
||||
|
||||
/* Copyright (C) 2009 - 2021 by Daniel Stenberg et al
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. M.I.T. makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
|
||||
/* ================================================================ */
|
||||
|
||||
/*
|
||||
* NOTE 1:
|
||||
* -------
|
||||
*
|
||||
* Nothing in this file is intended to be modified or adjusted by the
|
||||
* c-ares library user nor by the c-ares library builder.
|
||||
*
|
||||
* If you think that something actually needs to be changed, adjusted
|
||||
* or fixed in this file, then, report it on the c-ares development
|
||||
* mailing list: http://lists.haxx.se/listinfo/c-ares/
|
||||
*
|
||||
* This header file shall only export symbols which are 'cares' or 'CARES'
|
||||
* prefixed, otherwise public name space would be polluted.
|
||||
*
|
||||
* NOTE 2:
|
||||
* -------
|
||||
*
|
||||
* Right now you might be staring at file ares_build.h.in or ares_build.h,
|
||||
* this is due to the following reason:
|
||||
*
|
||||
* On systems capable of running the configure script, the configure process
|
||||
* will overwrite the distributed ares_build.h file with one that is suitable
|
||||
* and specific to the library being configured and built, which is generated
|
||||
* from the ares_build.h.in template file.
|
||||
*
|
||||
* Copyright (C) The c-ares project and its contributors
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
|
||||
/* ================================================================ */
|
||||
|
||||
#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
|
||||
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
|
||||
#endif
|
||||
#define CARES_TYPEOF_ARES_SOCKLEN_T @CARES_TYPEOF_ARES_SOCKLEN_T@
|
||||
#define CARES_TYPEOF_ARES_SSIZE_T @CARES_TYPEOF_ARES_SSIZE_T@
|
||||
|
||||
/* Prefix names with CARES_ to make sure they don't conflict with other config.h
|
||||
* files. We need to include some dependent headers that may be system specific
|
||||
* for C-Ares */
|
||||
#undef CARES_HAVE_SYS_TYPES_H
|
||||
#undef CARES_HAVE_SYS_SOCKET_H
|
||||
#undef CARES_HAVE_WINDOWS_H
|
||||
#undef CARES_HAVE_WS2TCPIP_H
|
||||
#undef CARES_HAVE_WINSOCK2_H
|
||||
#undef CARES_HAVE_WINDOWS_H
|
||||
#undef CARES_HAVE_ARPA_NAMESER_H
|
||||
#undef CARES_HAVE_ARPA_NAMESER_COMPAT_H
|
||||
|
||||
/* ================================================================ */
|
||||
/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */
|
||||
/* ================================================================ */
|
||||
|
||||
/* Configure process defines this to 1 when it finds out that system */
|
||||
/* header file ws2tcpip.h must be included by the external interface. */
|
||||
#undef CARES_PULL_WS2TCPIP_H
|
||||
#ifdef CARES_PULL_WS2TCPIP_H
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
/* Configure process defines this to 1 when it finds out that system */
|
||||
/* header file sys/types.h must be included by the external interface. */
|
||||
#undef CARES_PULL_SYS_TYPES_H
|
||||
#ifdef CARES_PULL_SYS_TYPES_H
|
||||
#ifdef CARES_HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/* Configure process defines this to 1 when it finds out that system */
|
||||
/* header file sys/socket.h must be included by the external interface. */
|
||||
#undef CARES_PULL_SYS_SOCKET_H
|
||||
#ifdef CARES_PULL_SYS_SOCKET_H
|
||||
#ifdef CARES_HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
/* Integral data type used for ares_socklen_t. */
|
||||
#undef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
#ifdef CARES_HAVE_WINSOCK2_H
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifdef CARES_HAVE_WS2TCPIP_H
|
||||
# include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#ifdef CARES_HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* Data type definition of ares_socklen_t. */
|
||||
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
|
||||
|
||||
/* Integral data type used for ares_ssize_t. */
|
||||
#undef CARES_TYPEOF_ARES_SSIZE_T
|
||||
|
||||
/* Data type definition of ares_ssize_t. */
|
||||
typedef CARES_TYPEOF_ARES_SSIZE_T ares_ssize_t;
|
||||
|
||||
#endif /* __CARES_BUILD_H */
|
||||
|
||||
157
src/third_party/cares/dist/include/ares_dns.h
vendored
157
src/third_party/cares/dist/include/ares_dns.h
vendored
@ -1,21 +1,32 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) Massachusetts Institute of Technology
|
||||
* Copyright (c) The c-ares project and its contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef HEADER_CARES_DNS_H
|
||||
#define HEADER_CARES_DNS_H
|
||||
|
||||
/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE TO INTEGRATORS:
|
||||
*
|
||||
@ -29,84 +40,88 @@
|
||||
* Macro DNS__16BIT reads a network short (16 bit) given in network
|
||||
* byte order, and returns its value as an unsigned short.
|
||||
*/
|
||||
#define DNS__16BIT(p) ((unsigned short)((unsigned int) 0xffff & \
|
||||
(((unsigned int)((unsigned char)(p)[0]) << 8U) | \
|
||||
((unsigned int)((unsigned char)(p)[1])))))
|
||||
#define DNS__16BIT(p) \
|
||||
((unsigned short)((unsigned int)0xffff & \
|
||||
(((unsigned int)((unsigned char)(p)[0]) << 8U) | \
|
||||
((unsigned int)((unsigned char)(p)[1])))))
|
||||
|
||||
/*
|
||||
* Macro DNS__32BIT reads a network long (32 bit) given in network
|
||||
* byte order, and returns its value as an unsigned int.
|
||||
*/
|
||||
#define DNS__32BIT(p) ((unsigned int) \
|
||||
(((unsigned int)((unsigned char)(p)[0]) << 24U) | \
|
||||
((unsigned int)((unsigned char)(p)[1]) << 16U) | \
|
||||
((unsigned int)((unsigned char)(p)[2]) << 8U) | \
|
||||
((unsigned int)((unsigned char)(p)[3]))))
|
||||
#define DNS__32BIT(p) \
|
||||
((unsigned int)(((unsigned int)((unsigned char)(p)[0]) << 24U) | \
|
||||
((unsigned int)((unsigned char)(p)[1]) << 16U) | \
|
||||
((unsigned int)((unsigned char)(p)[2]) << 8U) | \
|
||||
((unsigned int)((unsigned char)(p)[3]))))
|
||||
|
||||
#define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \
|
||||
((p)[1] = (unsigned char)((v) & 0xff)))
|
||||
#define DNS__SET32BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 24) & 0xff)), \
|
||||
((p)[1] = (unsigned char)(((v) >> 16) & 0xff)), \
|
||||
((p)[2] = (unsigned char)(((v) >> 8) & 0xff)), \
|
||||
((p)[3] = (unsigned char)((v) & 0xff)))
|
||||
#define DNS__SET16BIT(p, v) \
|
||||
(((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \
|
||||
((p)[1] = (unsigned char)((v) & 0xff)))
|
||||
#define DNS__SET32BIT(p, v) \
|
||||
(((p)[0] = (unsigned char)(((v) >> 24) & 0xff)), \
|
||||
((p)[1] = (unsigned char)(((v) >> 16) & 0xff)), \
|
||||
((p)[2] = (unsigned char)(((v) >> 8) & 0xff)), \
|
||||
((p)[3] = (unsigned char)((v) & 0xff)))
|
||||
|
||||
#if 0
|
||||
/* we cannot use this approach on systems where we can't access 16/32 bit
|
||||
data on un-aligned addresses */
|
||||
#define DNS__16BIT(p) ntohs(*(unsigned short*)(p))
|
||||
#define DNS__32BIT(p) ntohl(*(unsigned long*)(p))
|
||||
#define DNS__SET16BIT(p, v) *(unsigned short*)(p) = htons(v)
|
||||
#define DNS__SET32BIT(p, v) *(unsigned long*)(p) = htonl(v)
|
||||
# define DNS__16BIT(p) ntohs(*(unsigned short *)(p))
|
||||
# define DNS__32BIT(p) ntohl(*(unsigned long *)(p))
|
||||
# define DNS__SET16BIT(p, v) *(unsigned short *)(p) = htons(v)
|
||||
# define DNS__SET32BIT(p, v) *(unsigned long *)(p) = htonl(v)
|
||||
#endif
|
||||
|
||||
/* Macros for parsing a DNS header */
|
||||
#define DNS_HEADER_QID(h) DNS__16BIT(h)
|
||||
#define DNS_HEADER_QR(h) (((h)[2] >> 7) & 0x1)
|
||||
#define DNS_HEADER_OPCODE(h) (((h)[2] >> 3) & 0xf)
|
||||
#define DNS_HEADER_AA(h) (((h)[2] >> 2) & 0x1)
|
||||
#define DNS_HEADER_TC(h) (((h)[2] >> 1) & 0x1)
|
||||
#define DNS_HEADER_RD(h) ((h)[2] & 0x1)
|
||||
#define DNS_HEADER_RA(h) (((h)[3] >> 7) & 0x1)
|
||||
#define DNS_HEADER_Z(h) (((h)[3] >> 4) & 0x7)
|
||||
#define DNS_HEADER_RCODE(h) ((h)[3] & 0xf)
|
||||
#define DNS_HEADER_QDCOUNT(h) DNS__16BIT((h) + 4)
|
||||
#define DNS_HEADER_ANCOUNT(h) DNS__16BIT((h) + 6)
|
||||
#define DNS_HEADER_NSCOUNT(h) DNS__16BIT((h) + 8)
|
||||
#define DNS_HEADER_ARCOUNT(h) DNS__16BIT((h) + 10)
|
||||
#define DNS_HEADER_QID(h) DNS__16BIT(h)
|
||||
#define DNS_HEADER_QR(h) (((h)[2] >> 7) & 0x1)
|
||||
#define DNS_HEADER_OPCODE(h) (((h)[2] >> 3) & 0xf)
|
||||
#define DNS_HEADER_AA(h) (((h)[2] >> 2) & 0x1)
|
||||
#define DNS_HEADER_TC(h) (((h)[2] >> 1) & 0x1)
|
||||
#define DNS_HEADER_RD(h) ((h)[2] & 0x1)
|
||||
#define DNS_HEADER_RA(h) (((h)[3] >> 7) & 0x1)
|
||||
#define DNS_HEADER_Z(h) (((h)[3] >> 4) & 0x7)
|
||||
#define DNS_HEADER_RCODE(h) ((h)[3] & 0xf)
|
||||
#define DNS_HEADER_QDCOUNT(h) DNS__16BIT((h) + 4)
|
||||
#define DNS_HEADER_ANCOUNT(h) DNS__16BIT((h) + 6)
|
||||
#define DNS_HEADER_NSCOUNT(h) DNS__16BIT((h) + 8)
|
||||
#define DNS_HEADER_ARCOUNT(h) DNS__16BIT((h) + 10)
|
||||
|
||||
/* Macros for constructing a DNS header */
|
||||
#define DNS_HEADER_SET_QID(h, v) DNS__SET16BIT(h, v)
|
||||
#define DNS_HEADER_SET_QR(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 7))
|
||||
#define DNS_HEADER_SET_OPCODE(h, v) ((h)[2] |= (unsigned char)(((v) & 0xf) << 3))
|
||||
#define DNS_HEADER_SET_AA(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 2))
|
||||
#define DNS_HEADER_SET_TC(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 1))
|
||||
#define DNS_HEADER_SET_RD(h, v) ((h)[2] |= (unsigned char)((v) & 0x1))
|
||||
#define DNS_HEADER_SET_RA(h, v) ((h)[3] |= (unsigned char)(((v) & 0x1) << 7))
|
||||
#define DNS_HEADER_SET_Z(h, v) ((h)[3] |= (unsigned char)(((v) & 0x7) << 4))
|
||||
#define DNS_HEADER_SET_RCODE(h, v) ((h)[3] |= (unsigned char)((v) & 0xf))
|
||||
#define DNS_HEADER_SET_QDCOUNT(h, v) DNS__SET16BIT((h) + 4, v)
|
||||
#define DNS_HEADER_SET_ANCOUNT(h, v) DNS__SET16BIT((h) + 6, v)
|
||||
#define DNS_HEADER_SET_NSCOUNT(h, v) DNS__SET16BIT((h) + 8, v)
|
||||
#define DNS_HEADER_SET_ARCOUNT(h, v) DNS__SET16BIT((h) + 10, v)
|
||||
#define DNS_HEADER_SET_QID(h, v) DNS__SET16BIT(h, v)
|
||||
#define DNS_HEADER_SET_QR(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 7))
|
||||
#define DNS_HEADER_SET_OPCODE(h, v) \
|
||||
((h)[2] |= (unsigned char)(((v) & 0xf) << 3))
|
||||
#define DNS_HEADER_SET_AA(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 2))
|
||||
#define DNS_HEADER_SET_TC(h, v) ((h)[2] |= (unsigned char)(((v) & 0x1) << 1))
|
||||
#define DNS_HEADER_SET_RD(h, v) ((h)[2] |= (unsigned char)((v) & 0x1))
|
||||
#define DNS_HEADER_SET_RA(h, v) ((h)[3] |= (unsigned char)(((v) & 0x1) << 7))
|
||||
#define DNS_HEADER_SET_Z(h, v) ((h)[3] |= (unsigned char)(((v) & 0x7) << 4))
|
||||
#define DNS_HEADER_SET_RCODE(h, v) ((h)[3] |= (unsigned char)((v) & 0xf))
|
||||
#define DNS_HEADER_SET_QDCOUNT(h, v) DNS__SET16BIT((h) + 4, v)
|
||||
#define DNS_HEADER_SET_ANCOUNT(h, v) DNS__SET16BIT((h) + 6, v)
|
||||
#define DNS_HEADER_SET_NSCOUNT(h, v) DNS__SET16BIT((h) + 8, v)
|
||||
#define DNS_HEADER_SET_ARCOUNT(h, v) DNS__SET16BIT((h) + 10, v)
|
||||
|
||||
/* Macros for parsing the fixed part of a DNS question */
|
||||
#define DNS_QUESTION_TYPE(q) DNS__16BIT(q)
|
||||
#define DNS_QUESTION_CLASS(q) DNS__16BIT((q) + 2)
|
||||
#define DNS_QUESTION_TYPE(q) DNS__16BIT(q)
|
||||
#define DNS_QUESTION_CLASS(q) DNS__16BIT((q) + 2)
|
||||
|
||||
/* Macros for constructing the fixed part of a DNS question */
|
||||
#define DNS_QUESTION_SET_TYPE(q, v) DNS__SET16BIT(q, v)
|
||||
#define DNS_QUESTION_SET_CLASS(q, v) DNS__SET16BIT((q) + 2, v)
|
||||
#define DNS_QUESTION_SET_TYPE(q, v) DNS__SET16BIT(q, v)
|
||||
#define DNS_QUESTION_SET_CLASS(q, v) DNS__SET16BIT((q) + 2, v)
|
||||
|
||||
/* Macros for parsing the fixed part of a DNS resource record */
|
||||
#define DNS_RR_TYPE(r) DNS__16BIT(r)
|
||||
#define DNS_RR_CLASS(r) DNS__16BIT((r) + 2)
|
||||
#define DNS_RR_TTL(r) DNS__32BIT((r) + 4)
|
||||
#define DNS_RR_LEN(r) DNS__16BIT((r) + 8)
|
||||
#define DNS_RR_TYPE(r) DNS__16BIT(r)
|
||||
#define DNS_RR_CLASS(r) DNS__16BIT((r) + 2)
|
||||
#define DNS_RR_TTL(r) DNS__32BIT((r) + 4)
|
||||
#define DNS_RR_LEN(r) DNS__16BIT((r) + 8)
|
||||
|
||||
/* Macros for constructing the fixed part of a DNS resource record */
|
||||
#define DNS_RR_SET_TYPE(r, v) DNS__SET16BIT(r, v)
|
||||
#define DNS_RR_SET_CLASS(r, v) DNS__SET16BIT((r) + 2, v)
|
||||
#define DNS_RR_SET_TTL(r, v) DNS__SET32BIT((r) + 4, v)
|
||||
#define DNS_RR_SET_LEN(r, v) DNS__SET16BIT((r) + 8, v)
|
||||
#define DNS_RR_SET_TYPE(r, v) DNS__SET16BIT(r, v)
|
||||
#define DNS_RR_SET_CLASS(r, v) DNS__SET16BIT((r) + 2, v)
|
||||
#define DNS_RR_SET_TTL(r, v) DNS__SET32BIT((r) + 4, v)
|
||||
#define DNS_RR_SET_LEN(r, v) DNS__SET16BIT((r) + 8, v)
|
||||
|
||||
#endif /* HEADER_CARES_DNS_H */
|
||||
|
||||
970
src/third_party/cares/dist/include/ares_dns_record.h
vendored
Normal file
970
src/third_party/cares/dist/include/ares_dns_record.h
vendored
Normal file
@ -0,0 +1,970 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES_DNS_RECORD_H
|
||||
#define __ARES_DNS_RECORD_H
|
||||
|
||||
/* Include ares.h, not this file directly */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! \addtogroup ares_dns_record DNS Record Handling
|
||||
*
|
||||
* This is a set of functions to create and manipulate DNS records.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! DNS Record types handled by c-ares. Some record types may only be valid
|
||||
* on requests (e.g. ARES_REC_TYPE_ANY), and some may only be valid on
|
||||
* responses */
|
||||
typedef enum {
|
||||
ARES_REC_TYPE_A = 1, /*!< Host address. */
|
||||
ARES_REC_TYPE_NS = 2, /*!< Authoritative server. */
|
||||
ARES_REC_TYPE_CNAME = 5, /*!< Canonical name. */
|
||||
ARES_REC_TYPE_SOA = 6, /*!< Start of authority zone. */
|
||||
ARES_REC_TYPE_PTR = 12, /*!< Domain name pointer. */
|
||||
ARES_REC_TYPE_HINFO = 13, /*!< Host information. */
|
||||
ARES_REC_TYPE_MX = 15, /*!< Mail routing information. */
|
||||
ARES_REC_TYPE_TXT = 16, /*!< Text strings. */
|
||||
ARES_REC_TYPE_AAAA = 28, /*!< RFC 3596. Ip6 Address. */
|
||||
ARES_REC_TYPE_SRV = 33, /*!< RFC 2782. Server Selection. */
|
||||
ARES_REC_TYPE_NAPTR = 35, /*!< RFC 3403. Naming Authority Pointer */
|
||||
ARES_REC_TYPE_OPT = 41, /*!< RFC 6891. EDNS0 option (meta-RR) */
|
||||
|
||||
ARES_REC_TYPE_TLSA = 52, /*!< RFC 6698. DNS-Based Authentication of Named
|
||||
* Entities (DANE) Transport Layer Security
|
||||
* (TLS) Protocol: TLSA */
|
||||
ARES_REC_TYPE_SVCB = 64, /*!< RFC 9460. General Purpose Service Binding */
|
||||
ARES_REC_TYPE_HTTPS = 65, /*!< RFC 9460. Service Binding type for use with
|
||||
* HTTPS */
|
||||
ARES_REC_TYPE_ANY = 255, /*!< Wildcard match. Not response RR. */
|
||||
ARES_REC_TYPE_URI = 256, /*!< RFC 7553. Uniform Resource Identifier */
|
||||
ARES_REC_TYPE_CAA = 257, /*!< RFC 6844. Certification Authority
|
||||
* Authorization. */
|
||||
ARES_REC_TYPE_RAW_RR = 65536 /*!< Used as an indicator that the RR record
|
||||
* is not parsed, but provided in wire
|
||||
* format */
|
||||
} ares_dns_rec_type_t;
|
||||
|
||||
/*! DNS Classes for requests and responses. */
|
||||
typedef enum {
|
||||
ARES_CLASS_IN = 1, /*!< Internet */
|
||||
ARES_CLASS_CHAOS = 3, /*!< CHAOS */
|
||||
ARES_CLASS_HESOID = 4, /*!< Hesoid [Dyer 87] */
|
||||
ARES_CLASS_NONE = 254, /*!< RFC 2136 */
|
||||
ARES_CLASS_ANY = 255 /*!< Any class (requests only) */
|
||||
} ares_dns_class_t;
|
||||
|
||||
/*! DNS RR Section type */
|
||||
typedef enum {
|
||||
ARES_SECTION_ANSWER = 1, /*!< Answer section */
|
||||
ARES_SECTION_AUTHORITY = 2, /*!< Authority section */
|
||||
ARES_SECTION_ADDITIONAL = 3 /*!< Additional information section */
|
||||
} ares_dns_section_t;
|
||||
|
||||
/*! DNS Header opcodes */
|
||||
typedef enum {
|
||||
ARES_OPCODE_QUERY = 0, /*!< Standard query */
|
||||
ARES_OPCODE_IQUERY = 1, /*!< Inverse query. Obsolete. */
|
||||
ARES_OPCODE_STATUS = 2, /*!< Name server status query */
|
||||
ARES_OPCODE_NOTIFY = 4, /*!< Zone change notification (RFC 1996) */
|
||||
ARES_OPCODE_UPDATE = 5, /*!< Zone update message (RFC2136) */
|
||||
} ares_dns_opcode_t;
|
||||
|
||||
/*! DNS Header flags */
|
||||
typedef enum {
|
||||
ARES_FLAG_QR = 1 << 0, /*!< QR. If set, is a response */
|
||||
ARES_FLAG_AA = 1 << 1, /*!< Authoritative Answer. If set, is authoritative */
|
||||
ARES_FLAG_TC = 1 << 2, /*!< Truncation. If set, is truncated response */
|
||||
ARES_FLAG_RD = 1 << 3, /*!< Recursion Desired. If set, recursion is desired */
|
||||
ARES_FLAG_RA = 1 << 4, /*!< Recursion Available. If set, server supports
|
||||
* recursion */
|
||||
ARES_FLAG_AD = 1 << 5, /*!< RFC 2065. Authentic Data bit indicates in a
|
||||
* response that the data included has been verified by
|
||||
* the server providing it */
|
||||
ARES_FLAG_CD = 1 << 6, /*!< RFC 2065. Checking Disabled bit indicates in a
|
||||
* query that non-verified data is acceptable to the
|
||||
* resolver sending the query. */
|
||||
} ares_dns_flags_t;
|
||||
|
||||
/*! DNS Response Codes from server */
|
||||
typedef enum {
|
||||
ARES_RCODE_NOERROR = 0, /*!< Success */
|
||||
ARES_RCODE_FORMERR = 1, /*!< Format error. The name server was unable
|
||||
* to interpret the query. */
|
||||
ARES_RCODE_SERVFAIL = 2, /*!< Server Failure. The name server was
|
||||
* unable to process this query due to a
|
||||
* problem with the nameserver */
|
||||
ARES_RCODE_NXDOMAIN = 3, /*!< Name Error. Meaningful only for
|
||||
* responses from an authoritative name
|
||||
* server, this code signifies that the
|
||||
* domain name referenced in the query does
|
||||
* not exist. */
|
||||
ARES_RCODE_NOTIMP = 4, /*!< Not implemented. The name server does
|
||||
* not support the requested kind of
|
||||
* query */
|
||||
ARES_RCODE_REFUSED = 5, /*!< Refused. The name server refuses to
|
||||
* perform the specified operation for
|
||||
* policy reasons. */
|
||||
ARES_RCODE_YXDOMAIN = 6, /*!< RFC 2136. Some name that ought not to
|
||||
* exist, does exist. */
|
||||
ARES_RCODE_YXRRSET = 7, /*!< RFC 2136. Some RRset that ought to not
|
||||
* exist, does exist. */
|
||||
ARES_RCODE_NXRRSET = 8, /*!< RFC 2136. Some RRset that ought to exist,
|
||||
* does not exist. */
|
||||
ARES_RCODE_NOTAUTH = 9, /*!< RFC 2136. The server is not authoritative
|
||||
* for the zone named in the Zone section.
|
||||
*/
|
||||
ARES_RCODE_NOTZONE = 10, /*!< RFC 2136. A name used in the Prerequisite
|
||||
* or Update Section is not within the zone
|
||||
* denoted by the Zone Section. */
|
||||
ARES_RCODE_DSOTYPEI = 11, /*!< RFC 8409. DSO-TYPE Not implemented */
|
||||
ARES_RCODE_BADSIG = 16, /*!< RFC 8945. TSIG Signature Failure */
|
||||
ARES_RCODE_BADKEY = 17, /*!< RFC 8945. Key not recognized. */
|
||||
ARES_RCODE_BADTIME = 18, /*!< RFC 8945. Signature out of time window. */
|
||||
ARES_RCODE_BADMODE = 19, /*!< RFC 2930. Bad TKEY Mode */
|
||||
ARES_RCODE_BADNAME = 20, /*!< RFC 2930. Duplicate Key Name */
|
||||
ARES_RCODE_BADALG = 21, /*!< RFC 2930. Algorithm not supported */
|
||||
ARES_RCODE_BADTRUNC = 22, /*!< RFC 8945. Bad Truncation */
|
||||
ARES_RCODE_BADCOOKIE = 23, /*!< RVC 7973. Bad/missing Server Cookie */
|
||||
} ares_dns_rcode_t;
|
||||
|
||||
/*! Data types used */
|
||||
typedef enum {
|
||||
ARES_DATATYPE_INADDR = 1, /*!< struct in_addr * type */
|
||||
ARES_DATATYPE_INADDR6 = 2, /*!< struct ares_in6_addr * type */
|
||||
ARES_DATATYPE_U8 = 3, /*!< 8bit unsigned integer */
|
||||
ARES_DATATYPE_U16 = 4, /*!< 16bit unsigned integer */
|
||||
ARES_DATATYPE_U32 = 5, /*!< 32bit unsigned integer */
|
||||
ARES_DATATYPE_NAME = 6, /*!< Null-terminated string of a domain name */
|
||||
ARES_DATATYPE_STR = 7, /*!< Null-terminated string */
|
||||
ARES_DATATYPE_BIN = 8, /*!< Binary data */
|
||||
ARES_DATATYPE_BINP = 9, /*!< Officially defined as binary data, but likely
|
||||
* printable. Guaranteed to have a NULL
|
||||
* terminator for convenience (not included in
|
||||
* length) */
|
||||
ARES_DATATYPE_OPT = 10, /*!< Array of options. 16bit identifier, BIN
|
||||
* data. */
|
||||
} ares_dns_datatype_t;
|
||||
|
||||
/*! Keys used for all RR Types. We take the record type and multiply by 100
|
||||
* to ensure we have a proper offset between keys so we can keep these sorted
|
||||
*/
|
||||
typedef enum {
|
||||
/*! A Record. Address. Datatype: INADDR */
|
||||
ARES_RR_A_ADDR = (ARES_REC_TYPE_A * 100) + 1,
|
||||
/*! NS Record. Name. Datatype: NAME */
|
||||
ARES_RR_NS_NSDNAME = (ARES_REC_TYPE_NS * 100) + 1,
|
||||
/*! CNAME Record. CName. Datatype: NAME */
|
||||
ARES_RR_CNAME_CNAME = (ARES_REC_TYPE_CNAME * 100) + 1,
|
||||
/*! SOA Record. MNAME, Primary Source of Data. Datatype: NAME */
|
||||
ARES_RR_SOA_MNAME = (ARES_REC_TYPE_SOA * 100) + 1,
|
||||
/*! SOA Record. RNAME, Mailbox of person responsible. Datatype: NAME */
|
||||
ARES_RR_SOA_RNAME = (ARES_REC_TYPE_SOA * 100) + 2,
|
||||
/*! SOA Record. Serial, version. Datatype: U32 */
|
||||
ARES_RR_SOA_SERIAL = (ARES_REC_TYPE_SOA * 100) + 3,
|
||||
/*! SOA Record. Refresh, zone refersh interval. Datatype: U32 */
|
||||
ARES_RR_SOA_REFRESH = (ARES_REC_TYPE_SOA * 100) + 4,
|
||||
/*! SOA Record. Retry, failed refresh retry interval. Datatype: U32 */
|
||||
ARES_RR_SOA_RETRY = (ARES_REC_TYPE_SOA * 100) + 5,
|
||||
/*! SOA Record. Expire, upper limit on authority. Datatype: U32 */
|
||||
ARES_RR_SOA_EXPIRE = (ARES_REC_TYPE_SOA * 100) + 6,
|
||||
/*! SOA Record. Minimum, RR TTL. Datatype: U32 */
|
||||
ARES_RR_SOA_MINIMUM = (ARES_REC_TYPE_SOA * 100) + 7,
|
||||
/*! PTR Record. DNAME, pointer domain. Datatype: NAME */
|
||||
ARES_RR_PTR_DNAME = (ARES_REC_TYPE_PTR * 100) + 1,
|
||||
/*! HINFO Record. CPU. Datatype: STR */
|
||||
ARES_RR_HINFO_CPU = (ARES_REC_TYPE_HINFO * 100) + 1,
|
||||
/*! HINFO Record. OS. Datatype: STR */
|
||||
ARES_RR_HINFO_OS = (ARES_REC_TYPE_HINFO * 100) + 2,
|
||||
/*! MX Record. Preference. Datatype: U16 */
|
||||
ARES_RR_MX_PREFERENCE = (ARES_REC_TYPE_MX * 100) + 1,
|
||||
/*! MX Record. Exchange, domain. Datatype: NAME */
|
||||
ARES_RR_MX_EXCHANGE = (ARES_REC_TYPE_MX * 100) + 2,
|
||||
/*! TXT Record. Data. Datatype: BINP */
|
||||
ARES_RR_TXT_DATA = (ARES_REC_TYPE_TXT * 100) + 1,
|
||||
/*! AAAA Record. Address. Datatype: INADDR6 */
|
||||
ARES_RR_AAAA_ADDR = (ARES_REC_TYPE_AAAA * 100) + 1,
|
||||
/*! SRV Record. Priority. Datatype: U16 */
|
||||
ARES_RR_SRV_PRIORITY = (ARES_REC_TYPE_SRV * 100) + 2,
|
||||
/*! SRV Record. Weight. Datatype: U16 */
|
||||
ARES_RR_SRV_WEIGHT = (ARES_REC_TYPE_SRV * 100) + 3,
|
||||
/*! SRV Record. Port. Datatype: U16 */
|
||||
ARES_RR_SRV_PORT = (ARES_REC_TYPE_SRV * 100) + 4,
|
||||
/*! SRV Record. Target domain. Datatype: NAME */
|
||||
ARES_RR_SRV_TARGET = (ARES_REC_TYPE_SRV * 100) + 5,
|
||||
/*! NAPTR Record. Order. Datatype: U16 */
|
||||
ARES_RR_NAPTR_ORDER = (ARES_REC_TYPE_NAPTR * 100) + 1,
|
||||
/*! NAPTR Record. Preference. Datatype: U16 */
|
||||
ARES_RR_NAPTR_PREFERENCE = (ARES_REC_TYPE_NAPTR * 100) + 2,
|
||||
/*! NAPTR Record. Flags. Datatype: STR */
|
||||
ARES_RR_NAPTR_FLAGS = (ARES_REC_TYPE_NAPTR * 100) + 3,
|
||||
/*! NAPTR Record. Services. Datatype: STR */
|
||||
ARES_RR_NAPTR_SERVICES = (ARES_REC_TYPE_NAPTR * 100) + 4,
|
||||
/*! NAPTR Record. Regexp. Datatype: STR */
|
||||
ARES_RR_NAPTR_REGEXP = (ARES_REC_TYPE_NAPTR * 100) + 5,
|
||||
/*! NAPTR Record. Replacement. Datatype: NAME */
|
||||
ARES_RR_NAPTR_REPLACEMENT = (ARES_REC_TYPE_NAPTR * 100) + 6,
|
||||
/*! OPT Record. UDP Size. Datatype: U16 */
|
||||
ARES_RR_OPT_UDP_SIZE = (ARES_REC_TYPE_OPT * 100) + 1,
|
||||
/*! OPT Record. Version. Datatype: U8 */
|
||||
ARES_RR_OPT_VERSION = (ARES_REC_TYPE_OPT * 100) + 3,
|
||||
/*! OPT Record. Flags. Datatype: U16 */
|
||||
ARES_RR_OPT_FLAGS = (ARES_REC_TYPE_OPT * 100) + 4,
|
||||
/*! OPT Record. Options. Datatype: OPT */
|
||||
ARES_RR_OPT_OPTIONS = (ARES_REC_TYPE_OPT * 100) + 5,
|
||||
/*! TLSA Record. Certificate Usage. Datatype: U8 */
|
||||
ARES_RR_TLSA_CERT_USAGE = (ARES_REC_TYPE_TLSA * 100) + 1,
|
||||
/*! TLSA Record. Selector. Datatype: U8 */
|
||||
ARES_RR_TLSA_SELECTOR = (ARES_REC_TYPE_TLSA * 100) + 2,
|
||||
/*! TLSA Record. Matching Type. Datatype: U8 */
|
||||
ARES_RR_TLSA_MATCH = (ARES_REC_TYPE_TLSA * 100) + 3,
|
||||
/*! TLSA Record. Certificate Association Data. Datatype: BIN */
|
||||
ARES_RR_TLSA_DATA = (ARES_REC_TYPE_TLSA * 100) + 4,
|
||||
/*! SVCB Record. SvcPriority. Datatype: U16 */
|
||||
ARES_RR_SVCB_PRIORITY = (ARES_REC_TYPE_SVCB * 100) + 1,
|
||||
/*! SVCB Record. TargetName. Datatype: NAME */
|
||||
ARES_RR_SVCB_TARGET = (ARES_REC_TYPE_SVCB * 100) + 2,
|
||||
/*! SVCB Record. SvcParams. Datatype: OPT */
|
||||
ARES_RR_SVCB_PARAMS = (ARES_REC_TYPE_SVCB * 100) + 3,
|
||||
/*! HTTPS Record. SvcPriority. Datatype: U16 */
|
||||
ARES_RR_HTTPS_PRIORITY = (ARES_REC_TYPE_HTTPS * 100) + 1,
|
||||
/*! HTTPS Record. TargetName. Datatype: NAME */
|
||||
ARES_RR_HTTPS_TARGET = (ARES_REC_TYPE_HTTPS * 100) + 2,
|
||||
/*! HTTPS Record. SvcParams. Datatype: OPT */
|
||||
ARES_RR_HTTPS_PARAMS = (ARES_REC_TYPE_HTTPS * 100) + 3,
|
||||
/*! URI Record. Priority. Datatype: U16 */
|
||||
ARES_RR_URI_PRIORITY = (ARES_REC_TYPE_URI * 100) + 1,
|
||||
/*! URI Record. Weight. Datatype: U16 */
|
||||
ARES_RR_URI_WEIGHT = (ARES_REC_TYPE_URI * 100) + 2,
|
||||
/*! URI Record. Target domain. Datatype: NAME */
|
||||
ARES_RR_URI_TARGET = (ARES_REC_TYPE_URI * 100) + 3,
|
||||
/*! CAA Record. Critical flag. Datatype: U8 */
|
||||
ARES_RR_CAA_CRITICAL = (ARES_REC_TYPE_CAA * 100) + 1,
|
||||
/*! CAA Record. Tag/Property. Datatype: STR */
|
||||
ARES_RR_CAA_TAG = (ARES_REC_TYPE_CAA * 100) + 2,
|
||||
/*! CAA Record. Value. Datatype: BINP */
|
||||
ARES_RR_CAA_VALUE = (ARES_REC_TYPE_CAA * 100) + 3,
|
||||
/*! RAW Record. RR Type. Datatype: U16 */
|
||||
ARES_RR_RAW_RR_TYPE = (ARES_REC_TYPE_RAW_RR * 100) + 1,
|
||||
/*! RAW Record. RR Data. Datatype: BIN */
|
||||
ARES_RR_RAW_RR_DATA = (ARES_REC_TYPE_RAW_RR * 100) + 2,
|
||||
} ares_dns_rr_key_t;
|
||||
|
||||
/*! TLSA Record ARES_RR_TLSA_CERT_USAGE known values */
|
||||
typedef enum {
|
||||
/*! Certificate Usage 0. CA Constraint. */
|
||||
ARES_TLSA_USAGE_CA = 0,
|
||||
/*! Certificate Usage 1. Service Certificate Constraint. */
|
||||
ARES_TLSA_USAGE_SERVICE = 1,
|
||||
/*! Certificate Usage 2. Trust Anchor Assertion. */
|
||||
ARES_TLSA_USAGE_TRUSTANCHOR = 2,
|
||||
/*! Certificate Usage 3. Domain-issued certificate. */
|
||||
ARES_TLSA_USAGE_DOMAIN = 3
|
||||
} ares_tlsa_usage_t;
|
||||
|
||||
/*! TLSA Record ARES_RR_TLSA_SELECTOR known values */
|
||||
typedef enum {
|
||||
/*! Full Certificate */
|
||||
ARES_TLSA_SELECTOR_FULL = 0,
|
||||
/*! DER-encoded SubjectPublicKeyInfo */
|
||||
ARES_TLSA_SELECTOR_SUBJPUBKEYINFO = 1
|
||||
} ares_tlsa_selector_t;
|
||||
|
||||
/*! TLSA Record ARES_RR_TLSA_MATCH known values */
|
||||
typedef enum {
|
||||
/*! Exact match */
|
||||
ARES_TLSA_MATCH_EXACT = 0,
|
||||
/*! Sha256 match */
|
||||
ARES_TLSA_MATCH_SHA256 = 1,
|
||||
/*! Sha512 match */
|
||||
ARES_TLSA_MATCH_SHA512 = 2
|
||||
} ares_tlsa_match_t;
|
||||
|
||||
/*! SVCB (and HTTPS) RR known parameters */
|
||||
typedef enum {
|
||||
/*! Mandatory keys in this RR (RFC 9460 Section 8) */
|
||||
ARES_SVCB_PARAM_MANDATORY = 0,
|
||||
/*! Additional supported protocols (RFC 9460 Section 7.1) */
|
||||
ARES_SVCB_PARAM_ALPN = 1,
|
||||
/*! No support for default protocol (RFC 9460 Section 7.1) */
|
||||
ARES_SVCB_PARAM_NO_DEFAULT_ALPN = 2,
|
||||
/*! Port for alternative endpoint (RFC 9460 Section 7.2) */
|
||||
ARES_SVCB_PARAM_PORT = 3,
|
||||
/*! IPv4 address hints (RFC 9460 Section 7.3) */
|
||||
ARES_SVCB_PARAM_IPV4HINT = 4,
|
||||
/*! RESERVED (held for Encrypted ClientHello) */
|
||||
ARES_SVCB_PARAM_ECH = 5,
|
||||
/*! IPv6 address hints (RFC 9460 Section 7.3) */
|
||||
ARES_SVCB_PARAM_IPV6HINT = 6
|
||||
} ares_svcb_param_t;
|
||||
|
||||
/*! OPT RR known parameters */
|
||||
typedef enum {
|
||||
/*! RFC 8764. Apple's DNS Long-Lived Queries Protocol */
|
||||
ARES_OPT_PARAM_LLQ = 1,
|
||||
/*! http://files.dns-sd.org/draft-sekar-dns-ul.txt: Update Lease */
|
||||
ARES_OPT_PARAM_UL = 2,
|
||||
/*! RFC 5001. Name Server Identification */
|
||||
ARES_OPT_PARAM_NSID = 3,
|
||||
/*! RFC 6975. DNSSEC Algorithm Understood */
|
||||
ARES_OPT_PARAM_DAU = 5,
|
||||
/*! RFC 6975. DS Hash Understood */
|
||||
ARES_OPT_PARAM_DHU = 6,
|
||||
/*! RFC 6975. NSEC3 Hash Understood */
|
||||
ARES_OPT_PARAM_N3U = 7,
|
||||
/*! RFC 7871. Client Subnet */
|
||||
ARES_OPT_PARAM_EDNS_CLIENT_SUBNET = 8,
|
||||
/*! RFC 7314. Expire Timer */
|
||||
ARES_OPT_PARAM_EDNS_EXPIRE = 9,
|
||||
/*! RFC 7873. Client and Server Cookies */
|
||||
ARES_OPT_PARAM_COOKIE = 10,
|
||||
/*! RFC 7828. TCP Keepalive timeout */
|
||||
ARES_OPT_PARAM_EDNS_TCP_KEEPALIVE = 11,
|
||||
/*! RFC 7830. Padding */
|
||||
ARES_OPT_PARAM_PADDING = 12,
|
||||
/*! RFC 7901. Chain query requests */
|
||||
ARES_OPT_PARAM_CHAIN = 13,
|
||||
/*! RFC 8145. Signaling Trust Anchor Knowledge in DNSSEC */
|
||||
ARES_OPT_PARAM_EDNS_KEY_TAG = 14,
|
||||
/*! RFC 8914. Extended ERROR code and message */
|
||||
ARES_OPT_PARAM_EXTENDED_DNS_ERROR = 15,
|
||||
} ares_opt_param_t;
|
||||
|
||||
/*! Data type for option records for keys like ARES_RR_OPT_OPTIONS and
|
||||
* ARES_RR_HTTPS_PARAMS returned by ares_dns_opt_get_datatype() */
|
||||
typedef enum {
|
||||
/*! No value allowed for this option */
|
||||
ARES_OPT_DATATYPE_NONE = 1,
|
||||
/*! List of strings, each prefixed with a single octet representing the length
|
||||
*/
|
||||
ARES_OPT_DATATYPE_STR_LIST = 2,
|
||||
/*! List of 8bit integers, concatenated */
|
||||
ARES_OPT_DATATYPE_U8_LIST = 3,
|
||||
/*! 16bit integer in network byte order */
|
||||
ARES_OPT_DATATYPE_U16 = 4,
|
||||
/*! list of 16bit integer in network byte order, concatenated. */
|
||||
ARES_OPT_DATATYPE_U16_LIST = 5,
|
||||
/*! 32bit integer in network byte order */
|
||||
ARES_OPT_DATATYPE_U32 = 6,
|
||||
/*! list 32bit integer in network byte order, concatenated */
|
||||
ARES_OPT_DATATYPE_U32_LIST = 7,
|
||||
/*! List of ipv4 addresses in network byte order, concatenated */
|
||||
ARES_OPT_DATATYPE_INADDR4_LIST = 8,
|
||||
/*! List of ipv6 addresses in network byte order, concatenated */
|
||||
ARES_OPT_DATATYPE_INADDR6_LIST = 9,
|
||||
/*! Binary Data */
|
||||
ARES_OPT_DATATYPE_BIN = 10,
|
||||
/*! DNS Domain Name Format */
|
||||
ARES_OPT_DATATYPE_NAME = 11
|
||||
} ares_dns_opt_datatype_t;
|
||||
|
||||
/*! Data type for flags to ares_dns_parse() */
|
||||
typedef enum {
|
||||
/*! Parse Answers from RFC 1035 that allow name compression as RAW */
|
||||
ARES_DNS_PARSE_AN_BASE_RAW = 1 << 0,
|
||||
/*! Parse Authority from RFC 1035 that allow name compression as RAW */
|
||||
ARES_DNS_PARSE_NS_BASE_RAW = 1 << 1,
|
||||
/*! Parse Additional from RFC 1035 that allow name compression as RAW */
|
||||
ARES_DNS_PARSE_AR_BASE_RAW = 1 << 2,
|
||||
/*! Parse Answers from later RFCs (no name compression) RAW */
|
||||
ARES_DNS_PARSE_AN_EXT_RAW = 1 << 3,
|
||||
/*! Parse Authority from later RFCs (no name compression) as RAW */
|
||||
ARES_DNS_PARSE_NS_EXT_RAW = 1 << 4,
|
||||
/*< Parse Additional from later RFCs (no name compression) as RAW */
|
||||
ARES_DNS_PARSE_AR_EXT_RAW = 1 << 5
|
||||
} ares_dns_parse_flags_t;
|
||||
|
||||
/*! String representation of DNS Record Type
|
||||
*
|
||||
* \param[in] type DNS Record Type
|
||||
* \return string
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_rec_type_tostr(ares_dns_rec_type_t type);
|
||||
|
||||
/*! String representation of DNS Class
|
||||
*
|
||||
* \param[in] qclass DNS Class
|
||||
* \return string
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_class_tostr(ares_dns_class_t qclass);
|
||||
|
||||
/*! String representation of DNS OpCode
|
||||
*
|
||||
* \param[in] opcode DNS OpCode
|
||||
* \return string
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_opcode_tostr(ares_dns_opcode_t opcode);
|
||||
|
||||
/*! String representation of DNS Resource Record Parameter
|
||||
*
|
||||
* \param[in] key DNS Resource Record parameter
|
||||
* \return string
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_rr_key_tostr(ares_dns_rr_key_t key);
|
||||
|
||||
/*! String representation of DNS Resource Record section
|
||||
*
|
||||
* \param[in] section Section
|
||||
* \return string
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_section_tostr(ares_dns_section_t section);
|
||||
|
||||
/*! Convert DNS class name as string to ares_dns_class_t
|
||||
*
|
||||
* \param[out] qclass Pointer passed by reference to write class
|
||||
* \param[in] str String to convert
|
||||
* \return ARES_TRUE on success
|
||||
*/
|
||||
CARES_EXTERN ares_bool_t ares_dns_class_fromstr(ares_dns_class_t *qclass,
|
||||
const char *str);
|
||||
|
||||
/*! Convert DNS record type as string to ares_dns_rec_type_t
|
||||
*
|
||||
* \param[out] qtype Pointer passed by reference to write record type
|
||||
* \param[in] str String to convert
|
||||
* \return ARES_TRUE on success
|
||||
*/
|
||||
CARES_EXTERN ares_bool_t ares_dns_rec_type_fromstr(ares_dns_rec_type_t *qtype,
|
||||
const char *str);
|
||||
|
||||
|
||||
/*! Convert DNS response code as string to from ares_dns_rcode_t
|
||||
*
|
||||
* \param[in] rcode Response code to convert
|
||||
* \return ARES_TRUE on success
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_rcode_tostr(ares_dns_rcode_t rcode);
|
||||
|
||||
/*! Convert any valid ip address (ipv4 or ipv6) into struct ares_addr and
|
||||
* return the starting pointer of the network byte order address and the
|
||||
* length of the address (4 or 16).
|
||||
*
|
||||
* \param[in] ipaddr ASCII string form of the ip address
|
||||
* \param[in,out] addr Must set "family" member to one of AF_UNSPEC,
|
||||
* AF_INET, AF_INET6 on input.
|
||||
* \param[out] ptr_len Length of binary form address
|
||||
* \return Pointer to start of binary address or NULL on error.
|
||||
*/
|
||||
CARES_EXTERN const void *ares_dns_pton(const char *ipaddr,
|
||||
struct ares_addr *addr, size_t *out_len);
|
||||
|
||||
/*! Convert an ip address into the PTR format for in-addr.arpa or in6.arpa
|
||||
*
|
||||
* \param[in] addr properly filled address structure
|
||||
* \return String representing PTR, use ares_free_string() to free
|
||||
*/
|
||||
CARES_EXTERN char *ares_dns_addr_to_ptr(const struct ares_addr *addr);
|
||||
|
||||
|
||||
/*! The options/parameters extensions to some RRs can be somewhat opaque, this
|
||||
* is a helper to return the best match for a datatype for interpreting the
|
||||
* option record.
|
||||
*
|
||||
* \param[in] key Key associated with options/parameters
|
||||
* \param[in] opt Option Key/Parameter
|
||||
* \return Datatype
|
||||
*/
|
||||
CARES_EXTERN ares_dns_opt_datatype_t
|
||||
ares_dns_opt_get_datatype(ares_dns_rr_key_t key, unsigned short opt);
|
||||
|
||||
/*! The options/parameters extensions to some RRs can be somewhat opaque, this
|
||||
* is a helper to return the name if the option is known.
|
||||
*
|
||||
* \param[in] key Key associated with options/parameters
|
||||
* \param[in] opt Option Key/Parameter
|
||||
* \return name, or NULL if not known.
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_opt_get_name(ares_dns_rr_key_t key,
|
||||
unsigned short opt);
|
||||
|
||||
|
||||
/*! Retrieve a list of Resource Record keys that can be set or retrieved for
|
||||
* the Resource record type.
|
||||
*
|
||||
* \param[in] type Record Type
|
||||
* \param[out] cnt Number of keys returned
|
||||
* \return array of keys associated with Resource Record
|
||||
*/
|
||||
CARES_EXTERN const ares_dns_rr_key_t *
|
||||
ares_dns_rr_get_keys(ares_dns_rec_type_t type, size_t *cnt);
|
||||
|
||||
/*! Retrieve the datatype associated with a Resource Record key.
|
||||
*
|
||||
* \param[in] key Resource Record Key
|
||||
* \return datatype
|
||||
*/
|
||||
CARES_EXTERN ares_dns_datatype_t
|
||||
ares_dns_rr_key_datatype(ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve the DNS Resource Record type associated with a Resource Record key.
|
||||
*
|
||||
* \param[in] key Resource Record Key
|
||||
* \return DNS Resource Record Type
|
||||
*/
|
||||
CARES_EXTERN ares_dns_rec_type_t
|
||||
ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key);
|
||||
|
||||
/*! Opaque data type representing a DNS RR (Resource Record) */
|
||||
struct ares_dns_rr;
|
||||
|
||||
/*! Typedef for opaque data type representing a DNS RR (Resource Record) */
|
||||
typedef struct ares_dns_rr ares_dns_rr_t;
|
||||
|
||||
/*! Opaque data type representing a DNS Query Data QD Packet */
|
||||
struct ares_dns_qd;
|
||||
|
||||
/*! Typedef for opaque data type representing a DNS Query Data QD Packet */
|
||||
typedef struct ares_dns_qd ares_dns_qd_t;
|
||||
|
||||
/*! Opaque data type representing a DNS Packet */
|
||||
struct ares_dns_record;
|
||||
|
||||
/*! Typedef for opaque data type representing a DNS Packet */
|
||||
typedef struct ares_dns_record ares_dns_record_t;
|
||||
|
||||
|
||||
/*! Create a new DNS record object
|
||||
*
|
||||
* \param[out] dnsrec Pointer passed by reference for a newly allocated
|
||||
* record object. Must be ares_dns_record_destroy()'d by
|
||||
* caller.
|
||||
* \param[in] id DNS Query ID. If structuring a new query to be sent
|
||||
* with ares_send(), this value should be zero.
|
||||
* \param[in] flags DNS Flags from \ares_dns_flags_t
|
||||
* \param[in] opcode DNS OpCode (typically ARES_OPCODE_QUERY)
|
||||
* \param[in] rcode DNS RCode
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_record_create(ares_dns_record_t **dnsrec,
|
||||
unsigned short id,
|
||||
unsigned short flags,
|
||||
ares_dns_opcode_t opcode,
|
||||
ares_dns_rcode_t rcode);
|
||||
|
||||
/*! Destroy a DNS record object
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
*/
|
||||
CARES_EXTERN void ares_dns_record_destroy(ares_dns_record_t *dnsrec);
|
||||
|
||||
/*! Get the DNS Query ID
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \return DNS query id
|
||||
*/
|
||||
CARES_EXTERN unsigned short
|
||||
ares_dns_record_get_id(const ares_dns_record_t *dnsrec);
|
||||
|
||||
/*! Get the DNS Record Flags
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \return One or more \ares_dns_flags_t
|
||||
*/
|
||||
CARES_EXTERN unsigned short
|
||||
ares_dns_record_get_flags(const ares_dns_record_t *dnsrec);
|
||||
|
||||
/*! Get the DNS Record OpCode
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \return opcode
|
||||
*/
|
||||
CARES_EXTERN ares_dns_opcode_t
|
||||
ares_dns_record_get_opcode(const ares_dns_record_t *dnsrec);
|
||||
|
||||
/*! Get the DNS Record RCode
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \return rcode
|
||||
*/
|
||||
CARES_EXTERN ares_dns_rcode_t
|
||||
ares_dns_record_get_rcode(const ares_dns_record_t *dnsrec);
|
||||
|
||||
/*! Add a query to the DNS Record. Typically a record will have only 1
|
||||
* query. Most DNS servers will reject queries with more than 1 question.
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \param[in] name Name/Hostname of request
|
||||
* \param[in] qtype Type of query
|
||||
* \param[in] qclass Class of query (typically ARES_CLASS_IN)
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_record_query_add(ares_dns_record_t *dnsrec,
|
||||
const char *name,
|
||||
ares_dns_rec_type_t qtype,
|
||||
ares_dns_class_t qclass);
|
||||
|
||||
/*! Get the count of queries in the DNS Record
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \return count of queries
|
||||
*/
|
||||
CARES_EXTERN size_t ares_dns_record_query_cnt(const ares_dns_record_t *dnsrec);
|
||||
|
||||
/*! Get the data about the query at the provided index.
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \param[in] idx Index of query
|
||||
* \param[out] name Optional. Returns name, may pass NULL if not desired.
|
||||
* \param[out] qtype Optional. Returns record type, may pass NULL.
|
||||
* \param[out] qclass Optional. Returns class, may pass NULL.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_record_query_get(
|
||||
const ares_dns_record_t *dnsrec, size_t idx, const char **name,
|
||||
ares_dns_rec_type_t *qtype, ares_dns_class_t *qclass);
|
||||
|
||||
/*! Get the count of Resource Records in the provided section
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \param[in] sect Section. ARES_SECTION_ANSWER is most used.
|
||||
* \return count of resource records.
|
||||
*/
|
||||
CARES_EXTERN size_t ares_dns_record_rr_cnt(const ares_dns_record_t *dnsrec,
|
||||
ares_dns_section_t sect);
|
||||
|
||||
|
||||
/*! Add a Resource Record to the DNS Record.
|
||||
*
|
||||
* \param[out] rr_out Pointer to created resource record. This pointer
|
||||
* is owned by the DNS record itself, this is just made
|
||||
* available to facilitate adding RR-specific fields.
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \param[in] sect Section to add resource record to
|
||||
* \param[in] name Resource Record name/hostname
|
||||
* \param[in] type Record Type
|
||||
* \param[in] rclass Class
|
||||
* \param[in] ttl TTL
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_record_rr_add(
|
||||
ares_dns_rr_t **rr_out, ares_dns_record_t *dnsrec, ares_dns_section_t sect,
|
||||
const char *name, ares_dns_rec_type_t type, ares_dns_class_t rclass,
|
||||
unsigned int ttl);
|
||||
|
||||
/*! Fetch a resource record based on the section and index.
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \param[in] sect Section for resource record
|
||||
* \param[in] idx Index of resource record in section
|
||||
* \return NULL on misuse, otherwise a pointer to the resource record
|
||||
*/
|
||||
CARES_EXTERN ares_dns_rr_t *ares_dns_record_rr_get(ares_dns_record_t *dnsrec,
|
||||
ares_dns_section_t sect,
|
||||
size_t idx);
|
||||
|
||||
|
||||
/*! Remove the resource record based on the section and index
|
||||
*
|
||||
* \param[in] dnsrec Initialized record object
|
||||
* \param[in] sect Section for resource record
|
||||
* \param[in] idx Index of resource record in section
|
||||
* \return ARES_SUCCESS on success, otherwise an error code.
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_record_rr_del(ares_dns_record_t *dnsrec,
|
||||
ares_dns_section_t sect,
|
||||
size_t idx);
|
||||
|
||||
|
||||
/*! Retrieve the resource record Name/Hostname
|
||||
*
|
||||
* \param[in] rr Pointer to resource record
|
||||
* \return Name
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_rr_get_name(const ares_dns_rr_t *rr);
|
||||
|
||||
/*! Retrieve the resource record type
|
||||
*
|
||||
* \param[in] rr Pointer to resource record
|
||||
* \return type
|
||||
*/
|
||||
CARES_EXTERN ares_dns_rec_type_t ares_dns_rr_get_type(const ares_dns_rr_t *rr);
|
||||
|
||||
/*! Retrieve the resource record class
|
||||
*
|
||||
* \param[in] rr Pointer to resource record
|
||||
* \return class
|
||||
*/
|
||||
CARES_EXTERN ares_dns_class_t ares_dns_rr_get_class(const ares_dns_rr_t *rr);
|
||||
|
||||
/*! Retrieve the resource record TTL
|
||||
*
|
||||
* \param[in] rr Pointer to resource record
|
||||
* \return TTL
|
||||
*/
|
||||
CARES_EXTERN unsigned int ares_dns_rr_get_ttl(const ares_dns_rr_t *rr);
|
||||
|
||||
/*! Set ipv4 address data type for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_INADDR
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] addr Pointer to ipv4 address to use.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_addr(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
const struct in_addr *addr);
|
||||
|
||||
/*! Set ipv6 address data type for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_INADDR6
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] addr Pointer to ipv6 address to use.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t
|
||||
ares_dns_rr_set_addr6(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
|
||||
const struct ares_in6_addr *addr);
|
||||
|
||||
/*! Set string data for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_STR or ARES_DATATYPE_NAME.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] val Pointer to string to set.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_str(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
const char *val);
|
||||
|
||||
/*! Set 8bit unsigned integer for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_U8
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] val 8bit unsigned integer
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_u8(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
unsigned char val);
|
||||
|
||||
/*! Set 16bit unsigned integer for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_U16
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] val 16bit unsigned integer
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_u16(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
unsigned short val);
|
||||
|
||||
/*! Set 32bit unsigned integer for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_U32
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] val 32bit unsigned integer
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_u32(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
unsigned int val);
|
||||
|
||||
/*! Set binary (BIN or BINP) data for specified resource record and key. Can
|
||||
* only be used on keys with datatype ARES_DATATYPE_BIN or ARES_DATATYPE_BINP.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] val Pointer to binary data.
|
||||
* \param[in] len Length of binary data
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
const unsigned char *val,
|
||||
size_t len);
|
||||
|
||||
/*! Set the option for the RR
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] opt Option record key id.
|
||||
* \param[out] val Optional. Value to associate with option.
|
||||
* \param[out] val_len Length of value passed.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_rr_set_opt(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
unsigned short opt,
|
||||
const unsigned char *val,
|
||||
size_t val_len);
|
||||
|
||||
/*! Retrieve a pointer to the ipv4 address. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_INADDR.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return pointer to ipv4 address or NULL on error
|
||||
*/
|
||||
CARES_EXTERN const struct in_addr *
|
||||
ares_dns_rr_get_addr(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve a pointer to the ipv6 address. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_INADDR6.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return pointer to ipv6 address or NULL on error
|
||||
*/
|
||||
CARES_EXTERN const struct ares_in6_addr *
|
||||
ares_dns_rr_get_addr6(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve a pointer to the string. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_STR and ARES_DATATYPE_NAME.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return pointer string or NULL on error
|
||||
*/
|
||||
CARES_EXTERN const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve an 8bit unsigned integer. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_U8.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return 8bit unsigned integer
|
||||
*/
|
||||
CARES_EXTERN unsigned char ares_dns_rr_get_u8(const ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve an 16bit unsigned integer. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_U16.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return 16bit unsigned integer
|
||||
*/
|
||||
CARES_EXTERN unsigned short ares_dns_rr_get_u16(const ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve an 32bit unsigned integer. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_U32.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return 32bit unsigned integer
|
||||
*/
|
||||
CARES_EXTERN unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve a pointer to the binary data. Can only be used on keys with
|
||||
* datatype ARES_DATATYPE_BIN or ARES_DATATYPE_BINP. If BINP, the data is
|
||||
* guaranteed to have a NULL terminator which is NOT included in the length.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[out] len Length of binary data returned
|
||||
* \return pointer binary data or NULL on error
|
||||
*/
|
||||
CARES_EXTERN const unsigned char *
|
||||
ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
|
||||
size_t *len);
|
||||
|
||||
/*! Retrieve the number of options stored for the RR.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \return count, or 0 if none.
|
||||
*/
|
||||
CARES_EXTERN size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key);
|
||||
|
||||
/*! Retrieve the option for the RR by index.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] idx Index of option record
|
||||
* \param[out] val Optional. Pointer passed by reference to hold value.
|
||||
* Options may not have values. Value if returned is
|
||||
* guaranteed to be NULL terminated, however in most
|
||||
* cases it is not printable.
|
||||
* \param[out] val_len Optional. Pointer passed by reference to hold value
|
||||
* length.
|
||||
* \return option key/id on success, 65535 on misuse.
|
||||
*/
|
||||
CARES_EXTERN unsigned short
|
||||
ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
|
||||
size_t idx, const unsigned char **val, size_t *val_len);
|
||||
|
||||
/*! Retrieve the option for the RR by the option key/id.
|
||||
*
|
||||
* \param[in] dns_rr Pointer to resource record
|
||||
* \param[in] key DNS Resource Record Key
|
||||
* \param[in] opt Option record key id (this is not the index).
|
||||
* \param[out] val Optional. Pointer passed by reference to hold value.
|
||||
* Options may not have values. Value if returned is
|
||||
* guaranteed to be NULL terminated, however in most cases
|
||||
* it is not printable.
|
||||
* \param[out] val_len Optional. Pointer passed by reference to hold value
|
||||
* length.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on misuse.
|
||||
*/
|
||||
CARES_EXTERN ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key,
|
||||
unsigned short opt,
|
||||
const unsigned char **val,
|
||||
size_t *val_len);
|
||||
|
||||
/*! Parse a complete DNS message.
|
||||
*
|
||||
* \param[in] buf pointer to bytes to be parsed
|
||||
* \param[in] buf_len Length of buf provided
|
||||
* \param[in] flags Flags dictating how the message should be parsed.
|
||||
* \param[out] dnsrec Pointer passed by reference for a new DNS record object
|
||||
* that must be ares_dns_record_destroy()'d by caller.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_parse(const unsigned char *buf,
|
||||
size_t buf_len, unsigned int flags,
|
||||
ares_dns_record_t **dnsrec);
|
||||
|
||||
/*! Write a complete DNS message
|
||||
*
|
||||
* \param[in] dnsrec Pointer to initialized and filled DNS record object.
|
||||
* \param[out] buf Pointer passed by reference to be filled in with with
|
||||
* DNS message. Must be ares_free()'d by caller.
|
||||
* \param[out] buf_len Length of returned buffer containing DNS message.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
CARES_EXTERN ares_status_t ares_dns_write(ares_dns_record_t *dnsrec,
|
||||
unsigned char **buf, size_t *buf_len);
|
||||
/*! @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ARES_DNS_RECORD_H */
|
||||
404
src/third_party/cares/dist/include/ares_nameser.h
vendored
404
src/third_party/cares/dist/include/ares_nameser.h
vendored
@ -1,3 +1,29 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) Massachusetts Institute of Technology
|
||||
* Copyright (c) Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef ARES_NAMESER_H
|
||||
#define ARES_NAMESER_H
|
||||
@ -18,51 +44,51 @@
|
||||
*/
|
||||
|
||||
#ifndef NS_PACKETSZ
|
||||
# define NS_PACKETSZ 512 /* maximum packet size */
|
||||
# define NS_PACKETSZ 512 /* maximum packet size */
|
||||
#endif
|
||||
|
||||
#ifndef NS_MAXDNAME
|
||||
# define NS_MAXDNAME 256 /* maximum domain name */
|
||||
# define NS_MAXDNAME 256 /* maximum domain name */
|
||||
#endif
|
||||
|
||||
#ifndef NS_MAXCDNAME
|
||||
# define NS_MAXCDNAME 255 /* maximum compressed domain name */
|
||||
# define NS_MAXCDNAME 255 /* maximum compressed domain name */
|
||||
#endif
|
||||
|
||||
#ifndef NS_MAXLABEL
|
||||
# define NS_MAXLABEL 63
|
||||
# define NS_MAXLABEL 63
|
||||
#endif
|
||||
|
||||
#ifndef NS_HFIXEDSZ
|
||||
# define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */
|
||||
# define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */
|
||||
#endif
|
||||
|
||||
#ifndef NS_QFIXEDSZ
|
||||
# define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */
|
||||
# define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */
|
||||
#endif
|
||||
|
||||
#ifndef NS_RRFIXEDSZ
|
||||
# define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
|
||||
# define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
|
||||
#endif
|
||||
|
||||
#ifndef NS_INT16SZ
|
||||
# define NS_INT16SZ 2
|
||||
# define NS_INT16SZ 2
|
||||
#endif
|
||||
|
||||
#ifndef NS_INADDRSZ
|
||||
# define NS_INADDRSZ 4
|
||||
# define NS_INADDRSZ 4
|
||||
#endif
|
||||
|
||||
#ifndef NS_IN6ADDRSZ
|
||||
# define NS_IN6ADDRSZ 16
|
||||
# define NS_IN6ADDRSZ 16
|
||||
#endif
|
||||
|
||||
#ifndef NS_CMPRSFLGS
|
||||
# define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */
|
||||
# define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */
|
||||
#endif
|
||||
|
||||
#ifndef NS_DEFAULTPORT
|
||||
# define NS_DEFAULTPORT 53 /* For both TCP and UDP. */
|
||||
# define NS_DEFAULTPORT 53 /* For both TCP and UDP. */
|
||||
#endif
|
||||
|
||||
/* ============================================================================
|
||||
@ -73,106 +99,106 @@
|
||||
#ifndef CARES_HAVE_ARPA_NAMESER_H
|
||||
|
||||
typedef enum __ns_class {
|
||||
ns_c_invalid = 0, /* Cookie. */
|
||||
ns_c_in = 1, /* Internet. */
|
||||
ns_c_2 = 2, /* unallocated/unsupported. */
|
||||
ns_c_chaos = 3, /* MIT Chaos-net. */
|
||||
ns_c_hs = 4, /* MIT Hesiod. */
|
||||
/* Query class values which do not appear in resource records */
|
||||
ns_c_none = 254, /* for prereq. sections in update requests */
|
||||
ns_c_any = 255, /* Wildcard match. */
|
||||
ns_c_max = 65536
|
||||
ns_c_invalid = 0, /* Cookie. */
|
||||
ns_c_in = 1, /* Internet. */
|
||||
ns_c_2 = 2, /* unallocated/unsupported. */
|
||||
ns_c_chaos = 3, /* MIT Chaos-net. */
|
||||
ns_c_hs = 4, /* MIT Hesiod. */
|
||||
/* Query class values which do not appear in resource records */
|
||||
ns_c_none = 254, /* for prereq. sections in update requests */
|
||||
ns_c_any = 255, /* Wildcard match. */
|
||||
ns_c_max = 65536
|
||||
} ns_class;
|
||||
|
||||
typedef enum __ns_type {
|
||||
ns_t_invalid = 0, /* Cookie. */
|
||||
ns_t_a = 1, /* Host address. */
|
||||
ns_t_ns = 2, /* Authoritative server. */
|
||||
ns_t_md = 3, /* Mail destination. */
|
||||
ns_t_mf = 4, /* Mail forwarder. */
|
||||
ns_t_cname = 5, /* Canonical name. */
|
||||
ns_t_soa = 6, /* Start of authority zone. */
|
||||
ns_t_mb = 7, /* Mailbox domain name. */
|
||||
ns_t_mg = 8, /* Mail group member. */
|
||||
ns_t_mr = 9, /* Mail rename name. */
|
||||
ns_t_null = 10, /* Null resource record. */
|
||||
ns_t_wks = 11, /* Well known service. */
|
||||
ns_t_ptr = 12, /* Domain name pointer. */
|
||||
ns_t_hinfo = 13, /* Host information. */
|
||||
ns_t_minfo = 14, /* Mailbox information. */
|
||||
ns_t_mx = 15, /* Mail routing information. */
|
||||
ns_t_txt = 16, /* Text strings. */
|
||||
ns_t_rp = 17, /* Responsible person. */
|
||||
ns_t_afsdb = 18, /* AFS cell database. */
|
||||
ns_t_x25 = 19, /* X_25 calling address. */
|
||||
ns_t_isdn = 20, /* ISDN calling address. */
|
||||
ns_t_rt = 21, /* Router. */
|
||||
ns_t_nsap = 22, /* NSAP address. */
|
||||
ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
|
||||
ns_t_sig = 24, /* Security signature. */
|
||||
ns_t_key = 25, /* Security key. */
|
||||
ns_t_px = 26, /* X.400 mail mapping. */
|
||||
ns_t_gpos = 27, /* Geographical position (withdrawn). */
|
||||
ns_t_aaaa = 28, /* Ip6 Address. */
|
||||
ns_t_loc = 29, /* Location Information. */
|
||||
ns_t_nxt = 30, /* Next domain (security). */
|
||||
ns_t_eid = 31, /* Endpoint identifier. */
|
||||
ns_t_nimloc = 32, /* Nimrod Locator. */
|
||||
ns_t_srv = 33, /* Server Selection. */
|
||||
ns_t_atma = 34, /* ATM Address */
|
||||
ns_t_naptr = 35, /* Naming Authority PoinTeR */
|
||||
ns_t_kx = 36, /* Key Exchange */
|
||||
ns_t_cert = 37, /* Certification record */
|
||||
ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */
|
||||
ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */
|
||||
ns_t_sink = 40, /* Kitchen sink (experimentatl) */
|
||||
ns_t_opt = 41, /* EDNS0 option (meta-RR) */
|
||||
ns_t_apl = 42, /* Address prefix list (RFC3123) */
|
||||
ns_t_ds = 43, /* Delegation Signer (RFC4034) */
|
||||
ns_t_sshfp = 44, /* SSH Key Fingerprint (RFC4255) */
|
||||
ns_t_rrsig = 46, /* Resource Record Signature (RFC4034) */
|
||||
ns_t_nsec = 47, /* Next Secure (RFC4034) */
|
||||
ns_t_dnskey = 48, /* DNS Public Key (RFC4034) */
|
||||
ns_t_tkey = 249, /* Transaction key */
|
||||
ns_t_tsig = 250, /* Transaction signature. */
|
||||
ns_t_ixfr = 251, /* Incremental zone transfer. */
|
||||
ns_t_axfr = 252, /* Transfer zone of authority. */
|
||||
ns_t_mailb = 253, /* Transfer mailbox records. */
|
||||
ns_t_maila = 254, /* Transfer mail agent records. */
|
||||
ns_t_any = 255, /* Wildcard match. */
|
||||
ns_t_uri = 256, /* Uniform Resource Identifier (RFC7553) */
|
||||
ns_t_caa = 257, /* Certification Authority Authorization. */
|
||||
ns_t_max = 65536
|
||||
ns_t_invalid = 0, /* Cookie. */
|
||||
ns_t_a = 1, /* Host address. */
|
||||
ns_t_ns = 2, /* Authoritative server. */
|
||||
ns_t_md = 3, /* Mail destination. */
|
||||
ns_t_mf = 4, /* Mail forwarder. */
|
||||
ns_t_cname = 5, /* Canonical name. */
|
||||
ns_t_soa = 6, /* Start of authority zone. */
|
||||
ns_t_mb = 7, /* Mailbox domain name. */
|
||||
ns_t_mg = 8, /* Mail group member. */
|
||||
ns_t_mr = 9, /* Mail rename name. */
|
||||
ns_t_null = 10, /* Null resource record. */
|
||||
ns_t_wks = 11, /* Well known service. */
|
||||
ns_t_ptr = 12, /* Domain name pointer. */
|
||||
ns_t_hinfo = 13, /* Host information. */
|
||||
ns_t_minfo = 14, /* Mailbox information. */
|
||||
ns_t_mx = 15, /* Mail routing information. */
|
||||
ns_t_txt = 16, /* Text strings. */
|
||||
ns_t_rp = 17, /* Responsible person. */
|
||||
ns_t_afsdb = 18, /* AFS cell database. */
|
||||
ns_t_x25 = 19, /* X_25 calling address. */
|
||||
ns_t_isdn = 20, /* ISDN calling address. */
|
||||
ns_t_rt = 21, /* Router. */
|
||||
ns_t_nsap = 22, /* NSAP address. */
|
||||
ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
|
||||
ns_t_sig = 24, /* Security signature. */
|
||||
ns_t_key = 25, /* Security key. */
|
||||
ns_t_px = 26, /* X.400 mail mapping. */
|
||||
ns_t_gpos = 27, /* Geographical position (withdrawn). */
|
||||
ns_t_aaaa = 28, /* Ip6 Address. */
|
||||
ns_t_loc = 29, /* Location Information. */
|
||||
ns_t_nxt = 30, /* Next domain (security). */
|
||||
ns_t_eid = 31, /* Endpoint identifier. */
|
||||
ns_t_nimloc = 32, /* Nimrod Locator. */
|
||||
ns_t_srv = 33, /* Server Selection. */
|
||||
ns_t_atma = 34, /* ATM Address */
|
||||
ns_t_naptr = 35, /* Naming Authority PoinTeR */
|
||||
ns_t_kx = 36, /* Key Exchange */
|
||||
ns_t_cert = 37, /* Certification record */
|
||||
ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */
|
||||
ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */
|
||||
ns_t_sink = 40, /* Kitchen sink (experimental) */
|
||||
ns_t_opt = 41, /* EDNS0 option (meta-RR) */
|
||||
ns_t_apl = 42, /* Address prefix list (RFC3123) */
|
||||
ns_t_ds = 43, /* Delegation Signer (RFC4034) */
|
||||
ns_t_sshfp = 44, /* SSH Key Fingerprint (RFC4255) */
|
||||
ns_t_rrsig = 46, /* Resource Record Signature (RFC4034) */
|
||||
ns_t_nsec = 47, /* Next Secure (RFC4034) */
|
||||
ns_t_dnskey = 48, /* DNS Public Key (RFC4034) */
|
||||
ns_t_tkey = 249, /* Transaction key */
|
||||
ns_t_tsig = 250, /* Transaction signature. */
|
||||
ns_t_ixfr = 251, /* Incremental zone transfer. */
|
||||
ns_t_axfr = 252, /* Transfer zone of authority. */
|
||||
ns_t_mailb = 253, /* Transfer mailbox records. */
|
||||
ns_t_maila = 254, /* Transfer mail agent records. */
|
||||
ns_t_any = 255, /* Wildcard match. */
|
||||
ns_t_uri = 256, /* Uniform Resource Identifier (RFC7553) */
|
||||
ns_t_caa = 257, /* Certification Authority Authorization. */
|
||||
ns_t_max = 65536
|
||||
} ns_type;
|
||||
|
||||
typedef enum __ns_opcode {
|
||||
ns_o_query = 0, /* Standard query. */
|
||||
ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */
|
||||
ns_o_status = 2, /* Name server status query (unsupported). */
|
||||
/* Opcode 3 is undefined/reserved. */
|
||||
ns_o_notify = 4, /* Zone change notification. */
|
||||
ns_o_update = 5, /* Zone update message. */
|
||||
ns_o_max = 6
|
||||
ns_o_query = 0, /* Standard query. */
|
||||
ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */
|
||||
ns_o_status = 2, /* Name server status query (unsupported). */
|
||||
/* Opcode 3 is undefined/reserved. */
|
||||
ns_o_notify = 4, /* Zone change notification. */
|
||||
ns_o_update = 5, /* Zone update message. */
|
||||
ns_o_max = 6
|
||||
} ns_opcode;
|
||||
|
||||
typedef enum __ns_rcode {
|
||||
ns_r_noerror = 0, /* No error occurred. */
|
||||
ns_r_formerr = 1, /* Format error. */
|
||||
ns_r_servfail = 2, /* Server failure. */
|
||||
ns_r_nxdomain = 3, /* Name error. */
|
||||
ns_r_notimpl = 4, /* Unimplemented. */
|
||||
ns_r_refused = 5, /* Operation refused. */
|
||||
/* these are for BIND_UPDATE */
|
||||
ns_r_yxdomain = 6, /* Name exists */
|
||||
ns_r_yxrrset = 7, /* RRset exists */
|
||||
ns_r_nxrrset = 8, /* RRset does not exist */
|
||||
ns_r_notauth = 9, /* Not authoritative for zone */
|
||||
ns_r_notzone = 10, /* Zone of record different from zone section */
|
||||
ns_r_max = 11,
|
||||
/* The following are TSIG extended errors */
|
||||
ns_r_badsig = 16,
|
||||
ns_r_badkey = 17,
|
||||
ns_r_badtime = 18
|
||||
ns_r_noerror = 0, /* No error occurred. */
|
||||
ns_r_formerr = 1, /* Format error. */
|
||||
ns_r_servfail = 2, /* Server failure. */
|
||||
ns_r_nxdomain = 3, /* Name error. */
|
||||
ns_r_notimpl = 4, /* Unimplemented. */
|
||||
ns_r_refused = 5, /* Operation refused. */
|
||||
/* these are for BIND_UPDATE */
|
||||
ns_r_yxdomain = 6, /* Name exists */
|
||||
ns_r_yxrrset = 7, /* RRset exists */
|
||||
ns_r_nxrrset = 8, /* RRset does not exist */
|
||||
ns_r_notauth = 9, /* Not authoritative for zone */
|
||||
ns_r_notzone = 10, /* Zone of record different from zone section */
|
||||
ns_r_max = 11,
|
||||
/* The following are TSIG extended errors */
|
||||
ns_r_badsig = 16,
|
||||
ns_r_badkey = 17,
|
||||
ns_r_badtime = 18
|
||||
} ns_rcode;
|
||||
|
||||
#endif /* CARES_HAVE_ARPA_NAMESER_H */
|
||||
@ -186,45 +212,45 @@ typedef enum __ns_rcode {
|
||||
*/
|
||||
|
||||
#ifndef PACKETSZ
|
||||
# define PACKETSZ NS_PACKETSZ
|
||||
# define PACKETSZ NS_PACKETSZ
|
||||
#endif
|
||||
|
||||
#ifndef MAXDNAME
|
||||
# define MAXDNAME NS_MAXDNAME
|
||||
# define MAXDNAME NS_MAXDNAME
|
||||
#endif
|
||||
|
||||
#ifndef MAXCDNAME
|
||||
# define MAXCDNAME NS_MAXCDNAME
|
||||
# define MAXCDNAME NS_MAXCDNAME
|
||||
#endif
|
||||
|
||||
#ifndef MAXLABEL
|
||||
# define MAXLABEL NS_MAXLABEL
|
||||
# define MAXLABEL NS_MAXLABEL
|
||||
#endif
|
||||
|
||||
#ifndef HFIXEDSZ
|
||||
# define HFIXEDSZ NS_HFIXEDSZ
|
||||
# define HFIXEDSZ NS_HFIXEDSZ
|
||||
#endif
|
||||
|
||||
#ifndef QFIXEDSZ
|
||||
# define QFIXEDSZ NS_QFIXEDSZ
|
||||
# define QFIXEDSZ NS_QFIXEDSZ
|
||||
#endif
|
||||
|
||||
#ifndef RRFIXEDSZ
|
||||
# define RRFIXEDSZ NS_RRFIXEDSZ
|
||||
# define RRFIXEDSZ NS_RRFIXEDSZ
|
||||
#endif
|
||||
|
||||
#ifndef INDIR_MASK
|
||||
# define INDIR_MASK NS_CMPRSFLGS
|
||||
# define INDIR_MASK NS_CMPRSFLGS
|
||||
#endif
|
||||
|
||||
#ifndef NAMESERVER_PORT
|
||||
# define NAMESERVER_PORT NS_DEFAULTPORT
|
||||
# define NAMESERVER_PORT NS_DEFAULTPORT
|
||||
#endif
|
||||
|
||||
|
||||
/* opcodes */
|
||||
#ifndef O_QUERY
|
||||
# define O_QUERY 0 /* ns_o_query */
|
||||
# define O_QUERY 0 /* ns_o_query */
|
||||
#endif
|
||||
#ifndef O_IQUERY
|
||||
# define O_IQUERY 1 /* ns_o_iquery */
|
||||
@ -242,242 +268,242 @@ typedef enum __ns_rcode {
|
||||
|
||||
/* response codes */
|
||||
#ifndef SERVFAIL
|
||||
# define SERVFAIL ns_r_servfail
|
||||
# define SERVFAIL ns_r_servfail
|
||||
#endif
|
||||
#ifndef NOTIMP
|
||||
# define NOTIMP ns_r_notimpl
|
||||
# define NOTIMP ns_r_notimpl
|
||||
#endif
|
||||
#ifndef REFUSED
|
||||
# define REFUSED ns_r_refused
|
||||
# define REFUSED ns_r_refused
|
||||
#endif
|
||||
#if defined(_WIN32) && !defined(HAVE_ARPA_NAMESER_COMPAT_H) && defined(NOERROR)
|
||||
# undef NOERROR /* it seems this is already defined in winerror.h */
|
||||
#endif
|
||||
#ifndef NOERROR
|
||||
# define NOERROR ns_r_noerror
|
||||
# define NOERROR ns_r_noerror
|
||||
#endif
|
||||
#ifndef FORMERR
|
||||
# define FORMERR ns_r_formerr
|
||||
# define FORMERR ns_r_formerr
|
||||
#endif
|
||||
#ifndef NXDOMAIN
|
||||
# define NXDOMAIN ns_r_nxdomain
|
||||
# define NXDOMAIN ns_r_nxdomain
|
||||
#endif
|
||||
/* Non-standard response codes, use numeric values */
|
||||
#ifndef YXDOMAIN
|
||||
# define YXDOMAIN 6 /* ns_r_yxdomain */
|
||||
# define YXDOMAIN 6 /* ns_r_yxdomain */
|
||||
#endif
|
||||
#ifndef YXRRSET
|
||||
# define YXRRSET 7 /* ns_r_yxrrset */
|
||||
# define YXRRSET 7 /* ns_r_yxrrset */
|
||||
#endif
|
||||
#ifndef NXRRSET
|
||||
# define NXRRSET 8 /* ns_r_nxrrset */
|
||||
# define NXRRSET 8 /* ns_r_nxrrset */
|
||||
#endif
|
||||
#ifndef NOTAUTH
|
||||
# define NOTAUTH 9 /* ns_r_notauth */
|
||||
# define NOTAUTH 9 /* ns_r_notauth */
|
||||
#endif
|
||||
#ifndef NOTZONE
|
||||
# define NOTZONE 10 /* ns_r_notzone */
|
||||
# define NOTZONE 10 /* ns_r_notzone */
|
||||
#endif
|
||||
#ifndef TSIG_BADSIG
|
||||
# define TSIG_BADSIG 16 /* ns_r_badsig */
|
||||
# define TSIG_BADSIG 16 /* ns_r_badsig */
|
||||
#endif
|
||||
#ifndef TSIG_BADKEY
|
||||
# define TSIG_BADKEY 17 /* ns_r_badkey */
|
||||
# define TSIG_BADKEY 17 /* ns_r_badkey */
|
||||
#endif
|
||||
#ifndef TSIG_BADTIME
|
||||
# define TSIG_BADTIME 18 /* ns_r_badtime */
|
||||
# define TSIG_BADTIME 18 /* ns_r_badtime */
|
||||
#endif
|
||||
|
||||
|
||||
/* classes */
|
||||
#ifndef C_IN
|
||||
# define C_IN 1 /* ns_c_in */
|
||||
# define C_IN 1 /* ns_c_in */
|
||||
#endif
|
||||
#ifndef C_CHAOS
|
||||
# define C_CHAOS 3 /* ns_c_chaos */
|
||||
# define C_CHAOS 3 /* ns_c_chaos */
|
||||
#endif
|
||||
#ifndef C_HS
|
||||
# define C_HS 4 /* ns_c_hs */
|
||||
# define C_HS 4 /* ns_c_hs */
|
||||
#endif
|
||||
#ifndef C_NONE
|
||||
# define C_NONE 254 /* ns_c_none */
|
||||
# define C_NONE 254 /* ns_c_none */
|
||||
#endif
|
||||
#ifndef C_ANY
|
||||
# define C_ANY 255 /* ns_c_any */
|
||||
# define C_ANY 255 /* ns_c_any */
|
||||
#endif
|
||||
|
||||
|
||||
/* types */
|
||||
#ifndef T_A
|
||||
# define T_A 1 /* ns_t_a */
|
||||
# define T_A 1 /* ns_t_a */
|
||||
#endif
|
||||
#ifndef T_NS
|
||||
# define T_NS 2 /* ns_t_ns */
|
||||
# define T_NS 2 /* ns_t_ns */
|
||||
#endif
|
||||
#ifndef T_MD
|
||||
# define T_MD 3 /* ns_t_md */
|
||||
# define T_MD 3 /* ns_t_md */
|
||||
#endif
|
||||
#ifndef T_MF
|
||||
# define T_MF 4 /* ns_t_mf */
|
||||
# define T_MF 4 /* ns_t_mf */
|
||||
#endif
|
||||
#ifndef T_CNAME
|
||||
# define T_CNAME 5 /* ns_t_cname */
|
||||
# define T_CNAME 5 /* ns_t_cname */
|
||||
#endif
|
||||
#ifndef T_SOA
|
||||
# define T_SOA 6 /* ns_t_soa */
|
||||
# define T_SOA 6 /* ns_t_soa */
|
||||
#endif
|
||||
#ifndef T_MB
|
||||
# define T_MB 7 /* ns_t_mb */
|
||||
# define T_MB 7 /* ns_t_mb */
|
||||
#endif
|
||||
#ifndef T_MG
|
||||
# define T_MG 8 /* ns_t_mg */
|
||||
# define T_MG 8 /* ns_t_mg */
|
||||
#endif
|
||||
#ifndef T_MR
|
||||
# define T_MR 9 /* ns_t_mr */
|
||||
# define T_MR 9 /* ns_t_mr */
|
||||
#endif
|
||||
#ifndef T_NULL
|
||||
# define T_NULL 10 /* ns_t_null */
|
||||
# define T_NULL 10 /* ns_t_null */
|
||||
#endif
|
||||
#ifndef T_WKS
|
||||
# define T_WKS 11 /* ns_t_wks */
|
||||
# define T_WKS 11 /* ns_t_wks */
|
||||
#endif
|
||||
#ifndef T_PTR
|
||||
# define T_PTR 12 /* ns_t_ptr */
|
||||
# define T_PTR 12 /* ns_t_ptr */
|
||||
#endif
|
||||
#ifndef T_HINFO
|
||||
# define T_HINFO 13 /* ns_t_hinfo */
|
||||
# define T_HINFO 13 /* ns_t_hinfo */
|
||||
#endif
|
||||
#ifndef T_MINFO
|
||||
# define T_MINFO 14 /* ns_t_minfo */
|
||||
# define T_MINFO 14 /* ns_t_minfo */
|
||||
#endif
|
||||
#ifndef T_MX
|
||||
# define T_MX 15 /* ns_t_mx */
|
||||
# define T_MX 15 /* ns_t_mx */
|
||||
#endif
|
||||
#ifndef T_TXT
|
||||
# define T_TXT 16 /* ns_t_txt */
|
||||
# define T_TXT 16 /* ns_t_txt */
|
||||
#endif
|
||||
#ifndef T_RP
|
||||
# define T_RP 17 /* ns_t_rp */
|
||||
# define T_RP 17 /* ns_t_rp */
|
||||
#endif
|
||||
#ifndef T_AFSDB
|
||||
# define T_AFSDB 18 /* ns_t_afsdb */
|
||||
# define T_AFSDB 18 /* ns_t_afsdb */
|
||||
#endif
|
||||
#ifndef T_X25
|
||||
# define T_X25 19 /* ns_t_x25 */
|
||||
# define T_X25 19 /* ns_t_x25 */
|
||||
#endif
|
||||
#ifndef T_ISDN
|
||||
# define T_ISDN 20 /* ns_t_isdn */
|
||||
# define T_ISDN 20 /* ns_t_isdn */
|
||||
#endif
|
||||
#ifndef T_RT
|
||||
# define T_RT 21 /* ns_t_rt */
|
||||
# define T_RT 21 /* ns_t_rt */
|
||||
#endif
|
||||
#ifndef T_NSAP
|
||||
# define T_NSAP 22 /* ns_t_nsap */
|
||||
# define T_NSAP 22 /* ns_t_nsap */
|
||||
#endif
|
||||
#ifndef T_NSAP_PTR
|
||||
# define T_NSAP_PTR 23 /* ns_t_nsap_ptr */
|
||||
# define T_NSAP_PTR 23 /* ns_t_nsap_ptr */
|
||||
#endif
|
||||
#ifndef T_SIG
|
||||
# define T_SIG 24 /* ns_t_sig */
|
||||
# define T_SIG 24 /* ns_t_sig */
|
||||
#endif
|
||||
#ifndef T_KEY
|
||||
# define T_KEY 25 /* ns_t_key */
|
||||
# define T_KEY 25 /* ns_t_key */
|
||||
#endif
|
||||
#ifndef T_PX
|
||||
# define T_PX 26 /* ns_t_px */
|
||||
# define T_PX 26 /* ns_t_px */
|
||||
#endif
|
||||
#ifndef T_GPOS
|
||||
# define T_GPOS 27 /* ns_t_gpos */
|
||||
# define T_GPOS 27 /* ns_t_gpos */
|
||||
#endif
|
||||
#ifndef T_AAAA
|
||||
# define T_AAAA 28 /* ns_t_aaaa */
|
||||
# define T_AAAA 28 /* ns_t_aaaa */
|
||||
#endif
|
||||
#ifndef T_LOC
|
||||
# define T_LOC 29 /* ns_t_loc */
|
||||
# define T_LOC 29 /* ns_t_loc */
|
||||
#endif
|
||||
#ifndef T_NXT
|
||||
# define T_NXT 30 /* ns_t_nxt */
|
||||
# define T_NXT 30 /* ns_t_nxt */
|
||||
#endif
|
||||
#ifndef T_EID
|
||||
# define T_EID 31 /* ns_t_eid */
|
||||
# define T_EID 31 /* ns_t_eid */
|
||||
#endif
|
||||
#ifndef T_NIMLOC
|
||||
# define T_NIMLOC 32 /* ns_t_nimloc */
|
||||
# define T_NIMLOC 32 /* ns_t_nimloc */
|
||||
#endif
|
||||
#ifndef T_SRV
|
||||
# define T_SRV 33 /* ns_t_srv */
|
||||
# define T_SRV 33 /* ns_t_srv */
|
||||
#endif
|
||||
#ifndef T_ATMA
|
||||
# define T_ATMA 34 /* ns_t_atma */
|
||||
# define T_ATMA 34 /* ns_t_atma */
|
||||
#endif
|
||||
#ifndef T_NAPTR
|
||||
# define T_NAPTR 35 /* ns_t_naptr */
|
||||
# define T_NAPTR 35 /* ns_t_naptr */
|
||||
#endif
|
||||
#ifndef T_KX
|
||||
# define T_KX 36 /* ns_t_kx */
|
||||
# define T_KX 36 /* ns_t_kx */
|
||||
#endif
|
||||
#ifndef T_CERT
|
||||
# define T_CERT 37 /* ns_t_cert */
|
||||
# define T_CERT 37 /* ns_t_cert */
|
||||
#endif
|
||||
#ifndef T_A6
|
||||
# define T_A6 38 /* ns_t_a6 */
|
||||
# define T_A6 38 /* ns_t_a6 */
|
||||
#endif
|
||||
#ifndef T_DNAME
|
||||
# define T_DNAME 39 /* ns_t_dname */
|
||||
# define T_DNAME 39 /* ns_t_dname */
|
||||
#endif
|
||||
#ifndef T_SINK
|
||||
# define T_SINK 40 /* ns_t_sink */
|
||||
# define T_SINK 40 /* ns_t_sink */
|
||||
#endif
|
||||
#ifndef T_OPT
|
||||
# define T_OPT 41 /* ns_t_opt */
|
||||
# define T_OPT 41 /* ns_t_opt */
|
||||
#endif
|
||||
#ifndef T_APL
|
||||
# define T_APL 42 /* ns_t_apl */
|
||||
# define T_APL 42 /* ns_t_apl */
|
||||
#endif
|
||||
#ifndef T_DS
|
||||
# define T_DS 43 /* ns_t_ds */
|
||||
# define T_DS 43 /* ns_t_ds */
|
||||
#endif
|
||||
#ifndef T_SSHFP
|
||||
# define T_SSHFP 44 /* ns_t_sshfp */
|
||||
# define T_SSHFP 44 /* ns_t_sshfp */
|
||||
#endif
|
||||
#ifndef T_RRSIG
|
||||
# define T_RRSIG 46 /* ns_t_rrsig */
|
||||
# define T_RRSIG 46 /* ns_t_rrsig */
|
||||
#endif
|
||||
#ifndef T_NSEC
|
||||
# define T_NSEC 47 /* ns_t_nsec */
|
||||
# define T_NSEC 47 /* ns_t_nsec */
|
||||
#endif
|
||||
#ifndef T_DNSKEY
|
||||
# define T_DNSKEY 48 /* ns_t_dnskey */
|
||||
# define T_DNSKEY 48 /* ns_t_dnskey */
|
||||
#endif
|
||||
#ifndef T_TKEY
|
||||
# define T_TKEY 249 /* ns_t_tkey */
|
||||
# define T_TKEY 249 /* ns_t_tkey */
|
||||
#endif
|
||||
#ifndef T_TSIG
|
||||
# define T_TSIG 250 /* ns_t_tsig */
|
||||
# define T_TSIG 250 /* ns_t_tsig */
|
||||
#endif
|
||||
#ifndef T_IXFR
|
||||
# define T_IXFR 251 /* ns_t_ixfr */
|
||||
# define T_IXFR 251 /* ns_t_ixfr */
|
||||
#endif
|
||||
#ifndef T_AXFR
|
||||
# define T_AXFR 252 /* ns_t_axfr */
|
||||
# define T_AXFR 252 /* ns_t_axfr */
|
||||
#endif
|
||||
#ifndef T_MAILB
|
||||
# define T_MAILB 253 /* ns_t_mailb */
|
||||
# define T_MAILB 253 /* ns_t_mailb */
|
||||
#endif
|
||||
#ifndef T_MAILA
|
||||
# define T_MAILA 254 /* ns_t_maila */
|
||||
# define T_MAILA 254 /* ns_t_maila */
|
||||
#endif
|
||||
#ifndef T_ANY
|
||||
# define T_ANY 255 /* ns_t_any */
|
||||
# define T_ANY 255 /* ns_t_any */
|
||||
#endif
|
||||
#ifndef T_URI
|
||||
# define T_URI 256 /* ns_t_uri */
|
||||
# define T_URI 256 /* ns_t_uri */
|
||||
#endif
|
||||
#ifndef T_CAA
|
||||
# define T_CAA 257 /* ns_t_caa */
|
||||
# define T_CAA 257 /* ns_t_caa */
|
||||
#endif
|
||||
#ifndef T_MAX
|
||||
# define T_MAX 65536 /* ns_t_max */
|
||||
# define T_MAX 65536 /* ns_t_max */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
60
src/third_party/cares/dist/include/ares_rules.h
vendored
60
src/third_party/cares/dist/include/ares_rules.h
vendored
@ -1,20 +1,31 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2009 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __CARES_RULES_H
|
||||
#define __CARES_RULES_H
|
||||
|
||||
|
||||
/* Copyright (C) 2009 - 2021 by Daniel Stenberg et al
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. M.I.T. makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
/* ================================================================ */
|
||||
/* COMPILE TIME SANITY CHECKS */
|
||||
/* ================================================================ */
|
||||
@ -70,7 +81,7 @@
|
||||
|
||||
#ifndef CARES_TYPEOF_ARES_SOCKLEN_T
|
||||
# error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!"
|
||||
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing
|
||||
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -81,15 +92,14 @@
|
||||
|
||||
#define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
|
||||
|
||||
/*
|
||||
* Verify that the size previously defined and expected for
|
||||
* ares_socklen_t is actually the same as the one reported
|
||||
* by sizeof() at compile time.
|
||||
*/
|
||||
/*
|
||||
* Verify that the size previously defined and expected for
|
||||
* ares_socklen_t is actually the same as the one reported
|
||||
* by sizeof() at compile time.
|
||||
*/
|
||||
|
||||
typedef char
|
||||
__cares_rule_02__
|
||||
[CareschkszEQ(ares_socklen_t, sizeof(CARES_TYPEOF_ARES_SOCKLEN_T))];
|
||||
typedef char __cares_rule_02__[CareschkszEQ(
|
||||
ares_socklen_t, sizeof(CARES_TYPEOF_ARES_SOCKLEN_T))];
|
||||
|
||||
/*
|
||||
* Verify at compile time that the size of ares_socklen_t as reported
|
||||
@ -97,9 +107,7 @@ typedef char
|
||||
* the current compilation.
|
||||
*/
|
||||
|
||||
typedef char
|
||||
__cares_rule_03__
|
||||
[CareschkszGE(ares_socklen_t, int)];
|
||||
typedef char __cares_rule_03__[CareschkszGE(ares_socklen_t, int)];
|
||||
|
||||
/* ================================================================ */
|
||||
/* EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS */
|
||||
|
||||
@ -1,20 +1,45 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef ARES__VERSION_H
|
||||
#define ARES__VERSION_H
|
||||
|
||||
/* This is the global package copyright */
|
||||
#define ARES_COPYRIGHT "2004 - 2021 Daniel Stenberg, <daniel@haxx.se>."
|
||||
#define ARES_COPYRIGHT "2004 - 2024 Daniel Stenberg, <daniel@haxx.se>."
|
||||
|
||||
#define ARES_VERSION_MAJOR 1
|
||||
#define ARES_VERSION_MINOR 19
|
||||
#define ARES_VERSION_MINOR 27
|
||||
#define ARES_VERSION_PATCH 0
|
||||
#define ARES_VERSION ((ARES_VERSION_MAJOR<<16)|\
|
||||
(ARES_VERSION_MINOR<<8)|\
|
||||
(ARES_VERSION_PATCH))
|
||||
#define ARES_VERSION_STR "1.19.0"
|
||||
#define ARES_VERSION \
|
||||
((ARES_VERSION_MAJOR << 16) | (ARES_VERSION_MINOR << 8) | \
|
||||
(ARES_VERSION_PATCH))
|
||||
#define ARES_VERSION_STR "1.27.0"
|
||||
|
||||
#if (ARES_VERSION >= 0x010700)
|
||||
# define CARES_HAVE_ARES_LIBRARY_INIT 1
|
||||
# define CARES_HAVE_ARES_LIBRARY_INIT 1
|
||||
# define CARES_HAVE_ARES_LIBRARY_CLEANUP 1
|
||||
#else
|
||||
# undef CARES_HAVE_ARES_LIBRARY_INIT
|
||||
|
||||
5
src/third_party/cares/dist/libcares.pc.cmake
vendored
5
src/third_party/cares/dist/libcares.pc.cmake
vendored
@ -4,6 +4,9 @@
|
||||
# | (_|_____| (_| | | | __/\__ \
|
||||
# \___| \__,_|_| \___||___/
|
||||
#
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=@CMAKE_INSTALL_FULL_BINDIR@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
@ -14,6 +17,6 @@ Description: asynchronous DNS lookup library
|
||||
Version: @CARES_VERSION@
|
||||
Requires:
|
||||
Requires.private:
|
||||
Cflags: -I${includedir} @CPPFLAG_CARES_STATICLIB@
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lcares
|
||||
Libs.private: @CARES_PRIVATE_LIBS@
|
||||
|
||||
4
src/third_party/cares/dist/libcares.pc.in
vendored
4
src/third_party/cares/dist/libcares.pc.in
vendored
@ -4,6 +4,8 @@
|
||||
# | (_|_____| (_| | | | __/\__ \
|
||||
# \___| \__,_|_| \___||___/
|
||||
#
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
@ -15,6 +17,6 @@ Description: asynchronous DNS lookup library
|
||||
Version: @VERSION@
|
||||
Requires:
|
||||
Requires.private:
|
||||
Cflags: -I${includedir} @CPPFLAG_CARES_STATICLIB@
|
||||
Cflags: -I${includedir} @PKGCONFIG_CFLAGS@
|
||||
Libs: -L${libdir} -lcares
|
||||
Libs.private: @CARES_PRIVATE_LIBS@
|
||||
|
||||
4
src/third_party/cares/dist/maketgz
vendored
4
src/third_party/cares/dist/maketgz
vendored
@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env perl
|
||||
# Copyright (C) Daniel Stenberg
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
$version = $ARGV[0];
|
||||
|
||||
@ -58,7 +60,7 @@ print "produce CHANGES\n";
|
||||
print "running make dist\n";
|
||||
`make dist VERSION=$version`;
|
||||
|
||||
# remove temporay sourced man pages
|
||||
# remove temporary sourced man pages
|
||||
`make -s clean-sourced-manpages`;
|
||||
|
||||
print "removing temporary configure.ac file\n";
|
||||
|
||||
2
src/third_party/cares/dist/msvc_ver.inc
vendored
2
src/third_party/cares/dist/msvc_ver.inc
vendored
@ -1,3 +1,5 @@
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
# -----------------------------------------------
|
||||
# Detect NMAKE version deducing old MSVC versions
|
||||
# -----------------------------------------------
|
||||
|
||||
33
src/third_party/cares/dist/sonar-project.properties
vendored
Normal file
33
src/third_party/cares/dist/sonar-project.properties
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# Copyright (C) The c-ares project and its contributors
|
||||
# SPDX-License-Identifier: MIT
|
||||
sonar.projectKey=c-ares_c-ares
|
||||
sonar.organization=c-ares
|
||||
|
||||
# This is the name and version displayed in the SonarCloud UI.
|
||||
sonar.projectName=c-ares
|
||||
sonar.projectVersion=1.0
|
||||
|
||||
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
|
||||
sonar.sources=src/lib, src/tools
|
||||
sonar.tests=test/
|
||||
sonar.exclusions=test/
|
||||
|
||||
# Encoding of the source code. Default is default system encoding
|
||||
sonar.sourceEncoding=UTF-8
|
||||
|
||||
|
||||
sonar.issue.ignore.multicriteria=m1,m2,m3
|
||||
# c:S5955 Loop variables should be declared in the minimal possible scope
|
||||
# Not possible in C89
|
||||
sonar.issue.ignore.multicriteria.m1.ruleKey=c:S5955
|
||||
sonar.issue.ignore.multicriteria.m1.resourceKey=**/*
|
||||
|
||||
# c:S924 Reduce the number of nested "goto" statements from 2 to 1 authorized.
|
||||
# This is a common practice in error handling, don't understand this recommendation.
|
||||
sonar.issue.ignore.multicriteria.m2.ruleKey=c:S924
|
||||
sonar.issue.ignore.multicriteria.m2.resourceKey=**/*
|
||||
|
||||
# php:S105 Tabulation characters should not be used
|
||||
# Required for MSVC Makefiles
|
||||
sonar.issue.ignore.multicriteria.m3.ruleKey=php:S105
|
||||
sonar.issue.ignore.multicriteria.m3.resourceKey=**/Makefile.inc
|
||||
@ -1,19 +1,30 @@
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright 2005 Dominick Meglio
|
||||
* Copyright (C) 2019 by Andrew Selivanov
|
||||
* Copyright (C) 2021 by Brad House
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 1998 Massachusetts Institute of Technology
|
||||
* Copyright (c) 2005 Dominick Meglio
|
||||
* Copyright (c) 2019 Andrew Selivanov
|
||||
* Copyright (c) 2021 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
@ -43,147 +54,143 @@
|
||||
#include "ares_inet_net_pton.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
|
||||
struct hostent **host)
|
||||
ares_status_t ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
|
||||
struct hostent **host)
|
||||
{
|
||||
struct ares_addrinfo_node *next;
|
||||
struct ares_addrinfo_node *next;
|
||||
struct ares_addrinfo_cname *next_cname;
|
||||
char **aliases = NULL;
|
||||
char *addrs = NULL;
|
||||
int naliases = 0, naddrs = 0, alias = 0, i;
|
||||
char **aliases = NULL;
|
||||
char *addrs = NULL;
|
||||
size_t naliases = 0;
|
||||
size_t naddrs = 0;
|
||||
size_t alias = 0;
|
||||
size_t i;
|
||||
|
||||
if (ai == NULL || host == NULL)
|
||||
if (ai == NULL || host == NULL) {
|
||||
return ARES_EBADQUERY;
|
||||
|
||||
*host = ares_malloc(sizeof(**host));
|
||||
if (!(*host))
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
memset(*host, 0, sizeof(**host));
|
||||
}
|
||||
|
||||
/* Use the first node of the response as the family, since hostent can only
|
||||
* represent one family. We assume getaddrinfo() returned a sorted list if
|
||||
* the user requested AF_UNSPEC. */
|
||||
if (family == AF_UNSPEC && ai->nodes)
|
||||
if (family == AF_UNSPEC && ai->nodes) {
|
||||
family = ai->nodes->ai_family;
|
||||
}
|
||||
|
||||
if (family != AF_INET && family != AF_INET6) {
|
||||
return ARES_EBADQUERY;
|
||||
}
|
||||
|
||||
*host = ares_malloc(sizeof(**host));
|
||||
if (!(*host)) {
|
||||
goto enomem;
|
||||
}
|
||||
memset(*host, 0, sizeof(**host));
|
||||
|
||||
next = ai->nodes;
|
||||
while (next)
|
||||
{
|
||||
if(next->ai_family == family)
|
||||
{
|
||||
++naddrs;
|
||||
}
|
||||
next = next->ai_next;
|
||||
while (next) {
|
||||
if (next->ai_family == family) {
|
||||
++naddrs;
|
||||
}
|
||||
next = next->ai_next;
|
||||
}
|
||||
|
||||
next_cname = ai->cnames;
|
||||
while (next_cname)
|
||||
{
|
||||
if(next_cname->alias)
|
||||
++naliases;
|
||||
next_cname = next_cname->next;
|
||||
while (next_cname) {
|
||||
if (next_cname->alias) {
|
||||
++naliases;
|
||||
}
|
||||
next_cname = next_cname->next;
|
||||
}
|
||||
|
||||
aliases = ares_malloc((naliases + 1) * sizeof(char *));
|
||||
if (!aliases)
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
if (!aliases) {
|
||||
goto enomem;
|
||||
}
|
||||
(*host)->h_aliases = aliases;
|
||||
memset(aliases, 0, (naliases + 1) * sizeof(char *));
|
||||
|
||||
if (naliases)
|
||||
{
|
||||
next_cname = ai->cnames;
|
||||
while (next_cname)
|
||||
{
|
||||
if(next_cname->alias) {
|
||||
aliases[alias] = ares_strdup(next_cname->alias);
|
||||
if (!aliases[alias]) {
|
||||
goto enomem;
|
||||
}
|
||||
alias++;
|
||||
}
|
||||
next_cname = next_cname->next;
|
||||
}
|
||||
if (naliases) {
|
||||
for (next_cname = ai->cnames; next_cname != NULL;
|
||||
next_cname = next_cname->next) {
|
||||
if (next_cname->alias == NULL) {
|
||||
continue;
|
||||
}
|
||||
aliases[alias] = ares_strdup(next_cname->alias);
|
||||
if (!aliases[alias]) {
|
||||
goto enomem;
|
||||
}
|
||||
alias++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
(*host)->h_addr_list = ares_malloc((naddrs + 1) * sizeof(char *));
|
||||
if (!(*host)->h_addr_list)
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
if (!(*host)->h_addr_list) {
|
||||
goto enomem;
|
||||
}
|
||||
|
||||
memset((*host)->h_addr_list, 0, (naddrs + 1) * sizeof(char *));
|
||||
|
||||
if (ai->cnames)
|
||||
{
|
||||
(*host)->h_name = ares_strdup(ai->cnames->name);
|
||||
if ((*host)->h_name == NULL && ai->cnames->name)
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
if (ai->cnames) {
|
||||
(*host)->h_name = ares_strdup(ai->cnames->name);
|
||||
if ((*host)->h_name == NULL && ai->cnames->name) {
|
||||
goto enomem;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*host)->h_name = ares_strdup(ai->name);
|
||||
if ((*host)->h_name == NULL && ai->name)
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
} else {
|
||||
(*host)->h_name = ares_strdup(ai->name);
|
||||
if ((*host)->h_name == NULL && ai->name) {
|
||||
goto enomem;
|
||||
}
|
||||
}
|
||||
|
||||
(*host)->h_addrtype = (HOSTENT_ADDRTYPE_TYPE)family;
|
||||
|
||||
if (family == AF_INET) {
|
||||
(*host)->h_length = sizeof(struct in_addr);
|
||||
}
|
||||
|
||||
if (family == AF_INET6) {
|
||||
(*host)->h_length = sizeof(struct ares_in6_addr);
|
||||
}
|
||||
|
||||
if (naddrs) {
|
||||
addrs = ares_malloc(naddrs * (size_t)(*host)->h_length);
|
||||
if (!addrs) {
|
||||
goto enomem;
|
||||
}
|
||||
|
||||
(*host)->h_addrtype = family;
|
||||
(*host)->h_length = (family == AF_INET)?
|
||||
sizeof(struct in_addr):sizeof(struct ares_in6_addr);
|
||||
|
||||
if (naddrs)
|
||||
{
|
||||
addrs = ares_malloc(naddrs * (*host)->h_length);
|
||||
if (!addrs)
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
next = ai->nodes;
|
||||
while (next)
|
||||
{
|
||||
if(next->ai_family == family)
|
||||
{
|
||||
(*host)->h_addr_list[i] = addrs + (i * (*host)->h_length);
|
||||
if (family == AF_INET6)
|
||||
{
|
||||
memcpy((*host)->h_addr_list[i],
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
|
||||
(*host)->h_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy((*host)->h_addr_list[i],
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),
|
||||
(*host)->h_length);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
next = next->ai_next;
|
||||
}
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
ares_free(addrs);
|
||||
}
|
||||
i = 0;
|
||||
for (next = ai->nodes; next != NULL; next = next->ai_next) {
|
||||
if (next->ai_family != family) {
|
||||
continue;
|
||||
}
|
||||
(*host)->h_addr_list[i] = addrs + (i * (size_t)(*host)->h_length);
|
||||
if (family == AF_INET6) {
|
||||
memcpy(
|
||||
(*host)->h_addr_list[i],
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
|
||||
(size_t)(*host)->h_length);
|
||||
}
|
||||
if (family == AF_INET) {
|
||||
memcpy(
|
||||
(*host)->h_addr_list[i],
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),
|
||||
(size_t)(*host)->h_length);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (naddrs == 0 && naliases == 0)
|
||||
{
|
||||
ares_free_hostent(*host);
|
||||
*host = NULL;
|
||||
return ARES_ENODATA;
|
||||
if (i == 0) {
|
||||
ares_free(addrs);
|
||||
}
|
||||
}
|
||||
|
||||
if (naddrs == 0 && naliases == 0) {
|
||||
ares_free_hostent(*host);
|
||||
*host = NULL;
|
||||
return ARES_ENODATA;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
|
||||
@ -193,74 +200,79 @@ enomem:
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
int ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
|
||||
int req_naddrttls, struct ares_addrttl *addrttls,
|
||||
struct ares_addr6ttl *addr6ttls, int *naddrttls)
|
||||
ares_status_t ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
|
||||
size_t req_naddrttls,
|
||||
struct ares_addrttl *addrttls,
|
||||
struct ares_addr6ttl *addr6ttls,
|
||||
size_t *naddrttls)
|
||||
{
|
||||
struct ares_addrinfo_node *next;
|
||||
struct ares_addrinfo_node *next;
|
||||
struct ares_addrinfo_cname *next_cname;
|
||||
int cname_ttl = INT_MAX;
|
||||
int cname_ttl = INT_MAX;
|
||||
|
||||
if (family != AF_INET && family != AF_INET6)
|
||||
if (family != AF_INET && family != AF_INET6) {
|
||||
return ARES_EBADQUERY;
|
||||
}
|
||||
|
||||
if (ai == NULL || naddrttls == NULL)
|
||||
if (ai == NULL || naddrttls == NULL) {
|
||||
return ARES_EBADQUERY;
|
||||
}
|
||||
|
||||
if (family == AF_INET && addrttls == NULL)
|
||||
if (family == AF_INET && addrttls == NULL) {
|
||||
return ARES_EBADQUERY;
|
||||
}
|
||||
|
||||
if (family == AF_INET6 && addr6ttls == NULL)
|
||||
if (family == AF_INET6 && addr6ttls == NULL) {
|
||||
return ARES_EBADQUERY;
|
||||
}
|
||||
|
||||
if (req_naddrttls == 0)
|
||||
if (req_naddrttls == 0) {
|
||||
return ARES_EBADQUERY;
|
||||
}
|
||||
|
||||
*naddrttls = 0;
|
||||
|
||||
next_cname = ai->cnames;
|
||||
while (next_cname)
|
||||
{
|
||||
if(next_cname->ttl < cname_ttl)
|
||||
cname_ttl = next_cname->ttl;
|
||||
next_cname = next_cname->next;
|
||||
while (next_cname) {
|
||||
if (next_cname->ttl < cname_ttl) {
|
||||
cname_ttl = next_cname->ttl;
|
||||
}
|
||||
next_cname = next_cname->next;
|
||||
}
|
||||
|
||||
for (next = ai->nodes; next != NULL; next = next->ai_next) {
|
||||
if (next->ai_family != family) {
|
||||
continue;
|
||||
}
|
||||
|
||||
next = ai->nodes;
|
||||
while (next)
|
||||
{
|
||||
if(next->ai_family == family)
|
||||
{
|
||||
if (*naddrttls < req_naddrttls)
|
||||
{
|
||||
if (family == AF_INET6)
|
||||
{
|
||||
if(next->ai_ttl > cname_ttl)
|
||||
addr6ttls[*naddrttls].ttl = cname_ttl;
|
||||
else
|
||||
addr6ttls[*naddrttls].ttl = next->ai_ttl;
|
||||
|
||||
memcpy(&addr6ttls[*naddrttls].ip6addr,
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
|
||||
sizeof(struct ares_in6_addr));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(next->ai_ttl > cname_ttl)
|
||||
addrttls[*naddrttls].ttl = cname_ttl;
|
||||
else
|
||||
addrttls[*naddrttls].ttl = next->ai_ttl;
|
||||
memcpy(&addrttls[*naddrttls].ipaddr,
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),
|
||||
sizeof(struct in_addr));
|
||||
}
|
||||
(*naddrttls)++;
|
||||
}
|
||||
}
|
||||
next = next->ai_next;
|
||||
if (*naddrttls >= req_naddrttls) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (family == AF_INET6) {
|
||||
if (next->ai_ttl > cname_ttl) {
|
||||
addr6ttls[*naddrttls].ttl = cname_ttl;
|
||||
} else {
|
||||
addr6ttls[*naddrttls].ttl = next->ai_ttl;
|
||||
}
|
||||
|
||||
memcpy(
|
||||
&addr6ttls[*naddrttls].ip6addr,
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in6 *, next->ai_addr)->sin6_addr),
|
||||
sizeof(struct ares_in6_addr));
|
||||
} else {
|
||||
if (next->ai_ttl > cname_ttl) {
|
||||
addrttls[*naddrttls].ttl = cname_ttl;
|
||||
} else {
|
||||
addrttls[*naddrttls].ttl = next->ai_ttl;
|
||||
}
|
||||
memcpy(
|
||||
&addrttls[*naddrttls].ipaddr,
|
||||
&(CARES_INADDR_CAST(struct sockaddr_in *, next->ai_addr)->sin_addr),
|
||||
sizeof(struct in_addr));
|
||||
}
|
||||
(*naddrttls)++;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +1,28 @@
|
||||
/* Copyright (C) 2021
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) Massachusetts Institute of Technology
|
||||
* Copyright (c) Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
@ -26,164 +38,152 @@
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
|
||||
#include <ws2ipdef.h>
|
||||
#include <iphlpapi.h>
|
||||
# include <ws2ipdef.h>
|
||||
#endif
|
||||
|
||||
#if defined(USE_WINSOCK)
|
||||
# if defined(HAVE_IPHLPAPI_H)
|
||||
# include <iphlpapi.h>
|
||||
# endif
|
||||
# if defined(HAVE_NETIOAPI_H)
|
||||
# include <netioapi.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_inet_net_pton.h"
|
||||
#include "ares_nowarn.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares_append_ai_node(int aftype,
|
||||
unsigned short port,
|
||||
int ttl,
|
||||
const void *adata,
|
||||
struct ares_addrinfo_node **nodes)
|
||||
ares_status_t ares_append_ai_node(int aftype, unsigned short port,
|
||||
unsigned int ttl, const void *adata,
|
||||
struct ares_addrinfo_node **nodes)
|
||||
{
|
||||
struct ares_addrinfo_node *node;
|
||||
|
||||
node = ares__append_addrinfo_node(nodes);
|
||||
if (!node)
|
||||
{
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
if (!node) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
memset(node, 0, sizeof(*node));
|
||||
|
||||
if (aftype == AF_INET)
|
||||
{
|
||||
struct sockaddr_in *sin = ares_malloc(sizeof(*sin));
|
||||
if (!sin)
|
||||
{
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
memset(sin, 0, sizeof(*sin));
|
||||
memcpy(&sin->sin_addr.s_addr, adata, sizeof(sin->sin_addr.s_addr));
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_port = htons(port);
|
||||
|
||||
node->ai_addr = (struct sockaddr *)sin;
|
||||
node->ai_family = AF_INET;
|
||||
node->ai_addrlen = sizeof(*sin);
|
||||
node->ai_addr = (struct sockaddr *)sin;
|
||||
node->ai_ttl = ttl;
|
||||
if (aftype == AF_INET) {
|
||||
struct sockaddr_in *sin = ares_malloc(sizeof(*sin));
|
||||
if (!sin) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
if (aftype == AF_INET6)
|
||||
{
|
||||
struct sockaddr_in6 *sin6 = ares_malloc(sizeof(*sin6));
|
||||
if (!sin6)
|
||||
{
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
memset(sin, 0, sizeof(*sin));
|
||||
memcpy(&sin->sin_addr.s_addr, adata, sizeof(sin->sin_addr.s_addr));
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_port = htons(port);
|
||||
|
||||
memset(sin6, 0, sizeof(*sin6));
|
||||
memcpy(&sin6->sin6_addr.s6_addr, adata, sizeof(sin6->sin6_addr.s6_addr));
|
||||
sin6->sin6_family = AF_INET6;
|
||||
sin6->sin6_port = htons(port);
|
||||
node->ai_addr = (struct sockaddr *)sin;
|
||||
node->ai_family = AF_INET;
|
||||
node->ai_addrlen = sizeof(*sin);
|
||||
node->ai_addr = (struct sockaddr *)sin;
|
||||
node->ai_ttl = (int)ttl;
|
||||
}
|
||||
|
||||
node->ai_addr = (struct sockaddr *)sin6;
|
||||
node->ai_family = AF_INET6;
|
||||
node->ai_addrlen = sizeof(*sin6);
|
||||
node->ai_addr = (struct sockaddr *)sin6;
|
||||
node->ai_ttl = ttl;
|
||||
if (aftype == AF_INET6) {
|
||||
struct sockaddr_in6 *sin6 = ares_malloc(sizeof(*sin6));
|
||||
if (!sin6) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
memset(sin6, 0, sizeof(*sin6));
|
||||
memcpy(&sin6->sin6_addr.s6_addr, adata, sizeof(sin6->sin6_addr.s6_addr));
|
||||
sin6->sin6_family = AF_INET6;
|
||||
sin6->sin6_port = htons(port);
|
||||
|
||||
node->ai_addr = (struct sockaddr *)sin6;
|
||||
node->ai_family = AF_INET6;
|
||||
node->ai_addrlen = sizeof(*sin6);
|
||||
node->ai_addr = (struct sockaddr *)sin6;
|
||||
node->ai_ttl = (int)ttl;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int ares__default_loopback_addrs(int aftype,
|
||||
unsigned short port,
|
||||
struct ares_addrinfo_node **nodes)
|
||||
static ares_status_t
|
||||
ares__default_loopback_addrs(int aftype, unsigned short port,
|
||||
struct ares_addrinfo_node **nodes)
|
||||
{
|
||||
int status = ARES_SUCCESS;
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
|
||||
if (aftype == AF_UNSPEC || aftype == AF_INET6)
|
||||
{
|
||||
struct ares_in6_addr addr6;
|
||||
ares_inet_pton(AF_INET6, "::1", &addr6);
|
||||
status = ares_append_ai_node(AF_INET6, port, 0, &addr6, nodes);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
if (aftype == AF_UNSPEC || aftype == AF_INET6) {
|
||||
struct ares_in6_addr addr6;
|
||||
ares_inet_pton(AF_INET6, "::1", &addr6);
|
||||
status = ares_append_ai_node(AF_INET6, port, 0, &addr6, nodes);
|
||||
if (status != ARES_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if (aftype == AF_UNSPEC || aftype == AF_INET)
|
||||
{
|
||||
struct in_addr addr4;
|
||||
ares_inet_pton(AF_INET, "127.0.0.1", &addr4);
|
||||
status = ares_append_ai_node(AF_INET, port, 0, &addr4, nodes);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
return status;
|
||||
}
|
||||
if (aftype == AF_UNSPEC || aftype == AF_INET) {
|
||||
struct in_addr addr4;
|
||||
ares_inet_pton(AF_INET, "127.0.0.1", &addr4);
|
||||
status = ares_append_ai_node(AF_INET, port, 0, &addr4, nodes);
|
||||
if (status != ARES_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static int ares__system_loopback_addrs(int aftype,
|
||||
unsigned short port,
|
||||
struct ares_addrinfo_node **nodes)
|
||||
static ares_status_t
|
||||
ares__system_loopback_addrs(int aftype, unsigned short port,
|
||||
struct ares_addrinfo_node **nodes)
|
||||
{
|
||||
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && !defined(__WATCOMC__)
|
||||
#if defined(_WIN32) && defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && \
|
||||
!defined(__WATCOMC__)
|
||||
PMIB_UNICASTIPADDRESS_TABLE table;
|
||||
unsigned int i;
|
||||
int status;
|
||||
unsigned int i;
|
||||
ares_status_t status;
|
||||
|
||||
*nodes = NULL;
|
||||
|
||||
if (GetUnicastIpAddressTable(aftype, &table) != NO_ERROR)
|
||||
if (GetUnicastIpAddressTable((ADDRESS_FAMILY)aftype, &table) != NO_ERROR) {
|
||||
return ARES_ENOTFOUND;
|
||||
}
|
||||
|
||||
for (i=0; i<table->NumEntries; i++)
|
||||
{
|
||||
if (table->Table[i].InterfaceLuid.Info.IfType !=
|
||||
IF_TYPE_SOFTWARE_LOOPBACK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (table->Table[i].Address.si_family == AF_INET)
|
||||
{
|
||||
status = ares_append_ai_node(table->Table[i].Address.si_family, port, 0,
|
||||
&table->Table[i].Address.Ipv4.sin_addr,
|
||||
nodes);
|
||||
}
|
||||
else if (table->Table[i].Address.si_family == AF_INET6)
|
||||
{
|
||||
status = ares_append_ai_node(table->Table[i].Address.si_family, port, 0,
|
||||
&table->Table[i].Address.Ipv6.sin6_addr,
|
||||
nodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Ignore any others */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
for (i = 0; i < table->NumEntries; i++) {
|
||||
if (table->Table[i].InterfaceLuid.Info.IfType !=
|
||||
IF_TYPE_SOFTWARE_LOOPBACK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*nodes == NULL)
|
||||
status = ARES_ENOTFOUND;
|
||||
if (table->Table[i].Address.si_family == AF_INET) {
|
||||
status =
|
||||
ares_append_ai_node(table->Table[i].Address.si_family, port, 0,
|
||||
&table->Table[i].Address.Ipv4.sin_addr, nodes);
|
||||
} else if (table->Table[i].Address.si_family == AF_INET6) {
|
||||
status =
|
||||
ares_append_ai_node(table->Table[i].Address.si_family, port, 0,
|
||||
&table->Table[i].Address.Ipv6.sin6_addr, nodes);
|
||||
} else {
|
||||
/* Ignore any others */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (*nodes == NULL) {
|
||||
status = ARES_ENOTFOUND;
|
||||
}
|
||||
|
||||
fail:
|
||||
FreeMibTable(table);
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
ares__freeaddrinfo_nodes(*nodes);
|
||||
*nodes = NULL;
|
||||
}
|
||||
if (status != ARES_SUCCESS) {
|
||||
ares__freeaddrinfo_nodes(*nodes);
|
||||
*nodes = NULL;
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@ -196,14 +196,12 @@ fail:
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int ares__addrinfo_localhost(const char *name,
|
||||
unsigned short port,
|
||||
const struct ares_addrinfo_hints *hints,
|
||||
struct ares_addrinfo *ai)
|
||||
ares_status_t ares__addrinfo_localhost(const char *name, unsigned short port,
|
||||
const struct ares_addrinfo_hints *hints,
|
||||
struct ares_addrinfo *ai)
|
||||
{
|
||||
struct ares_addrinfo_node *nodes = NULL;
|
||||
int result;
|
||||
ares_status_t status;
|
||||
|
||||
/* Validate family */
|
||||
switch (hints->ai_family) {
|
||||
@ -216,21 +214,19 @@ int ares__addrinfo_localhost(const char *name,
|
||||
}
|
||||
|
||||
ai->name = ares_strdup(name);
|
||||
if(!ai->name)
|
||||
{
|
||||
goto enomem;
|
||||
}
|
||||
if (!ai->name) {
|
||||
goto enomem;
|
||||
}
|
||||
|
||||
result = ares__system_loopback_addrs(hints->ai_family, port, &nodes);
|
||||
status = ares__system_loopback_addrs(hints->ai_family, port, &nodes);
|
||||
|
||||
if (result == ARES_ENOTFOUND)
|
||||
{
|
||||
result = ares__default_loopback_addrs(hints->ai_family, port, &nodes);
|
||||
}
|
||||
if (status == ARES_ENOTFOUND) {
|
||||
status = ares__default_loopback_addrs(hints->ai_family, port, &nodes);
|
||||
}
|
||||
|
||||
ares__addrinfo_cat_nodes(&ai->nodes, nodes);
|
||||
|
||||
return result;
|
||||
return status;
|
||||
|
||||
enomem:
|
||||
ares__freeaddrinfo_nodes(nodes);
|
||||
|
||||
1152
src/third_party/cares/dist/src/lib/ares__buf.c
vendored
Normal file
1152
src/third_party/cares/dist/src/lib/ares__buf.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
572
src/third_party/cares/dist/src/lib/ares__buf.h
vendored
Normal file
572
src/third_party/cares/dist/src/lib/ares__buf.h
vendored
Normal file
@ -0,0 +1,572 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__BUF_H
|
||||
#define __ARES__BUF_H
|
||||
|
||||
/*! \addtogroup ares__buf Safe Data Builder and buffer
|
||||
*
|
||||
* This is a buffer building and parsing framework with a focus on security over
|
||||
* performance. All data to be read from the buffer will perform explicit length
|
||||
* validation and return a success/fail result. There are also various helpers
|
||||
* for writing data to the buffer which dynamically grows.
|
||||
*
|
||||
* All operations that fetch or consume data from the buffer will move forward
|
||||
* the internal pointer, thus marking the data as processed which may no longer
|
||||
* be accessible after certain operations (such as append).
|
||||
*
|
||||
* The helpers for this object are meant to be added as needed. If you can't
|
||||
* find it, write it!
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
struct ares__buf;
|
||||
|
||||
/*! Opaque data type for generic hash table implementation */
|
||||
typedef struct ares__buf ares__buf_t;
|
||||
|
||||
/*! Create a new buffer object that dynamically allocates buffers for data.
|
||||
*
|
||||
* \return initialized buffer object or NULL if out of memory.
|
||||
*/
|
||||
ares__buf_t *ares__buf_create(void);
|
||||
|
||||
/*! Create a new buffer object that uses a user-provided data pointer. The
|
||||
* data provided will not be manipulated, and cannot be appended to. This
|
||||
* is strictly used for parsing.
|
||||
*
|
||||
* \param[in] data Data to provide to buffer, must not be NULL.
|
||||
* \param[in] data_len Size of buffer provided, must be > 0
|
||||
*
|
||||
* \return initialized buffer object or NULL if out of memory or misuse.
|
||||
*/
|
||||
ares__buf_t *ares__buf_create_const(const unsigned char *data, size_t data_len);
|
||||
|
||||
|
||||
/*! Destroy an initialized buffer object.
|
||||
*
|
||||
* \param[in] buf Initialized buf object
|
||||
*/
|
||||
void ares__buf_destroy(ares__buf_t *buf);
|
||||
|
||||
|
||||
/*! Append multiple bytes to a dynamic buffer object
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] data Data to copy to buffer object
|
||||
* \param[in] data_len Length of data to copy to buffer object.
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_append(ares__buf_t *buf, const unsigned char *data,
|
||||
size_t data_len);
|
||||
|
||||
/*! Append a single byte to the dynamic buffer object
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] byte Single byte to append to buffer object.
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_append_byte(ares__buf_t *buf, unsigned char byte);
|
||||
|
||||
/*! Append a null-terminated string to the dynamic buffer object
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] str String to append to buffer object.
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_append_str(ares__buf_t *buf, const char *str);
|
||||
|
||||
/*! Append a 16bit Big Endian number to the buffer.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] u16 16bit integer
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_append_be16(ares__buf_t *buf, unsigned short u16);
|
||||
|
||||
/*! Append a 32bit Big Endian number to the buffer.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] u32 32bit integer
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_append_be32(ares__buf_t *buf, unsigned int u32);
|
||||
|
||||
/*! Append a number in ASCII decimal form.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] num Number to print
|
||||
* \param[in] len Length to output, use 0 for no padding
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
ares_status_t ares__buf_append_num_dec(ares__buf_t *buf, size_t num,
|
||||
size_t len);
|
||||
|
||||
/*! Append a number in ASCII hexadecimal form.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] num Number to print
|
||||
* \param[in] len Length to output, use 0 for no padding
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
ares_status_t ares__buf_append_num_hex(ares__buf_t *buf, size_t num,
|
||||
size_t len);
|
||||
|
||||
/*! Sets the current buffer length. This *may* be used if there is a need to
|
||||
* override a prior position in the buffer, such as if there is a length
|
||||
* prefix that isn't easily predictable, and you must go back and overwrite
|
||||
* that position.
|
||||
*
|
||||
* Only valid on non-const buffers. Length provided must not exceed current
|
||||
* allocated buffer size, but otherwise there are very few protections on
|
||||
* this function. Use cautiously.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] len Length to set
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_set_length(ares__buf_t *buf, size_t len);
|
||||
|
||||
|
||||
/*! Start a dynamic append operation that returns a buffer suitable for
|
||||
* writing. A desired minimum length is passed in, and the actual allocated
|
||||
* buffer size is returned which may be greater than the requested size.
|
||||
* No operation other than ares__buf_append_finish() is allowed on the
|
||||
* buffer after this request.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in,out] len Desired non-zero length passed in, actual buffer size
|
||||
* returned.
|
||||
* \return Pointer to writable buffer or NULL on failure (usage, out of mem)
|
||||
*/
|
||||
unsigned char *ares__buf_append_start(ares__buf_t *buf, size_t *len);
|
||||
|
||||
/*! Finish a dynamic append operation. Called after
|
||||
* ares__buf_append_start() once desired data is written.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object.
|
||||
* \param[in] len Length of data written. May be zero to terminate
|
||||
* operation. Must not be greater than returned from
|
||||
* ares__buf_append_start().
|
||||
*/
|
||||
void ares__buf_append_finish(ares__buf_t *buf, size_t len);
|
||||
|
||||
/*! Write the data provided to the buffer in a hexdump format.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object.
|
||||
* \param[in] data Data to hex dump
|
||||
* \param[in] data_len Length of data to hexdump
|
||||
* \return ARES_SUCCESS on success.
|
||||
*/
|
||||
ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data,
|
||||
size_t len);
|
||||
|
||||
/*! Clean up ares__buf_t and return allocated pointer to unprocessed data. It
|
||||
* is the responsibility of the caller to ares_free() the returned buffer.
|
||||
* The passed in buf parameter is invalidated by this call.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object. Can not be a "const" buffer.
|
||||
* \param[out] len Length of data returned
|
||||
* \return pointer to unprocessed data (may be zero length) or NULL on error.
|
||||
*/
|
||||
unsigned char *ares__buf_finish_bin(ares__buf_t *buf, size_t *len);
|
||||
|
||||
/*! Clean up ares__buf_t and return allocated pointer to unprocessed data and
|
||||
* return it as a string (null terminated). It is the responsibility of the
|
||||
* caller to ares_free() the returned buffer. The passed in buf parameter is
|
||||
* invalidated by this call.
|
||||
*
|
||||
* This function in no way validates the data in this buffer is actually
|
||||
* a string, that characters are printable, or that there aren't multiple
|
||||
* NULL terminators. It is assumed that the caller will either validate that
|
||||
* themselves or has built this buffer with only a valid character set.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object. Can not be a "const" buffer.
|
||||
* \param[out] len Optional. Length of data returned, or NULL if not needed.
|
||||
* \return pointer to unprocessed data or NULL on error.
|
||||
*/
|
||||
char *ares__buf_finish_str(ares__buf_t *buf, size_t *len);
|
||||
|
||||
/*! Tag a position to save in the buffer in case parsing needs to rollback,
|
||||
* such as if insufficient data is available, but more data may be added in
|
||||
* the future. Only a single tag can be set per buffer object. Setting a
|
||||
* tag will override any pre-existing tag.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
*/
|
||||
void ares__buf_tag(ares__buf_t *buf);
|
||||
|
||||
/*! Rollback to a tagged position. Will automatically clear the tag.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_tag_rollback(ares__buf_t *buf);
|
||||
|
||||
/*! Clear the tagged position without rolling back. You should do this any
|
||||
* time a tag is no longer needed as future append operations can reclaim
|
||||
* buffer space.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_tag_clear(ares__buf_t *buf);
|
||||
|
||||
/*! Fetch the buffer and length of data starting from the tagged position up
|
||||
* to the _current_ position. It will not unset the tagged position. The
|
||||
* data may be invalidated by any future ares__buf_*() calls.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] len Length between tag and current offset in buffer
|
||||
* \return NULL on failure (such as no tag), otherwise pointer to start of
|
||||
* buffer
|
||||
*/
|
||||
const unsigned char *ares__buf_tag_fetch(const ares__buf_t *buf, size_t *len);
|
||||
|
||||
/*! Get the length of the current tag offset to the current position.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \return length
|
||||
*/
|
||||
size_t ares__buf_tag_length(const ares__buf_t *buf);
|
||||
|
||||
/*! Fetch the bytes starting from the tagged position up to the _current_
|
||||
* position using the provided buffer. It will not unset the tagged position.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in,out] bytes Buffer to hold data
|
||||
* \param[in,out] len On input, buffer size, on output, bytes place in
|
||||
* buffer.
|
||||
* \return ARES_SUCCESS if fetched, ARES_EFORMERR if insufficient buffer size
|
||||
*/
|
||||
ares_status_t ares__buf_tag_fetch_bytes(const ares__buf_t *buf,
|
||||
unsigned char *bytes, size_t *len);
|
||||
|
||||
/*! Fetch the bytes starting from the tagged position up to the _current_
|
||||
* position as a NULL-terminated string using the provided buffer. The data
|
||||
* is validated to be ASCII-printable data. It will not unset the tagged
|
||||
* poition.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in,out] str Buffer to hold data
|
||||
* \param[in] len On input, buffer size, on output, bytes place in
|
||||
* buffer.
|
||||
* \return ARES_SUCCESS if fetched, ARES_EFORMERR if insufficient buffer size,
|
||||
* ARES_EBADSTR if not printable ASCII
|
||||
*/
|
||||
ares_status_t ares__buf_tag_fetch_string(const ares__buf_t *buf, char *str,
|
||||
size_t len);
|
||||
|
||||
/*! Consume the given number of bytes without reading them.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] len Length to consume
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_consume(ares__buf_t *buf, size_t len);
|
||||
|
||||
/*! Fetch a 16bit Big Endian number from the buffer.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] u16 Buffer to hold 16bit integer
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_fetch_be16(ares__buf_t *buf, unsigned short *u16);
|
||||
|
||||
/*! Fetch a 32bit Big Endian number from the buffer.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] u32 Buffer to hold 32bit integer
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_fetch_be32(ares__buf_t *buf, unsigned int *u32);
|
||||
|
||||
|
||||
/*! Fetch the requested number of bytes into the provided buffer
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] bytes Buffer to hold data
|
||||
* \param[in] len Requested number of bytes (must be > 0)
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
|
||||
size_t len);
|
||||
|
||||
|
||||
/*! Fetch the requested number of bytes and return a new buffer that must be
|
||||
* ares_free()'d by the caller.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] len Requested number of bytes (must be > 0)
|
||||
* \param[in] null_term Even though this is considered binary data, the user
|
||||
* knows it may be a vald string, so add a null
|
||||
* terminator.
|
||||
* \param[out] bytes Pointer passed by reference. Will be allocated.
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_fetch_bytes_dup(ares__buf_t *buf, size_t len,
|
||||
ares_bool_t null_term,
|
||||
unsigned char **bytes);
|
||||
|
||||
/*! Fetch the requested number of bytes and place them into the provided
|
||||
* dest buffer object.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] dest Buffer object to append bytes.
|
||||
* \param[in] len Requested number of bytes (must be > 0)
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_fetch_bytes_into_buf(ares__buf_t *buf,
|
||||
ares__buf_t *dest, size_t len);
|
||||
|
||||
/*! Fetch the requested number of bytes and return a new buffer that must be
|
||||
* ares_free()'d by the caller. The returned buffer is a null terminated
|
||||
* string.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] len Requested number of bytes (must be > 0)
|
||||
* \param[out] str Pointer passed by reference. Will be allocated.
|
||||
* \return ARES_SUCCESS or one of the c-ares error codes
|
||||
*/
|
||||
ares_status_t ares__buf_fetch_str_dup(ares__buf_t *buf, size_t len, char **str);
|
||||
|
||||
/*! Consume whitespace characters (0x09, 0x0B, 0x0C, 0x0D, 0x20, and optionally
|
||||
* 0x0A).
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] include_linefeed ARES_TRUE to include consuming 0x0A,
|
||||
* ARES_FALSE otherwise.
|
||||
* \return number of whitespace characters consumed
|
||||
*/
|
||||
size_t ares__buf_consume_whitespace(ares__buf_t *buf,
|
||||
ares_bool_t include_linefeed);
|
||||
|
||||
|
||||
/*! Consume any non-whitespace character (anything other than 0x09, 0x0B, 0x0C,
|
||||
* 0x0D, 0x20, and 0x0A).
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \return number of characters consumed
|
||||
*/
|
||||
size_t ares__buf_consume_nonwhitespace(ares__buf_t *buf);
|
||||
|
||||
|
||||
/*! Consume until a character in the character set provided is reached
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] charset character set
|
||||
* \param[in] len length of character set
|
||||
* \param[in] require_charset require we find a character from the charset.
|
||||
* if ARES_FALSE it will simply consume the
|
||||
* rest of the buffer. If ARES_TRUE will return
|
||||
* 0 if not found.
|
||||
* \return number of characters consumed
|
||||
*/
|
||||
size_t ares__buf_consume_until_charset(ares__buf_t *buf,
|
||||
const unsigned char *charset, size_t len,
|
||||
ares_bool_t require_charset);
|
||||
|
||||
|
||||
/*! Consume while the characters match the characters in the provided set.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] charset character set
|
||||
* \param[in] len length of character set
|
||||
* \return number of characters consumed
|
||||
*/
|
||||
size_t ares__buf_consume_charset(ares__buf_t *buf, const unsigned char *charset,
|
||||
size_t len);
|
||||
|
||||
|
||||
/*! Consume from the current position until the end of the line, and optionally
|
||||
* the end of line character (0x0A) itself.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] include_linefeed ARES_TRUE to include consuming 0x0A,
|
||||
* ARES_FALSE otherwise.
|
||||
* \return number of characters consumed
|
||||
*/
|
||||
size_t ares__buf_consume_line(ares__buf_t *buf, ares_bool_t include_linefeed);
|
||||
|
||||
typedef enum {
|
||||
/*! No flags */
|
||||
ARES_BUF_SPLIT_NONE = 0,
|
||||
/*! The delimiter will be the first character in the buffer, except the
|
||||
* first buffer since the start doesn't have a delimiter
|
||||
*/
|
||||
ARES_BUF_SPLIT_DONT_CONSUME_DELIMS = 1 << 0,
|
||||
/*! Allow blank sections, by default blank sections are not emitted. If using
|
||||
* ARES_BUF_SPLIT_DONT_CONSUME_DELIMS, the delimiter is not counted as part
|
||||
* of the section */
|
||||
ARES_BUF_SPLIT_ALLOW_BLANK = 1 << 1,
|
||||
/*! Remove duplicate entries */
|
||||
ARES_BUF_SPLIT_NO_DUPLICATES = 1 << 2,
|
||||
/*! Perform case-insensitive matching when comparing values */
|
||||
ARES_BUF_SPLIT_CASE_INSENSITIVE = 1 << 3
|
||||
} ares__buf_split_t;
|
||||
|
||||
/*! Split the provided buffer into multiple sub-buffers stored in the variable
|
||||
* pointed to by the linked list. The sub buffers are const buffers pointing
|
||||
* into the buf provided.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] delims Possible delimiters
|
||||
* \param[in] delims_len Length of possible delimiters
|
||||
* \param[in] flags One more more flags
|
||||
* \param[out] list Result. Depending on flags, this may be a
|
||||
* valid list with no elements. Use
|
||||
* ares__llist_destroy() to free the memory which
|
||||
* will also free the contained ares__buf_t
|
||||
* objects.
|
||||
* \return ARES_SUCCESS on success, or error like ARES_ENOMEM.
|
||||
*/
|
||||
ares_status_t ares__buf_split(ares__buf_t *buf, const unsigned char *delims,
|
||||
size_t delims_len, ares__buf_split_t flags,
|
||||
ares__llist_t **list);
|
||||
|
||||
|
||||
/*! Check the unprocessed buffer to see if it begins with the sequence of
|
||||
* characters provided.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] data Bytes of data to compare.
|
||||
* \param[in] data_len Length of data to compare.
|
||||
* \return ARES_TRUE on match, ARES_FALSE otherwise.
|
||||
*/
|
||||
ares_bool_t ares__buf_begins_with(const ares__buf_t *buf,
|
||||
const unsigned char *data, size_t data_len);
|
||||
|
||||
|
||||
/*! Size of unprocessed remaining data length
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \return length remaining
|
||||
*/
|
||||
size_t ares__buf_len(const ares__buf_t *buf);
|
||||
|
||||
/*! Retrieve a pointer to the currently unprocessed data. Generally this isn't
|
||||
* recommended to be used in practice. The returned pointer may be invalidated
|
||||
* by any future ares__buf_*() calls.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[out] len Length of available data
|
||||
* \return Pointer to buffer of unprocessed data
|
||||
*/
|
||||
const unsigned char *ares__buf_peek(const ares__buf_t *buf, size_t *len);
|
||||
|
||||
|
||||
/*! Wipe any processed data from the beginning of the buffer. This will
|
||||
* move any remaining data to the front of the internally allocated buffer.
|
||||
*
|
||||
* Can not be used on const buffer objects.
|
||||
*
|
||||
* Typically not needed to call, as any new append operation will automatically
|
||||
* call this function if there is insufficient space to append the data in
|
||||
* order to try to avoid another memory allocation.
|
||||
*
|
||||
* It may be useful to call in order to ensure the current message being
|
||||
* processed is in the beginning of the buffer if there is an intent to use
|
||||
* ares__buf_set_position() and ares__buf_get_position() as may be necessary
|
||||
* when processing DNS compressed names.
|
||||
*
|
||||
* If there is an active tag, it will NOT clear the tag, it will use the tag
|
||||
* as the start of the unprocessed data rather than the current offset. If
|
||||
* a prior tag is no longer needed, may be wise to call ares__buf_tag_clear().
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
*/
|
||||
void ares__buf_reclaim(ares__buf_t *buf);
|
||||
|
||||
/*! Set the current offset within the internal buffer.
|
||||
*
|
||||
* Typically this should not be used, if possible, use the ares__buf_tag*()
|
||||
* operations instead.
|
||||
*
|
||||
* One exception is DNS name compression which may backwards reference to
|
||||
* an index in the message. It may be necessary in such a case to call
|
||||
* ares__buf_reclaim() if using a dynamic (non-const) buffer before processing
|
||||
* such a message.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \param[in] idx Index to set position
|
||||
* \return ARES_SUCCESS if valid index
|
||||
*/
|
||||
ares_status_t ares__buf_set_position(ares__buf_t *buf, size_t idx);
|
||||
|
||||
/*! Get the current offset within the internal buffer.
|
||||
*
|
||||
* Typically this should not be used, if possible, use the ares__buf_tag*()
|
||||
* operations instead.
|
||||
*
|
||||
* This can be used to get the current position, useful for saving if a
|
||||
* jump via ares__buf_set_position() is performed and need to restore the
|
||||
* current position for future operations.
|
||||
*
|
||||
* \param[in] buf Initialized buffer object
|
||||
* \return index of current position
|
||||
*/
|
||||
size_t ares__buf_get_position(const ares__buf_t *buf);
|
||||
|
||||
/*! Parse a character-string as defined in RFC1035, as a null-terminated
|
||||
* string.
|
||||
*
|
||||
* \param[in] buf initialized buffer object
|
||||
* \param[in] remaining_len maximum length that should be used for parsing
|
||||
* the string, this is often less than the remaining
|
||||
* buffer and is based on the RR record length.
|
||||
* \param[out] str Pointer passed by reference to be filled in with
|
||||
* allocated string of the parsed that must be
|
||||
* ares_free()'d by the caller.
|
||||
* \param[in] allow_multiple ARES_TRUE if it should attempt to parse multiple
|
||||
* strings back to back, and will concatenate in
|
||||
* the returned str.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
ares_status_t ares__buf_parse_dns_str(ares__buf_t *buf, size_t remaining_len,
|
||||
char **name, ares_bool_t allow_multiple);
|
||||
|
||||
/*! Parse a character-string as defined in RFC1035, as binary, however for
|
||||
* convenience this does guarantee a NULL terminator (that is not included
|
||||
* in the returned length).
|
||||
*
|
||||
* \param[in] buf initialized buffer object
|
||||
* \param[in] remaining_len maximum length that should be used for parsing
|
||||
* the string, this is often less than the remaining
|
||||
* buffer and is based on the RR record length.
|
||||
* \param[out] bin Pointer passed by reference to be filled in with
|
||||
* allocated string of the parsed that must be
|
||||
* ares_free()'d by the caller.
|
||||
* \param[out] bin_len Length of returned string.
|
||||
* \param[in] allow_multiple ARES_TRUE if it should attempt to parse multiple
|
||||
* strings back to back, and will concatenate in
|
||||
* the returned str.
|
||||
* \return ARES_SUCCESS on success
|
||||
*/
|
||||
ares_status_t ares__buf_parse_dns_binstr(ares__buf_t *buf, size_t remaining_len,
|
||||
unsigned char **bin, size_t *bin_len,
|
||||
ares_bool_t allow_multiple);
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__BUF_H */
|
||||
@ -1,61 +1,111 @@
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 1998 Massachusetts Institute of Technology
|
||||
* Copyright (c) The c-ares project and its contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include <assert.h>
|
||||
|
||||
void ares__close_sockets(ares_channel channel, struct server_state *server)
|
||||
static void ares__requeue_queries(struct server_connection *conn)
|
||||
{
|
||||
struct send_request *sendreq;
|
||||
struct query *query;
|
||||
struct timeval now = ares__tvnow();
|
||||
|
||||
/* Free all pending output buffers. */
|
||||
while (server->qhead)
|
||||
{
|
||||
/* Advance server->qhead; pull out query as we go. */
|
||||
sendreq = server->qhead;
|
||||
server->qhead = sendreq->next;
|
||||
if (sendreq->data_storage != NULL)
|
||||
ares_free(sendreq->data_storage);
|
||||
ares_free(sendreq);
|
||||
}
|
||||
server->qtail = NULL;
|
||||
|
||||
/* Reset any existing input buffer. */
|
||||
if (server->tcp_buffer)
|
||||
ares_free(server->tcp_buffer);
|
||||
server->tcp_buffer = NULL;
|
||||
server->tcp_lenbuf_pos = 0;
|
||||
|
||||
/* Reset brokenness */
|
||||
server->is_broken = 0;
|
||||
|
||||
/* Close the TCP and UDP sockets. */
|
||||
if (server->tcp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
SOCK_STATE_CALLBACK(channel, server->tcp_socket, 0, 0);
|
||||
ares__close_socket(channel, server->tcp_socket);
|
||||
server->tcp_socket = ARES_SOCKET_BAD;
|
||||
server->tcp_connection_generation = ++channel->tcp_connection_generation;
|
||||
}
|
||||
if (server->udp_socket != ARES_SOCKET_BAD)
|
||||
{
|
||||
SOCK_STATE_CALLBACK(channel, server->udp_socket, 0, 0);
|
||||
ares__close_socket(channel, server->udp_socket);
|
||||
server->udp_socket = ARES_SOCKET_BAD;
|
||||
}
|
||||
while ((query = ares__llist_first_val(conn->queries_to_conn)) != NULL) {
|
||||
ares__requeue_query(query, &now);
|
||||
}
|
||||
}
|
||||
|
||||
void ares__close_connection(struct server_connection *conn)
|
||||
{
|
||||
struct server_state *server = conn->server;
|
||||
ares_channel_t *channel = server->channel;
|
||||
|
||||
/* Unlink */
|
||||
ares__llist_node_claim(
|
||||
ares__htable_asvp_get_direct(channel->connnode_by_socket, conn->fd));
|
||||
ares__htable_asvp_remove(channel->connnode_by_socket, conn->fd);
|
||||
|
||||
if (conn->is_tcp) {
|
||||
/* Reset any existing input and output buffer. */
|
||||
ares__buf_consume(server->tcp_parser, ares__buf_len(server->tcp_parser));
|
||||
ares__buf_consume(server->tcp_send, ares__buf_len(server->tcp_send));
|
||||
server->tcp_conn = NULL;
|
||||
}
|
||||
|
||||
/* Requeue queries to other connections */
|
||||
ares__requeue_queries(conn);
|
||||
|
||||
ares__llist_destroy(conn->queries_to_conn);
|
||||
|
||||
SOCK_STATE_CALLBACK(channel, conn->fd, 0, 0);
|
||||
ares__close_socket(channel, conn->fd);
|
||||
|
||||
ares_free(conn);
|
||||
}
|
||||
|
||||
void ares__close_sockets(struct server_state *server)
|
||||
{
|
||||
ares__llist_node_t *node;
|
||||
|
||||
while ((node = ares__llist_node_first(server->connections)) != NULL) {
|
||||
struct server_connection *conn = ares__llist_node_val(node);
|
||||
ares__close_connection(conn);
|
||||
}
|
||||
}
|
||||
|
||||
void ares__check_cleanup_conn(const ares_channel_t *channel,
|
||||
struct server_connection *conn)
|
||||
{
|
||||
ares_bool_t do_cleanup = ARES_FALSE;
|
||||
|
||||
if (channel == NULL || conn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ares__llist_len(conn->queries_to_conn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we are configured not to stay open, close it out */
|
||||
if (!(channel->flags & ARES_FLAG_STAYOPEN)) {
|
||||
do_cleanup = ARES_TRUE;
|
||||
}
|
||||
|
||||
/* If the udp connection hit its max queries, always close it */
|
||||
if (!conn->is_tcp && channel->udp_max_queries > 0 &&
|
||||
conn->total_queries >= channel->udp_max_queries) {
|
||||
do_cleanup = ARES_TRUE;
|
||||
}
|
||||
|
||||
if (!do_cleanup) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__close_connection(conn);
|
||||
}
|
||||
|
||||
@ -1,260 +0,0 @@
|
||||
|
||||
/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_inet_net_pton.h"
|
||||
#include "ares_nowarn.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares__get_hostent(FILE *fp, int family, struct hostent **host)
|
||||
{
|
||||
char *line = NULL, *p, *q, **alias;
|
||||
char *txtaddr, *txthost, *txtalias;
|
||||
int status;
|
||||
size_t addrlen, linesize, naliases;
|
||||
struct ares_addr addr;
|
||||
struct hostent *hostent = NULL;
|
||||
|
||||
*host = NULL; /* Assume failure */
|
||||
|
||||
/* Validate family */
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
case AF_UNSPEC:
|
||||
break;
|
||||
default:
|
||||
return ARES_EBADFAMILY;
|
||||
}
|
||||
|
||||
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
|
||||
{
|
||||
|
||||
/* Trim line comment. */
|
||||
p = line;
|
||||
while (*p && (*p != '#'))
|
||||
p++;
|
||||
*p = '\0';
|
||||
|
||||
/* Trim trailing whitespace. */
|
||||
q = p - 1;
|
||||
while ((q >= line) && ISSPACE(*q))
|
||||
q--;
|
||||
*++q = '\0';
|
||||
|
||||
/* Skip leading whitespace. */
|
||||
p = line;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if empty. */
|
||||
continue;
|
||||
|
||||
/* Pointer to start of IPv4 or IPv6 address part. */
|
||||
txtaddr = p;
|
||||
|
||||
/* Advance past address part. */
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if reached end of line. */
|
||||
continue;
|
||||
|
||||
/* Null terminate address part. */
|
||||
*p = '\0';
|
||||
|
||||
/* Advance to host name */
|
||||
p++;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if reached end of line. */
|
||||
continue; /* LCOV_EXCL_LINE: trailing whitespace already stripped */
|
||||
|
||||
/* Pointer to start of host name. */
|
||||
txthost = p;
|
||||
|
||||
/* Advance past host name. */
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
|
||||
/* Pointer to start of first alias. */
|
||||
txtalias = NULL;
|
||||
if (*p)
|
||||
{
|
||||
q = p + 1;
|
||||
while (*q && ISSPACE(*q))
|
||||
q++;
|
||||
if (*q)
|
||||
txtalias = q;
|
||||
}
|
||||
|
||||
/* Null terminate host name. */
|
||||
*p = '\0';
|
||||
|
||||
/* find out number of aliases. */
|
||||
naliases = 0;
|
||||
if (txtalias)
|
||||
{
|
||||
p = txtalias;
|
||||
while (*p)
|
||||
{
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
naliases++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert address string to network address for the requested family. */
|
||||
addrlen = 0;
|
||||
addr.family = AF_UNSPEC;
|
||||
addr.addrV4.s_addr = INADDR_NONE;
|
||||
if ((family == AF_INET) || (family == AF_UNSPEC))
|
||||
{
|
||||
if (ares_inet_pton(AF_INET, txtaddr, &addr.addrV4) > 0)
|
||||
{
|
||||
/* Actual network address family and length. */
|
||||
addr.family = AF_INET;
|
||||
addrlen = sizeof(addr.addrV4);
|
||||
}
|
||||
}
|
||||
if ((family == AF_INET6) || ((family == AF_UNSPEC) && (!addrlen)))
|
||||
{
|
||||
if (ares_inet_pton(AF_INET6, txtaddr, &addr.addrV6) > 0)
|
||||
{
|
||||
/* Actual network address family and length. */
|
||||
addr.family = AF_INET6;
|
||||
addrlen = sizeof(addr.addrV6);
|
||||
}
|
||||
}
|
||||
if (!addrlen)
|
||||
/* Ignore line if invalid address string for the requested family. */
|
||||
continue;
|
||||
|
||||
/*
|
||||
** Actual address family possible values are AF_INET and AF_INET6 only.
|
||||
*/
|
||||
|
||||
/* Allocate memory for the hostent structure. */
|
||||
hostent = ares_malloc(sizeof(struct hostent));
|
||||
if (!hostent)
|
||||
break;
|
||||
|
||||
/* Initialize fields for out of memory condition. */
|
||||
hostent->h_aliases = NULL;
|
||||
hostent->h_addr_list = NULL;
|
||||
|
||||
/* Copy official host name. */
|
||||
hostent->h_name = ares_strdup(txthost);
|
||||
if (!hostent->h_name)
|
||||
break;
|
||||
|
||||
/* Copy network address. */
|
||||
hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
|
||||
if (!hostent->h_addr_list)
|
||||
break;
|
||||
hostent->h_addr_list[1] = NULL;
|
||||
hostent->h_addr_list[0] = ares_malloc(addrlen);
|
||||
if (!hostent->h_addr_list[0])
|
||||
break;
|
||||
if (addr.family == AF_INET)
|
||||
memcpy(hostent->h_addr_list[0], &addr.addrV4, sizeof(addr.addrV4));
|
||||
else
|
||||
memcpy(hostent->h_addr_list[0], &addr.addrV6, sizeof(addr.addrV6));
|
||||
|
||||
/* Copy aliases. */
|
||||
hostent->h_aliases = ares_malloc((naliases + 1) * sizeof(char *));
|
||||
if (!hostent->h_aliases)
|
||||
break;
|
||||
alias = hostent->h_aliases;
|
||||
while (naliases)
|
||||
*(alias + naliases--) = NULL;
|
||||
*alias = NULL;
|
||||
while (txtalias)
|
||||
{
|
||||
p = txtalias;
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
q = p;
|
||||
while (*q && ISSPACE(*q))
|
||||
q++;
|
||||
*p = '\0';
|
||||
if ((*alias = ares_strdup(txtalias)) == NULL)
|
||||
break;
|
||||
alias++;
|
||||
txtalias = *q ? q : NULL;
|
||||
}
|
||||
if (txtalias)
|
||||
/* Alias memory allocation failure. */
|
||||
break;
|
||||
|
||||
/* Copy actual network address family and length. */
|
||||
hostent->h_addrtype = aresx_sitoss(addr.family);
|
||||
hostent->h_length = aresx_uztoss(addrlen);
|
||||
|
||||
/* Free line buffer. */
|
||||
ares_free(line);
|
||||
|
||||
/* Return hostent successfully */
|
||||
*host = hostent;
|
||||
return ARES_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/* If allocated, free line buffer. */
|
||||
if (line)
|
||||
ares_free(line);
|
||||
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
/* Memory allocation failure; clean up. */
|
||||
if (hostent)
|
||||
{
|
||||
if (hostent->h_name)
|
||||
ares_free((char *) hostent->h_name);
|
||||
if (hostent->h_aliases)
|
||||
{
|
||||
for (alias = hostent->h_aliases; *alias; alias++)
|
||||
ares_free(*alias);
|
||||
ares_free(hostent->h_aliases);
|
||||
}
|
||||
if (hostent->h_addr_list)
|
||||
{
|
||||
if (hostent->h_addr_list[0])
|
||||
ares_free(hostent->h_addr_list[0]);
|
||||
ares_free(hostent->h_addr_list);
|
||||
}
|
||||
ares_free(hostent);
|
||||
}
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
1119
src/third_party/cares/dist/src/lib/ares__hosts_file.c
vendored
Normal file
1119
src/third_party/cares/dist/src/lib/ares__hosts_file.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
446
src/third_party/cares/dist/src/lib/ares__htable.c
vendored
Normal file
446
src/third_party/cares/dist/src/lib/ares__htable.c
vendored
Normal file
@ -0,0 +1,446 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include "ares__llist.h"
|
||||
#include "ares__htable.h"
|
||||
|
||||
#define ARES__HTABLE_MAX_BUCKETS (1U << 24)
|
||||
#define ARES__HTABLE_MIN_BUCKETS (1U << 4)
|
||||
#define ARES__HTABLE_EXPAND_PERCENT 75
|
||||
|
||||
struct ares__htable {
|
||||
ares__htable_hashfunc_t hash;
|
||||
ares__htable_bucket_key_t bucket_key;
|
||||
ares__htable_bucket_free_t bucket_free;
|
||||
ares__htable_key_eq_t key_eq;
|
||||
unsigned int seed;
|
||||
unsigned int size;
|
||||
size_t num_keys;
|
||||
size_t num_collisions;
|
||||
/* NOTE: if we converted buckets into ares__slist_t we could guarantee on
|
||||
* hash collisions we would have O(log n) worst case insert and search
|
||||
* performance. (We'd also need to make key_eq into a key_cmp to
|
||||
* support sort). That said, risk with a random hash seed is near zero,
|
||||
* and ares__slist_t is heavier weight, so I think using ares__llist_t
|
||||
* is an overall win. */
|
||||
ares__llist_t **buckets;
|
||||
};
|
||||
|
||||
static unsigned int ares__htable_generate_seed(ares__htable_t *htable)
|
||||
{
|
||||
unsigned int seed = 0;
|
||||
time_t t = time(NULL);
|
||||
|
||||
/* Mix stack address, heap address, and time to generate a random seed, it
|
||||
* doesn't have to be super secure, just quick. Likelihood of a hash
|
||||
* collision attack is very low with a small amount of effort */
|
||||
seed |= (unsigned int)((size_t)htable & 0xFFFFFFFF);
|
||||
seed |= (unsigned int)((size_t)&seed & 0xFFFFFFFF);
|
||||
seed |= (unsigned int)(t & 0xFFFFFFFF);
|
||||
return seed;
|
||||
}
|
||||
|
||||
static void ares__htable_buckets_destroy(ares__llist_t **buckets,
|
||||
unsigned int size,
|
||||
ares_bool_t destroy_vals)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (buckets == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (buckets[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!destroy_vals) {
|
||||
ares__llist_replace_destructor(buckets[i], NULL);
|
||||
}
|
||||
|
||||
ares__llist_destroy(buckets[i]);
|
||||
}
|
||||
|
||||
ares_free(buckets);
|
||||
}
|
||||
|
||||
void ares__htable_destroy(ares__htable_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return;
|
||||
}
|
||||
ares__htable_buckets_destroy(htable->buckets, htable->size, ARES_TRUE);
|
||||
ares_free(htable);
|
||||
}
|
||||
|
||||
ares__htable_t *ares__htable_create(ares__htable_hashfunc_t hash_func,
|
||||
ares__htable_bucket_key_t bucket_key,
|
||||
ares__htable_bucket_free_t bucket_free,
|
||||
ares__htable_key_eq_t key_eq)
|
||||
{
|
||||
ares__htable_t *htable = NULL;
|
||||
|
||||
if (hash_func == NULL || bucket_key == NULL || bucket_free == NULL ||
|
||||
key_eq == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable = ares_malloc_zero(sizeof(*htable));
|
||||
if (htable == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->hash = hash_func;
|
||||
htable->bucket_key = bucket_key;
|
||||
htable->bucket_free = bucket_free;
|
||||
htable->key_eq = key_eq;
|
||||
htable->seed = ares__htable_generate_seed(htable);
|
||||
htable->size = ARES__HTABLE_MIN_BUCKETS;
|
||||
htable->buckets = ares_malloc_zero(sizeof(*htable->buckets) * htable->size);
|
||||
|
||||
if (htable->buckets == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return htable;
|
||||
|
||||
fail:
|
||||
ares__htable_destroy(htable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const void **ares__htable_all_buckets(const ares__htable_t *htable, size_t *num)
|
||||
{
|
||||
const void **out = NULL;
|
||||
size_t cnt = 0;
|
||||
size_t i;
|
||||
|
||||
if (htable == NULL || num == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*num = 0;
|
||||
|
||||
out = ares_malloc_zero(sizeof(*out) * htable->num_keys);
|
||||
if (out == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < htable->size; i++) {
|
||||
ares__llist_node_t *node;
|
||||
for (node = ares__llist_node_first(htable->buckets[i]); node != NULL;
|
||||
node = ares__llist_node_next(node)) {
|
||||
out[cnt++] = ares__llist_node_val(node);
|
||||
}
|
||||
}
|
||||
|
||||
*num = cnt;
|
||||
return out;
|
||||
}
|
||||
|
||||
/*! Grabs the Hashtable index from the key and length. The h index is
|
||||
* the hash of the function reduced to the size of the bucket list.
|
||||
* We are doing "hash & (size - 1)" since we are guaranteeing a power of
|
||||
* 2 for size. This is equivalent to "hash % size", but should be more
|
||||
* efficient */
|
||||
#define HASH_IDX(h, key) h->hash(key, h->seed) & (h->size - 1)
|
||||
|
||||
static ares__llist_node_t *ares__htable_find(const ares__htable_t *htable,
|
||||
unsigned int idx, const void *key)
|
||||
{
|
||||
ares__llist_node_t *node = NULL;
|
||||
|
||||
for (node = ares__llist_node_first(htable->buckets[idx]); node != NULL;
|
||||
node = ares__llist_node_next(node)) {
|
||||
if (htable->key_eq(key, htable->bucket_key(ares__llist_node_val(node)))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static ares_bool_t ares__htable_expand(ares__htable_t *htable)
|
||||
{
|
||||
ares__llist_t **buckets = NULL;
|
||||
unsigned int old_size = htable->size;
|
||||
size_t i;
|
||||
ares__llist_t **prealloc_llist = NULL;
|
||||
size_t prealloc_llist_len = 0;
|
||||
ares_bool_t rv = ARES_FALSE;
|
||||
|
||||
/* Not a failure, just won't expand */
|
||||
if (old_size == ARES__HTABLE_MAX_BUCKETS) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
htable->size <<= 1;
|
||||
|
||||
/* We must pre-allocate all memory we'll need before moving entries to the
|
||||
* new hash array. Otherwise if there's a memory allocation failure in the
|
||||
* middle, we wouldn't be able to recover. */
|
||||
buckets = ares_malloc_zero(sizeof(*buckets) * htable->size);
|
||||
if (buckets == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* The maximum number of new llists we'll need is the number of collisions
|
||||
* that were recorded */
|
||||
prealloc_llist_len = htable->num_collisions;
|
||||
if (prealloc_llist_len) {
|
||||
prealloc_llist =
|
||||
ares_malloc_zero(sizeof(*prealloc_llist) * prealloc_llist_len);
|
||||
if (prealloc_llist == NULL) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < prealloc_llist_len; i++) {
|
||||
prealloc_llist[i] = ares__llist_create(htable->bucket_free);
|
||||
if (prealloc_llist[i] == NULL) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Iterate across all buckets and move the entries to the new buckets */
|
||||
htable->num_collisions = 0;
|
||||
for (i = 0; i < old_size; i++) {
|
||||
ares__llist_node_t *node;
|
||||
|
||||
/* Nothing in this bucket */
|
||||
if (htable->buckets[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Fast path optimization (most likely case), there is likely only a single
|
||||
* entry in both the source and destination, check for this to confirm and
|
||||
* if so, just move the bucket over */
|
||||
if (ares__llist_len(htable->buckets[i]) == 1) {
|
||||
const void *val = ares__llist_first_val(htable->buckets[i]);
|
||||
size_t idx = HASH_IDX(htable, htable->bucket_key(val));
|
||||
|
||||
if (buckets[idx] == NULL) {
|
||||
/* Swap! */
|
||||
buckets[idx] = htable->buckets[i];
|
||||
htable->buckets[i] = NULL;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Slow path, collisions */
|
||||
while ((node = ares__llist_node_first(htable->buckets[i])) != NULL) {
|
||||
const void *val = ares__llist_node_val(node);
|
||||
size_t idx = HASH_IDX(htable, htable->bucket_key(val));
|
||||
|
||||
/* Try fast path again as maybe we popped one collision off and the
|
||||
* next we can reuse the llist parent */
|
||||
if (buckets[idx] == NULL && ares__llist_len(htable->buckets[i]) == 1) {
|
||||
/* Swap! */
|
||||
buckets[idx] = htable->buckets[i];
|
||||
htable->buckets[i] = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Grab one off our preallocated list */
|
||||
if (buckets[idx] == NULL) {
|
||||
/* Silence static analysis, this isn't possible but it doesn't know */
|
||||
if (prealloc_llist == NULL || prealloc_llist_len == 0) {
|
||||
goto done;
|
||||
}
|
||||
buckets[idx] = prealloc_llist[prealloc_llist_len - 1];
|
||||
prealloc_llist_len--;
|
||||
} else {
|
||||
/* Collision occurred since the bucket wasn't empty */
|
||||
htable->num_collisions++;
|
||||
}
|
||||
|
||||
ares__llist_node_move_parent_first(node, buckets[idx]);
|
||||
}
|
||||
|
||||
/* Abandoned bucket, destroy */
|
||||
if (htable->buckets[i] != NULL) {
|
||||
ares__llist_destroy(htable->buckets[i]);
|
||||
htable->buckets[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* We have guaranteed all the buckets have either been moved or destroyed,
|
||||
* so we just call ares_free() on the array and swap out the pointer */
|
||||
ares_free(htable->buckets);
|
||||
htable->buckets = buckets;
|
||||
buckets = NULL;
|
||||
rv = ARES_TRUE;
|
||||
|
||||
done:
|
||||
ares_free(buckets);
|
||||
/* destroy any unused preallocated buckets */
|
||||
ares__htable_buckets_destroy(prealloc_llist, (unsigned int)prealloc_llist_len,
|
||||
ARES_FALSE);
|
||||
|
||||
/* On failure, we need to restore the htable size */
|
||||
if (rv != ARES_TRUE) {
|
||||
htable->size = old_size;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_insert(ares__htable_t *htable, void *bucket)
|
||||
{
|
||||
unsigned int idx = 0;
|
||||
ares__llist_node_t *node = NULL;
|
||||
const void *key = NULL;
|
||||
|
||||
if (htable == NULL || bucket == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
|
||||
key = htable->bucket_key(bucket);
|
||||
idx = HASH_IDX(htable, key);
|
||||
|
||||
/* See if we have a matching bucket already, if so, replace it */
|
||||
node = ares__htable_find(htable, idx, key);
|
||||
if (node != NULL) {
|
||||
ares__llist_node_replace(node, bucket);
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
/* Check to see if we should rehash because likelihood of collisions has
|
||||
* increased beyond our threshold */
|
||||
if (htable->num_keys + 1 >
|
||||
(htable->size * ARES__HTABLE_EXPAND_PERCENT) / 100) {
|
||||
if (!ares__htable_expand(htable)) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
/* If we expanded, need to calculate a new index */
|
||||
idx = HASH_IDX(htable, key);
|
||||
}
|
||||
|
||||
/* We lazily allocate the linked list */
|
||||
if (htable->buckets[idx] == NULL) {
|
||||
htable->buckets[idx] = ares__llist_create(htable->bucket_free);
|
||||
if (htable->buckets[idx] == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
node = ares__llist_insert_first(htable->buckets[idx], bucket);
|
||||
if (node == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
/* Track collisions for rehash stability */
|
||||
if (ares__llist_len(htable->buckets[idx]) > 1) {
|
||||
htable->num_collisions++;
|
||||
}
|
||||
|
||||
htable->num_keys++;
|
||||
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
void *ares__htable_get(const ares__htable_t *htable, const void *key)
|
||||
{
|
||||
unsigned int idx;
|
||||
|
||||
if (htable == NULL || key == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx = HASH_IDX(htable, key);
|
||||
|
||||
return ares__llist_node_val(ares__htable_find(htable, idx, key));
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_remove(ares__htable_t *htable, const void *key)
|
||||
{
|
||||
ares__llist_node_t *node;
|
||||
unsigned int idx;
|
||||
|
||||
if (htable == NULL || key == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
idx = HASH_IDX(htable, key);
|
||||
node = ares__htable_find(htable, idx, key);
|
||||
if (node == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
htable->num_keys--;
|
||||
|
||||
/* Reduce collisions */
|
||||
if (ares__llist_len(ares__llist_node_parent(node)) > 1) {
|
||||
htable->num_collisions--;
|
||||
}
|
||||
|
||||
ares__llist_node_destroy(node);
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
size_t ares__htable_num_keys(const ares__htable_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return htable->num_keys;
|
||||
}
|
||||
|
||||
unsigned int ares__htable_hash_FNV1a(const unsigned char *key, size_t key_len,
|
||||
unsigned int seed)
|
||||
{
|
||||
/* recommended seed is 2166136261U, but we don't want collisions */
|
||||
unsigned int hv = seed;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < key_len; i++) {
|
||||
hv ^= (unsigned int)key[i];
|
||||
/* hv *= 0x01000193 */
|
||||
hv += (hv << 1) + (hv << 4) + (hv << 7) + (hv << 8) + (hv << 24);
|
||||
}
|
||||
|
||||
return hv;
|
||||
}
|
||||
|
||||
/* Case insensitive version, meant for ASCII strings */
|
||||
unsigned int ares__htable_hash_FNV1a_casecmp(const unsigned char *key,
|
||||
size_t key_len, unsigned int seed)
|
||||
{
|
||||
/* recommended seed is 2166136261U, but we don't want collisions */
|
||||
unsigned int hv = seed;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < key_len; i++) {
|
||||
hv ^= (unsigned int)ares__tolower(key[i]);
|
||||
/* hv *= 0x01000193 */
|
||||
hv += (hv << 1) + (hv << 4) + (hv << 7) + (hv << 8) + (hv << 24);
|
||||
}
|
||||
|
||||
return hv;
|
||||
}
|
||||
176
src/third_party/cares/dist/src/lib/ares__htable.h
vendored
Normal file
176
src/third_party/cares/dist/src/lib/ares__htable.h
vendored
Normal file
@ -0,0 +1,176 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__HTABLE_H
|
||||
#define __ARES__HTABLE_H
|
||||
|
||||
|
||||
/*! \addtogroup ares__htable Base HashTable Data Structure
|
||||
*
|
||||
* This is a basic hashtable data structure that is meant to be wrapped
|
||||
* by a higher level implementation. This data structure is designed to
|
||||
* be callback-based in order to facilitate wrapping without needing to
|
||||
* worry about any underlying complexities of the hashtable implementation.
|
||||
*
|
||||
* This implementation supports automatic growing by powers of 2 when reaching
|
||||
* 75% capacity. A rehash will be performed on the expanded bucket list.
|
||||
*
|
||||
* Average time complexity:
|
||||
* - Insert: O(1)
|
||||
* - Search: O(1)
|
||||
* - Delete: O(1)
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct ares__htable;
|
||||
|
||||
/*! Opaque data type for generic hash table implementation */
|
||||
typedef struct ares__htable ares__htable_t;
|
||||
|
||||
/*! Callback for generating a hash of the key.
|
||||
*
|
||||
* \param[in] key pointer to key to be hashed
|
||||
* \param[in] seed randomly generated seed used by hash function.
|
||||
* value is specific to the hashtable instance
|
||||
* but otherwise will not change between calls.
|
||||
* \return hash
|
||||
*/
|
||||
typedef unsigned int (*ares__htable_hashfunc_t)(const void *key,
|
||||
unsigned int seed);
|
||||
|
||||
/*! Callback to free the bucket
|
||||
*
|
||||
* \param[in] bucket user provided bucket
|
||||
*/
|
||||
typedef void (*ares__htable_bucket_free_t)(void *bucket);
|
||||
|
||||
/*! Callback to extract the key from the user-provided bucket
|
||||
*
|
||||
* \param[in] bucket user provided bucket
|
||||
* \return pointer to key held in bucket
|
||||
*/
|
||||
typedef const void *(*ares__htable_bucket_key_t)(const void *bucket);
|
||||
|
||||
/*! Callback to compare two keys for equality
|
||||
*
|
||||
* \param[in] key1 first key
|
||||
* \param[in] key2 second key
|
||||
* \return ARES_TRUE if equal, ARES_FALSE if not
|
||||
*/
|
||||
typedef ares_bool_t (*ares__htable_key_eq_t)(const void *key1,
|
||||
const void *key2);
|
||||
|
||||
|
||||
/*! Destroy the initialized hashtable
|
||||
*
|
||||
* \param[in] initialized hashtable
|
||||
*/
|
||||
void ares__htable_destroy(ares__htable_t *htable);
|
||||
|
||||
/*! Create a new hashtable
|
||||
*
|
||||
* \param[in] hash_func Required. Callback for Hash function.
|
||||
* \param[in] bucket_key Required. Callback to extract key from bucket.
|
||||
* \param[in] bucket_free Required. Callback to free bucket.
|
||||
* \param[in] key_eq Required. Callback to check for key equality.
|
||||
* \return initialized hashtable. NULL if out of memory or misuse.
|
||||
*/
|
||||
ares__htable_t *ares__htable_create(ares__htable_hashfunc_t hash_func,
|
||||
ares__htable_bucket_key_t bucket_key,
|
||||
ares__htable_bucket_free_t bucket_free,
|
||||
ares__htable_key_eq_t key_eq);
|
||||
|
||||
/*! Count of keys from initialized hashtable
|
||||
*
|
||||
* \param[in] htable Initialized hashtable.
|
||||
* \return count of keys
|
||||
*/
|
||||
size_t ares__htable_num_keys(const ares__htable_t *htable);
|
||||
|
||||
/*! Retrieve an array of buckets from the hashtable. This is mainly used as
|
||||
* a helper for retrieving an array of keys.
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
* \param[out] num Count of returned buckets
|
||||
* \return Array of pointers to the buckets. These are internal pointers
|
||||
* to data within the hashtable, so if the key is removed, there
|
||||
* will be a dangling pointer. It is expected wrappers will make
|
||||
* such values safe by duplicating them.
|
||||
*/
|
||||
const void **ares__htable_all_buckets(const ares__htable_t *htable,
|
||||
size_t *num);
|
||||
|
||||
/*! Insert bucket into hashtable
|
||||
*
|
||||
* \param[in] htable Initialized hashtable.
|
||||
* \param[in] bucket User-provided bucket to insert. Takes "ownership". Not
|
||||
* allowed to be NULL.
|
||||
* \return ARES_TRUE on success, ARES_FALSE if out of memory
|
||||
*/
|
||||
ares_bool_t ares__htable_insert(ares__htable_t *htable, void *bucket);
|
||||
|
||||
/*! Retrieve bucket from hashtable based on key.
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
* \param[in] key Pointer to key to use for comparison.
|
||||
* \return matching bucket, or NULL if not found.
|
||||
*/
|
||||
void *ares__htable_get(const ares__htable_t *htable, const void *key);
|
||||
|
||||
/*! Remove bucket from hashtable by key
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
* \param[in] key Pointer to key to use for comparison
|
||||
* \return ARES_TRUE if found, ARES_FALSE if not found
|
||||
*/
|
||||
ares_bool_t ares__htable_remove(ares__htable_t *htable, const void *key);
|
||||
|
||||
/*! FNV1a hash algorithm. Can be used as underlying primitive for building
|
||||
* a wrapper hashtable.
|
||||
*
|
||||
* \param[in] key pointer to key
|
||||
* \param[in] key_len Length of key
|
||||
* \param[in] seed Seed for generating hash
|
||||
* \return hash value
|
||||
*/
|
||||
unsigned int ares__htable_hash_FNV1a(const unsigned char *key, size_t key_len,
|
||||
unsigned int seed);
|
||||
|
||||
/*! FNV1a hash algorithm, but converts all characters to lowercase before
|
||||
* hashing to make the hash case-insensitive. Can be used as underlying
|
||||
* primitive for building a wrapper hashtable. Used on string-based keys.
|
||||
*
|
||||
* \param[in] key pointer to key
|
||||
* \param[in] key_len Length of key
|
||||
* \param[in] seed Seed for generating hash
|
||||
* \return hash value
|
||||
*/
|
||||
unsigned int ares__htable_hash_FNV1a_casecmp(const unsigned char *key,
|
||||
size_t key_len, unsigned int seed);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__HTABLE_H */
|
||||
228
src/third_party/cares/dist/src/lib/ares__htable_asvp.c
vendored
Normal file
228
src/third_party/cares/dist/src/lib/ares__htable_asvp.c
vendored
Normal file
@ -0,0 +1,228 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include "ares__htable.h"
|
||||
#include "ares__htable_asvp.h"
|
||||
|
||||
struct ares__htable_asvp {
|
||||
ares__htable_asvp_val_free_t free_val;
|
||||
ares__htable_t *hash;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
ares_socket_t key;
|
||||
void *val;
|
||||
ares__htable_asvp_t *parent;
|
||||
} ares__htable_asvp_bucket_t;
|
||||
|
||||
void ares__htable_asvp_destroy(ares__htable_asvp_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__htable_destroy(htable->hash);
|
||||
ares_free(htable);
|
||||
}
|
||||
|
||||
static unsigned int hash_func(const void *key, unsigned int seed)
|
||||
{
|
||||
const ares_socket_t *arg = key;
|
||||
return ares__htable_hash_FNV1a((const unsigned char *)arg, sizeof(*arg),
|
||||
seed);
|
||||
}
|
||||
|
||||
static const void *bucket_key(const void *bucket)
|
||||
{
|
||||
const ares__htable_asvp_bucket_t *arg = bucket;
|
||||
return &arg->key;
|
||||
}
|
||||
|
||||
static void bucket_free(void *bucket)
|
||||
{
|
||||
ares__htable_asvp_bucket_t *arg = bucket;
|
||||
|
||||
if (arg->parent->free_val) {
|
||||
arg->parent->free_val(arg->val);
|
||||
}
|
||||
|
||||
ares_free(arg);
|
||||
}
|
||||
|
||||
static ares_bool_t key_eq(const void *key1, const void *key2)
|
||||
{
|
||||
const ares_socket_t *k1 = key1;
|
||||
const ares_socket_t *k2 = key2;
|
||||
|
||||
if (*k1 == *k2) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares__htable_asvp_t *
|
||||
ares__htable_asvp_create(ares__htable_asvp_val_free_t val_free)
|
||||
{
|
||||
ares__htable_asvp_t *htable = ares_malloc(sizeof(*htable));
|
||||
if (htable == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->hash =
|
||||
ares__htable_create(hash_func, bucket_key, bucket_free, key_eq);
|
||||
if (htable->hash == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->free_val = val_free;
|
||||
|
||||
return htable;
|
||||
|
||||
fail:
|
||||
if (htable) {
|
||||
ares__htable_destroy(htable->hash);
|
||||
ares_free(htable);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ares_socket_t *ares__htable_asvp_keys(const ares__htable_asvp_t *htable,
|
||||
size_t *num)
|
||||
{
|
||||
const void **buckets = NULL;
|
||||
size_t cnt = 0;
|
||||
ares_socket_t *out = NULL;
|
||||
size_t i;
|
||||
|
||||
if (htable == NULL || num == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*num = 0;
|
||||
|
||||
buckets = ares__htable_all_buckets(htable->hash, &cnt);
|
||||
if (buckets == NULL || cnt == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out = ares_malloc_zero(sizeof(*out) * cnt);
|
||||
if (out == NULL) {
|
||||
ares_free(buckets);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
out[i] = ((const ares__htable_asvp_bucket_t *)buckets[i])->key;
|
||||
}
|
||||
|
||||
ares_free(buckets);
|
||||
*num = cnt;
|
||||
return out;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_asvp_insert(ares__htable_asvp_t *htable,
|
||||
ares_socket_t key, void *val)
|
||||
{
|
||||
ares__htable_asvp_bucket_t *bucket = NULL;
|
||||
|
||||
if (htable == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bucket = ares_malloc(sizeof(*bucket));
|
||||
if (bucket == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bucket->parent = htable;
|
||||
bucket->key = key;
|
||||
bucket->val = val;
|
||||
|
||||
if (!ares__htable_insert(htable->hash, bucket)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ARES_TRUE;
|
||||
|
||||
fail:
|
||||
if (bucket) {
|
||||
ares_free(bucket);
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_asvp_get(const ares__htable_asvp_t *htable,
|
||||
ares_socket_t key, void **val)
|
||||
{
|
||||
ares__htable_asvp_bucket_t *bucket = NULL;
|
||||
|
||||
if (val) {
|
||||
*val = NULL;
|
||||
}
|
||||
|
||||
if (htable == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
bucket = ares__htable_get(htable->hash, &key);
|
||||
if (bucket == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
if (val) {
|
||||
*val = bucket->val;
|
||||
}
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
void *ares__htable_asvp_get_direct(const ares__htable_asvp_t *htable,
|
||||
ares_socket_t key)
|
||||
{
|
||||
void *val = NULL;
|
||||
ares__htable_asvp_get(htable, key, &val);
|
||||
return val;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_asvp_remove(ares__htable_asvp_t *htable,
|
||||
ares_socket_t key)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
return ares__htable_remove(htable->hash, &key);
|
||||
}
|
||||
|
||||
size_t ares__htable_asvp_num_keys(const ares__htable_asvp_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return ares__htable_num_keys(htable->hash);
|
||||
}
|
||||
130
src/third_party/cares/dist/src/lib/ares__htable_asvp.h
vendored
Normal file
130
src/third_party/cares/dist/src/lib/ares__htable_asvp.h
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__HTABLE_ASVP_H
|
||||
#define __ARES__HTABLE_ASVP_H
|
||||
|
||||
/*! \addtogroup ares__htable_asvp HashTable with ares_socket_t Key and
|
||||
* void pointer Value
|
||||
*
|
||||
* This data structure wraps the base ares__htable data structure in order to
|
||||
* split the key and value data types as ares_socket_t and void pointer,
|
||||
* respectively.
|
||||
*
|
||||
* Average time complexity:
|
||||
* - Insert: O(1)
|
||||
* - Search: O(1)
|
||||
* - Delete: O(1)
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct ares__htable_asvp;
|
||||
|
||||
/*! Opaque data type for ares_socket_t key, void pointer hash table
|
||||
* implementation */
|
||||
typedef struct ares__htable_asvp ares__htable_asvp_t;
|
||||
|
||||
/*! Callback to free value stored in hashtable
|
||||
*
|
||||
* \param[in] val user-supplied value
|
||||
*/
|
||||
typedef void (*ares__htable_asvp_val_free_t)(void *val);
|
||||
|
||||
/*! Destroy hashtable
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
*/
|
||||
void ares__htable_asvp_destroy(ares__htable_asvp_t *htable);
|
||||
|
||||
/*! Create size_t key, void pointer value hash table
|
||||
*
|
||||
* \param[in] val_free Optional. Call back to free user-supplied value. If
|
||||
* NULL it is expected the caller will clean up any user
|
||||
* supplied values.
|
||||
*/
|
||||
ares__htable_asvp_t *
|
||||
ares__htable_asvp_create(ares__htable_asvp_val_free_t val_free);
|
||||
|
||||
/*! Retrieve an array of keys from the hashtable.
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
* \param[out] num_keys Count of returned keys
|
||||
* \return Array of keys in the hashtable. Must be free'd with ares_free().
|
||||
*/
|
||||
ares_socket_t *ares__htable_asvp_keys(const ares__htable_asvp_t *htable,
|
||||
size_t *num);
|
||||
|
||||
|
||||
/*! Insert key/value into hash table
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to associate with value
|
||||
* \param[in] val value to store (takes ownership). May be NULL.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on out of memory or misuse
|
||||
*/
|
||||
ares_bool_t ares__htable_asvp_insert(ares__htable_asvp_t *htable,
|
||||
ares_socket_t key, void *val);
|
||||
|
||||
/*! Retrieve value from hashtable based on key
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \param[out] val Optional. Pointer to store value.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on failure
|
||||
*/
|
||||
ares_bool_t ares__htable_asvp_get(const ares__htable_asvp_t *htable,
|
||||
ares_socket_t key, void **val);
|
||||
|
||||
/*! Retrieve value from hashtable directly as return value. Caveat to this
|
||||
* function over ares__htable_asvp_get() is that if a NULL value is stored
|
||||
* you cannot determine if the key is not found or the value is NULL.
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \return value associated with key in hashtable or NULL
|
||||
*/
|
||||
void *ares__htable_asvp_get_direct(const ares__htable_asvp_t *htable,
|
||||
ares_socket_t key);
|
||||
|
||||
/*! Remove a value from the hashtable by key
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \return ARES_TRUE if found, ARES_FALSE if not found
|
||||
*/
|
||||
ares_bool_t ares__htable_asvp_remove(ares__htable_asvp_t *htable,
|
||||
ares_socket_t key);
|
||||
|
||||
/*! Retrieve the number of keys stored in the hash table
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \return count
|
||||
*/
|
||||
size_t ares__htable_asvp_num_keys(const ares__htable_asvp_t *htable);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__HTABLE_ASVP_H */
|
||||
198
src/third_party/cares/dist/src/lib/ares__htable_strvp.c
vendored
Normal file
198
src/third_party/cares/dist/src/lib/ares__htable_strvp.c
vendored
Normal file
@ -0,0 +1,198 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include "ares__htable.h"
|
||||
#include "ares__htable_strvp.h"
|
||||
|
||||
struct ares__htable_strvp {
|
||||
ares__htable_strvp_val_free_t free_val;
|
||||
ares__htable_t *hash;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *key;
|
||||
void *val;
|
||||
ares__htable_strvp_t *parent;
|
||||
} ares__htable_strvp_bucket_t;
|
||||
|
||||
void ares__htable_strvp_destroy(ares__htable_strvp_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__htable_destroy(htable->hash);
|
||||
ares_free(htable);
|
||||
}
|
||||
|
||||
static unsigned int hash_func(const void *key, unsigned int seed)
|
||||
{
|
||||
const char *arg = key;
|
||||
return ares__htable_hash_FNV1a_casecmp((const unsigned char *)arg,
|
||||
ares_strlen(arg), seed);
|
||||
}
|
||||
|
||||
static const void *bucket_key(const void *bucket)
|
||||
{
|
||||
const ares__htable_strvp_bucket_t *arg = bucket;
|
||||
return arg->key;
|
||||
}
|
||||
|
||||
static void bucket_free(void *bucket)
|
||||
{
|
||||
ares__htable_strvp_bucket_t *arg = bucket;
|
||||
|
||||
if (arg->parent->free_val) {
|
||||
arg->parent->free_val(arg->val);
|
||||
}
|
||||
ares_free(arg->key);
|
||||
ares_free(arg);
|
||||
}
|
||||
|
||||
static ares_bool_t key_eq(const void *key1, const void *key2)
|
||||
{
|
||||
const char *k1 = key1;
|
||||
const char *k2 = key2;
|
||||
|
||||
if (strcasecmp(k1, k2) == 0) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares__htable_strvp_t *
|
||||
ares__htable_strvp_create(ares__htable_strvp_val_free_t val_free)
|
||||
{
|
||||
ares__htable_strvp_t *htable = ares_malloc(sizeof(*htable));
|
||||
if (htable == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->hash =
|
||||
ares__htable_create(hash_func, bucket_key, bucket_free, key_eq);
|
||||
if (htable->hash == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->free_val = val_free;
|
||||
|
||||
return htable;
|
||||
|
||||
fail:
|
||||
if (htable) {
|
||||
ares__htable_destroy(htable->hash);
|
||||
ares_free(htable);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_strvp_insert(ares__htable_strvp_t *htable,
|
||||
const char *key, void *val)
|
||||
{
|
||||
ares__htable_strvp_bucket_t *bucket = NULL;
|
||||
|
||||
if (htable == NULL || key == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bucket = ares_malloc(sizeof(*bucket));
|
||||
if (bucket == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bucket->parent = htable;
|
||||
bucket->key = ares_strdup(key);
|
||||
if (bucket->key == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
bucket->val = val;
|
||||
|
||||
if (!ares__htable_insert(htable->hash, bucket)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ARES_TRUE;
|
||||
|
||||
fail:
|
||||
if (bucket) {
|
||||
ares_free(bucket->key);
|
||||
ares_free(bucket);
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_strvp_get(const ares__htable_strvp_t *htable,
|
||||
const char *key, void **val)
|
||||
{
|
||||
ares__htable_strvp_bucket_t *bucket = NULL;
|
||||
|
||||
if (val) {
|
||||
*val = NULL;
|
||||
}
|
||||
|
||||
if (htable == NULL || key == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
bucket = ares__htable_get(htable->hash, key);
|
||||
if (bucket == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
if (val) {
|
||||
*val = bucket->val;
|
||||
}
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
void *ares__htable_strvp_get_direct(const ares__htable_strvp_t *htable,
|
||||
const char *key)
|
||||
{
|
||||
void *val = NULL;
|
||||
ares__htable_strvp_get(htable, key, &val);
|
||||
return val;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_strvp_remove(ares__htable_strvp_t *htable,
|
||||
const char *key)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
return ares__htable_remove(htable->hash, key);
|
||||
}
|
||||
|
||||
size_t ares__htable_strvp_num_keys(const ares__htable_strvp_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return ares__htable_num_keys(htable->hash);
|
||||
}
|
||||
118
src/third_party/cares/dist/src/lib/ares__htable_strvp.h
vendored
Normal file
118
src/third_party/cares/dist/src/lib/ares__htable_strvp.h
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__HTABLE_STRVP_H
|
||||
#define __ARES__HTABLE_STRVP_H
|
||||
|
||||
/*! \addtogroup ares__htable_strvp HashTable with string Key and void pointer
|
||||
* Value
|
||||
*
|
||||
* This data structure wraps the base ares__htable data structure in order to
|
||||
* split the key and value data types as string and void pointer, respectively.
|
||||
*
|
||||
* Average time complexity:
|
||||
* - Insert: O(1)
|
||||
* - Search: O(1)
|
||||
* - Delete: O(1)
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct ares__htable_strvp;
|
||||
|
||||
/*! Opaque data type for size_t key, void pointer hash table implementation */
|
||||
typedef struct ares__htable_strvp ares__htable_strvp_t;
|
||||
|
||||
/*! Callback to free value stored in hashtable
|
||||
*
|
||||
* \param[in] val user-supplied value
|
||||
*/
|
||||
typedef void (*ares__htable_strvp_val_free_t)(void *val);
|
||||
|
||||
/*! Destroy hashtable
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
*/
|
||||
void ares__htable_strvp_destroy(ares__htable_strvp_t *htable);
|
||||
|
||||
/*! Create string, void pointer value hash table
|
||||
*
|
||||
* \param[in] val_free Optional. Call back to free user-supplied value. If
|
||||
* NULL it is expected the caller will clean up any user
|
||||
* supplied values.
|
||||
*/
|
||||
ares__htable_strvp_t *
|
||||
ares__htable_strvp_create(ares__htable_strvp_val_free_t val_free);
|
||||
|
||||
/*! Insert key/value into hash table
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to associate with value
|
||||
* \param[in] val value to store (takes ownership). May be NULL.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on failure or out of memory
|
||||
*/
|
||||
ares_bool_t ares__htable_strvp_insert(ares__htable_strvp_t *htable,
|
||||
const char *key, void *val);
|
||||
|
||||
/*! Retrieve value from hashtable based on key
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \param[out] val Optional. Pointer to store value.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on failure
|
||||
*/
|
||||
ares_bool_t ares__htable_strvp_get(const ares__htable_strvp_t *htable,
|
||||
const char *key, void **val);
|
||||
|
||||
/*! Retrieve value from hashtable directly as return value. Caveat to this
|
||||
* function over ares__htable_strvp_get() is that if a NULL value is stored
|
||||
* you cannot determine if the key is not found or the value is NULL.
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \return value associated with key in hashtable or NULL
|
||||
*/
|
||||
void *ares__htable_strvp_get_direct(const ares__htable_strvp_t *htable,
|
||||
const char *key);
|
||||
|
||||
/*! Remove a value from the hashtable by key
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \return ARES_TRUE if found, ARES_FALSE if not
|
||||
*/
|
||||
ares_bool_t ares__htable_strvp_remove(ares__htable_strvp_t *htable,
|
||||
const char *key);
|
||||
|
||||
/*! Retrieve the number of keys stored in the hash table
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \return count
|
||||
*/
|
||||
size_t ares__htable_strvp_num_keys(const ares__htable_strvp_t *htable);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__HTABLE_STVP_H */
|
||||
193
src/third_party/cares/dist/src/lib/ares__htable_szvp.c
vendored
Normal file
193
src/third_party/cares/dist/src/lib/ares__htable_szvp.c
vendored
Normal file
@ -0,0 +1,193 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include "ares__htable.h"
|
||||
#include "ares__htable_szvp.h"
|
||||
|
||||
struct ares__htable_szvp {
|
||||
ares__htable_szvp_val_free_t free_val;
|
||||
ares__htable_t *hash;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
size_t key;
|
||||
void *val;
|
||||
ares__htable_szvp_t *parent;
|
||||
} ares__htable_szvp_bucket_t;
|
||||
|
||||
void ares__htable_szvp_destroy(ares__htable_szvp_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__htable_destroy(htable->hash);
|
||||
ares_free(htable);
|
||||
}
|
||||
|
||||
static unsigned int hash_func(const void *key, unsigned int seed)
|
||||
{
|
||||
const size_t *arg = key;
|
||||
return ares__htable_hash_FNV1a((const unsigned char *)arg, sizeof(*arg),
|
||||
seed);
|
||||
}
|
||||
|
||||
static const void *bucket_key(const void *bucket)
|
||||
{
|
||||
const ares__htable_szvp_bucket_t *arg = bucket;
|
||||
return &arg->key;
|
||||
}
|
||||
|
||||
static void bucket_free(void *bucket)
|
||||
{
|
||||
ares__htable_szvp_bucket_t *arg = bucket;
|
||||
|
||||
if (arg->parent->free_val) {
|
||||
arg->parent->free_val(arg->val);
|
||||
}
|
||||
|
||||
ares_free(arg);
|
||||
}
|
||||
|
||||
static ares_bool_t key_eq(const void *key1, const void *key2)
|
||||
{
|
||||
const size_t *k1 = key1;
|
||||
const size_t *k2 = key2;
|
||||
|
||||
if (*k1 == *k2) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares__htable_szvp_t *
|
||||
ares__htable_szvp_create(ares__htable_szvp_val_free_t val_free)
|
||||
{
|
||||
ares__htable_szvp_t *htable = ares_malloc(sizeof(*htable));
|
||||
if (htable == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->hash =
|
||||
ares__htable_create(hash_func, bucket_key, bucket_free, key_eq);
|
||||
if (htable->hash == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
htable->free_val = val_free;
|
||||
|
||||
return htable;
|
||||
|
||||
fail:
|
||||
if (htable) {
|
||||
ares__htable_destroy(htable->hash);
|
||||
ares_free(htable);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_szvp_insert(ares__htable_szvp_t *htable, size_t key,
|
||||
void *val)
|
||||
{
|
||||
ares__htable_szvp_bucket_t *bucket = NULL;
|
||||
|
||||
if (htable == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bucket = ares_malloc(sizeof(*bucket));
|
||||
if (bucket == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
bucket->parent = htable;
|
||||
bucket->key = key;
|
||||
bucket->val = val;
|
||||
|
||||
if (!ares__htable_insert(htable->hash, bucket)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ARES_TRUE;
|
||||
|
||||
fail:
|
||||
if (bucket) {
|
||||
ares_free(bucket);
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_szvp_get(const ares__htable_szvp_t *htable, size_t key,
|
||||
void **val)
|
||||
{
|
||||
ares__htable_szvp_bucket_t *bucket = NULL;
|
||||
|
||||
if (val) {
|
||||
*val = NULL;
|
||||
}
|
||||
|
||||
if (htable == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
bucket = ares__htable_get(htable->hash, &key);
|
||||
if (bucket == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
if (val) {
|
||||
*val = bucket->val;
|
||||
}
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
void *ares__htable_szvp_get_direct(const ares__htable_szvp_t *htable,
|
||||
size_t key)
|
||||
{
|
||||
void *val = NULL;
|
||||
ares__htable_szvp_get(htable, key, &val);
|
||||
return val;
|
||||
}
|
||||
|
||||
ares_bool_t ares__htable_szvp_remove(ares__htable_szvp_t *htable, size_t key)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
return ares__htable_remove(htable->hash, &key);
|
||||
}
|
||||
|
||||
size_t ares__htable_szvp_num_keys(const ares__htable_szvp_t *htable)
|
||||
{
|
||||
if (htable == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return ares__htable_num_keys(htable->hash);
|
||||
}
|
||||
117
src/third_party/cares/dist/src/lib/ares__htable_szvp.h
vendored
Normal file
117
src/third_party/cares/dist/src/lib/ares__htable_szvp.h
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__HTABLE_STVP_H
|
||||
#define __ARES__HTABLE_STVP_H
|
||||
|
||||
/*! \addtogroup ares__htable_szvp HashTable with size_t Key and void pointer
|
||||
* Value
|
||||
*
|
||||
* This data structure wraps the base ares__htable data structure in order to
|
||||
* split the key and value data types as size_t and void pointer, respectively.
|
||||
*
|
||||
* Average time complexity:
|
||||
* - Insert: O(1)
|
||||
* - Search: O(1)
|
||||
* - Delete: O(1)
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct ares__htable_szvp;
|
||||
|
||||
/*! Opaque data type for size_t key, void pointer hash table implementation */
|
||||
typedef struct ares__htable_szvp ares__htable_szvp_t;
|
||||
|
||||
/*! Callback to free value stored in hashtable
|
||||
*
|
||||
* \param[in] val user-supplied value
|
||||
*/
|
||||
typedef void (*ares__htable_szvp_val_free_t)(void *val);
|
||||
|
||||
/*! Destroy hashtable
|
||||
*
|
||||
* \param[in] htable Initialized hashtable
|
||||
*/
|
||||
void ares__htable_szvp_destroy(ares__htable_szvp_t *htable);
|
||||
|
||||
/*! Create size_t key, void pointer value hash table
|
||||
*
|
||||
* \param[in] val_free Optional. Call back to free user-supplied value. If
|
||||
* NULL it is expected the caller will clean up any user
|
||||
* supplied values.
|
||||
*/
|
||||
ares__htable_szvp_t *
|
||||
ares__htable_szvp_create(ares__htable_szvp_val_free_t val_free);
|
||||
|
||||
/*! Insert key/value into hash table
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to associate with value
|
||||
* \param[in] val value to store (takes ownership). May be NULL.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on failure or out of memory
|
||||
*/
|
||||
ares_bool_t ares__htable_szvp_insert(ares__htable_szvp_t *htable, size_t key,
|
||||
void *val);
|
||||
|
||||
/*! Retrieve value from hashtable based on key
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \param[out] val Optional. Pointer to store value.
|
||||
* \return ARES_TRUE on success, ARES_FALSE on failure
|
||||
*/
|
||||
ares_bool_t ares__htable_szvp_get(const ares__htable_szvp_t *htable, size_t key,
|
||||
void **val);
|
||||
|
||||
/*! Retrieve value from hashtable directly as return value. Caveat to this
|
||||
* function over ares__htable_szvp_get() is that if a NULL value is stored
|
||||
* you cannot determine if the key is not found or the value is NULL.
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \return value associated with key in hashtable or NULL
|
||||
*/
|
||||
void *ares__htable_szvp_get_direct(const ares__htable_szvp_t *htable,
|
||||
size_t key);
|
||||
|
||||
/*! Remove a value from the hashtable by key
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \param[in] key key to use to search
|
||||
* \return ARES_TRUE if found, ARES_FALSE if not
|
||||
*/
|
||||
ares_bool_t ares__htable_szvp_remove(ares__htable_szvp_t *htable, size_t key);
|
||||
|
||||
/*! Retrieve the number of keys stored in the hash table
|
||||
*
|
||||
* \param[in] htable Initialized hash table
|
||||
* \return count
|
||||
*/
|
||||
size_t ares__htable_szvp_num_keys(const ares__htable_szvp_t *htable);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__HTABLE_STVP_H */
|
||||
592
src/third_party/cares/dist/src/lib/ares__iface_ips.c
vendored
Normal file
592
src/third_party/cares/dist/src/lib/ares__iface_ips.c
vendored
Normal file
@ -0,0 +1,592 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
# if defined(HAVE_IPHLPAPI_H)
|
||||
# include <iphlpapi.h>
|
||||
# endif
|
||||
# if defined(HAVE_NETIOAPI_H)
|
||||
# include <netioapi.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NET_IF_H
|
||||
# include <net/if.h>
|
||||
#endif
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
# include <ifaddrs.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips,
|
||||
const char *name);
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
struct ares_addr addr;
|
||||
unsigned char netmask;
|
||||
unsigned int ll_scope;
|
||||
ares__iface_ip_flags_t flags;
|
||||
} ares__iface_ip_t;
|
||||
|
||||
struct ares__iface_ips {
|
||||
ares__iface_ip_t *ips;
|
||||
size_t cnt;
|
||||
size_t alloc_size;
|
||||
ares__iface_ip_flags_t enum_flags;
|
||||
};
|
||||
|
||||
static ares__iface_ips_t *ares__iface_ips_alloc(ares__iface_ip_flags_t flags)
|
||||
{
|
||||
ares__iface_ips_t *ips = ares_malloc_zero(sizeof(*ips));
|
||||
if (ips == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Prealloc 4 entries */
|
||||
ips->alloc_size = 4;
|
||||
ips->ips = ares_malloc_zero(ips->alloc_size * sizeof(*ips->ips));
|
||||
if (ips->ips == NULL) {
|
||||
ares_free(ips);
|
||||
return NULL;
|
||||
}
|
||||
ips->enum_flags = flags;
|
||||
return ips;
|
||||
}
|
||||
|
||||
static void ares__iface_ip_destroy(ares__iface_ip_t *ip)
|
||||
{
|
||||
if (ip == NULL) {
|
||||
return;
|
||||
}
|
||||
ares_free(ip->name);
|
||||
memset(ip, 0, sizeof(*ip));
|
||||
}
|
||||
|
||||
void ares__iface_ips_destroy(ares__iface_ips_t *ips)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (ips == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < ips->cnt; i++) {
|
||||
ares__iface_ip_destroy(&ips->ips[i]);
|
||||
}
|
||||
ares_free(ips->ips);
|
||||
ares_free(ips);
|
||||
}
|
||||
|
||||
ares_status_t ares__iface_ips(ares__iface_ips_t **ips,
|
||||
ares__iface_ip_flags_t flags, const char *name)
|
||||
{
|
||||
ares_status_t status;
|
||||
|
||||
if (ips == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
*ips = ares__iface_ips_alloc(flags);
|
||||
if (*ips == NULL) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
status = ares__iface_ips_enumerate(*ips, name);
|
||||
if (status != ARES_SUCCESS) {
|
||||
ares__iface_ips_destroy(*ips);
|
||||
*ips = NULL;
|
||||
return status;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
static ares_status_t
|
||||
ares__iface_ips_add(ares__iface_ips_t *ips, ares__iface_ip_flags_t flags,
|
||||
const char *name, const struct ares_addr *addr,
|
||||
unsigned char netmask, unsigned int ll_scope)
|
||||
{
|
||||
size_t idx;
|
||||
|
||||
if (ips == NULL || name == NULL || addr == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
/* Don't want loopback */
|
||||
if (flags & ARES_IFACE_IP_LOOPBACK &&
|
||||
!(ips->enum_flags & ARES_IFACE_IP_LOOPBACK)) {
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
/* Don't want offline */
|
||||
if (flags & ARES_IFACE_IP_OFFLINE &&
|
||||
!(ips->enum_flags & ARES_IFACE_IP_OFFLINE)) {
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
/* Check for link-local */
|
||||
if (ares__addr_is_linklocal(addr)) {
|
||||
flags |= ARES_IFACE_IP_LINKLOCAL;
|
||||
}
|
||||
if (flags & ARES_IFACE_IP_LINKLOCAL &&
|
||||
!(ips->enum_flags & ARES_IFACE_IP_LINKLOCAL)) {
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
/* Set address flag based on address provided */
|
||||
if (addr->family == AF_INET) {
|
||||
flags |= ARES_IFACE_IP_V4;
|
||||
}
|
||||
|
||||
if (addr->family == AF_INET6) {
|
||||
flags |= ARES_IFACE_IP_V6;
|
||||
}
|
||||
|
||||
/* If they specified either v4 or v6 validate flags otherwise assume they
|
||||
* want to enumerate both */
|
||||
if (ips->enum_flags & (ARES_IFACE_IP_V4 | ARES_IFACE_IP_V6)) {
|
||||
if (flags & ARES_IFACE_IP_V4 && !(ips->enum_flags & ARES_IFACE_IP_V4)) {
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
if (flags & ARES_IFACE_IP_V6 && !(ips->enum_flags & ARES_IFACE_IP_V6)) {
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate more ips */
|
||||
if (ips->cnt + 1 > ips->alloc_size) {
|
||||
void *temp;
|
||||
size_t alloc_size;
|
||||
|
||||
alloc_size = ares__round_up_pow2(ips->alloc_size + 1);
|
||||
temp = ares_realloc_zero(ips->ips, ips->alloc_size * sizeof(*ips->ips),
|
||||
alloc_size * sizeof(*ips->ips));
|
||||
if (temp == NULL) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
ips->ips = temp;
|
||||
ips->alloc_size = alloc_size;
|
||||
}
|
||||
|
||||
/* Add */
|
||||
idx = ips->cnt++;
|
||||
|
||||
ips->ips[idx].flags = flags;
|
||||
ips->ips[idx].netmask = netmask;
|
||||
ips->ips[idx].ll_scope = ll_scope;
|
||||
memcpy(&ips->ips[idx].addr, addr, sizeof(*addr));
|
||||
ips->ips[idx].name = ares_strdup(name);
|
||||
if (ips->ips[idx].name == NULL) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
size_t ares__iface_ips_cnt(const ares__iface_ips_t *ips)
|
||||
{
|
||||
if (ips == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return ips->cnt;
|
||||
}
|
||||
|
||||
const char *ares__iface_ips_get_name(const ares__iface_ips_t *ips, size_t idx)
|
||||
{
|
||||
if (ips == NULL || idx >= ips->cnt) {
|
||||
return NULL;
|
||||
}
|
||||
return ips->ips[idx].name;
|
||||
}
|
||||
|
||||
const struct ares_addr *ares__iface_ips_get_addr(const ares__iface_ips_t *ips,
|
||||
size_t idx)
|
||||
{
|
||||
if (ips == NULL || idx >= ips->cnt) {
|
||||
return NULL;
|
||||
}
|
||||
return &ips->ips[idx].addr;
|
||||
}
|
||||
|
||||
ares__iface_ip_flags_t ares__iface_ips_get_flags(const ares__iface_ips_t *ips,
|
||||
size_t idx)
|
||||
{
|
||||
if (ips == NULL || idx >= ips->cnt) {
|
||||
return 0;
|
||||
}
|
||||
return ips->ips[idx].flags;
|
||||
}
|
||||
|
||||
unsigned char ares__iface_ips_get_netmask(const ares__iface_ips_t *ips,
|
||||
size_t idx)
|
||||
{
|
||||
if (ips == NULL || idx >= ips->cnt) {
|
||||
return 0;
|
||||
}
|
||||
return ips->ips[idx].netmask;
|
||||
}
|
||||
|
||||
unsigned int ares__iface_ips_get_ll_scope(const ares__iface_ips_t *ips,
|
||||
size_t idx)
|
||||
{
|
||||
if (ips == NULL || idx >= ips->cnt) {
|
||||
return 0;
|
||||
}
|
||||
return ips->ips[idx].ll_scope;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
|
||||
# if 0
|
||||
static char *wcharp_to_charp(const wchar_t *in)
|
||||
{
|
||||
char *out;
|
||||
int len;
|
||||
|
||||
len = WideCharToMultiByte(CP_UTF8, 0, in, -1, NULL, 0, NULL, NULL);
|
||||
if (len == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
out = ares_malloc_zero((size_t)len + 1);
|
||||
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, in, -1, out, len, NULL, NULL) == -1) {
|
||||
ares_free(out);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
# endif
|
||||
|
||||
static ares_bool_t name_match(const char *name, const char *adapter_name,
|
||||
unsigned int ll_scope)
|
||||
{
|
||||
if (name == NULL || *name == 0) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
if (strcasecmp(name, adapter_name) == 0) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
if (ares_str_isnum(name) && (unsigned int)atoi(name) == ll_scope) {
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips,
|
||||
const char *name)
|
||||
{
|
||||
ULONG myflags = GAA_FLAG_INCLUDE_PREFIX /*|GAA_FLAG_INCLUDE_ALL_INTERFACES */;
|
||||
ULONG outBufLen = 0;
|
||||
DWORD retval;
|
||||
IP_ADAPTER_ADDRESSES *addresses = NULL;
|
||||
IP_ADAPTER_ADDRESSES *address = NULL;
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
|
||||
/* Get necessary buffer size */
|
||||
GetAdaptersAddresses(AF_UNSPEC, myflags, NULL, NULL, &outBufLen);
|
||||
if (outBufLen == 0) {
|
||||
status = ARES_EFILE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
addresses = ares_malloc_zero(outBufLen);
|
||||
if (addresses == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
retval =
|
||||
GetAdaptersAddresses(AF_UNSPEC, myflags, NULL, addresses, &outBufLen);
|
||||
if (retval != ERROR_SUCCESS) {
|
||||
status = ARES_EFILE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (address = addresses; address != NULL; address = address->Next) {
|
||||
IP_ADAPTER_UNICAST_ADDRESS *ipaddr = NULL;
|
||||
ares__iface_ip_flags_t addrflag = 0;
|
||||
char ifname[64] = "";
|
||||
|
||||
# if defined(HAVE_CONVERTINTERFACEINDEXTOLUID) && \
|
||||
defined(HAVE_CONVERTINTERFACELUIDTONAMEA)
|
||||
/* Retrieve name from interface index.
|
||||
* address->AdapterName appears to be a GUID/UUID of some sort, not a name.
|
||||
* address->FriendlyName is user-changeable.
|
||||
* That said, this doesn't appear to help us out on systems that don't
|
||||
* have if_nametoindex() or if_indextoname() as they don't have these
|
||||
* functions either! */
|
||||
NET_LUID luid;
|
||||
ConvertInterfaceIndexToLuid(address->IfIndex, &luid);
|
||||
ConvertInterfaceLuidToNameA(&luid, ifname, sizeof(ifname));
|
||||
# else
|
||||
ares_strcpy(ifname, address->AdapterName, sizeof(ifname));
|
||||
# endif
|
||||
|
||||
if (address->OperStatus != IfOperStatusUp) {
|
||||
addrflag |= ARES_IFACE_IP_OFFLINE;
|
||||
}
|
||||
|
||||
if (address->IfType == IF_TYPE_SOFTWARE_LOOPBACK) {
|
||||
addrflag |= ARES_IFACE_IP_LOOPBACK;
|
||||
}
|
||||
|
||||
for (ipaddr = address->FirstUnicastAddress; ipaddr != NULL;
|
||||
ipaddr = ipaddr->Next) {
|
||||
struct ares_addr addr;
|
||||
|
||||
if (ipaddr->Address.lpSockaddr->sa_family == AF_INET) {
|
||||
const struct sockaddr_in *sockaddr_in =
|
||||
(const struct sockaddr_in *)((void *)ipaddr->Address.lpSockaddr);
|
||||
addr.family = AF_INET;
|
||||
memcpy(&addr.addr.addr4, &sockaddr_in->sin_addr,
|
||||
sizeof(addr.addr.addr4));
|
||||
} else if (ipaddr->Address.lpSockaddr->sa_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *sockaddr_in6 =
|
||||
(const struct sockaddr_in6 *)((void *)ipaddr->Address.lpSockaddr);
|
||||
addr.family = AF_INET6;
|
||||
memcpy(&addr.addr.addr6, &sockaddr_in6->sin6_addr,
|
||||
sizeof(addr.addr.addr6));
|
||||
} else {
|
||||
/* Unknown */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Sometimes windows may use numerics to indicate a DNS server's adapter,
|
||||
* which corresponds to the index rather than the name. Check and
|
||||
* validate both. */
|
||||
if (!name_match(name, ifname, address->Ipv6IfIndex)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
status = ares__iface_ips_add(ips, addrflag, ifname, &addr,
|
||||
ipaddr->OnLinkPrefixLength /* netmask */,
|
||||
address->Ipv6IfIndex /* ll_scope */);
|
||||
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
ares_free(addresses);
|
||||
return status;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_GETIFADDRS)
|
||||
|
||||
static unsigned char count_addr_bits(const unsigned char *addr, size_t addr_len)
|
||||
{
|
||||
size_t i;
|
||||
unsigned char count = 0;
|
||||
|
||||
for (i = 0; i < addr_len; i++) {
|
||||
count += ares__count_bits_u8(addr[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips,
|
||||
const char *name)
|
||||
{
|
||||
struct ifaddrs *ifap = NULL;
|
||||
struct ifaddrs *ifa = NULL;
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
|
||||
if (getifaddrs(&ifap) != 0) {
|
||||
status = ARES_EFILE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
||||
ares__iface_ip_flags_t addrflag = 0;
|
||||
struct ares_addr addr;
|
||||
unsigned char netmask = 0;
|
||||
unsigned int ll_scope = 0;
|
||||
|
||||
if (ifa->ifa_addr == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(ifa->ifa_flags & IFF_UP)) {
|
||||
addrflag |= ARES_IFACE_IP_OFFLINE;
|
||||
}
|
||||
|
||||
if (ifa->ifa_flags & IFF_LOOPBACK) {
|
||||
addrflag |= ARES_IFACE_IP_LOOPBACK;
|
||||
}
|
||||
|
||||
if (ifa->ifa_addr->sa_family == AF_INET) {
|
||||
const struct sockaddr_in *sockaddr_in =
|
||||
(const struct sockaddr_in *)((void *)ifa->ifa_addr);
|
||||
addr.family = AF_INET;
|
||||
memcpy(&addr.addr.addr4, &sockaddr_in->sin_addr, sizeof(addr.addr.addr4));
|
||||
/* netmask */
|
||||
sockaddr_in = (struct sockaddr_in *)((void *)ifa->ifa_netmask);
|
||||
netmask = count_addr_bits((const void *)&sockaddr_in->sin_addr, 4);
|
||||
} else if (ifa->ifa_addr->sa_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *sockaddr_in6 =
|
||||
(const struct sockaddr_in6 *)((void *)ifa->ifa_addr);
|
||||
addr.family = AF_INET6;
|
||||
memcpy(&addr.addr.addr6, &sockaddr_in6->sin6_addr,
|
||||
sizeof(addr.addr.addr6));
|
||||
/* netmask */
|
||||
sockaddr_in6 = (struct sockaddr_in6 *)((void *)ifa->ifa_netmask);
|
||||
netmask = count_addr_bits((const void *)&sockaddr_in6->sin6_addr, 16);
|
||||
# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
ll_scope = sockaddr_in6->sin6_scope_id;
|
||||
# endif
|
||||
} else {
|
||||
/* unknown */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Name mismatch */
|
||||
if (strcasecmp(ifa->ifa_name, name) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
status = ares__iface_ips_add(ips, addrflag, ifa->ifa_name, &addr, netmask,
|
||||
ll_scope);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
freeifaddrs(ifap);
|
||||
return status;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static ares_status_t ares__iface_ips_enumerate(ares__iface_ips_t *ips,
|
||||
const char *name)
|
||||
{
|
||||
(void)ips;
|
||||
(void)name;
|
||||
return ARES_ENOTIMP;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
unsigned int ares__if_nametoindex(const char *name)
|
||||
{
|
||||
#ifdef HAVE_IF_NAMETOINDEX
|
||||
return if_nametoindex(name);
|
||||
#else
|
||||
ares_status_t status;
|
||||
ares__iface_ips_t *ips = NULL;
|
||||
size_t i;
|
||||
unsigned int index = 0;
|
||||
|
||||
status =
|
||||
ares__iface_ips(&ips, ARES_IFACE_IP_V6 | ARES_IFACE_IP_LINKLOCAL, name);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < ares__iface_ips_cnt(ips); i++) {
|
||||
if (ares__iface_ips_get_flags(ips, i) & ARES_IFACE_IP_LINKLOCAL) {
|
||||
index = ares__iface_ips_get_ll_scope(ips, i);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
ares__iface_ips_destroy(ips);
|
||||
return index;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *ares__if_indextoname(unsigned int index, char *name,
|
||||
size_t name_len)
|
||||
{
|
||||
#ifdef HAVE_IF_INDEXTONAME
|
||||
if (name_len < IF_NAMESIZE) {
|
||||
return NULL;
|
||||
}
|
||||
return if_indextoname(index, name);
|
||||
#else
|
||||
ares_status_t status;
|
||||
ares__iface_ips_t *ips = NULL;
|
||||
size_t i;
|
||||
const char *ptr = NULL;
|
||||
|
||||
if (name_len < IF_NAMESIZE) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
status =
|
||||
ares__iface_ips(&ips, ARES_IFACE_IP_V6 | ARES_IFACE_IP_LINKLOCAL, NULL);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < ares__iface_ips_cnt(ips); i++) {
|
||||
if (ares__iface_ips_get_flags(ips, i) & ARES_IFACE_IP_LINKLOCAL &&
|
||||
ares__iface_ips_get_ll_scope(ips, i) == index) {
|
||||
ares_strcpy(name, ares__iface_ips_get_name(ips, i), name_len);
|
||||
ptr = name;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
ares__iface_ips_destroy(ips);
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
139
src/third_party/cares/dist/src/lib/ares__iface_ips.h
vendored
Normal file
139
src/third_party/cares/dist/src/lib/ares__iface_ips.h
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__IFACE_IPS_H
|
||||
#define __ARES__IFACE_IPS_H
|
||||
|
||||
/*! Flags for interface ip addresses. */
|
||||
typedef enum {
|
||||
ARES_IFACE_IP_V4 = 1 << 0, /*!< IPv4 address. During enumeration if
|
||||
* this flag is set ARES_IFACE_IP_V6
|
||||
* is not, will only enumerate v4
|
||||
* addresses. */
|
||||
ARES_IFACE_IP_V6 = 1 << 1, /*!< IPv6 address. During enumeration if
|
||||
* this flag is set ARES_IFACE_IP_V4
|
||||
* is not, will only enumerate v6
|
||||
* addresses. */
|
||||
ARES_IFACE_IP_LOOPBACK = 1 << 2, /*!< Loopback adapter */
|
||||
ARES_IFACE_IP_OFFLINE = 1 << 3, /*!< Adapter offline */
|
||||
ARES_IFACE_IP_LINKLOCAL = 1 << 4, /*!< Link-local ip address */
|
||||
/*! Default, enumerate all ips for online interfaces, including loopback */
|
||||
ARES_IFACE_IP_DEFAULT = (ARES_IFACE_IP_V4 | ARES_IFACE_IP_V6 |
|
||||
ARES_IFACE_IP_LOOPBACK | ARES_IFACE_IP_LINKLOCAL)
|
||||
} ares__iface_ip_flags_t;
|
||||
|
||||
struct ares__iface_ips;
|
||||
|
||||
/*! Opaque pointer for holding enumerated interface ip addresses */
|
||||
typedef struct ares__iface_ips ares__iface_ips_t;
|
||||
|
||||
/*! Destroy ip address enumeration created by ares__iface_ips().
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
*/
|
||||
void ares__iface_ips_destroy(ares__iface_ips_t *ips);
|
||||
|
||||
/*! Enumerate ip addresses on interfaces
|
||||
*
|
||||
* \param[out] ips Returns initialized ip address structure
|
||||
* \param[in] flags Flags for enumeration
|
||||
* \param[in] name Interface name to enumerate, or NULL to enumerate all
|
||||
* \return ARES_ENOMEM on out of memory, ARES_ENOTIMP if not supported on
|
||||
* the system, ARES_SUCCESS on success
|
||||
*/
|
||||
ares_status_t ares__iface_ips(ares__iface_ips_t **ips,
|
||||
ares__iface_ip_flags_t flags, const char *name);
|
||||
|
||||
/*! Count of ips enumerated
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
* \return count
|
||||
*/
|
||||
size_t ares__iface_ips_cnt(const ares__iface_ips_t *ips);
|
||||
|
||||
/*! Retrieve interface name
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
* \param[in] idx Index of entry to pull
|
||||
* \return interface name
|
||||
*/
|
||||
const char *ares__iface_ips_get_name(const ares__iface_ips_t *ips, size_t idx);
|
||||
|
||||
/*! Retrieve interface address
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
* \param[in] idx Index of entry to pull
|
||||
* \return interface address
|
||||
*/
|
||||
const struct ares_addr *ares__iface_ips_get_addr(const ares__iface_ips_t *ips,
|
||||
size_t idx);
|
||||
|
||||
/*! Retrieve interface address flags
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
* \param[in] idx Index of entry to pull
|
||||
* \return interface address flags
|
||||
*/
|
||||
ares__iface_ip_flags_t ares__iface_ips_get_flags(const ares__iface_ips_t *ips,
|
||||
size_t idx);
|
||||
|
||||
/*! Retrieve interface address netmask
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
* \param[in] idx Index of entry to pull
|
||||
* \return interface address netmask
|
||||
*/
|
||||
unsigned char ares__iface_ips_get_netmask(const ares__iface_ips_t *ips,
|
||||
size_t idx);
|
||||
|
||||
/*! Retrieve interface ipv6 link local scope
|
||||
*
|
||||
* \param[in] ips Initialized IP address enumeration structure
|
||||
* \param[in] idx Index of entry to pull
|
||||
* \return interface ipv6 link local scope
|
||||
*/
|
||||
unsigned int ares__iface_ips_get_ll_scope(const ares__iface_ips_t *ips,
|
||||
size_t idx);
|
||||
|
||||
|
||||
/*! Retrieve the interface index (aka link local scope) from the interface
|
||||
* name.
|
||||
*
|
||||
* \param[in] name Interface name
|
||||
* \return 0 on failure, index otherwise
|
||||
*/
|
||||
unsigned int ares__if_nametoindex(const char *name);
|
||||
|
||||
/*! Retrieves the interface name from the index (aka link local scope)
|
||||
*
|
||||
* \param[in] index Interface index (> 0)
|
||||
* \param[in] name Buffer to hold name
|
||||
* \param[in] name_len Length of provided buffer, must be at least IF_NAMESIZE
|
||||
* \return NULL on failure, or pointer to name on success
|
||||
*/
|
||||
const char *ares__if_indextoname(unsigned int index, char *name,
|
||||
size_t name_len);
|
||||
|
||||
#endif
|
||||
360
src/third_party/cares/dist/src/lib/ares__llist.c
vendored
Normal file
360
src/third_party/cares/dist/src/lib/ares__llist.c
vendored
Normal file
@ -0,0 +1,360 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include "ares__llist.h"
|
||||
|
||||
struct ares__llist {
|
||||
ares__llist_node_t *head;
|
||||
ares__llist_node_t *tail;
|
||||
ares__llist_destructor_t destruct;
|
||||
size_t cnt;
|
||||
};
|
||||
|
||||
struct ares__llist_node {
|
||||
void *data;
|
||||
ares__llist_node_t *prev;
|
||||
ares__llist_node_t *next;
|
||||
ares__llist_t *parent;
|
||||
};
|
||||
|
||||
ares__llist_t *ares__llist_create(ares__llist_destructor_t destruct)
|
||||
{
|
||||
ares__llist_t *list = ares_malloc_zero(sizeof(*list));
|
||||
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->destruct = destruct;
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void ares__llist_replace_destructor(ares__llist_t *list,
|
||||
ares__llist_destructor_t destruct)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
list->destruct = destruct;
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
ARES__LLIST_INSERT_HEAD,
|
||||
ARES__LLIST_INSERT_TAIL,
|
||||
ARES__LLIST_INSERT_BEFORE
|
||||
} ares__llist_insert_type_t;
|
||||
|
||||
static void ares__llist_attach_at(ares__llist_t *list,
|
||||
ares__llist_insert_type_t type,
|
||||
ares__llist_node_t *at,
|
||||
ares__llist_node_t *node)
|
||||
{
|
||||
if (list == NULL || node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
node->parent = list;
|
||||
|
||||
if (type == ARES__LLIST_INSERT_BEFORE && (at == list->head || at == NULL)) {
|
||||
type = ARES__LLIST_INSERT_HEAD;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case ARES__LLIST_INSERT_HEAD:
|
||||
node->next = list->head;
|
||||
node->prev = NULL;
|
||||
if (list->head) {
|
||||
list->head->prev = node;
|
||||
}
|
||||
list->head = node;
|
||||
break;
|
||||
case ARES__LLIST_INSERT_TAIL:
|
||||
node->next = NULL;
|
||||
node->prev = list->tail;
|
||||
if (list->tail) {
|
||||
list->tail->next = node;
|
||||
}
|
||||
list->tail = node;
|
||||
break;
|
||||
case ARES__LLIST_INSERT_BEFORE:
|
||||
node->next = at;
|
||||
node->prev = at->prev;
|
||||
at->prev = node;
|
||||
break;
|
||||
}
|
||||
if (list->tail == NULL) {
|
||||
list->tail = node;
|
||||
}
|
||||
if (list->head == NULL) {
|
||||
list->head = node;
|
||||
}
|
||||
|
||||
list->cnt++;
|
||||
}
|
||||
|
||||
static ares__llist_node_t *ares__llist_insert_at(ares__llist_t *list,
|
||||
ares__llist_insert_type_t type,
|
||||
ares__llist_node_t *at,
|
||||
void *val)
|
||||
{
|
||||
ares__llist_node_t *node = NULL;
|
||||
|
||||
if (list == NULL || val == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = ares_malloc_zero(sizeof(*node));
|
||||
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node->data = val;
|
||||
ares__llist_attach_at(list, type, at, node);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_insert_first(ares__llist_t *list, void *val)
|
||||
{
|
||||
return ares__llist_insert_at(list, ARES__LLIST_INSERT_HEAD, NULL, val);
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_insert_last(ares__llist_t *list, void *val)
|
||||
{
|
||||
return ares__llist_insert_at(list, ARES__LLIST_INSERT_TAIL, NULL, val);
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_insert_before(ares__llist_node_t *node,
|
||||
void *val)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ares__llist_insert_at(node->parent, ARES__LLIST_INSERT_BEFORE, node,
|
||||
val);
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_insert_after(ares__llist_node_t *node,
|
||||
void *val)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (node->next == NULL) {
|
||||
return ares__llist_insert_last(node->parent, val);
|
||||
}
|
||||
|
||||
return ares__llist_insert_at(node->parent, ARES__LLIST_INSERT_BEFORE,
|
||||
node->next, val);
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_node_first(ares__llist_t *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return list->head;
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_node_last(ares__llist_t *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return list->tail;
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_node_next(ares__llist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return node->next;
|
||||
}
|
||||
|
||||
ares__llist_node_t *ares__llist_node_prev(ares__llist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return node->prev;
|
||||
}
|
||||
|
||||
void *ares__llist_node_val(ares__llist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return node->data;
|
||||
}
|
||||
|
||||
size_t ares__llist_len(const ares__llist_t *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return list->cnt;
|
||||
}
|
||||
|
||||
ares__llist_t *ares__llist_node_parent(ares__llist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return node->parent;
|
||||
}
|
||||
|
||||
void *ares__llist_first_val(ares__llist_t *list)
|
||||
{
|
||||
return ares__llist_node_val(ares__llist_node_first(list));
|
||||
}
|
||||
|
||||
void *ares__llist_last_val(ares__llist_t *list)
|
||||
{
|
||||
return ares__llist_node_val(ares__llist_node_last(list));
|
||||
}
|
||||
|
||||
static void ares__llist_node_detach(ares__llist_node_t *node)
|
||||
{
|
||||
ares__llist_t *list;
|
||||
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
list = node->parent;
|
||||
|
||||
if (node->prev) {
|
||||
node->prev->next = node->next;
|
||||
}
|
||||
|
||||
if (node->next) {
|
||||
node->next->prev = node->prev;
|
||||
}
|
||||
|
||||
if (node == list->head) {
|
||||
list->head = node->next;
|
||||
}
|
||||
|
||||
if (node == list->tail) {
|
||||
list->tail = node->prev;
|
||||
}
|
||||
|
||||
node->parent = NULL;
|
||||
list->cnt--;
|
||||
}
|
||||
|
||||
void *ares__llist_node_claim(ares__llist_node_t *node)
|
||||
{
|
||||
void *val;
|
||||
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
val = node->data;
|
||||
ares__llist_node_detach(node);
|
||||
ares_free(node);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void ares__llist_node_destroy(ares__llist_node_t *node)
|
||||
{
|
||||
ares__llist_destructor_t destruct;
|
||||
void *val;
|
||||
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
destruct = node->parent->destruct;
|
||||
|
||||
val = ares__llist_node_claim(node);
|
||||
if (val != NULL && destruct != NULL) {
|
||||
destruct(val);
|
||||
}
|
||||
}
|
||||
|
||||
void ares__llist_node_replace(ares__llist_node_t *node, void *val)
|
||||
{
|
||||
ares__llist_destructor_t destruct;
|
||||
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
destruct = node->parent->destruct;
|
||||
if (destruct != NULL) {
|
||||
destruct(node->data);
|
||||
}
|
||||
|
||||
node->data = val;
|
||||
}
|
||||
|
||||
void ares__llist_destroy(ares__llist_t *list)
|
||||
{
|
||||
ares__llist_node_t *node;
|
||||
|
||||
if (list == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((node = ares__llist_node_first(list)) != NULL) {
|
||||
ares__llist_node_destroy(node);
|
||||
}
|
||||
ares_free(list);
|
||||
}
|
||||
|
||||
void ares__llist_node_move_parent_last(ares__llist_node_t *node,
|
||||
ares__llist_t *new_parent)
|
||||
{
|
||||
if (node == NULL || new_parent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__llist_node_detach(node);
|
||||
ares__llist_attach_at(new_parent, ARES__LLIST_INSERT_TAIL, NULL, node);
|
||||
}
|
||||
|
||||
void ares__llist_node_move_parent_first(ares__llist_node_t *node,
|
||||
ares__llist_t *new_parent)
|
||||
{
|
||||
if (node == NULL || new_parent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__llist_node_detach(node);
|
||||
ares__llist_attach_at(new_parent, ARES__LLIST_INSERT_HEAD, NULL, node);
|
||||
}
|
||||
220
src/third_party/cares/dist/src/lib/ares__llist.h
vendored
Normal file
220
src/third_party/cares/dist/src/lib/ares__llist.h
vendored
Normal file
@ -0,0 +1,220 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__LLIST_H
|
||||
#define __ARES__LLIST_H
|
||||
|
||||
/*! \addtogroup ares__llist LinkedList Data Structure
|
||||
*
|
||||
* This is a doubly-linked list data structure.
|
||||
*
|
||||
* Average time complexity:
|
||||
* - Insert: O(1) -- head or tail
|
||||
* - Search: O(n)
|
||||
* - Delete: O(1) -- delete assumes you hold a node pointer
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct ares__llist;
|
||||
|
||||
/*! Opaque data structure for linked list */
|
||||
typedef struct ares__llist ares__llist_t;
|
||||
|
||||
struct ares__llist_node;
|
||||
|
||||
/*! Opaque data structure for a node in a linked list */
|
||||
typedef struct ares__llist_node ares__llist_node_t;
|
||||
|
||||
/*! Callback to free user-defined node data
|
||||
*
|
||||
* \param[in] data user supplied data
|
||||
*/
|
||||
typedef void (*ares__llist_destructor_t)(void *data);
|
||||
|
||||
/*! Create a linked list object
|
||||
*
|
||||
* \param[in] destruct Optional. Destructor to call on all removed nodes
|
||||
* \return linked list object or NULL on out of memory
|
||||
*/
|
||||
ares__llist_t *ares__llist_create(ares__llist_destructor_t destruct);
|
||||
|
||||
/*! Replace destructor for linked list nodes. Typically this is used
|
||||
* when wanting to disable the destructor by using NULL.
|
||||
*
|
||||
* \param[in] list Initialized linked list object
|
||||
* \param[in] destruct replacement destructor, NULL is allowed
|
||||
*/
|
||||
void ares__llist_replace_destructor(ares__llist_t *list,
|
||||
ares__llist_destructor_t destruct);
|
||||
|
||||
/*! Insert value as the first node in the linked list
|
||||
*
|
||||
* \param[in] list Initialized linked list object
|
||||
* \param[in] val user-supplied value.
|
||||
* \return node object referencing place in list, or null if out of memory or
|
||||
* misuse
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_insert_first(ares__llist_t *list, void *val);
|
||||
|
||||
/*! Insert value as the last node in the linked list
|
||||
*
|
||||
* \param[in] list Initialized linked list object
|
||||
* \param[in] val user-supplied value.
|
||||
* \return node object referencing place in list, or null if out of memory or
|
||||
* misuse
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_insert_last(ares__llist_t *list, void *val);
|
||||
|
||||
/*! Insert value before specified node in the linked list
|
||||
*
|
||||
* \param[in] node node referenced to insert before
|
||||
* \param[in] val user-supplied value.
|
||||
* \return node object referencing place in list, or null if out of memory or
|
||||
* misuse
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_insert_before(ares__llist_node_t *node,
|
||||
void *val);
|
||||
|
||||
/*! Insert value after specified node in the linked list
|
||||
*
|
||||
* \param[in] node node referenced to insert after
|
||||
* \param[in] val user-supplied value.
|
||||
* \return node object referencing place in list, or null if out of memory or
|
||||
* misuse
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_insert_after(ares__llist_node_t *node,
|
||||
void *val);
|
||||
|
||||
/*! Obtain first node in list
|
||||
*
|
||||
* \param[in] list Initialized list object
|
||||
* \return first node in list or NULL if none
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_node_first(ares__llist_t *list);
|
||||
|
||||
/*! Obtain last node in list
|
||||
*
|
||||
* \param[in] list Initialized list object
|
||||
* \return last node in list or NULL if none
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_node_last(ares__llist_t *list);
|
||||
|
||||
/*! Obtain next node in respect to specified node
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
* \return node or NULL if none
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_node_next(ares__llist_node_t *node);
|
||||
|
||||
/*! Obtain previous node in respect to specified node
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
* \return node or NULL if none
|
||||
*/
|
||||
ares__llist_node_t *ares__llist_node_prev(ares__llist_node_t *node);
|
||||
|
||||
/*! Obtain value from node
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
* \return user provided value from node
|
||||
*/
|
||||
void *ares__llist_node_val(ares__llist_node_t *node);
|
||||
|
||||
/*! Obtain the number of entries in the list
|
||||
*
|
||||
* \param[in] list Initialized list object
|
||||
* \return count
|
||||
*/
|
||||
size_t ares__llist_len(const ares__llist_t *list);
|
||||
|
||||
/*! Obtain list object from referenced node
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
* \return list object node belongs to
|
||||
*/
|
||||
ares__llist_t *ares__llist_node_parent(ares__llist_node_t *node);
|
||||
|
||||
/*! Obtain the first user-supplied value in the list
|
||||
*
|
||||
* \param[in] list Initialized list object
|
||||
* \return first user supplied value or NULL if none
|
||||
*/
|
||||
void *ares__llist_first_val(ares__llist_t *list);
|
||||
|
||||
/*! Obtain the last user-supplied value in the list
|
||||
*
|
||||
* \param[in] list Initialized list object
|
||||
* \return last user supplied value or NULL if none
|
||||
*/
|
||||
void *ares__llist_last_val(ares__llist_t *list);
|
||||
|
||||
/*! Take ownership of user-supplied value in list without calling destructor.
|
||||
* Will unchain entry from list.
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
* \return user supplied value
|
||||
*/
|
||||
void *ares__llist_node_claim(ares__llist_node_t *node);
|
||||
|
||||
/*! Replace user-supplied value for node
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
* \param[in] val new user-supplied value
|
||||
*/
|
||||
void ares__llist_node_replace(ares__llist_node_t *node, void *val);
|
||||
|
||||
/*! Destroy the node, removing it from the list and calling destructor.
|
||||
*
|
||||
* \param[in] node Node referenced
|
||||
*/
|
||||
void ares__llist_node_destroy(ares__llist_node_t *node);
|
||||
|
||||
/*! Destroy the list object and all nodes in the list.
|
||||
*
|
||||
* \param[in] list Initialized list object
|
||||
*/
|
||||
void ares__llist_destroy(ares__llist_t *list);
|
||||
|
||||
/*! Detach node from the current list and re-attach it to the new list as the
|
||||
* last entry.
|
||||
*
|
||||
* \param[in] node node to move
|
||||
* \param[in] parent new list
|
||||
*/
|
||||
void ares__llist_node_move_parent_last(ares__llist_node_t *node,
|
||||
ares__llist_t *new_parent);
|
||||
|
||||
/*! Detach node from the current list and re-attach it to the new list as the
|
||||
* first entry.
|
||||
*
|
||||
* \param[in] node node to move
|
||||
* \param[in] parent new list
|
||||
*/
|
||||
void ares__llist_node_move_parent_first(ares__llist_node_t *node,
|
||||
ares__llist_t *new_parent);
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__LLIST_H */
|
||||
@ -1,18 +1,29 @@
|
||||
/* Copyright (C) 2019 by Andrew Selivanov
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 2019 Andrew Selivanov
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
@ -25,8 +36,6 @@
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "ares_nameser.h"
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
@ -36,194 +45,144 @@
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
int ares__parse_into_addrinfo(const unsigned char *abuf,
|
||||
int alen, int cname_only_is_enodata,
|
||||
unsigned short port,
|
||||
struct ares_addrinfo *ai)
|
||||
ares_status_t ares__parse_into_addrinfo(const unsigned char *abuf, size_t alen,
|
||||
ares_bool_t cname_only_is_enodata,
|
||||
unsigned short port,
|
||||
struct ares_addrinfo *ai)
|
||||
{
|
||||
unsigned int qdcount, ancount;
|
||||
int status, i, rr_type, rr_class, rr_len, rr_ttl;
|
||||
int got_a = 0, got_aaaa = 0, got_cname = 0;
|
||||
long len;
|
||||
const unsigned char *aptr;
|
||||
char *question_hostname = NULL;
|
||||
char *hostname, *rr_name = NULL, *rr_data;
|
||||
struct ares_addrinfo_cname *cname, *cnames = NULL;
|
||||
struct ares_addrinfo_node *nodes = NULL;
|
||||
ares_status_t status;
|
||||
ares_dns_record_t *dnsrec = NULL;
|
||||
size_t i;
|
||||
size_t ancount;
|
||||
const char *hostname = NULL;
|
||||
ares_bool_t got_a = ARES_FALSE;
|
||||
ares_bool_t got_aaaa = ARES_FALSE;
|
||||
ares_bool_t got_cname = ARES_FALSE;
|
||||
struct ares_addrinfo_cname *cnames = NULL;
|
||||
struct ares_addrinfo_node *nodes = NULL;
|
||||
|
||||
/* Give up if abuf doesn't have room for a header. */
|
||||
if (alen < HFIXEDSZ)
|
||||
return ARES_EBADRESP;
|
||||
status = ares_dns_parse(abuf, alen, 0, &dnsrec);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Fetch the question and answer count from the header. */
|
||||
qdcount = DNS_HEADER_QDCOUNT(abuf);
|
||||
ancount = DNS_HEADER_ANCOUNT(abuf);
|
||||
if (qdcount != 1)
|
||||
return ARES_EBADRESP;
|
||||
/* Save question hostname */
|
||||
status = ares_dns_record_query_get(dnsrec, 0, &hostname, NULL, NULL);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
ancount = ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER);
|
||||
if (ancount == 0) {
|
||||
status = ARES_ENODATA;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Expand the name from the question, and skip past the question. */
|
||||
aptr = abuf + HFIXEDSZ;
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &question_hostname, &len, 0);
|
||||
if (status != ARES_SUCCESS)
|
||||
return status;
|
||||
if (aptr + len + QFIXEDSZ > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
goto failed_stat;
|
||||
for (i = 0; i < ancount; i++) {
|
||||
ares_dns_rec_type_t rtype;
|
||||
const ares_dns_rr_t *rr =
|
||||
ares_dns_record_rr_get(dnsrec, ARES_SECTION_ANSWER, i);
|
||||
|
||||
if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hostname = question_hostname;
|
||||
rtype = ares_dns_rr_get_type(rr);
|
||||
|
||||
aptr += len + QFIXEDSZ;
|
||||
/* Issue #683
|
||||
* Old code did this hostname sanity check, however it appears this is
|
||||
* flawed logic. Other resolvers don't do this sanity check. Leaving
|
||||
* this code commented out for future reference.
|
||||
*
|
||||
* rname = ares_dns_rr_get_name(rr);
|
||||
* if ((rtype == ARES_REC_TYPE_A || rtype == ARES_REC_TYPE_AAAA) &&
|
||||
* strcasecmp(rname, hostname) != 0) {
|
||||
* continue;
|
||||
* }
|
||||
*/
|
||||
|
||||
/* Examine each answer resource record (RR) in turn. */
|
||||
for (i = 0; i < (int)ancount; i++)
|
||||
{
|
||||
/* Decode the RR up to the data field. */
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len, 0);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
rr_name = NULL;
|
||||
goto failed_stat;
|
||||
}
|
||||
if (rtype == ARES_REC_TYPE_CNAME) {
|
||||
struct ares_addrinfo_cname *cname;
|
||||
|
||||
aptr += len;
|
||||
if (aptr + RRFIXEDSZ > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
goto failed_stat;
|
||||
}
|
||||
rr_type = DNS_RR_TYPE(aptr);
|
||||
rr_class = DNS_RR_CLASS(aptr);
|
||||
rr_len = DNS_RR_LEN(aptr);
|
||||
rr_ttl = DNS_RR_TTL(aptr);
|
||||
aptr += RRFIXEDSZ;
|
||||
if (aptr + rr_len > abuf + alen)
|
||||
{
|
||||
status = ARES_EBADRESP;
|
||||
goto failed_stat;
|
||||
}
|
||||
got_cname = ARES_TRUE;
|
||||
/* replace hostname with data from cname
|
||||
* SA: Seems wrong as it introduces order dependency. */
|
||||
hostname = ares_dns_rr_get_str(rr, ARES_RR_CNAME_CNAME);
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_A
|
||||
&& rr_len == sizeof(struct in_addr)
|
||||
&& strcasecmp(rr_name, hostname) == 0)
|
||||
{
|
||||
got_a = 1;
|
||||
if (aptr + sizeof(struct in_addr) > abuf + alen)
|
||||
{ /* LCOV_EXCL_START: already checked above */
|
||||
status = ARES_EBADRESP;
|
||||
goto failed_stat;
|
||||
} /* LCOV_EXCL_STOP */
|
||||
|
||||
status = ares_append_ai_node(AF_INET, port, rr_ttl, aptr, &nodes);
|
||||
if (status != ARES_SUCCESS)
|
||||
goto failed_stat;
|
||||
}
|
||||
else if (rr_class == C_IN && rr_type == T_AAAA
|
||||
&& rr_len == sizeof(struct ares_in6_addr)
|
||||
&& strcasecmp(rr_name, hostname) == 0)
|
||||
{
|
||||
got_aaaa = 1;
|
||||
if (aptr + sizeof(struct ares_in6_addr) > abuf + alen)
|
||||
{ /* LCOV_EXCL_START: already checked above */
|
||||
status = ARES_EBADRESP;
|
||||
goto failed_stat;
|
||||
} /* LCOV_EXCL_STOP */
|
||||
|
||||
status = ares_append_ai_node(AF_INET6, port, rr_ttl, aptr, &nodes);
|
||||
if (status != ARES_SUCCESS)
|
||||
goto failed_stat;
|
||||
}
|
||||
|
||||
if (rr_class == C_IN && rr_type == T_CNAME)
|
||||
{
|
||||
got_cname = 1;
|
||||
status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
|
||||
&len, 1);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
goto failed_stat;
|
||||
}
|
||||
|
||||
/* Decode the RR data and replace the hostname with it. */
|
||||
/* SA: Seems wrong as it introduses order dependency. */
|
||||
hostname = rr_data;
|
||||
|
||||
cname = ares__append_addrinfo_cname(&cnames);
|
||||
if (!cname)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
ares_free(rr_data);
|
||||
goto failed_stat;
|
||||
}
|
||||
cname->ttl = rr_ttl;
|
||||
cname->alias = rr_name;
|
||||
cname->name = rr_data;
|
||||
rr_name = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* rr_name is only saved for cname */
|
||||
ares_free(rr_name);
|
||||
rr_name = NULL;
|
||||
}
|
||||
|
||||
|
||||
aptr += rr_len;
|
||||
if (aptr > abuf + alen)
|
||||
{ /* LCOV_EXCL_START: already checked above */
|
||||
status = ARES_EBADRESP;
|
||||
goto failed_stat;
|
||||
} /* LCOV_EXCL_STOP */
|
||||
cname = ares__append_addrinfo_cname(&cnames);
|
||||
if (cname == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
cname->ttl = (int)ares_dns_rr_get_ttl(rr);
|
||||
cname->alias = ares_strdup(ares_dns_rr_get_name(rr));
|
||||
if (cname->alias == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
cname->name = ares_strdup(hostname);
|
||||
if (cname->name == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
} else if (rtype == ARES_REC_TYPE_A) {
|
||||
got_a = ARES_TRUE;
|
||||
status =
|
||||
ares_append_ai_node(AF_INET, port, ares_dns_rr_get_ttl(rr),
|
||||
ares_dns_rr_get_addr(rr, ARES_RR_A_ADDR), &nodes);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
} else if (rtype == ARES_REC_TYPE_AAAA) {
|
||||
got_aaaa = ARES_TRUE;
|
||||
status = ares_append_ai_node(AF_INET6, port, ares_dns_rr_get_ttl(rr),
|
||||
ares_dns_rr_get_addr6(rr, ARES_RR_AAAA_ADDR),
|
||||
&nodes);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (status == ARES_SUCCESS)
|
||||
{
|
||||
if (!got_a && !got_aaaa)
|
||||
{
|
||||
if (!got_cname || (got_cname && cname_only_is_enodata))
|
||||
{
|
||||
status = ARES_ENODATA;
|
||||
goto failed_stat;
|
||||
}
|
||||
}
|
||||
if (!got_a && !got_aaaa &&
|
||||
(!got_cname || (got_cname && cname_only_is_enodata))) {
|
||||
status = ARES_ENODATA;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* save the question hostname as ai->name */
|
||||
if (ai->name == NULL || strcasecmp(ai->name, question_hostname) != 0)
|
||||
{
|
||||
ares_free(ai->name);
|
||||
ai->name = ares_strdup(question_hostname);
|
||||
if (!ai->name)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
goto failed_stat;
|
||||
}
|
||||
}
|
||||
|
||||
if (got_a || got_aaaa)
|
||||
{
|
||||
ares__addrinfo_cat_nodes(&ai->nodes, nodes);
|
||||
nodes = NULL;
|
||||
}
|
||||
|
||||
if (got_cname)
|
||||
{
|
||||
ares__addrinfo_cat_cnames(&ai->cnames, cnames);
|
||||
cnames = NULL;
|
||||
}
|
||||
/* save the hostname as ai->name */
|
||||
if (ai->name == NULL || strcasecmp(ai->name, hostname) != 0) {
|
||||
ares_free(ai->name);
|
||||
ai->name = ares_strdup(hostname);
|
||||
if (ai->name == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
ares_free(question_hostname);
|
||||
return status;
|
||||
if (got_a || got_aaaa) {
|
||||
ares__addrinfo_cat_nodes(&ai->nodes, nodes);
|
||||
nodes = NULL;
|
||||
}
|
||||
|
||||
failed_stat:
|
||||
ares_free(question_hostname);
|
||||
ares_free(rr_name);
|
||||
if (got_cname) {
|
||||
ares__addrinfo_cat_cnames(&ai->cnames, cnames);
|
||||
cnames = NULL;
|
||||
}
|
||||
|
||||
done:
|
||||
ares__freeaddrinfo_cnames(cnames);
|
||||
ares__freeaddrinfo_nodes(nodes);
|
||||
ares_dns_record_destroy(dnsrec);
|
||||
|
||||
/* compatibility */
|
||||
if (status == ARES_EBADNAME) {
|
||||
status = ARES_EBADRESP;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
113
src/third_party/cares/dist/src/lib/ares__read_line.c
vendored
113
src/third_party/cares/dist/src/lib/ares__read_line.c
vendored
@ -1,23 +1,33 @@
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 1998 Massachusetts Institute of Technology
|
||||
* Copyright (c) The c-ares project and its contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_nowarn.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
/* This is an internal function. Its contract is to read a line from
|
||||
@ -28,46 +38,53 @@
|
||||
* appropriate. The initial value of *buf should be NULL. After the
|
||||
* calling routine is done reading lines, it should free *buf.
|
||||
*/
|
||||
int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
|
||||
ares_status_t ares__read_line(FILE *fp, char **buf, size_t *bufsize)
|
||||
{
|
||||
char *newbuf;
|
||||
char *newbuf;
|
||||
size_t offset = 0;
|
||||
size_t len;
|
||||
|
||||
if (*buf == NULL)
|
||||
{
|
||||
*buf = ares_malloc(128);
|
||||
if (!*buf)
|
||||
return ARES_ENOMEM;
|
||||
*bufsize = 128;
|
||||
if (*buf == NULL) {
|
||||
*buf = ares_malloc(128);
|
||||
if (!*buf) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
*bufsize = 128;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int bytestoread = (int)(*bufsize - offset);
|
||||
|
||||
if (!fgets(*buf + offset, bytestoread, fp)) {
|
||||
return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF;
|
||||
}
|
||||
len = offset + ares_strlen(*buf + offset);
|
||||
|
||||
/* Probably means there was an embedded NULL as the first character in
|
||||
* the line, throw away line */
|
||||
if (len == 0) {
|
||||
offset = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int bytestoread = aresx_uztosi(*bufsize - offset);
|
||||
|
||||
if (!fgets(*buf + offset, bytestoread, fp))
|
||||
return (offset != 0) ? 0 : (ferror(fp)) ? ARES_EFILE : ARES_EOF;
|
||||
len = offset + strlen(*buf + offset);
|
||||
if ((*buf)[len - 1] == '\n')
|
||||
{
|
||||
(*buf)[len - 1] = 0;
|
||||
break;
|
||||
}
|
||||
offset = len;
|
||||
if(len < *bufsize - 1)
|
||||
continue;
|
||||
|
||||
/* Allocate more space. */
|
||||
newbuf = ares_realloc(*buf, *bufsize * 2);
|
||||
if (!newbuf)
|
||||
{
|
||||
ares_free(*buf);
|
||||
*buf = NULL;
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
*buf = newbuf;
|
||||
*bufsize *= 2;
|
||||
if ((*buf)[len - 1] == '\n') {
|
||||
(*buf)[len - 1] = 0;
|
||||
break;
|
||||
}
|
||||
offset = len;
|
||||
if (len < *bufsize - 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Allocate more space. */
|
||||
newbuf = ares_realloc(*buf, *bufsize * 2);
|
||||
if (!newbuf) {
|
||||
ares_free(*buf);
|
||||
*buf = NULL;
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
*buf = newbuf;
|
||||
*bufsize *= 2;
|
||||
}
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1,258 +0,0 @@
|
||||
/* Copyright (C) 2019 by Andrew Selivanov
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_inet_net_pton.h"
|
||||
#include "ares_nowarn.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
#define MAX_ALIASES 40
|
||||
|
||||
int ares__readaddrinfo(FILE *fp,
|
||||
const char *name,
|
||||
unsigned short port,
|
||||
const struct ares_addrinfo_hints *hints,
|
||||
struct ares_addrinfo *ai)
|
||||
{
|
||||
char *line = NULL, *p, *q;
|
||||
char *txtaddr, *txthost, *txtalias;
|
||||
char *aliases[MAX_ALIASES];
|
||||
unsigned int i, alias_count;
|
||||
int status = ARES_SUCCESS;
|
||||
size_t linesize;
|
||||
struct ares_addrinfo_cname *cname = NULL, *cnames = NULL;
|
||||
struct ares_addrinfo_node *nodes = NULL;
|
||||
int match_with_alias, match_with_canonical;
|
||||
int want_cname = hints->ai_flags & ARES_AI_CANONNAME;
|
||||
|
||||
/* Validate family */
|
||||
switch (hints->ai_family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
case AF_UNSPEC:
|
||||
break;
|
||||
default:
|
||||
return ARES_EBADFAMILY;
|
||||
}
|
||||
|
||||
ai->name = ares_strdup(name);
|
||||
if(!ai->name)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while ((status = ares__read_line(fp, &line, &linesize)) == ARES_SUCCESS)
|
||||
{
|
||||
match_with_alias = 0;
|
||||
match_with_canonical = 0;
|
||||
alias_count = 0;
|
||||
/* Trim line comment. */
|
||||
p = line;
|
||||
while (*p && (*p != '#'))
|
||||
p++;
|
||||
*p = '\0';
|
||||
|
||||
/* Trim trailing whitespace. */
|
||||
q = p - 1;
|
||||
while ((q >= line) && ISSPACE(*q))
|
||||
q--;
|
||||
*++q = '\0';
|
||||
|
||||
/* Skip leading whitespace. */
|
||||
p = line;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if empty. */
|
||||
continue;
|
||||
|
||||
/* Pointer to start of IPv4 or IPv6 address part. */
|
||||
txtaddr = p;
|
||||
|
||||
/* Advance past address part. */
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if reached end of line. */
|
||||
continue;
|
||||
|
||||
/* Null terminate address part. */
|
||||
*p = '\0';
|
||||
|
||||
/* Advance to host name */
|
||||
p++;
|
||||
while (*p && ISSPACE(*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
/* Ignore line if reached end of line. */
|
||||
continue; /* LCOV_EXCL_LINE: trailing whitespace already stripped */
|
||||
|
||||
/* Pointer to start of host name. */
|
||||
txthost = p;
|
||||
|
||||
/* Advance past host name. */
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
|
||||
/* Pointer to start of first alias. */
|
||||
txtalias = NULL;
|
||||
if (*p)
|
||||
{
|
||||
q = p + 1;
|
||||
while (*q && ISSPACE(*q))
|
||||
q++;
|
||||
if (*q)
|
||||
txtalias = q;
|
||||
}
|
||||
|
||||
/* Null terminate host name. */
|
||||
*p = '\0';
|
||||
|
||||
/* Find out if host name matches with canonical host name. */
|
||||
if (strcasecmp(txthost, name) == 0)
|
||||
{
|
||||
match_with_canonical = 1;
|
||||
}
|
||||
|
||||
/* Find out if host name matches with one of the aliases. */
|
||||
while (txtalias)
|
||||
{
|
||||
p = txtalias;
|
||||
while (*p && !ISSPACE(*p))
|
||||
p++;
|
||||
q = p;
|
||||
while (*q && ISSPACE(*q))
|
||||
q++;
|
||||
*p = '\0';
|
||||
if (strcasecmp(txtalias, name) == 0)
|
||||
{
|
||||
match_with_alias = 1;
|
||||
if (!want_cname)
|
||||
break;
|
||||
}
|
||||
if (alias_count < MAX_ALIASES)
|
||||
{
|
||||
aliases[alias_count++] = txtalias;
|
||||
}
|
||||
txtalias = *q ? q : NULL;
|
||||
}
|
||||
|
||||
/* Try next line if host does not match. */
|
||||
if (!match_with_alias && !match_with_canonical)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert address string to network address for the requested families.
|
||||
* Actual address family possible values are AF_INET and AF_INET6 only.
|
||||
*/
|
||||
if ((hints->ai_family == AF_INET) || (hints->ai_family == AF_UNSPEC))
|
||||
{
|
||||
struct in_addr addr4;
|
||||
if (ares_inet_pton(AF_INET, txtaddr, &addr4) == 1)
|
||||
{
|
||||
status = ares_append_ai_node(AF_INET, port, 0, &addr4, &nodes);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((hints->ai_family == AF_INET6) || (hints->ai_family == AF_UNSPEC))
|
||||
{
|
||||
struct ares_in6_addr addr6;
|
||||
if (ares_inet_pton(AF_INET6, txtaddr, &addr6) == 1)
|
||||
{
|
||||
status = ares_append_ai_node(AF_INET6, port, 0, &addr6, &nodes);
|
||||
if (status != ARES_SUCCESS)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status != ARES_SUCCESS)
|
||||
/* Ignore line if invalid address string for the requested family. */
|
||||
continue;
|
||||
|
||||
if (want_cname)
|
||||
{
|
||||
for (i = 0; i < alias_count; ++i)
|
||||
{
|
||||
cname = ares__append_addrinfo_cname(&cnames);
|
||||
if (!cname)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
cname->alias = ares_strdup(aliases[i]);
|
||||
cname->name = ares_strdup(txthost);
|
||||
}
|
||||
/* No aliases, cname only. */
|
||||
if(!alias_count)
|
||||
{
|
||||
cname = ares__append_addrinfo_cname(&cnames);
|
||||
if (!cname)
|
||||
{
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
cname->name = ares_strdup(txthost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Last read failed. */
|
||||
if (status == ARES_ENOMEM)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* If no results, its a failure */
|
||||
if (!nodes)
|
||||
{
|
||||
status = ARES_ENOTFOUND;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Free line buffer. */
|
||||
ares_free(line);
|
||||
ares__addrinfo_cat_cnames(&ai->cnames, cnames);
|
||||
ares__addrinfo_cat_nodes(&ai->nodes, nodes);
|
||||
|
||||
return ARES_SUCCESS;
|
||||
|
||||
fail:
|
||||
ares_free(line);
|
||||
ares__freeaddrinfo_cnames(cnames);
|
||||
ares__freeaddrinfo_nodes(nodes);
|
||||
ares_free(ai->name);
|
||||
ai->name = NULL;
|
||||
return status;
|
||||
}
|
||||
479
src/third_party/cares/dist/src/lib/ares__slist.c
vendored
Normal file
479
src/third_party/cares/dist/src/lib/ares__slist.c
vendored
Normal file
@ -0,0 +1,479 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
#include "ares__slist.h"
|
||||
|
||||
/* SkipList implementation */
|
||||
|
||||
#define ARES__SLIST_START_LEVELS 4
|
||||
|
||||
struct ares__slist {
|
||||
ares_rand_state *rand_state;
|
||||
unsigned char rand_data[8];
|
||||
size_t rand_bits;
|
||||
|
||||
ares__slist_node_t **head;
|
||||
size_t levels;
|
||||
ares__slist_node_t *tail;
|
||||
|
||||
ares__slist_cmp_t cmp;
|
||||
ares__slist_destructor_t destruct;
|
||||
size_t cnt;
|
||||
};
|
||||
|
||||
struct ares__slist_node {
|
||||
void *data;
|
||||
ares__slist_node_t **prev;
|
||||
ares__slist_node_t **next;
|
||||
size_t levels;
|
||||
ares__slist_t *parent;
|
||||
};
|
||||
|
||||
ares__slist_t *ares__slist_create(ares_rand_state *rand_state,
|
||||
ares__slist_cmp_t cmp,
|
||||
ares__slist_destructor_t destruct)
|
||||
{
|
||||
ares__slist_t *list;
|
||||
|
||||
if (rand_state == NULL || cmp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list = ares_malloc_zero(sizeof(*list));
|
||||
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list->rand_state = rand_state;
|
||||
list->cmp = cmp;
|
||||
list->destruct = destruct;
|
||||
|
||||
list->levels = ARES__SLIST_START_LEVELS;
|
||||
list->head = ares_malloc_zero(sizeof(*list->head) * list->levels);
|
||||
if (list->head == NULL) {
|
||||
ares_free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static ares_bool_t ares__slist_coin_flip(ares__slist_t *list)
|
||||
{
|
||||
size_t total_bits = sizeof(list->rand_data) * 8;
|
||||
size_t bit;
|
||||
|
||||
/* Refill random data used for coin flips. We pull this in 8 byte chunks.
|
||||
* ares__rand_bytes() has some built-in caching of its own so we don't need
|
||||
* to be excessive in caching ourselves. Prefer to require less memory per
|
||||
* skiplist */
|
||||
if (list->rand_bits == 0) {
|
||||
ares__rand_bytes(list->rand_state, list->rand_data,
|
||||
sizeof(list->rand_data));
|
||||
list->rand_bits = total_bits;
|
||||
}
|
||||
|
||||
bit = total_bits - list->rand_bits;
|
||||
list->rand_bits--;
|
||||
|
||||
return (list->rand_data[bit / 8] & (1 << (bit % 8))) ? ARES_TRUE : ARES_FALSE;
|
||||
}
|
||||
|
||||
void ares__slist_replace_destructor(ares__slist_t *list,
|
||||
ares__slist_destructor_t destruct)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
list->destruct = destruct;
|
||||
}
|
||||
|
||||
static size_t ares__slist_max_level(const ares__slist_t *list)
|
||||
{
|
||||
size_t max_level = 0;
|
||||
|
||||
if (list->cnt + 1 <= (1 << ARES__SLIST_START_LEVELS)) {
|
||||
max_level = ARES__SLIST_START_LEVELS;
|
||||
} else {
|
||||
max_level = ares__log2(ares__round_up_pow2(list->cnt + 1));
|
||||
}
|
||||
|
||||
if (list->levels > max_level) {
|
||||
max_level = list->levels;
|
||||
}
|
||||
|
||||
return max_level;
|
||||
}
|
||||
|
||||
static size_t ares__slist_calc_level(ares__slist_t *list)
|
||||
{
|
||||
size_t max_level = ares__slist_max_level(list);
|
||||
size_t level;
|
||||
|
||||
for (level = 1; ares__slist_coin_flip(list) && level < max_level; level++)
|
||||
;
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
static void ares__slist_node_push(ares__slist_t *list, ares__slist_node_t *node)
|
||||
{
|
||||
size_t i;
|
||||
ares__slist_node_t *left = NULL;
|
||||
|
||||
/* Scan from highest level in the slist, even if we're not using that number
|
||||
* of levels for this entry as this is what makes it O(log n) */
|
||||
for (i = list->levels; i-- > 0;) {
|
||||
/* set left if left is NULL and the current node value is greater than the
|
||||
* head at this level */
|
||||
if (left == NULL && list->head[i] != NULL &&
|
||||
list->cmp(node->data, list->head[i]->data) > 0) {
|
||||
left = list->head[i];
|
||||
}
|
||||
|
||||
if (left != NULL) {
|
||||
/* scan forward to find our insertion point */
|
||||
while (left->next[i] != NULL &&
|
||||
list->cmp(node->data, left->next[i]->data) > 0) {
|
||||
left = left->next[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* search only as we didn't randomly select this number of levels */
|
||||
if (i >= node->levels) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (left == NULL) {
|
||||
/* head insertion */
|
||||
node->next[i] = list->head[i];
|
||||
node->prev[i] = NULL;
|
||||
list->head[i] = node;
|
||||
} else {
|
||||
/* Chain */
|
||||
node->next[i] = left->next[i];
|
||||
node->prev[i] = left;
|
||||
left->next[i] = node;
|
||||
}
|
||||
|
||||
if (node->next[i] != NULL) {
|
||||
/* chain prev */
|
||||
node->next[i]->prev[i] = node;
|
||||
} else {
|
||||
if (i == 0) {
|
||||
/* update tail */
|
||||
list->tail = node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val)
|
||||
{
|
||||
ares__slist_node_t *node = NULL;
|
||||
|
||||
if (list == NULL || val == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = ares_malloc_zero(sizeof(*node));
|
||||
|
||||
if (node == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
node->data = val;
|
||||
node->parent = list;
|
||||
|
||||
/* Randomly determine the number of levels we want to use */
|
||||
node->levels = ares__slist_calc_level(list);
|
||||
|
||||
/* Allocate array of next and prev nodes for linking each level */
|
||||
node->next = ares_malloc_zero(sizeof(*node->next) * node->levels);
|
||||
if (node->next == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
node->prev = ares_malloc_zero(sizeof(*node->prev) * node->levels);
|
||||
if (node->prev == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* If the number of levels is greater than we currently support in the slist,
|
||||
* increase the count */
|
||||
if (list->levels < node->levels) {
|
||||
void *ptr =
|
||||
ares_realloc_zero(list->head, sizeof(*list->head) * list->levels,
|
||||
sizeof(*list->head) * node->levels);
|
||||
if (ptr == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
list->head = ptr;
|
||||
list->levels = node->levels;
|
||||
}
|
||||
|
||||
ares__slist_node_push(list, node);
|
||||
|
||||
list->cnt++;
|
||||
|
||||
return node;
|
||||
|
||||
fail:
|
||||
if (node) {
|
||||
ares_free(node->prev);
|
||||
ares_free(node->next);
|
||||
ares_free(node);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ares__slist_node_pop(ares__slist_node_t *node)
|
||||
{
|
||||
ares__slist_t *list = node->parent;
|
||||
size_t i;
|
||||
|
||||
/* relink each node at each level */
|
||||
for (i = node->levels; i-- > 0;) {
|
||||
if (node->next[i] == NULL) {
|
||||
if (i == 0) {
|
||||
list->tail = node->prev[0];
|
||||
}
|
||||
} else {
|
||||
node->next[i]->prev[i] = node->prev[i];
|
||||
}
|
||||
|
||||
if (node->prev[i] == NULL) {
|
||||
list->head[i] = node->next[i];
|
||||
} else {
|
||||
node->prev[i]->next[i] = node->next[i];
|
||||
}
|
||||
}
|
||||
|
||||
memset(node->next, 0, sizeof(*node->next) * node->levels);
|
||||
memset(node->prev, 0, sizeof(*node->prev) * node->levels);
|
||||
}
|
||||
|
||||
void *ares__slist_node_claim(ares__slist_node_t *node)
|
||||
{
|
||||
ares__slist_t *list;
|
||||
void *val;
|
||||
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list = node->parent;
|
||||
val = node->data;
|
||||
|
||||
ares__slist_node_pop(node);
|
||||
|
||||
ares_free(node->next);
|
||||
ares_free(node->prev);
|
||||
ares_free(node);
|
||||
|
||||
list->cnt--;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void ares__slist_node_reinsert(ares__slist_node_t *node)
|
||||
{
|
||||
ares__slist_t *list;
|
||||
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
list = node->parent;
|
||||
|
||||
ares__slist_node_pop(node);
|
||||
ares__slist_node_push(list, node);
|
||||
}
|
||||
|
||||
ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val)
|
||||
{
|
||||
size_t i;
|
||||
ares__slist_node_t *node = NULL;
|
||||
int rv = -1;
|
||||
|
||||
if (list == NULL || val == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Scan nodes starting at the highest level. For each level scan forward
|
||||
* until the value is between the prior and next node, or if equal quit
|
||||
* as we found a match */
|
||||
for (i = list->levels; i-- > 0;) {
|
||||
if (node == NULL) {
|
||||
node = list->head[i];
|
||||
}
|
||||
|
||||
if (node == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
rv = list->cmp(val, node->data);
|
||||
|
||||
if (rv < 0) {
|
||||
/* back off, our value is greater than current node reference */
|
||||
node = node->prev[i];
|
||||
} else if (rv > 0) {
|
||||
/* move forward and try again. if it goes past, it will loop again and
|
||||
* go to previous entry */
|
||||
node = node->next[i];
|
||||
}
|
||||
|
||||
/* rv == 0 will terminate loop */
|
||||
|
||||
} while (node != NULL && rv > 0);
|
||||
|
||||
/* Found a match, no need to continue */
|
||||
if (rv == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* no match */
|
||||
if (rv != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* The list may have multiple entries that match. They're guaranteed to be
|
||||
* in order, but we're not guaranteed to have selected the _first_ matching
|
||||
* node. Lets scan backwards to find the first match */
|
||||
while (node->prev[0] != NULL && list->cmp(node->prev[0]->data, val) == 0) {
|
||||
node = node->prev[0];
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
ares__slist_node_t *ares__slist_node_first(ares__slist_t *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return list->head[0];
|
||||
}
|
||||
|
||||
ares__slist_node_t *ares__slist_node_last(ares__slist_t *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return list->tail;
|
||||
}
|
||||
|
||||
ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return node->next[0];
|
||||
}
|
||||
|
||||
ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return node->prev[0];
|
||||
}
|
||||
|
||||
void *ares__slist_node_val(ares__slist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return node->data;
|
||||
}
|
||||
|
||||
size_t ares__slist_len(const ares__slist_t *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return list->cnt;
|
||||
}
|
||||
|
||||
ares__slist_t *ares__slist_node_parent(ares__slist_node_t *node)
|
||||
{
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return node->parent;
|
||||
}
|
||||
|
||||
void *ares__slist_first_val(ares__slist_t *list)
|
||||
{
|
||||
return ares__slist_node_val(ares__slist_node_first(list));
|
||||
}
|
||||
|
||||
void *ares__slist_last_val(ares__slist_t *list)
|
||||
{
|
||||
return ares__slist_node_val(ares__slist_node_last(list));
|
||||
}
|
||||
|
||||
void ares__slist_node_destroy(ares__slist_node_t *node)
|
||||
{
|
||||
ares__slist_destructor_t destruct;
|
||||
void *val;
|
||||
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
destruct = node->parent->destruct;
|
||||
val = ares__slist_node_claim(node);
|
||||
|
||||
if (val != NULL && destruct != NULL) {
|
||||
destruct(val);
|
||||
}
|
||||
}
|
||||
|
||||
void ares__slist_destroy(ares__slist_t *list)
|
||||
{
|
||||
ares__slist_node_t *node;
|
||||
|
||||
if (list == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((node = ares__slist_node_first(list)) != NULL) {
|
||||
ares__slist_node_destroy(node);
|
||||
}
|
||||
|
||||
ares_free(list->head);
|
||||
ares_free(list);
|
||||
}
|
||||
206
src/third_party/cares/dist/src/lib/ares__slist.h
vendored
Normal file
206
src/third_party/cares/dist/src/lib/ares__slist.h
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__SLIST_H
|
||||
#define __ARES__SLIST_H
|
||||
|
||||
|
||||
/*! \addtogroup ares__slist SkipList Data Structure
|
||||
*
|
||||
* This data structure is known as a Skip List, which in essence is a sorted
|
||||
* linked list with multiple levels of linkage to gain some algorithmic
|
||||
* advantages. The usage symantecs are almost identical to what you'd expect
|
||||
* with a linked list.
|
||||
*
|
||||
* Average time complexity:
|
||||
* - Insert: O(log n)
|
||||
* - Search: O(log n)
|
||||
* - Delete: O(1) -- delete assumes you hold a node pointer
|
||||
*
|
||||
* It should be noted, however, that "effort" involved with an insert or
|
||||
* remove operation is higher than a normal linked list. For very small
|
||||
* lists this may be less efficient, but for any list with a moderate number
|
||||
* of entries this will prove much more efficient.
|
||||
*
|
||||
* This data structure is often compared with a Binary Search Tree in
|
||||
* functionality and usage.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
struct ares__slist;
|
||||
|
||||
/*! SkipList Object, opaque */
|
||||
typedef struct ares__slist ares__slist_t;
|
||||
|
||||
struct ares__slist_node;
|
||||
|
||||
/*! SkipList Node Object, opaque */
|
||||
typedef struct ares__slist_node ares__slist_node_t;
|
||||
|
||||
/*! SkipList Node Value destructor callback
|
||||
*
|
||||
* \param[in] data User-defined data to destroy
|
||||
*/
|
||||
typedef void (*ares__slist_destructor_t)(void *data);
|
||||
|
||||
/*! SkipList comparison function
|
||||
*
|
||||
* \param[in] data1 First user-defined data object
|
||||
* \param[in] data2 Second user-defined data object
|
||||
* \return < 0 if data1 < data1, > 0 if data1 > data2, 0 if data1 == data2
|
||||
*/
|
||||
typedef int (*ares__slist_cmp_t)(const void *data1, const void *data2);
|
||||
|
||||
/*! Create SkipList
|
||||
*
|
||||
* \param[in] rand_state Initialized ares random state.
|
||||
* \param[in] cmp SkipList comparison function
|
||||
* \param[in] destruct SkipList Node Value Destructor. Optional, use NULL.
|
||||
* \return Initialized SkipList Object or NULL on misuse or ENOMEM
|
||||
*/
|
||||
ares__slist_t *ares__slist_create(ares_rand_state *rand_state,
|
||||
ares__slist_cmp_t cmp,
|
||||
ares__slist_destructor_t destruct);
|
||||
|
||||
/*! Replace SkipList Node Value Destructor
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \param[in] destruct Replacement destructor. May be NULL.
|
||||
*/
|
||||
void ares__slist_replace_destructor(ares__slist_t *list,
|
||||
ares__slist_destructor_t destruct);
|
||||
|
||||
/*! Insert Value into SkipList
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \param[in] val Node Value. Must not be NULL. Function takes ownership
|
||||
* and will have destructor called.
|
||||
* \return SkipList Node Object or NULL on misuse or ENOMEM
|
||||
*/
|
||||
ares__slist_node_t *ares__slist_insert(ares__slist_t *list, void *val);
|
||||
|
||||
/*! Fetch first node in SkipList
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \return SkipList Node Object or NULL if none
|
||||
*/
|
||||
ares__slist_node_t *ares__slist_node_first(ares__slist_t *list);
|
||||
|
||||
/*! Fetch last node in SkipList
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \return SkipList Node Object or NULL if none
|
||||
*/
|
||||
ares__slist_node_t *ares__slist_node_last(ares__slist_t *list);
|
||||
|
||||
/*! Fetch next node in SkipList
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
* \return SkipList Node Object or NULL if none
|
||||
*/
|
||||
ares__slist_node_t *ares__slist_node_next(ares__slist_node_t *node);
|
||||
|
||||
/*! Fetch previous node in SkipList
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
* \return SkipList Node Object or NULL if none
|
||||
*/
|
||||
ares__slist_node_t *ares__slist_node_prev(ares__slist_node_t *node);
|
||||
|
||||
/*! Fetch SkipList Node Object by Value
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \param[in] val Object to use for comparison
|
||||
* \return SkipList Node Object or NULL if not found
|
||||
*/
|
||||
ares__slist_node_t *ares__slist_node_find(ares__slist_t *list, const void *val);
|
||||
|
||||
|
||||
/*! Fetch Node Value
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
* \return user defined node value
|
||||
*/
|
||||
void *ares__slist_node_val(ares__slist_node_t *node);
|
||||
|
||||
/*! Fetch number of entries in SkipList Object
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \return number of entries
|
||||
*/
|
||||
size_t ares__slist_len(const ares__slist_t *list);
|
||||
|
||||
/*! Fetch SkipList Object from SkipList Node
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
* \return SkipList Object
|
||||
*/
|
||||
ares__slist_t *ares__slist_node_parent(ares__slist_node_t *node);
|
||||
|
||||
/*! Fetch first Node Value in SkipList
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \return user defined node value or NULL if none
|
||||
*/
|
||||
void *ares__slist_first_val(ares__slist_t *list);
|
||||
|
||||
/*! Fetch last Node Value in SkipList
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
* \return user defined node value or NULL if none
|
||||
*/
|
||||
void *ares__slist_last_val(ares__slist_t *list);
|
||||
|
||||
/*! Take back ownership of Node Value in SkipList, remove from SkipList.
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
* \return user defined node value
|
||||
*/
|
||||
void *ares__slist_node_claim(ares__slist_node_t *node);
|
||||
|
||||
/*! The internals of the node have changed, thus its position in the sorted
|
||||
* list is no longer valid. This function will remove it and re-add it to
|
||||
* the proper position without needing to perform any memory allocations
|
||||
* and thus cannot fail.
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
*/
|
||||
void ares__slist_node_reinsert(ares__slist_node_t *node);
|
||||
|
||||
/*! Remove Node from SkipList, calling destructor for Node Value.
|
||||
*
|
||||
* \param[in] node SkipList Node Object
|
||||
*/
|
||||
void ares__slist_node_destroy(ares__slist_node_t *node);
|
||||
|
||||
/*! Destroy SkipList Object. If there are any nodes, they will be destroyed.
|
||||
*
|
||||
* \param[in] list Initialized SkipList Object
|
||||
*/
|
||||
void ares__slist_destroy(ares__slist_t *list);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* __ARES__SLIST_H */
|
||||
480
src/third_party/cares/dist/src/lib/ares__socket.c
vendored
Normal file
480
src/third_party/cares/dist/src/lib/ares__socket.c
vendored
Normal file
@ -0,0 +1,480 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) Massachusetts Institute of Technology
|
||||
* Copyright (c) The c-ares project and its contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
|
||||
#ifdef HAVE_SYS_UIO_H
|
||||
# include <sys/uio.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
# include <netinet/tcp.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_IOCTL_H
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
#ifdef NETWARE
|
||||
# include <sys/filio.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
ares_ssize_t ares__socket_recvfrom(ares_channel_t *channel, ares_socket_t s,
|
||||
void *data, size_t data_len, int flags,
|
||||
struct sockaddr *from,
|
||||
ares_socklen_t *from_len)
|
||||
{
|
||||
if (channel->sock_funcs && channel->sock_funcs->arecvfrom) {
|
||||
return channel->sock_funcs->arecvfrom(s, data, data_len, flags, from,
|
||||
from_len, channel->sock_func_cb_data);
|
||||
}
|
||||
|
||||
#ifdef HAVE_RECVFROM
|
||||
return (ares_ssize_t)recvfrom(s, data, (RECVFROM_TYPE_ARG3)data_len, flags,
|
||||
from, from_len);
|
||||
#else
|
||||
return sread(s, data, data_len);
|
||||
#endif
|
||||
}
|
||||
|
||||
ares_ssize_t ares__socket_recv(ares_channel_t *channel, ares_socket_t s,
|
||||
void *data, size_t data_len)
|
||||
{
|
||||
if (channel->sock_funcs && channel->sock_funcs->arecvfrom) {
|
||||
return channel->sock_funcs->arecvfrom(s, data, data_len, 0, 0, 0,
|
||||
channel->sock_func_cb_data);
|
||||
}
|
||||
|
||||
/* sread() is a wrapper for read() or recv() depending on the system */
|
||||
return sread(s, data, data_len);
|
||||
}
|
||||
|
||||
/*
|
||||
* setsocknonblock sets the given socket to either blocking or non-blocking
|
||||
* mode based on the 'nonblock' boolean argument. This function is highly
|
||||
* portable.
|
||||
*/
|
||||
static int setsocknonblock(ares_socket_t sockfd, /* operate on this */
|
||||
int nonblock /* TRUE or FALSE */)
|
||||
{
|
||||
#if defined(USE_BLOCKING_SOCKETS)
|
||||
|
||||
return 0; /* returns success */
|
||||
|
||||
#elif defined(HAVE_FCNTL_O_NONBLOCK)
|
||||
|
||||
/* most recent unix versions */
|
||||
int flags;
|
||||
flags = fcntl(sockfd, F_GETFL, 0);
|
||||
if (nonblock) {
|
||||
return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
|
||||
} else {
|
||||
return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK)); /* LCOV_EXCL_LINE */
|
||||
}
|
||||
|
||||
#elif defined(HAVE_IOCTL_FIONBIO)
|
||||
|
||||
/* older unix versions */
|
||||
int flags = nonblock ? 1 : 0;
|
||||
return ioctl(sockfd, FIONBIO, &flags);
|
||||
|
||||
#elif defined(HAVE_IOCTLSOCKET_FIONBIO)
|
||||
|
||||
# ifdef WATT32
|
||||
char flags = nonblock ? 1 : 0;
|
||||
# else
|
||||
/* Windows */
|
||||
unsigned long flags = nonblock ? 1UL : 0UL;
|
||||
# endif
|
||||
return ioctlsocket(sockfd, (long)FIONBIO, &flags);
|
||||
|
||||
#elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO)
|
||||
|
||||
/* Amiga */
|
||||
long flags = nonblock ? 1L : 0L;
|
||||
return IoctlSocket(sockfd, FIONBIO, flags);
|
||||
|
||||
#elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK)
|
||||
|
||||
/* BeOS */
|
||||
long b = nonblock ? 1L : 0L;
|
||||
return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
|
||||
|
||||
#else
|
||||
# error "no non-blocking method was found/used/set"
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(IPV6_V6ONLY) && defined(WIN32)
|
||||
/* It makes support for IPv4-mapped IPv6 addresses.
|
||||
* Linux kernel, NetBSD, FreeBSD and Darwin: default is off;
|
||||
* Windows Vista and later: default is on;
|
||||
* DragonFly BSD: acts like off, and dummy setting;
|
||||
* OpenBSD and earlier Windows: unsupported.
|
||||
* Linux: controlled by /proc/sys/net/ipv6/bindv6only.
|
||||
*/
|
||||
static void set_ipv6_v6only(ares_socket_t sockfd, int on)
|
||||
{
|
||||
(void)setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on));
|
||||
}
|
||||
#else
|
||||
# define set_ipv6_v6only(s, v)
|
||||
#endif
|
||||
|
||||
static int configure_socket(ares_socket_t s, struct server_state *server)
|
||||
{
|
||||
union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in sa4;
|
||||
struct sockaddr_in6 sa6;
|
||||
} local;
|
||||
|
||||
ares_socklen_t bindlen = 0;
|
||||
ares_channel_t *channel = server->channel;
|
||||
|
||||
/* do not set options for user-managed sockets */
|
||||
if (channel->sock_funcs && channel->sock_funcs->asocket) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)setsocknonblock(s, 1);
|
||||
|
||||
#if defined(FD_CLOEXEC) && !defined(MSDOS)
|
||||
/* Configure the socket fd as close-on-exec. */
|
||||
if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) {
|
||||
return -1; /* LCOV_EXCL_LINE */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set the socket's send and receive buffer sizes. */
|
||||
if ((channel->socket_send_buffer_size > 0) &&
|
||||
setsockopt(s, SOL_SOCKET, SO_SNDBUF,
|
||||
(void *)&channel->socket_send_buffer_size,
|
||||
sizeof(channel->socket_send_buffer_size)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((channel->socket_receive_buffer_size > 0) &&
|
||||
setsockopt(s, SOL_SOCKET, SO_RCVBUF,
|
||||
(void *)&channel->socket_receive_buffer_size,
|
||||
sizeof(channel->socket_receive_buffer_size)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef SO_BINDTODEVICE
|
||||
if (channel->local_dev_name[0] &&
|
||||
setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, channel->local_dev_name,
|
||||
sizeof(channel->local_dev_name))) {
|
||||
/* Only root can do this, and usually not fatal if it doesn't work, so */
|
||||
/* just continue on. */
|
||||
}
|
||||
#endif
|
||||
|
||||
if (server->addr.family == AF_INET && channel->local_ip4) {
|
||||
memset(&local.sa4, 0, sizeof(local.sa4));
|
||||
local.sa4.sin_family = AF_INET;
|
||||
local.sa4.sin_addr.s_addr = htonl(channel->local_ip4);
|
||||
bindlen = sizeof(local.sa4);
|
||||
} else if (server->addr.family == AF_INET6 && server->ll_scope == 0 &&
|
||||
memcmp(channel->local_ip6, ares_in6addr_any._S6_un._S6_u8,
|
||||
sizeof(channel->local_ip6)) != 0) {
|
||||
/* Only if not link-local and an ip other than "::" is specified */
|
||||
memset(&local.sa6, 0, sizeof(local.sa6));
|
||||
local.sa6.sin6_family = AF_INET6;
|
||||
memcpy(&local.sa6.sin6_addr, channel->local_ip6,
|
||||
sizeof(channel->local_ip6));
|
||||
bindlen = sizeof(local.sa6);
|
||||
}
|
||||
|
||||
if (bindlen && bind(s, &local.sa, bindlen) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (server->addr.family == AF_INET6) {
|
||||
set_ipv6_v6only(s, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ares_status_t ares__open_connection(ares_channel_t *channel,
|
||||
struct server_state *server,
|
||||
ares_bool_t is_tcp)
|
||||
{
|
||||
ares_socket_t s;
|
||||
int opt;
|
||||
ares_socklen_t salen;
|
||||
|
||||
union {
|
||||
struct sockaddr_in sa4;
|
||||
struct sockaddr_in6 sa6;
|
||||
} saddr;
|
||||
struct sockaddr *sa;
|
||||
struct server_connection *conn;
|
||||
ares__llist_node_t *node;
|
||||
int type = is_tcp ? SOCK_STREAM : SOCK_DGRAM;
|
||||
#ifdef __OpenBSD__
|
||||
if ((is_tcp && server->tcp_port == 53) ||
|
||||
(!is_tcp && server->udp_port == 53)) {
|
||||
type |= SOCK_DNS;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (server->addr.family) {
|
||||
case AF_INET:
|
||||
sa = (void *)&saddr.sa4;
|
||||
salen = sizeof(saddr.sa4);
|
||||
memset(sa, 0, (size_t)salen);
|
||||
saddr.sa4.sin_family = AF_INET;
|
||||
saddr.sa4.sin_port = htons(is_tcp ? server->tcp_port : server->udp_port);
|
||||
memcpy(&saddr.sa4.sin_addr, &server->addr.addr.addr4,
|
||||
sizeof(saddr.sa4.sin_addr));
|
||||
break;
|
||||
case AF_INET6:
|
||||
sa = (void *)&saddr.sa6;
|
||||
salen = sizeof(saddr.sa6);
|
||||
memset(sa, 0, (size_t)salen);
|
||||
saddr.sa6.sin6_family = AF_INET6;
|
||||
saddr.sa6.sin6_port = htons(is_tcp ? server->tcp_port : server->udp_port);
|
||||
memcpy(&saddr.sa6.sin6_addr, &server->addr.addr.addr6,
|
||||
sizeof(saddr.sa6.sin6_addr));
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
saddr.sa6.sin6_scope_id = server->ll_scope;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
return ARES_EBADFAMILY; /* LCOV_EXCL_LINE */
|
||||
}
|
||||
|
||||
/* Acquire a socket. */
|
||||
s = ares__open_socket(channel, server->addr.family, type, 0);
|
||||
if (s == ARES_SOCKET_BAD) {
|
||||
return ARES_ECONNREFUSED;
|
||||
}
|
||||
|
||||
/* Configure it. */
|
||||
if (configure_socket(s, server) < 0) {
|
||||
ares__close_socket(channel, s);
|
||||
return ARES_ECONNREFUSED;
|
||||
}
|
||||
|
||||
#ifdef TCP_NODELAY
|
||||
if (is_tcp) {
|
||||
/*
|
||||
* Disable the Nagle algorithm (only relevant for TCP sockets, and thus not
|
||||
* in configure_socket). In general, in DNS lookups we're pretty much
|
||||
* interested in firing off a single request and then waiting for a reply,
|
||||
* so batching isn't very interesting.
|
||||
*/
|
||||
opt = 1;
|
||||
if ((!channel->sock_funcs || !channel->sock_funcs->asocket) &&
|
||||
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *)&opt, sizeof(opt)) ==
|
||||
-1) {
|
||||
ares__close_socket(channel, s);
|
||||
return ARES_ECONNREFUSED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (channel->sock_config_cb) {
|
||||
int err = channel->sock_config_cb(s, type, channel->sock_config_cb_data);
|
||||
if (err < 0) {
|
||||
ares__close_socket(channel, s);
|
||||
return ARES_ECONNREFUSED;
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect to the server. */
|
||||
if (ares__connect_socket(channel, s, sa, salen) == -1) {
|
||||
int err = SOCKERRNO;
|
||||
|
||||
if (err != EINPROGRESS && err != EWOULDBLOCK) {
|
||||
ares__close_socket(channel, s);
|
||||
return ARES_ECONNREFUSED;
|
||||
}
|
||||
}
|
||||
|
||||
if (channel->sock_create_cb) {
|
||||
int err = channel->sock_create_cb(s, type, channel->sock_create_cb_data);
|
||||
if (err < 0) {
|
||||
ares__close_socket(channel, s);
|
||||
return ARES_ECONNREFUSED;
|
||||
}
|
||||
}
|
||||
|
||||
conn = ares_malloc(sizeof(*conn));
|
||||
if (conn == NULL) {
|
||||
ares__close_socket(channel, s);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
memset(conn, 0, sizeof(*conn));
|
||||
conn->fd = s;
|
||||
conn->server = server;
|
||||
conn->queries_to_conn = ares__llist_create(NULL);
|
||||
conn->is_tcp = is_tcp;
|
||||
if (conn->queries_to_conn == NULL) {
|
||||
ares__close_socket(channel, s);
|
||||
ares_free(conn);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
/* TCP connections are thrown to the end as we don't spawn multiple TCP
|
||||
* connections. UDP connections are put on front where the newest connection
|
||||
* can be quickly pulled */
|
||||
if (is_tcp) {
|
||||
node = ares__llist_insert_last(server->connections, conn);
|
||||
} else {
|
||||
node = ares__llist_insert_first(server->connections, conn);
|
||||
}
|
||||
if (node == NULL) {
|
||||
ares__close_socket(channel, s);
|
||||
ares__llist_destroy(conn->queries_to_conn);
|
||||
ares_free(conn);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
/* Register globally to quickly map event on file descriptor to connection
|
||||
* node object */
|
||||
if (!ares__htable_asvp_insert(channel->connnode_by_socket, s, node)) {
|
||||
ares__close_socket(channel, s);
|
||||
ares__llist_destroy(conn->queries_to_conn);
|
||||
ares__llist_node_claim(node);
|
||||
ares_free(conn);
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
SOCK_STATE_CALLBACK(channel, s, 1, 0);
|
||||
|
||||
if (is_tcp) {
|
||||
server->tcp_conn = conn;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
ares_socket_t ares__open_socket(ares_channel_t *channel, int af, int type,
|
||||
int protocol)
|
||||
{
|
||||
if (channel->sock_funcs && channel->sock_funcs->asocket) {
|
||||
return channel->sock_funcs->asocket(af, type, protocol,
|
||||
channel->sock_func_cb_data);
|
||||
}
|
||||
|
||||
return socket(af, type, protocol);
|
||||
}
|
||||
|
||||
int ares__connect_socket(ares_channel_t *channel, ares_socket_t sockfd,
|
||||
const struct sockaddr *addr, ares_socklen_t addrlen)
|
||||
{
|
||||
if (channel->sock_funcs && channel->sock_funcs->aconnect) {
|
||||
return channel->sock_funcs->aconnect(sockfd, addr, addrlen,
|
||||
channel->sock_func_cb_data);
|
||||
}
|
||||
|
||||
return connect(sockfd, addr, addrlen);
|
||||
}
|
||||
|
||||
void ares__close_socket(ares_channel_t *channel, ares_socket_t s)
|
||||
{
|
||||
if (s == ARES_SOCKET_BAD) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel->sock_funcs && channel->sock_funcs->aclose) {
|
||||
channel->sock_funcs->aclose(s, channel->sock_func_cb_data);
|
||||
} else {
|
||||
sclose(s);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HAVE_WRITEV
|
||||
/* Structure for scatter/gather I/O. */
|
||||
struct iovec {
|
||||
void *iov_base; /* Pointer to data. */
|
||||
size_t iov_len; /* Length of data. */
|
||||
};
|
||||
#endif
|
||||
|
||||
ares_ssize_t ares__socket_write(ares_channel_t *channel, ares_socket_t s,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
if (channel->sock_funcs && channel->sock_funcs->asendv) {
|
||||
struct iovec vec;
|
||||
vec.iov_base = (void *)((size_t)data); /* Cast off const */
|
||||
vec.iov_len = len;
|
||||
return channel->sock_funcs->asendv(s, &vec, 1, channel->sock_func_cb_data);
|
||||
}
|
||||
return swrite(s, data, len);
|
||||
}
|
||||
|
||||
void ares_set_socket_callback(ares_channel_t *channel,
|
||||
ares_sock_create_callback cb, void *data)
|
||||
{
|
||||
if (channel == NULL) {
|
||||
return;
|
||||
}
|
||||
channel->sock_create_cb = cb;
|
||||
channel->sock_create_cb_data = data;
|
||||
}
|
||||
|
||||
void ares_set_socket_configure_callback(ares_channel_t *channel,
|
||||
ares_sock_config_callback cb,
|
||||
void *data)
|
||||
{
|
||||
if (channel == NULL || channel->optmask & ARES_OPT_EVENT_THREAD) {
|
||||
return;
|
||||
}
|
||||
channel->sock_config_cb = cb;
|
||||
channel->sock_config_cb_data = data;
|
||||
}
|
||||
|
||||
void ares_set_socket_functions(ares_channel_t *channel,
|
||||
const struct ares_socket_functions *funcs,
|
||||
void *data)
|
||||
{
|
||||
if (channel == NULL || channel->optmask & ARES_OPT_EVENT_THREAD) {
|
||||
return;
|
||||
}
|
||||
channel->sock_funcs = funcs;
|
||||
channel->sock_func_cb_data = data;
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/*
|
||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
* Copyright (C) 2019 by Andrew Selivanov
|
||||
* Copyright (C) 2019 Andrew Selivanov
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -32,6 +32,8 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
@ -52,151 +54,118 @@
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
struct addrinfo_sort_elem
|
||||
{
|
||||
struct addrinfo_sort_elem {
|
||||
struct ares_addrinfo_node *ai;
|
||||
int has_src_addr;
|
||||
ares_sockaddr src_addr;
|
||||
int original_order;
|
||||
ares_bool_t has_src_addr;
|
||||
ares_sockaddr src_addr;
|
||||
size_t original_order;
|
||||
};
|
||||
|
||||
#define ARES_IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
|
||||
|
||||
#define ARES_IPV6_ADDR_SCOPE_NODELOCAL 0x01
|
||||
#define ARES_IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
|
||||
#define ARES_IPV6_ADDR_SCOPE_LINKLOCAL 0x02
|
||||
#define ARES_IPV6_ADDR_SCOPE_SITELOCAL 0x05
|
||||
#define ARES_IPV6_ADDR_SCOPE_ORGLOCAL 0x08
|
||||
#define ARES_IPV6_ADDR_SCOPE_GLOBAL 0x0e
|
||||
#define ARES_IPV6_ADDR_SCOPE_NODELOCAL 0x01
|
||||
#define ARES_IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
|
||||
#define ARES_IPV6_ADDR_SCOPE_LINKLOCAL 0x02
|
||||
#define ARES_IPV6_ADDR_SCOPE_SITELOCAL 0x05
|
||||
#define ARES_IPV6_ADDR_SCOPE_ORGLOCAL 0x08
|
||||
#define ARES_IPV6_ADDR_SCOPE_GLOBAL 0x0e
|
||||
|
||||
#define ARES_IN_LOOPBACK(a) ((((long int)(a)) & 0xff000000) == 0x7f000000)
|
||||
#define ARES_IN_LOOPBACK(a) \
|
||||
((((long unsigned int)(a)) & 0xff000000) == 0x7f000000)
|
||||
|
||||
/* RFC 4193. */
|
||||
#define ARES_IN6_IS_ADDR_ULA(a) (((a)->s6_addr[0] & 0xfe) == 0xfc)
|
||||
|
||||
/* These macros are modelled after the ones in <netinet/in6.h>. */
|
||||
/* RFC 4380, section 2.6 */
|
||||
#define ARES_IN6_IS_ADDR_TEREDO(a) \
|
||||
((*(const unsigned int *)(const void *)(&(a)->s6_addr[0]) == ntohl(0x20010000)))
|
||||
#define ARES_IN6_IS_ADDR_TEREDO(a) \
|
||||
((*(const unsigned int *)(const void *)(&(a)->s6_addr[0]) == \
|
||||
ntohl(0x20010000)))
|
||||
/* RFC 3056, section 2. */
|
||||
#define ARES_IN6_IS_ADDR_6TO4(a) \
|
||||
(((a)->s6_addr[0] == 0x20) && ((a)->s6_addr[1] == 0x02))
|
||||
#define ARES_IN6_IS_ADDR_6TO4(a) \
|
||||
(((a)->s6_addr[0] == 0x20) && ((a)->s6_addr[1] == 0x02))
|
||||
/* 6bone testing address area (3ffe::/16), deprecated in RFC 3701. */
|
||||
#define ARES_IN6_IS_ADDR_6BONE(a) \
|
||||
(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))
|
||||
|
||||
#define ARES_IN6_IS_ADDR_6BONE(a) \
|
||||
(((a)->s6_addr[0] == 0x3f) && ((a)->s6_addr[1] == 0xfe))
|
||||
|
||||
static int get_scope(const struct sockaddr *addr)
|
||||
{
|
||||
if (addr->sa_family == AF_INET6)
|
||||
{
|
||||
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
||||
if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr))
|
||||
{
|
||||
return ARES_IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
|
||||
}
|
||||
else if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr) ||
|
||||
IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr))
|
||||
{
|
||||
/*
|
||||
* RFC 4291 section 2.5.3 says loopback is to be treated as having
|
||||
* link-local scope.
|
||||
*/
|
||||
return ARES_IPV6_ADDR_SCOPE_LINKLOCAL;
|
||||
}
|
||||
else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr))
|
||||
{
|
||||
return ARES_IPV6_ADDR_SCOPE_SITELOCAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ARES_IPV6_ADDR_SCOPE_GLOBAL;
|
||||
}
|
||||
}
|
||||
else if (addr->sa_family == AF_INET)
|
||||
{
|
||||
const struct sockaddr_in *addr4 = CARES_INADDR_CAST(const struct sockaddr_in *, addr);
|
||||
unsigned long int na = ntohl(addr4->sin_addr.s_addr);
|
||||
if (ARES_IN_LOOPBACK(na) || /* 127.0.0.0/8 */
|
||||
(na & 0xffff0000) == 0xa9fe0000) /* 169.254.0.0/16 */
|
||||
{
|
||||
return ARES_IPV6_ADDR_SCOPE_LINKLOCAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* RFC 6724 section 3.2. Other IPv4 addresses, including private
|
||||
* addresses and shared addresses (100.64.0.0/10), are assigned global
|
||||
* scope.
|
||||
*/
|
||||
return ARES_IPV6_ADDR_SCOPE_GLOBAL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (addr->sa_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *addr6 =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
||||
if (IN6_IS_ADDR_MULTICAST(&addr6->sin6_addr)) {
|
||||
return ARES_IPV6_ADDR_MC_SCOPE(&addr6->sin6_addr);
|
||||
} else if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr) ||
|
||||
IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
|
||||
/*
|
||||
* This should never happen.
|
||||
* Return a scope with low priority as a last resort.
|
||||
* RFC 4291 section 2.5.3 says loopback is to be treated as having
|
||||
* link-local scope.
|
||||
*/
|
||||
return ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
||||
return ARES_IPV6_ADDR_SCOPE_LINKLOCAL;
|
||||
} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
|
||||
return ARES_IPV6_ADDR_SCOPE_SITELOCAL;
|
||||
} else {
|
||||
return ARES_IPV6_ADDR_SCOPE_GLOBAL;
|
||||
}
|
||||
} else if (addr->sa_family == AF_INET) {
|
||||
const struct sockaddr_in *addr4 =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in *, addr);
|
||||
unsigned long int na = ntohl(addr4->sin_addr.s_addr);
|
||||
if (ARES_IN_LOOPBACK(na) || /* 127.0.0.0/8 */
|
||||
(na & 0xffff0000) == 0xa9fe0000) /* 169.254.0.0/16 */
|
||||
{
|
||||
return ARES_IPV6_ADDR_SCOPE_LINKLOCAL;
|
||||
} else {
|
||||
/*
|
||||
* RFC 6724 section 3.2. Other IPv4 addresses, including private
|
||||
* addresses and shared addresses (100.64.0.0/10), are assigned global
|
||||
* scope.
|
||||
*/
|
||||
return ARES_IPV6_ADDR_SCOPE_GLOBAL;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* This should never happen.
|
||||
* Return a scope with low priority as a last resort.
|
||||
*/
|
||||
return ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
||||
}
|
||||
}
|
||||
|
||||
static int get_label(const struct sockaddr *addr)
|
||||
{
|
||||
if (addr->sa_family == AF_INET)
|
||||
{
|
||||
if (addr->sa_family == AF_INET) {
|
||||
return 4;
|
||||
} else if (addr->sa_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *addr6 =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
||||
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
|
||||
return 0;
|
||||
} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
|
||||
return 4;
|
||||
}
|
||||
else if (addr->sa_family == AF_INET6)
|
||||
{
|
||||
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
||||
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr))
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_6TO4(&addr6->sin6_addr))
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_TEREDO(&addr6->sin6_addr))
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_ULA(&addr6->sin6_addr))
|
||||
{
|
||||
return 13;
|
||||
}
|
||||
else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr))
|
||||
{
|
||||
return 11;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_6BONE(&addr6->sin6_addr))
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* All other IPv6 addresses, including global unicast addresses. */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* This should never happen.
|
||||
* Return a semi-random label as a last resort.
|
||||
*/
|
||||
} else if (ARES_IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
|
||||
return 2;
|
||||
} else if (ARES_IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
|
||||
return 5;
|
||||
} else if (ARES_IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
|
||||
return 13;
|
||||
} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr)) {
|
||||
return 3;
|
||||
} else if (IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr)) {
|
||||
return 11;
|
||||
} else if (ARES_IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
|
||||
return 12;
|
||||
} else {
|
||||
/* All other IPv6 addresses, including global unicast addresses. */
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* This should never happen.
|
||||
* Return a semi-random label as a last resort.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -205,77 +174,57 @@ static int get_label(const struct sockaddr *addr)
|
||||
*/
|
||||
static int get_precedence(const struct sockaddr *addr)
|
||||
{
|
||||
if (addr->sa_family == AF_INET)
|
||||
{
|
||||
if (addr->sa_family == AF_INET) {
|
||||
return 35;
|
||||
} else if (addr->sa_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *addr6 =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
||||
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr)) {
|
||||
return 50;
|
||||
} else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr)) {
|
||||
return 35;
|
||||
}
|
||||
else if (addr->sa_family == AF_INET6)
|
||||
{
|
||||
const struct sockaddr_in6 *addr6 = CARES_INADDR_CAST(const struct sockaddr_in6 *, addr);
|
||||
if (IN6_IS_ADDR_LOOPBACK(&addr6->sin6_addr))
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
else if (IN6_IS_ADDR_V4MAPPED(&addr6->sin6_addr))
|
||||
{
|
||||
return 35;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_6TO4(&addr6->sin6_addr))
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_TEREDO(&addr6->sin6_addr))
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
else if (ARES_IN6_IS_ADDR_ULA(&addr6->sin6_addr))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) ||
|
||||
} else if (ARES_IN6_IS_ADDR_6TO4(&addr6->sin6_addr)) {
|
||||
return 30;
|
||||
} else if (ARES_IN6_IS_ADDR_TEREDO(&addr6->sin6_addr)) {
|
||||
return 5;
|
||||
} else if (ARES_IN6_IS_ADDR_ULA(&addr6->sin6_addr)) {
|
||||
return 3;
|
||||
} else if (IN6_IS_ADDR_V4COMPAT(&addr6->sin6_addr) ||
|
||||
IN6_IS_ADDR_SITELOCAL(&addr6->sin6_addr) ||
|
||||
ARES_IN6_IS_ADDR_6BONE(&addr6->sin6_addr))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* All other IPv6 addresses, including global unicast addresses. */
|
||||
return 40;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ARES_IN6_IS_ADDR_6BONE(&addr6->sin6_addr)) {
|
||||
return 1;
|
||||
} else {
|
||||
/* All other IPv6 addresses, including global unicast addresses. */
|
||||
return 40;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Find number of matching initial bits between the two addresses a1 and a2.
|
||||
*/
|
||||
static int common_prefix_len(const struct in6_addr *a1,
|
||||
const struct in6_addr *a2)
|
||||
static size_t common_prefix_len(const struct in6_addr *a1,
|
||||
const struct in6_addr *a2)
|
||||
{
|
||||
const char *p1 = (const char *)a1;
|
||||
const char *p2 = (const char *)a2;
|
||||
unsigned i;
|
||||
for (i = 0; i < sizeof(*a1); ++i)
|
||||
{
|
||||
int x, j;
|
||||
if (p1[i] == p2[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x = p1[i] ^ p2[i];
|
||||
for (j = 0; j < CHAR_BIT; ++j)
|
||||
{
|
||||
if (x & (1 << (CHAR_BIT - 1)))
|
||||
{
|
||||
return i * CHAR_BIT + j;
|
||||
}
|
||||
x <<= 1;
|
||||
}
|
||||
const unsigned char *p1 = (const unsigned char *)a1;
|
||||
const unsigned char *p2 = (const unsigned char *)a2;
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(*a1); ++i) {
|
||||
unsigned char x;
|
||||
size_t j;
|
||||
if (p1[i] == p2[i]) {
|
||||
continue;
|
||||
}
|
||||
x = p1[i] ^ p2[i];
|
||||
for (j = 0; j < CHAR_BIT; ++j) {
|
||||
if (x & (1 << (CHAR_BIT - 1))) {
|
||||
return i * CHAR_BIT + j;
|
||||
}
|
||||
x <<= 1;
|
||||
}
|
||||
}
|
||||
return sizeof(*a1) * CHAR_BIT;
|
||||
}
|
||||
|
||||
@ -287,36 +236,46 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2)
|
||||
{
|
||||
const struct addrinfo_sort_elem *a1 = (const struct addrinfo_sort_elem *)ptr1;
|
||||
const struct addrinfo_sort_elem *a2 = (const struct addrinfo_sort_elem *)ptr2;
|
||||
int scope_src1, scope_dst1, scope_match1;
|
||||
int scope_src2, scope_dst2, scope_match2;
|
||||
int label_src1, label_dst1, label_match1;
|
||||
int label_src2, label_dst2, label_match2;
|
||||
int precedence1, precedence2;
|
||||
int prefixlen1, prefixlen2;
|
||||
int scope_src1;
|
||||
int scope_dst1;
|
||||
int scope_match1;
|
||||
int scope_src2;
|
||||
int scope_dst2;
|
||||
int scope_match2;
|
||||
int label_src1;
|
||||
int label_dst1;
|
||||
int label_match1;
|
||||
int label_src2;
|
||||
int label_dst2;
|
||||
int label_match2;
|
||||
int precedence1;
|
||||
int precedence2;
|
||||
size_t prefixlen1;
|
||||
size_t prefixlen2;
|
||||
|
||||
/* Rule 1: Avoid unusable destinations. */
|
||||
if (a1->has_src_addr != a2->has_src_addr)
|
||||
{
|
||||
return a2->has_src_addr - a1->has_src_addr;
|
||||
}
|
||||
if (a1->has_src_addr != a2->has_src_addr) {
|
||||
return ((int)a2->has_src_addr) - ((int)a1->has_src_addr);
|
||||
}
|
||||
|
||||
/* Rule 2: Prefer matching scope. */
|
||||
scope_src1 = ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
||||
if (a1->has_src_addr)
|
||||
if (a1->has_src_addr) {
|
||||
scope_src1 = get_scope(&a1->src_addr.sa);
|
||||
scope_dst1 = get_scope(a1->ai->ai_addr);
|
||||
}
|
||||
scope_dst1 = get_scope(a1->ai->ai_addr);
|
||||
scope_match1 = (scope_src1 == scope_dst1);
|
||||
|
||||
scope_src2 = ARES_IPV6_ADDR_SCOPE_NODELOCAL;
|
||||
if (a2->has_src_addr)
|
||||
if (a2->has_src_addr) {
|
||||
scope_src2 = get_scope(&a2->src_addr.sa);
|
||||
scope_dst2 = get_scope(a2->ai->ai_addr);
|
||||
}
|
||||
scope_dst2 = get_scope(a2->ai->ai_addr);
|
||||
scope_match2 = (scope_src2 == scope_dst2);
|
||||
|
||||
if (scope_match1 != scope_match2)
|
||||
{
|
||||
return scope_match2 - scope_match1;
|
||||
}
|
||||
if (scope_match1 != scope_match2) {
|
||||
return scope_match2 - scope_match1;
|
||||
}
|
||||
|
||||
/* Rule 3: Avoid deprecated addresses. */
|
||||
|
||||
@ -324,81 +283,76 @@ static int rfc6724_compare(const void *ptr1, const void *ptr2)
|
||||
|
||||
/* Rule 5: Prefer matching label. */
|
||||
label_src1 = 1;
|
||||
if (a1->has_src_addr)
|
||||
if (a1->has_src_addr) {
|
||||
label_src1 = get_label(&a1->src_addr.sa);
|
||||
label_dst1 = get_label(a1->ai->ai_addr);
|
||||
}
|
||||
label_dst1 = get_label(a1->ai->ai_addr);
|
||||
label_match1 = (label_src1 == label_dst1);
|
||||
|
||||
label_src2 = 1;
|
||||
if (a2->has_src_addr)
|
||||
if (a2->has_src_addr) {
|
||||
label_src2 = get_label(&a2->src_addr.sa);
|
||||
label_dst2 = get_label(a2->ai->ai_addr);
|
||||
}
|
||||
label_dst2 = get_label(a2->ai->ai_addr);
|
||||
label_match2 = (label_src2 == label_dst2);
|
||||
|
||||
if (label_match1 != label_match2)
|
||||
{
|
||||
return label_match2 - label_match1;
|
||||
}
|
||||
if (label_match1 != label_match2) {
|
||||
return label_match2 - label_match1;
|
||||
}
|
||||
|
||||
/* Rule 6: Prefer higher precedence. */
|
||||
precedence1 = get_precedence(a1->ai->ai_addr);
|
||||
precedence2 = get_precedence(a2->ai->ai_addr);
|
||||
if (precedence1 != precedence2)
|
||||
{
|
||||
return precedence2 - precedence1;
|
||||
}
|
||||
if (precedence1 != precedence2) {
|
||||
return precedence2 - precedence1;
|
||||
}
|
||||
|
||||
/* Rule 7: Prefer native transport. */
|
||||
|
||||
/* Rule 8: Prefer smaller scope. */
|
||||
if (scope_dst1 != scope_dst2)
|
||||
{
|
||||
return scope_dst1 - scope_dst2;
|
||||
}
|
||||
if (scope_dst1 != scope_dst2) {
|
||||
return scope_dst1 - scope_dst2;
|
||||
}
|
||||
|
||||
/* Rule 9: Use longest matching prefix. */
|
||||
if (a1->has_src_addr && a1->ai->ai_addr->sa_family == AF_INET6 &&
|
||||
a2->has_src_addr && a2->ai->ai_addr->sa_family == AF_INET6)
|
||||
{
|
||||
const struct sockaddr_in6 *a1_src = &a1->src_addr.sa6;
|
||||
const struct sockaddr_in6 *a1_dst =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, a1->ai->ai_addr);
|
||||
const struct sockaddr_in6 *a2_src = &a2->src_addr.sa6;
|
||||
const struct sockaddr_in6 *a2_dst =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, a2->ai->ai_addr);
|
||||
prefixlen1 = common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
|
||||
prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
|
||||
if (prefixlen1 != prefixlen2)
|
||||
{
|
||||
return prefixlen2 - prefixlen1;
|
||||
}
|
||||
a2->has_src_addr && a2->ai->ai_addr->sa_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *a1_src = &a1->src_addr.sa6;
|
||||
const struct sockaddr_in6 *a1_dst =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, a1->ai->ai_addr);
|
||||
const struct sockaddr_in6 *a2_src = &a2->src_addr.sa6;
|
||||
const struct sockaddr_in6 *a2_dst =
|
||||
CARES_INADDR_CAST(const struct sockaddr_in6 *, a2->ai->ai_addr);
|
||||
prefixlen1 = common_prefix_len(&a1_src->sin6_addr, &a1_dst->sin6_addr);
|
||||
prefixlen2 = common_prefix_len(&a2_src->sin6_addr, &a2_dst->sin6_addr);
|
||||
if (prefixlen1 != prefixlen2) {
|
||||
return (int)prefixlen2 - (int)prefixlen1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Rule 10: Leave the order unchanged.
|
||||
* We need this since qsort() is not necessarily stable.
|
||||
*/
|
||||
return a1->original_order - a2->original_order;
|
||||
return ((int)a1->original_order) - ((int)a2->original_order);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the source address that will be used if trying to connect to the given
|
||||
* address.
|
||||
*
|
||||
* Returns 1 if a source address was found, 0 if the address is unreachable,
|
||||
* Returns 1 if a source address was found, 0 if the address is unreachable
|
||||
* and -1 if a fatal error occurred. If 0 or 1, the contents of src_addr are
|
||||
* undefined.
|
||||
*/
|
||||
static int find_src_addr(ares_channel channel,
|
||||
const struct sockaddr *addr,
|
||||
static int find_src_addr(ares_channel_t *channel, const struct sockaddr *addr,
|
||||
struct sockaddr *src_addr)
|
||||
{
|
||||
ares_socket_t sock;
|
||||
int ret;
|
||||
ares_socket_t sock;
|
||||
int ret;
|
||||
ares_socklen_t len;
|
||||
|
||||
switch (addr->sa_family)
|
||||
{
|
||||
switch (addr->sa_family) {
|
||||
case AF_INET:
|
||||
len = sizeof(struct sockaddr_in);
|
||||
break;
|
||||
@ -408,38 +362,30 @@ static int find_src_addr(ares_channel channel,
|
||||
default:
|
||||
/* No known usable source address for non-INET families. */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sock = ares__open_socket(channel, addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (sock == ARES_SOCKET_BAD)
|
||||
{
|
||||
if (errno == EAFNOSUPPORT)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
ret = ares__connect_socket(channel, sock, addr, len);
|
||||
}
|
||||
while (ret == -1 && errno == EINTR);
|
||||
|
||||
if (ret == -1)
|
||||
{
|
||||
ares__close_socket(channel, sock);
|
||||
if (sock == ARES_SOCKET_BAD) {
|
||||
if (errno == EAFNOSUPPORT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (getsockname(sock, src_addr, &len) != 0)
|
||||
{
|
||||
ares__close_socket(channel, sock);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
ret = ares__connect_socket(channel, sock, addr, len);
|
||||
} while (ret == -1 && errno == EINTR);
|
||||
|
||||
if (ret == -1) {
|
||||
ares__close_socket(channel, sock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (getsockname(sock, src_addr, &len) != 0) {
|
||||
ares__close_socket(channel, sock);
|
||||
return -1;
|
||||
}
|
||||
ares__close_socket(channel, sock);
|
||||
return 1;
|
||||
}
|
||||
@ -448,47 +394,47 @@ static int find_src_addr(ares_channel channel,
|
||||
* Sort the linked list starting at sentinel->ai_next in RFC6724 order.
|
||||
* Will leave the list unchanged if an error occurs.
|
||||
*/
|
||||
int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sentinel)
|
||||
ares_status_t ares__sortaddrinfo(ares_channel_t *channel,
|
||||
struct ares_addrinfo_node *list_sentinel)
|
||||
{
|
||||
struct ares_addrinfo_node *cur;
|
||||
int nelem = 0, i;
|
||||
int has_src_addr;
|
||||
size_t nelem = 0;
|
||||
size_t i;
|
||||
int has_src_addr;
|
||||
struct addrinfo_sort_elem *elems;
|
||||
|
||||
cur = list_sentinel->ai_next;
|
||||
while (cur)
|
||||
{
|
||||
++nelem;
|
||||
cur = cur->ai_next;
|
||||
}
|
||||
while (cur) {
|
||||
++nelem;
|
||||
cur = cur->ai_next;
|
||||
}
|
||||
|
||||
if (!nelem)
|
||||
return ARES_ENODATA;
|
||||
if (!nelem) {
|
||||
return ARES_ENODATA;
|
||||
}
|
||||
|
||||
elems = (struct addrinfo_sort_elem *)ares_malloc(
|
||||
nelem * sizeof(struct addrinfo_sort_elem));
|
||||
if (!elems)
|
||||
{
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
nelem * sizeof(struct addrinfo_sort_elem));
|
||||
if (!elems) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert the linked list to an array that also contains the candidate
|
||||
* source address for each destination address.
|
||||
*/
|
||||
for (i = 0, cur = list_sentinel->ai_next; i < nelem; ++i, cur = cur->ai_next)
|
||||
{
|
||||
assert(cur != NULL);
|
||||
elems[i].ai = cur;
|
||||
elems[i].original_order = i;
|
||||
has_src_addr = find_src_addr(channel, cur->ai_addr, &elems[i].src_addr.sa);
|
||||
if (has_src_addr == -1)
|
||||
{
|
||||
ares_free(elems);
|
||||
return ARES_ENOTFOUND;
|
||||
}
|
||||
elems[i].has_src_addr = has_src_addr;
|
||||
for (i = 0, cur = list_sentinel->ai_next; i < nelem;
|
||||
++i, cur = cur->ai_next) {
|
||||
assert(cur != NULL);
|
||||
elems[i].ai = cur;
|
||||
elems[i].original_order = i;
|
||||
has_src_addr = find_src_addr(channel, cur->ai_addr, &elems[i].src_addr.sa);
|
||||
if (has_src_addr == -1) {
|
||||
ares_free(elems);
|
||||
return ARES_ENOTFOUND;
|
||||
}
|
||||
elems[i].has_src_addr = (has_src_addr == 1) ? ARES_TRUE : ARES_FALSE;
|
||||
}
|
||||
|
||||
/* Sort the addresses, and rearrange the linked list so it matches the sorted
|
||||
* order. */
|
||||
@ -496,10 +442,9 @@ int ares__sortaddrinfo(ares_channel channel, struct ares_addrinfo_node *list_sen
|
||||
rfc6724_compare);
|
||||
|
||||
list_sentinel->ai_next = elems[0].ai;
|
||||
for (i = 0; i < nelem - 1; ++i)
|
||||
{
|
||||
elems[i].ai->ai_next = elems[i + 1].ai;
|
||||
}
|
||||
for (i = 0; i < nelem - 1; ++i) {
|
||||
elems[i].ai->ai_next = elems[i + 1].ai;
|
||||
}
|
||||
elems[nelem - 1].ai->ai_next = NULL;
|
||||
|
||||
ares_free(elems);
|
||||
|
||||
607
src/third_party/cares/dist/src/lib/ares__threads.c
vendored
Normal file
607
src/third_party/cares/dist/src/lib/ares__threads.c
vendored
Normal file
@ -0,0 +1,607 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
#ifdef CARES_THREADS
|
||||
# ifdef _WIN32
|
||||
|
||||
struct ares__thread_mutex {
|
||||
CRITICAL_SECTION mutex;
|
||||
};
|
||||
|
||||
ares__thread_mutex_t *ares__thread_mutex_create(void)
|
||||
{
|
||||
ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut));
|
||||
if (mut == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&mut->mutex);
|
||||
return mut;
|
||||
}
|
||||
|
||||
void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (mut == NULL) {
|
||||
return;
|
||||
}
|
||||
DeleteCriticalSection(&mut->mutex);
|
||||
ares_free(mut);
|
||||
}
|
||||
|
||||
void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (mut == NULL) {
|
||||
return;
|
||||
}
|
||||
EnterCriticalSection(&mut->mutex);
|
||||
}
|
||||
|
||||
void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (mut == NULL) {
|
||||
return;
|
||||
}
|
||||
LeaveCriticalSection(&mut->mutex);
|
||||
}
|
||||
|
||||
struct ares__thread_cond {
|
||||
CONDITION_VARIABLE cond;
|
||||
};
|
||||
|
||||
ares__thread_cond_t *ares__thread_cond_create(void)
|
||||
{
|
||||
ares__thread_cond_t *cond = ares_malloc_zero(sizeof(*cond));
|
||||
if (cond == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
InitializeConditionVariable(&cond->cond);
|
||||
return cond;
|
||||
}
|
||||
|
||||
void ares__thread_cond_destroy(ares__thread_cond_t *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
ares_free(cond);
|
||||
}
|
||||
|
||||
void ares__thread_cond_signal(ares__thread_cond_t *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
WakeConditionVariable(&cond->cond);
|
||||
}
|
||||
|
||||
void ares__thread_cond_broadcast(ares__thread_cond_t *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
WakeAllConditionVariable(&cond->cond);
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_cond_wait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (cond == NULL || mut == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
SleepConditionVariableCS(&cond->cond, &mut->mutex, INFINITE);
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_cond_timedwait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut,
|
||||
unsigned long timeout_ms)
|
||||
{
|
||||
if (cond == NULL || mut == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
if (!SleepConditionVariableCS(&cond->cond, &mut->mutex, timeout_ms)) {
|
||||
return ARES_ETIMEOUT;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
struct ares__thread {
|
||||
HANDLE thread;
|
||||
DWORD id;
|
||||
|
||||
void *(*func)(void *arg);
|
||||
void *arg;
|
||||
void *rv;
|
||||
};
|
||||
|
||||
/* Wrap for pthread compatibility */
|
||||
static DWORD WINAPI ares__thread_func(LPVOID lpParameter)
|
||||
{
|
||||
ares__thread_t *thread = lpParameter;
|
||||
|
||||
thread->rv = thread->func(thread->arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_create(ares__thread_t **thread,
|
||||
ares__thread_func_t func, void *arg)
|
||||
{
|
||||
ares__thread_t *thr = NULL;
|
||||
|
||||
if (func == NULL || thread == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
thr = ares_malloc_zero(sizeof(*thr));
|
||||
if (thr == NULL) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
thr->func = func;
|
||||
thr->arg = arg;
|
||||
thr->thread = CreateThread(NULL, 0, ares__thread_func, thr, 0, &thr->id);
|
||||
if (thr->thread == NULL) {
|
||||
ares_free(thr);
|
||||
return ARES_ESERVFAIL;
|
||||
}
|
||||
|
||||
*thread = thr;
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_join(ares__thread_t *thread, void **rv)
|
||||
{
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
|
||||
if (thread == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
if (WaitForSingleObject(thread->thread, INFINITE) != WAIT_OBJECT_0) {
|
||||
status = ARES_ENOTFOUND;
|
||||
} else {
|
||||
CloseHandle(thread->thread);
|
||||
}
|
||||
|
||||
if (status == ARES_SUCCESS && rv != NULL) {
|
||||
*rv = thread->rv;
|
||||
}
|
||||
ares_free(thread);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
# else /* !WIN32 == PTHREAD */
|
||||
# include <pthread.h>
|
||||
|
||||
/* for clock_gettime() */
|
||||
# ifdef HAVE_TIME_H
|
||||
# include <time.h>
|
||||
# endif
|
||||
|
||||
/* for gettimeofday() */
|
||||
# ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# endif
|
||||
|
||||
struct ares__thread_mutex {
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
ares__thread_mutex_t *ares__thread_mutex_create(void)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut));
|
||||
if (mut == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0) {
|
||||
ares_free(mut);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&mut->mutex, &attr) != 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
return mut;
|
||||
|
||||
fail:
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
ares_free(mut);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (mut == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_destroy(&mut->mutex);
|
||||
ares_free(mut);
|
||||
}
|
||||
|
||||
void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (mut == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_lock(&mut->mutex);
|
||||
}
|
||||
|
||||
void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (mut == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_mutex_unlock(&mut->mutex);
|
||||
}
|
||||
|
||||
struct ares__thread_cond {
|
||||
pthread_cond_t cond;
|
||||
};
|
||||
|
||||
ares__thread_cond_t *ares__thread_cond_create(void)
|
||||
{
|
||||
ares__thread_cond_t *cond = ares_malloc_zero(sizeof(*cond));
|
||||
if (cond == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pthread_cond_init(&cond->cond, NULL);
|
||||
return cond;
|
||||
}
|
||||
|
||||
void ares__thread_cond_destroy(ares__thread_cond_t *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_cond_destroy(&cond->cond);
|
||||
ares_free(cond);
|
||||
}
|
||||
|
||||
void ares__thread_cond_signal(ares__thread_cond_t *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_cond_signal(&cond->cond);
|
||||
}
|
||||
|
||||
void ares__thread_cond_broadcast(ares__thread_cond_t *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return;
|
||||
}
|
||||
pthread_cond_broadcast(&cond->cond);
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_cond_wait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut)
|
||||
{
|
||||
if (cond == NULL || mut == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
pthread_cond_wait(&cond->cond, &mut->mutex);
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
static void ares__timespec_timeout(struct timespec *ts, unsigned long add_ms)
|
||||
{
|
||||
# if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
|
||||
clock_gettime(CLOCK_REALTIME, ts);
|
||||
# elif defined(HAVE_GETTIMEOFDAY)
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
ts->tv_sec = tv.tv_sec;
|
||||
ts->tv_nsec = tv.tv_usec * 1000;
|
||||
# else
|
||||
# error cannot determine current system time
|
||||
# endif
|
||||
|
||||
ts->tv_sec += add_ms / 1000;
|
||||
ts->tv_nsec += (add_ms % 1000) * 1000000;
|
||||
|
||||
/* Normalize if needed */
|
||||
if (ts->tv_nsec >= 1000000000) {
|
||||
ts->tv_sec += ts->tv_nsec / 1000000000;
|
||||
ts->tv_nsec %= 1000000000;
|
||||
}
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_cond_timedwait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut,
|
||||
unsigned long timeout_ms)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
if (cond == NULL || mut == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
ares__timespec_timeout(&ts, timeout_ms);
|
||||
|
||||
if (pthread_cond_timedwait(&cond->cond, &mut->mutex, &ts) != 0) {
|
||||
return ARES_ETIMEOUT;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
struct ares__thread {
|
||||
pthread_t thread;
|
||||
};
|
||||
|
||||
ares_status_t ares__thread_create(ares__thread_t **thread,
|
||||
ares__thread_func_t func, void *arg)
|
||||
{
|
||||
ares__thread_t *thr = NULL;
|
||||
|
||||
if (func == NULL || thread == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
thr = ares_malloc_zero(sizeof(*thr));
|
||||
if (thr == NULL) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
if (pthread_create(&thr->thread, NULL, func, arg) != 0) {
|
||||
ares_free(thr);
|
||||
return ARES_ESERVFAIL;
|
||||
}
|
||||
|
||||
*thread = thr;
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_join(ares__thread_t *thread, void **rv)
|
||||
{
|
||||
void *ret = NULL;
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
|
||||
if (thread == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
if (pthread_join(thread->thread, &ret) != 0) {
|
||||
status = ARES_ENOTFOUND;
|
||||
}
|
||||
ares_free(thread);
|
||||
|
||||
if (status == ARES_SUCCESS && rv != NULL) {
|
||||
*rv = ret;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
ares_bool_t ares_threadsafety(void)
|
||||
{
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
#else /* !CARES_THREADS */
|
||||
|
||||
/* NoOp */
|
||||
ares__thread_mutex_t *ares__thread_mutex_create(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
|
||||
{
|
||||
(void)mut;
|
||||
}
|
||||
|
||||
void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
|
||||
{
|
||||
(void)mut;
|
||||
}
|
||||
|
||||
void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
|
||||
{
|
||||
(void)mut;
|
||||
}
|
||||
|
||||
ares__thread_cond_t *ares__thread_cond_create(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ares__thread_cond_destroy(ares__thread_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
}
|
||||
|
||||
void ares__thread_cond_signal(ares__thread_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
}
|
||||
|
||||
void ares__thread_cond_broadcast(ares__thread_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_cond_wait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut)
|
||||
{
|
||||
(void)cond;
|
||||
(void)mut;
|
||||
return ARES_ENOTIMP;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_cond_timedwait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut,
|
||||
unsigned long timeout_ms)
|
||||
{
|
||||
(void)cond;
|
||||
(void)mut;
|
||||
(void)timeout_ms;
|
||||
return ARES_ENOTIMP;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_create(ares__thread_t **thread,
|
||||
ares__thread_func_t func, void *arg)
|
||||
{
|
||||
(void)thread;
|
||||
(void)func;
|
||||
(void)arg;
|
||||
return ARES_ENOTIMP;
|
||||
}
|
||||
|
||||
ares_status_t ares__thread_join(ares__thread_t *thread, void **rv)
|
||||
{
|
||||
(void)thread;
|
||||
(void)rv;
|
||||
return ARES_ENOTIMP;
|
||||
}
|
||||
|
||||
ares_bool_t ares_threadsafety(void)
|
||||
{
|
||||
return ARES_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ares_status_t ares__channel_threading_init(ares_channel_t *channel)
|
||||
{
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
|
||||
/* Threading is optional! */
|
||||
if (!ares_threadsafety()) {
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
channel->lock = ares__thread_mutex_create();
|
||||
if (channel->lock == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
channel->cond_empty = ares__thread_cond_create();
|
||||
if (channel->cond_empty == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
if (status != ARES_SUCCESS) {
|
||||
ares__channel_threading_destroy(channel);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void ares__channel_threading_destroy(ares_channel_t *channel)
|
||||
{
|
||||
ares__thread_mutex_destroy(channel->lock);
|
||||
channel->lock = NULL;
|
||||
ares__thread_cond_destroy(channel->cond_empty);
|
||||
channel->cond_empty = NULL;
|
||||
}
|
||||
|
||||
void ares__channel_lock(ares_channel_t *channel)
|
||||
{
|
||||
ares__thread_mutex_lock(channel->lock);
|
||||
}
|
||||
|
||||
void ares__channel_unlock(ares_channel_t *channel)
|
||||
{
|
||||
ares__thread_mutex_unlock(channel->lock);
|
||||
}
|
||||
|
||||
/* Must not be holding a channel lock already, public function only */
|
||||
ares_status_t ares_queue_wait_empty(ares_channel_t *channel, int timeout_ms)
|
||||
{
|
||||
ares_status_t status = ARES_SUCCESS;
|
||||
struct timeval tout;
|
||||
|
||||
if (!ares_threadsafety()) {
|
||||
return ARES_ENOTIMP;
|
||||
}
|
||||
|
||||
if (channel == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
if (timeout_ms >= 0) {
|
||||
tout = ares__tvnow();
|
||||
tout.tv_sec += timeout_ms / 1000;
|
||||
tout.tv_usec += (timeout_ms % 1000) * 1000;
|
||||
}
|
||||
|
||||
ares__thread_mutex_lock(channel->lock);
|
||||
while (ares__llist_len(channel->all_queries)) {
|
||||
if (timeout_ms < 0) {
|
||||
ares__thread_cond_wait(channel->cond_empty, channel->lock);
|
||||
} else {
|
||||
struct timeval tv_remaining;
|
||||
struct timeval tv_now = ares__tvnow();
|
||||
unsigned long tms;
|
||||
|
||||
ares__timeval_remaining(&tv_remaining, &tv_now, &tout);
|
||||
tms = (unsigned long)((tv_remaining.tv_sec * 1000) +
|
||||
(tv_remaining.tv_usec / 1000));
|
||||
if (tms == 0) {
|
||||
status = ARES_ETIMEOUT;
|
||||
} else {
|
||||
status =
|
||||
ares__thread_cond_timedwait(channel->cond_empty, channel->lock, tms);
|
||||
}
|
||||
}
|
||||
}
|
||||
ares__thread_mutex_unlock(channel->lock);
|
||||
return status;
|
||||
}
|
||||
|
||||
void ares_queue_notify_empty(ares_channel_t *channel)
|
||||
{
|
||||
if (channel == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* We are guaranteed to be holding a channel lock already */
|
||||
if (ares__llist_len(channel->all_queries)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Notify all waiters of the conditional */
|
||||
ares__thread_cond_broadcast(channel->cond_empty);
|
||||
}
|
||||
60
src/third_party/cares/dist/src/lib/ares__threads.h
vendored
Normal file
60
src/third_party/cares/dist/src/lib/ares__threads.h
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES__THREADS_H
|
||||
#define __ARES__THREADS_H
|
||||
|
||||
struct ares__thread_mutex;
|
||||
typedef struct ares__thread_mutex ares__thread_mutex_t;
|
||||
|
||||
ares__thread_mutex_t *ares__thread_mutex_create(void);
|
||||
void ares__thread_mutex_destroy(ares__thread_mutex_t *mut);
|
||||
void ares__thread_mutex_lock(ares__thread_mutex_t *mut);
|
||||
void ares__thread_mutex_unlock(ares__thread_mutex_t *mut);
|
||||
|
||||
|
||||
struct ares__thread_cond;
|
||||
typedef struct ares__thread_cond ares__thread_cond_t;
|
||||
|
||||
ares__thread_cond_t *ares__thread_cond_create(void);
|
||||
void ares__thread_cond_destroy(ares__thread_cond_t *cond);
|
||||
void ares__thread_cond_signal(ares__thread_cond_t *cond);
|
||||
void ares__thread_cond_broadcast(ares__thread_cond_t *cond);
|
||||
ares_status_t ares__thread_cond_wait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut);
|
||||
ares_status_t ares__thread_cond_timedwait(ares__thread_cond_t *cond,
|
||||
ares__thread_mutex_t *mut,
|
||||
unsigned long timeout_ms);
|
||||
|
||||
|
||||
struct ares__thread;
|
||||
typedef struct ares__thread ares__thread_t;
|
||||
|
||||
typedef void *(*ares__thread_func_t)(void *arg);
|
||||
ares_status_t ares__thread_create(ares__thread_t **thread,
|
||||
ares__thread_func_t func, void *arg);
|
||||
ares_status_t ares__thread_join(ares__thread_t *thread, void **rv);
|
||||
|
||||
#endif
|
||||
@ -1,15 +1,27 @@
|
||||
|
||||
/* Copyright (C) 2008 by Daniel Stenberg et al
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. M.I.T. makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 2008 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
@ -26,9 +38,9 @@ struct timeval ares__tvnow(void)
|
||||
** increases monotonically and wraps once 49.7 days have elapsed.
|
||||
*/
|
||||
struct timeval now;
|
||||
DWORD milliseconds = GetTickCount();
|
||||
now.tv_sec = milliseconds / 1000;
|
||||
now.tv_usec = (milliseconds % 1000) * 1000;
|
||||
DWORD milliseconds = GetTickCount();
|
||||
now.tv_sec = (long)milliseconds / 1000;
|
||||
now.tv_usec = (long)(milliseconds % 1000) * 1000;
|
||||
return now;
|
||||
}
|
||||
|
||||
@ -43,26 +55,26 @@ struct timeval ares__tvnow(void)
|
||||
** in any case the time starting point does not change once that the
|
||||
** system has started up.
|
||||
*/
|
||||
struct timeval now;
|
||||
struct timeval now;
|
||||
struct timespec tsnow;
|
||||
if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
|
||||
now.tv_sec = tsnow.tv_sec;
|
||||
now.tv_usec = tsnow.tv_nsec / 1000;
|
||||
if (0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
|
||||
now.tv_sec = tsnow.tv_sec;
|
||||
now.tv_usec = (int)(tsnow.tv_nsec / 1000);
|
||||
}
|
||||
/*
|
||||
** Even when the configure process has truly detected monotonic clock
|
||||
** availability, it might happen that it is not actually available at
|
||||
** run-time. When this occurs simply fallback to other time source.
|
||||
*/
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
# ifdef HAVE_GETTIMEOFDAY
|
||||
else
|
||||
(void)gettimeofday(&now, NULL); /* LCOV_EXCL_LINE */
|
||||
#else
|
||||
(void)gettimeofday(&now, NULL); /* LCOV_EXCL_LINE */
|
||||
# else
|
||||
else {
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_usec = 0;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
return now;
|
||||
}
|
||||
|
||||
@ -88,24 +100,9 @@ struct timeval ares__tvnow(void)
|
||||
** time() returns the value of time in seconds since the Epoch.
|
||||
*/
|
||||
struct timeval now;
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_sec = (long)time(NULL);
|
||||
now.tv_usec = 0;
|
||||
return now;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if 0 /* Not used */
|
||||
/*
|
||||
* Make sure that the first argument is the more recent time, as otherwise
|
||||
* we'll get a weird negative time-diff back...
|
||||
*
|
||||
* Returns: the time difference in number of milliseconds.
|
||||
*/
|
||||
long ares__tvdiff(struct timeval newer, struct timeval older)
|
||||
{
|
||||
return (newer.tv_sec-older.tv_sec)*1000+
|
||||
(newer.tv_usec-older.tv_usec)/1000;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
360
src/third_party/cares/dist/src/lib/ares_android.c
vendored
360
src/third_party/cares/dist/src/lib/ares_android.c
vendored
@ -1,28 +1,39 @@
|
||||
/* Copyright (C) 2017 by John Schember <john@nachtimwald.com>
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) John Schember
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#if defined(ANDROID) || defined(__ANDROID__)
|
||||
|
||||
#include <jni.h>
|
||||
# include <jni.h>
|
||||
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_android.h"
|
||||
#include "ares_private.h"
|
||||
# include "ares_setup.h"
|
||||
# include "ares.h"
|
||||
# include "ares_android.h"
|
||||
# include "ares_private.h"
|
||||
|
||||
static JavaVM *android_jvm = NULL;
|
||||
static jobject android_connectivity_manager = NULL;
|
||||
static JavaVM *android_jvm = NULL;
|
||||
static jobject android_connectivity_manager = NULL;
|
||||
|
||||
/* ConnectivityManager.getActiveNetwork */
|
||||
static jmethodID android_cm_active_net_mid = NULL;
|
||||
@ -39,12 +50,13 @@ static jmethodID android_list_get_mid = NULL;
|
||||
/* InetAddress.getHostAddress */
|
||||
static jmethodID android_ia_host_addr_mid = NULL;
|
||||
|
||||
static jclass jni_get_class(JNIEnv *env, const char *path)
|
||||
static jclass jni_get_class(JNIEnv *env, const char *path)
|
||||
{
|
||||
jclass cls = NULL;
|
||||
|
||||
if (env == NULL || path == NULL || *path == '\0')
|
||||
if (env == NULL || path == NULL || *path == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cls = (*env)->FindClass(env, path);
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
@ -60,14 +72,12 @@ static jmethodID jni_get_method_id(JNIEnv *env, jclass cls,
|
||||
jmethodID mid = NULL;
|
||||
|
||||
if (env == NULL || cls == NULL || func_name == NULL || *func_name == '\0' ||
|
||||
signature == NULL || *signature == '\0')
|
||||
{
|
||||
signature == NULL || *signature == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mid = (*env)->GetMethodID(env, cls, func_name, signature);
|
||||
if ((*env)->ExceptionOccurred(env))
|
||||
{
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
(*env)->ExceptionClear(env);
|
||||
return NULL;
|
||||
}
|
||||
@ -82,29 +92,31 @@ void ares_library_init_jvm(JavaVM *jvm)
|
||||
|
||||
int ares_library_init_android(jobject connectivity_manager)
|
||||
{
|
||||
JNIEnv *env = NULL;
|
||||
int need_detatch = 0;
|
||||
int res;
|
||||
int ret = ARES_ENOTINITIALIZED;
|
||||
jclass obj_cls = NULL;
|
||||
JNIEnv *env = NULL;
|
||||
int need_detatch = 0;
|
||||
int res;
|
||||
ares_status_t ret = ARES_ENOTINITIALIZED;
|
||||
jclass obj_cls = NULL;
|
||||
|
||||
if (android_jvm == NULL)
|
||||
if (android_jvm == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
res = (*android_jvm)->GetEnv(android_jvm, (void **)&env, JNI_VERSION_1_6);
|
||||
if (res == JNI_EDETACHED)
|
||||
{
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
if (res == JNI_EDETACHED) {
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
need_detatch = 1;
|
||||
}
|
||||
if (res != JNI_OK || env == NULL)
|
||||
if (res != JNI_OK || env == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
android_connectivity_manager =
|
||||
(*env)->NewGlobalRef(env, connectivity_manager);
|
||||
if (android_connectivity_manager == NULL)
|
||||
(*env)->NewGlobalRef(env, connectivity_manager);
|
||||
if (android_connectivity_manager == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Initialization has succeeded. Now attempt to cache the methods that will be
|
||||
* called by ares_get_android_server_list. */
|
||||
@ -112,166 +124,178 @@ int ares_library_init_android(jobject connectivity_manager)
|
||||
|
||||
/* ConnectivityManager in API 1. */
|
||||
obj_cls = jni_get_class(env, "android/net/ConnectivityManager");
|
||||
if (obj_cls == NULL)
|
||||
if (obj_cls == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* ConnectivityManager.getActiveNetwork in API 23. */
|
||||
android_cm_active_net_mid =
|
||||
jni_get_method_id(env, obj_cls, "getActiveNetwork",
|
||||
"()Landroid/net/Network;");
|
||||
if (android_cm_active_net_mid == NULL)
|
||||
android_cm_active_net_mid = jni_get_method_id(
|
||||
env, obj_cls, "getActiveNetwork", "()Landroid/net/Network;");
|
||||
if (android_cm_active_net_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* ConnectivityManager.getLinkProperties in API 21. */
|
||||
android_cm_link_props_mid =
|
||||
jni_get_method_id(env, obj_cls, "getLinkProperties",
|
||||
"(Landroid/net/Network;)Landroid/net/LinkProperties;");
|
||||
if (android_cm_link_props_mid == NULL)
|
||||
jni_get_method_id(env, obj_cls, "getLinkProperties",
|
||||
"(Landroid/net/Network;)Landroid/net/LinkProperties;");
|
||||
if (android_cm_link_props_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* LinkProperties in API 21. */
|
||||
(*env)->DeleteLocalRef(env, obj_cls);
|
||||
obj_cls = jni_get_class(env, "android/net/LinkProperties");
|
||||
if (obj_cls == NULL)
|
||||
if (obj_cls == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* getDnsServers in API 21. */
|
||||
android_lp_dns_servers_mid = jni_get_method_id(env, obj_cls, "getDnsServers",
|
||||
"()Ljava/util/List;");
|
||||
if (android_lp_dns_servers_mid == NULL)
|
||||
android_lp_dns_servers_mid =
|
||||
jni_get_method_id(env, obj_cls, "getDnsServers", "()Ljava/util/List;");
|
||||
if (android_lp_dns_servers_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* getDomains in API 21. */
|
||||
android_lp_domains_mid = jni_get_method_id(env, obj_cls, "getDomains",
|
||||
"()Ljava/lang/String;");
|
||||
if (android_lp_domains_mid == NULL)
|
||||
android_lp_domains_mid =
|
||||
jni_get_method_id(env, obj_cls, "getDomains", "()Ljava/lang/String;");
|
||||
if (android_lp_domains_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
(*env)->DeleteLocalRef(env, obj_cls);
|
||||
obj_cls = jni_get_class(env, "java/util/List");
|
||||
if (obj_cls == NULL)
|
||||
if (obj_cls == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
android_list_size_mid = jni_get_method_id(env, obj_cls, "size", "()I");
|
||||
if (android_list_size_mid == NULL)
|
||||
if (android_list_size_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
android_list_get_mid = jni_get_method_id(env, obj_cls, "get",
|
||||
"(I)Ljava/lang/Object;");
|
||||
if (android_list_get_mid == NULL)
|
||||
android_list_get_mid =
|
||||
jni_get_method_id(env, obj_cls, "get", "(I)Ljava/lang/Object;");
|
||||
if (android_list_get_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
(*env)->DeleteLocalRef(env, obj_cls);
|
||||
obj_cls = jni_get_class(env, "java/net/InetAddress");
|
||||
if (obj_cls == NULL)
|
||||
if (obj_cls == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
android_ia_host_addr_mid = jni_get_method_id(env, obj_cls, "getHostAddress",
|
||||
"()Ljava/lang/String;");
|
||||
if (android_ia_host_addr_mid == NULL)
|
||||
android_ia_host_addr_mid =
|
||||
jni_get_method_id(env, obj_cls, "getHostAddress", "()Ljava/lang/String;");
|
||||
if (android_ia_host_addr_mid == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
(*env)->DeleteLocalRef(env, obj_cls);
|
||||
goto done;
|
||||
|
||||
cleanup:
|
||||
if (obj_cls != NULL)
|
||||
if (obj_cls != NULL) {
|
||||
(*env)->DeleteLocalRef(env, obj_cls);
|
||||
}
|
||||
|
||||
android_cm_active_net_mid = NULL;
|
||||
android_cm_link_props_mid = NULL;
|
||||
android_cm_active_net_mid = NULL;
|
||||
android_cm_link_props_mid = NULL;
|
||||
android_lp_dns_servers_mid = NULL;
|
||||
android_lp_domains_mid = NULL;
|
||||
android_list_size_mid = NULL;
|
||||
android_list_get_mid = NULL;
|
||||
android_ia_host_addr_mid = NULL;
|
||||
android_lp_domains_mid = NULL;
|
||||
android_list_size_mid = NULL;
|
||||
android_list_get_mid = NULL;
|
||||
android_ia_host_addr_mid = NULL;
|
||||
|
||||
done:
|
||||
if (need_detatch)
|
||||
if (need_detatch) {
|
||||
(*android_jvm)->DetachCurrentThread(android_jvm);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ares_library_android_initialized(void)
|
||||
{
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL)
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL) {
|
||||
return ARES_ENOTINITIALIZED;
|
||||
}
|
||||
return ARES_SUCCESS;
|
||||
}
|
||||
|
||||
void ares_library_cleanup_android(void)
|
||||
{
|
||||
JNIEnv *env = NULL;
|
||||
int need_detatch = 0;
|
||||
int res;
|
||||
JNIEnv *env = NULL;
|
||||
int need_detatch = 0;
|
||||
int res;
|
||||
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL)
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
res = (*android_jvm)->GetEnv(android_jvm, (void **)&env, JNI_VERSION_1_6);
|
||||
if (res == JNI_EDETACHED)
|
||||
{
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
if (res == JNI_EDETACHED) {
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
need_detatch = 1;
|
||||
}
|
||||
if (res != JNI_OK || env == NULL)
|
||||
if (res != JNI_OK || env == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
android_cm_active_net_mid = NULL;
|
||||
android_cm_link_props_mid = NULL;
|
||||
android_cm_active_net_mid = NULL;
|
||||
android_cm_link_props_mid = NULL;
|
||||
android_lp_dns_servers_mid = NULL;
|
||||
android_lp_domains_mid = NULL;
|
||||
android_list_size_mid = NULL;
|
||||
android_list_get_mid = NULL;
|
||||
android_ia_host_addr_mid = NULL;
|
||||
android_lp_domains_mid = NULL;
|
||||
android_list_size_mid = NULL;
|
||||
android_list_get_mid = NULL;
|
||||
android_ia_host_addr_mid = NULL;
|
||||
|
||||
(*env)->DeleteGlobalRef(env, android_connectivity_manager);
|
||||
android_connectivity_manager = NULL;
|
||||
|
||||
if (need_detatch)
|
||||
if (need_detatch) {
|
||||
(*android_jvm)->DetachCurrentThread(android_jvm);
|
||||
}
|
||||
}
|
||||
|
||||
char **ares_get_android_server_list(size_t max_servers,
|
||||
size_t *num_servers)
|
||||
char **ares_get_android_server_list(size_t max_servers, size_t *num_servers)
|
||||
{
|
||||
JNIEnv *env = NULL;
|
||||
jobject active_network = NULL;
|
||||
jobject link_properties = NULL;
|
||||
jobject server_list = NULL;
|
||||
jobject server = NULL;
|
||||
jstring str = NULL;
|
||||
jint nserv;
|
||||
JNIEnv *env = NULL;
|
||||
jobject active_network = NULL;
|
||||
jobject link_properties = NULL;
|
||||
jobject server_list = NULL;
|
||||
jobject server = NULL;
|
||||
jstring str = NULL;
|
||||
jint nserv;
|
||||
const char *ch_server_address;
|
||||
int res;
|
||||
size_t i;
|
||||
char **dns_list = NULL;
|
||||
int need_detatch = 0;
|
||||
int res;
|
||||
size_t i;
|
||||
char **dns_list = NULL;
|
||||
int need_detatch = 0;
|
||||
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL ||
|
||||
max_servers == 0 || num_servers == NULL)
|
||||
{
|
||||
max_servers == 0 || num_servers == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (android_cm_active_net_mid == NULL || android_cm_link_props_mid == NULL ||
|
||||
android_lp_dns_servers_mid == NULL || android_list_size_mid == NULL ||
|
||||
android_list_get_mid == NULL || android_ia_host_addr_mid == NULL)
|
||||
{
|
||||
android_list_get_mid == NULL || android_ia_host_addr_mid == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = (*android_jvm)->GetEnv(android_jvm, (void **)&env, JNI_VERSION_1_6);
|
||||
if (res == JNI_EDETACHED)
|
||||
{
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
if (res == JNI_EDETACHED) {
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
need_detatch = 1;
|
||||
}
|
||||
if (res != JNI_OK || env == NULL)
|
||||
if (res != JNI_OK || env == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* JNI below is equivalent to this Java code.
|
||||
import android.content.Context;
|
||||
@ -296,93 +320,100 @@ char **ares_get_android_server_list(size_t max_servers,
|
||||
|
||||
active_network = (*env)->CallObjectMethod(env, android_connectivity_manager,
|
||||
android_cm_active_net_mid);
|
||||
if (active_network == NULL)
|
||||
if (active_network == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
link_properties =
|
||||
(*env)->CallObjectMethod(env, android_connectivity_manager,
|
||||
android_cm_link_props_mid, active_network);
|
||||
if (link_properties == NULL)
|
||||
(*env)->CallObjectMethod(env, android_connectivity_manager,
|
||||
android_cm_link_props_mid, active_network);
|
||||
if (link_properties == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
server_list = (*env)->CallObjectMethod(env, link_properties,
|
||||
android_lp_dns_servers_mid);
|
||||
if (server_list == NULL)
|
||||
server_list =
|
||||
(*env)->CallObjectMethod(env, link_properties, android_lp_dns_servers_mid);
|
||||
if (server_list == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
nserv = (*env)->CallIntMethod(env, server_list, android_list_size_mid);
|
||||
if (nserv > (jint)max_servers)
|
||||
if (nserv > (jint)max_servers) {
|
||||
nserv = (jint)max_servers;
|
||||
if (nserv <= 0)
|
||||
}
|
||||
if (nserv <= 0) {
|
||||
goto done;
|
||||
}
|
||||
*num_servers = (size_t)nserv;
|
||||
|
||||
dns_list = ares_malloc(sizeof(*dns_list)*(*num_servers));
|
||||
for (i=0; i<*num_servers; i++)
|
||||
{
|
||||
server = (*env)->CallObjectMethod(env, server_list, android_list_get_mid,
|
||||
(jint)i);
|
||||
dns_list[i] = ares_malloc(64);
|
||||
dns_list = ares_malloc(sizeof(*dns_list) * (*num_servers));
|
||||
for (i = 0; i < *num_servers; i++) {
|
||||
size_t len = 64;
|
||||
server =
|
||||
(*env)->CallObjectMethod(env, server_list, android_list_get_mid, (jint)i);
|
||||
dns_list[i] = ares_malloc(len);
|
||||
dns_list[i][0] = 0;
|
||||
if (server == NULL)
|
||||
{
|
||||
if (server == NULL) {
|
||||
continue;
|
||||
}
|
||||
str = (*env)->CallObjectMethod(env, server, android_ia_host_addr_mid);
|
||||
ch_server_address = (*env)->GetStringUTFChars(env, str, 0);
|
||||
strncpy(dns_list[i], ch_server_address, 64);
|
||||
ares_strcpy(dns_list[i], ch_server_address, len);
|
||||
(*env)->ReleaseStringUTFChars(env, str, ch_server_address);
|
||||
(*env)->DeleteLocalRef(env, str);
|
||||
(*env)->DeleteLocalRef(env, server);
|
||||
}
|
||||
|
||||
done:
|
||||
if ((*env)->ExceptionOccurred(env))
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
if (server_list != NULL)
|
||||
if (server_list != NULL) {
|
||||
(*env)->DeleteLocalRef(env, server_list);
|
||||
if (link_properties != NULL)
|
||||
}
|
||||
if (link_properties != NULL) {
|
||||
(*env)->DeleteLocalRef(env, link_properties);
|
||||
if (active_network != NULL)
|
||||
}
|
||||
if (active_network != NULL) {
|
||||
(*env)->DeleteLocalRef(env, active_network);
|
||||
}
|
||||
|
||||
if (need_detatch)
|
||||
if (need_detatch) {
|
||||
(*android_jvm)->DetachCurrentThread(android_jvm);
|
||||
}
|
||||
return dns_list;
|
||||
}
|
||||
|
||||
char *ares_get_android_search_domains_list(void)
|
||||
{
|
||||
JNIEnv *env = NULL;
|
||||
jobject active_network = NULL;
|
||||
jobject link_properties = NULL;
|
||||
jstring domains = NULL;
|
||||
JNIEnv *env = NULL;
|
||||
jobject active_network = NULL;
|
||||
jobject link_properties = NULL;
|
||||
jstring domains = NULL;
|
||||
const char *domain;
|
||||
int res;
|
||||
char *domain_list = NULL;
|
||||
int need_detatch = 0;
|
||||
int res;
|
||||
char *domain_list = NULL;
|
||||
int need_detatch = 0;
|
||||
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL)
|
||||
{
|
||||
if (android_jvm == NULL || android_connectivity_manager == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (android_cm_active_net_mid == NULL || android_cm_link_props_mid == NULL ||
|
||||
android_lp_domains_mid == NULL)
|
||||
{
|
||||
android_lp_domains_mid == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = (*android_jvm)->GetEnv(android_jvm, (void **)&env, JNI_VERSION_1_6);
|
||||
if (res == JNI_EDETACHED)
|
||||
{
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
if (res == JNI_EDETACHED) {
|
||||
env = NULL;
|
||||
res = (*android_jvm)->AttachCurrentThread(android_jvm, &env, NULL);
|
||||
need_detatch = 1;
|
||||
}
|
||||
if (res != JNI_OK || env == NULL)
|
||||
if (res != JNI_OK || env == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* JNI below is equivalent to this Java code.
|
||||
import android.content.Context;
|
||||
@ -393,7 +424,7 @@ char *ares_get_android_search_domains_list(void)
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
Network an = cm.getActiveNetwork();
|
||||
LinkProperties lp = cm.getLinkProperties(an);
|
||||
String domains = lp.getDomains();
|
||||
String domains = lp.getDomains();
|
||||
for (String domain: domains.split(",")) {
|
||||
String d = domain;
|
||||
}
|
||||
@ -404,38 +435,45 @@ char *ares_get_android_search_domains_list(void)
|
||||
|
||||
active_network = (*env)->CallObjectMethod(env, android_connectivity_manager,
|
||||
android_cm_active_net_mid);
|
||||
if (active_network == NULL)
|
||||
if (active_network == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
link_properties =
|
||||
(*env)->CallObjectMethod(env, android_connectivity_manager,
|
||||
android_cm_link_props_mid, active_network);
|
||||
if (link_properties == NULL)
|
||||
(*env)->CallObjectMethod(env, android_connectivity_manager,
|
||||
android_cm_link_props_mid, active_network);
|
||||
if (link_properties == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Get the domains. It is a common separated list of domains to search. */
|
||||
domains = (*env)->CallObjectMethod(env, link_properties,
|
||||
android_lp_domains_mid);
|
||||
if (domains == NULL)
|
||||
domains =
|
||||
(*env)->CallObjectMethod(env, link_properties, android_lp_domains_mid);
|
||||
if (domains == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Split on , */
|
||||
domain = (*env)->GetStringUTFChars(env, domains, 0);
|
||||
domain = (*env)->GetStringUTFChars(env, domains, 0);
|
||||
domain_list = ares_strdup(domain);
|
||||
(*env)->ReleaseStringUTFChars(env, domains, domain);
|
||||
(*env)->DeleteLocalRef(env, domains);
|
||||
|
||||
done:
|
||||
if ((*env)->ExceptionOccurred(env))
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
|
||||
if (link_properties != NULL)
|
||||
if (link_properties != NULL) {
|
||||
(*env)->DeleteLocalRef(env, link_properties);
|
||||
if (active_network != NULL)
|
||||
}
|
||||
if (active_network != NULL) {
|
||||
(*env)->DeleteLocalRef(env, active_network);
|
||||
}
|
||||
|
||||
if (need_detatch)
|
||||
if (need_detatch) {
|
||||
(*android_jvm)->DetachCurrentThread(android_jvm);
|
||||
}
|
||||
return domain_list;
|
||||
}
|
||||
#else
|
||||
|
||||
@ -1,16 +1,27 @@
|
||||
/* Copyright (C) 2017 by John Schember <john@nachtimwald.com>
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) John Schember
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __ARES_ANDROID_H__
|
||||
@ -19,8 +30,8 @@
|
||||
#if defined(ANDROID) || defined(__ANDROID__)
|
||||
|
||||
char **ares_get_android_server_list(size_t max_servers, size_t *num_servers);
|
||||
char *ares_get_android_search_domains_list(void);
|
||||
void ares_library_cleanup_android(void);
|
||||
char *ares_get_android_search_domains_list(void);
|
||||
void ares_library_cleanup_android(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
106
src/third_party/cares/dist/src/lib/ares_cancel.c
vendored
106
src/third_party/cares/dist/src/lib/ares_cancel.c
vendored
@ -1,15 +1,27 @@
|
||||
|
||||
/* Copyright (C) 2004 by Daniel Stenberg et al
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
* documentation for any purpose and without fee is hereby granted, provided
|
||||
* that the above copyright notice appear in all copies and that both that
|
||||
* copyright notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. M.I.T. makes no representations about the
|
||||
* suitability of this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 2004 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
@ -23,41 +35,59 @@
|
||||
* on the given channel. It does NOT kill the channel, use ares_destroy() for
|
||||
* that.
|
||||
*/
|
||||
void ares_cancel(ares_channel channel)
|
||||
void ares_cancel(ares_channel_t *channel)
|
||||
{
|
||||
struct query *query;
|
||||
struct list_node list_head_copy;
|
||||
struct list_node* list_head;
|
||||
struct list_node* list_node;
|
||||
int i;
|
||||
if (channel == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__channel_lock(channel);
|
||||
|
||||
if (ares__llist_len(channel->all_queries) > 0) {
|
||||
ares__llist_node_t *node = NULL;
|
||||
ares__llist_node_t *next = NULL;
|
||||
|
||||
if (!ares__is_list_empty(&(channel->all_queries)))
|
||||
{
|
||||
/* Swap list heads, so that only those queries which were present on entry
|
||||
* into this function are cancelled. New queries added by callbacks of
|
||||
* queries being cancelled will not be cancelled themselves.
|
||||
*/
|
||||
list_head = &(channel->all_queries);
|
||||
list_head_copy.prev = list_head->prev;
|
||||
list_head_copy.next = list_head->next;
|
||||
list_head_copy.prev->next = &list_head_copy;
|
||||
list_head_copy.next->prev = &list_head_copy;
|
||||
list_head->prev = list_head;
|
||||
list_head->next = list_head;
|
||||
for (list_node = list_head_copy.next; list_node != &list_head_copy; )
|
||||
{
|
||||
query = list_node->data;
|
||||
list_node = list_node->next; /* since we're deleting the query */
|
||||
ares__llist_t *list_copy = channel->all_queries;
|
||||
channel->all_queries = ares__llist_create(NULL);
|
||||
|
||||
/* Out of memory, this function doesn't return a result code though so we
|
||||
* can't report to caller */
|
||||
if (channel->all_queries == NULL) {
|
||||
channel->all_queries = list_copy;
|
||||
goto done;
|
||||
}
|
||||
|
||||
node = ares__llist_node_first(list_copy);
|
||||
while (node != NULL) {
|
||||
struct query *query;
|
||||
struct server_connection *conn;
|
||||
|
||||
/* Cache next since this node is being deleted */
|
||||
next = ares__llist_node_next(node);
|
||||
|
||||
query = ares__llist_node_claim(node);
|
||||
conn = query->conn;
|
||||
query->node_all_queries = NULL;
|
||||
|
||||
/* NOTE: its possible this may enqueue new queries */
|
||||
query->callback(query->arg, ARES_ECANCELLED, 0, NULL, 0);
|
||||
ares__free_query(query);
|
||||
|
||||
/* See if the connection should be cleaned up */
|
||||
ares__check_cleanup_conn(channel, conn);
|
||||
|
||||
node = next;
|
||||
}
|
||||
|
||||
ares__llist_destroy(list_copy);
|
||||
}
|
||||
if (!(channel->flags & ARES_FLAG_STAYOPEN) && ares__is_list_empty(&(channel->all_queries)))
|
||||
{
|
||||
if (channel->servers)
|
||||
{
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
ares__close_sockets(channel, &channel->servers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ares_queue_notify_empty(channel);
|
||||
|
||||
done:
|
||||
ares__channel_unlock(channel);
|
||||
}
|
||||
|
||||
@ -1,22 +1,14 @@
|
||||
/* Copyright (C) The c-ares project and its contributors
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
/* Generated from ares_config.h.cmake */
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
#undef AC_APPLE_UNIVERSAL_BUILD
|
||||
|
||||
/* define this if ares is built for a big endian system */
|
||||
#undef ARES_BIG_ENDIAN
|
||||
|
||||
/* when building as static part of libcurl */
|
||||
#undef BUILDING_LIBCURL
|
||||
|
||||
/* Defined for build that exposes internal static functions for testing. */
|
||||
#undef CARES_EXPOSE_STATICS
|
||||
|
||||
/* Defined for build with symbol hiding. */
|
||||
#undef CARES_SYMBOL_HIDING
|
||||
|
||||
/* Definition to make a library symbol externally visible. */
|
||||
#undef CARES_SYMBOL_SCOPE_EXTERN
|
||||
#cmakedefine CARES_SYMBOL_HIDING
|
||||
|
||||
/* Use resolver library to configure cares */
|
||||
#cmakedefine CARES_USE_LIBRESOLV
|
||||
@ -63,12 +55,6 @@
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#cmakedefine HAVE_ASSERT_H
|
||||
|
||||
/* Define to 1 if you have the `bitncmp' function. */
|
||||
#cmakedefine HAVE_BITNCMP
|
||||
|
||||
/* Define to 1 if bool is an available type. */
|
||||
#cmakedefine HAVE_BOOL_T
|
||||
|
||||
/* Define to 1 if you have the clock_gettime function and monotonic timer. */
|
||||
#cmakedefine HAVE_CLOCK_GETTIME_MONOTONIC
|
||||
|
||||
@ -90,6 +76,24 @@
|
||||
/* Define to 1 if you have the <errno.h> header file. */
|
||||
#cmakedefine HAVE_ERRNO_H
|
||||
|
||||
/* Define to 1 if you have the <poll.h> header file. */
|
||||
#cmakedefine HAVE_POLL_H
|
||||
|
||||
/* Define to 1 if you have the poll function. */
|
||||
#cmakedefine HAVE_POLL
|
||||
|
||||
/* Define to 1 if you have the pipe function. */
|
||||
#cmakedefine HAVE_PIPE
|
||||
|
||||
/* Define to 1 if you have the pipe2 function. */
|
||||
#cmakedefine HAVE_PIPE2
|
||||
|
||||
/* Define to 1 if you have the kqueue function. */
|
||||
#cmakedefine HAVE_KQUEUE
|
||||
|
||||
/* Define to 1 if you have the epoll{_create,ctl,wait} functions. */
|
||||
#cmakedefine HAVE_EPOLL
|
||||
|
||||
/* Define to 1 if you have the fcntl function. */
|
||||
#cmakedefine HAVE_FCNTL
|
||||
|
||||
@ -111,18 +115,15 @@
|
||||
/* Define to 1 if you have the getenv function. */
|
||||
#cmakedefine HAVE_GETENV
|
||||
|
||||
/* Define to 1 if you have the gethostbyaddr function. */
|
||||
#cmakedefine HAVE_GETHOSTBYADDR
|
||||
|
||||
/* Define to 1 if you have the gethostbyname function. */
|
||||
#cmakedefine HAVE_GETHOSTBYNAME
|
||||
|
||||
/* Define to 1 if you have the gethostname function. */
|
||||
#cmakedefine HAVE_GETHOSTNAME
|
||||
|
||||
/* Define to 1 if you have the getnameinfo function. */
|
||||
#cmakedefine HAVE_GETNAMEINFO
|
||||
|
||||
/* Define to 1 if you have the getrandom function. */
|
||||
#cmakedefine HAVE_GETRANDOM
|
||||
|
||||
/* Define to 1 if you have the getservbyport_r function. */
|
||||
#cmakedefine HAVE_GETSERVBYPORT_R
|
||||
|
||||
@ -135,6 +136,15 @@
|
||||
/* Define to 1 if you have the `if_indextoname' function. */
|
||||
#cmakedefine HAVE_IF_INDEXTONAME
|
||||
|
||||
/* Define to 1 if you have the `if_nametoindex' function. */
|
||||
#cmakedefine HAVE_IF_NAMETOINDEX
|
||||
|
||||
/* Define to 1 if you have the `ConvertInterfaceIndexToLuid' function. */
|
||||
#cmakedefine HAVE_CONVERTINTERFACEINDEXTOLUID
|
||||
|
||||
/* Define to 1 if you have the `ConvertInterfaceLuidToNameA' function. */
|
||||
#cmakedefine HAVE_CONVERTINTERFACELUIDTONAMEA
|
||||
|
||||
/* Define to 1 if you have a IPv6 capable working inet_net_pton function. */
|
||||
#cmakedefine HAVE_INET_NET_PTON
|
||||
|
||||
@ -172,12 +182,15 @@
|
||||
/* Define to 1 if you have the `resolve' library (-lresolve). */
|
||||
#cmakedefine HAVE_LIBRESOLV
|
||||
|
||||
/* Define to 1 if you have iphlpapi.h */
|
||||
#cmakedefine HAVE_IPHLPAPI_H
|
||||
|
||||
/* Define to 1 if you have netioapi.h */
|
||||
#cmakedefine HAVE_NETIOAPI_H
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#cmakedefine HAVE_LIMITS_H
|
||||
|
||||
/* if your compiler supports LL */
|
||||
#cmakedefine HAVE_LL
|
||||
|
||||
/* Define to 1 if the compiler supports the 'long long' data type. */
|
||||
#cmakedefine HAVE_LONGLONG
|
||||
|
||||
@ -187,6 +200,9 @@
|
||||
/* Define to 1 if you have the memory.h header file. */
|
||||
#cmakedefine HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the AvailabilityMacros.h header file. */
|
||||
#cmakedefine HAVE_AVAILABILITYMACROS_H
|
||||
|
||||
/* Define to 1 if you have the MSG_NOSIGNAL flag. */
|
||||
#cmakedefine HAVE_MSG_NOSIGNAL
|
||||
|
||||
@ -223,14 +239,8 @@
|
||||
/* Define to 1 if you have the <signal.h> header file. */
|
||||
#cmakedefine HAVE_SIGNAL_H
|
||||
|
||||
/* Define to 1 if sig_atomic_t is an available typedef. */
|
||||
#cmakedefine HAVE_SIG_ATOMIC_T
|
||||
|
||||
/* Define to 1 if sig_atomic_t is already defined as volatile. */
|
||||
#cmakedefine HAVE_SIG_ATOMIC_T_VOLATILE
|
||||
|
||||
/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */
|
||||
#cmakedefine HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
#cmakedefine HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
|
||||
/* Define to 1 if you have the socket function. */
|
||||
#cmakedefine HAVE_SOCKET
|
||||
@ -298,6 +308,15 @@
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#cmakedefine HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/random.h> header file. */
|
||||
#cmakedefine HAVE_SYS_RANDOM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/event.h> header file. */
|
||||
#cmakedefine HAVE_SYS_EVENT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/epoll.h> header file. */
|
||||
#cmakedefine HAVE_SYS_EPOLL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SELECT_H
|
||||
|
||||
@ -319,6 +338,9 @@
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#cmakedefine HAVE_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <ifaddrs.h> header file. */
|
||||
#cmakedefine HAVE_IFADDRS_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H
|
||||
|
||||
@ -331,6 +353,18 @@
|
||||
/* Define to 1 if you have the winsock.h header file. */
|
||||
#cmakedefine HAVE_WINSOCK_H
|
||||
|
||||
/* Define to 1 if you have the mswsock.h header file. */
|
||||
#cmakedefine HAVE_MSWSOCK_H
|
||||
|
||||
/* Define to 1 if you have the winternl.h header file. */
|
||||
#cmakedefine HAVE_WINTERNL_H
|
||||
|
||||
/* Define to 1 if you have the ntstatus.h header file. */
|
||||
#cmakedefine HAVE_NTSTATUS_H
|
||||
|
||||
/* Define to 1 if you have the ntdef.h header file. */
|
||||
#cmakedefine HAVE_NTDEF_H
|
||||
|
||||
/* Define to 1 if you have the writev function. */
|
||||
#cmakedefine HAVE_WRITEV
|
||||
|
||||
@ -349,6 +383,12 @@
|
||||
/* Define if have arc4random_buf() */
|
||||
#cmakedefine HAVE_ARC4RANDOM_BUF
|
||||
|
||||
/* Define if have getifaddrs() */
|
||||
#cmakedefine HAVE_GETIFADDRS
|
||||
|
||||
/* Define if have stat() */
|
||||
#cmakedefine HAVE_STAT
|
||||
|
||||
/* a suitable file/device to read random data from */
|
||||
#cmakedefine CARES_RANDOM_FILE "@CARES_RANDOM_FILE@"
|
||||
|
||||
@ -400,9 +440,6 @@
|
||||
/* Define to the function return type for recv. */
|
||||
#define RECV_TYPE_RETV @RECV_TYPE_RETV@
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#define RETSIGTYPE @RETSIGTYPE@
|
||||
|
||||
/* Define to the type qualifier of arg 2 for send. */
|
||||
#define SEND_QUAL_ARG2 @SEND_QUAL_ARG2@
|
||||
|
||||
@ -421,15 +458,21 @@
|
||||
/* Define to the function return type for send. */
|
||||
#define SEND_TYPE_RETV @SEND_TYPE_RETV@
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#cmakedefine TIME_WITH_SYS_TIME
|
||||
|
||||
/* Define to disable non-blocking sockets. */
|
||||
#undef USE_BLOCKING_SOCKETS
|
||||
|
||||
/* Define to avoid automatic inclusion of winsock.h */
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
/* Type to use in place of in_addr_t when system does not provide it. */
|
||||
#undef in_addr_t
|
||||
/* Define to 1 if you have the pthread.h header file. */
|
||||
#cmakedefine HAVE_PTHREAD_H
|
||||
|
||||
/* Define to 1 if you have the pthread_np.h header file. */
|
||||
#cmakedefine HAVE_PTHREAD_NP_H
|
||||
|
||||
/* Define to 1 if threads are enabled */
|
||||
#cmakedefine CARES_THREADS
|
||||
|
||||
/* Define to 1 if pthread_init() exists */
|
||||
#cmakedefine HAVE_PTHREAD_INIT
|
||||
|
||||
|
||||
487
src/third_party/cares/dist/src/lib/ares_config.h.in
vendored
487
src/third_party/cares/dist/src/lib/ares_config.h.in
vendored
@ -1,22 +1,13 @@
|
||||
/* src/lib/ares_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define if building universal (internal helper macro) */
|
||||
#undef AC_APPLE_UNIVERSAL_BUILD
|
||||
|
||||
/* define this if ares is built for a big endian system */
|
||||
#undef ARES_BIG_ENDIAN
|
||||
|
||||
/* Defined for build that exposes internal static functions for testing. */
|
||||
#undef CARES_EXPOSE_STATICS
|
||||
|
||||
/* a suitable file/device to read random data from */
|
||||
#undef CARES_RANDOM_FILE
|
||||
|
||||
/* Defined for build with symbol hiding. */
|
||||
/* Set to 1 if non-pubilc shared library symbols are hidden */
|
||||
#undef CARES_SYMBOL_HIDING
|
||||
|
||||
/* Definition to make a library symbol externally visible. */
|
||||
#undef CARES_SYMBOL_SCOPE_EXTERN
|
||||
/* Threading enabled */
|
||||
#undef CARES_THREADS
|
||||
|
||||
/* the signed version of size_t */
|
||||
#undef CARES_TYPEOF_ARES_SSIZE_T
|
||||
@ -27,34 +18,31 @@
|
||||
/* if a /etc/inet dir is being used */
|
||||
#undef ETC_INET
|
||||
|
||||
/* Define to the type of arg 2 for gethostname. */
|
||||
/* gethostname() arg2 type */
|
||||
#undef GETHOSTNAME_TYPE_ARG2
|
||||
|
||||
/* Define to the type qualifier of arg 1 for getnameinfo. */
|
||||
#undef GETNAMEINFO_QUAL_ARG1
|
||||
|
||||
/* Define to the type of arg 1 for getnameinfo. */
|
||||
/* getnameinfo() arg1 type */
|
||||
#undef GETNAMEINFO_TYPE_ARG1
|
||||
|
||||
/* Define to the type of arg 2 for getnameinfo. */
|
||||
/* getnameinfo() arg2 type */
|
||||
#undef GETNAMEINFO_TYPE_ARG2
|
||||
|
||||
/* Define to the type of args 4 and 6 for getnameinfo. */
|
||||
/* getnameinfo() arg4 and 6 type */
|
||||
#undef GETNAMEINFO_TYPE_ARG46
|
||||
|
||||
/* Define to the type of arg 7 for getnameinfo. */
|
||||
/* getnameinfo() arg7 type */
|
||||
#undef GETNAMEINFO_TYPE_ARG7
|
||||
|
||||
/* Specifies the number of arguments to getservbyport_r */
|
||||
/* number of arguments for getservbyname_r() */
|
||||
#undef GETSERVBYNAME_R_ARGS
|
||||
|
||||
/* number of arguments for getservbyport_r() */
|
||||
#undef GETSERVBYPORT_R_ARGS
|
||||
|
||||
/* Specifies the size of the buffer to pass to getservbyport_r */
|
||||
#undef GETSERVBYPORT_R_BUFSIZE
|
||||
|
||||
/* Define to 1 if you have AF_INET6. */
|
||||
/* Define to 1 if you have AF_INET6 */
|
||||
#undef HAVE_AF_INET6
|
||||
|
||||
/* Define to 1 if you have the arc4random_buf function. */
|
||||
/* Define to 1 if you have `arc4random_buf` */
|
||||
#undef HAVE_ARC4RANDOM_BUF
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
@ -69,129 +57,131 @@
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#undef HAVE_ASSERT_H
|
||||
|
||||
/* Define to 1 if you have the `bitncmp' function. */
|
||||
#undef HAVE_BITNCMP
|
||||
/* Define to 1 if you have the <AvailabilityMacros.h> header file. */
|
||||
#undef HAVE_AVAILABILITYMACROS_H
|
||||
|
||||
/* Define to 1 if bool is an available type. */
|
||||
#undef HAVE_BOOL_T
|
||||
/* Define to 1 if you have `clock_gettime` */
|
||||
#undef HAVE_CLOCK_GETTIME
|
||||
|
||||
/* Define to 1 if you have the clock_gettime function and monotonic timer. */
|
||||
/* clock_gettime() with CLOCK_MONOTONIC support */
|
||||
#undef HAVE_CLOCK_GETTIME_MONOTONIC
|
||||
|
||||
/* Define to 1 if you have the closesocket function. */
|
||||
/* Define to 1 if you have `closesocket` */
|
||||
#undef HAVE_CLOSESOCKET
|
||||
|
||||
/* Define to 1 if you have the CloseSocket camel case function. */
|
||||
/* Define to 1 if you have `CloseSocket` */
|
||||
#undef HAVE_CLOSESOCKET_CAMEL
|
||||
|
||||
/* Define to 1 if you have the connect function. */
|
||||
/* Define to 1 if you have `connect` */
|
||||
#undef HAVE_CONNECT
|
||||
|
||||
/* define if the compiler supports basic C++11 syntax */
|
||||
#undef HAVE_CXX11
|
||||
/* Define to 1 if you have `ConvertInterfaceIndexToLuid` */
|
||||
#undef HAVE_CONVERTINTERFACEINDEXTOLUID
|
||||
|
||||
/* Define to 1 if you have `ConvertInterfaceLuidToNameA` */
|
||||
#undef HAVE_CONVERTINTERFACELUIDTONAMEA
|
||||
|
||||
/* define if the compiler supports basic C++14 syntax */
|
||||
#undef HAVE_CXX14
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you have `epoll_{create1,ctl,wait}` */
|
||||
#undef HAVE_EPOLL
|
||||
|
||||
/* Define to 1 if you have the <errno.h> header file. */
|
||||
#undef HAVE_ERRNO_H
|
||||
|
||||
/* Define to 1 if you have the fcntl function. */
|
||||
/* Define to 1 if you have `fcntl` */
|
||||
#undef HAVE_FCNTL
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have a working fcntl O_NONBLOCK function. */
|
||||
/* fcntl() with O_NONBLOCK support */
|
||||
#undef HAVE_FCNTL_O_NONBLOCK
|
||||
|
||||
/* Define to 1 if you have the freeaddrinfo function. */
|
||||
#undef HAVE_FREEADDRINFO
|
||||
|
||||
/* Define to 1 if you have a working getaddrinfo function. */
|
||||
#undef HAVE_GETADDRINFO
|
||||
|
||||
/* Define to 1 if the getaddrinfo function is threadsafe. */
|
||||
#undef HAVE_GETADDRINFO_THREADSAFE
|
||||
|
||||
/* Define to 1 if you have the getenv function. */
|
||||
/* Define to 1 if you have `getenv` */
|
||||
#undef HAVE_GETENV
|
||||
|
||||
/* Define to 1 if you have the gethostbyaddr function. */
|
||||
#undef HAVE_GETHOSTBYADDR
|
||||
|
||||
/* Define to 1 if you have the gethostbyname function. */
|
||||
#undef HAVE_GETHOSTBYNAME
|
||||
|
||||
/* Define to 1 if you have the gethostname function. */
|
||||
/* Define to 1 if you have `gethostname` */
|
||||
#undef HAVE_GETHOSTNAME
|
||||
|
||||
/* Define to 1 if you have the getnameinfo function. */
|
||||
/* Define to 1 if you have `getifaddrs` */
|
||||
#undef HAVE_GETIFADDRS
|
||||
|
||||
/* Define to 1 if you have `getnameinfo` */
|
||||
#undef HAVE_GETNAMEINFO
|
||||
|
||||
/* Define to 1 if you have the getservbyport_r function. */
|
||||
/* Define to 1 if you have `getrandom` */
|
||||
#undef HAVE_GETRANDOM
|
||||
|
||||
/* Define to 1 if you have `getservbyport_r` */
|
||||
#undef HAVE_GETSERVBYPORT_R
|
||||
|
||||
/* Define to 1 if you have the `gettimeofday' function. */
|
||||
/* Define to 1 if you have `gettimeofday` */
|
||||
#undef HAVE_GETTIMEOFDAY
|
||||
|
||||
/* Define to 1 if you have the `if_indextoname' function. */
|
||||
/* Define to 1 if you have the <ifaddrs.h> header file. */
|
||||
#undef HAVE_IFADDRS_H
|
||||
|
||||
/* Define to 1 if you have `if_indextoname` */
|
||||
#undef HAVE_IF_INDEXTONAME
|
||||
|
||||
/* Define to 1 if you have a IPv6 capable working inet_net_pton function. */
|
||||
/* Define to 1 if you have `if_nametoindex` */
|
||||
#undef HAVE_IF_NAMETOINDEX
|
||||
|
||||
/* Define to 1 if you have `inet_net_pton` */
|
||||
#undef HAVE_INET_NET_PTON
|
||||
|
||||
/* Define to 1 if you have a IPv6 capable working inet_ntop function. */
|
||||
/* Define to 1 if you have `inet_ntop` */
|
||||
#undef HAVE_INET_NTOP
|
||||
|
||||
/* Define to 1 if you have a IPv6 capable working inet_pton function. */
|
||||
/* Define to 1 if you have `inet_pton` */
|
||||
#undef HAVE_INET_PTON
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the ioctl function. */
|
||||
/* Define to 1 if you have `ioctl` */
|
||||
#undef HAVE_IOCTL
|
||||
|
||||
/* Define to 1 if you have the ioctlsocket function. */
|
||||
/* Define to 1 if you have `ioctlsocket` */
|
||||
#undef HAVE_IOCTLSOCKET
|
||||
|
||||
/* Define to 1 if you have the IoctlSocket camel case function. */
|
||||
/* Define to 1 if you have `IoctlSocket` */
|
||||
#undef HAVE_IOCTLSOCKET_CAMEL
|
||||
|
||||
/* Define to 1 if you have a working IoctlSocket camel case FIONBIO function.
|
||||
*/
|
||||
#undef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
|
||||
|
||||
/* Define to 1 if you have a working ioctlsocket FIONBIO function. */
|
||||
/* ioctlsocket() with FIONBIO support */
|
||||
#undef HAVE_IOCTLSOCKET_FIONBIO
|
||||
|
||||
/* Define to 1 if you have a working ioctl FIONBIO function. */
|
||||
/* ioctl() with FIONBIO support */
|
||||
#undef HAVE_IOCTL_FIONBIO
|
||||
|
||||
/* Define to 1 if you have a working ioctl SIOCGIFADDR function. */
|
||||
#undef HAVE_IOCTL_SIOCGIFADDR
|
||||
/* Define to 1 if you have the <iphlpapi.h> header file. */
|
||||
#undef HAVE_IPHLPAPI_H
|
||||
|
||||
/* Define to 1 if you have the `resolve' library (-lresolve). */
|
||||
#undef HAVE_LIBRESOLVE
|
||||
/* Define to 1 if you have `kqueue` */
|
||||
#undef HAVE_KQUEUE
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* if your compiler supports LL */
|
||||
#undef HAVE_LL
|
||||
|
||||
/* Define to 1 if the compiler supports the 'long long' data type. */
|
||||
#undef HAVE_LONGLONG
|
||||
|
||||
/* Define to 1 if you have the malloc.h header file. */
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
#undef HAVE_MALLOC_H
|
||||
|
||||
/* Define to 1 if you have the memory.h header file. */
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the MSG_NOSIGNAL flag. */
|
||||
#undef HAVE_MSG_NOSIGNAL
|
||||
/* Define to 1 if you have the <minix/config.h> header file. */
|
||||
#undef HAVE_MINIX_CONFIG_H
|
||||
|
||||
/* Define to 1 if you have the <mswsock.h> header file. */
|
||||
#undef HAVE_MSWSOCK_H
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#undef HAVE_NETDB_H
|
||||
@ -202,64 +192,88 @@
|
||||
/* Define to 1 if you have the <netinet/tcp.h> header file. */
|
||||
#undef HAVE_NETINET_TCP_H
|
||||
|
||||
/* Define to 1 if you have the <netioapi.h> header file. */
|
||||
#undef HAVE_NETIOAPI_H
|
||||
|
||||
/* Define to 1 if you have the <net/if.h> header file. */
|
||||
#undef HAVE_NET_IF_H
|
||||
|
||||
/* Define to 1 if you have PF_INET6. */
|
||||
/* Define to 1 if you have the <ntdef.h> header file. */
|
||||
#undef HAVE_NTDEF_H
|
||||
|
||||
/* Define to 1 if you have the <ntstatus.h> header file. */
|
||||
#undef HAVE_NTSTATUS_H
|
||||
|
||||
/* Define to 1 if you have PF_INET6 */
|
||||
#undef HAVE_PF_INET6
|
||||
|
||||
/* Define to 1 if you have the recv function. */
|
||||
/* Define to 1 if you have `pipe` */
|
||||
#undef HAVE_PIPE
|
||||
|
||||
/* Define to 1 if you have `pipe2` */
|
||||
#undef HAVE_PIPE2
|
||||
|
||||
/* Define to 1 if you have `poll` */
|
||||
#undef HAVE_POLL
|
||||
|
||||
/* Define to 1 if you have the <poll.h> header file. */
|
||||
#undef HAVE_POLL_H
|
||||
|
||||
/* Define to 1 if you have the <pthread.h> header file. */
|
||||
#undef HAVE_PTHREAD_H
|
||||
|
||||
/* Define to 1 if you have the <pthread_np.h> header file. */
|
||||
#undef HAVE_PTHREAD_NP_H
|
||||
|
||||
/* Have PTHREAD_PRIO_INHERIT. */
|
||||
#undef HAVE_PTHREAD_PRIO_INHERIT
|
||||
|
||||
/* Define to 1 if you have `recv` */
|
||||
#undef HAVE_RECV
|
||||
|
||||
/* Define to 1 if you have the recvfrom function. */
|
||||
/* Define to 1 if you have `recvfrom` */
|
||||
#undef HAVE_RECVFROM
|
||||
|
||||
/* Define to 1 if you have the send function. */
|
||||
/* Define to 1 if you have `send` */
|
||||
#undef HAVE_SEND
|
||||
|
||||
/* Define to 1 if you have the setsockopt function. */
|
||||
/* Define to 1 if you have `setsockopt` */
|
||||
#undef HAVE_SETSOCKOPT
|
||||
|
||||
/* Define to 1 if you have a working setsockopt SO_NONBLOCK function. */
|
||||
/* setsockopt() with SO_NONBLOCK support */
|
||||
#undef HAVE_SETSOCKOPT_SO_NONBLOCK
|
||||
|
||||
/* Define to 1 if you have the <signal.h> header file. */
|
||||
#undef HAVE_SIGNAL_H
|
||||
|
||||
/* Define to 1 if sig_atomic_t is an available typedef. */
|
||||
#undef HAVE_SIG_ATOMIC_T
|
||||
|
||||
/* Define to 1 if sig_atomic_t is already defined as volatile. */
|
||||
#undef HAVE_SIG_ATOMIC_T_VOLATILE
|
||||
|
||||
/* Define to 1 if your struct sockaddr_in6 has sin6_scope_id. */
|
||||
#undef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
|
||||
/* Define to 1 if you have the socket function. */
|
||||
/* Define to 1 if you have `socket` */
|
||||
#undef HAVE_SOCKET
|
||||
|
||||
/* Define to 1 if you have the <socket.h> header file. */
|
||||
#undef HAVE_SOCKET_H
|
||||
|
||||
/* socklen_t */
|
||||
#undef HAVE_SOCKLEN_T
|
||||
|
||||
/* Define to 1 if you have `stat` */
|
||||
#undef HAVE_STAT
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#undef HAVE_STDBOOL_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#undef HAVE_STDIO_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the strcasecmp function. */
|
||||
/* Define to 1 if you have `strcasecmp` */
|
||||
#undef HAVE_STRCASECMP
|
||||
|
||||
/* Define to 1 if you have the strcmpi function. */
|
||||
#undef HAVE_STRCMPI
|
||||
|
||||
/* Define to 1 if you have the strdup function. */
|
||||
/* Define to 1 if you have `strdup` */
|
||||
#undef HAVE_STRDUP
|
||||
|
||||
/* Define to 1 if you have the stricmp function. */
|
||||
/* Define to 1 if you have `stricmp` */
|
||||
#undef HAVE_STRICMP
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
@ -268,39 +282,54 @@
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the strncasecmp function. */
|
||||
/* Define to 1 if you have `strncasecmp` */
|
||||
#undef HAVE_STRNCASECMP
|
||||
|
||||
/* Define to 1 if you have the strncmpi function. */
|
||||
/* Define to 1 if you have `strncmpi` */
|
||||
#undef HAVE_STRNCMPI
|
||||
|
||||
/* Define to 1 if you have the strnicmp function. */
|
||||
/* Define to 1 if you have `strnicmp` */
|
||||
#undef HAVE_STRNICMP
|
||||
|
||||
/* Define to 1 if you have the <stropts.h> header file. */
|
||||
#undef HAVE_STROPTS_H
|
||||
|
||||
/* Define to 1 if you have struct addrinfo. */
|
||||
/* Define to 1 if the system has the type `struct addrinfo'. */
|
||||
#undef HAVE_STRUCT_ADDRINFO
|
||||
|
||||
/* Define to 1 if you have struct in6_addr. */
|
||||
/* Define to 1 if `ai_flags' is a member of `struct addrinfo'. */
|
||||
#undef HAVE_STRUCT_ADDRINFO_AI_FLAGS
|
||||
|
||||
/* Define to 1 if the system has the type `struct in6_addr'. */
|
||||
#undef HAVE_STRUCT_IN6_ADDR
|
||||
|
||||
/* Define to 1 if you have struct sockaddr_in6. */
|
||||
/* Define to 1 if the system has the type `struct sockaddr_in6'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_IN6
|
||||
|
||||
/* if struct sockaddr_storage is defined */
|
||||
/* Define to 1 if `sin6_scope_id' is a member of `struct sockaddr_in6'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
|
||||
|
||||
/* Define to 1 if the system has the type `struct sockaddr_storage'. */
|
||||
#undef HAVE_STRUCT_SOCKADDR_STORAGE
|
||||
|
||||
/* Define to 1 if you have the timeval struct. */
|
||||
/* Define to 1 if the system has the type `struct timeval'. */
|
||||
#undef HAVE_STRUCT_TIMEVAL
|
||||
|
||||
/* Define to 1 if you have the <sys/epoll.h> header file. */
|
||||
#undef HAVE_SYS_EPOLL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/event.h> header file. */
|
||||
#undef HAVE_SYS_EVENT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/filio.h> header file. */
|
||||
#undef HAVE_SYS_FILIO_H
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#undef HAVE_SYS_IOCTL_H
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#undef HAVE_SYS_PARAM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/random.h> header file. */
|
||||
#undef HAVE_SYS_RANDOM_H
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#undef HAVE_SYS_SELECT_H
|
||||
|
||||
@ -325,42 +354,39 @@
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define to 1 if you have the windows.h header file. */
|
||||
/* Whether user namespaces are available */
|
||||
#undef HAVE_USER_NAMESPACE
|
||||
|
||||
/* Whether UTS namespaces are available */
|
||||
#undef HAVE_UTS_NAMESPACE
|
||||
|
||||
/* Define to 1 if you have the <wchar.h> header file. */
|
||||
#undef HAVE_WCHAR_H
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* Define to 1 if you have the winsock2.h header file. */
|
||||
/* Define to 1 if you have the <winsock2.h> header file. */
|
||||
#undef HAVE_WINSOCK2_H
|
||||
|
||||
/* Define to 1 if you have the winsock.h header file. */
|
||||
#undef HAVE_WINSOCK_H
|
||||
/* Define to 1 if you have the <winternl.h> header file. */
|
||||
#undef HAVE_WINTERNL_H
|
||||
|
||||
/* Define to 1 if you have the writev function. */
|
||||
/* Define to 1 if you have `writev` */
|
||||
#undef HAVE_WRITEV
|
||||
|
||||
/* Define to 1 if you have the ws2tcpip.h header file. */
|
||||
/* Define to 1 if you have the <ws2ipdef.h> header file. */
|
||||
#undef HAVE_WS2IPDEF_H
|
||||
|
||||
/* Define to 1 if you have the <ws2tcpip.h> header file. */
|
||||
#undef HAVE_WS2TCPIP_H
|
||||
|
||||
/* Define if __system_property_get exists. */
|
||||
/* Define to 1 if you have `__system_property_get` */
|
||||
#undef HAVE___SYSTEM_PROPERTY_GET
|
||||
|
||||
/* Define to the sub-directory where libtool stores uninstalled libraries. */
|
||||
#undef LT_OBJDIR
|
||||
|
||||
/* Define to 1 if you need the malloc.h header file even with stdlib.h */
|
||||
#undef NEED_MALLOC_H
|
||||
|
||||
/* Define to 1 if you need the memory.h header file even with stdlib.h */
|
||||
#undef NEED_MEMORY_H
|
||||
|
||||
/* Define to 1 if _REENTRANT preprocessor symbol must be defined. */
|
||||
#undef NEED_REENTRANT
|
||||
|
||||
/* Define to 1 if _THREAD_SAFE preprocessor symbol must be defined. */
|
||||
#undef NEED_THREAD_SAFE
|
||||
|
||||
/* cpu-machine-OS */
|
||||
#undef OS
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
@ -382,124 +408,165 @@
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to the type qualifier pointed by arg 5 for recvfrom. */
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#undef PTHREAD_CREATE_JOINABLE
|
||||
|
||||
/* recvfrom() arg5 qualifier */
|
||||
#undef RECVFROM_QUAL_ARG5
|
||||
|
||||
/* Define to the type of arg 1 for recvfrom. */
|
||||
/* recvfrom() arg1 type */
|
||||
#undef RECVFROM_TYPE_ARG1
|
||||
|
||||
/* Define to the type pointed by arg 2 for recvfrom. */
|
||||
/* recvfrom() arg2 type */
|
||||
#undef RECVFROM_TYPE_ARG2
|
||||
|
||||
/* Define to 1 if the type pointed by arg 2 for recvfrom is void. */
|
||||
#undef RECVFROM_TYPE_ARG2_IS_VOID
|
||||
|
||||
/* Define to the type of arg 3 for recvfrom. */
|
||||
/* recvfrom() arg3 type */
|
||||
#undef RECVFROM_TYPE_ARG3
|
||||
|
||||
/* Define to the type of arg 4 for recvfrom. */
|
||||
/* recvfrom() arg4 type */
|
||||
#undef RECVFROM_TYPE_ARG4
|
||||
|
||||
/* Define to the type pointed by arg 5 for recvfrom. */
|
||||
/* recvfrom() arg5 type */
|
||||
#undef RECVFROM_TYPE_ARG5
|
||||
|
||||
/* Define to 1 if the type pointed by arg 5 for recvfrom is void. */
|
||||
#undef RECVFROM_TYPE_ARG5_IS_VOID
|
||||
|
||||
/* Define to the type pointed by arg 6 for recvfrom. */
|
||||
#undef RECVFROM_TYPE_ARG6
|
||||
|
||||
/* Define to 1 if the type pointed by arg 6 for recvfrom is void. */
|
||||
#undef RECVFROM_TYPE_ARG6_IS_VOID
|
||||
|
||||
/* Define to the function return type for recvfrom. */
|
||||
/* recvfrom() return value */
|
||||
#undef RECVFROM_TYPE_RETV
|
||||
|
||||
/* Define to the type of arg 1 for recv. */
|
||||
/* recv() arg1 type */
|
||||
#undef RECV_TYPE_ARG1
|
||||
|
||||
/* Define to the type of arg 2 for recv. */
|
||||
/* recv() arg2 type */
|
||||
#undef RECV_TYPE_ARG2
|
||||
|
||||
/* Define to the type of arg 3 for recv. */
|
||||
/* recv() arg3 type */
|
||||
#undef RECV_TYPE_ARG3
|
||||
|
||||
/* Define to the type of arg 4 for recv. */
|
||||
/* recv() arg4 type */
|
||||
#undef RECV_TYPE_ARG4
|
||||
|
||||
/* Define to the function return type for recv. */
|
||||
/* recv() return value */
|
||||
#undef RECV_TYPE_RETV
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#undef RETSIGTYPE
|
||||
|
||||
/* Define to the type qualifier of arg 2 for send. */
|
||||
/* send() arg2 qualifier */
|
||||
#undef SEND_QUAL_ARG2
|
||||
|
||||
/* Define to the type of arg 1 for send. */
|
||||
/* send() arg1 type */
|
||||
#undef SEND_TYPE_ARG1
|
||||
|
||||
/* Define to the type of arg 2 for send. */
|
||||
/* send() arg2 type */
|
||||
#undef SEND_TYPE_ARG2
|
||||
|
||||
/* Define to the type of arg 3 for send. */
|
||||
/* send() arg3 type */
|
||||
#undef SEND_TYPE_ARG3
|
||||
|
||||
/* Define to the type of arg 4 for send. */
|
||||
/* send() arg4 type */
|
||||
#undef SEND_TYPE_ARG4
|
||||
|
||||
/* Define to the function return type for send. */
|
||||
/* send() return value */
|
||||
#undef SEND_TYPE_RETV
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
/* Define to 1 if all of the C90 standard headers exist (not just the ones
|
||||
required in a freestanding environment). This macro is provided for
|
||||
backward compatibility; new code need not use it. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. This
|
||||
macro is obsolete. */
|
||||
#undef TIME_WITH_SYS_TIME
|
||||
/* Enable extensions on AIX 3, Interix. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
/* Enable general extensions on macOS. */
|
||||
#ifndef _DARWIN_C_SOURCE
|
||||
# undef _DARWIN_C_SOURCE
|
||||
#endif
|
||||
/* Enable general extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
/* Enable X/Open compliant socket functions that do not require linking
|
||||
with -lxnet on HP-UX 11.11. */
|
||||
#ifndef _HPUX_ALT_XOPEN_SOCKET_API
|
||||
# undef _HPUX_ALT_XOPEN_SOCKET_API
|
||||
#endif
|
||||
/* Identify the host operating system as Minix.
|
||||
This macro does not affect the system headers' behavior.
|
||||
A future release of Autoconf may stop defining this macro. */
|
||||
#ifndef _MINIX
|
||||
# undef _MINIX
|
||||
#endif
|
||||
/* Enable general extensions on NetBSD.
|
||||
Enable NetBSD compatibility extensions on Minix. */
|
||||
#ifndef _NETBSD_SOURCE
|
||||
# undef _NETBSD_SOURCE
|
||||
#endif
|
||||
/* Enable OpenBSD compatibility extensions on NetBSD.
|
||||
Oddly enough, this does nothing on OpenBSD. */
|
||||
#ifndef _OPENBSD_SOURCE
|
||||
# undef _OPENBSD_SOURCE
|
||||
#endif
|
||||
/* Define to 1 if needed for POSIX-compatible behavior. */
|
||||
#ifndef _POSIX_SOURCE
|
||||
# undef _POSIX_SOURCE
|
||||
#endif
|
||||
/* Define to 2 if needed for POSIX-compatible behavior. */
|
||||
#ifndef _POSIX_1_SOURCE
|
||||
# undef _POSIX_1_SOURCE
|
||||
#endif
|
||||
/* Enable POSIX-compatible threading on Solaris. */
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC TS 18661-5:2014. */
|
||||
#ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
|
||||
# undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC TS 18661-1:2014. */
|
||||
#ifndef __STDC_WANT_IEC_60559_BFP_EXT__
|
||||
# undef __STDC_WANT_IEC_60559_BFP_EXT__
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC TS 18661-2:2015. */
|
||||
#ifndef __STDC_WANT_IEC_60559_DFP_EXT__
|
||||
# undef __STDC_WANT_IEC_60559_DFP_EXT__
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC TS 18661-4:2015. */
|
||||
#ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__
|
||||
# undef __STDC_WANT_IEC_60559_FUNCS_EXT__
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC TS 18661-3:2015. */
|
||||
#ifndef __STDC_WANT_IEC_60559_TYPES_EXT__
|
||||
# undef __STDC_WANT_IEC_60559_TYPES_EXT__
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC TR 24731-2:2010. */
|
||||
#ifndef __STDC_WANT_LIB_EXT2__
|
||||
# undef __STDC_WANT_LIB_EXT2__
|
||||
#endif
|
||||
/* Enable extensions specified by ISO/IEC 24747:2009. */
|
||||
#ifndef __STDC_WANT_MATH_SPEC_FUNCS__
|
||||
# undef __STDC_WANT_MATH_SPEC_FUNCS__
|
||||
#endif
|
||||
/* Enable extensions on HP NonStop. */
|
||||
#ifndef _TANDEM_SOURCE
|
||||
# undef _TANDEM_SOURCE
|
||||
#endif
|
||||
/* Enable X/Open extensions. Define to 500 only if necessary
|
||||
to make mbstate_t available. */
|
||||
#ifndef _XOPEN_SOURCE
|
||||
# undef _XOPEN_SOURCE
|
||||
#endif
|
||||
|
||||
/* Define to disable non-blocking sockets. */
|
||||
#undef USE_BLOCKING_SOCKETS
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to avoid automatic inclusion of winsock.h */
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#if defined AC_APPLE_UNIVERSAL_BUILD
|
||||
# if defined __BIG_ENDIAN__
|
||||
# define WORDS_BIGENDIAN 1
|
||||
# endif
|
||||
#else
|
||||
# ifndef WORDS_BIGENDIAN
|
||||
# undef WORDS_BIGENDIAN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Define to 1 if OS is AIX. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
|
||||
/* Enable large inode numbers on Mac OS X 10.5. */
|
||||
#ifndef _DARWIN_USE_64_BIT_INODE
|
||||
# define _DARWIN_USE_64_BIT_INODE 1
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
#undef _LARGE_FILES
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Type to use in place of in_addr_t when system does not provide it. */
|
||||
#undef in_addr_t
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
@ -1,197 +1,107 @@
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "ares_nameser.h"
|
||||
|
||||
#include "ares.h"
|
||||
#include "ares_dns.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
|
||||
/* Header format, from RFC 1035:
|
||||
* 1 1 1 1 1 1
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | ID |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | QDCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | ANCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | NSCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | ARCOUNT |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* AA, TC, RA, and RCODE are only set in responses. Brief description
|
||||
* of the remaining fields:
|
||||
* ID Identifier to match responses with queries
|
||||
* QR Query (0) or response (1)
|
||||
* Opcode For our purposes, always O_QUERY
|
||||
* RD Recursion desired
|
||||
* Z Reserved (zero)
|
||||
* QDCOUNT Number of queries
|
||||
* ANCOUNT Number of answers
|
||||
* NSCOUNT Number of name server records
|
||||
* ARCOUNT Number of additional records
|
||||
*
|
||||
* Question format, from RFC 1035:
|
||||
* 1 1 1 1 1 1
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | |
|
||||
* / QNAME /
|
||||
* / /
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | QTYPE |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | QCLASS |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* The query name is encoded as a series of labels, each represented
|
||||
* as a one-byte length (maximum 63) followed by the text of the
|
||||
* label. The list is terminated by a label of length zero (which can
|
||||
* be thought of as the root domain).
|
||||
*/
|
||||
|
||||
int ares_create_query(const char *name, int dnsclass, int type,
|
||||
unsigned short id, int rd, unsigned char **bufp,
|
||||
int *buflenp, int max_udp_size)
|
||||
{
|
||||
size_t len;
|
||||
unsigned char *q;
|
||||
const char *p;
|
||||
size_t buflen;
|
||||
unsigned char *buf;
|
||||
ares_status_t status;
|
||||
ares_dns_record_t *dnsrec = NULL;
|
||||
size_t len;
|
||||
|
||||
/* Set our results early, in case we bail out early with an error. */
|
||||
if (name == NULL || bufp == NULL || buflenp == NULL) {
|
||||
status = ARES_EFORMERR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
*bufp = NULL;
|
||||
*buflenp = 0;
|
||||
*bufp = NULL;
|
||||
|
||||
/* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
|
||||
if (ares__is_onion_domain(name))
|
||||
return ARES_ENOTFOUND;
|
||||
|
||||
/* Allocate a memory area for the maximum size this packet might need. +2
|
||||
* is for the length byte and zero termination if no dots or ecscaping is
|
||||
* used.
|
||||
*/
|
||||
len = strlen(name) + 2 + HFIXEDSZ + QFIXEDSZ +
|
||||
(max_udp_size ? EDNSFIXEDSZ : 0);
|
||||
buf = ares_malloc(len);
|
||||
if (!buf)
|
||||
return ARES_ENOMEM;
|
||||
|
||||
/* Set up the header. */
|
||||
q = buf;
|
||||
memset(q, 0, HFIXEDSZ);
|
||||
DNS_HEADER_SET_QID(q, id);
|
||||
DNS_HEADER_SET_OPCODE(q, O_QUERY);
|
||||
if (rd) {
|
||||
DNS_HEADER_SET_RD(q, 1);
|
||||
}
|
||||
else {
|
||||
DNS_HEADER_SET_RD(q, 0);
|
||||
}
|
||||
DNS_HEADER_SET_QDCOUNT(q, 1);
|
||||
|
||||
if (max_udp_size) {
|
||||
DNS_HEADER_SET_ARCOUNT(q, 1);
|
||||
if (ares__is_onion_domain(name)) {
|
||||
status = ARES_ENOTFOUND;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* A name of "." is a screw case for the loop below, so adjust it. */
|
||||
if (strcmp(name, ".") == 0)
|
||||
name++;
|
||||
status = ares_dns_record_create(&dnsrec, id, rd ? ARES_FLAG_RD : 0,
|
||||
ARES_OPCODE_QUERY, ARES_RCODE_NOERROR);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Start writing out the name after the header. */
|
||||
q += HFIXEDSZ;
|
||||
while (*name)
|
||||
{
|
||||
if (*name == '.') {
|
||||
ares_free (buf);
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
status = ares_dns_record_query_add(dnsrec, name, (ares_dns_rec_type_t)type,
|
||||
(ares_dns_class_t)dnsclass);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Count the number of bytes in this label. */
|
||||
len = 0;
|
||||
for (p = name; *p && *p != '.'; p++)
|
||||
{
|
||||
if (*p == '\\' && *(p + 1) != 0)
|
||||
p++;
|
||||
len++;
|
||||
}
|
||||
if (len > MAXLABEL) {
|
||||
ares_free (buf);
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
/* max_udp_size > 0 indicates EDNS, so send OPT RR as an additional record */
|
||||
if (max_udp_size > 0) {
|
||||
ares_dns_rr_t *rr = NULL;
|
||||
|
||||
/* Encode the length and copy the data. */
|
||||
*q++ = (unsigned char)len;
|
||||
for (p = name; *p && *p != '.'; p++)
|
||||
{
|
||||
if (*p == '\\' && *(p + 1) != 0)
|
||||
p++;
|
||||
*q++ = *p;
|
||||
}
|
||||
|
||||
/* Go to the next label and repeat, unless we hit the end. */
|
||||
if (!*p)
|
||||
break;
|
||||
name = p + 1;
|
||||
status = ares_dns_record_rr_add(&rr, dnsrec, ARES_SECTION_ADDITIONAL, "",
|
||||
ARES_REC_TYPE_OPT, ARES_CLASS_IN, 0);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Add the zero-length label at the end. */
|
||||
*q++ = 0;
|
||||
if (max_udp_size > 65535) {
|
||||
status = ARES_EFORMERR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Finish off the question with the type and class. */
|
||||
DNS_QUESTION_SET_TYPE(q, type);
|
||||
DNS_QUESTION_SET_CLASS(q, dnsclass);
|
||||
status = ares_dns_rr_set_u16(rr, ARES_RR_OPT_UDP_SIZE,
|
||||
(unsigned short)max_udp_size);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
q += QFIXEDSZ;
|
||||
if (max_udp_size)
|
||||
{
|
||||
memset(q, 0, EDNSFIXEDSZ);
|
||||
q++;
|
||||
DNS_RR_SET_TYPE(q, T_OPT);
|
||||
DNS_RR_SET_CLASS(q, max_udp_size);
|
||||
q += (EDNSFIXEDSZ-1);
|
||||
}
|
||||
buflen = (q - buf);
|
||||
status = ares_dns_rr_set_u8(rr, ARES_RR_OPT_VERSION, 0);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Reject names that are longer than the maximum of 255 bytes that's
|
||||
* specified in RFC 1035 ("To simplify implementations, the total length of
|
||||
* a domain name (i.e., label octets and label length octets) is restricted
|
||||
* to 255 octets or less."). */
|
||||
if (buflen > (size_t)(MAXCDNAME + HFIXEDSZ + QFIXEDSZ +
|
||||
(max_udp_size ? EDNSFIXEDSZ : 0))) {
|
||||
ares_free (buf);
|
||||
return ARES_EBADNAME;
|
||||
status = ares_dns_rr_set_u16(rr, ARES_RR_OPT_FLAGS, 0);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* we know this fits in an int at this point */
|
||||
*buflenp = (int) buflen;
|
||||
*bufp = buf;
|
||||
status = ares_dns_write(dnsrec, bufp, &len);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
*buflenp = (int)len;
|
||||
|
||||
done:
|
||||
ares_dns_record_destroy(dnsrec);
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
264
src/third_party/cares/dist/src/lib/ares_data.c
vendored
264
src/third_party/cares/dist/src/lib/ares_data.c
vendored
@ -1,17 +1,27 @@
|
||||
|
||||
/* Copyright (C) 2009-2013 by Daniel Stenberg
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 2009 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
|
||||
@ -23,7 +33,6 @@
|
||||
#include "ares_data.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
|
||||
/*
|
||||
** ares_free_data() - c-ares external API function.
|
||||
**
|
||||
@ -42,12 +51,12 @@ void ares_free_data(void *dataptr)
|
||||
{
|
||||
while (dataptr != NULL) {
|
||||
struct ares_data *ptr;
|
||||
void *next_data = NULL;
|
||||
void *next_data = NULL;
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:1684)
|
||||
/* 1684: conversion from pointer to same-sized integral type */
|
||||
# pragma warning(disable : 1684)
|
||||
/* 1684: conversion from pointer to same-sized integral type */
|
||||
#endif
|
||||
|
||||
ptr = (void *)((char *)dataptr - offsetof(struct ares_data, data));
|
||||
@ -56,97 +65,68 @@ void ares_free_data(void *dataptr)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
if (ptr->mark != ARES_DATATYPE_MARK)
|
||||
if (ptr->mark != ARES_DATATYPE_MARK) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ptr->type)
|
||||
{
|
||||
case ARES_DATATYPE_MX_REPLY:
|
||||
switch (ptr->type) {
|
||||
case ARES_DATATYPE_MX_REPLY:
|
||||
next_data = ptr->data.mx_reply.next;
|
||||
ares_free(ptr->data.mx_reply.host);
|
||||
break;
|
||||
|
||||
if (ptr->data.mx_reply.next)
|
||||
next_data = ptr->data.mx_reply.next;
|
||||
if (ptr->data.mx_reply.host)
|
||||
ares_free(ptr->data.mx_reply.host);
|
||||
break;
|
||||
case ARES_DATATYPE_SRV_REPLY:
|
||||
next_data = ptr->data.srv_reply.next;
|
||||
ares_free(ptr->data.srv_reply.host);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_SRV_REPLY:
|
||||
case ARES_DATATYPE_URI_REPLY:
|
||||
next_data = ptr->data.uri_reply.next;
|
||||
ares_free(ptr->data.uri_reply.uri);
|
||||
break;
|
||||
|
||||
if (ptr->data.srv_reply.next)
|
||||
next_data = ptr->data.srv_reply.next;
|
||||
if (ptr->data.srv_reply.host)
|
||||
ares_free(ptr->data.srv_reply.host);
|
||||
break;
|
||||
case ARES_DATATYPE_TXT_REPLY:
|
||||
case ARES_DATATYPE_TXT_EXT:
|
||||
next_data = ptr->data.txt_reply.next;
|
||||
ares_free(ptr->data.txt_reply.txt);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_URI_REPLY:
|
||||
case ARES_DATATYPE_ADDR_NODE:
|
||||
next_data = ptr->data.addr_node.next;
|
||||
break;
|
||||
|
||||
if (ptr->data.uri_reply.next)
|
||||
next_data = ptr->data.uri_reply.next;
|
||||
if (ptr->data.uri_reply.uri)
|
||||
ares_free(ptr->data.uri_reply.uri);
|
||||
break;
|
||||
case ARES_DATATYPE_ADDR_PORT_NODE:
|
||||
next_data = ptr->data.addr_port_node.next;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_TXT_REPLY:
|
||||
case ARES_DATATYPE_TXT_EXT:
|
||||
case ARES_DATATYPE_NAPTR_REPLY:
|
||||
next_data = ptr->data.naptr_reply.next;
|
||||
ares_free(ptr->data.naptr_reply.flags);
|
||||
ares_free(ptr->data.naptr_reply.service);
|
||||
ares_free(ptr->data.naptr_reply.regexp);
|
||||
ares_free(ptr->data.naptr_reply.replacement);
|
||||
break;
|
||||
|
||||
if (ptr->data.txt_reply.next)
|
||||
next_data = ptr->data.txt_reply.next;
|
||||
if (ptr->data.txt_reply.txt)
|
||||
ares_free(ptr->data.txt_reply.txt);
|
||||
break;
|
||||
case ARES_DATATYPE_SOA_REPLY:
|
||||
ares_free(ptr->data.soa_reply.nsname);
|
||||
ares_free(ptr->data.soa_reply.hostmaster);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_ADDR_NODE:
|
||||
case ARES_DATATYPE_CAA_REPLY:
|
||||
next_data = ptr->data.caa_reply.next;
|
||||
ares_free(ptr->data.caa_reply.property);
|
||||
ares_free(ptr->data.caa_reply.value);
|
||||
break;
|
||||
|
||||
if (ptr->data.addr_node.next)
|
||||
next_data = ptr->data.addr_node.next;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_ADDR_PORT_NODE:
|
||||
|
||||
if (ptr->data.addr_port_node.next)
|
||||
next_data = ptr->data.addr_port_node.next;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_NAPTR_REPLY:
|
||||
|
||||
if (ptr->data.naptr_reply.next)
|
||||
next_data = ptr->data.naptr_reply.next;
|
||||
if (ptr->data.naptr_reply.flags)
|
||||
ares_free(ptr->data.naptr_reply.flags);
|
||||
if (ptr->data.naptr_reply.service)
|
||||
ares_free(ptr->data.naptr_reply.service);
|
||||
if (ptr->data.naptr_reply.regexp)
|
||||
ares_free(ptr->data.naptr_reply.regexp);
|
||||
if (ptr->data.naptr_reply.replacement)
|
||||
ares_free(ptr->data.naptr_reply.replacement);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_SOA_REPLY:
|
||||
if (ptr->data.soa_reply.nsname)
|
||||
ares_free(ptr->data.soa_reply.nsname);
|
||||
if (ptr->data.soa_reply.hostmaster)
|
||||
ares_free(ptr->data.soa_reply.hostmaster);
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_CAA_REPLY:
|
||||
|
||||
if (ptr->data.caa_reply.next)
|
||||
next_data = ptr->data.caa_reply.next;
|
||||
if (ptr->data.caa_reply.property)
|
||||
ares_free(ptr->data.caa_reply.property);
|
||||
if (ptr->data.caa_reply.value)
|
||||
ares_free(ptr->data.caa_reply.value);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
ares_free(ptr);
|
||||
dataptr = next_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** ares_malloc_data() - c-ares internal helper function.
|
||||
**
|
||||
@ -162,92 +142,28 @@ void *ares_malloc_data(ares_datatype type)
|
||||
{
|
||||
struct ares_data *ptr;
|
||||
|
||||
ptr = ares_malloc(sizeof(struct ares_data));
|
||||
if (!ptr)
|
||||
ptr = ares_malloc_zero(sizeof(*ptr));
|
||||
if (!ptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ARES_DATATYPE_MX_REPLY:
|
||||
ptr->data.mx_reply.next = NULL;
|
||||
ptr->data.mx_reply.host = NULL;
|
||||
ptr->data.mx_reply.priority = 0;
|
||||
break;
|
||||
switch (type) {
|
||||
case ARES_DATATYPE_MX_REPLY:
|
||||
case ARES_DATATYPE_SRV_REPLY:
|
||||
case ARES_DATATYPE_URI_REPLY:
|
||||
case ARES_DATATYPE_TXT_EXT:
|
||||
case ARES_DATATYPE_TXT_REPLY:
|
||||
case ARES_DATATYPE_CAA_REPLY:
|
||||
case ARES_DATATYPE_ADDR_NODE:
|
||||
case ARES_DATATYPE_ADDR_PORT_NODE:
|
||||
case ARES_DATATYPE_NAPTR_REPLY:
|
||||
case ARES_DATATYPE_SOA_REPLY:
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_SRV_REPLY:
|
||||
ptr->data.srv_reply.next = NULL;
|
||||
ptr->data.srv_reply.host = NULL;
|
||||
ptr->data.srv_reply.priority = 0;
|
||||
ptr->data.srv_reply.weight = 0;
|
||||
ptr->data.srv_reply.port = 0;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_URI_REPLY:
|
||||
ptr->data.uri_reply.next = NULL;
|
||||
ptr->data.uri_reply.priority = 0;
|
||||
ptr->data.uri_reply.weight = 0;
|
||||
ptr->data.uri_reply.uri = NULL;
|
||||
ptr->data.uri_reply.ttl = 0;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_TXT_EXT:
|
||||
ptr->data.txt_ext.record_start = 0;
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case ARES_DATATYPE_TXT_REPLY:
|
||||
ptr->data.txt_reply.next = NULL;
|
||||
ptr->data.txt_reply.txt = NULL;
|
||||
ptr->data.txt_reply.length = 0;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_CAA_REPLY:
|
||||
ptr->data.caa_reply.next = NULL;
|
||||
ptr->data.caa_reply.plength = 0;
|
||||
ptr->data.caa_reply.property = NULL;
|
||||
ptr->data.caa_reply.length = 0;
|
||||
ptr->data.caa_reply.value = NULL;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_ADDR_NODE:
|
||||
ptr->data.addr_node.next = NULL;
|
||||
ptr->data.addr_node.family = 0;
|
||||
memset(&ptr->data.addr_node.addrV6, 0,
|
||||
sizeof(ptr->data.addr_node.addrV6));
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_ADDR_PORT_NODE:
|
||||
ptr->data.addr_port_node.next = NULL;
|
||||
ptr->data.addr_port_node.family = 0;
|
||||
ptr->data.addr_port_node.udp_port = 0;
|
||||
ptr->data.addr_port_node.tcp_port = 0;
|
||||
memset(&ptr->data.addr_port_node.addrV6, 0,
|
||||
sizeof(ptr->data.addr_port_node.addrV6));
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_NAPTR_REPLY:
|
||||
ptr->data.naptr_reply.next = NULL;
|
||||
ptr->data.naptr_reply.flags = NULL;
|
||||
ptr->data.naptr_reply.service = NULL;
|
||||
ptr->data.naptr_reply.regexp = NULL;
|
||||
ptr->data.naptr_reply.replacement = NULL;
|
||||
ptr->data.naptr_reply.order = 0;
|
||||
ptr->data.naptr_reply.preference = 0;
|
||||
break;
|
||||
|
||||
case ARES_DATATYPE_SOA_REPLY:
|
||||
ptr->data.soa_reply.nsname = NULL;
|
||||
ptr->data.soa_reply.hostmaster = NULL;
|
||||
ptr->data.soa_reply.serial = 0;
|
||||
ptr->data.soa_reply.refresh = 0;
|
||||
ptr->data.soa_reply.retry = 0;
|
||||
ptr->data.soa_reply.expire = 0;
|
||||
ptr->data.soa_reply.minttl = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
ares_free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
default:
|
||||
ares_free(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr->mark = ARES_DATATYPE_MARK;
|
||||
ptr->type = type;
|
||||
|
||||
89
src/third_party/cares/dist/src/lib/ares_data.h
vendored
89
src/third_party/cares/dist/src/lib/ares_data.h
vendored
@ -1,41 +1,51 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2009 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES_DATA_H
|
||||
#define __ARES_DATA_H
|
||||
|
||||
|
||||
/* Copyright (C) 2009-2013 by Daniel Stenberg
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
ARES_DATATYPE_UNKNOWN = 1, /* unknown data type - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_SRV_REPLY, /* struct ares_srv_reply - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_TXT_REPLY, /* struct ares_txt_reply - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_TXT_EXT, /* struct ares_txt_ext - introduced in 1.11.0 */
|
||||
ARES_DATATYPE_ADDR_NODE, /* struct ares_addr_node - introduced in 1.7.1 */
|
||||
ARES_DATATYPE_UNKNOWN = 1, /* unknown data type - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_SRV_REPLY, /* struct ares_srv_reply - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_TXT_REPLY, /* struct ares_txt_reply - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_TXT_EXT, /* struct ares_txt_ext - introduced in 1.11.0 */
|
||||
ARES_DATATYPE_ADDR_NODE, /* struct ares_addr_node - introduced in 1.7.1 */
|
||||
ARES_DATATYPE_MX_REPLY, /* struct ares_mx_reply - introduced in 1.7.2 */
|
||||
ARES_DATATYPE_NAPTR_REPLY,/* struct ares_naptr_reply - introduced in 1.7.6 */
|
||||
ARES_DATATYPE_SOA_REPLY, /* struct ares_soa_reply - introduced in 1.9.0 */
|
||||
ARES_DATATYPE_URI_REPLY, /* struct ares_uri_reply */
|
||||
ARES_DATATYPE_NAPTR_REPLY, /* struct ares_naptr_reply - introduced in 1.7.6 */
|
||||
ARES_DATATYPE_SOA_REPLY, /* struct ares_soa_reply - introduced in 1.9.0 */
|
||||
ARES_DATATYPE_URI_REPLY, /* struct ares_uri_reply */
|
||||
#if 0
|
||||
ARES_DATATYPE_ADDR6TTL, /* struct ares_addrttl */
|
||||
ARES_DATATYPE_ADDRTTL, /* struct ares_addr6ttl */
|
||||
ARES_DATATYPE_HOSTENT, /* struct hostent */
|
||||
ARES_DATATYPE_OPTIONS, /* struct ares_options */
|
||||
#endif
|
||||
ARES_DATATYPE_ADDR_PORT_NODE, /* struct ares_addr_port_node - introduced in 1.11.0 */
|
||||
ARES_DATATYPE_CAA_REPLY, /* struct ares_caa_reply - introduced in 1.17 */
|
||||
ARES_DATATYPE_LAST /* not used - introduced in 1.7.0 */
|
||||
ARES_DATATYPE_ADDR_PORT_NODE, /* struct ares_addr_port_node - introduced
|
||||
in 1.11.0 */
|
||||
ARES_DATATYPE_CAA_REPLY, /* struct ares_caa_reply - introduced in 1.17 */
|
||||
ARES_DATATYPE_LAST /* not used - introduced in 1.7.0 */
|
||||
} ares_datatype;
|
||||
|
||||
#define ARES_DATATYPE_MARK 0xbead
|
||||
@ -59,19 +69,20 @@ typedef enum {
|
||||
*/
|
||||
|
||||
struct ares_data {
|
||||
ares_datatype type; /* Actual data type identifier. */
|
||||
unsigned int mark; /* Private ares_data signature. */
|
||||
ares_datatype type; /* Actual data type identifier. */
|
||||
unsigned int mark; /* Private ares_data signature. */
|
||||
|
||||
union {
|
||||
struct ares_txt_reply txt_reply;
|
||||
struct ares_txt_ext txt_ext;
|
||||
struct ares_srv_reply srv_reply;
|
||||
struct ares_addr_node addr_node;
|
||||
struct ares_addr_port_node addr_port_node;
|
||||
struct ares_mx_reply mx_reply;
|
||||
struct ares_naptr_reply naptr_reply;
|
||||
struct ares_soa_reply soa_reply;
|
||||
struct ares_caa_reply caa_reply;
|
||||
struct ares_uri_reply uri_reply;
|
||||
struct ares_txt_reply txt_reply;
|
||||
struct ares_txt_ext txt_ext;
|
||||
struct ares_srv_reply srv_reply;
|
||||
struct ares_addr_node addr_node;
|
||||
struct ares_addr_port_node addr_port_node;
|
||||
struct ares_mx_reply mx_reply;
|
||||
struct ares_naptr_reply naptr_reply;
|
||||
struct ares_soa_reply soa_reply;
|
||||
struct ares_caa_reply caa_reply;
|
||||
struct ares_uri_reply uri_reply;
|
||||
} data;
|
||||
};
|
||||
|
||||
|
||||
181
src/third_party/cares/dist/src/lib/ares_destroy.c
vendored
181
src/third_party/cares/dist/src/lib/ares_destroy.c
vendored
@ -1,18 +1,28 @@
|
||||
|
||||
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||
* Copyright (C) 2004-2011 by Daniel Stenberg
|
||||
/* MIT License
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software and its documentation for any purpose and without
|
||||
* fee is hereby granted, provided that the above copyright
|
||||
* notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting
|
||||
* documentation, and that the name of M.I.T. not be used in
|
||||
* advertising or publicity pertaining to distribution of the
|
||||
* software without specific, written prior permission.
|
||||
* M.I.T. makes no representations about the suitability of
|
||||
* this software for any purpose. It is provided "as is"
|
||||
* without express or implied warranty.
|
||||
* Copyright (c) 1998 Massachusetts Institute of Technology
|
||||
* Copyright (c) 2004 Daniel Stenberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "ares_setup.h"
|
||||
@ -22,100 +32,105 @@
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
void ares_destroy_options(struct ares_options *options)
|
||||
void ares_destroy(ares_channel_t *channel)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
ares__llist_node_t *node = NULL;
|
||||
|
||||
if(options->servers)
|
||||
ares_free(options->servers);
|
||||
for (i = 0; i < options->ndomains; i++)
|
||||
ares_free(options->domains[i]);
|
||||
if(options->domains)
|
||||
ares_free(options->domains);
|
||||
if(options->sortlist)
|
||||
ares_free(options->sortlist);
|
||||
if(options->lookups)
|
||||
ares_free(options->lookups);
|
||||
if(options->resolvconf_path)
|
||||
ares_free(options->resolvconf_path);
|
||||
if(options->hosts_path)
|
||||
ares_free(options->hosts_path);
|
||||
}
|
||||
|
||||
void ares_destroy(ares_channel channel)
|
||||
{
|
||||
int i;
|
||||
struct query *query;
|
||||
struct list_node* list_head;
|
||||
struct list_node* list_node;
|
||||
|
||||
if (!channel)
|
||||
if (channel == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Lock because callbacks will be triggered */
|
||||
ares__channel_lock(channel);
|
||||
|
||||
/* Destroy all queries */
|
||||
node = ares__llist_node_first(channel->all_queries);
|
||||
while (node != NULL) {
|
||||
ares__llist_node_t *next = ares__llist_node_next(node);
|
||||
struct query *query = ares__llist_node_claim(node);
|
||||
|
||||
query->node_all_queries = NULL;
|
||||
query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
|
||||
ares__free_query(query);
|
||||
|
||||
node = next;
|
||||
}
|
||||
|
||||
ares_queue_notify_empty(channel);
|
||||
|
||||
list_head = &(channel->all_queries);
|
||||
for (list_node = list_head->next; list_node != list_head; )
|
||||
{
|
||||
query = list_node->data;
|
||||
list_node = list_node->next; /* since we're deleting the query */
|
||||
query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
|
||||
ares__free_query(query);
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
/* Freeing the query should remove it from all the lists in which it sits,
|
||||
* so all query lists should be empty now.
|
||||
*/
|
||||
assert(ares__is_list_empty(&(channel->all_queries)));
|
||||
for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
|
||||
{
|
||||
assert(ares__is_list_empty(&(channel->queries_by_qid[i])));
|
||||
}
|
||||
for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
|
||||
{
|
||||
assert(ares__is_list_empty(&(channel->queries_by_timeout[i])));
|
||||
}
|
||||
assert(ares__llist_len(channel->all_queries) == 0);
|
||||
assert(ares__htable_szvp_num_keys(channel->queries_by_qid) == 0);
|
||||
assert(ares__slist_len(channel->queries_by_timeout) == 0);
|
||||
#endif
|
||||
|
||||
ares__destroy_servers_state(channel);
|
||||
|
||||
#ifndef NDEBUG
|
||||
assert(ares__htable_asvp_num_keys(channel->connnode_by_socket) == 0);
|
||||
#endif
|
||||
|
||||
/* No more callbacks will be triggered after this point, unlock */
|
||||
ares__channel_unlock(channel);
|
||||
|
||||
/* Shut down the event thread */
|
||||
if (channel->optmask & ARES_OPT_EVENT_THREAD) {
|
||||
ares_event_thread_destroy(channel);
|
||||
}
|
||||
|
||||
if (channel->domains) {
|
||||
for (i = 0; i < channel->ndomains; i++)
|
||||
for (i = 0; i < channel->ndomains; i++) {
|
||||
ares_free(channel->domains[i]);
|
||||
}
|
||||
ares_free(channel->domains);
|
||||
}
|
||||
|
||||
if(channel->sortlist)
|
||||
ares_free(channel->sortlist);
|
||||
ares__llist_destroy(channel->all_queries);
|
||||
ares__slist_destroy(channel->queries_by_timeout);
|
||||
ares__htable_szvp_destroy(channel->queries_by_qid);
|
||||
ares__htable_asvp_destroy(channel->connnode_by_socket);
|
||||
|
||||
if (channel->lookups)
|
||||
ares_free(channel->lookups);
|
||||
ares_free(channel->sortlist);
|
||||
ares_free(channel->lookups);
|
||||
ares_free(channel->resolvconf_path);
|
||||
ares_free(channel->hosts_path);
|
||||
ares__destroy_rand_state(channel->rand_state);
|
||||
|
||||
if (channel->resolvconf_path)
|
||||
ares_free(channel->resolvconf_path);
|
||||
ares__hosts_file_destroy(channel->hf);
|
||||
|
||||
if (channel->hosts_path)
|
||||
ares_free(channel->hosts_path);
|
||||
ares__qcache_destroy(channel->qcache);
|
||||
|
||||
if (channel->rand_state)
|
||||
ares__destroy_rand_state(channel->rand_state);
|
||||
ares__channel_threading_destroy(channel);
|
||||
|
||||
ares_free(channel);
|
||||
}
|
||||
|
||||
void ares__destroy_servers_state(ares_channel channel)
|
||||
void ares__destroy_server(struct server_state *server)
|
||||
{
|
||||
struct server_state *server;
|
||||
int i;
|
||||
if (server == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel->servers)
|
||||
{
|
||||
for (i = 0; i < channel->nservers; i++)
|
||||
{
|
||||
server = &channel->servers[i];
|
||||
ares__close_sockets(channel, server);
|
||||
assert(ares__is_list_empty(&server->queries_to_server));
|
||||
}
|
||||
ares_free(channel->servers);
|
||||
channel->servers = NULL;
|
||||
}
|
||||
channel->nservers = -1;
|
||||
ares__close_sockets(server);
|
||||
ares__llist_destroy(server->connections);
|
||||
ares__buf_destroy(server->tcp_parser);
|
||||
ares__buf_destroy(server->tcp_send);
|
||||
ares_free(server);
|
||||
}
|
||||
|
||||
void ares__destroy_servers_state(ares_channel_t *channel)
|
||||
{
|
||||
ares__slist_node_t *node;
|
||||
|
||||
while ((node = ares__slist_node_first(channel->servers)) != NULL) {
|
||||
struct server_state *server = ares__slist_node_claim(node);
|
||||
ares__destroy_server(server);
|
||||
}
|
||||
|
||||
ares__slist_destroy(channel->servers);
|
||||
channel->servers = NULL;
|
||||
}
|
||||
|
||||
885
src/third_party/cares/dist/src/lib/ares_dns_mapping.c
vendored
Normal file
885
src/third_party/cares/dist/src/lib/ares_dns_mapping.c
vendored
Normal file
@ -0,0 +1,885 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
ares_bool_t ares_dns_opcode_isvalid(ares_dns_opcode_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case ARES_OPCODE_QUERY:
|
||||
case ARES_OPCODE_IQUERY:
|
||||
case ARES_OPCODE_STATUS:
|
||||
case ARES_OPCODE_NOTIFY:
|
||||
case ARES_OPCODE_UPDATE:
|
||||
return ARES_TRUE;
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_rcode_isvalid(ares_dns_rcode_t rcode)
|
||||
{
|
||||
switch (rcode) {
|
||||
case ARES_RCODE_NOERROR:
|
||||
case ARES_RCODE_FORMERR:
|
||||
case ARES_RCODE_SERVFAIL:
|
||||
case ARES_RCODE_NXDOMAIN:
|
||||
case ARES_RCODE_NOTIMP:
|
||||
case ARES_RCODE_REFUSED:
|
||||
case ARES_RCODE_YXDOMAIN:
|
||||
case ARES_RCODE_YXRRSET:
|
||||
case ARES_RCODE_NXRRSET:
|
||||
case ARES_RCODE_NOTAUTH:
|
||||
case ARES_RCODE_NOTZONE:
|
||||
case ARES_RCODE_DSOTYPEI:
|
||||
case ARES_RCODE_BADSIG:
|
||||
case ARES_RCODE_BADKEY:
|
||||
case ARES_RCODE_BADTIME:
|
||||
case ARES_RCODE_BADMODE:
|
||||
case ARES_RCODE_BADNAME:
|
||||
case ARES_RCODE_BADALG:
|
||||
case ARES_RCODE_BADTRUNC:
|
||||
case ARES_RCODE_BADCOOKIE:
|
||||
return ARES_TRUE;
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_flags_arevalid(unsigned short flags)
|
||||
{
|
||||
unsigned short allflags = ARES_FLAG_QR | ARES_FLAG_AA | ARES_FLAG_TC |
|
||||
ARES_FLAG_RD | ARES_FLAG_RA | ARES_FLAG_AD |
|
||||
ARES_FLAG_CD;
|
||||
|
||||
if (flags & ~allflags) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
return ARES_TRUE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_rec_type_isvalid(ares_dns_rec_type_t type,
|
||||
ares_bool_t is_query)
|
||||
{
|
||||
switch (type) {
|
||||
case ARES_REC_TYPE_A:
|
||||
case ARES_REC_TYPE_NS:
|
||||
case ARES_REC_TYPE_CNAME:
|
||||
case ARES_REC_TYPE_SOA:
|
||||
case ARES_REC_TYPE_PTR:
|
||||
case ARES_REC_TYPE_HINFO:
|
||||
case ARES_REC_TYPE_MX:
|
||||
case ARES_REC_TYPE_TXT:
|
||||
case ARES_REC_TYPE_AAAA:
|
||||
case ARES_REC_TYPE_SRV:
|
||||
case ARES_REC_TYPE_NAPTR:
|
||||
case ARES_REC_TYPE_OPT:
|
||||
case ARES_REC_TYPE_TLSA:
|
||||
case ARES_REC_TYPE_SVCB:
|
||||
case ARES_REC_TYPE_HTTPS:
|
||||
case ARES_REC_TYPE_ANY:
|
||||
case ARES_REC_TYPE_URI:
|
||||
case ARES_REC_TYPE_CAA:
|
||||
return ARES_TRUE;
|
||||
case ARES_REC_TYPE_RAW_RR:
|
||||
return is_query ? ARES_FALSE : ARES_TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return is_query ? ARES_TRUE : ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_rec_type_allow_name_compression(ares_dns_rec_type_t type)
|
||||
{
|
||||
/* Only record types defined in RFC1035 allow name compression within the
|
||||
* RDATA. Otherwise nameservers that don't understand an RR may not be
|
||||
* able to pass along the RR in a proper manner */
|
||||
switch (type) {
|
||||
case ARES_REC_TYPE_A:
|
||||
case ARES_REC_TYPE_NS:
|
||||
case ARES_REC_TYPE_CNAME:
|
||||
case ARES_REC_TYPE_SOA:
|
||||
case ARES_REC_TYPE_PTR:
|
||||
case ARES_REC_TYPE_HINFO:
|
||||
case ARES_REC_TYPE_MX:
|
||||
case ARES_REC_TYPE_TXT:
|
||||
return ARES_TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_class_isvalid(ares_dns_class_t qclass,
|
||||
ares_bool_t is_query)
|
||||
{
|
||||
switch (qclass) {
|
||||
case ARES_CLASS_IN:
|
||||
case ARES_CLASS_CHAOS:
|
||||
case ARES_CLASS_HESOID:
|
||||
case ARES_CLASS_NONE:
|
||||
return ARES_TRUE;
|
||||
case ARES_CLASS_ANY:
|
||||
return is_query ? ARES_TRUE : ARES_FALSE;
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_section_isvalid(ares_dns_section_t sect)
|
||||
{
|
||||
switch (sect) {
|
||||
case ARES_SECTION_ANSWER:
|
||||
case ARES_SECTION_AUTHORITY:
|
||||
case ARES_SECTION_ADDITIONAL:
|
||||
return ARES_TRUE;
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_dns_rec_type_t ares_dns_rr_key_to_rec_type(ares_dns_rr_key_t key)
|
||||
{
|
||||
/* NOTE: due to the way we've numerated the keys, we can simply divide by
|
||||
* 100 to get the type rather than having to do a huge switch
|
||||
* statement. That said, we do then validate the type returned is
|
||||
* valid in case something completely bogus is passed in */
|
||||
ares_dns_rec_type_t type = key / 100;
|
||||
if (!ares_dns_rec_type_isvalid(type, ARES_FALSE)) {
|
||||
return 0;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
const char *ares_dns_rec_type_tostr(ares_dns_rec_type_t type)
|
||||
{
|
||||
switch (type) {
|
||||
case ARES_REC_TYPE_A:
|
||||
return "A";
|
||||
case ARES_REC_TYPE_NS:
|
||||
return "NS";
|
||||
case ARES_REC_TYPE_CNAME:
|
||||
return "CNAME";
|
||||
case ARES_REC_TYPE_SOA:
|
||||
return "SOA";
|
||||
case ARES_REC_TYPE_PTR:
|
||||
return "PTR";
|
||||
case ARES_REC_TYPE_HINFO:
|
||||
return "HINFO";
|
||||
case ARES_REC_TYPE_MX:
|
||||
return "MX";
|
||||
case ARES_REC_TYPE_TXT:
|
||||
return "TXT";
|
||||
case ARES_REC_TYPE_AAAA:
|
||||
return "AAAA";
|
||||
case ARES_REC_TYPE_SRV:
|
||||
return "SRV";
|
||||
case ARES_REC_TYPE_NAPTR:
|
||||
return "NAPTR";
|
||||
case ARES_REC_TYPE_OPT:
|
||||
return "OPT";
|
||||
case ARES_REC_TYPE_TLSA:
|
||||
return "TLSA";
|
||||
case ARES_REC_TYPE_SVCB:
|
||||
return "SVCB";
|
||||
case ARES_REC_TYPE_HTTPS:
|
||||
return "HTTPS";
|
||||
case ARES_REC_TYPE_ANY:
|
||||
return "ANY";
|
||||
case ARES_REC_TYPE_URI:
|
||||
return "URI";
|
||||
case ARES_REC_TYPE_CAA:
|
||||
return "CAA";
|
||||
case ARES_REC_TYPE_RAW_RR:
|
||||
return "RAWRR";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
const char *ares_dns_class_tostr(ares_dns_class_t qclass)
|
||||
{
|
||||
switch (qclass) {
|
||||
case ARES_CLASS_IN:
|
||||
return "IN";
|
||||
case ARES_CLASS_CHAOS:
|
||||
return "CH";
|
||||
case ARES_CLASS_HESOID:
|
||||
return "HS";
|
||||
case ARES_CLASS_ANY:
|
||||
return "ANY";
|
||||
case ARES_CLASS_NONE:
|
||||
return "NONE";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
const char *ares_dns_opcode_tostr(ares_dns_opcode_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case ARES_OPCODE_QUERY:
|
||||
return "QUERY";
|
||||
case ARES_OPCODE_IQUERY:
|
||||
return "IQUERY";
|
||||
case ARES_OPCODE_STATUS:
|
||||
return "STATUS";
|
||||
case ARES_OPCODE_NOTIFY:
|
||||
return "NOTIFY";
|
||||
case ARES_OPCODE_UPDATE:
|
||||
return "UPDATE";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
const char *ares_dns_rr_key_tostr(ares_dns_rr_key_t key)
|
||||
{
|
||||
switch (key) {
|
||||
case ARES_RR_A_ADDR:
|
||||
return "ADDR";
|
||||
|
||||
case ARES_RR_NS_NSDNAME:
|
||||
return "NSDNAME";
|
||||
|
||||
case ARES_RR_CNAME_CNAME:
|
||||
return "CNAME";
|
||||
|
||||
case ARES_RR_SOA_MNAME:
|
||||
return "MNAME";
|
||||
|
||||
case ARES_RR_SOA_RNAME:
|
||||
return "RNAME";
|
||||
|
||||
case ARES_RR_SOA_SERIAL:
|
||||
return "SERIAL";
|
||||
|
||||
case ARES_RR_SOA_REFRESH:
|
||||
return "REFRESH";
|
||||
|
||||
case ARES_RR_SOA_RETRY:
|
||||
return "RETRY";
|
||||
|
||||
case ARES_RR_SOA_EXPIRE:
|
||||
return "EXPIRE";
|
||||
|
||||
case ARES_RR_SOA_MINIMUM:
|
||||
return "MINIMUM";
|
||||
|
||||
case ARES_RR_PTR_DNAME:
|
||||
return "DNAME";
|
||||
|
||||
case ARES_RR_AAAA_ADDR:
|
||||
return "ADDR";
|
||||
|
||||
case ARES_RR_HINFO_CPU:
|
||||
return "CPU";
|
||||
|
||||
case ARES_RR_HINFO_OS:
|
||||
return "OS";
|
||||
|
||||
case ARES_RR_MX_PREFERENCE:
|
||||
return "PREFERENCE";
|
||||
|
||||
case ARES_RR_MX_EXCHANGE:
|
||||
return "EXCHANGE";
|
||||
|
||||
case ARES_RR_TXT_DATA:
|
||||
return "DATA";
|
||||
|
||||
case ARES_RR_SRV_PRIORITY:
|
||||
return "PRIORITY";
|
||||
|
||||
case ARES_RR_SRV_WEIGHT:
|
||||
return "WEIGHT";
|
||||
|
||||
case ARES_RR_SRV_PORT:
|
||||
return "PORT";
|
||||
|
||||
case ARES_RR_SRV_TARGET:
|
||||
return "TARGET";
|
||||
|
||||
case ARES_RR_NAPTR_ORDER:
|
||||
return "ORDER";
|
||||
|
||||
case ARES_RR_NAPTR_PREFERENCE:
|
||||
return "PREFERENCE";
|
||||
|
||||
case ARES_RR_NAPTR_FLAGS:
|
||||
return "FLAGS";
|
||||
|
||||
case ARES_RR_NAPTR_SERVICES:
|
||||
return "SERVICES";
|
||||
|
||||
case ARES_RR_NAPTR_REGEXP:
|
||||
return "REGEXP";
|
||||
|
||||
case ARES_RR_NAPTR_REPLACEMENT:
|
||||
return "REPLACEMENT";
|
||||
|
||||
case ARES_RR_OPT_UDP_SIZE:
|
||||
return "UDP_SIZE";
|
||||
|
||||
case ARES_RR_OPT_VERSION:
|
||||
return "VERSION";
|
||||
|
||||
case ARES_RR_OPT_FLAGS:
|
||||
return "FLAGS";
|
||||
|
||||
case ARES_RR_OPT_OPTIONS:
|
||||
return "OPTIONS";
|
||||
|
||||
case ARES_RR_TLSA_CERT_USAGE:
|
||||
return "CERT_USAGE";
|
||||
|
||||
case ARES_RR_TLSA_SELECTOR:
|
||||
return "SELECTOR";
|
||||
|
||||
case ARES_RR_TLSA_MATCH:
|
||||
return "MATCH";
|
||||
|
||||
case ARES_RR_TLSA_DATA:
|
||||
return "DATA";
|
||||
|
||||
case ARES_RR_SVCB_PRIORITY:
|
||||
return "PRIORITY";
|
||||
|
||||
case ARES_RR_SVCB_TARGET:
|
||||
return "TARGET";
|
||||
|
||||
case ARES_RR_SVCB_PARAMS:
|
||||
return "PARAMS";
|
||||
|
||||
case ARES_RR_HTTPS_PRIORITY:
|
||||
return "PRIORITY";
|
||||
|
||||
case ARES_RR_HTTPS_TARGET:
|
||||
return "TARGET";
|
||||
|
||||
case ARES_RR_HTTPS_PARAMS:
|
||||
return "PARAMS";
|
||||
|
||||
case ARES_RR_URI_PRIORITY:
|
||||
return "PRIORITY";
|
||||
|
||||
case ARES_RR_URI_WEIGHT:
|
||||
return "WEIGHT";
|
||||
|
||||
case ARES_RR_URI_TARGET:
|
||||
return "TARGET";
|
||||
|
||||
case ARES_RR_CAA_CRITICAL:
|
||||
return "CRITICAL";
|
||||
|
||||
case ARES_RR_CAA_TAG:
|
||||
return "TAG";
|
||||
|
||||
case ARES_RR_CAA_VALUE:
|
||||
return "VALUE";
|
||||
|
||||
case ARES_RR_RAW_RR_TYPE:
|
||||
return "TYPE";
|
||||
|
||||
case ARES_RR_RAW_RR_DATA:
|
||||
return "DATA";
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
ares_dns_datatype_t ares_dns_rr_key_datatype(ares_dns_rr_key_t key)
|
||||
{
|
||||
switch (key) {
|
||||
case ARES_RR_A_ADDR:
|
||||
return ARES_DATATYPE_INADDR;
|
||||
|
||||
case ARES_RR_AAAA_ADDR:
|
||||
return ARES_DATATYPE_INADDR6;
|
||||
|
||||
case ARES_RR_NS_NSDNAME:
|
||||
case ARES_RR_CNAME_CNAME:
|
||||
case ARES_RR_SOA_MNAME:
|
||||
case ARES_RR_SOA_RNAME:
|
||||
case ARES_RR_PTR_DNAME:
|
||||
case ARES_RR_MX_EXCHANGE:
|
||||
case ARES_RR_SRV_TARGET:
|
||||
case ARES_RR_SVCB_TARGET:
|
||||
case ARES_RR_HTTPS_TARGET:
|
||||
case ARES_RR_NAPTR_REPLACEMENT:
|
||||
case ARES_RR_URI_TARGET:
|
||||
return ARES_DATATYPE_NAME;
|
||||
|
||||
case ARES_RR_HINFO_CPU:
|
||||
case ARES_RR_HINFO_OS:
|
||||
case ARES_RR_NAPTR_FLAGS:
|
||||
case ARES_RR_NAPTR_SERVICES:
|
||||
case ARES_RR_NAPTR_REGEXP:
|
||||
case ARES_RR_CAA_TAG:
|
||||
return ARES_DATATYPE_STR;
|
||||
|
||||
case ARES_RR_SOA_SERIAL:
|
||||
case ARES_RR_SOA_REFRESH:
|
||||
case ARES_RR_SOA_RETRY:
|
||||
case ARES_RR_SOA_EXPIRE:
|
||||
case ARES_RR_SOA_MINIMUM:
|
||||
return ARES_DATATYPE_U32;
|
||||
|
||||
case ARES_RR_MX_PREFERENCE:
|
||||
case ARES_RR_SRV_PRIORITY:
|
||||
case ARES_RR_SRV_WEIGHT:
|
||||
case ARES_RR_SRV_PORT:
|
||||
case ARES_RR_NAPTR_ORDER:
|
||||
case ARES_RR_NAPTR_PREFERENCE:
|
||||
case ARES_RR_OPT_UDP_SIZE:
|
||||
case ARES_RR_OPT_FLAGS:
|
||||
case ARES_RR_SVCB_PRIORITY:
|
||||
case ARES_RR_HTTPS_PRIORITY:
|
||||
case ARES_RR_URI_PRIORITY:
|
||||
case ARES_RR_URI_WEIGHT:
|
||||
case ARES_RR_RAW_RR_TYPE:
|
||||
return ARES_DATATYPE_U16;
|
||||
|
||||
case ARES_RR_OPT_VERSION:
|
||||
case ARES_RR_TLSA_CERT_USAGE:
|
||||
case ARES_RR_TLSA_SELECTOR:
|
||||
case ARES_RR_TLSA_MATCH:
|
||||
case ARES_RR_CAA_CRITICAL:
|
||||
return ARES_DATATYPE_U8;
|
||||
|
||||
case ARES_RR_CAA_VALUE:
|
||||
case ARES_RR_TXT_DATA:
|
||||
return ARES_DATATYPE_BINP;
|
||||
|
||||
case ARES_RR_TLSA_DATA:
|
||||
case ARES_RR_RAW_RR_DATA:
|
||||
return ARES_DATATYPE_BIN;
|
||||
|
||||
case ARES_RR_OPT_OPTIONS:
|
||||
case ARES_RR_SVCB_PARAMS:
|
||||
case ARES_RR_HTTPS_PARAMS:
|
||||
return ARES_DATATYPE_OPT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const ares_dns_rr_key_t rr_a_keys[] = { ARES_RR_A_ADDR };
|
||||
static const ares_dns_rr_key_t rr_ns_keys[] = { ARES_RR_NS_NSDNAME };
|
||||
static const ares_dns_rr_key_t rr_cname_keys[] = { ARES_RR_CNAME_CNAME };
|
||||
static const ares_dns_rr_key_t rr_soa_keys[] = {
|
||||
ARES_RR_SOA_MNAME, ARES_RR_SOA_RNAME, ARES_RR_SOA_SERIAL,
|
||||
ARES_RR_SOA_REFRESH, ARES_RR_SOA_RETRY, ARES_RR_SOA_EXPIRE,
|
||||
ARES_RR_SOA_MINIMUM
|
||||
};
|
||||
static const ares_dns_rr_key_t rr_ptr_keys[] = { ARES_RR_PTR_DNAME };
|
||||
static const ares_dns_rr_key_t rr_hinfo_keys[] = { ARES_RR_HINFO_CPU,
|
||||
ARES_RR_HINFO_OS };
|
||||
static const ares_dns_rr_key_t rr_mx_keys[] = { ARES_RR_MX_PREFERENCE,
|
||||
ARES_RR_MX_EXCHANGE };
|
||||
static const ares_dns_rr_key_t rr_txt_keys[] = { ARES_RR_TXT_DATA };
|
||||
static const ares_dns_rr_key_t rr_aaaa_keys[] = { ARES_RR_AAAA_ADDR };
|
||||
static const ares_dns_rr_key_t rr_srv_keys[] = {
|
||||
ARES_RR_SRV_PRIORITY, ARES_RR_SRV_WEIGHT, ARES_RR_SRV_PORT, ARES_RR_SRV_TARGET
|
||||
};
|
||||
static const ares_dns_rr_key_t rr_naptr_keys[] = {
|
||||
ARES_RR_NAPTR_ORDER, ARES_RR_NAPTR_PREFERENCE, ARES_RR_NAPTR_FLAGS,
|
||||
ARES_RR_NAPTR_SERVICES, ARES_RR_NAPTR_REGEXP, ARES_RR_NAPTR_REPLACEMENT
|
||||
};
|
||||
static const ares_dns_rr_key_t rr_opt_keys[] = { ARES_RR_OPT_UDP_SIZE,
|
||||
ARES_RR_OPT_VERSION,
|
||||
ARES_RR_OPT_FLAGS,
|
||||
ARES_RR_OPT_OPTIONS };
|
||||
static const ares_dns_rr_key_t rr_tlsa_keys[] = { ARES_RR_TLSA_CERT_USAGE,
|
||||
ARES_RR_TLSA_SELECTOR,
|
||||
ARES_RR_TLSA_MATCH,
|
||||
ARES_RR_TLSA_DATA };
|
||||
static const ares_dns_rr_key_t rr_svcb_keys[] = { ARES_RR_SVCB_PRIORITY,
|
||||
ARES_RR_SVCB_TARGET,
|
||||
ARES_RR_SVCB_PARAMS };
|
||||
static const ares_dns_rr_key_t rr_https_keys[] = { ARES_RR_HTTPS_PRIORITY,
|
||||
ARES_RR_HTTPS_TARGET,
|
||||
ARES_RR_HTTPS_PARAMS };
|
||||
static const ares_dns_rr_key_t rr_uri_keys[] = { ARES_RR_URI_PRIORITY,
|
||||
ARES_RR_URI_WEIGHT,
|
||||
ARES_RR_URI_TARGET };
|
||||
static const ares_dns_rr_key_t rr_caa_keys[] = { ARES_RR_CAA_CRITICAL,
|
||||
ARES_RR_CAA_TAG,
|
||||
ARES_RR_CAA_VALUE };
|
||||
static const ares_dns_rr_key_t rr_raw_rr_keys[] = { ARES_RR_RAW_RR_TYPE,
|
||||
ARES_RR_RAW_RR_DATA };
|
||||
|
||||
const ares_dns_rr_key_t *ares_dns_rr_get_keys(ares_dns_rec_type_t type,
|
||||
size_t *cnt)
|
||||
{
|
||||
if (cnt == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*cnt = 0;
|
||||
|
||||
switch (type) {
|
||||
case ARES_REC_TYPE_A:
|
||||
*cnt = sizeof(rr_a_keys) / sizeof(*rr_a_keys);
|
||||
return rr_a_keys;
|
||||
case ARES_REC_TYPE_NS:
|
||||
*cnt = sizeof(rr_ns_keys) / sizeof(*rr_ns_keys);
|
||||
return rr_ns_keys;
|
||||
case ARES_REC_TYPE_CNAME:
|
||||
*cnt = sizeof(rr_cname_keys) / sizeof(*rr_cname_keys);
|
||||
return rr_cname_keys;
|
||||
case ARES_REC_TYPE_SOA:
|
||||
*cnt = sizeof(rr_soa_keys) / sizeof(*rr_soa_keys);
|
||||
return rr_soa_keys;
|
||||
case ARES_REC_TYPE_PTR:
|
||||
*cnt = sizeof(rr_ptr_keys) / sizeof(*rr_ptr_keys);
|
||||
return rr_ptr_keys;
|
||||
case ARES_REC_TYPE_HINFO:
|
||||
*cnt = sizeof(rr_hinfo_keys) / sizeof(*rr_hinfo_keys);
|
||||
return rr_hinfo_keys;
|
||||
case ARES_REC_TYPE_MX:
|
||||
*cnt = sizeof(rr_mx_keys) / sizeof(*rr_mx_keys);
|
||||
return rr_mx_keys;
|
||||
case ARES_REC_TYPE_TXT:
|
||||
*cnt = sizeof(rr_txt_keys) / sizeof(*rr_txt_keys);
|
||||
return rr_txt_keys;
|
||||
case ARES_REC_TYPE_AAAA:
|
||||
*cnt = sizeof(rr_aaaa_keys) / sizeof(*rr_aaaa_keys);
|
||||
return rr_aaaa_keys;
|
||||
case ARES_REC_TYPE_SRV:
|
||||
*cnt = sizeof(rr_srv_keys) / sizeof(*rr_srv_keys);
|
||||
return rr_srv_keys;
|
||||
case ARES_REC_TYPE_NAPTR:
|
||||
*cnt = sizeof(rr_naptr_keys) / sizeof(*rr_naptr_keys);
|
||||
return rr_naptr_keys;
|
||||
case ARES_REC_TYPE_OPT:
|
||||
*cnt = sizeof(rr_opt_keys) / sizeof(*rr_opt_keys);
|
||||
return rr_opt_keys;
|
||||
case ARES_REC_TYPE_TLSA:
|
||||
*cnt = sizeof(rr_tlsa_keys) / sizeof(*rr_tlsa_keys);
|
||||
return rr_tlsa_keys;
|
||||
case ARES_REC_TYPE_SVCB:
|
||||
*cnt = sizeof(rr_svcb_keys) / sizeof(*rr_svcb_keys);
|
||||
return rr_svcb_keys;
|
||||
case ARES_REC_TYPE_HTTPS:
|
||||
*cnt = sizeof(rr_https_keys) / sizeof(*rr_https_keys);
|
||||
return rr_https_keys;
|
||||
case ARES_REC_TYPE_ANY:
|
||||
/* Not real */
|
||||
break;
|
||||
case ARES_REC_TYPE_URI:
|
||||
*cnt = sizeof(rr_uri_keys) / sizeof(*rr_uri_keys);
|
||||
return rr_uri_keys;
|
||||
case ARES_REC_TYPE_CAA:
|
||||
*cnt = sizeof(rr_caa_keys) / sizeof(*rr_caa_keys);
|
||||
return rr_caa_keys;
|
||||
case ARES_REC_TYPE_RAW_RR:
|
||||
*cnt = sizeof(rr_raw_rr_keys) / sizeof(*rr_raw_rr_keys);
|
||||
return rr_raw_rr_keys;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_class_fromstr(ares_dns_class_t *qclass, const char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
ares_dns_class_t qclass;
|
||||
} list[] = {
|
||||
{"IN", ARES_CLASS_IN },
|
||||
{ "CH", ARES_CLASS_CHAOS },
|
||||
{ "HS", ARES_CLASS_HESOID},
|
||||
{ "NONE", ARES_CLASS_NONE },
|
||||
{ "ANY", ARES_CLASS_ANY },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
if (qclass == NULL || str == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; list[i].name != NULL; i++) {
|
||||
if (strcasecmp(list[i].name, str) == 0) {
|
||||
*qclass = list[i].qclass;
|
||||
return ARES_TRUE;
|
||||
}
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
ares_bool_t ares_dns_rec_type_fromstr(ares_dns_rec_type_t *qtype,
|
||||
const char *str)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
static const struct {
|
||||
const char *name;
|
||||
ares_dns_rec_type_t type;
|
||||
} list[] = {
|
||||
{"A", ARES_REC_TYPE_A },
|
||||
{ "NS", ARES_REC_TYPE_NS },
|
||||
{ "CNAME", ARES_REC_TYPE_CNAME },
|
||||
{ "SOA", ARES_REC_TYPE_SOA },
|
||||
{ "PTR", ARES_REC_TYPE_PTR },
|
||||
{ "HINFO", ARES_REC_TYPE_HINFO },
|
||||
{ "MX", ARES_REC_TYPE_MX },
|
||||
{ "TXT", ARES_REC_TYPE_TXT },
|
||||
{ "AAAA", ARES_REC_TYPE_AAAA },
|
||||
{ "SRV", ARES_REC_TYPE_SRV },
|
||||
{ "NAPTR", ARES_REC_TYPE_NAPTR },
|
||||
{ "OPT", ARES_REC_TYPE_OPT },
|
||||
{ "TLSA", ARES_REC_TYPE_TLSA },
|
||||
{ "SVCB", ARES_REC_TYPE_SVCB },
|
||||
{ "HTTPS", ARES_REC_TYPE_HTTPS },
|
||||
{ "ANY", ARES_REC_TYPE_ANY },
|
||||
{ "URI", ARES_REC_TYPE_URI },
|
||||
{ "CAA", ARES_REC_TYPE_CAA },
|
||||
{ "RAW_RR", ARES_REC_TYPE_RAW_RR},
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
if (qtype == NULL || str == NULL) {
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; list[i].name != NULL; i++) {
|
||||
if (strcasecmp(list[i].name, str) == 0) {
|
||||
*qtype = list[i].type;
|
||||
return ARES_TRUE;
|
||||
}
|
||||
}
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
const char *ares_dns_section_tostr(ares_dns_section_t section)
|
||||
{
|
||||
switch (section) {
|
||||
case ARES_SECTION_ANSWER:
|
||||
return "ANSWER";
|
||||
case ARES_SECTION_AUTHORITY:
|
||||
return "AUTHORITY";
|
||||
case ARES_SECTION_ADDITIONAL:
|
||||
return "ADDITIONAL";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
static ares_dns_opt_datatype_t ares_dns_opt_get_type_opt(unsigned short opt)
|
||||
{
|
||||
ares_opt_param_t param = (ares_opt_param_t)opt;
|
||||
switch (param) {
|
||||
case ARES_OPT_PARAM_LLQ:
|
||||
/* Really it is u16 version, u16 opcode, u16 error, u64 id, u32 lease */
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
case ARES_OPT_PARAM_UL:
|
||||
return ARES_OPT_DATATYPE_U32;
|
||||
case ARES_OPT_PARAM_NSID:
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
case ARES_OPT_PARAM_DAU:
|
||||
return ARES_OPT_DATATYPE_U8_LIST;
|
||||
case ARES_OPT_PARAM_DHU:
|
||||
return ARES_OPT_DATATYPE_U8_LIST;
|
||||
case ARES_OPT_PARAM_N3U:
|
||||
return ARES_OPT_DATATYPE_U8_LIST;
|
||||
case ARES_OPT_PARAM_EDNS_CLIENT_SUBNET:
|
||||
/* Really it is a u16 address family, u8 source prefix length,
|
||||
* u8 scope prefix length, address */
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
case ARES_OPT_PARAM_EDNS_EXPIRE:
|
||||
return ARES_OPT_DATATYPE_U32;
|
||||
case ARES_OPT_PARAM_COOKIE:
|
||||
/* 8 bytes for client, 16-40 bytes for server */
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
case ARES_OPT_PARAM_EDNS_TCP_KEEPALIVE:
|
||||
/* Timeout in 100ms intervals */
|
||||
return ARES_OPT_DATATYPE_U16;
|
||||
case ARES_OPT_PARAM_PADDING:
|
||||
/* Arbitrary padding */
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
case ARES_OPT_PARAM_CHAIN:
|
||||
return ARES_OPT_DATATYPE_NAME;
|
||||
case ARES_OPT_PARAM_EDNS_KEY_TAG:
|
||||
return ARES_OPT_DATATYPE_U16_LIST;
|
||||
case ARES_OPT_PARAM_EXTENDED_DNS_ERROR:
|
||||
/* Really 16bit code followed by textual message */
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
}
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
}
|
||||
|
||||
static ares_dns_opt_datatype_t ares_dns_opt_get_type_svcb(unsigned short opt)
|
||||
{
|
||||
ares_svcb_param_t param = (ares_svcb_param_t)opt;
|
||||
switch (param) {
|
||||
case ARES_SVCB_PARAM_NO_DEFAULT_ALPN:
|
||||
return ARES_OPT_DATATYPE_NONE;
|
||||
case ARES_SVCB_PARAM_ECH:
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
case ARES_SVCB_PARAM_MANDATORY:
|
||||
return ARES_OPT_DATATYPE_U16_LIST;
|
||||
case ARES_SVCB_PARAM_ALPN:
|
||||
return ARES_OPT_DATATYPE_STR_LIST;
|
||||
case ARES_SVCB_PARAM_PORT:
|
||||
return ARES_OPT_DATATYPE_U16;
|
||||
case ARES_SVCB_PARAM_IPV4HINT:
|
||||
return ARES_OPT_DATATYPE_INADDR4_LIST;
|
||||
case ARES_SVCB_PARAM_IPV6HINT:
|
||||
return ARES_OPT_DATATYPE_INADDR6_LIST;
|
||||
}
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
}
|
||||
|
||||
ares_dns_opt_datatype_t ares_dns_opt_get_datatype(ares_dns_rr_key_t key,
|
||||
unsigned short opt)
|
||||
{
|
||||
switch (key) {
|
||||
case ARES_RR_OPT_OPTIONS:
|
||||
return ares_dns_opt_get_type_opt(opt);
|
||||
case ARES_RR_SVCB_PARAMS:
|
||||
case ARES_RR_HTTPS_PARAMS:
|
||||
return ares_dns_opt_get_type_svcb(opt);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ARES_OPT_DATATYPE_BIN;
|
||||
}
|
||||
|
||||
static const char *ares_dns_opt_get_name_opt(unsigned short opt)
|
||||
{
|
||||
ares_opt_param_t param = (ares_opt_param_t)opt;
|
||||
switch (param) {
|
||||
case ARES_OPT_PARAM_LLQ:
|
||||
return "LLQ";
|
||||
case ARES_OPT_PARAM_UL:
|
||||
return "UL";
|
||||
case ARES_OPT_PARAM_NSID:
|
||||
return "NSID";
|
||||
case ARES_OPT_PARAM_DAU:
|
||||
return "DAU";
|
||||
case ARES_OPT_PARAM_DHU:
|
||||
return "DHU";
|
||||
case ARES_OPT_PARAM_N3U:
|
||||
return "N3U";
|
||||
case ARES_OPT_PARAM_EDNS_CLIENT_SUBNET:
|
||||
return "edns-client-subnet";
|
||||
case ARES_OPT_PARAM_EDNS_EXPIRE:
|
||||
return "edns-expire";
|
||||
case ARES_OPT_PARAM_COOKIE:
|
||||
return "COOKIE";
|
||||
case ARES_OPT_PARAM_EDNS_TCP_KEEPALIVE:
|
||||
return "edns-tcp-keepalive";
|
||||
case ARES_OPT_PARAM_PADDING:
|
||||
return "Padding";
|
||||
case ARES_OPT_PARAM_CHAIN:
|
||||
return "CHAIN";
|
||||
case ARES_OPT_PARAM_EDNS_KEY_TAG:
|
||||
return "edns-key-tag";
|
||||
case ARES_OPT_PARAM_EXTENDED_DNS_ERROR:
|
||||
return "extended-dns-error";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *ares_dns_opt_get_name_svcb(unsigned short opt)
|
||||
{
|
||||
ares_svcb_param_t param = (ares_svcb_param_t)opt;
|
||||
switch (param) {
|
||||
case ARES_SVCB_PARAM_NO_DEFAULT_ALPN:
|
||||
return "no-default-alpn";
|
||||
case ARES_SVCB_PARAM_ECH:
|
||||
return "ech";
|
||||
case ARES_SVCB_PARAM_MANDATORY:
|
||||
return "mandatory";
|
||||
case ARES_SVCB_PARAM_ALPN:
|
||||
return "alpn";
|
||||
case ARES_SVCB_PARAM_PORT:
|
||||
return "port";
|
||||
case ARES_SVCB_PARAM_IPV4HINT:
|
||||
return "ipv4hint";
|
||||
case ARES_SVCB_PARAM_IPV6HINT:
|
||||
return "ipv6hint";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *ares_dns_opt_get_name(ares_dns_rr_key_t key, unsigned short opt)
|
||||
{
|
||||
switch (key) {
|
||||
case ARES_RR_OPT_OPTIONS:
|
||||
return ares_dns_opt_get_name_opt(opt);
|
||||
case ARES_RR_SVCB_PARAMS:
|
||||
case ARES_RR_HTTPS_PARAMS:
|
||||
return ares_dns_opt_get_name_svcb(opt);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *ares_dns_rcode_tostr(ares_dns_rcode_t rcode)
|
||||
{
|
||||
switch (rcode) {
|
||||
case ARES_RCODE_NOERROR:
|
||||
return "NOERROR";
|
||||
case ARES_RCODE_FORMERR:
|
||||
return "FORMERR";
|
||||
case ARES_RCODE_SERVFAIL:
|
||||
return "SERVFAIL";
|
||||
case ARES_RCODE_NXDOMAIN:
|
||||
return "NXDOMAIN";
|
||||
case ARES_RCODE_NOTIMP:
|
||||
return "NOTIMP";
|
||||
case ARES_RCODE_REFUSED:
|
||||
return "REFUSED";
|
||||
case ARES_RCODE_YXDOMAIN:
|
||||
return "YXDOMAIN";
|
||||
case ARES_RCODE_YXRRSET:
|
||||
return "YXRRSET";
|
||||
case ARES_RCODE_NXRRSET:
|
||||
return "NXRRSET";
|
||||
case ARES_RCODE_NOTAUTH:
|
||||
return "NOTAUTH";
|
||||
case ARES_RCODE_NOTZONE:
|
||||
return "NOTZONE";
|
||||
case ARES_RCODE_DSOTYPEI:
|
||||
return "DSOTYPEI";
|
||||
case ARES_RCODE_BADSIG:
|
||||
return "BADSIG";
|
||||
case ARES_RCODE_BADKEY:
|
||||
return "BADKEY";
|
||||
case ARES_RCODE_BADTIME:
|
||||
return "BADTIME";
|
||||
case ARES_RCODE_BADMODE:
|
||||
return "BADMODE";
|
||||
case ARES_RCODE_BADNAME:
|
||||
return "BADNAME";
|
||||
case ARES_RCODE_BADALG:
|
||||
return "BADALG";
|
||||
case ARES_RCODE_BADTRUNC:
|
||||
return "BADTRUNC";
|
||||
case ARES_RCODE_BADCOOKIE:
|
||||
return "BADCOOKIE";
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
676
src/third_party/cares/dist/src/lib/ares_dns_name.c
vendored
Normal file
676
src/third_party/cares/dist/src/lib/ares_dns_name.c
vendored
Normal file
@ -0,0 +1,676 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#include "ares_setup.h"
|
||||
#include "ares.h"
|
||||
#include "ares_private.h"
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
size_t name_len;
|
||||
size_t idx;
|
||||
} ares_nameoffset_t;
|
||||
|
||||
static void ares__nameoffset_free(void *arg)
|
||||
{
|
||||
ares_nameoffset_t *off = arg;
|
||||
if (off == NULL) {
|
||||
return;
|
||||
}
|
||||
ares_free(off->name);
|
||||
ares_free(off);
|
||||
}
|
||||
|
||||
static ares_status_t ares__nameoffset_create(ares__llist_t **list,
|
||||
const char *name, size_t idx)
|
||||
{
|
||||
ares_status_t status;
|
||||
ares_nameoffset_t *off = NULL;
|
||||
|
||||
if (list == NULL || name == NULL || ares_strlen(name) == 0 ||
|
||||
ares_strlen(name) > 255) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
if (*list == NULL) {
|
||||
*list = ares__llist_create(ares__nameoffset_free);
|
||||
}
|
||||
if (*list == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
off = ares_malloc_zero(sizeof(*off));
|
||||
if (off == NULL) {
|
||||
return ARES_ENOMEM;
|
||||
}
|
||||
|
||||
off->name = ares_strdup(name);
|
||||
off->name_len = ares_strlen(off->name);
|
||||
off->idx = idx;
|
||||
|
||||
if (ares__llist_insert_last(*list, off) == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
|
||||
fail:
|
||||
ares__nameoffset_free(off);
|
||||
return status;
|
||||
}
|
||||
|
||||
static const ares_nameoffset_t *ares__nameoffset_find(ares__llist_t *list,
|
||||
const char *name)
|
||||
{
|
||||
size_t name_len = ares_strlen(name);
|
||||
ares__llist_node_t *node;
|
||||
const ares_nameoffset_t *longest_match = NULL;
|
||||
|
||||
if (list == NULL || name == NULL || name_len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (node = ares__llist_node_first(list); node != NULL;
|
||||
node = ares__llist_node_next(node)) {
|
||||
const ares_nameoffset_t *val = ares__llist_node_val(node);
|
||||
size_t prefix_len;
|
||||
|
||||
/* Can't be a match if the stored name is longer */
|
||||
if (val->name_len > name_len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Can't be the longest match if our existing longest match is longer */
|
||||
if (longest_match != NULL && longest_match->name_len > val->name_len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
prefix_len = name_len - val->name_len;
|
||||
|
||||
if (strcasecmp(val->name, name + prefix_len) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* We need to make sure if `val->name` is "example.com" that name is
|
||||
* is separated by a label, e.g. "myexample.com" is not ok, however
|
||||
* "my.example.com" is, so we look for the preceding "." */
|
||||
if (prefix_len != 0 && name[prefix_len - 1] != '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
longest_match = val;
|
||||
}
|
||||
|
||||
return longest_match;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ares__buf_t **label;
|
||||
size_t num;
|
||||
} ares_dns_labels_t;
|
||||
|
||||
static void ares_dns_labels_free(ares_dns_labels_t *labels)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (labels == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < labels->num; i++) {
|
||||
ares__buf_destroy(labels->label[i]);
|
||||
labels->label[i] = NULL;
|
||||
}
|
||||
ares_free(labels->label);
|
||||
labels->label = NULL;
|
||||
labels->num = 0;
|
||||
}
|
||||
|
||||
static ares__buf_t *ares_dns_labels_add(ares_dns_labels_t *labels)
|
||||
{
|
||||
void *temp;
|
||||
|
||||
if (labels == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
temp = ares_realloc_zero(labels->label, sizeof(*labels->label) * labels->num,
|
||||
sizeof(*labels->label) * (labels->num + 1));
|
||||
if (temp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
labels->label = temp;
|
||||
|
||||
labels->label[labels->num] = ares__buf_create();
|
||||
if (labels->label[labels->num] == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
labels->num++;
|
||||
return labels->label[labels->num - 1];
|
||||
}
|
||||
|
||||
static const ares__buf_t *
|
||||
ares_dns_labels_get_last(const ares_dns_labels_t *labels)
|
||||
{
|
||||
if (labels == NULL || labels->num == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return labels->label[labels->num - 1];
|
||||
}
|
||||
|
||||
static void ares_dns_name_labels_del_last(ares_dns_labels_t *labels)
|
||||
{
|
||||
if (labels == NULL || labels->num == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ares__buf_destroy(labels->label[labels->num - 1]);
|
||||
labels->label[labels->num - 1] = NULL;
|
||||
labels->num--;
|
||||
}
|
||||
|
||||
static ares_status_t ares_parse_dns_name_escape(ares__buf_t *namebuf,
|
||||
ares__buf_t *label,
|
||||
ares_bool_t validate_hostname)
|
||||
{
|
||||
ares_status_t status;
|
||||
unsigned char c;
|
||||
|
||||
status = ares__buf_fetch_bytes(namebuf, &c, 1);
|
||||
if (status != ARES_SUCCESS) {
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
|
||||
/* If next character is a digit, read 2 more digits */
|
||||
if (isdigit(c)) {
|
||||
size_t i;
|
||||
unsigned int val = 0;
|
||||
|
||||
val = c - '0';
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
status = ares__buf_fetch_bytes(namebuf, &c, 1);
|
||||
if (status != ARES_SUCCESS) {
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
|
||||
if (!isdigit(c)) {
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
val *= 10;
|
||||
val += c - '0';
|
||||
}
|
||||
|
||||
/* Out of range */
|
||||
if (val > 255) {
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
|
||||
if (validate_hostname && !ares__is_hostnamech((unsigned char)val)) {
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
|
||||
return ares__buf_append_byte(label, (unsigned char)val);
|
||||
}
|
||||
|
||||
/* We can just output the character */
|
||||
if (validate_hostname && !ares__is_hostnamech(c)) {
|
||||
return ARES_EBADNAME;
|
||||
}
|
||||
|
||||
return ares__buf_append_byte(label, c);
|
||||
}
|
||||
|
||||
static ares_status_t ares_split_dns_name(ares_dns_labels_t *labels,
|
||||
ares_bool_t validate_hostname,
|
||||
const char *name)
|
||||
{
|
||||
ares_status_t status;
|
||||
ares__buf_t *label = NULL;
|
||||
ares__buf_t *namebuf = NULL;
|
||||
size_t i;
|
||||
size_t total_len = 0;
|
||||
unsigned char c;
|
||||
|
||||
if (name == NULL || labels == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
/* Put name into a buffer for parsing */
|
||||
namebuf = ares__buf_create();
|
||||
if (namebuf == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (*name != '\0') {
|
||||
status =
|
||||
ares__buf_append(namebuf, (const unsigned char *)name, ares_strlen(name));
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start with 1 label */
|
||||
label = ares_dns_labels_add(labels);
|
||||
if (label == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
while (ares__buf_fetch_bytes(namebuf, &c, 1) == ARES_SUCCESS) {
|
||||
/* New label */
|
||||
if (c == '.') {
|
||||
label = ares_dns_labels_add(labels);
|
||||
if (label == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Escape */
|
||||
if (c == '\\') {
|
||||
status = ares_parse_dns_name_escape(namebuf, label, validate_hostname);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Output direct character */
|
||||
if (validate_hostname && !ares__is_hostnamech(c)) {
|
||||
status = ARES_EBADNAME;
|
||||
goto done;
|
||||
}
|
||||
|
||||
status = ares__buf_append_byte(label, c);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove trailing blank label */
|
||||
if (ares__buf_len(ares_dns_labels_get_last(labels)) == 0) {
|
||||
ares_dns_name_labels_del_last(labels);
|
||||
}
|
||||
|
||||
/* If someone passed in "." there could have been 2 blank labels, check for
|
||||
* that */
|
||||
if (labels->num == 1 &&
|
||||
ares__buf_len(ares_dns_labels_get_last(labels)) == 0) {
|
||||
ares_dns_name_labels_del_last(labels);
|
||||
}
|
||||
|
||||
/* Scan to make sure label lengths are valid */
|
||||
for (i = 0; i < labels->num; i++) {
|
||||
size_t len = ares__buf_len(labels->label[i]);
|
||||
/* No 0-length labels, and no labels over 63 bytes */
|
||||
if (len == 0 || len > 63) {
|
||||
status = ARES_EBADNAME;
|
||||
goto done;
|
||||
}
|
||||
total_len += len;
|
||||
}
|
||||
|
||||
/* Can't exceed maximum (unescaped) length */
|
||||
if (labels->num && total_len + labels->num - 1 > 255) {
|
||||
status = ARES_EBADNAME;
|
||||
goto done;
|
||||
}
|
||||
|
||||
status = ARES_SUCCESS;
|
||||
|
||||
done:
|
||||
ares__buf_destroy(namebuf);
|
||||
if (status != ARES_SUCCESS) {
|
||||
ares_dns_labels_free(labels);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ares_status_t ares__dns_name_write(ares__buf_t *buf, ares__llist_t **list,
|
||||
ares_bool_t validate_hostname,
|
||||
const char *name)
|
||||
{
|
||||
const ares_nameoffset_t *off = NULL;
|
||||
size_t name_len;
|
||||
size_t pos = ares__buf_len(buf);
|
||||
ares_dns_labels_t labels;
|
||||
char name_copy[512];
|
||||
ares_status_t status;
|
||||
|
||||
if (buf == NULL || name == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
memset(&labels, 0, sizeof(labels));
|
||||
|
||||
/* NOTE: due to possible escaping, name_copy buffer is > 256 to allow for
|
||||
* this */
|
||||
name_len = ares_strcpy(name_copy, name, sizeof(name_copy));
|
||||
|
||||
/* Find longest match */
|
||||
if (list != NULL) {
|
||||
off = ares__nameoffset_find(*list, name_copy);
|
||||
if (off != NULL && off->name_len != name_len) {
|
||||
/* truncate */
|
||||
name_len -= (off->name_len + 1);
|
||||
name_copy[name_len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Output labels */
|
||||
if (off == NULL || off->name_len != name_len) {
|
||||
size_t i;
|
||||
|
||||
status = ares_split_dns_name(&labels, validate_hostname, name_copy);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < labels.num; i++) {
|
||||
size_t len = 0;
|
||||
const unsigned char *ptr = ares__buf_peek(labels.label[i], &len);
|
||||
|
||||
status = ares__buf_append_byte(buf, (unsigned char)(len & 0xFF));
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
status = ares__buf_append(buf, ptr, len);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we are NOT jumping to another label, output terminator */
|
||||
if (off == NULL) {
|
||||
status = ares__buf_append_byte(buf, 0);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Output name compression offset jump */
|
||||
if (off != NULL) {
|
||||
unsigned short u16 =
|
||||
(unsigned short)0xC000 | (unsigned short)(off->idx & 0x3FFF);
|
||||
status = ares__buf_append_be16(buf, u16);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Store pointer for future jumps as long as its not an exact match for
|
||||
* a prior entry */
|
||||
if (list != NULL && (off == NULL || off->name_len != name_len) &&
|
||||
name_len > 0) {
|
||||
status = ares__nameoffset_create(list, name /* not truncated copy! */, pos);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
status = ARES_SUCCESS;
|
||||
|
||||
done:
|
||||
ares_dns_labels_free(&labels);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Reserved characters for names that need to be escaped */
|
||||
static ares_bool_t is_reservedch(int ch)
|
||||
{
|
||||
switch (ch) {
|
||||
case '"':
|
||||
case '.':
|
||||
case ';':
|
||||
case '\\':
|
||||
case '(':
|
||||
case ')':
|
||||
case '@':
|
||||
case '$':
|
||||
return ARES_TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ARES_FALSE;
|
||||
}
|
||||
|
||||
static ares_status_t ares__fetch_dnsname_into_buf(ares__buf_t *buf,
|
||||
ares__buf_t *dest, size_t len,
|
||||
ares_bool_t is_hostname)
|
||||
{
|
||||
size_t remaining_len;
|
||||
const unsigned char *ptr = ares__buf_peek(buf, &remaining_len);
|
||||
ares_status_t status;
|
||||
size_t i;
|
||||
|
||||
if (buf == NULL || len == 0 || remaining_len < len) {
|
||||
return ARES_EBADRESP;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
unsigned char c = ptr[i];
|
||||
|
||||
/* Hostnames have a very specific allowed character set. Anything outside
|
||||
* of that (non-printable and reserved included) are disallowed */
|
||||
if (is_hostname && !ares__is_hostnamech(c)) {
|
||||
status = ARES_EBADRESP;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* NOTE: dest may be NULL if the user is trying to skip the name. validation
|
||||
* still occurs above. */
|
||||
if (dest == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Non-printable characters need to be output as \DDD */
|
||||
if (!ares__isprint(c)) {
|
||||
unsigned char escape[4];
|
||||
|
||||
escape[0] = '\\';
|
||||
escape[1] = '0' + (c / 100);
|
||||
escape[2] = '0' + ((c % 100) / 10);
|
||||
escape[3] = '0' + (c % 10);
|
||||
|
||||
status = ares__buf_append(dest, escape, sizeof(escape));
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Reserved characters need to be escaped, otherwise normal */
|
||||
if (is_reservedch(c)) {
|
||||
status = ares__buf_append_byte(dest, '\\');
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
status = ares__buf_append_byte(dest, c);
|
||||
if (status != ARES_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return ares__buf_consume(buf, len);
|
||||
|
||||
fail:
|
||||
return status;
|
||||
}
|
||||
|
||||
ares_status_t ares__dns_name_parse(ares__buf_t *buf, char **name,
|
||||
ares_bool_t is_hostname)
|
||||
{
|
||||
size_t save_offset = 0;
|
||||
unsigned char c;
|
||||
ares_status_t status;
|
||||
ares__buf_t *namebuf = NULL;
|
||||
size_t label_start = ares__buf_get_position(buf);
|
||||
|
||||
if (buf == NULL) {
|
||||
return ARES_EFORMERR;
|
||||
}
|
||||
|
||||
if (name != NULL) {
|
||||
namebuf = ares__buf_create();
|
||||
if (namebuf == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* The compression scheme allows a domain name in a message to be
|
||||
* represented as either:
|
||||
*
|
||||
* - a sequence of labels ending in a zero octet
|
||||
* - a pointer
|
||||
* - a sequence of labels ending with a pointer
|
||||
*/
|
||||
while (1) {
|
||||
/* Keep track of the minimum label starting position to prevent forward
|
||||
* jumping */
|
||||
if (label_start > ares__buf_get_position(buf)) {
|
||||
label_start = ares__buf_get_position(buf);
|
||||
}
|
||||
|
||||
status = ares__buf_fetch_bytes(buf, &c, 1);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Pointer/Redirect */
|
||||
if ((c & 0xc0) == 0xc0) {
|
||||
/* The pointer takes the form of a two octet sequence:
|
||||
*
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | 1 1| OFFSET |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* The first two bits are ones. This allows a pointer to be distinguished
|
||||
* from a label, since the label must begin with two zero bits because
|
||||
* labels are restricted to 63 octets or less. (The 10 and 01
|
||||
* combinations are reserved for future use.) The OFFSET field specifies
|
||||
* an offset from the start of the message (i.e., the first octet of the
|
||||
* ID field in the domain header). A zero offset specifies the first byte
|
||||
* of the ID field, etc.
|
||||
*/
|
||||
size_t offset = (size_t)((c & 0x3F) << 8);
|
||||
|
||||
/* Fetch second byte of the redirect length */
|
||||
status = ares__buf_fetch_bytes(buf, &c, 1);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
offset |= ((size_t)c);
|
||||
|
||||
/* According to RFC 1035 4.1.4:
|
||||
* In this scheme, an entire domain name or a list of labels at
|
||||
* the end of a domain name is replaced with a pointer to a prior
|
||||
* occurrence of the same name.
|
||||
* Note the word "prior", meaning it must go backwards. This was
|
||||
* confirmed via the ISC BIND code that it also prevents forward
|
||||
* pointers.
|
||||
*/
|
||||
if (offset >= label_start) {
|
||||
status = ARES_EBADNAME;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* First time we make a jump, save the current position */
|
||||
if (save_offset == 0) {
|
||||
save_offset = ares__buf_get_position(buf);
|
||||
}
|
||||
|
||||
status = ares__buf_set_position(buf, offset);
|
||||
if (status != ARES_SUCCESS) {
|
||||
status = ARES_EBADNAME;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
continue;
|
||||
} else if ((c & 0xc0) != 0) {
|
||||
/* 10 and 01 are reserved */
|
||||
status = ARES_EBADNAME;
|
||||
goto fail;
|
||||
} else if (c == 0) {
|
||||
/* termination via zero octet*/
|
||||
break;
|
||||
}
|
||||
|
||||
/* New label */
|
||||
|
||||
/* Labels are separated by periods */
|
||||
if (ares__buf_len(namebuf) != 0 && name != NULL) {
|
||||
status = ares__buf_append_byte(namebuf, '.');
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
status = ares__fetch_dnsname_into_buf(buf, namebuf, c, is_hostname);
|
||||
if (status != ARES_SUCCESS) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restore offset read after first redirect/pointer as this is where the DNS
|
||||
* message continues */
|
||||
if (save_offset) {
|
||||
ares__buf_set_position(buf, save_offset);
|
||||
}
|
||||
|
||||
if (name != NULL) {
|
||||
*name = ares__buf_finish_str(namebuf, NULL);
|
||||
if (*name == NULL) {
|
||||
status = ARES_ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return ARES_SUCCESS;
|
||||
|
||||
fail:
|
||||
/* We want badname response if we couldn't parse */
|
||||
if (status == ARES_EBADRESP) {
|
||||
status = ARES_EBADNAME;
|
||||
}
|
||||
|
||||
ares__buf_destroy(namebuf);
|
||||
return status;
|
||||
}
|
||||
1255
src/third_party/cares/dist/src/lib/ares_dns_parse.c
vendored
Normal file
1255
src/third_party/cares/dist/src/lib/ares_dns_parse.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
236
src/third_party/cares/dist/src/lib/ares_dns_private.h
vendored
Normal file
236
src/third_party/cares/dist/src/lib/ares_dns_private.h
vendored
Normal file
@ -0,0 +1,236 @@
|
||||
/* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Brad House
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
#ifndef __ARES_DNS_PRIVATE_H
|
||||
#define __ARES_DNS_PRIVATE_H
|
||||
|
||||
ares_bool_t ares_dns_rec_type_allow_name_compression(ares_dns_rec_type_t type);
|
||||
ares_bool_t ares_dns_opcode_isvalid(ares_dns_opcode_t opcode);
|
||||
ares_bool_t ares_dns_rcode_isvalid(ares_dns_rcode_t rcode);
|
||||
ares_bool_t ares_dns_flags_arevalid(unsigned short flags);
|
||||
ares_bool_t ares_dns_rec_type_isvalid(ares_dns_rec_type_t type,
|
||||
ares_bool_t is_query);
|
||||
ares_bool_t ares_dns_class_isvalid(ares_dns_class_t qclass,
|
||||
ares_bool_t is_query);
|
||||
ares_bool_t ares_dns_section_isvalid(ares_dns_section_t sect);
|
||||
ares_status_t ares_dns_rr_set_str_own(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key, char *val);
|
||||
ares_status_t ares_dns_rr_set_bin_own(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key, unsigned char *val,
|
||||
size_t len);
|
||||
ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
|
||||
ares_dns_rr_key_t key, unsigned short opt,
|
||||
unsigned char *val, size_t val_len);
|
||||
ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
|
||||
ares_dns_section_t sect, size_t cnt);
|
||||
ares_bool_t ares_dns_has_opt_rr(const ares_dns_record_t *rec);
|
||||
void ares_dns_record_write_ttl_decrement(ares_dns_record_t *dnsrec,
|
||||
unsigned int ttl_decrement);
|
||||
|
||||
struct ares_dns_qd {
|
||||
char *name;
|
||||
ares_dns_rec_type_t qtype;
|
||||
ares_dns_class_t qclass;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct in_addr addr;
|
||||
} ares__dns_a_t;
|
||||
|
||||
typedef struct {
|
||||
char *nsdname;
|
||||
} ares__dns_ns_t;
|
||||
|
||||
typedef struct {
|
||||
char *cname;
|
||||
} ares__dns_cname_t;
|
||||
|
||||
typedef struct {
|
||||
char *mname;
|
||||
char *rname;
|
||||
unsigned int serial;
|
||||
unsigned int refresh;
|
||||
unsigned int retry;
|
||||
unsigned int expire;
|
||||
unsigned int minimum;
|
||||
} ares__dns_soa_t;
|
||||
|
||||
typedef struct {
|
||||
char *dname;
|
||||
} ares__dns_ptr_t;
|
||||
|
||||
typedef struct {
|
||||
char *cpu;
|
||||
char *os;
|
||||
} ares__dns_hinfo_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short preference;
|
||||
char *exchange;
|
||||
} ares__dns_mx_t;
|
||||
|
||||
typedef struct {
|
||||
char *data;
|
||||
size_t data_len;
|
||||
} ares__dns_txt_t;
|
||||
|
||||
typedef struct {
|
||||
struct ares_in6_addr addr;
|
||||
} ares__dns_aaaa_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short priority;
|
||||
unsigned short weight;
|
||||
unsigned short port;
|
||||
char *target;
|
||||
} ares__dns_srv_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short order;
|
||||
unsigned short preference;
|
||||
char *flags;
|
||||
char *services;
|
||||
char *regexp;
|
||||
char *replacement;
|
||||
} ares__dns_naptr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short opt;
|
||||
unsigned char *val;
|
||||
size_t val_len;
|
||||
} ares__dns_optval_t;
|
||||
|
||||
typedef struct {
|
||||
ares__dns_optval_t *optval; /*!< Attribute/value pairs */
|
||||
size_t cnt; /*!< Count of Attribute/Value pairs */
|
||||
size_t alloc; /*!< Allocated count of attribute/value
|
||||
* pairs */
|
||||
} ares__dns_options_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short udp_size; /*!< taken from class */
|
||||
unsigned char version; /*!< taken from bits 8-16 of ttl */
|
||||
unsigned short flags; /*!< Flags, remaining 16 bits, though only
|
||||
* 1 currently defined */
|
||||
ares__dns_options_t *options; /*!< Attribute/Value pairs */
|
||||
} ares__dns_opt_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char cert_usage;
|
||||
unsigned char selector;
|
||||
unsigned char match;
|
||||
unsigned char *data;
|
||||
size_t data_len;
|
||||
} ares__dns_tlsa_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short priority;
|
||||
char *target;
|
||||
ares__dns_options_t *params;
|
||||
} ares__dns_svcb_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned short priority;
|
||||
unsigned short weight;
|
||||
char *target;
|
||||
} ares__dns_uri_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char critical;
|
||||
char *tag;
|
||||
unsigned char *value;
|
||||
size_t value_len;
|
||||
} ares__dns_caa_t;
|
||||
|
||||
/*! Raw, unparsed RR data */
|
||||
typedef struct {
|
||||
unsigned short type; /*!< Not ares_rec_type_t because it likely isn't one
|
||||
* of those values since it wasn't parsed */
|
||||
unsigned char *data; /*!< Raw RR data */
|
||||
size_t length; /*!< Length of raw RR data */
|
||||
} ares__dns_raw_rr_t;
|
||||
|
||||
/*! DNS RR data structure */
|
||||
struct ares_dns_rr {
|
||||
ares_dns_record_t *parent;
|
||||
char *name;
|
||||
ares_dns_rec_type_t type;
|
||||
ares_dns_class_t rclass;
|
||||
unsigned int ttl;
|
||||
|
||||
union {
|
||||
ares__dns_a_t a;
|
||||
ares__dns_ns_t ns;
|
||||
ares__dns_cname_t cname;
|
||||
ares__dns_soa_t soa;
|
||||
ares__dns_ptr_t ptr;
|
||||
ares__dns_hinfo_t hinfo;
|
||||
ares__dns_mx_t mx;
|
||||
ares__dns_txt_t txt;
|
||||
ares__dns_aaaa_t aaaa;
|
||||
ares__dns_srv_t srv;
|
||||
ares__dns_naptr_t naptr;
|
||||
ares__dns_opt_t opt;
|
||||
ares__dns_tlsa_t tlsa;
|
||||
ares__dns_svcb_t svcb;
|
||||
ares__dns_svcb_t https; /*!< https is a type of svcb, so this is right */
|
||||
ares__dns_uri_t uri;
|
||||
ares__dns_caa_t caa;
|
||||
ares__dns_raw_rr_t raw_rr;
|
||||
} r;
|
||||
};
|
||||
|
||||
/*! DNS data structure */
|
||||
struct ares_dns_record {
|
||||
unsigned short id; /*!< DNS query id */
|
||||
unsigned short flags; /*!< One or more ares_dns_flags_t */
|
||||
ares_dns_opcode_t opcode; /*!< DNS Opcode */
|
||||
ares_dns_rcode_t rcode; /*!< DNS RCODE */
|
||||
unsigned short raw_rcode; /*!< Raw rcode, used to ultimately form real
|
||||
* rcode after reading OPT record if it
|
||||
* exists */
|
||||
unsigned int ttl_decrement; /*!< Special case to apply to writing out
|
||||
* this record, where it will decrement
|
||||
* the ttl of any resource records by
|
||||
* this amount. Used for cache */
|
||||
|
||||
ares_dns_qd_t *qd;
|
||||
size_t qdcount;
|
||||
size_t qdalloc;
|
||||
|
||||
ares_dns_rr_t *an;
|
||||
size_t ancount;
|
||||
size_t analloc;
|
||||
|
||||
ares_dns_rr_t *ns;
|
||||
size_t nscount;
|
||||
size_t nsalloc;
|
||||
|
||||
ares_dns_rr_t *ar;
|
||||
size_t arcount;
|
||||
size_t aralloc;
|
||||
};
|
||||
|
||||
#endif
|
||||
1316
src/third_party/cares/dist/src/lib/ares_dns_record.c
vendored
Normal file
1316
src/third_party/cares/dist/src/lib/ares_dns_record.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user