grpc 1.2.5 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (327) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1434 -399
  3. data/etc/roots.pem +34 -150
  4. data/include/grpc/grpc.h +71 -0
  5. data/include/grpc/impl/codegen/atm.h +5 -0
  6. data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
  7. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +11 -0
  9. data/include/grpc/impl/codegen/grpc_types.h +54 -13
  10. data/include/grpc/impl/codegen/port_platform.h +15 -1
  11. data/include/grpc/support/alloc.h +2 -1
  12. data/include/grpc/support/sync.h +4 -0
  13. data/include/grpc/support/tls.h +1 -1
  14. data/src/core/ext/census/gen/trace_context.pb.h +1 -1
  15. data/src/core/ext/census/grpc_filter.c +14 -10
  16. data/src/core/ext/census/grpc_plugin.c +3 -1
  17. data/src/core/ext/census/trace_label.h +1 -1
  18. data/src/core/ext/census/trace_propagation.h +1 -1
  19. data/src/core/ext/census/trace_status.h +1 -1
  20. data/src/core/ext/census/trace_string.h +1 -1
  21. data/src/core/ext/census/tracing.h +1 -1
  22. data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
  23. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
  24. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
  25. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
  26. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
  27. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
  28. data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
  29. data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
  30. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
  31. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
  32. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
  33. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
  34. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
  35. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
  36. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
  37. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
  38. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
  39. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
  40. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
  41. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
  42. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
  43. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
  44. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
  45. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
  46. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
  47. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
  48. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
  49. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
  50. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
  51. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
  52. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
  53. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
  54. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
  55. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
  56. data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
  57. data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  63. data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
  64. data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
  65. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
  66. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
  67. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
  68. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
  69. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  70. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  71. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
  72. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
  73. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
  74. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
  75. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
  76. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
  77. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
  78. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
  79. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
  80. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
  81. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  82. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  83. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
  84. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  85. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
  86. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
  87. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  88. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
  89. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
  90. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
  91. data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
  92. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
  93. data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
  94. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
  95. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
  96. data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
  97. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
  98. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
  99. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
  100. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
  101. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
  102. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  103. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  104. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  105. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
  106. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
  107. data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
  108. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
  109. data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
  110. data/src/core/lib/channel/channel_args.c +7 -0
  111. data/src/core/lib/channel/channel_args.h +2 -0
  112. data/src/core/lib/channel/channel_stack.c +20 -27
  113. data/src/core/lib/channel/channel_stack.h +18 -16
  114. data/src/core/lib/channel/compress_filter.c +20 -18
  115. data/src/core/lib/channel/connected_channel.c +9 -8
  116. data/src/core/lib/channel/deadline_filter.c +28 -24
  117. data/src/core/lib/channel/deadline_filter.h +3 -3
  118. data/src/core/lib/channel/handshaker.c +3 -2
  119. data/src/core/lib/channel/http_client_filter.c +119 -61
  120. data/src/core/lib/channel/http_server_filter.c +124 -69
  121. data/src/core/lib/channel/message_size_filter.c +23 -19
  122. data/src/core/lib/http/httpcli.c +8 -6
  123. data/src/core/lib/http/httpcli_security_connector.c +5 -5
  124. data/src/core/lib/http/parser.c +57 -31
  125. data/src/core/lib/iomgr/closure.c +15 -0
  126. data/src/core/lib/iomgr/closure.h +4 -0
  127. data/src/core/lib/iomgr/combiner.c +8 -0
  128. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  129. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
  130. data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
  131. data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
  132. data/src/core/lib/iomgr/error.c +360 -177
  133. data/src/core/lib/iomgr/error.h +31 -33
  134. data/src/core/lib/iomgr/error_internal.h +30 -9
  135. data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
  136. data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
  137. data/src/core/lib/iomgr/ev_posix.c +6 -0
  138. data/src/core/lib/iomgr/ev_posix.h +3 -0
  139. data/src/core/lib/iomgr/exec_ctx.c +6 -0
  140. data/src/core/lib/iomgr/executor.c +8 -2
  141. data/src/core/lib/iomgr/load_file.c +6 -3
  142. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  143. data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
  144. data/src/core/lib/iomgr/pollset.h +4 -0
  145. data/src/core/lib/iomgr/pollset_windows.c +2 -2
  146. data/src/core/lib/iomgr/port.h +9 -0
  147. data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
  148. data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
  149. data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
  150. data/src/core/lib/iomgr/resource_quota.c +19 -4
  151. data/src/core/lib/iomgr/resource_quota.h +2 -0
  152. data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
  153. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  154. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  155. data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
  156. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  157. data/src/core/lib/iomgr/tcp_client.h +0 -4
  158. data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
  159. data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
  160. data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
  161. data/src/core/lib/iomgr/tcp_posix.c +111 -22
  162. data/src/core/lib/iomgr/tcp_posix.h +3 -4
  163. data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  165. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  166. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  167. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  168. data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
  169. data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
  170. data/src/core/lib/iomgr/tcp_uv.c +16 -13
  171. data/src/core/lib/iomgr/tcp_windows.c +24 -12
  172. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  173. data/src/core/lib/iomgr/timer.h +3 -0
  174. data/src/core/lib/iomgr/timer_generic.c +257 -72
  175. data/src/core/lib/iomgr/timer_generic.h +1 -1
  176. data/src/core/lib/iomgr/timer_heap.c +8 -8
  177. data/src/core/lib/iomgr/udp_server.c +54 -24
  178. data/src/core/lib/iomgr/udp_server.h +7 -7
  179. data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
  180. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
  181. data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
  182. data/src/core/lib/profiling/basic_timers.c +1 -1
  183. data/src/core/lib/security/credentials/credentials.h +1 -1
  184. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
  185. data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
  186. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
  187. data/src/core/lib/security/transport/client_auth_filter.c +33 -26
  188. data/src/core/lib/security/transport/secure_endpoint.c +8 -5
  189. data/src/core/lib/security/transport/security_connector.c +37 -37
  190. data/src/core/lib/security/transport/security_connector.h +1 -1
  191. data/src/core/lib/security/transport/security_handshaker.c +15 -12
  192. data/src/core/lib/security/transport/server_auth_filter.c +20 -18
  193. data/src/core/lib/security/transport/tsi_error.c +5 -3
  194. data/src/core/lib/security/transport/tsi_error.h +1 -1
  195. data/src/core/lib/{security/util → slice}/b64.c +21 -6
  196. data/src/core/lib/{security/util → slice}/b64.h +16 -4
  197. data/src/core/lib/slice/slice.c +4 -2
  198. data/src/core/lib/slice/slice_buffer.c +16 -14
  199. data/src/core/lib/support/arena.c +98 -0
  200. data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
  201. data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
  202. data/src/core/lib/support/cpu_linux.c +5 -0
  203. data/src/core/lib/support/sync.c +4 -0
  204. data/src/core/lib/support/time.c +4 -10
  205. data/src/core/lib/support/wrap_memcpy.c +3 -1
  206. data/src/core/lib/surface/call.c +252 -221
  207. data/src/core/lib/surface/channel.c +72 -21
  208. data/src/core/lib/surface/channel.h +8 -0
  209. data/src/core/lib/surface/completion_queue.c +2 -3
  210. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  211. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  212. data/src/core/lib/surface/init_secure.c +3 -1
  213. data/src/core/lib/surface/lame_client.c +18 -14
  214. data/src/core/lib/surface/server.c +43 -41
  215. data/src/core/lib/surface/validate_metadata.c +8 -4
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.h +1 -1
  218. data/src/core/lib/transport/connectivity_state.c +2 -1
  219. data/src/core/lib/transport/error_utils.c +17 -17
  220. data/src/core/lib/transport/error_utils.h +1 -1
  221. data/src/core/lib/transport/metadata_batch.c +6 -7
  222. data/src/core/lib/transport/pid_controller.c +1 -0
  223. data/src/core/lib/transport/service_config.c +12 -0
  224. data/src/core/lib/transport/service_config.h +6 -0
  225. data/src/core/lib/transport/transport.c +29 -17
  226. data/src/core/lib/transport/transport.h +85 -42
  227. data/src/core/lib/transport/transport_impl.h +5 -3
  228. data/src/core/lib/transport/transport_op_string.c +20 -14
  229. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
  230. data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
  231. data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
  232. data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
  233. data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
  234. data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
  235. data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
  236. data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
  237. data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
  238. data/src/ruby/ext/grpc/extconf.rb +1 -0
  239. data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
  240. data/src/ruby/ext/grpc/rb_channel.c +520 -93
  241. data/src/ruby/ext/grpc/rb_channel.h +2 -0
  242. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
  243. data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
  244. data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
  245. data/src/ruby/ext/grpc/rb_grpc.c +29 -7
  246. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  247. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
  249. data/src/ruby/ext/grpc/rb_server.c +5 -3
  250. data/src/ruby/lib/grpc/version.rb +1 -1
  251. data/src/ruby/spec/channel_connection_spec.rb +173 -0
  252. data/src/ruby/spec/channel_spec.rb +29 -0
  253. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
  254. data/third_party/cares/ares_build.h +264 -0
  255. data/third_party/cares/cares/ares.h +636 -0
  256. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  257. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  258. data/third_party/cares/cares/ares__read_line.c +73 -0
  259. data/third_party/cares/cares/ares__timeval.c +111 -0
  260. data/third_party/cares/cares/ares_cancel.c +63 -0
  261. data/third_party/cares/cares/ares_create_query.c +202 -0
  262. data/third_party/cares/cares/ares_data.c +221 -0
  263. data/third_party/cares/cares/ares_data.h +72 -0
  264. data/third_party/cares/cares/ares_destroy.c +108 -0
  265. data/third_party/cares/cares/ares_dns.h +103 -0
  266. data/third_party/cares/cares/ares_expand_name.c +205 -0
  267. data/third_party/cares/cares/ares_expand_string.c +70 -0
  268. data/third_party/cares/cares/ares_fds.c +59 -0
  269. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  270. data/third_party/cares/cares/ares_free_string.c +25 -0
  271. data/third_party/cares/cares/ares_getenv.c +30 -0
  272. data/third_party/cares/cares/ares_getenv.h +26 -0
  273. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  274. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  275. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  276. data/third_party/cares/cares/ares_getopt.c +122 -0
  277. data/third_party/cares/cares/ares_getopt.h +53 -0
  278. data/third_party/cares/cares/ares_getsock.c +66 -0
  279. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  280. data/third_party/cares/cares/ares_init.c +2146 -0
  281. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  282. data/third_party/cares/cares/ares_ipv6.h +78 -0
  283. data/third_party/cares/cares/ares_library_init.c +167 -0
  284. data/third_party/cares/cares/ares_library_init.h +42 -0
  285. data/third_party/cares/cares/ares_llist.c +63 -0
  286. data/third_party/cares/cares/ares_llist.h +39 -0
  287. data/third_party/cares/cares/ares_mkquery.c +24 -0
  288. data/third_party/cares/cares/ares_nowarn.c +260 -0
  289. data/third_party/cares/cares/ares_nowarn.h +61 -0
  290. data/third_party/cares/cares/ares_options.c +402 -0
  291. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  292. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  293. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  294. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  295. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  296. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  297. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  298. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  299. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  300. data/third_party/cares/cares/ares_platform.c +11035 -0
  301. data/third_party/cares/cares/ares_platform.h +43 -0
  302. data/third_party/cares/cares/ares_private.h +363 -0
  303. data/third_party/cares/cares/ares_process.c +1359 -0
  304. data/third_party/cares/cares/ares_query.c +186 -0
  305. data/third_party/cares/cares/ares_rules.h +125 -0
  306. data/third_party/cares/cares/ares_search.c +316 -0
  307. data/third_party/cares/cares/ares_send.c +131 -0
  308. data/third_party/cares/cares/ares_setup.h +217 -0
  309. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  310. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  311. data/third_party/cares/cares/ares_strdup.c +49 -0
  312. data/third_party/cares/cares/ares_strdup.h +24 -0
  313. data/third_party/cares/cares/ares_strerror.c +56 -0
  314. data/third_party/cares/cares/ares_timeout.c +88 -0
  315. data/third_party/cares/cares/ares_version.c +11 -0
  316. data/third_party/cares/cares/ares_version.h +24 -0
  317. data/third_party/cares/cares/ares_writev.c +79 -0
  318. data/third_party/cares/cares/bitncmp.c +59 -0
  319. data/third_party/cares/cares/bitncmp.h +26 -0
  320. data/third_party/cares/cares/config-win32.h +377 -0
  321. data/third_party/cares/cares/inet_net_pton.c +450 -0
  322. data/third_party/cares/cares/inet_ntop.c +208 -0
  323. data/third_party/cares/cares/setup_once.h +554 -0
  324. data/third_party/cares/cares/windows_port.c +22 -0
  325. data/third_party/cares/config_darwin/ares_config.h +523 -0
  326. data/third_party/cares/config_linux/ares_config.h +524 -0
  327. metadata +164 -68
@@ -0,0 +1,402 @@
1
+
2
+ /* Copyright 1998 by the Massachusetts Institute of Technology.
3
+ * Copyright (C) 2008-2013 by Daniel Stenberg
4
+ *
5
+ * Permission to use, copy, modify, and distribute this
6
+ * software and its documentation for any purpose and without
7
+ * fee is hereby granted, provided that the above copyright
8
+ * notice appear in all copies and that both that copyright
9
+ * notice and this permission notice appear in supporting
10
+ * documentation, and that the name of M.I.T. not be used in
11
+ * advertising or publicity pertaining to distribution of the
12
+ * software without specific, written prior permission.
13
+ * M.I.T. makes no representations about the suitability of
14
+ * this software for any purpose. It is provided "as is"
15
+ * without express or implied warranty.
16
+ */
17
+
18
+
19
+ #include "ares_setup.h"
20
+
21
+ #ifdef HAVE_ARPA_INET_H
22
+ # include <arpa/inet.h>
23
+ #endif
24
+
25
+ #include "ares.h"
26
+ #include "ares_data.h"
27
+ #include "ares_inet_net_pton.h"
28
+ #include "ares_private.h"
29
+
30
+
31
+ int ares_get_servers(ares_channel channel,
32
+ struct ares_addr_node **servers)
33
+ {
34
+ struct ares_addr_node *srvr_head = NULL;
35
+ struct ares_addr_node *srvr_last = NULL;
36
+ struct ares_addr_node *srvr_curr;
37
+ int status = ARES_SUCCESS;
38
+ int i;
39
+
40
+ if (!channel)
41
+ return ARES_ENODATA;
42
+
43
+ for (i = 0; i < channel->nservers; i++)
44
+ {
45
+ /* Allocate storage for this server node appending it to the list */
46
+ srvr_curr = ares_malloc_data(ARES_DATATYPE_ADDR_NODE);
47
+ if (!srvr_curr)
48
+ {
49
+ status = ARES_ENOMEM;
50
+ break;
51
+ }
52
+ if (srvr_last)
53
+ {
54
+ srvr_last->next = srvr_curr;
55
+ }
56
+ else
57
+ {
58
+ srvr_head = srvr_curr;
59
+ }
60
+ srvr_last = srvr_curr;
61
+
62
+ /* Fill this server node data */
63
+ srvr_curr->family = channel->servers[i].addr.family;
64
+ if (srvr_curr->family == AF_INET)
65
+ memcpy(&srvr_curr->addrV4, &channel->servers[i].addr.addrV4,
66
+ sizeof(srvr_curr->addrV4));
67
+ else
68
+ memcpy(&srvr_curr->addrV6, &channel->servers[i].addr.addrV6,
69
+ sizeof(srvr_curr->addrV6));
70
+ }
71
+
72
+ if (status != ARES_SUCCESS)
73
+ {
74
+ if (srvr_head)
75
+ {
76
+ ares_free_data(srvr_head);
77
+ srvr_head = NULL;
78
+ }
79
+ }
80
+
81
+ *servers = srvr_head;
82
+
83
+ return status;
84
+ }
85
+
86
+ int ares_get_servers_ports(ares_channel channel,
87
+ struct ares_addr_port_node **servers)
88
+ {
89
+ struct ares_addr_port_node *srvr_head = NULL;
90
+ struct ares_addr_port_node *srvr_last = NULL;
91
+ struct ares_addr_port_node *srvr_curr;
92
+ int status = ARES_SUCCESS;
93
+ int i;
94
+
95
+ if (!channel)
96
+ return ARES_ENODATA;
97
+
98
+ for (i = 0; i < channel->nservers; i++)
99
+ {
100
+ /* Allocate storage for this server node appending it to the list */
101
+ srvr_curr = ares_malloc_data(ARES_DATATYPE_ADDR_PORT_NODE);
102
+ if (!srvr_curr)
103
+ {
104
+ status = ARES_ENOMEM;
105
+ break;
106
+ }
107
+ if (srvr_last)
108
+ {
109
+ srvr_last->next = srvr_curr;
110
+ }
111
+ else
112
+ {
113
+ srvr_head = srvr_curr;
114
+ }
115
+ srvr_last = srvr_curr;
116
+
117
+ /* Fill this server node data */
118
+ srvr_curr->family = channel->servers[i].addr.family;
119
+ srvr_curr->udp_port = ntohs((unsigned short)channel->servers[i].addr.udp_port);
120
+ srvr_curr->tcp_port = ntohs((unsigned short)channel->servers[i].addr.tcp_port);
121
+ if (srvr_curr->family == AF_INET)
122
+ memcpy(&srvr_curr->addrV4, &channel->servers[i].addr.addrV4,
123
+ sizeof(srvr_curr->addrV4));
124
+ else
125
+ memcpy(&srvr_curr->addrV6, &channel->servers[i].addr.addrV6,
126
+ sizeof(srvr_curr->addrV6));
127
+ }
128
+
129
+ if (status != ARES_SUCCESS)
130
+ {
131
+ if (srvr_head)
132
+ {
133
+ ares_free_data(srvr_head);
134
+ srvr_head = NULL;
135
+ }
136
+ }
137
+
138
+ *servers = srvr_head;
139
+
140
+ return status;
141
+ }
142
+
143
+ int ares_set_servers(ares_channel channel,
144
+ struct ares_addr_node *servers)
145
+ {
146
+ struct ares_addr_node *srvr;
147
+ int num_srvrs = 0;
148
+ int i;
149
+
150
+ if (ares_library_initialized() != ARES_SUCCESS)
151
+ return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
152
+
153
+ if (!channel)
154
+ return ARES_ENODATA;
155
+
156
+ ares__destroy_servers_state(channel);
157
+
158
+ for (srvr = servers; srvr; srvr = srvr->next)
159
+ {
160
+ num_srvrs++;
161
+ }
162
+
163
+ if (num_srvrs > 0)
164
+ {
165
+ /* Allocate storage for servers state */
166
+ channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
167
+ if (!channel->servers)
168
+ {
169
+ return ARES_ENOMEM;
170
+ }
171
+ channel->nservers = num_srvrs;
172
+ /* Fill servers state address data */
173
+ for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
174
+ {
175
+ channel->servers[i].addr.family = srvr->family;
176
+ channel->servers[i].addr.udp_port = 0;
177
+ channel->servers[i].addr.tcp_port = 0;
178
+ if (srvr->family == AF_INET)
179
+ memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4,
180
+ sizeof(srvr->addrV4));
181
+ else
182
+ memcpy(&channel->servers[i].addr.addrV6, &srvr->addrV6,
183
+ sizeof(srvr->addrV6));
184
+ }
185
+ /* Initialize servers state remaining data */
186
+ ares__init_servers_state(channel);
187
+ }
188
+
189
+ return ARES_SUCCESS;
190
+ }
191
+
192
+ int ares_set_servers_ports(ares_channel channel,
193
+ struct ares_addr_port_node *servers)
194
+ {
195
+ struct ares_addr_port_node *srvr;
196
+ int num_srvrs = 0;
197
+ int i;
198
+
199
+ if (ares_library_initialized() != ARES_SUCCESS)
200
+ return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
201
+
202
+ if (!channel)
203
+ return ARES_ENODATA;
204
+
205
+ ares__destroy_servers_state(channel);
206
+
207
+ for (srvr = servers; srvr; srvr = srvr->next)
208
+ {
209
+ num_srvrs++;
210
+ }
211
+
212
+ if (num_srvrs > 0)
213
+ {
214
+ /* Allocate storage for servers state */
215
+ channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
216
+ if (!channel->servers)
217
+ {
218
+ return ARES_ENOMEM;
219
+ }
220
+ channel->nservers = num_srvrs;
221
+ /* Fill servers state address data */
222
+ for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
223
+ {
224
+ channel->servers[i].addr.family = srvr->family;
225
+ channel->servers[i].addr.udp_port = htons((unsigned short)srvr->udp_port);
226
+ channel->servers[i].addr.tcp_port = htons((unsigned short)srvr->tcp_port);
227
+ if (srvr->family == AF_INET)
228
+ memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4,
229
+ sizeof(srvr->addrV4));
230
+ else
231
+ memcpy(&channel->servers[i].addr.addrV6, &srvr->addrV6,
232
+ sizeof(srvr->addrV6));
233
+ }
234
+ /* Initialize servers state remaining data */
235
+ ares__init_servers_state(channel);
236
+ }
237
+
238
+ return ARES_SUCCESS;
239
+ }
240
+
241
+ /* Incomming string format: host[:port][,host[:port]]... */
242
+ /* IPv6 addresses with ports require square brackets [fe80::1%lo0]:53 */
243
+ static int set_servers_csv(ares_channel channel,
244
+ const char* _csv, int use_port)
245
+ {
246
+ size_t i;
247
+ char* csv = NULL;
248
+ char* ptr;
249
+ char* start_host;
250
+ int cc = 0;
251
+ int rv = ARES_SUCCESS;
252
+ struct ares_addr_port_node *servers = NULL;
253
+ struct ares_addr_port_node *last = NULL;
254
+
255
+ if (ares_library_initialized() != ARES_SUCCESS)
256
+ return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
257
+
258
+ if (!channel)
259
+ return ARES_ENODATA;
260
+
261
+ ares__destroy_servers_state(channel);
262
+
263
+ i = strlen(_csv);
264
+ if (i == 0)
265
+ return ARES_SUCCESS; /* blank all servers */
266
+
267
+ csv = ares_malloc(i + 2);
268
+ if (!csv)
269
+ return ARES_ENOMEM;
270
+
271
+ strcpy(csv, _csv);
272
+ if (csv[i-1] != ',') { /* make parsing easier by ensuring ending ',' */
273
+ csv[i] = ',';
274
+ csv[i+1] = 0;
275
+ }
276
+
277
+ start_host = csv;
278
+ for (ptr = csv; *ptr; ptr++) {
279
+ if (*ptr == ':') {
280
+ /* count colons to determine if we have an IPv6 number or IPv4 with
281
+ port */
282
+ cc++;
283
+ }
284
+ else if (*ptr == '[') {
285
+ /* move start_host if an open square bracket is found wrapping an IPv6
286
+ address */
287
+ start_host = ptr + 1;
288
+ }
289
+ else if (*ptr == ',') {
290
+ char* pp = ptr - 1;
291
+ char* p = ptr;
292
+ int port = 0;
293
+ struct in_addr in4;
294
+ struct ares_in6_addr in6;
295
+ struct ares_addr_port_node *s = NULL;
296
+
297
+ *ptr = 0; /* null terminate host:port string */
298
+ /* Got an entry..see if the port was specified. */
299
+ if (cc > 0) {
300
+ while (pp > start_host) {
301
+ /* a single close square bracket followed by a colon, ']:' indicates
302
+ an IPv6 address with port */
303
+ if ((*pp == ']') && (*p == ':'))
304
+ break; /* found port */
305
+ /* a single colon, ':' indicates an IPv4 address with port */
306
+ if ((*pp == ':') && (cc == 1))
307
+ break; /* found port */
308
+ if (!(ISDIGIT(*pp) || (*pp == ':'))) {
309
+ /* Found end of digits before we found :, so wasn't a port */
310
+ /* must allow ':' for IPv6 case of ']:' indicates we found a port */
311
+ pp = p = ptr;
312
+ break;
313
+ }
314
+ pp--;
315
+ p--;
316
+ }
317
+ if ((pp != start_host) && ((pp + 1) < ptr)) {
318
+ /* Found it. Parse over the port number */
319
+ /* when an IPv6 address is wrapped with square brackets the port
320
+ starts at pp + 2 */
321
+ if (*pp == ']')
322
+ p++; /* move p before ':' */
323
+ /* p will point to the start of the port */
324
+ port = (int)strtol(p, NULL, 10);
325
+ *pp = 0; /* null terminate host */
326
+ }
327
+ }
328
+ /* resolve host, try ipv4 first, rslt is in network byte order */
329
+ rv = ares_inet_pton(AF_INET, start_host, &in4);
330
+ if (!rv) {
331
+ /* Ok, try IPv6 then */
332
+ rv = ares_inet_pton(AF_INET6, start_host, &in6);
333
+ if (!rv) {
334
+ rv = ARES_EBADSTR;
335
+ goto out;
336
+ }
337
+ /* was ipv6, add new server */
338
+ s = ares_malloc(sizeof(*s));
339
+ if (!s) {
340
+ rv = ARES_ENOMEM;
341
+ goto out;
342
+ }
343
+ s->family = AF_INET6;
344
+ memcpy(&s->addr, &in6, sizeof(struct ares_in6_addr));
345
+ }
346
+ else {
347
+ /* was ipv4, add new server */
348
+ s = ares_malloc(sizeof(*s));
349
+ if (!s) {
350
+ rv = ARES_ENOMEM;
351
+ goto out;
352
+ }
353
+ s->family = AF_INET;
354
+ memcpy(&s->addr, &in4, sizeof(struct in_addr));
355
+ }
356
+ if (s) {
357
+ s->udp_port = use_port ? port: 0;
358
+ s->tcp_port = s->udp_port;
359
+ s->next = NULL;
360
+ if (last) {
361
+ last->next = s;
362
+ /* need to move last to maintain the linked list */
363
+ last = last->next;
364
+ }
365
+ else {
366
+ servers = s;
367
+ last = s;
368
+ }
369
+ }
370
+
371
+ /* Set up for next one */
372
+ start_host = ptr + 1;
373
+ cc = 0;
374
+ }
375
+ }
376
+
377
+ rv = ares_set_servers_ports(channel, servers);
378
+
379
+ out:
380
+ if (csv)
381
+ ares_free(csv);
382
+ while (servers) {
383
+ struct ares_addr_port_node *s = servers;
384
+ servers = servers->next;
385
+ ares_free(s);
386
+ }
387
+
388
+ return rv;
389
+ }
390
+
391
+ int ares_set_servers_csv(ares_channel channel,
392
+ const char* _csv)
393
+ {
394
+ return set_servers_csv(channel, _csv, FALSE);
395
+ }
396
+
397
+ int ares_set_servers_ports_csv(ares_channel channel,
398
+ const char* _csv)
399
+ {
400
+ return set_servers_csv(channel, _csv, TRUE);
401
+ }
402
+
@@ -0,0 +1,264 @@
1
+
2
+ /* Copyright 1998 by the Massachusetts Institute of Technology.
3
+ *
4
+ * Permission to use, copy, modify, and distribute this
5
+ * software and its documentation for any purpose and without
6
+ * fee is hereby granted, provided that the above copyright
7
+ * notice appear in all copies and that both that copyright
8
+ * notice and this permission notice appear in supporting
9
+ * documentation, and that the name of M.I.T. not be used in
10
+ * advertising or publicity pertaining to distribution of the
11
+ * software without specific, written prior permission.
12
+ * M.I.T. makes no representations about the suitability of
13
+ * this software for any purpose. It is provided "as is"
14
+ * without express or implied warranty.
15
+ */
16
+
17
+ #include "ares_setup.h"
18
+
19
+ #ifdef HAVE_NETINET_IN_H
20
+ # include <netinet/in.h>
21
+ #endif
22
+ #ifdef HAVE_NETDB_H
23
+ # include <netdb.h>
24
+ #endif
25
+ #ifdef HAVE_ARPA_INET_H
26
+ # include <arpa/inet.h>
27
+ #endif
28
+ #ifdef HAVE_ARPA_NAMESER_H
29
+ # include <arpa/nameser.h>
30
+ #else
31
+ # include "nameser.h"
32
+ #endif
33
+ #ifdef HAVE_ARPA_NAMESER_COMPAT_H
34
+ # include <arpa/nameser_compat.h>
35
+ #endif
36
+
37
+ #ifdef HAVE_STRINGS_H
38
+ # include <strings.h>
39
+ #endif
40
+
41
+ #ifdef HAVE_LIMITS_H
42
+ # include <limits.h>
43
+ #endif
44
+
45
+ #include "ares.h"
46
+ #include "ares_dns.h"
47
+ #include "ares_private.h"
48
+
49
+ int ares_parse_a_reply(const unsigned char *abuf, int alen,
50
+ struct hostent **host,
51
+ struct ares_addrttl *addrttls, int *naddrttls)
52
+ {
53
+ unsigned int qdcount, ancount;
54
+ int status, i, rr_type, rr_class, rr_len, rr_ttl, naddrs;
55
+ int cname_ttl = INT_MAX; /* the TTL imposed by the CNAME chain */
56
+ int naliases;
57
+ long len;
58
+ const unsigned char *aptr;
59
+ char *hostname, *rr_name, *rr_data, **aliases;
60
+ struct in_addr *addrs;
61
+ struct hostent *hostent;
62
+ const int max_addr_ttls = (addrttls && naddrttls) ? *naddrttls : 0;
63
+
64
+ /* Set *host to NULL for all failure cases. */
65
+ if (host)
66
+ *host = NULL;
67
+ /* Same with *naddrttls. */
68
+ if (naddrttls)
69
+ *naddrttls = 0;
70
+
71
+ /* Give up if abuf doesn't have room for a header. */
72
+ if (alen < HFIXEDSZ)
73
+ return ARES_EBADRESP;
74
+
75
+ /* Fetch the question and answer count from the header. */
76
+ qdcount = DNS_HEADER_QDCOUNT(abuf);
77
+ ancount = DNS_HEADER_ANCOUNT(abuf);
78
+ if (qdcount != 1)
79
+ return ARES_EBADRESP;
80
+
81
+ /* Expand the name from the question, and skip past the question. */
82
+ aptr = abuf + HFIXEDSZ;
83
+ status = ares__expand_name_for_response(aptr, abuf, alen, &hostname, &len);
84
+ if (status != ARES_SUCCESS)
85
+ return status;
86
+ if (aptr + len + QFIXEDSZ > abuf + alen)
87
+ {
88
+ ares_free(hostname);
89
+ return ARES_EBADRESP;
90
+ }
91
+ aptr += len + QFIXEDSZ;
92
+
93
+ if (host)
94
+ {
95
+ /* Allocate addresses and aliases; ancount gives an upper bound for
96
+ both. */
97
+ addrs = ares_malloc(ancount * sizeof(struct in_addr));
98
+ if (!addrs)
99
+ {
100
+ ares_free(hostname);
101
+ return ARES_ENOMEM;
102
+ }
103
+ aliases = ares_malloc((ancount + 1) * sizeof(char *));
104
+ if (!aliases)
105
+ {
106
+ ares_free(hostname);
107
+ ares_free(addrs);
108
+ return ARES_ENOMEM;
109
+ }
110
+ }
111
+ else
112
+ {
113
+ addrs = NULL;
114
+ aliases = NULL;
115
+ }
116
+
117
+ naddrs = 0;
118
+ naliases = 0;
119
+
120
+ /* Examine each answer resource record (RR) in turn. */
121
+ for (i = 0; i < (int)ancount; i++)
122
+ {
123
+ /* Decode the RR up to the data field. */
124
+ status = ares__expand_name_for_response(aptr, abuf, alen, &rr_name, &len);
125
+ if (status != ARES_SUCCESS)
126
+ break;
127
+ aptr += len;
128
+ if (aptr + RRFIXEDSZ > abuf + alen)
129
+ {
130
+ ares_free(rr_name);
131
+ status = ARES_EBADRESP;
132
+ break;
133
+ }
134
+ rr_type = DNS_RR_TYPE(aptr);
135
+ rr_class = DNS_RR_CLASS(aptr);
136
+ rr_len = DNS_RR_LEN(aptr);
137
+ rr_ttl = DNS_RR_TTL(aptr);
138
+ aptr += RRFIXEDSZ;
139
+ if (aptr + rr_len > abuf + alen)
140
+ {
141
+ ares_free(rr_name);
142
+ status = ARES_EBADRESP;
143
+ break;
144
+ }
145
+
146
+ if (rr_class == C_IN && rr_type == T_A
147
+ && rr_len == sizeof(struct in_addr)
148
+ && strcasecmp(rr_name, hostname) == 0)
149
+ {
150
+ if (addrs)
151
+ {
152
+ if (aptr + sizeof(struct in_addr) > abuf + alen)
153
+ { /* LCOV_EXCL_START: already checked above */
154
+ ares_free(rr_name);
155
+ status = ARES_EBADRESP;
156
+ break;
157
+ } /* LCOV_EXCL_STOP */
158
+ memcpy(&addrs[naddrs], aptr, sizeof(struct in_addr));
159
+ }
160
+ if (naddrs < max_addr_ttls)
161
+ {
162
+ struct ares_addrttl * const at = &addrttls[naddrs];
163
+ if (aptr + sizeof(struct in_addr) > abuf + alen)
164
+ { /* LCOV_EXCL_START: already checked above */
165
+ ares_free(rr_name);
166
+ status = ARES_EBADRESP;
167
+ break;
168
+ } /* LCOV_EXCL_STOP */
169
+ memcpy(&at->ipaddr, aptr, sizeof(struct in_addr));
170
+ at->ttl = rr_ttl;
171
+ }
172
+ naddrs++;
173
+ status = ARES_SUCCESS;
174
+ }
175
+
176
+ if (rr_class == C_IN && rr_type == T_CNAME)
177
+ {
178
+ /* Record the RR name as an alias. */
179
+ if (aliases)
180
+ aliases[naliases] = rr_name;
181
+ else
182
+ ares_free(rr_name);
183
+ naliases++;
184
+
185
+ /* Decode the RR data and replace the hostname with it. */
186
+ status = ares__expand_name_for_response(aptr, abuf, alen, &rr_data,
187
+ &len);
188
+ if (status != ARES_SUCCESS)
189
+ break;
190
+ ares_free(hostname);
191
+ hostname = rr_data;
192
+
193
+ /* Take the min of the TTLs we see in the CNAME chain. */
194
+ if (cname_ttl > rr_ttl)
195
+ cname_ttl = rr_ttl;
196
+ }
197
+ else
198
+ ares_free(rr_name);
199
+
200
+ aptr += rr_len;
201
+ if (aptr > abuf + alen)
202
+ { /* LCOV_EXCL_START: already checked above */
203
+ status = ARES_EBADRESP;
204
+ break;
205
+ } /* LCOV_EXCL_STOP */
206
+ }
207
+
208
+ if (status == ARES_SUCCESS && naddrs == 0 && naliases == 0)
209
+ /* the check for naliases to be zero is to make sure CNAME responses
210
+ don't get caught here */
211
+ status = ARES_ENODATA;
212
+ if (status == ARES_SUCCESS)
213
+ {
214
+ /* We got our answer. */
215
+ if (naddrttls)
216
+ {
217
+ const int n = naddrs < max_addr_ttls ? naddrs : max_addr_ttls;
218
+ for (i = 0; i < n; i++)
219
+ {
220
+ /* Ensure that each A TTL is no larger than the CNAME TTL. */
221
+ if (addrttls[i].ttl > cname_ttl)
222
+ addrttls[i].ttl = cname_ttl;
223
+ }
224
+ *naddrttls = n;
225
+ }
226
+ if (aliases)
227
+ aliases[naliases] = NULL;
228
+ if (host)
229
+ {
230
+ /* Allocate memory to build the host entry. */
231
+ hostent = ares_malloc(sizeof(struct hostent));
232
+ if (hostent)
233
+ {
234
+ hostent->h_addr_list = ares_malloc((naddrs + 1) * sizeof(char *));
235
+ if (hostent->h_addr_list)
236
+ {
237
+ /* Fill in the hostent and return successfully. */
238
+ hostent->h_name = hostname;
239
+ hostent->h_aliases = aliases;
240
+ hostent->h_addrtype = AF_INET;
241
+ hostent->h_length = sizeof(struct in_addr);
242
+ for (i = 0; i < naddrs; i++)
243
+ hostent->h_addr_list[i] = (char *) &addrs[i];
244
+ hostent->h_addr_list[naddrs] = NULL;
245
+ if (!naddrs && addrs)
246
+ ares_free(addrs);
247
+ *host = hostent;
248
+ return ARES_SUCCESS;
249
+ }
250
+ ares_free(hostent);
251
+ }
252
+ status = ARES_ENOMEM;
253
+ }
254
+ }
255
+ if (aliases)
256
+ {
257
+ for (i = 0; i < naliases; i++)
258
+ ares_free(aliases[i]);
259
+ ares_free(aliases);
260
+ }
261
+ ares_free(addrs);
262
+ ares_free(hostname);
263
+ return status;
264
+ }