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,648 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 Massachusetts Institute of Technology
4
+ * Copyright (c) 2010 Daniel Stenberg
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
+ #ifndef __ARES_PRIVATE_H
28
+ #define __ARES_PRIVATE_H
29
+
30
+ /* ============================================================================
31
+ * NOTE: All c-ares source files should include ares_private.h as the first
32
+ * header.
33
+ * ============================================================================
34
+ */
35
+
36
+ #include "ares_setup.h"
37
+ #include "ares.h"
38
+
39
+ #ifdef HAVE_NETINET_IN_H
40
+ # include <netinet/in.h>
41
+ #endif
42
+
43
+ #include "ares_mem.h"
44
+ #include "ares_ipv6.h"
45
+ #include "util/ares_math.h"
46
+ #include "util/ares_time.h"
47
+ #include "util/ares_rand.h"
48
+ #include "ares_array.h"
49
+ #include "ares_llist.h"
50
+ #include "dsa/ares_slist.h"
51
+ #include "ares_htable_strvp.h"
52
+ #include "ares_htable_szvp.h"
53
+ #include "ares_htable_asvp.h"
54
+ #include "ares_htable_dict.h"
55
+ #include "ares_htable_vpvp.h"
56
+ #include "ares_htable_vpstr.h"
57
+ #include "record/ares_dns_multistring.h"
58
+ #include "ares_buf.h"
59
+ #include "record/ares_dns_private.h"
60
+ #include "util/ares_iface_ips.h"
61
+ #include "util/ares_threads.h"
62
+ #include "ares_socket.h"
63
+ #include "ares_conn.h"
64
+ #include "ares_str.h"
65
+ #include "str/ares_strsplit.h"
66
+ #include "util/ares_uri.h"
67
+
68
+ #ifndef HAVE_GETENV
69
+ # include "ares_getenv.h"
70
+ # define getenv(ptr) ares_getenv(ptr)
71
+ #endif
72
+
73
+ #define DEFAULT_TIMEOUT 2000 /* milliseconds */
74
+ #define DEFAULT_TRIES 3
75
+ #ifndef INADDR_NONE
76
+ # define INADDR_NONE 0xffffffff
77
+ #endif
78
+
79
+ /* By using a double cast, we can get rid of the bogus warning of
80
+ * warning: cast from 'const struct sockaddr *' to 'const struct sockaddr_in6 *'
81
+ * increases required alignment from 1 to 4 [-Wcast-align]
82
+ */
83
+ #define CARES_INADDR_CAST(type, var) ((type)((const void *)var))
84
+
85
+ #if defined(USE_WINSOCK)
86
+ # define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"
87
+ # define PATH_RESOLV_CONF ""
88
+ #elif defined(WATT32)
89
+
90
+ # define PATH_RESOLV_CONF "/dev/ENV/etc/resolv.conf"
91
+ W32_FUNC const char *_w32_GetHostsFile(void);
92
+
93
+ #elif defined(NETWARE)
94
+
95
+ # define PATH_RESOLV_CONF "sys:/etc/resolv.cfg"
96
+ # define PATH_HOSTS "sys:/etc/hosts"
97
+
98
+ #elif defined(__riscos__)
99
+
100
+ # define PATH_RESOLV_CONF ""
101
+ # define PATH_HOSTS "InetDBase:Hosts"
102
+
103
+ #elif defined(__HAIKU__)
104
+
105
+ # define PATH_RESOLV_CONF "/system/settings/network/resolv.conf"
106
+ # define PATH_HOSTS "/system/settings/network/hosts"
107
+
108
+ #else
109
+
110
+ # define PATH_RESOLV_CONF "/etc/resolv.conf"
111
+ # ifdef ETC_INET
112
+ # define PATH_HOSTS "/etc/inet/hosts"
113
+ # else
114
+ # define PATH_HOSTS "/etc/hosts"
115
+ # endif
116
+
117
+ #endif
118
+
119
+ /********* EDNS defines section ******/
120
+ #define EDNSPACKETSZ \
121
+ 1232 /* Reasonable UDP payload size, as agreed by operators \
122
+ https://www.dnsflagday.net/2020/#faq */
123
+ #define MAXENDSSZ 4096 /* Maximum (local) limit for edns packet size */
124
+ #define EDNSFIXEDSZ 11 /* Size of EDNS header */
125
+
126
+ /********* EDNS defines section ******/
127
+
128
+ /* Default values for server failover behavior. We retry failed servers with
129
+ * a 10% probability and a minimum delay of 5 seconds between retries.
130
+ */
131
+ #define DEFAULT_SERVER_RETRY_CHANCE 10
132
+ #define DEFAULT_SERVER_RETRY_DELAY 5000
133
+
134
+ /* Upper bound on the consecutive failure count tracked per server. Only the
135
+ * relative order of the counts is used for server selection, so magnitude
136
+ * beyond "clearly down" carries no additional signal. Capping it bounds how
137
+ * long a server that failed for an extended period sorts behind other failed
138
+ * servers once it comes back online. */
139
+ #define SERVER_CONSEC_FAILURES_CAP 16
140
+
141
+ typedef void (*ares_query_enqueue_cb)(void *data);
142
+
143
+ struct ares_query;
144
+ typedef struct ares_query ares_query_t;
145
+
146
+ /* State to represent a DNS query */
147
+ struct ares_query {
148
+ /* Query ID from qbuf, for faster lookup, and current timeout */
149
+ unsigned short qid; /* host byte order */
150
+ ares_timeval_t ts; /*!< Timestamp query was sent */
151
+ ares_timeval_t timeout;
152
+ ares_channel_t *channel;
153
+
154
+ /*
155
+ * Node object for each list entry the query belongs to in order to
156
+ * make removal operations O(1).
157
+ */
158
+ ares_slist_node_t *node_queries_by_timeout;
159
+ ares_llist_node_t *node_queries_to_conn;
160
+ ares_llist_node_t *node_all_queries;
161
+
162
+ /* connection handle query is associated with */
163
+ ares_conn_t *conn;
164
+
165
+ /* Query */
166
+ ares_dns_record_t *query;
167
+
168
+ ares_callback_dnsrec callback;
169
+ void *arg;
170
+
171
+ /* Query status */
172
+ size_t try_count; /* Number of times we tried this query already. */
173
+ size_t cookie_try_count; /* Attempt count for cookie resends */
174
+ ares_bool_t using_tcp;
175
+ ares_status_t error_status;
176
+ size_t timeouts; /* number of timeouts we saw for this request */
177
+ ares_bool_t no_retries; /* do not perform any additional retries, this is
178
+ * set when a query is to be canceled */
179
+ };
180
+
181
+ struct apattern {
182
+ struct ares_addr addr;
183
+ unsigned char mask;
184
+ };
185
+
186
+ struct ares_qcache;
187
+ typedef struct ares_qcache ares_qcache_t;
188
+
189
+ struct ares_hosts_file;
190
+ typedef struct ares_hosts_file ares_hosts_file_t;
191
+
192
+ struct ares_channeldata {
193
+ /* Configuration data */
194
+ unsigned int flags;
195
+ size_t timeout; /* in milliseconds */
196
+ size_t tries;
197
+ size_t ndots;
198
+ size_t maxtimeout; /* in milliseconds */
199
+ ares_bool_t rotate;
200
+ unsigned short udp_port; /* stored in network order */
201
+ unsigned short tcp_port; /* stored in network order */
202
+ int socket_send_buffer_size; /* setsockopt takes int */
203
+ int socket_receive_buffer_size; /* setsockopt takes int */
204
+ char **domains;
205
+ size_t ndomains;
206
+ struct apattern *sortlist;
207
+ size_t nsort;
208
+ char *lookups;
209
+ size_t ednspsz;
210
+ unsigned int qcache_max_ttl;
211
+ ares_evsys_t evsys;
212
+ unsigned int optmask;
213
+
214
+ /* For binding to local devices and/or IP addresses. Leave
215
+ * them null/zero for no binding.
216
+ */
217
+ char local_dev_name[32];
218
+ unsigned int local_ip4;
219
+ unsigned char local_ip6[16];
220
+
221
+ /* Thread safety lock */
222
+ ares_thread_mutex_t *lock;
223
+
224
+ /* Conditional to wake waiters when queue is empty */
225
+ ares_thread_cond_t *cond_empty;
226
+
227
+ /* Server addresses and communications state. Sorted by least consecutive
228
+ * failures, followed by the configuration order if failures are equal. */
229
+ ares_slist_t *servers;
230
+
231
+ /* random state to use when generating new ids and generating retry penalties
232
+ */
233
+ ares_rand_state *rand_state;
234
+
235
+ /* All active queries in a single list */
236
+ ares_llist_t *all_queries;
237
+ /* Queries bucketed by qid, for quickly dispatching DNS responses: */
238
+ ares_htable_szvp_t *queries_by_qid;
239
+
240
+ /* Queries bucketed by timeout, for quickly handling timeouts: */
241
+ ares_slist_t *queries_by_timeout;
242
+
243
+ /* Map linked list node member for connection to file descriptor. We use
244
+ * the node instead of the connection object itself so we can quickly look
245
+ * up a connection and remove it if necessary (as otherwise we'd have to
246
+ * scan all connections) */
247
+ ares_htable_asvp_t *connnode_by_socket;
248
+
249
+ ares_sock_state_cb sock_state_cb;
250
+ void *sock_state_cb_data;
251
+
252
+ ares_sock_create_callback sock_create_cb;
253
+ void *sock_create_cb_data;
254
+
255
+ ares_sock_config_callback sock_config_cb;
256
+ void *sock_config_cb_data;
257
+
258
+ struct ares_socket_functions_ex sock_funcs;
259
+ void *sock_func_cb_data;
260
+ const struct ares_socket_functions *legacy_sock_funcs;
261
+ void *legacy_sock_funcs_cb_data;
262
+
263
+ ares_pending_write_cb notify_pending_write_cb;
264
+ void *notify_pending_write_cb_data;
265
+ ares_bool_t notify_pending_write;
266
+
267
+ ares_query_enqueue_cb query_enqueue_cb;
268
+ void *query_enqueue_cb_data;
269
+
270
+ /* Path for resolv.conf file, configurable via ares_options */
271
+ char *resolvconf_path;
272
+
273
+ /* Path for hosts file, configurable via ares_options */
274
+ char *hosts_path;
275
+
276
+ /* Maximum UDP queries per connection allowed */
277
+ size_t udp_max_queries;
278
+
279
+ /* Cache of local hosts file */
280
+ ares_hosts_file_t *hf;
281
+
282
+ /* Query Cache */
283
+ ares_qcache_t *qcache;
284
+
285
+ /* Fields controlling server failover behavior.
286
+ * The retry chance is the probability (1/N) by which we will retry a failed
287
+ * server instead of the best server when selecting a server to send queries
288
+ * to.
289
+ * The retry delay is the minimum time in milliseconds to wait between doing
290
+ * such retries (applied per-server).
291
+ */
292
+ unsigned short server_retry_chance;
293
+ size_t server_retry_delay;
294
+
295
+ /* Callback triggered when a server has a successful or failed response */
296
+ ares_server_state_callback server_state_cb;
297
+ void *server_state_cb_data;
298
+
299
+ /* TRUE if a reinit is pending. Reinit spawns a thread to read the system
300
+ * configuration and then apply the configuration since configuration
301
+ * reading may block. The thread handle is provided for waiting on thread
302
+ * exit. */
303
+ ares_bool_t reinit_pending;
304
+ ares_thread_t *reinit_thread;
305
+
306
+ /* Whether the system is up or not. This is mainly to prevent deadlocks
307
+ * and access violations during the cleanup process. Some things like
308
+ * system config changes might get triggered and we need a flag to make
309
+ * sure we don't take action. */
310
+ ares_bool_t sys_up;
311
+ };
312
+
313
+ /* Does the domain end in ".onion" or ".onion."? Case-insensitive. */
314
+ ares_bool_t ares_is_onion_domain(const char *name);
315
+
316
+ /* Returns one of the normal ares status codes like ARES_SUCCESS */
317
+ ares_status_t ares_send_query(ares_server_t *requested_server /* Optional */,
318
+ ares_query_t *query, const ares_timeval_t *now);
319
+ ares_status_t ares_requeue_query(ares_query_t *query, const ares_timeval_t *now,
320
+ ares_status_t status,
321
+ ares_bool_t inc_try_count,
322
+ ares_dns_record_t *dnsrec,
323
+ ares_array_t **requeue);
324
+
325
+ /*! Count the number of labels (dots+1) in a domain */
326
+ size_t ares_name_label_cnt(const char *name);
327
+
328
+ /*! Retrieve a list of names to use for searching. The first successful
329
+ * query in the list wins. This function also uses the HOSTSALIASES file
330
+ * as well as uses channel configuration to determine the search order.
331
+ *
332
+ * \param[in] channel initialized ares channel
333
+ * \param[in] name initial name being searched
334
+ * \param[out] names array of names to attempt, use ares_strsplit_free()
335
+ * when no longer needed.
336
+ * \param[out] names_len number of names in array
337
+ * \return ARES_SUCCESS on success, otherwise one of the other error codes.
338
+ */
339
+ ares_status_t ares_search_name_list(const ares_channel_t *channel,
340
+ const char *name, char ***names,
341
+ size_t *names_len);
342
+
343
+ /*! Function to create callback arg for converting from ares_callback_dnsrec
344
+ * to ares_calback */
345
+ void *ares_dnsrec_convert_arg(ares_callback callback, void *arg);
346
+
347
+ /*! Callback function used to convert from the ares_callback_dnsrec prototype to
348
+ * the ares_callback prototype, by writing the result and passing that to
349
+ * the inner callback.
350
+ */
351
+ void ares_dnsrec_convert_cb(void *arg, ares_status_t status, size_t timeouts,
352
+ const ares_dns_record_t *dnsrec);
353
+
354
+ void ares_free_query(ares_query_t *query);
355
+
356
+ unsigned short ares_generate_new_id(ares_rand_state *state);
357
+ ares_status_t ares_expand_name_validated(const unsigned char *encoded,
358
+ const unsigned char *abuf, size_t alen,
359
+ char **s, size_t *enclen,
360
+ ares_bool_t is_hostname);
361
+ ares_status_t ares_expand_string_ex(const unsigned char *encoded,
362
+ const unsigned char *abuf, size_t alen,
363
+ unsigned char **s, size_t *enclen);
364
+ ares_status_t ares_init_servers_state(ares_channel_t *channel);
365
+ ares_status_t ares_init_by_options(ares_channel_t *channel,
366
+ const struct ares_options *options,
367
+ int optmask);
368
+ void ares_set_query_enqueue_cb(ares_channel_t *channel,
369
+ ares_query_enqueue_cb callback,
370
+ void *user_data);
371
+ ares_status_t ares_init_by_sysconfig(ares_channel_t *channel);
372
+ void ares_set_socket_functions_def(ares_channel_t *channel);
373
+
374
+ typedef struct {
375
+ ares_llist_t *sconfig;
376
+ struct apattern *sortlist;
377
+ size_t nsortlist;
378
+ char **domains;
379
+ size_t ndomains;
380
+ char *lookups;
381
+ size_t ndots;
382
+ size_t tries;
383
+ ares_bool_t rotate;
384
+ size_t timeout_ms;
385
+ ares_bool_t usevc;
386
+ } ares_sysconfig_t;
387
+
388
+ ares_status_t ares_sysconfig_set_options(ares_sysconfig_t *sysconfig,
389
+ const char *str);
390
+
391
+ ares_status_t ares_init_by_environment(ares_sysconfig_t *sysconfig);
392
+
393
+
394
+ typedef ares_status_t (*ares_sysconfig_line_cb_t)(const ares_channel_t *channel,
395
+ ares_sysconfig_t *sysconfig,
396
+ ares_buf_t *line);
397
+
398
+ ares_status_t ares_sysconfig_parse_resolv_line(const ares_channel_t *channel,
399
+ ares_sysconfig_t *sysconfig,
400
+ ares_buf_t *line);
401
+
402
+ ares_status_t ares_sysconfig_process_buf(const ares_channel_t *channel,
403
+ ares_sysconfig_t *sysconfig,
404
+ ares_buf_t *buf,
405
+ ares_sysconfig_line_cb_t cb);
406
+
407
+ ares_status_t ares_init_sysconfig_files(const ares_channel_t *channel,
408
+ ares_sysconfig_t *sysconfig,
409
+ ares_bool_t process_resolvconf);
410
+ #ifdef __APPLE__
411
+ ares_status_t ares_init_sysconfig_macos(const ares_channel_t *channel,
412
+ ares_sysconfig_t *sysconfig);
413
+ #endif
414
+ #ifdef USE_WINSOCK
415
+ ares_status_t ares_init_sysconfig_windows(const ares_channel_t *channel,
416
+ ares_sysconfig_t *sysconfig);
417
+ #endif
418
+
419
+ ares_status_t ares_parse_sortlist(struct apattern **sortlist, size_t *nsort,
420
+ const char *str);
421
+
422
+ /* Returns ARES_SUCCESS if alias found, alias is set. Returns ARES_ENOTFOUND
423
+ * if not alias found. Returns other errors on critical failure like
424
+ * ARES_ENOMEM */
425
+ ares_status_t ares_lookup_hostaliases(const ares_channel_t *channel,
426
+ const char *name, char **alias);
427
+
428
+ ares_bool_t ares_parse_port(const char *str, unsigned short *port,
429
+ ares_bool_t allow_zero);
430
+
431
+ ares_status_t ares_cat_domain(const char *name, const char *domain, char **s);
432
+ ares_status_t ares_sortaddrinfo(ares_channel_t *channel,
433
+ struct ares_addrinfo_node *ai_node);
434
+
435
+ void ares_freeaddrinfo_nodes(struct ares_addrinfo_node *ai_node);
436
+ ares_bool_t ares_is_localhost(const char *name);
437
+
438
+ struct ares_addrinfo_node *
439
+ ares_append_addrinfo_node(struct ares_addrinfo_node **ai_node);
440
+ void ares_addrinfo_cat_nodes(struct ares_addrinfo_node **head,
441
+ struct ares_addrinfo_node *tail);
442
+
443
+ void ares_freeaddrinfo_cnames(struct ares_addrinfo_cname *ai_cname);
444
+
445
+ struct ares_addrinfo_cname *
446
+ ares_append_addrinfo_cname(struct ares_addrinfo_cname **ai_cname);
447
+
448
+ ares_status_t ares_append_ai_node(int aftype, unsigned short port,
449
+ unsigned int ttl, const void *adata,
450
+ struct ares_addrinfo_node **nodes);
451
+
452
+ void ares_addrinfo_cat_cnames(struct ares_addrinfo_cname **head,
453
+ struct ares_addrinfo_cname *tail);
454
+
455
+ ares_status_t ares_parse_into_addrinfo(const ares_dns_record_t *dnsrec,
456
+ ares_bool_t cname_only_is_enodata,
457
+ unsigned short port,
458
+ struct ares_addrinfo *ai);
459
+ ares_status_t ares_parse_ptr_reply_dnsrec(const ares_dns_record_t *dnsrec,
460
+ const void *addr, int addrlen,
461
+ int family, struct hostent **host);
462
+
463
+ /* host address must be valid or NULL as will create or append */
464
+ ares_status_t ares_addrinfo2hostent(const struct ares_addrinfo *ai, int family,
465
+ struct hostent **host);
466
+
467
+ ares_status_t ares_addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
468
+ size_t req_naddrttls,
469
+ struct ares_addrttl *addrttls,
470
+ struct ares_addr6ttl *addr6ttls,
471
+ size_t *naddrttls);
472
+ ares_status_t ares_addrinfo_localhost(const char *name, unsigned short port,
473
+ const struct ares_addrinfo_hints *hints,
474
+ struct ares_addrinfo *ai);
475
+
476
+ ares_status_t ares_servers_update(ares_channel_t *channel,
477
+ ares_llist_t *server_list,
478
+ ares_bool_t user_specified);
479
+ ares_status_t
480
+ ares_sconfig_append(const ares_channel_t *channel, ares_llist_t **sconfig,
481
+ const struct ares_addr *addr, unsigned short udp_port,
482
+ unsigned short tcp_port, const char *ll_iface);
483
+ ares_status_t ares_sconfig_append_fromstr(const ares_channel_t *channel,
484
+ ares_llist_t **sconfig,
485
+ const char *str,
486
+ ares_bool_t ignore_invalid);
487
+ ares_status_t ares_in_addr_to_sconfig_llist(const struct in_addr *servers,
488
+ size_t nservers,
489
+ ares_llist_t **llist);
490
+ ares_status_t ares_get_server_addr(const ares_server_t *server,
491
+ ares_buf_t *buf);
492
+
493
+ struct ares_hosts_entry;
494
+ typedef struct ares_hosts_entry ares_hosts_entry_t;
495
+
496
+ void ares_hosts_file_destroy(ares_hosts_file_t *hf);
497
+ ares_status_t ares_hosts_search_ipaddr(ares_channel_t *channel,
498
+ ares_bool_t use_env, const char *ipaddr,
499
+ const ares_hosts_entry_t **entry);
500
+ ares_status_t ares_hosts_search_host(ares_channel_t *channel,
501
+ ares_bool_t use_env, const char *host,
502
+ const ares_hosts_entry_t **entry);
503
+ ares_status_t ares_hosts_entry_to_hostent(const ares_hosts_entry_t *entry,
504
+ int family, struct hostent **hostent);
505
+ ares_status_t ares_hosts_entry_to_addrinfo(const ares_hosts_entry_t *entry,
506
+ const char *name, int family,
507
+ unsigned short port,
508
+ ares_bool_t want_cnames,
509
+ struct ares_addrinfo *ai);
510
+
511
+ /* Same as ares_query_dnsrec() except does not take a channel lock. Use this
512
+ * if a channel lock is already held */
513
+ ares_status_t ares_query_nolock(ares_channel_t *channel, const char *name,
514
+ ares_dns_class_t dnsclass,
515
+ ares_dns_rec_type_t type,
516
+ ares_callback_dnsrec callback, void *arg,
517
+ unsigned short *qid);
518
+
519
+ /*! Flags controlling behavior for ares_send_nolock() */
520
+ typedef enum {
521
+ ARES_SEND_FLAG_NOCACHE = 1 << 0, /*!< Do not query the cache */
522
+ ARES_SEND_FLAG_NORETRY = 1 << 1 /*!< Do not retry this query on error */
523
+ } ares_send_flags_t;
524
+
525
+ /* Similar to ares_send_dnsrec() except does not take a channel lock, allows
526
+ * specifying a particular server to use, and also flags controlling behavior.
527
+ */
528
+ ares_status_t ares_send_nolock(ares_channel_t *channel, ares_server_t *server,
529
+ ares_send_flags_t flags,
530
+ const ares_dns_record_t *dnsrec,
531
+ ares_callback_dnsrec callback, void *arg,
532
+ unsigned short *qid);
533
+
534
+ /* Same as ares_gethostbyaddr() except does not take a channel lock. Use this
535
+ * if a channel lock is already held */
536
+ void ares_gethostbyaddr_nolock(ares_channel_t *channel, const void *addr,
537
+ int addrlen, int family,
538
+ ares_host_callback callback, void *arg);
539
+
540
+ /*! Parse a compressed DNS name as defined in RFC1035 starting at the current
541
+ * offset within the buffer.
542
+ *
543
+ * It is assumed that either a const buffer is being used, or before
544
+ * the message processing was started that ares_buf_reclaim() was called.
545
+ *
546
+ * \param[in] buf Initialized buffer object
547
+ * \param[out] name Pointer passed by reference to be filled in with
548
+ * allocated string of the parsed name that must be
549
+ * ares_free()'d by the caller.
550
+ * \param[in] is_hostname if ARES_TRUE, will validate the character set for
551
+ * a valid hostname or will return error.
552
+ * \param[in] allow_compression if ARES_FALSE, a compression pointer
553
+ * encountered while parsing the name will be rejected
554
+ * with ARES_EBADNAME. Used for RR types (e.g. SRV)
555
+ * whose RDATA names must not use name compression.
556
+ * \return ARES_SUCCESS on success
557
+ */
558
+ ares_status_t ares_dns_name_parse(ares_buf_t *buf, char **name,
559
+ ares_bool_t is_hostname,
560
+ ares_bool_t allow_compression);
561
+
562
+ /*! Write the DNS name to the buffer in the DNS domain-name syntax as a
563
+ * series of labels. The maximum domain name length is 255 characters with
564
+ * each label being a maximum of 63 characters. If the validate_hostname
565
+ * flag is set, it will strictly validate the character set.
566
+ *
567
+ * \param[in,out] buf Initialized buffer object to write name to
568
+ * \param[in,out] list Pointer passed by reference to maintain a list of
569
+ * domain name to indexes used for name compression.
570
+ * Pass NULL (not by reference) if name compression isn't
571
+ * desired. Otherwise the list will be automatically
572
+ * created upon first entry.
573
+ * \param[in] validate_hostname Validate the hostname character set.
574
+ * \param[in] name Name to write out, it may have escape
575
+ * sequences.
576
+ * \return ARES_SUCCESS on success, most likely ARES_EBADNAME if the name is
577
+ * bad.
578
+ */
579
+ ares_status_t ares_dns_name_write(ares_buf_t *buf, ares_llist_t **list,
580
+ ares_bool_t validate_hostname,
581
+ const char *name);
582
+
583
+ /*! Check if the queue is empty, if so, wake any waiters. This is only
584
+ * effective if built with threading support.
585
+ *
586
+ * Must be holding a channel lock when calling this function.
587
+ *
588
+ * \param[in] channel Initialized ares channel object
589
+ */
590
+ void ares_queue_notify_empty(ares_channel_t *channel);
591
+
592
+ #define ARES_CONFIG_CHECK(x) \
593
+ (x && x->lookups && ares_slist_len(x->servers) > 0 && x->timeout > 0 && \
594
+ x->tries > 0)
595
+
596
+ ares_bool_t ares_subnet_match(const struct ares_addr *addr,
597
+ const struct ares_addr *subnet,
598
+ unsigned char netmask);
599
+ ares_bool_t ares_addr_is_linklocal(const struct ares_addr *addr);
600
+
601
+ void ares_qcache_destroy(ares_qcache_t *cache);
602
+ ares_status_t ares_qcache_create(ares_rand_state *rand_state,
603
+ unsigned int max_ttl,
604
+ ares_qcache_t **cache_out);
605
+ void ares_qcache_flush(ares_qcache_t *cache);
606
+ ares_status_t ares_qcache_insert(ares_channel_t *channel,
607
+ const ares_timeval_t *now,
608
+ const ares_query_t *query,
609
+ const ares_dns_record_t *dnsrec);
610
+ ares_status_t ares_qcache_fetch(ares_channel_t *channel,
611
+ const ares_timeval_t *now,
612
+ const ares_dns_record_t *dnsrec,
613
+ const ares_dns_record_t **dnsrec_resp);
614
+
615
+ void ares_metrics_record(const ares_query_t *query, ares_server_t *server,
616
+ ares_status_t status, const ares_dns_record_t *dnsrec);
617
+ size_t ares_metrics_server_timeout(const ares_server_t *server,
618
+ const ares_timeval_t *now);
619
+
620
+ ares_status_t ares_cookie_apply(ares_dns_record_t *dnsrec, ares_conn_t *conn,
621
+ const ares_timeval_t *now);
622
+ ares_status_t ares_cookie_validate(ares_query_t *query,
623
+ const ares_dns_record_t *dnsresp,
624
+ ares_conn_t *conn,
625
+ const ares_timeval_t *now,
626
+ ares_array_t **requeue);
627
+
628
+ ares_status_t ares_channel_threading_init(ares_channel_t *channel);
629
+ void ares_channel_threading_destroy(ares_channel_t *channel);
630
+ void ares_channel_lock(const ares_channel_t *channel);
631
+ void ares_channel_unlock(const ares_channel_t *channel);
632
+
633
+ struct ares_event_thread;
634
+ typedef struct ares_event_thread ares_event_thread_t;
635
+
636
+ void ares_event_thread_destroy(ares_channel_t *channel);
637
+ ares_status_t ares_event_thread_init(ares_channel_t *channel);
638
+
639
+
640
+ #ifdef _WIN32
641
+ # define HOSTENT_ADDRTYPE_TYPE short
642
+ # define HOSTENT_LENGTH_TYPE short
643
+ #else
644
+ # define HOSTENT_ADDRTYPE_TYPE int
645
+ # define HOSTENT_LENGTH_TYPE int
646
+ #endif
647
+
648
+ #endif /* __ARES_PRIVATE_H */