visaljs 0.0.9 → 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 (232) hide show
  1. package/README.md +12 -4
  2. package/THIRD_PARTY_LICENSES +31 -1
  3. package/cli.js +3745 -890
  4. package/node/include/js_node.h +12 -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 +405 -94
  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/http_chars.ts +22 -0
  31. package/node/prelude/internal/perf_histogram.js +1 -1
  32. package/node/prelude/internal/process_more.js +32 -17
  33. package/node/prelude/internal/process_signals.js +8 -2
  34. package/node/prelude/internal/punycode.ts +163 -0
  35. package/node/prelude/internal/readline.js +648 -274
  36. package/node/prelude/internal/readline_editor.js +1240 -0
  37. package/node/prelude/internal/string_width.js +43 -0
  38. package/node/prelude/internal/tls/common.js +145 -33
  39. package/node/prelude/internal/tls/wrap.js +182 -49
  40. package/node/prelude/internal/tls/x509.js +4 -1
  41. package/node/prelude/internal/udp.js +177 -0
  42. package/node/prelude/net.js +30 -14
  43. package/node/prelude/os.js +24 -6
  44. package/node/prelude/perf_hooks.js +37 -2
  45. package/node/prelude/punycode.js +2 -130
  46. package/node/prelude/readline.js +113 -4
  47. package/node/prelude/readline_promises.js +56 -32
  48. package/node/prelude/tls.js +21 -4
  49. package/node/prelude/util.js +3 -16
  50. package/node/src/host_dns.c +623 -0
  51. package/node/src/host_http.c +12 -0
  52. package/node/src/host_net.c +46 -0
  53. package/node/src/host_os.c +1 -6
  54. package/node/src/host_sys.c +79 -0
  55. package/node/src/host_udp.c +418 -0
  56. package/node/third_party/c-ares/LICENSE.md +24 -0
  57. package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
  58. package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
  59. package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
  60. package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
  61. package/node/third_party/c-ares/include/ares.h +1237 -0
  62. package/node/third_party/c-ares/include/ares_build.h +202 -0
  63. package/node/third_party/c-ares/include/ares_dns.h +127 -0
  64. package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
  65. package/node/third_party/c-ares/include/ares_nameser.h +510 -0
  66. package/node/third_party/c-ares/include/ares_version.h +47 -0
  67. package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
  68. package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
  69. package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
  70. package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
  71. package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
  72. package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
  73. package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
  74. package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
  75. package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
  76. package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
  77. package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
  78. package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
  79. package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
  80. package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
  81. package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
  82. package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
  83. package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
  84. package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
  85. package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
  86. package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
  87. package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
  88. package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
  89. package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
  90. package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
  91. package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
  92. package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
  93. package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
  94. package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
  95. package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
  96. package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
  97. package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
  98. package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
  99. package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
  100. package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
  101. package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
  102. package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
  103. package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
  104. package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
  105. package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
  106. package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
  107. package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
  108. package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
  109. package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
  110. package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
  111. package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
  112. package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
  113. package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
  114. package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
  115. package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
  116. package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
  117. package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
  118. package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
  119. package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
  120. package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
  121. package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
  122. package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
  123. package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
  124. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  125. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  126. package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
  127. package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
  128. package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
  129. package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
  130. package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
  131. package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
  132. package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
  133. package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
  134. package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
  135. package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
  136. package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
  137. package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
  138. package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
  139. package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
  140. package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
  141. package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
  142. package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
  143. package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
  144. package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
  145. package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
  146. package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
  147. package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
  148. package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
  149. package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
  150. package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
  151. package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
  152. package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
  153. package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
  154. package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
  155. package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
  156. package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
  157. package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  158. package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  159. package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  160. package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  161. package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  162. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  163. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  164. package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  165. package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  166. package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  167. package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  168. package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
  169. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
  170. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
  171. package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
  172. package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
  173. package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
  174. package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
  175. package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
  176. package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
  177. package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
  178. package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
  179. package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
  180. package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  181. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
  182. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
  183. package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
  184. package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
  185. package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
  186. package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
  187. package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
  188. package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
  189. package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
  190. package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
  191. package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
  192. package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
  193. package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
  194. package/package.json +1 -1
  195. package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
  196. package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
  197. package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
  198. package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
  199. package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
  200. package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
  201. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  202. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  203. package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
  204. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  205. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  206. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  207. package/runtime/include/js_buffer.h +185 -0
  208. package/runtime/include/js_builtins.h +58 -0
  209. package/runtime/include/js_crypto.h +11 -0
  210. package/runtime/include/js_exception.h +3 -0
  211. package/runtime/include/js_function.h +1 -1
  212. package/runtime/include/js_gc.h +13 -10
  213. package/runtime/include/js_jobs.h +2 -0
  214. package/runtime/include/js_object.h +79 -3
  215. package/runtime/include/js_ops.h +27 -0
  216. package/runtime/include/js_runtime.h +1 -0
  217. package/runtime/include/js_web.h +0 -3
  218. package/runtime/include/jscontext.h +8 -0
  219. package/runtime/src/builtins.c +17 -4
  220. package/runtime/src/crypto_internal.h +1 -0
  221. package/runtime/src/crypto_subtle.c +66 -7
  222. package/runtime/src/crypto_tls.c +265 -19
  223. package/runtime/src/function.c +37 -10
  224. package/runtime/src/gc.c +76 -93
  225. package/runtime/src/inspect.c +18 -1
  226. package/runtime/src/iterator.c +5 -1
  227. package/runtime/src/jobs.c +37 -22
  228. package/runtime/src/object.c +91 -8
  229. package/runtime/src/os.c +16 -6
  230. package/runtime/src/os.h +2 -0
  231. package/runtime/src/process.c +97 -10
  232. package/runtime/src/typedarray.c +23 -0
@@ -0,0 +1,38 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 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
+
28
+ #include "ares_private.h"
29
+ #include "ares_getenv.h"
30
+
31
+ #ifndef HAVE_GETENV
32
+
33
+ char *ares_getenv(const char *name)
34
+ {
35
+ return NULL;
36
+ }
37
+
38
+ #endif
@@ -0,0 +1,34 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 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
+ #ifndef HEADER_CARES_GETENV_H
28
+ #define HEADER_CARES_GETENV_H
29
+
30
+ #ifndef HAVE_GETENV
31
+ extern char *ares_getenv(const char *name);
32
+ #endif
33
+
34
+ #endif /* HEADER_CARES_GETENV_H */
@@ -0,0 +1,229 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 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
+
28
+ #include "ares_private.h"
29
+
30
+ #ifdef HAVE_NETINET_IN_H
31
+ # include <netinet/in.h>
32
+ #endif
33
+ #ifdef HAVE_NETDB_H
34
+ # include <netdb.h>
35
+ #endif
36
+ #ifdef HAVE_ARPA_INET_H
37
+ # include <arpa/inet.h>
38
+ #endif
39
+
40
+ #include "ares_nameser.h"
41
+ #include "ares_inet_net_pton.h"
42
+
43
+ struct addr_query {
44
+ /* Arguments passed to ares_gethostbyaddr() */
45
+ ares_channel_t *channel;
46
+ struct ares_addr addr;
47
+ ares_host_callback callback;
48
+ void *arg;
49
+ char *lookups; /* duplicate memory from channel for ares_reinit() */
50
+ const char *remaining_lookups;
51
+ size_t timeouts;
52
+ };
53
+
54
+ static void next_lookup(struct addr_query *aquery);
55
+ static void addr_callback(void *arg, ares_status_t status, size_t timeouts,
56
+ const ares_dns_record_t *dnsrec);
57
+ static void end_aquery(struct addr_query *aquery, ares_status_t status,
58
+ struct hostent *host);
59
+ static ares_status_t file_lookup(ares_channel_t *channel,
60
+ const struct ares_addr *addr,
61
+ struct hostent **host);
62
+
63
+ void ares_gethostbyaddr_nolock(ares_channel_t *channel, const void *addr,
64
+ int addrlen, int family,
65
+ ares_host_callback callback, void *arg)
66
+ {
67
+ struct addr_query *aquery;
68
+
69
+ if (family != AF_INET && family != AF_INET6) {
70
+ callback(arg, ARES_ENOTIMP, 0, NULL);
71
+ return;
72
+ }
73
+
74
+ if ((family == AF_INET && addrlen != sizeof(aquery->addr.addr.addr4)) ||
75
+ (family == AF_INET6 && addrlen != sizeof(aquery->addr.addr.addr6))) {
76
+ callback(arg, ARES_ENOTIMP, 0, NULL);
77
+ return;
78
+ }
79
+
80
+ aquery = ares_malloc(sizeof(struct addr_query));
81
+ if (!aquery) {
82
+ callback(arg, ARES_ENOMEM, 0, NULL);
83
+ return;
84
+ }
85
+ aquery->lookups = ares_strdup(channel->lookups);
86
+ if (aquery->lookups == NULL) {
87
+ /* LCOV_EXCL_START: OutOfMemory */
88
+ ares_free(aquery);
89
+ callback(arg, ARES_ENOMEM, 0, NULL);
90
+ return;
91
+ /* LCOV_EXCL_STOP */
92
+ }
93
+ aquery->channel = channel;
94
+ if (family == AF_INET) {
95
+ memcpy(&aquery->addr.addr.addr4, addr, sizeof(aquery->addr.addr.addr4));
96
+ } else {
97
+ memcpy(&aquery->addr.addr.addr6, addr, sizeof(aquery->addr.addr.addr6));
98
+ }
99
+ aquery->addr.family = family;
100
+ aquery->callback = callback;
101
+ aquery->arg = arg;
102
+ aquery->remaining_lookups = aquery->lookups;
103
+ aquery->timeouts = 0;
104
+
105
+ next_lookup(aquery);
106
+ }
107
+
108
+ void ares_gethostbyaddr(ares_channel_t *channel, const void *addr, int addrlen,
109
+ int family, ares_host_callback callback, void *arg)
110
+ {
111
+ if (channel == NULL) {
112
+ return;
113
+ }
114
+ ares_channel_lock(channel);
115
+ ares_gethostbyaddr_nolock(channel, addr, addrlen, family, callback, arg);
116
+ ares_channel_unlock(channel);
117
+ }
118
+
119
+ static void next_lookup(struct addr_query *aquery)
120
+ {
121
+ const char *p;
122
+ ares_status_t status;
123
+ struct hostent *host = NULL;
124
+ char *name;
125
+
126
+ for (p = aquery->remaining_lookups; *p; p++) {
127
+ switch (*p) {
128
+ case 'b':
129
+ name = ares_dns_addr_to_ptr(&aquery->addr);
130
+ if (name == NULL) {
131
+ end_aquery(aquery, ARES_ENOMEM,
132
+ NULL); /* LCOV_EXCL_LINE: OutOfMemory */
133
+ return; /* LCOV_EXCL_LINE: OutOfMemory */
134
+ }
135
+ aquery->remaining_lookups = p + 1;
136
+ ares_query_nolock(aquery->channel, name, ARES_CLASS_IN,
137
+ ARES_REC_TYPE_PTR, addr_callback, aquery, NULL);
138
+ ares_free(name);
139
+ return;
140
+ case 'f':
141
+ status = file_lookup(aquery->channel, &aquery->addr, &host);
142
+
143
+ /* this status check below previously checked for !ARES_ENOTFOUND,
144
+ but we should not assume that this single error code is the one
145
+ that can occur, as that is in fact no longer the case */
146
+ if (status == ARES_SUCCESS) {
147
+ end_aquery(aquery, status, host);
148
+ return;
149
+ }
150
+ break;
151
+ default:
152
+ break;
153
+ }
154
+ }
155
+ end_aquery(aquery, ARES_ENOTFOUND, NULL);
156
+ }
157
+
158
+ static void addr_callback(void *arg, ares_status_t status, size_t timeouts,
159
+ const ares_dns_record_t *dnsrec)
160
+ {
161
+ struct addr_query *aquery = (struct addr_query *)arg;
162
+ struct hostent *host;
163
+ size_t addrlen;
164
+
165
+ aquery->timeouts += timeouts;
166
+ if (status == ARES_SUCCESS) {
167
+ if (aquery->addr.family == AF_INET) {
168
+ addrlen = sizeof(aquery->addr.addr.addr4);
169
+ status = ares_parse_ptr_reply_dnsrec(dnsrec, &aquery->addr.addr.addr4,
170
+ (int)addrlen, AF_INET, &host);
171
+ } else {
172
+ addrlen = sizeof(aquery->addr.addr.addr6);
173
+ status = ares_parse_ptr_reply_dnsrec(dnsrec, &aquery->addr.addr.addr6,
174
+ (int)addrlen, AF_INET6, &host);
175
+ }
176
+ end_aquery(aquery, status, host);
177
+ } else if (status == ARES_EDESTRUCTION || status == ARES_ECANCELLED) {
178
+ end_aquery(aquery, status, NULL);
179
+ } else {
180
+ next_lookup(aquery);
181
+ }
182
+ }
183
+
184
+ static void end_aquery(struct addr_query *aquery, ares_status_t status,
185
+ struct hostent *host)
186
+ {
187
+ aquery->callback(aquery->arg, (int)status, (int)aquery->timeouts, host);
188
+ if (host) {
189
+ ares_free_hostent(host);
190
+ }
191
+ ares_free(aquery->lookups);
192
+ ares_free(aquery);
193
+ }
194
+
195
+ static ares_status_t file_lookup(ares_channel_t *channel,
196
+ const struct ares_addr *addr,
197
+ struct hostent **host)
198
+ {
199
+ char ipaddr[INET6_ADDRSTRLEN];
200
+ const void *ptr = NULL;
201
+ const ares_hosts_entry_t *entry;
202
+ ares_status_t status;
203
+
204
+ if (addr->family == AF_INET) {
205
+ ptr = &addr->addr.addr4;
206
+ } else if (addr->family == AF_INET6) {
207
+ ptr = &addr->addr.addr6;
208
+ }
209
+
210
+ if (ptr == NULL) {
211
+ return ARES_ENOTFOUND;
212
+ }
213
+
214
+ if (!ares_inet_ntop(addr->family, ptr, ipaddr, sizeof(ipaddr))) {
215
+ return ARES_ENOTFOUND;
216
+ }
217
+
218
+ status = ares_hosts_search_ipaddr(channel, ARES_FALSE, ipaddr, &entry);
219
+ if (status != ARES_SUCCESS) {
220
+ return status;
221
+ }
222
+
223
+ status = ares_hosts_entry_to_hostent(entry, addr->family, host);
224
+ if (status != ARES_SUCCESS) {
225
+ return status; /* LCOV_EXCL_LINE: OutOfMemory */
226
+ }
227
+
228
+ return ARES_SUCCESS;
229
+ }
@@ -0,0 +1,341 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998, 2011, 2013 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
+
28
+ #include "ares_private.h"
29
+
30
+ #ifdef HAVE_NETINET_IN_H
31
+ # include <netinet/in.h>
32
+ #endif
33
+ #ifdef HAVE_NETDB_H
34
+ # include <netdb.h>
35
+ #endif
36
+ #ifdef HAVE_ARPA_INET_H
37
+ # include <arpa/inet.h>
38
+ #endif
39
+
40
+ #include "ares_nameser.h"
41
+
42
+ #ifdef HAVE_STRINGS_H
43
+ # include <strings.h>
44
+ #endif
45
+
46
+ #include "ares_inet_net_pton.h"
47
+
48
+ static void sort_addresses(const struct hostent *host,
49
+ const struct apattern *sortlist, size_t nsort);
50
+ static void sort6_addresses(const struct hostent *host,
51
+ const struct apattern *sortlist, size_t nsort);
52
+ static size_t get_address_index(const struct in_addr *addr,
53
+ const struct apattern *sortlist, size_t nsort);
54
+ static size_t get6_address_index(const struct ares_in6_addr *addr,
55
+ const struct apattern *sortlist, size_t nsort);
56
+
57
+ struct host_query {
58
+ ares_host_callback callback;
59
+ void *arg;
60
+ ares_channel_t *channel;
61
+ };
62
+
63
+ static void ares_gethostbyname_callback(void *arg, int status, int timeouts,
64
+ struct ares_addrinfo *result)
65
+ {
66
+ struct hostent *hostent = NULL;
67
+ struct host_query *ghbn_arg = arg;
68
+
69
+ if (status == ARES_SUCCESS) {
70
+ status = (int)ares_addrinfo2hostent(result, AF_UNSPEC, &hostent);
71
+ }
72
+
73
+ /* addrinfo2hostent will only return ENODATA if there are no addresses _and_
74
+ * no cname/aliases. However, gethostbyname will return ENODATA even if there
75
+ * is cname/alias data */
76
+ if (status == ARES_SUCCESS && hostent &&
77
+ (!hostent->h_addr_list || !hostent->h_addr_list[0])) {
78
+ status = ARES_ENODATA;
79
+ }
80
+
81
+ if (status == ARES_SUCCESS && ghbn_arg->channel->nsort && hostent) {
82
+ if (hostent->h_addrtype == AF_INET6) {
83
+ sort6_addresses(hostent, ghbn_arg->channel->sortlist,
84
+ ghbn_arg->channel->nsort);
85
+ }
86
+ if (hostent->h_addrtype == AF_INET) {
87
+ sort_addresses(hostent, ghbn_arg->channel->sortlist,
88
+ ghbn_arg->channel->nsort);
89
+ }
90
+ }
91
+
92
+ ghbn_arg->callback(ghbn_arg->arg, status, timeouts, hostent);
93
+
94
+ ares_freeaddrinfo(result);
95
+ ares_free(ghbn_arg);
96
+ ares_free_hostent(hostent);
97
+ }
98
+
99
+ void ares_gethostbyname(ares_channel_t *channel, const char *name, int family,
100
+ ares_host_callback callback, void *arg)
101
+ {
102
+ struct ares_addrinfo_hints hints;
103
+ struct host_query *ghbn_arg;
104
+
105
+ if (channel == NULL) {
106
+ return;
107
+ }
108
+
109
+ if (!callback) {
110
+ return;
111
+ }
112
+
113
+ memset(&hints, 0, sizeof(hints));
114
+ hints.ai_flags = ARES_AI_CANONNAME;
115
+ hints.ai_family = family;
116
+
117
+ ghbn_arg = ares_malloc(sizeof(*ghbn_arg));
118
+ if (!ghbn_arg) {
119
+ callback(arg, ARES_ENOMEM, 0, NULL);
120
+ return;
121
+ }
122
+
123
+ ghbn_arg->callback = callback;
124
+ ghbn_arg->arg = arg;
125
+ ghbn_arg->channel = channel;
126
+
127
+ /* NOTE: ares_getaddrinfo() locks the channel, we don't use the channel
128
+ * outside so no need to lock */
129
+ ares_getaddrinfo(channel, name, NULL, &hints, ares_gethostbyname_callback,
130
+ ghbn_arg);
131
+ }
132
+
133
+ static void sort_addresses(const struct hostent *host,
134
+ const struct apattern *sortlist, size_t nsort)
135
+ {
136
+ struct in_addr a1;
137
+ struct in_addr a2;
138
+ int i1;
139
+ int i2;
140
+ size_t ind1;
141
+ size_t ind2;
142
+
143
+ /* This is a simple insertion sort, not optimized at all. i1 walks
144
+ * through the address list, with the loop invariant that everything
145
+ * to the left of i1 is sorted. In the loop body, the value at i1 is moved
146
+ * back through the list (via i2) until it is in sorted order.
147
+ */
148
+ for (i1 = 0; host->h_addr_list[i1]; i1++) {
149
+ memcpy(&a1, host->h_addr_list[i1], sizeof(struct in_addr));
150
+ ind1 = get_address_index(&a1, sortlist, nsort);
151
+ for (i2 = i1 - 1; i2 >= 0; i2--) {
152
+ memcpy(&a2, host->h_addr_list[i2], sizeof(struct in_addr));
153
+ ind2 = get_address_index(&a2, sortlist, nsort);
154
+ if (ind2 <= ind1) {
155
+ break;
156
+ }
157
+ memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct in_addr));
158
+ }
159
+ memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct in_addr));
160
+ }
161
+ }
162
+
163
+ /* Find the first entry in sortlist which matches addr. Return nsort
164
+ * if none of them match.
165
+ */
166
+ static size_t get_address_index(const struct in_addr *addr,
167
+ const struct apattern *sortlist, size_t nsort)
168
+ {
169
+ size_t i;
170
+ struct ares_addr aaddr;
171
+
172
+ memset(&aaddr, 0, sizeof(aaddr));
173
+ aaddr.family = AF_INET;
174
+ memcpy(&aaddr.addr.addr4, addr, 4);
175
+
176
+ for (i = 0; i < nsort; i++) {
177
+ if (sortlist[i].addr.family != AF_INET) {
178
+ continue;
179
+ }
180
+
181
+ if (ares_subnet_match(&aaddr, &sortlist[i].addr, sortlist[i].mask)) {
182
+ break;
183
+ }
184
+ }
185
+
186
+ return i;
187
+ }
188
+
189
+ static void sort6_addresses(const struct hostent *host,
190
+ const struct apattern *sortlist, size_t nsort)
191
+ {
192
+ struct ares_in6_addr a1;
193
+ struct ares_in6_addr a2;
194
+ int i1;
195
+ int i2;
196
+ size_t ind1;
197
+ size_t ind2;
198
+
199
+ /* This is a simple insertion sort, not optimized at all. i1 walks
200
+ * through the address list, with the loop invariant that everything
201
+ * to the left of i1 is sorted. In the loop body, the value at i1 is moved
202
+ * back through the list (via i2) until it is in sorted order.
203
+ */
204
+ for (i1 = 0; host->h_addr_list[i1]; i1++) {
205
+ memcpy(&a1, host->h_addr_list[i1], sizeof(struct ares_in6_addr));
206
+ ind1 = get6_address_index(&a1, sortlist, nsort);
207
+ for (i2 = i1 - 1; i2 >= 0; i2--) {
208
+ memcpy(&a2, host->h_addr_list[i2], sizeof(struct ares_in6_addr));
209
+ ind2 = get6_address_index(&a2, sortlist, nsort);
210
+ if (ind2 <= ind1) {
211
+ break;
212
+ }
213
+ memcpy(host->h_addr_list[i2 + 1], &a2, sizeof(struct ares_in6_addr));
214
+ }
215
+ memcpy(host->h_addr_list[i2 + 1], &a1, sizeof(struct ares_in6_addr));
216
+ }
217
+ }
218
+
219
+ /* Find the first entry in sortlist which matches addr. Return nsort
220
+ * if none of them match.
221
+ */
222
+ static size_t get6_address_index(const struct ares_in6_addr *addr,
223
+ const struct apattern *sortlist, size_t nsort)
224
+ {
225
+ size_t i;
226
+ struct ares_addr aaddr;
227
+
228
+ memset(&aaddr, 0, sizeof(aaddr));
229
+ aaddr.family = AF_INET6;
230
+ memcpy(&aaddr.addr.addr6, addr, 16);
231
+
232
+ for (i = 0; i < nsort; i++) {
233
+ if (sortlist[i].addr.family != AF_INET6) {
234
+ continue;
235
+ }
236
+
237
+ if (ares_subnet_match(&aaddr, &sortlist[i].addr, sortlist[i].mask)) {
238
+ break;
239
+ }
240
+ }
241
+ return i;
242
+ }
243
+
244
+ static ares_status_t ares_hostent_localhost(const char *name, int family,
245
+ struct hostent **host_out)
246
+ {
247
+ ares_status_t status;
248
+ struct ares_addrinfo *ai = NULL;
249
+ struct ares_addrinfo_hints hints;
250
+
251
+ memset(&hints, 0, sizeof(hints));
252
+ hints.ai_family = family;
253
+
254
+ ai = ares_malloc_zero(sizeof(*ai));
255
+ if (ai == NULL) {
256
+ status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
257
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
258
+ }
259
+
260
+ status = ares_addrinfo_localhost(name, 0, &hints, ai);
261
+ if (status != ARES_SUCCESS) {
262
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
263
+ }
264
+
265
+ status = ares_addrinfo2hostent(ai, family, host_out);
266
+ if (status != ARES_SUCCESS) {
267
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
268
+ }
269
+
270
+ done:
271
+ ares_freeaddrinfo(ai);
272
+ return status;
273
+ }
274
+
275
+ /* I really have no idea why this is exposed as a public function, but since
276
+ * it is, we can't kill this legacy function. */
277
+ static ares_status_t ares_gethostbyname_file_int(ares_channel_t *channel,
278
+ const char *name, int family,
279
+ struct hostent **host)
280
+ {
281
+ const ares_hosts_entry_t *entry;
282
+ ares_status_t status;
283
+
284
+ /* We only take the channel to ensure that ares_init() been called. */
285
+ if (channel == NULL || name == NULL || host == NULL) {
286
+ /* Anything will do, really. This seems fine, and is consistent with
287
+ other error cases. */
288
+ if (host != NULL) {
289
+ *host = NULL;
290
+ }
291
+ return ARES_ENOTFOUND;
292
+ }
293
+
294
+ *host = NULL;
295
+
296
+ /* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */
297
+ if (ares_is_onion_domain(name)) {
298
+ return ARES_ENOTFOUND;
299
+ }
300
+
301
+ status = ares_hosts_search_host(channel, ARES_FALSE, name, &entry);
302
+ if (status != ARES_SUCCESS) {
303
+ goto done;
304
+ }
305
+
306
+ status = ares_hosts_entry_to_hostent(entry, family, host);
307
+ if (status != ARES_SUCCESS) {
308
+ goto done; /* LCOV_EXCL_LINE: OutOfMemory */
309
+ }
310
+
311
+ done:
312
+ /* RFC6761 section 6.3 #3 states that "Name resolution APIs and libraries
313
+ * SHOULD recognize localhost names as special and SHOULD always return the
314
+ * IP loopback address for address queries".
315
+ * We will also ignore ALL errors when trying to resolve localhost, such
316
+ * as permissions errors reading /etc/hosts or a malformed /etc/hosts.
317
+ *
318
+ * Also, just because the query itself returned success from /etc/hosts
319
+ * lookup doesn't mean it returned everything it needed to for all requested
320
+ * address families. As long as we're not on a critical out of memory
321
+ * condition pass it through to fill in any other address classes. */
322
+ if (status != ARES_ENOMEM && ares_is_localhost(name)) {
323
+ return ares_hostent_localhost(name, family, host);
324
+ }
325
+
326
+ return status;
327
+ }
328
+
329
+ int ares_gethostbyname_file(ares_channel_t *channel, const char *name,
330
+ int family, struct hostent **host)
331
+ {
332
+ ares_status_t status;
333
+ if (channel == NULL) {
334
+ return ARES_ENOTFOUND;
335
+ }
336
+
337
+ ares_channel_lock(channel);
338
+ status = ares_gethostbyname_file_int(channel, name, family, host);
339
+ ares_channel_unlock(channel);
340
+ return (int)status;
341
+ }