visaljs 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +12 -4
  2. package/THIRD_PARTY_LICENSES +31 -1
  3. package/cli.js +962 -68
  4. package/node/include/js_node.h +11 -1
  5. package/node/prelude/_http_common.js +29 -0
  6. package/node/prelude/async_hooks.js +50 -11
  7. package/node/prelude/child_process.js +31 -4
  8. package/node/prelude/console.js +311 -143
  9. package/node/prelude/crypto.js +6 -4
  10. package/node/prelude/dgram.js +1169 -0
  11. package/node/prelude/diagnostics_channel.js +3 -1
  12. package/node/prelude/dns.js +250 -45
  13. package/node/prelude/dns_promises.js +8 -2
  14. package/node/prelude/fs_promises.js +9 -1
  15. package/node/prelude/http.js +395 -86
  16. package/node/prelude/https.js +13 -4
  17. package/node/prelude/internal/console_class.js +7 -0
  18. package/node/prelude/internal/console_global.js +25 -0
  19. package/node/prelude/internal/crypto/key_encryption.js +217 -0
  20. package/node/prelude/internal/crypto/keys.js +161 -26
  21. package/node/prelude/internal/crypto/random.js +24 -0
  22. package/node/prelude/internal/crypto/util.js +2 -1
  23. package/node/prelude/internal/crypto_x509.js +161 -0
  24. package/node/prelude/internal/dns_classes.js +6 -0
  25. package/node/prelude/internal/dns_resolver.js +371 -0
  26. package/node/prelude/internal/errors.js +9 -0
  27. package/node/prelude/internal/events_on.js +82 -37
  28. package/node/prelude/internal/features.js +8 -4
  29. package/node/prelude/internal/fs_filehandle.js +10 -4
  30. package/node/prelude/internal/perf_histogram.js +1 -1
  31. package/node/prelude/internal/process_more.js +32 -17
  32. package/node/prelude/internal/process_signals.js +8 -2
  33. package/node/prelude/internal/punycode.ts +163 -0
  34. package/node/prelude/internal/readline.js +648 -274
  35. package/node/prelude/internal/readline_editor.js +1240 -0
  36. package/node/prelude/internal/string_width.js +43 -0
  37. package/node/prelude/internal/tls/common.js +145 -33
  38. package/node/prelude/internal/tls/wrap.js +182 -49
  39. package/node/prelude/internal/tls/x509.js +4 -1
  40. package/node/prelude/internal/udp.js +177 -0
  41. package/node/prelude/net.js +13 -1
  42. package/node/prelude/os.js +24 -6
  43. package/node/prelude/perf_hooks.js +37 -2
  44. package/node/prelude/punycode.js +2 -130
  45. package/node/prelude/readline.js +113 -4
  46. package/node/prelude/readline_promises.js +56 -32
  47. package/node/prelude/tls.js +21 -4
  48. package/node/prelude/util.js +3 -16
  49. package/node/src/host_dns.c +623 -0
  50. package/node/src/host_http.c +12 -0
  51. package/node/src/host_net.c +46 -0
  52. package/node/src/host_os.c +1 -6
  53. package/node/src/host_sys.c +70 -0
  54. package/node/src/host_udp.c +418 -0
  55. package/node/third_party/c-ares/LICENSE.md +24 -0
  56. package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
  57. package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
  58. package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
  59. package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
  60. package/node/third_party/c-ares/include/ares.h +1237 -0
  61. package/node/third_party/c-ares/include/ares_build.h +202 -0
  62. package/node/third_party/c-ares/include/ares_dns.h +127 -0
  63. package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
  64. package/node/third_party/c-ares/include/ares_nameser.h +510 -0
  65. package/node/third_party/c-ares/include/ares_version.h +47 -0
  66. package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
  67. package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
  68. package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
  69. package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
  70. package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
  71. package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
  72. package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
  73. package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
  74. package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
  75. package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
  76. package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
  77. package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
  78. package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
  79. package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
  80. package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
  81. package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
  82. package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
  83. package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
  84. package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
  85. package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
  86. package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
  87. package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
  88. package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
  89. package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
  90. package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
  91. package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
  92. package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
  93. package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
  94. package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
  95. package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
  96. package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
  97. package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
  98. package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
  99. package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
  100. package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
  101. package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
  102. package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
  103. package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
  104. package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
  105. package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
  106. package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
  107. package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
  108. package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
  109. package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
  110. package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
  111. package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
  112. package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
  113. package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
  114. package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
  115. package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
  116. package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
  117. package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
  118. package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
  119. package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
  120. package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
  121. package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
  122. package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
  123. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  124. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  125. package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
  126. package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
  127. package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
  128. package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
  129. package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
  130. package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
  131. package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
  132. package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
  133. package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
  134. package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
  135. package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
  136. package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
  137. package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
  138. package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
  139. package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
  140. package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
  141. package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
  142. package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
  143. package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
  144. package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
  145. package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
  146. package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
  147. package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
  148. package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
  149. package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
  150. package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
  151. package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
  152. package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
  153. package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
  154. package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
  155. package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
  156. package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  157. package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  158. package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  159. package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  160. package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  161. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  162. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  163. package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  164. package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  165. package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  166. package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  167. package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
  168. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
  169. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
  170. package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
  171. package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
  172. package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
  173. package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
  174. package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
  175. package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
  176. package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
  177. package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
  178. package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
  179. package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  180. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
  181. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
  182. package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
  183. package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
  184. package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
  185. package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
  186. package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
  187. package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
  188. package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
  189. package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
  190. package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
  191. package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
  192. package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
  193. package/package.json +1 -1
  194. package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
  195. package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
  196. package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
  197. package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
  198. package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
  199. package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
  200. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  201. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  202. package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
  203. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  204. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  205. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  206. package/runtime/include/js_builtins.h +5 -0
  207. package/runtime/include/js_crypto.h +11 -0
  208. package/runtime/include/js_gc.h +13 -10
  209. package/runtime/include/js_jobs.h +2 -0
  210. package/runtime/include/js_object.h +58 -0
  211. package/runtime/include/jscontext.h +1 -0
  212. package/runtime/src/crypto_internal.h +1 -0
  213. package/runtime/src/crypto_subtle.c +66 -7
  214. package/runtime/src/crypto_tls.c +265 -19
  215. package/runtime/src/gc.c +73 -92
  216. package/runtime/src/inspect.c +18 -1
  217. package/runtime/src/jobs.c +37 -22
  218. package/runtime/src/object.c +49 -2
  219. package/runtime/src/os.c +16 -6
  220. package/runtime/src/os.h +2 -0
  221. package/runtime/src/process.c +97 -10
@@ -0,0 +1,224 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 2004 Daniel Stenberg
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice (including the next
13
+ * paragraph) shall be included in all copies or substantial portions of the
14
+ * Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ *
24
+ * SPDX-License-Identifier: MIT
25
+ */
26
+ #ifndef __ARES_SETUP_H
27
+ #define __ARES_SETUP_H
28
+
29
+ /* ============================================================================
30
+ * NOTE: This file is automatically included by ares_private.h and should not
31
+ * typically be included directly.
32
+ * All c-ares source files should include ares_private.h as the
33
+ * first header.
34
+ * ============================================================================
35
+ */
36
+
37
+ /*
38
+ * Include configuration script results or hand-crafted
39
+ * configuration file for platforms which lack config tool.
40
+ */
41
+
42
+ #ifdef HAVE_CONFIG_H
43
+ # include "ares_config.h"
44
+ #else
45
+ # ifdef _WIN32
46
+ # include "config-win32.h"
47
+ # endif
48
+ #endif /* HAVE_CONFIG_H */
49
+
50
+ /*
51
+ * c-ares external interface definitions are also used internally,
52
+ * and might also include required system header files to define them.
53
+ */
54
+
55
+ #include "ares_build.h"
56
+
57
+ /* ================================================================= */
58
+ /* No system header file shall be included in this file before this */
59
+ /* point. The only allowed ones are those included from ares_build.h */
60
+ /* ================================================================= */
61
+
62
+ /*
63
+ * Include header files for windows builds before redefining anything.
64
+ * Use this preproessor block only to include or exclude windows.h,
65
+ * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
66
+ * to any other further and independent block. Under Cygwin things work
67
+ * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
68
+ * never be included when __CYGWIN__ is defined. configure script takes
69
+ * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
70
+ * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
71
+ */
72
+
73
+ #ifdef USE_WINSOCK
74
+ # undef USE_WINSOCK
75
+ #endif
76
+
77
+ #ifdef HAVE_WINDOWS_H
78
+ # ifndef WIN32_LEAN_AND_MEAN
79
+ # define WIN32_LEAN_AND_MEAN
80
+ # endif
81
+ # include <windows.h>
82
+ # ifdef HAVE_WINSOCK2_H
83
+ # include <winsock2.h>
84
+ # define USE_WINSOCK 2
85
+ # ifdef HAVE_WS2TCPIP_H
86
+ # include <ws2tcpip.h>
87
+ # endif
88
+ # else
89
+ # ifdef HAVE_WINSOCK_H
90
+ # include <winsock.h>
91
+ # define USE_WINSOCK 1
92
+ # endif
93
+ # endif
94
+ #endif
95
+
96
+
97
+ #include <stdio.h>
98
+ #include <stdlib.h>
99
+ #include <string.h>
100
+ #include <stdarg.h>
101
+ #include <ctype.h>
102
+
103
+ #ifdef HAVE_ERRNO_H
104
+ # include <errno.h>
105
+ #endif
106
+
107
+ #ifdef HAVE_SYS_TYPES_H
108
+ # include <sys/types.h>
109
+ #endif
110
+
111
+ #ifdef HAVE_MALLOC_H
112
+ # include <malloc.h>
113
+ #endif
114
+
115
+ #ifdef HAVE_SYS_STAT_H
116
+ # include <sys/stat.h>
117
+ #endif
118
+
119
+ #ifdef HAVE_SYS_TIME_H
120
+ # include <sys/time.h>
121
+ #endif
122
+
123
+ #ifdef HAVE_TIME_H
124
+ # include <time.h>
125
+ #endif
126
+
127
+ #ifdef HAVE_UNISTD_H
128
+ # include <unistd.h>
129
+ #endif
130
+
131
+ #ifdef HAVE_SYS_SOCKET_H
132
+ # include <sys/socket.h>
133
+ #endif
134
+
135
+ /*
136
+ * Arg 2 type for gethostname in case it hasn't been defined in config file.
137
+ */
138
+
139
+ #ifndef GETHOSTNAME_TYPE_ARG2
140
+ # ifdef USE_WINSOCK
141
+ # define GETHOSTNAME_TYPE_ARG2 int
142
+ # else
143
+ # define GETHOSTNAME_TYPE_ARG2 size_t
144
+ # endif
145
+ #endif
146
+
147
+ #ifdef __POCC__
148
+ # include <sys/types.h>
149
+ # include <unistd.h>
150
+ # define ESRCH 3
151
+ #endif
152
+
153
+ /*
154
+ * Android does have the arpa/nameser.h header which is detected by configure
155
+ * but it appears to be empty with recent NDK r7b / r7c, so we undefine here.
156
+ * z/OS does have the arpa/nameser.h header which is detected by configure
157
+ * but it is not fully implemented and missing identifiers, so udefine here.
158
+ */
159
+ #if (defined(ANDROID) || defined(__ANDROID__) || defined(__MVS__)) && \
160
+ defined(HAVE_ARPA_NAMESER_H)
161
+ # undef HAVE_ARPA_NAMESER_H
162
+ #endif
163
+
164
+ /*
165
+ * Recent autoconf versions define these symbols in ares_config.h. We don't
166
+ * want them (since they collide with the libcurl ones when we build
167
+ * --enable-debug) so we undef them again here.
168
+ */
169
+
170
+ #ifdef PACKAGE_STRING
171
+ # undef PACKAGE_STRING
172
+ #endif
173
+ #ifdef PACKAGE_TARNAME
174
+ # undef PACKAGE_TARNAME
175
+ #endif
176
+ #ifdef PACKAGE_VERSION
177
+ # undef PACKAGE_VERSION
178
+ #endif
179
+ #ifdef PACKAGE_BUGREPORT
180
+ # undef PACKAGE_BUGREPORT
181
+ #endif
182
+ #ifdef PACKAGE_NAME
183
+ # undef PACKAGE_NAME
184
+ #endif
185
+ #ifdef VERSION
186
+ # undef VERSION
187
+ #endif
188
+ #ifdef PACKAGE
189
+ # undef PACKAGE
190
+ #endif
191
+
192
+ /* IPv6 compatibility */
193
+ #if !defined(HAVE_AF_INET6)
194
+ # if defined(HAVE_PF_INET6)
195
+ # define AF_INET6 PF_INET6
196
+ # else
197
+ # define AF_INET6 AF_MAX + 1
198
+ # endif
199
+ #endif
200
+
201
+
202
+ /* Definition of timeval struct for platforms that don't have it. */
203
+
204
+ #ifndef HAVE_STRUCT_TIMEVAL
205
+ struct timeval {
206
+ ares_int64_t tv_sec;
207
+ long tv_usec;
208
+ };
209
+ #endif
210
+
211
+
212
+ /*
213
+ * Macro used to include code only in debug builds.
214
+ */
215
+
216
+ #ifdef DEBUGBUILD
217
+ # define DEBUGF(x) x
218
+ #else
219
+ # define DEBUGF(x) \
220
+ do { \
221
+ } while (0)
222
+ #endif
223
+
224
+ #endif /* __ARES_SETUP_H */
@@ -0,0 +1,427 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) Massachusetts Institute of Technology
4
+ * Copyright (c) The c-ares project and its contributors
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice (including the next
14
+ * paragraph) shall be included in all copies or substantial portions of the
15
+ * Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ *
25
+ * SPDX-License-Identifier: MIT
26
+ */
27
+ #include "ares_private.h"
28
+ #ifdef HAVE_SYS_UIO_H
29
+ # include <sys/uio.h>
30
+ #endif
31
+ #ifdef HAVE_NETINET_IN_H
32
+ # include <netinet/in.h>
33
+ #endif
34
+ #ifdef HAVE_NETINET_TCP_H
35
+ # include <netinet/tcp.h>
36
+ #endif
37
+ #ifdef HAVE_NETDB_H
38
+ # include <netdb.h>
39
+ #endif
40
+ #ifdef HAVE_ARPA_INET_H
41
+ # include <arpa/inet.h>
42
+ #endif
43
+
44
+ #ifdef HAVE_STRINGS_H
45
+ # include <strings.h>
46
+ #endif
47
+ #ifdef HAVE_SYS_IOCTL_H
48
+ # include <sys/ioctl.h>
49
+ #endif
50
+ #ifdef NETWARE
51
+ # include <sys/filio.h>
52
+ #endif
53
+
54
+ #include <assert.h>
55
+ #include <fcntl.h>
56
+ #include <limits.h>
57
+
58
+ static ares_conn_err_t ares_socket_deref_error(int err)
59
+ {
60
+ switch (err) {
61
+ #if defined(EWOULDBLOCK)
62
+ case EWOULDBLOCK:
63
+ return ARES_CONN_ERR_WOULDBLOCK;
64
+ #endif
65
+ #if defined(EAGAIN) && (!defined(EWOULDBLOCK) || EAGAIN != EWOULDBLOCK)
66
+ case EAGAIN:
67
+ return ARES_CONN_ERR_WOULDBLOCK;
68
+ #endif
69
+ case EINPROGRESS:
70
+ return ARES_CONN_ERR_WOULDBLOCK;
71
+ case ENETDOWN:
72
+ return ARES_CONN_ERR_NETDOWN;
73
+ case ENETUNREACH:
74
+ return ARES_CONN_ERR_NETUNREACH;
75
+ case ECONNABORTED:
76
+ return ARES_CONN_ERR_CONNABORTED;
77
+ case ECONNRESET:
78
+ return ARES_CONN_ERR_CONNRESET;
79
+ case ECONNREFUSED:
80
+ return ARES_CONN_ERR_CONNREFUSED;
81
+ case ETIMEDOUT:
82
+ return ARES_CONN_ERR_CONNTIMEDOUT;
83
+ case EHOSTDOWN:
84
+ return ARES_CONN_ERR_HOSTDOWN;
85
+ case EHOSTUNREACH:
86
+ return ARES_CONN_ERR_HOSTUNREACH;
87
+ case EINTR:
88
+ return ARES_CONN_ERR_INTERRUPT;
89
+ case EAFNOSUPPORT:
90
+ return ARES_CONN_ERR_AFNOSUPPORT;
91
+ case EADDRNOTAVAIL:
92
+ return ARES_CONN_ERR_BADADDR;
93
+ default:
94
+ break;
95
+ }
96
+
97
+ return ARES_CONN_ERR_FAILURE;
98
+ }
99
+
100
+ ares_bool_t ares_sockaddr_addr_eq(const struct sockaddr *sa,
101
+ const struct ares_addr *aa)
102
+ {
103
+ const void *addr1;
104
+ const void *addr2;
105
+
106
+ if (sa->sa_family == aa->family) {
107
+ switch (aa->family) {
108
+ case AF_INET:
109
+ addr1 = &aa->addr.addr4;
110
+ addr2 = &(CARES_INADDR_CAST(const struct sockaddr_in *, sa))->sin_addr;
111
+ if (memcmp(addr1, addr2, sizeof(aa->addr.addr4)) == 0) {
112
+ return ARES_TRUE; /* match */
113
+ }
114
+ break;
115
+ case AF_INET6:
116
+ addr1 = &aa->addr.addr6;
117
+ addr2 =
118
+ &(CARES_INADDR_CAST(const struct sockaddr_in6 *, sa))->sin6_addr;
119
+ if (memcmp(addr1, addr2, sizeof(aa->addr.addr6)) == 0) {
120
+ return ARES_TRUE; /* match */
121
+ }
122
+ break;
123
+ default:
124
+ break; /* LCOV_EXCL_LINE */
125
+ }
126
+ }
127
+ return ARES_FALSE; /* different */
128
+ }
129
+
130
+ ares_conn_err_t ares_socket_write(ares_channel_t *channel, ares_socket_t fd,
131
+ const void *data, size_t len, size_t *written,
132
+ const struct sockaddr *sa,
133
+ ares_socklen_t salen)
134
+ {
135
+ int flags = 0;
136
+ ares_ssize_t rv;
137
+ ares_conn_err_t err = ARES_CONN_ERR_SUCCESS;
138
+
139
+ #ifdef HAVE_MSG_NOSIGNAL
140
+ flags |= MSG_NOSIGNAL;
141
+ #endif
142
+
143
+ rv = channel->sock_funcs.asendto(fd, data, len, flags, sa, salen,
144
+ channel->sock_func_cb_data);
145
+ if (rv <= 0) {
146
+ err = ares_socket_deref_error(SOCKERRNO);
147
+ } else {
148
+ *written = (size_t)rv;
149
+ }
150
+ return err;
151
+ }
152
+
153
+ ares_conn_err_t ares_socket_recv(ares_channel_t *channel, ares_socket_t s,
154
+ ares_bool_t is_tcp, void *data,
155
+ size_t data_len, size_t *read_bytes)
156
+ {
157
+ ares_ssize_t rv;
158
+
159
+ *read_bytes = 0;
160
+
161
+ rv = channel->sock_funcs.arecvfrom(s, data, data_len, 0, NULL, 0,
162
+ channel->sock_func_cb_data);
163
+
164
+ if (rv > 0) {
165
+ *read_bytes = (size_t)rv;
166
+ return ARES_CONN_ERR_SUCCESS;
167
+ }
168
+
169
+ if (rv == 0) {
170
+ /* UDP allows 0-byte packets and is connectionless, so this is success */
171
+ if (!is_tcp) {
172
+ return ARES_CONN_ERR_SUCCESS;
173
+ } else {
174
+ return ARES_CONN_ERR_CONNCLOSED;
175
+ }
176
+ }
177
+
178
+ /* If we're here, rv<0 */
179
+ return ares_socket_deref_error(SOCKERRNO);
180
+ }
181
+
182
+ ares_conn_err_t ares_socket_recvfrom(ares_channel_t *channel, ares_socket_t s,
183
+ ares_bool_t is_tcp, void *data,
184
+ size_t data_len, int flags,
185
+ struct sockaddr *from,
186
+ ares_socklen_t *from_len,
187
+ size_t *read_bytes)
188
+ {
189
+ ares_ssize_t rv;
190
+
191
+ *read_bytes = 0;
192
+
193
+ rv = channel->sock_funcs.arecvfrom(s, data, data_len, flags, from, from_len,
194
+ channel->sock_func_cb_data);
195
+
196
+ if (rv > 0) {
197
+ *read_bytes = (size_t)rv;
198
+ return ARES_CONN_ERR_SUCCESS;
199
+ }
200
+
201
+ if (rv == 0) {
202
+ /* UDP allows 0-byte packets and is connectionless, so this is success */
203
+ if (!is_tcp) {
204
+ return ARES_CONN_ERR_SUCCESS;
205
+ } else {
206
+ return ARES_CONN_ERR_CONNCLOSED;
207
+ }
208
+ }
209
+
210
+ /* If we're here, rv<0 */
211
+ return ares_socket_deref_error(SOCKERRNO);
212
+ }
213
+
214
+ ares_conn_err_t ares_socket_enable_tfo(const ares_channel_t *channel,
215
+ ares_socket_t fd)
216
+ {
217
+ ares_bool_t opt = ARES_TRUE;
218
+
219
+ if (channel->sock_funcs.asetsockopt(fd, ARES_SOCKET_OPT_TCP_FASTOPEN,
220
+ (void *)&opt, sizeof(opt),
221
+ channel->sock_func_cb_data) != 0) {
222
+ return ARES_CONN_ERR_NOTIMP;
223
+ }
224
+
225
+ return ARES_CONN_ERR_SUCCESS;
226
+ }
227
+
228
+ ares_status_t ares_socket_configure(ares_channel_t *channel, int family,
229
+ ares_bool_t is_tcp, ares_socket_t fd)
230
+ {
231
+ union {
232
+ struct sockaddr sa;
233
+ struct sockaddr_in sa4;
234
+ struct sockaddr_in6 sa6;
235
+ } local;
236
+
237
+ ares_socklen_t bindlen = 0;
238
+ int rv;
239
+ unsigned int bind_flags = 0;
240
+
241
+ /* Set the socket's send and receive buffer sizes. */
242
+ if (channel->socket_send_buffer_size > 0) {
243
+ rv = channel->sock_funcs.asetsockopt(
244
+ fd, ARES_SOCKET_OPT_SENDBUF_SIZE,
245
+ (void *)&channel->socket_send_buffer_size,
246
+ sizeof(channel->socket_send_buffer_size), channel->sock_func_cb_data);
247
+ if (rv != 0 && SOCKERRNO != ENOSYS) {
248
+ return ARES_ECONNREFUSED; /* LCOV_EXCL_LINE: UntestablePath */
249
+ }
250
+ }
251
+
252
+ if (channel->socket_receive_buffer_size > 0) {
253
+ rv = channel->sock_funcs.asetsockopt(
254
+ fd, ARES_SOCKET_OPT_RECVBUF_SIZE,
255
+ (void *)&channel->socket_receive_buffer_size,
256
+ sizeof(channel->socket_receive_buffer_size), channel->sock_func_cb_data);
257
+ if (rv != 0 && SOCKERRNO != ENOSYS) {
258
+ return ARES_ECONNREFUSED; /* LCOV_EXCL_LINE: UntestablePath */
259
+ }
260
+ }
261
+
262
+ /* Bind to network interface if configured */
263
+ if (ares_strlen(channel->local_dev_name)) {
264
+ /* Prior versions silently ignored failure, so we need to maintain that
265
+ * compatibility */
266
+ (void)channel->sock_funcs.asetsockopt(
267
+ fd, ARES_SOCKET_OPT_BIND_DEVICE, channel->local_dev_name,
268
+ (ares_socklen_t)ares_strlen(channel->local_dev_name),
269
+ channel->sock_func_cb_data);
270
+ }
271
+
272
+ /* Bind to ip address if configured */
273
+ if (family == AF_INET && channel->local_ip4) {
274
+ memset(&local.sa4, 0, sizeof(local.sa4));
275
+ local.sa4.sin_family = AF_INET;
276
+ local.sa4.sin_addr.s_addr = htonl(channel->local_ip4);
277
+ bindlen = sizeof(local.sa4);
278
+ } else if (family == AF_INET6 &&
279
+ memcmp(channel->local_ip6, ares_in6addr_any._S6_un._S6_u8,
280
+ sizeof(channel->local_ip6)) != 0) {
281
+ /* Only if not link-local and an ip other than "::" is specified */
282
+ memset(&local.sa6, 0, sizeof(local.sa6));
283
+ local.sa6.sin6_family = AF_INET6;
284
+ memcpy(&local.sa6.sin6_addr, channel->local_ip6,
285
+ sizeof(channel->local_ip6));
286
+ bindlen = sizeof(local.sa6);
287
+ }
288
+
289
+
290
+ if (bindlen && channel->sock_funcs.abind != NULL) {
291
+ bind_flags |= ARES_SOCKET_BIND_CLIENT;
292
+ if (is_tcp) {
293
+ bind_flags |= ARES_SOCKET_BIND_TCP;
294
+ }
295
+ if (channel->sock_funcs.abind(fd, bind_flags, &local.sa, bindlen,
296
+ channel->sock_func_cb_data) != 0) {
297
+ return ARES_ECONNREFUSED;
298
+ }
299
+ }
300
+
301
+ return ARES_SUCCESS;
302
+ }
303
+
304
+ ares_bool_t ares_sockaddr_to_ares_addr(struct ares_addr *ares_addr,
305
+ unsigned short *port,
306
+ const struct sockaddr *sockaddr)
307
+ {
308
+ if (sockaddr->sa_family == AF_INET) {
309
+ /* NOTE: memcpy sockaddr_in due to alignment issues found by UBSAN due to
310
+ * dnsinfo packing on MacOS */
311
+ struct sockaddr_in sockaddr_in;
312
+ memcpy(&sockaddr_in, sockaddr, sizeof(sockaddr_in));
313
+
314
+ ares_addr->family = AF_INET;
315
+ memcpy(&ares_addr->addr.addr4, &(sockaddr_in.sin_addr),
316
+ sizeof(ares_addr->addr.addr4));
317
+
318
+ if (port) {
319
+ *port = ntohs(sockaddr_in.sin_port);
320
+ }
321
+ return ARES_TRUE;
322
+ }
323
+
324
+ if (sockaddr->sa_family == AF_INET6) {
325
+ /* NOTE: memcpy sockaddr_in6 due to alignment issues found by UBSAN due to
326
+ * dnsinfo packing on MacOS */
327
+ struct sockaddr_in6 sockaddr_in6;
328
+ memcpy(&sockaddr_in6, sockaddr, sizeof(sockaddr_in6));
329
+
330
+ ares_addr->family = AF_INET6;
331
+ memcpy(&ares_addr->addr.addr6, &(sockaddr_in6.sin6_addr),
332
+ sizeof(ares_addr->addr.addr6));
333
+ if (port) {
334
+ *port = ntohs(sockaddr_in6.sin6_port);
335
+ }
336
+ return ARES_TRUE;
337
+ }
338
+
339
+ return ARES_FALSE;
340
+ }
341
+
342
+ ares_conn_err_t ares_socket_open(ares_socket_t *sock, ares_channel_t *channel,
343
+ int af, int type, int protocol)
344
+ {
345
+ ares_socket_t s;
346
+
347
+ *sock = ARES_SOCKET_BAD;
348
+
349
+ s =
350
+ channel->sock_funcs.asocket(af, type, protocol, channel->sock_func_cb_data);
351
+
352
+ if (s == ARES_SOCKET_BAD) {
353
+ return ares_socket_deref_error(SOCKERRNO);
354
+ }
355
+
356
+ *sock = s;
357
+
358
+ return ARES_CONN_ERR_SUCCESS;
359
+ }
360
+
361
+ ares_conn_err_t ares_socket_connect(ares_channel_t *channel,
362
+ ares_socket_t sockfd, ares_bool_t is_tfo,
363
+ const struct sockaddr *addr,
364
+ ares_socklen_t addrlen)
365
+ {
366
+ ares_conn_err_t err = ARES_CONN_ERR_SUCCESS;
367
+ unsigned int flags = 0;
368
+
369
+ if (is_tfo) {
370
+ flags |= ARES_SOCKET_CONN_TCP_FASTOPEN;
371
+ }
372
+
373
+ do {
374
+ int rv;
375
+
376
+ rv = channel->sock_funcs.aconnect(sockfd, addr, addrlen, flags,
377
+ channel->sock_func_cb_data);
378
+
379
+ if (rv < 0) {
380
+ err = ares_socket_deref_error(SOCKERRNO);
381
+ } else {
382
+ err = ARES_CONN_ERR_SUCCESS;
383
+ }
384
+ } while (err == ARES_CONN_ERR_INTERRUPT);
385
+
386
+ return err;
387
+ }
388
+
389
+ void ares_socket_close(ares_channel_t *channel, ares_socket_t s)
390
+ {
391
+ if (channel == NULL || s == ARES_SOCKET_BAD) {
392
+ return;
393
+ }
394
+
395
+ channel->sock_funcs.aclose(s, channel->sock_func_cb_data);
396
+ }
397
+
398
+ void ares_set_socket_callback(ares_channel_t *channel,
399
+ ares_sock_create_callback cb, void *data)
400
+ {
401
+ if (channel == NULL) {
402
+ return;
403
+ }
404
+ channel->sock_create_cb = cb;
405
+ channel->sock_create_cb_data = data;
406
+ }
407
+
408
+ void ares_set_socket_configure_callback(ares_channel_t *channel,
409
+ ares_sock_config_callback cb,
410
+ void *data)
411
+ {
412
+ if (channel == NULL || channel->optmask & ARES_OPT_EVENT_THREAD) {
413
+ return;
414
+ }
415
+ channel->sock_config_cb = cb;
416
+ channel->sock_config_cb_data = data;
417
+ }
418
+
419
+ void ares_set_pending_write_cb(ares_channel_t *channel,
420
+ ares_pending_write_cb callback, void *user_data)
421
+ {
422
+ if (channel == NULL || channel->optmask & ARES_OPT_EVENT_THREAD) {
423
+ return;
424
+ }
425
+ channel->notify_pending_write_cb = callback;
426
+ channel->notify_pending_write_cb_data = user_data;
427
+ }