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,492 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 Massachusetts Institute of Technology
4
+ * Copyright (c) 2008 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
+
28
+ #include "ares_private.h"
29
+
30
+ #ifdef HAVE_ARPA_INET_H
31
+ # include <arpa/inet.h>
32
+ #endif
33
+
34
+ #include "ares_data.h"
35
+ #include "ares_inet_net_pton.h"
36
+
37
+ void ares_destroy_options(struct ares_options *options)
38
+ {
39
+ int i;
40
+
41
+ ares_free(options->servers);
42
+
43
+ for (i = 0; options->domains && i < options->ndomains; i++) {
44
+ ares_free(options->domains[i]);
45
+ }
46
+
47
+ ares_free(options->domains);
48
+ ares_free(options->sortlist);
49
+ ares_free(options->lookups);
50
+ ares_free(options->resolvconf_path);
51
+ ares_free(options->hosts_path);
52
+ }
53
+
54
+ static struct in_addr *ares_save_opt_servers(const ares_channel_t *channel,
55
+ int *nservers)
56
+ {
57
+ ares_slist_node_t *snode;
58
+ struct in_addr *out =
59
+ ares_malloc_zero(ares_slist_len(channel->servers) * sizeof(*out));
60
+
61
+ *nservers = 0;
62
+
63
+ if (out == NULL) {
64
+ return NULL;
65
+ }
66
+
67
+ for (snode = ares_slist_node_first(channel->servers); snode != NULL;
68
+ snode = ares_slist_node_next(snode)) {
69
+ const ares_server_t *server = ares_slist_node_val(snode);
70
+
71
+ if (server->addr.family != AF_INET) {
72
+ continue;
73
+ }
74
+
75
+ memcpy(&out[*nservers], &server->addr.addr.addr4, sizeof(*out));
76
+ (*nservers)++;
77
+ }
78
+
79
+ return out;
80
+ }
81
+
82
+ /* Save options from initialized channel */
83
+ int ares_save_options(const ares_channel_t *channel,
84
+ struct ares_options *options, int *optmask)
85
+ {
86
+ size_t i;
87
+
88
+ /* NOTE: We can't zero the whole thing out, this is because the size of the
89
+ * struct ares_options changes over time, so if someone compiled
90
+ * with an older version, their struct size might be smaller and
91
+ * we might overwrite their memory! So using the optmask is critical
92
+ * here, as they could have only set options they knew about.
93
+ *
94
+ * Unfortunately ares_destroy_options() doesn't take an optmask, so
95
+ * there are a few pointers we *must* zero out otherwise we won't
96
+ * know if they were allocated or not
97
+ */
98
+ options->servers = NULL;
99
+ options->domains = NULL;
100
+ options->sortlist = NULL;
101
+ options->lookups = NULL;
102
+ options->resolvconf_path = NULL;
103
+ options->hosts_path = NULL;
104
+
105
+ if (!ARES_CONFIG_CHECK(channel)) {
106
+ return ARES_ENODATA;
107
+ }
108
+
109
+ if (channel->optmask & ARES_OPT_FLAGS) {
110
+ options->flags = (int)channel->flags;
111
+ }
112
+
113
+ /* We convert ARES_OPT_TIMEOUT to ARES_OPT_TIMEOUTMS in
114
+ * ares_init_by_options() */
115
+ if (channel->optmask & ARES_OPT_TIMEOUTMS) {
116
+ options->timeout = (int)channel->timeout;
117
+ }
118
+
119
+ if (channel->optmask & ARES_OPT_TRIES) {
120
+ options->tries = (int)channel->tries;
121
+ }
122
+
123
+ if (channel->optmask & ARES_OPT_NDOTS) {
124
+ options->ndots = (int)channel->ndots;
125
+ }
126
+
127
+ if (channel->optmask & ARES_OPT_MAXTIMEOUTMS) {
128
+ options->maxtimeout = (int)channel->maxtimeout;
129
+ }
130
+
131
+ if (channel->optmask & ARES_OPT_UDP_PORT) {
132
+ options->udp_port = channel->udp_port;
133
+ }
134
+ if (channel->optmask & ARES_OPT_TCP_PORT) {
135
+ options->tcp_port = channel->tcp_port;
136
+ }
137
+
138
+ if (channel->optmask & ARES_OPT_SOCK_STATE_CB) {
139
+ options->sock_state_cb = channel->sock_state_cb;
140
+ options->sock_state_cb_data = channel->sock_state_cb_data;
141
+ }
142
+
143
+ if (channel->optmask & ARES_OPT_SERVERS) {
144
+ options->servers = ares_save_opt_servers(channel, &options->nservers);
145
+ if (options->servers == NULL) {
146
+ return ARES_ENOMEM;
147
+ }
148
+ }
149
+
150
+ if (channel->optmask & ARES_OPT_DOMAINS) {
151
+ options->domains = NULL;
152
+ if (channel->ndomains) {
153
+ options->domains = ares_malloc(channel->ndomains * sizeof(char *));
154
+ if (!options->domains) {
155
+ return ARES_ENOMEM;
156
+ }
157
+
158
+ for (i = 0; i < channel->ndomains; i++) {
159
+ options->domains[i] = ares_strdup(channel->domains[i]);
160
+ if (!options->domains[i]) {
161
+ options->ndomains = (int)i;
162
+ return ARES_ENOMEM;
163
+ }
164
+ }
165
+ }
166
+ options->ndomains = (int)channel->ndomains;
167
+ }
168
+
169
+ if (channel->optmask & ARES_OPT_LOOKUPS) {
170
+ options->lookups = ares_strdup(channel->lookups);
171
+ if (!options->lookups && channel->lookups) {
172
+ return ARES_ENOMEM;
173
+ }
174
+ }
175
+
176
+ if (channel->optmask & ARES_OPT_SORTLIST) {
177
+ options->sortlist = NULL;
178
+ if (channel->nsort) {
179
+ options->sortlist = ares_malloc(channel->nsort * sizeof(struct apattern));
180
+ if (!options->sortlist) {
181
+ return ARES_ENOMEM;
182
+ }
183
+ for (i = 0; i < channel->nsort; i++) {
184
+ options->sortlist[i] = channel->sortlist[i];
185
+ }
186
+ }
187
+ options->nsort = (int)channel->nsort;
188
+ }
189
+
190
+ if (channel->optmask & ARES_OPT_RESOLVCONF) {
191
+ options->resolvconf_path = ares_strdup(channel->resolvconf_path);
192
+ if (!options->resolvconf_path) {
193
+ return ARES_ENOMEM;
194
+ }
195
+ }
196
+
197
+ if (channel->optmask & ARES_OPT_HOSTS_FILE) {
198
+ options->hosts_path = ares_strdup(channel->hosts_path);
199
+ if (!options->hosts_path) {
200
+ return ARES_ENOMEM;
201
+ }
202
+ }
203
+
204
+ if (channel->optmask & ARES_OPT_SOCK_SNDBUF &&
205
+ channel->socket_send_buffer_size > 0) {
206
+ options->socket_send_buffer_size = channel->socket_send_buffer_size;
207
+ }
208
+
209
+ if (channel->optmask & ARES_OPT_SOCK_RCVBUF &&
210
+ channel->socket_receive_buffer_size > 0) {
211
+ options->socket_receive_buffer_size = channel->socket_receive_buffer_size;
212
+ }
213
+
214
+ if (channel->optmask & ARES_OPT_EDNSPSZ) {
215
+ options->ednspsz = (int)channel->ednspsz;
216
+ }
217
+
218
+ if (channel->optmask & ARES_OPT_UDP_MAX_QUERIES) {
219
+ options->udp_max_queries = (int)channel->udp_max_queries;
220
+ }
221
+
222
+ if (channel->optmask & ARES_OPT_QUERY_CACHE) {
223
+ options->qcache_max_ttl = channel->qcache_max_ttl;
224
+ }
225
+
226
+ if (channel->optmask & ARES_OPT_EVENT_THREAD) {
227
+ options->evsys = channel->evsys;
228
+ }
229
+
230
+ /* Set options for server failover behavior */
231
+ if (channel->optmask & ARES_OPT_SERVER_FAILOVER) {
232
+ options->server_failover_opts.retry_chance = channel->server_retry_chance;
233
+ options->server_failover_opts.retry_delay = channel->server_retry_delay;
234
+ }
235
+
236
+ *optmask = (int)channel->optmask;
237
+
238
+ return ARES_SUCCESS;
239
+ }
240
+
241
+ static ares_status_t ares_init_options_servers(ares_channel_t *channel,
242
+ const struct in_addr *servers,
243
+ size_t nservers)
244
+ {
245
+ ares_llist_t *slist = NULL;
246
+ ares_status_t status;
247
+
248
+ status = ares_in_addr_to_sconfig_llist(servers, nservers, &slist);
249
+ if (status != ARES_SUCCESS) {
250
+ return status; /* LCOV_EXCL_LINE: OutOfMemory */
251
+ }
252
+
253
+ status = ares_servers_update(channel, slist, ARES_TRUE);
254
+
255
+ ares_llist_destroy(slist);
256
+
257
+ return status;
258
+ }
259
+
260
+ ares_status_t ares_init_by_options(ares_channel_t *channel,
261
+ const struct ares_options *options,
262
+ int optmask)
263
+ {
264
+ size_t i;
265
+
266
+ if (channel == NULL) {
267
+ return ARES_ENODATA; /* LCOV_EXCL_LINE: DefensiveCoding */
268
+ }
269
+
270
+ if (options == NULL) {
271
+ if (optmask != 0) {
272
+ return ARES_ENODATA; /* LCOV_EXCL_LINE: DefensiveCoding */
273
+ }
274
+ return ARES_SUCCESS;
275
+ }
276
+
277
+ /* Easy stuff. */
278
+
279
+ /* Event Thread requires threading support and is incompatible with socket
280
+ * state callbacks */
281
+ if (optmask & ARES_OPT_EVENT_THREAD) {
282
+ if (!ares_threadsafety()) {
283
+ return ARES_ENOTIMP;
284
+ }
285
+ if (optmask & ARES_OPT_SOCK_STATE_CB) {
286
+ return ARES_EFORMERR;
287
+ }
288
+ channel->evsys = options->evsys;
289
+ }
290
+
291
+ if (optmask & ARES_OPT_FLAGS) {
292
+ channel->flags = (unsigned int)options->flags;
293
+ }
294
+
295
+ if (optmask & ARES_OPT_TIMEOUTMS) {
296
+ /* Apparently some integrations were passing -1 to tell c-ares to use
297
+ * the default instead of just omitting the optmask */
298
+ if (options->timeout <= 0) {
299
+ optmask &= ~(ARES_OPT_TIMEOUTMS);
300
+ } else {
301
+ channel->timeout = (unsigned int)options->timeout;
302
+ }
303
+ } else if (optmask & ARES_OPT_TIMEOUT) {
304
+ optmask &= ~(ARES_OPT_TIMEOUT);
305
+ /* Apparently some integrations were passing -1 to tell c-ares to use
306
+ * the default instead of just omitting the optmask */
307
+ if (options->timeout > 0) {
308
+ /* Convert to milliseconds */
309
+ optmask |= ARES_OPT_TIMEOUTMS;
310
+ channel->timeout = (unsigned int)options->timeout * 1000;
311
+ }
312
+ }
313
+
314
+ if (optmask & ARES_OPT_TRIES) {
315
+ if (options->tries <= 0) {
316
+ optmask &= ~(ARES_OPT_TRIES);
317
+ } else {
318
+ channel->tries = (size_t)options->tries;
319
+ }
320
+ }
321
+
322
+ if (optmask & ARES_OPT_NDOTS) {
323
+ if (options->ndots < 0) {
324
+ optmask &= ~(ARES_OPT_NDOTS);
325
+ } else {
326
+ channel->ndots = (size_t)options->ndots;
327
+ }
328
+ }
329
+
330
+ if (optmask & ARES_OPT_MAXTIMEOUTMS) {
331
+ if (options->maxtimeout <= 0) {
332
+ optmask &= ~(ARES_OPT_MAXTIMEOUTMS);
333
+ } else {
334
+ channel->maxtimeout = (size_t)options->maxtimeout;
335
+ }
336
+ }
337
+
338
+ if (optmask & ARES_OPT_ROTATE) {
339
+ channel->rotate = ARES_TRUE;
340
+ }
341
+
342
+ if (optmask & ARES_OPT_NOROTATE) {
343
+ channel->rotate = ARES_FALSE;
344
+ }
345
+
346
+ if (optmask & ARES_OPT_UDP_PORT) {
347
+ channel->udp_port = options->udp_port;
348
+ }
349
+
350
+ if (optmask & ARES_OPT_TCP_PORT) {
351
+ channel->tcp_port = options->tcp_port;
352
+ }
353
+
354
+ if (optmask & ARES_OPT_SOCK_STATE_CB) {
355
+ channel->sock_state_cb = options->sock_state_cb;
356
+ channel->sock_state_cb_data = options->sock_state_cb_data;
357
+ }
358
+
359
+ if (optmask & ARES_OPT_SOCK_SNDBUF) {
360
+ if (options->socket_send_buffer_size <= 0) {
361
+ optmask &= ~(ARES_OPT_SOCK_SNDBUF);
362
+ } else {
363
+ channel->socket_send_buffer_size = options->socket_send_buffer_size;
364
+ }
365
+ }
366
+
367
+ if (optmask & ARES_OPT_SOCK_RCVBUF) {
368
+ if (options->socket_receive_buffer_size <= 0) {
369
+ optmask &= ~(ARES_OPT_SOCK_RCVBUF);
370
+ } else {
371
+ channel->socket_receive_buffer_size = options->socket_receive_buffer_size;
372
+ }
373
+ }
374
+
375
+ if (optmask & ARES_OPT_EDNSPSZ) {
376
+ if (options->ednspsz <= 0) {
377
+ optmask &= ~(ARES_OPT_EDNSPSZ);
378
+ } else {
379
+ channel->ednspsz = (size_t)options->ednspsz;
380
+ }
381
+ }
382
+
383
+ /* Copy the domains, if given. Keep channel->ndomains consistent so
384
+ * we can clean up in case of error.
385
+ */
386
+ if (optmask & ARES_OPT_DOMAINS && options->ndomains > 0) {
387
+ channel->domains =
388
+ ares_malloc_zero((size_t)options->ndomains * sizeof(char *));
389
+ if (!channel->domains) {
390
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
391
+ }
392
+ channel->ndomains = (size_t)options->ndomains;
393
+ for (i = 0; i < (size_t)options->ndomains; i++) {
394
+ channel->domains[i] = ares_strdup(options->domains[i]);
395
+ if (!channel->domains[i]) {
396
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
397
+ }
398
+ }
399
+ }
400
+
401
+ /* Set lookups, if given. */
402
+ if (optmask & ARES_OPT_LOOKUPS) {
403
+ if (options->lookups == NULL) {
404
+ optmask &= ~(ARES_OPT_LOOKUPS);
405
+ } else {
406
+ channel->lookups = ares_strdup(options->lookups);
407
+ if (!channel->lookups) {
408
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
409
+ }
410
+ }
411
+ }
412
+
413
+ /* copy sortlist */
414
+ if (optmask & ARES_OPT_SORTLIST && options->nsort > 0) {
415
+ channel->nsort = (size_t)options->nsort;
416
+ channel->sortlist =
417
+ ares_malloc((size_t)options->nsort * sizeof(struct apattern));
418
+ if (!channel->sortlist) {
419
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
420
+ }
421
+ for (i = 0; i < (size_t)options->nsort; i++) {
422
+ channel->sortlist[i] = options->sortlist[i];
423
+ }
424
+ }
425
+
426
+ /* Set path for resolv.conf file, if given. */
427
+ if (optmask & ARES_OPT_RESOLVCONF) {
428
+ if (options->resolvconf_path == NULL) {
429
+ optmask &= ~(ARES_OPT_RESOLVCONF);
430
+ } else {
431
+ channel->resolvconf_path = ares_strdup(options->resolvconf_path);
432
+ if (channel->resolvconf_path == NULL) {
433
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
434
+ }
435
+ }
436
+ }
437
+
438
+ /* Set path for hosts file, if given. */
439
+ if (optmask & ARES_OPT_HOSTS_FILE) {
440
+ if (options->hosts_path == NULL) {
441
+ optmask &= ~(ARES_OPT_HOSTS_FILE);
442
+ } else {
443
+ channel->hosts_path = ares_strdup(options->hosts_path);
444
+ if (channel->hosts_path == NULL) {
445
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
446
+ }
447
+ }
448
+ }
449
+
450
+ if (optmask & ARES_OPT_UDP_MAX_QUERIES) {
451
+ if (options->udp_max_queries <= 0) {
452
+ optmask &= ~(ARES_OPT_UDP_MAX_QUERIES);
453
+ } else {
454
+ channel->udp_max_queries = (size_t)options->udp_max_queries;
455
+ }
456
+ }
457
+
458
+ /* As of c-ares 1.31.0, the Query Cache is on by default. The only way to
459
+ * disable it is to set options->qcache_max_ttl = 0 while specifying the
460
+ * ARES_OPT_QUERY_CACHE which will actually disable it completely. */
461
+ if (optmask & ARES_OPT_QUERY_CACHE) {
462
+ /* qcache_max_ttl is unsigned unlike the others */
463
+ channel->qcache_max_ttl = options->qcache_max_ttl;
464
+ } else {
465
+ optmask |= ARES_OPT_QUERY_CACHE;
466
+ channel->qcache_max_ttl = 3600;
467
+ }
468
+
469
+ /* Initialize the ipv4 servers if provided */
470
+ if (optmask & ARES_OPT_SERVERS) {
471
+ if (options->nservers <= 0) {
472
+ optmask &= ~(ARES_OPT_SERVERS);
473
+ } else {
474
+ ares_status_t status;
475
+ status = ares_init_options_servers(channel, options->servers,
476
+ (size_t)options->nservers);
477
+ if (status != ARES_SUCCESS) {
478
+ return status; /* LCOV_EXCL_LINE: OutOfMemory */
479
+ }
480
+ }
481
+ }
482
+
483
+ /* Set fields for server failover behavior */
484
+ if (optmask & ARES_OPT_SERVER_FAILOVER) {
485
+ channel->server_retry_chance = options->server_failover_opts.retry_chance;
486
+ channel->server_retry_delay = options->server_failover_opts.retry_delay;
487
+ }
488
+
489
+ channel->optmask = (unsigned int)optmask;
490
+
491
+ return ARES_SUCCESS;
492
+ }
@@ -0,0 +1,179 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 2019 Andrew Selivanov
4
+ * Copyright (c) 2023 Brad House
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
+
29
+ #ifdef HAVE_NETINET_IN_H
30
+ # include <netinet/in.h>
31
+ #endif
32
+ #ifdef HAVE_NETDB_H
33
+ # include <netdb.h>
34
+ #endif
35
+ #ifdef HAVE_ARPA_INET_H
36
+ # include <arpa/inet.h>
37
+ #endif
38
+
39
+ #ifdef HAVE_STRINGS_H
40
+ # include <strings.h>
41
+ #endif
42
+
43
+ #ifdef HAVE_LIMITS_H
44
+ # include <limits.h>
45
+ #endif
46
+
47
+
48
+ ares_status_t ares_parse_into_addrinfo(const ares_dns_record_t *dnsrec,
49
+ ares_bool_t cname_only_is_enodata,
50
+ unsigned short port,
51
+ struct ares_addrinfo *ai)
52
+ {
53
+ ares_status_t status;
54
+ size_t i;
55
+ size_t ancount;
56
+ const char *hostname = NULL;
57
+ ares_bool_t got_a = ARES_FALSE;
58
+ ares_bool_t got_aaaa = ARES_FALSE;
59
+ ares_bool_t got_cname = ARES_FALSE;
60
+ struct ares_addrinfo_cname *cnames = NULL;
61
+ struct ares_addrinfo_node *nodes = NULL;
62
+
63
+ /* Save question hostname */
64
+ status = ares_dns_record_query_get(dnsrec, 0, &hostname, NULL, NULL);
65
+ if (status != ARES_SUCCESS) {
66
+ goto done; /* LCOV_EXCL_LINE: DefensiveCoding */
67
+ }
68
+
69
+ ancount = ares_dns_record_rr_cnt(dnsrec, ARES_SECTION_ANSWER);
70
+ if (ancount == 0) {
71
+ status = ARES_ENODATA;
72
+ goto done;
73
+ }
74
+
75
+ for (i = 0; i < ancount; i++) {
76
+ ares_dns_rec_type_t rtype;
77
+ const ares_dns_rr_t *rr =
78
+ ares_dns_record_rr_get_const(dnsrec, ARES_SECTION_ANSWER, i);
79
+
80
+ if (ares_dns_rr_get_class(rr) != ARES_CLASS_IN) {
81
+ continue;
82
+ }
83
+
84
+ rtype = ares_dns_rr_get_type(rr);
85
+
86
+ /* Issue #683
87
+ * Old code did this hostname sanity check, however it appears this is
88
+ * flawed logic. Other resolvers don't do this sanity check. Leaving
89
+ * this code commented out for future reference.
90
+ *
91
+ * rname = ares_dns_rr_get_name(rr);
92
+ * if ((rtype == ARES_REC_TYPE_A || rtype == ARES_REC_TYPE_AAAA) &&
93
+ * !ares_strcaseeq(rname, hostname)) {
94
+ * continue;
95
+ * }
96
+ */
97
+
98
+ if (rtype == ARES_REC_TYPE_CNAME) {
99
+ struct ares_addrinfo_cname *cname;
100
+
101
+ got_cname = ARES_TRUE;
102
+ /* replace hostname with data from cname
103
+ * SA: Seems wrong as it introduces order dependency. */
104
+ hostname = ares_dns_rr_get_str(rr, ARES_RR_CNAME_CNAME);
105
+
106
+ cname = ares_append_addrinfo_cname(&cnames);
107
+ if (cname == NULL) {
108
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
109
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
110
+ }
111
+ cname->ttl = (int)ares_dns_rr_get_ttl(rr);
112
+ cname->alias = ares_strdup(ares_dns_rr_get_name(rr));
113
+ if (cname->alias == NULL) {
114
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
115
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
116
+ }
117
+ cname->name = ares_strdup(hostname);
118
+ if (cname->name == NULL) {
119
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
120
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
121
+ }
122
+ } else if (rtype == ARES_REC_TYPE_A) {
123
+ got_a = ARES_TRUE;
124
+ status =
125
+ ares_append_ai_node(AF_INET, port, ares_dns_rr_get_ttl(rr),
126
+ ares_dns_rr_get_addr(rr, ARES_RR_A_ADDR), &nodes);
127
+ if (status != ARES_SUCCESS) {
128
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
129
+ }
130
+ } else if (rtype == ARES_REC_TYPE_AAAA) {
131
+ got_aaaa = ARES_TRUE;
132
+ status = ares_append_ai_node(AF_INET6, port, ares_dns_rr_get_ttl(rr),
133
+ ares_dns_rr_get_addr6(rr, ARES_RR_AAAA_ADDR),
134
+ &nodes);
135
+ if (status != ARES_SUCCESS) {
136
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
137
+ }
138
+ } else {
139
+ continue;
140
+ }
141
+ }
142
+
143
+ if (!got_a && !got_aaaa &&
144
+ (!got_cname || (got_cname && cname_only_is_enodata))) {
145
+ status = ARES_ENODATA;
146
+ goto done;
147
+ }
148
+
149
+ /* save the hostname as ai->name */
150
+ if (ai->name == NULL || !ares_strcaseeq(ai->name, hostname)) {
151
+ ares_free(ai->name);
152
+ ai->name = ares_strdup(hostname);
153
+ if (ai->name == NULL) {
154
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
155
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
156
+ }
157
+ }
158
+
159
+ if (got_a || got_aaaa) {
160
+ ares_addrinfo_cat_nodes(&ai->nodes, nodes);
161
+ nodes = NULL;
162
+ }
163
+
164
+ if (got_cname) {
165
+ ares_addrinfo_cat_cnames(&ai->cnames, cnames);
166
+ cnames = NULL;
167
+ }
168
+
169
+ done:
170
+ ares_freeaddrinfo_cnames(cnames);
171
+ ares_freeaddrinfo_nodes(nodes);
172
+
173
+ /* compatibility */
174
+ if (status == ARES_EBADNAME) {
175
+ status = ARES_EBADRESP;
176
+ }
177
+
178
+ return status;
179
+ }