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,642 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 Massachusetts Institute of Technology
4
+ * Copyright (c) 2007 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_SYS_PARAM_H
31
+ # include <sys/param.h>
32
+ #endif
33
+
34
+ #ifdef HAVE_NETINET_IN_H
35
+ # include <netinet/in.h>
36
+ #endif
37
+
38
+ #ifdef HAVE_NETDB_H
39
+ # include <netdb.h>
40
+ #endif
41
+
42
+ #ifdef HAVE_ARPA_INET_H
43
+ # include <arpa/inet.h>
44
+ #endif
45
+
46
+ #if defined(ANDROID) || defined(__ANDROID__)
47
+ # include <sys/system_properties.h>
48
+ # include "ares_android.h"
49
+ /* From the Bionic sources */
50
+ # define DNS_PROP_NAME_PREFIX "net.dns"
51
+ # define MAX_DNS_PROPERTIES 8
52
+ #endif
53
+
54
+ #if defined(CARES_USE_LIBRESOLV)
55
+ # include <resolv.h>
56
+ #endif
57
+
58
+ #include "ares_inet_net_pton.h"
59
+
60
+
61
+ #if defined(__MVS__)
62
+ static ares_status_t ares_init_sysconfig_mvs(const ares_channel_t *channel,
63
+ ares_sysconfig_t *sysconfig)
64
+ {
65
+ struct __res_state *res = 0;
66
+ size_t count4;
67
+ size_t count6;
68
+ int i;
69
+ __STATEEXTIPV6 *v6;
70
+ arse__llist_t *sconfig = NULL;
71
+ ares_status_t status;
72
+
73
+ if (0 == res) {
74
+ int rc = res_init();
75
+ while (rc == -1 && h_errno == TRY_AGAIN) {
76
+ rc = res_init();
77
+ }
78
+ if (rc == -1) {
79
+ return ARES_ENOMEM;
80
+ }
81
+ res = __res();
82
+ }
83
+
84
+ v6 = res->__res_extIPv6;
85
+ if (res->nscount > 0) {
86
+ count4 = (size_t)res->nscount;
87
+ }
88
+
89
+ if (v6 && v6->__stat_nscount > 0) {
90
+ count6 = (size_t)v6->__stat_nscount;
91
+ } else {
92
+ count6 = 0;
93
+ }
94
+
95
+ for (i = 0; i < count4; i++) {
96
+ struct sockaddr_in *addr_in = &(res->nsaddr_list[i]);
97
+ struct ares_addr addr;
98
+
99
+ addr.addr.addr4.s_addr = addr_in->sin_addr.s_addr;
100
+ addr.family = AF_INET;
101
+
102
+ status = ares_sconfig_append(channel, &sysconfig->sconfig, &addr,
103
+ htons(addr_in->sin_port),
104
+ htons(addr_in->sin_port), NULL);
105
+
106
+ if (status != ARES_SUCCESS) {
107
+ return status;
108
+ }
109
+ }
110
+
111
+ for (i = 0; i < count6; i++) {
112
+ struct sockaddr_in6 *addr_in = &(v6->__stat_nsaddr_list[i]);
113
+ struct ares_addr addr;
114
+
115
+ addr.family = AF_INET6;
116
+ memcpy(&(addr.addr.addr6), &(addr_in->sin6_addr),
117
+ sizeof(addr_in->sin6_addr));
118
+
119
+ status = ares_sconfig_append(channel, &sysconfig->sconfig, &addr,
120
+ htons(addr_in->sin_port),
121
+ htons(addr_in->sin_port), NULL);
122
+
123
+ if (status != ARES_SUCCESS) {
124
+ return status;
125
+ }
126
+ }
127
+
128
+ return ARES_SUCCESS;
129
+ }
130
+ #endif
131
+
132
+ #if defined(__riscos__)
133
+ static ares_status_t ares_init_sysconfig_riscos(const ares_channel_t *channel,
134
+ ares_sysconfig_t *sysconfig)
135
+ {
136
+ char *line;
137
+ ares_status_t status = ARES_SUCCESS;
138
+
139
+ /* Under RISC OS, name servers are listed in the
140
+ system variable Inet$Resolvers, space separated. */
141
+ line = getenv("Inet$Resolvers");
142
+ if (line) {
143
+ char *resolvers = ares_strdup(line);
144
+ char *pos;
145
+ char *space;
146
+
147
+ if (!resolvers) {
148
+ return ARES_ENOMEM;
149
+ }
150
+
151
+ pos = resolvers;
152
+ do {
153
+ space = strchr(pos, ' ');
154
+ if (space) {
155
+ *space = '\0';
156
+ }
157
+ status = ares_sconfig_append_fromstr(channel, &sysconfig->sconfig, pos,
158
+ ARES_TRUE);
159
+ if (status != ARES_SUCCESS) {
160
+ break;
161
+ }
162
+ pos = space + 1;
163
+ } while (space);
164
+
165
+ ares_free(resolvers);
166
+ }
167
+
168
+ return status;
169
+ }
170
+ #endif
171
+
172
+ #if defined(WATT32)
173
+ static ares_status_t ares_init_sysconfig_watt32(const ares_channel_t *channel,
174
+ ares_sysconfig_t *sysconfig)
175
+ {
176
+ size_t i;
177
+ ares_status_t status;
178
+
179
+ sock_init();
180
+
181
+ for (i = 0; def_nameservers[i]; i++) {
182
+ struct ares_addr addr;
183
+
184
+ addr.family = AF_INET;
185
+ addr.addr.addr4.s_addr = htonl(def_nameservers[i]);
186
+
187
+ status =
188
+ ares_sconfig_append(channel, &sysconfig->sconfig, &addr, 0, 0, NULL);
189
+
190
+ if (status != ARES_SUCCESS) {
191
+ return status;
192
+ }
193
+ }
194
+
195
+ return ARES_SUCCESS;
196
+ }
197
+ #endif
198
+
199
+ #if defined(ANDROID) || defined(__ANDROID__)
200
+ static ares_status_t ares_init_sysconfig_android(const ares_channel_t *channel,
201
+ ares_sysconfig_t *sysconfig)
202
+ {
203
+ size_t i;
204
+ char **dns_servers;
205
+ char *domains;
206
+ size_t num_servers;
207
+ ares_status_t status = ARES_EFILE;
208
+
209
+ /* Use the Android connectivity manager to get a list
210
+ * of DNS servers. As of Android 8 (Oreo) net.dns#
211
+ * system properties are no longer available. Google claims this
212
+ * improves privacy. Apps now need the ACCESS_NETWORK_STATE
213
+ * permission and must use the ConnectivityManager which
214
+ * is Java only. */
215
+ dns_servers = ares_get_android_server_list(MAX_DNS_PROPERTIES, &num_servers);
216
+ if (dns_servers != NULL) {
217
+ for (i = 0; i < num_servers; i++) {
218
+ status = ares_sconfig_append_fromstr(channel, &sysconfig->sconfig,
219
+ dns_servers[i], ARES_TRUE);
220
+ if (status != ARES_SUCCESS) {
221
+ break;
222
+ }
223
+ }
224
+ for (i = 0; i < num_servers; i++) {
225
+ ares_free(dns_servers[i]);
226
+ }
227
+ ares_free(dns_servers);
228
+ if (status != ARES_SUCCESS) {
229
+ return status;
230
+ }
231
+ }
232
+
233
+ domains = ares_get_android_search_domains_list();
234
+ sysconfig->domains = ares_strsplit(domains, ", ", &sysconfig->ndomains);
235
+ ares_free(domains);
236
+
237
+ # ifdef HAVE___SYSTEM_PROPERTY_GET
238
+ /* Old way using the system property still in place as
239
+ * a fallback. Older android versions can still use this.
240
+ * it's possible for older apps not not have added the new
241
+ * permission and we want to try to avoid breaking those.
242
+ *
243
+ * We'll only run this if we don't have any dns servers
244
+ * because this will get the same ones (if it works). */
245
+ if (sysconfig->sconfig == NULL) {
246
+ char propname[PROP_NAME_MAX];
247
+ char propvalue[PROP_VALUE_MAX] = "";
248
+ for (i = 1; i <= MAX_DNS_PROPERTIES; i++) {
249
+ snprintf(propname, sizeof(propname), "%s%zu", DNS_PROP_NAME_PREFIX, i);
250
+ if (__system_property_get(propname, propvalue) < 1) {
251
+ break;
252
+ }
253
+ status = ares_sconfig_append_fromstr(channel, &sysconfig->sconfig,
254
+ propvalue, ARES_TRUE);
255
+ if (status != ARES_SUCCESS) {
256
+ return status;
257
+ }
258
+ }
259
+ }
260
+ # endif /* HAVE___SYSTEM_PROPERTY_GET */
261
+
262
+ return status;
263
+ }
264
+ #endif
265
+
266
+ #if defined(__QNX__)
267
+ static ares_status_t
268
+ ares_init_sysconfig_qnx(const ares_channel_t *channel,
269
+ ares_sysconfig_t *sysconfig)
270
+ {
271
+ /* QNX:
272
+ * 1. use confstr(_CS_RESOLVE, ...) as primary resolv.conf data, replacing
273
+ * "_" with " ". If that is empty, then do normal /etc/resolv.conf
274
+ * processing.
275
+ * 2. We want to process /etc/nsswitch.conf as normal.
276
+ * 3. if confstr(_CS_DOMAIN, ...) this is the domain name. Use this as
277
+ * preference over anything else found.
278
+ */
279
+ ares_buf_t *buf = NULL;
280
+ unsigned char *data = NULL;
281
+ size_t data_size = 0;
282
+ ares_bool_t process_resolvconf = ARES_TRUE;
283
+ ares_status_t status = ARES_SUCCESS;
284
+
285
+ /* Prefer confstr(_CS_RESOLVE, ...) */
286
+ buf = ares_buf_create();
287
+ if (buf == NULL) {
288
+ status = ARES_ENOMEM;
289
+ goto done;
290
+ }
291
+
292
+ data_size = 1024;
293
+ data = ares_buf_append_start(buf, &data_size);
294
+ if (data == NULL) {
295
+ status = ARES_ENOMEM;
296
+ goto done;
297
+ }
298
+
299
+ data_size = confstr(_CS_RESOLVE, (char *)data, data_size);
300
+ if (data_size > 1) {
301
+ /* confstr returns byte for NULL terminator, strip */
302
+ data_size--;
303
+
304
+ ares_buf_append_finish(buf, data_size);
305
+ /* Its odd, this uses _ instead of " " between keywords, otherwise the
306
+ * format is the same as resolv.conf, replace. */
307
+ ares_buf_replace(buf, (const unsigned char *)"_", 1,
308
+ (const unsigned char *)" ", 1);
309
+
310
+ status = ares_sysconfig_process_buf(channel, sysconfig, buf,
311
+ ares_sysconfig_parse_resolv_line);
312
+ if (status != ARES_SUCCESS) {
313
+ /* ENOMEM is really the only error we'll get here */
314
+ goto done;
315
+ }
316
+
317
+ /* don't read resolv.conf if we processed *any* nameservers */
318
+ if (ares_llist_len(sysconfig->sconfig) != 0) {
319
+ process_resolvconf = ARES_FALSE;
320
+ }
321
+ }
322
+
323
+ /* Process files */
324
+ status = ares_init_sysconfig_files(channel, sysconfig, process_resolvconf);
325
+ if (status != ARES_SUCCESS) {
326
+ goto done;
327
+ }
328
+
329
+ /* Read confstr(_CS_DOMAIN, ...), but if we had a search path specified with
330
+ * more than one domain, lets prefer that instead. Its not exactly clear
331
+ * the best way to handle this. */
332
+ if (sysconfig->ndomains <= 1) {
333
+ char domain[256];
334
+ size_t domain_len;
335
+
336
+ domain_len = confstr(_CS_DOMAIN, domain, sizeof(domain));
337
+ if (domain_len != 0) {
338
+ ares_strsplit_free(sysconfig->domains, sysconfig->ndomains);
339
+ sysconfig->domains = ares_strsplit(domain, ", ", &sysconfig->ndomains);
340
+ if (sysconfig->domains == NULL) {
341
+ status = ARES_ENOMEM;
342
+ goto done;
343
+ }
344
+ }
345
+ }
346
+
347
+ done:
348
+ ares_buf_destroy(buf);
349
+
350
+ return status;
351
+ }
352
+ #endif
353
+
354
+ #if defined(CARES_USE_LIBRESOLV)
355
+ static ares_status_t
356
+ ares_init_sysconfig_libresolv(const ares_channel_t *channel,
357
+ ares_sysconfig_t *sysconfig)
358
+ {
359
+ struct __res_state res;
360
+ ares_status_t status = ARES_SUCCESS;
361
+ union res_sockaddr_union addr[MAXNS];
362
+ int nscount;
363
+ size_t i;
364
+ size_t entries = 0;
365
+ ares_buf_t *ipbuf = NULL;
366
+
367
+ memset(&res, 0, sizeof(res));
368
+
369
+ if (res_ninit(&res) != 0 || !(res.options & RES_INIT)) {
370
+ return ARES_EFILE;
371
+ }
372
+
373
+ nscount = res_getservers(&res, addr, MAXNS);
374
+
375
+ for (i = 0; i < (size_t)nscount; ++i) {
376
+ char ipaddr[INET6_ADDRSTRLEN] = "";
377
+ char *ipstr = NULL;
378
+ unsigned short port = 0;
379
+ unsigned int ll_scope = 0;
380
+
381
+ sa_family_t family = addr[i].sin.sin_family;
382
+ if (family == AF_INET) {
383
+ ares_inet_ntop(family, &addr[i].sin.sin_addr, ipaddr, sizeof(ipaddr));
384
+ port = ntohs(addr[i].sin.sin_port);
385
+ } else if (family == AF_INET6) {
386
+ ares_inet_ntop(family, &addr[i].sin6.sin6_addr, ipaddr, sizeof(ipaddr));
387
+ port = ntohs(addr[i].sin6.sin6_port);
388
+ ll_scope = addr[i].sin6.sin6_scope_id;
389
+ } else {
390
+ continue;
391
+ }
392
+
393
+
394
+ /* [ip]:port%iface */
395
+ ipbuf = ares_buf_create();
396
+ if (ipbuf == NULL) {
397
+ status = ARES_ENOMEM;
398
+ goto done;
399
+ }
400
+
401
+ status = ares_buf_append_str(ipbuf, "[");
402
+ if (status != ARES_SUCCESS) {
403
+ goto done;
404
+ }
405
+
406
+ status = ares_buf_append_str(ipbuf, ipaddr);
407
+ if (status != ARES_SUCCESS) {
408
+ goto done;
409
+ }
410
+
411
+ status = ares_buf_append_str(ipbuf, "]");
412
+ if (status != ARES_SUCCESS) {
413
+ goto done;
414
+ }
415
+
416
+ if (port) {
417
+ status = ares_buf_append_str(ipbuf, ":");
418
+ if (status != ARES_SUCCESS) {
419
+ goto done;
420
+ }
421
+ status = ares_buf_append_num_dec(ipbuf, port, 0);
422
+ if (status != ARES_SUCCESS) {
423
+ goto done;
424
+ }
425
+ }
426
+
427
+ if (ll_scope) {
428
+ status = ares_buf_append_str(ipbuf, "%");
429
+ if (status != ARES_SUCCESS) {
430
+ goto done;
431
+ }
432
+ status = ares_buf_append_num_dec(ipbuf, ll_scope, 0);
433
+ if (status != ARES_SUCCESS) {
434
+ goto done;
435
+ }
436
+ }
437
+
438
+ ipstr = ares_buf_finish_str(ipbuf, NULL);
439
+ ipbuf = NULL;
440
+ if (ipstr == NULL) {
441
+ status = ARES_ENOMEM;
442
+ goto done;
443
+ }
444
+
445
+ status = ares_sconfig_append_fromstr(channel, &sysconfig->sconfig, ipstr,
446
+ ARES_TRUE);
447
+
448
+ ares_free(ipstr);
449
+ if (status != ARES_SUCCESS) {
450
+ goto done;
451
+ }
452
+ }
453
+
454
+ while ((entries < MAXDNSRCH) && res.dnsrch[entries]) {
455
+ entries++;
456
+ }
457
+
458
+ if (entries) {
459
+ sysconfig->domains = ares_malloc_zero(entries * sizeof(char *));
460
+ if (sysconfig->domains == NULL) {
461
+ status = ARES_ENOMEM;
462
+ goto done;
463
+ } else {
464
+ sysconfig->ndomains = entries;
465
+ for (i = 0; i < sysconfig->ndomains; i++) {
466
+ sysconfig->domains[i] = ares_strdup(res.dnsrch[i]);
467
+ if (sysconfig->domains[i] == NULL) {
468
+ status = ARES_ENOMEM;
469
+ goto done;
470
+ }
471
+ }
472
+ }
473
+ }
474
+
475
+ if (res.ndots >= 0) {
476
+ sysconfig->ndots = (size_t)res.ndots;
477
+ }
478
+ /* Apple does not allow configuration of retry, so this is a static dummy
479
+ * value, ignore */
480
+ # ifndef __APPLE__
481
+ if (res.retry > 0) {
482
+ sysconfig->tries = (size_t)res.retry;
483
+ }
484
+ # endif
485
+ if (res.options & RES_ROTATE) {
486
+ sysconfig->rotate = ARES_TRUE;
487
+ }
488
+
489
+ if (res.retrans > 0) {
490
+ /* Apple does not allow configuration of retrans, so this is a dummy value
491
+ * that is extremely high (5s) */
492
+ # ifndef __APPLE__
493
+ if (res.retrans > 0) {
494
+ sysconfig->timeout_ms = (unsigned int)res.retrans * 1000;
495
+ }
496
+ # endif
497
+ }
498
+
499
+ done:
500
+ ares_buf_destroy(ipbuf);
501
+ res_ndestroy(&res);
502
+ return status;
503
+ }
504
+ #endif
505
+
506
+ static void ares_sysconfig_free(ares_sysconfig_t *sysconfig)
507
+ {
508
+ ares_llist_destroy(sysconfig->sconfig);
509
+ ares_strsplit_free(sysconfig->domains, sysconfig->ndomains);
510
+ ares_free(sysconfig->sortlist);
511
+ ares_free(sysconfig->lookups);
512
+ memset(sysconfig, 0, sizeof(*sysconfig));
513
+ }
514
+
515
+ static ares_status_t ares_sysconfig_apply(ares_channel_t *channel,
516
+ const ares_sysconfig_t *sysconfig)
517
+ {
518
+ ares_status_t status;
519
+
520
+ if (sysconfig->sconfig && !(channel->optmask & ARES_OPT_SERVERS)) {
521
+ status = ares_servers_update(channel, sysconfig->sconfig, ARES_FALSE);
522
+ if (status != ARES_SUCCESS) {
523
+ return status;
524
+ }
525
+ }
526
+
527
+ if (sysconfig->domains && !(channel->optmask & ARES_OPT_DOMAINS)) {
528
+ /* Make sure we duplicate first then replace so even if there is
529
+ * ARES_ENOMEM, the channel stays in a good state */
530
+ char **temp =
531
+ ares_strsplit_duplicate(sysconfig->domains, sysconfig->ndomains);
532
+ if (temp == NULL) {
533
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
534
+ }
535
+
536
+ ares_strsplit_free(channel->domains, channel->ndomains);
537
+ channel->domains = temp;
538
+ channel->ndomains = sysconfig->ndomains;
539
+ }
540
+
541
+ if (sysconfig->lookups && !(channel->optmask & ARES_OPT_LOOKUPS)) {
542
+ char *temp = ares_strdup(sysconfig->lookups);
543
+ if (temp == NULL) {
544
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
545
+ }
546
+
547
+ ares_free(channel->lookups);
548
+ channel->lookups = temp;
549
+ }
550
+
551
+ if (sysconfig->sortlist && !(channel->optmask & ARES_OPT_SORTLIST)) {
552
+ struct apattern *temp =
553
+ ares_malloc(sizeof(*channel->sortlist) * sysconfig->nsortlist);
554
+ if (temp == NULL) {
555
+ return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
556
+ }
557
+ memcpy(temp, sysconfig->sortlist,
558
+ sizeof(*channel->sortlist) * sysconfig->nsortlist);
559
+
560
+ ares_free(channel->sortlist);
561
+ channel->sortlist = temp;
562
+ channel->nsort = sysconfig->nsortlist;
563
+ }
564
+
565
+ if (!(channel->optmask & ARES_OPT_NDOTS)) {
566
+ channel->ndots = sysconfig->ndots;
567
+ }
568
+
569
+ if (sysconfig->tries && !(channel->optmask & ARES_OPT_TRIES)) {
570
+ channel->tries = sysconfig->tries;
571
+ }
572
+
573
+ if (sysconfig->timeout_ms && !(channel->optmask & ARES_OPT_TIMEOUTMS)) {
574
+ channel->timeout = sysconfig->timeout_ms;
575
+ }
576
+
577
+ if (!(channel->optmask & (ARES_OPT_ROTATE | ARES_OPT_NOROTATE))) {
578
+ channel->rotate = sysconfig->rotate;
579
+ }
580
+
581
+ if (sysconfig->usevc) {
582
+ channel->flags |= ARES_FLAG_USEVC;
583
+ }
584
+
585
+ return ARES_SUCCESS;
586
+ }
587
+
588
+ ares_status_t ares_init_by_sysconfig(ares_channel_t *channel)
589
+ {
590
+ ares_status_t status;
591
+ ares_sysconfig_t sysconfig;
592
+
593
+ memset(&sysconfig, 0, sizeof(sysconfig));
594
+ sysconfig.ndots = 1; /* Default value if not otherwise set */
595
+
596
+ #if defined(USE_WINSOCK)
597
+ status = ares_init_sysconfig_windows(channel, &sysconfig);
598
+ #elif defined(__MVS__)
599
+ status = ares_init_sysconfig_mvs(channel, &sysconfig);
600
+ #elif defined(__riscos__)
601
+ status = ares_init_sysconfig_riscos(channel, &sysconfig);
602
+ #elif defined(WATT32)
603
+ status = ares_init_sysconfig_watt32(channel, &sysconfig);
604
+ #elif defined(ANDROID) || defined(__ANDROID__)
605
+ status = ares_init_sysconfig_android(channel, &sysconfig);
606
+ #elif defined(__APPLE__)
607
+ status = ares_init_sysconfig_macos(channel, &sysconfig);
608
+ #elif defined(CARES_USE_LIBRESOLV)
609
+ status = ares_init_sysconfig_libresolv(channel, &sysconfig);
610
+ #elif defined(__QNX__)
611
+ status = ares_init_sysconfig_qnx(channel, &sysconfig);
612
+ #else
613
+ status = ares_init_sysconfig_files(channel, &sysconfig, ARES_TRUE);
614
+ #endif
615
+
616
+ if (status != ARES_SUCCESS) {
617
+ goto done;
618
+ }
619
+
620
+ /* Environment is supposed to override sysconfig */
621
+ status = ares_init_by_environment(&sysconfig);
622
+ if (status != ARES_SUCCESS) {
623
+ goto done;
624
+ }
625
+
626
+ /* Lock when applying the configuration to the channel. Don't need to
627
+ * lock prior to this. */
628
+
629
+ ares_channel_lock(channel);
630
+
631
+ status = ares_sysconfig_apply(channel, &sysconfig);
632
+ ares_channel_unlock(channel);
633
+
634
+ if (status != ARES_SUCCESS) {
635
+ goto done;
636
+ }
637
+
638
+ done:
639
+ ares_sysconfig_free(&sysconfig);
640
+
641
+ return status;
642
+ }