• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:env

22 #include "async_wrap-inl.h"
23 #include "base_object-inl.h"
24 #include "base64-inl.h"
26 #include "env-inl.h"
27 #include "memory_tracker-inl.h"
30 #include "req_wrap-inl.h"
31 #include "util-inl.h"
85 ChannelWrap* channel = task->channel; in ares_poll_cb()
88 uv_timer_again(channel->timer_handle()); in ares_poll_cb()
93 ares_process_fd(channel->cares_channel(), task->sock, task->sock); in ares_poll_cb()
98 ares_process_fd(channel->cares_channel(), in ares_poll_cb()
99 events & UV_READABLE ? task->sock : ARES_SOCKET_BAD, in ares_poll_cb()
100 events & UV_WRITABLE ? task->sock : ARES_SOCKET_BAD); in ares_poll_cb()
117 auto it = channel->task_list()->find(&lookup_task); in ares_sockstate_cb()
119 task = (it == channel->task_list()->end()) ? nullptr : *it; in ares_sockstate_cb()
124 channel->StartTimer(); in ares_sockstate_cb()
134 channel->task_list()->insert(task); in ares_sockstate_cb()
139 uv_poll_start(&task->poll_watcher, in ares_sockstate_cb()
144 /* read == 0 and write == 0 this is c-ares's way of notifying us that */ in ares_sockstate_cb()
150 channel->task_list()->erase(it); in ares_sockstate_cb()
151 channel->env()->CloseHandle(&task->poll_watcher, ares_poll_close_cb); in ares_sockstate_cb()
153 if (channel->task_list()->empty()) { in ares_sockstate_cb()
154 channel->CloseTimer(); in ares_sockstate_cb()
159 Local<Array> HostentToNames(Environment* env, struct hostent* host) { in HostentToNames() argument
160 EscapableHandleScope scope(env->isolate()); in HostentToNames()
164 for (uint32_t i = 0; host->h_aliases[i] != nullptr; ++i) in HostentToNames()
165 names.emplace_back(OneByteString(env->isolate(), host->h_aliases[i])); in HostentToNames()
167 Local<Array> ret = Array::New(env->isolate(), names.data(), names.size()); in HostentToNames()
172 Local<Array> HostentToNames(Environment* env, in HostentToNames() argument
175 size_t offset = names->Length(); in HostentToNames()
177 for (uint32_t i = 0; host->h_aliases[i] != nullptr; ++i) { in HostentToNames()
178 names->Set( in HostentToNames()
179 env->context(), in HostentToNames()
181 OneByteString(env->isolate(), host->h_aliases[i])).Check(); in HostentToNames()
189 Environment* env, in AddrTTLToArray() argument
194 ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl); in AddrTTLToArray()
196 return Array::New(env->isolate(), ttls.out(), naddrttls); in AddrTTLToArray()
200 Environment* env, in ParseGeneralReply() argument
207 HandleScope handle_scope(env->isolate()); in ParseGeneralReply()
248 if ((*type == ns_t_cname_or_a && ptr->h_name && ptr->h_aliases[0]) || in ParseGeneralReply()
253 ret->Set(env->context(), in ParseGeneralReply()
254 ret->Length(), in ParseGeneralReply()
255 OneByteString(env->isolate(), ptr->h_name)).Check(); in ParseGeneralReply()
263 HostentToNames(env, ptr.get(), ret); in ParseGeneralReply()
265 uint32_t offset = ret->Length(); in ParseGeneralReply()
266 for (uint32_t i = 0; ptr->h_aliases[i] != nullptr; i++) { in ParseGeneralReply()
267 auto alias = OneByteString(env->isolate(), ptr->h_aliases[i]); in ParseGeneralReply()
268 ret->Set(env->context(), i + offset, alias).Check(); in ParseGeneralReply()
271 uint32_t offset = ret->Length(); in ParseGeneralReply()
273 for (uint32_t i = 0; ptr->h_addr_list[i] != nullptr; ++i) { in ParseGeneralReply()
274 uv_inet_ntop(ptr->h_addrtype, ptr->h_addr_list[i], ip, sizeof(ip)); in ParseGeneralReply()
275 auto address = OneByteString(env->isolate(), ip); in ParseGeneralReply()
276 ret->Set(env->context(), i + offset, address).Check(); in ParseGeneralReply()
284 Environment* env, in ParseMxReply() argument
289 HandleScope handle_scope(env->isolate()); in ParseMxReply()
296 uint32_t offset = ret->Length(); in ParseMxReply()
298 for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { in ParseMxReply()
299 Local<Object> mx_record = Object::New(env->isolate()); in ParseMxReply()
300 mx_record->Set(env->context(), in ParseMxReply()
301 env->exchange_string(), in ParseMxReply()
302 OneByteString(env->isolate(), current->host)).Check(); in ParseMxReply()
303 mx_record->Set(env->context(), in ParseMxReply()
304 env->priority_string(), in ParseMxReply()
305 Integer::New(env->isolate(), current->priority)).Check(); in ParseMxReply()
307 mx_record->Set(env->context(), in ParseMxReply()
308 env->type_string(), in ParseMxReply()
309 env->dns_mx_string()).Check(); in ParseMxReply()
311 ret->Set(env->context(), i + offset, mx_record).Check(); in ParseMxReply()
319 Environment* env, in ParseCaaReply() argument
324 HandleScope handle_scope(env->isolate()); in ParseCaaReply()
331 uint32_t offset = ret->Length(); in ParseCaaReply()
333 for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { in ParseCaaReply()
334 Local<Object> caa_record = Object::New(env->isolate()); in ParseCaaReply()
336 caa_record->Set(env->context(), in ParseCaaReply()
337 env->dns_critical_string(), in ParseCaaReply()
338 Integer::New(env->isolate(), current->critical)).Check(); in ParseCaaReply()
339 caa_record->Set(env->context(), in ParseCaaReply()
340 OneByteString(env->isolate(), current->property), in ParseCaaReply()
341 OneByteString(env->isolate(), current->value)).Check(); in ParseCaaReply()
343 caa_record->Set(env->context(), in ParseCaaReply()
344 env->type_string(), in ParseCaaReply()
345 env->dns_caa_string()).Check(); in ParseCaaReply()
347 ret->Set(env->context(), i + offset, caa_record).Check(); in ParseCaaReply()
355 Environment* env, in ParseTxtReply() argument
360 HandleScope handle_scope(env->isolate()); in ParseTxtReply()
372 uint32_t offset = ret->Length(); in ParseTxtReply()
373 for (j = 0; current != nullptr; current = current->next) { in ParseTxtReply()
375 OneByteString(env->isolate(), current->txt, current->length); in ParseTxtReply()
377 // New record found - write out the current chunk in ParseTxtReply()
378 if (current->record_start) { in ParseTxtReply()
381 Local<Object> elem = Object::New(env->isolate()); in ParseTxtReply()
382 elem->Set(env->context(), env->entries_string(), txt_chunk).Check(); in ParseTxtReply()
383 elem->Set(env->context(), in ParseTxtReply()
384 env->type_string(), in ParseTxtReply()
385 env->dns_txt_string()).Check(); in ParseTxtReply()
386 ret->Set(env->context(), offset + i++, elem).Check(); in ParseTxtReply()
388 ret->Set(env->context(), offset + i++, txt_chunk).Check(); in ParseTxtReply()
392 txt_chunk = Array::New(env->isolate()); in ParseTxtReply()
396 txt_chunk->Set(env->context(), j++, txt).Check(); in ParseTxtReply()
402 Local<Object> elem = Object::New(env->isolate()); in ParseTxtReply()
403 elem->Set(env->context(), env->entries_string(), txt_chunk).Check(); in ParseTxtReply()
404 elem->Set(env->context(), in ParseTxtReply()
405 env->type_string(), in ParseTxtReply()
406 env->dns_txt_string()).Check(); in ParseTxtReply()
407 ret->Set(env->context(), offset + i, elem).Check(); in ParseTxtReply()
409 ret->Set(env->context(), offset + i, txt_chunk).Check(); in ParseTxtReply()
419 Environment* env, in ParseSrvReply() argument
424 HandleScope handle_scope(env->isolate()); in ParseSrvReply()
432 int offset = ret->Length(); in ParseSrvReply()
433 for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { in ParseSrvReply()
434 Local<Object> srv_record = Object::New(env->isolate()); in ParseSrvReply()
435 srv_record->Set(env->context(), in ParseSrvReply()
436 env->name_string(), in ParseSrvReply()
437 OneByteString(env->isolate(), current->host)).Check(); in ParseSrvReply()
438 srv_record->Set(env->context(), in ParseSrvReply()
439 env->port_string(), in ParseSrvReply()
440 Integer::New(env->isolate(), current->port)).Check(); in ParseSrvReply()
441 srv_record->Set(env->context(), in ParseSrvReply()
442 env->priority_string(), in ParseSrvReply()
443 Integer::New(env->isolate(), current->priority)).Check(); in ParseSrvReply()
444 srv_record->Set(env->context(), in ParseSrvReply()
445 env->weight_string(), in ParseSrvReply()
446 Integer::New(env->isolate(), current->weight)).Check(); in ParseSrvReply()
448 srv_record->Set(env->context(), in ParseSrvReply()
449 env->type_string(), in ParseSrvReply()
450 env->dns_srv_string()).Check(); in ParseSrvReply()
452 ret->Set(env->context(), i + offset, srv_record).Check(); in ParseSrvReply()
461 Environment* env, in ParseNaptrReply() argument
466 HandleScope handle_scope(env->isolate()); in ParseNaptrReply()
475 int offset = ret->Length(); in ParseNaptrReply()
476 for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { in ParseNaptrReply()
477 Local<Object> naptr_record = Object::New(env->isolate()); in ParseNaptrReply()
478 naptr_record->Set(env->context(), in ParseNaptrReply()
479 env->flags_string(), in ParseNaptrReply()
480 OneByteString(env->isolate(), current->flags)).Check(); in ParseNaptrReply()
481 naptr_record->Set(env->context(), in ParseNaptrReply()
482 env->service_string(), in ParseNaptrReply()
483 OneByteString(env->isolate(), in ParseNaptrReply()
484 current->service)).Check(); in ParseNaptrReply()
485 naptr_record->Set(env->context(), in ParseNaptrReply()
486 env->regexp_string(), in ParseNaptrReply()
487 OneByteString(env->isolate(), in ParseNaptrReply()
488 current->regexp)).Check(); in ParseNaptrReply()
489 naptr_record->Set(env->context(), in ParseNaptrReply()
490 env->replacement_string(), in ParseNaptrReply()
491 OneByteString(env->isolate(), in ParseNaptrReply()
492 current->replacement)).Check(); in ParseNaptrReply()
493 naptr_record->Set(env->context(), in ParseNaptrReply()
494 env->order_string(), in ParseNaptrReply()
495 Integer::New(env->isolate(), current->order)).Check(); in ParseNaptrReply()
496 naptr_record->Set(env->context(), in ParseNaptrReply()
497 env->preference_string(), in ParseNaptrReply()
498 Integer::New(env->isolate(), in ParseNaptrReply()
499 current->preference)).Check(); in ParseNaptrReply()
501 naptr_record->Set(env->context(), in ParseNaptrReply()
502 env->type_string(), in ParseNaptrReply()
503 env->dns_naptr_string()).Check(); in ParseNaptrReply()
505 ret->Set(env->context(), i + offset, naptr_record).Check(); in ParseNaptrReply()
514 Environment* env, in ParseSoaReply() argument
518 EscapableHandleScope handle_scope(env->isolate()); in ParseSoaReply()
598 Local<Object> soa_record = Object::New(env->isolate()); in ParseSoaReply()
599 soa_record->Set(env->context(), in ParseSoaReply()
600 env->nsname_string(), in ParseSoaReply()
601 OneByteString(env->isolate(), nsname.get())).Check(); in ParseSoaReply()
602 soa_record->Set(env->context(), in ParseSoaReply()
603 env->hostmaster_string(), in ParseSoaReply()
604 OneByteString(env->isolate(), in ParseSoaReply()
606 soa_record->Set(env->context(), in ParseSoaReply()
607 env->serial_string(), in ParseSoaReply()
608 Integer::NewFromUnsigned(env->isolate(), serial)).Check(); in ParseSoaReply()
609 soa_record->Set(env->context(), in ParseSoaReply()
610 env->refresh_string(), in ParseSoaReply()
611 Integer::New(env->isolate(), refresh)).Check(); in ParseSoaReply()
612 soa_record->Set(env->context(), in ParseSoaReply()
613 env->retry_string(), in ParseSoaReply()
614 Integer::New(env->isolate(), retry)).Check(); in ParseSoaReply()
615 soa_record->Set(env->context(), in ParseSoaReply()
616 env->expire_string(), in ParseSoaReply()
617 Integer::New(env->isolate(), expire)).Check(); in ParseSoaReply()
618 soa_record->Set(env->context(), in ParseSoaReply()
619 env->minttl_string(), in ParseSoaReply()
620 Integer::NewFromUnsigned(env->isolate(), minttl)).Check(); in ParseSoaReply()
621 soa_record->Set(env->context(), in ParseSoaReply()
622 env->type_string(), in ParseSoaReply()
623 env->dns_soa_string()).Check(); in ParseSoaReply()
638 Environment* env, in ChannelWrap() argument
642 : AsyncWrap(env, object, PROVIDER_DNSCHANNEL), in ChannelWrap()
652 tracker->TrackField("timer_handle", *timer_handle_); in MemoryInfo()
653 tracker->TrackField("task_list", task_list_, "NodeAresTask::List"); in MemoryInfo()
659 CHECK(args[0]->IsInt32()); in New()
660 CHECK(args[1]->IsInt32()); in New()
661 const int timeout = args[0].As<Int32>()->Value(); in New()
662 const int tries = args[1].As<Int32>()->Value(); in New()
663 Environment* env = Environment::GetCurrent(args); in New() local
664 new ChannelWrap(env, args.This(), timeout, tries); in New()
668 Environment* env, in GetAddrInfoReqWrap() argument
671 : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_GETADDRINFOREQWRAP), in GetAddrInfoReqWrap()
675 Environment* env, in GetNameInfoReqWrap() argument
677 : ReqWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_GETNAMEINFOREQWRAP) {} in GetNameInfoReqWrap()
679 /* This is called once per second by loop->timer. It is used to constantly */
680 /* call back into c-ares for possibly processing timeouts. */
682 ChannelWrap* channel = static_cast<ChannelWrap*>(handle->data); in AresTimeout()
683 CHECK_EQ(channel->timer_handle(), handle); in AresTimeout()
684 CHECK_EQ(false, channel->task_list()->empty()); in AresTimeout()
685 ares_process_fd(channel->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD); in AresTimeout()
690 tracker->TrackField("channel", channel); in MemoryInfo()
697 task->channel = channel; in Create()
698 task->sock = sock; in Create()
700 if (uv_poll_init_socket(channel->env()->event_loop(), in Create()
701 &task->poll_watcher, sock) < 0) { in Create()
723 // so this is a no-op except for the first call to it. in Setup()
726 return env()->ThrowError(ToErrorCodeString(r)); in Setup()
738 return env()->ThrowError(ToErrorCodeString(r)); in Setup()
747 timer_handle_->data = static_cast<void*>(this); in StartTimer()
748 uv_timer_init(env()->event_loop(), timer_handle_); in StartTimer()
762 env()->CloseHandle(timer_handle_, [](uv_timer_t* handle) { delete handle; }); in CloseTimer()
802 /* if no server or multi-servers, ignore */ in EnsureServers()
804 if (servers->next != nullptr) { in EnsureServers()
831 wrap->AresQuery(name, ns_c_in, ns_t_any); in Send()
836 wrap->AresQuery(name, ns_c_in, ns_t_a); in Send()
841 wrap->AresQuery(name, ns_c_in, ns_t_aaaa); in Send()
846 wrap->AresQuery(name, ns_c_in, T_CAA); in Send()
851 wrap->AresQuery(name, ns_c_in, ns_t_cname); in Send()
856 wrap->AresQuery(name, ns_c_in, ns_t_mx); in Send()
861 wrap->AresQuery(name, ns_c_in, ns_t_ns); in Send()
866 wrap->AresQuery(name, ns_c_in, ns_t_txt); in Send()
871 wrap->AresQuery(name, ns_c_in, ns_t_srv); in Send()
876 wrap->AresQuery(name, ns_c_in, ns_t_ptr); in Send()
881 wrap->AresQuery(name, ns_c_in, ns_t_naptr); in Send()
886 wrap->AresQuery(name, ns_c_in, ns_t_soa); in Send()
893 if (UNLIKELY(response->is_host)) in Parse()
896 unsigned char* buf = response->buf.data; in Parse()
897 int len = response->buf.size; in Parse()
899 Environment* env = wrap->env(); in Parse() local
900 HandleScope handle_scope(env->isolate()); in Parse()
901 Context::Scope context_scope(env->context()); in Parse()
903 Local<Array> ret = Array::New(env->isolate()); in Parse()
911 status = ParseGeneralReply(env, in Parse()
918 uint32_t a_count = ret->Length(); in Parse()
925 Local<Object> obj = Object::New(env->isolate()); in Parse()
926 obj->Set(env->context(), in Parse()
927 env->address_string(), in Parse()
928 ret->Get(env->context(), i).ToLocalChecked()).Check(); in Parse()
929 obj->Set(env->context(), in Parse()
930 env->ttl_string(), in Parse()
932 env->isolate(), addrttls[i].ttl)).Check(); in Parse()
933 obj->Set(env->context(), in Parse()
934 env->type_string(), in Parse()
935 env->dns_a_string()).Check(); in Parse()
936 ret->Set(env->context(), i, obj).Check(); in Parse()
940 Local<Object> obj = Object::New(env->isolate()); in Parse()
941 obj->Set(env->context(), in Parse()
942 env->value_string(), in Parse()
943 ret->Get(env->context(), i).ToLocalChecked()).Check(); in Parse()
944 obj->Set(env->context(), in Parse()
945 env->type_string(), in Parse()
946 env->dns_cname_string()).Check(); in Parse()
947 ret->Set(env->context(), i, obj).Check(); in Parse()
956 status = ParseGeneralReply(env, in Parse()
963 uint32_t aaaa_count = ret->Length() - a_count; in Parse()
968 CHECK_EQ(ret->Length(), a_count + aaaa_count); in Parse()
969 for (uint32_t i = a_count; i < ret->Length(); i++) { in Parse()
970 Local<Object> obj = Object::New(env->isolate()); in Parse()
971 obj->Set(env->context(), in Parse()
972 env->address_string(), in Parse()
973 ret->Get(env->context(), i).ToLocalChecked()).Check(); in Parse()
974 obj->Set(env->context(), in Parse()
975 env->ttl_string(), in Parse()
977 env->isolate(), addr6ttls[i - a_count].ttl)).Check(); in Parse()
978 obj->Set(env->context(), in Parse()
979 env->type_string(), in Parse()
980 env->dns_aaaa_string()).Check(); in Parse()
981 ret->Set(env->context(), i, obj).Check(); in Parse()
985 status = ParseMxReply(env, buf, len, ret, true); in Parse()
991 old_count = ret->Length(); in Parse()
992 status = ParseGeneralReply(env, buf, len, &type, ret); in Parse()
996 for (uint32_t i = old_count; i < ret->Length(); i++) { in Parse()
997 Local<Object> obj = Object::New(env->isolate()); in Parse()
998 obj->Set(env->context(), in Parse()
999 env->value_string(), in Parse()
1000 ret->Get(env->context(), i).ToLocalChecked()).Check(); in Parse()
1001 obj->Set(env->context(), in Parse()
1002 env->type_string(), in Parse()
1003 env->dns_ns_string()).Check(); in Parse()
1004 ret->Set(env->context(), i, obj).Check(); in Parse()
1008 status = ParseTxtReply(env, buf, len, ret, true); in Parse()
1013 status = ParseSrvReply(env, buf, len, ret, true); in Parse()
1019 old_count = ret->Length(); in Parse()
1020 status = ParseGeneralReply(env, buf, len, &type, ret); in Parse()
1023 for (uint32_t i = old_count; i < ret->Length(); i++) { in Parse()
1024 Local<Object> obj = Object::New(env->isolate()); in Parse()
1025 obj->Set(env->context(), in Parse()
1026 env->value_string(), in Parse()
1027 ret->Get(env->context(), i).ToLocalChecked()).Check(); in Parse()
1028 obj->Set(env->context(), in Parse()
1029 env->type_string(), in Parse()
1030 env->dns_ptr_string()).Check(); in Parse()
1031 ret->Set(env->context(), i, obj).Check(); in Parse()
1035 status = ParseNaptrReply(env, buf, len, ret, true); in Parse()
1041 status = ParseSoaReply(env, buf, len, &soa_record); in Parse()
1046 ret->Set(env->context(), ret->Length(), soa_record).Check(); in Parse()
1049 status = ParseCaaReply(env, buf, len, ret, true); in Parse()
1053 wrap->CallOnComplete(ret); in Parse()
1060 if (UNLIKELY(response->is_host)) in Parse()
1063 unsigned char* buf = response->buf.data; in Parse()
1064 int len = response->buf.size; in Parse()
1066 Environment* env = wrap->env(); in Parse() local
1067 HandleScope handle_scope(env->isolate()); in Parse()
1068 Context::Scope context_scope(env->context()); in Parse()
1072 Local<Array> ret = Array::New(env->isolate()); in Parse()
1075 status = ParseGeneralReply(env, in Parse()
1085 Local<Array> ttls = AddrTTLToArray<ares_addrttl>(env, addrttls, naddrttls); in Parse()
1087 wrap->CallOnComplete(ret, ttls); in Parse()
1094 if (UNLIKELY(response->is_host)) in Parse()
1097 unsigned char* buf = response->buf.data; in Parse()
1098 int len = response->buf.size; in Parse()
1100 Environment* env = wrap->env(); in Parse() local
1101 HandleScope handle_scope(env->isolate()); in Parse()
1102 Context::Scope context_scope(env->context()); in Parse()
1106 Local<Array> ret = Array::New(env->isolate()); in Parse()
1109 status = ParseGeneralReply(env, in Parse()
1119 Local<Array> ttls = AddrTTLToArray<ares_addr6ttl>(env, addrttls, naddrttls); in Parse()
1121 wrap->CallOnComplete(ret, ttls); in Parse()
1128 if (UNLIKELY(response->is_host)) in Parse()
1131 unsigned char* buf = response->buf.data; in Parse()
1132 int len = response->buf.size; in Parse()
1134 Environment* env = wrap->env(); in Parse() local
1135 HandleScope handle_scope(env->isolate()); in Parse()
1136 Context::Scope context_scope(env->context()); in Parse()
1138 Local<Array> ret = Array::New(env->isolate()); in Parse()
1139 int status = ParseCaaReply(env, buf, len, ret); in Parse()
1143 wrap->CallOnComplete(ret); in Parse()
1150 if (UNLIKELY(response->is_host)) in Parse()
1153 unsigned char* buf = response->buf.data; in Parse()
1154 int len = response->buf.size; in Parse()
1156 Environment* env = wrap->env(); in Parse() local
1157 HandleScope handle_scope(env->isolate()); in Parse()
1158 Context::Scope context_scope(env->context()); in Parse()
1160 Local<Array> ret = Array::New(env->isolate()); in Parse()
1162 int status = ParseGeneralReply(env, buf, len, &type, ret); in Parse()
1166 wrap->CallOnComplete(ret); in Parse()
1173 if (UNLIKELY(response->is_host)) in Parse()
1176 unsigned char* buf = response->buf.data; in Parse()
1177 int len = response->buf.size; in Parse()
1179 Environment* env = wrap->env(); in Parse() local
1180 HandleScope handle_scope(env->isolate()); in Parse()
1181 Context::Scope context_scope(env->context()); in Parse()
1183 Local<Array> mx_records = Array::New(env->isolate()); in Parse()
1184 int status = ParseMxReply(env, buf, len, mx_records); in Parse()
1189 wrap->CallOnComplete(mx_records); in Parse()
1196 if (UNLIKELY(response->is_host)) in Parse()
1199 unsigned char* buf = response->buf.data; in Parse()
1200 int len = response->buf.size; in Parse()
1202 Environment* env = wrap->env(); in Parse() local
1203 HandleScope handle_scope(env->isolate()); in Parse()
1204 Context::Scope context_scope(env->context()); in Parse()
1207 Local<Array> names = Array::New(env->isolate()); in Parse()
1208 int status = ParseGeneralReply(env, buf, len, &type, names); in Parse()
1212 wrap->CallOnComplete(names); in Parse()
1219 if (UNLIKELY(response->is_host)) in Parse()
1222 unsigned char* buf = response->buf.data; in Parse()
1223 int len = response->buf.size; in Parse()
1225 Environment* env = wrap->env(); in Parse() local
1226 HandleScope handle_scope(env->isolate()); in Parse()
1227 Context::Scope context_scope(env->context()); in Parse()
1229 Local<Array> txt_records = Array::New(env->isolate()); in Parse()
1230 int status = ParseTxtReply(env, buf, len, txt_records); in Parse()
1234 wrap->CallOnComplete(txt_records); in Parse()
1241 if (UNLIKELY(response->is_host)) in Parse()
1244 unsigned char* buf = response->buf.data; in Parse()
1245 int len = response->buf.size; in Parse()
1247 Environment* env = wrap->env(); in Parse() local
1248 HandleScope handle_scope(env->isolate()); in Parse()
1249 Context::Scope context_scope(env->context()); in Parse()
1251 Local<Array> srv_records = Array::New(env->isolate()); in Parse()
1252 int status = ParseSrvReply(env, buf, len, srv_records); in Parse()
1256 wrap->CallOnComplete(srv_records); in Parse()
1263 if (UNLIKELY(response->is_host)) in Parse()
1266 unsigned char* buf = response->buf.data; in Parse()
1267 int len = response->buf.size; in Parse()
1269 Environment* env = wrap->env(); in Parse() local
1270 HandleScope handle_scope(env->isolate()); in Parse()
1271 Context::Scope context_scope(env->context()); in Parse()
1274 Local<Array> aliases = Array::New(env->isolate()); in Parse()
1276 int status = ParseGeneralReply(env, buf, len, &type, aliases); in Parse()
1280 wrap->CallOnComplete(aliases); in Parse()
1287 if (UNLIKELY(response->is_host)) in Parse()
1290 unsigned char* buf = response->buf.data; in Parse()
1291 int len = response->buf.size; in Parse()
1293 Environment* env = wrap->env(); in Parse() local
1294 HandleScope handle_scope(env->isolate()); in Parse()
1295 Context::Scope context_scope(env->context()); in Parse()
1297 Local<Array> naptr_records = Array::New(env->isolate()); in Parse()
1298 int status = ParseNaptrReply(env, buf, len, naptr_records); in Parse()
1302 wrap->CallOnComplete(naptr_records); in Parse()
1309 if (UNLIKELY(response->is_host)) in Parse()
1312 unsigned char* buf = response->buf.data; in Parse()
1313 int len = response->buf.size; in Parse()
1315 Environment* env = wrap->env(); in Parse() local
1316 HandleScope handle_scope(env->isolate()); in Parse()
1317 Context::Scope context_scope(env->context()); in Parse()
1325 Local<Object> soa_record = Object::New(env->isolate()); in Parse()
1327 soa_record->Set(env->context(), in Parse()
1328 env->nsname_string(), in Parse()
1329 OneByteString(env->isolate(), soa_out->nsname)).Check(); in Parse()
1330 soa_record->Set(env->context(), in Parse()
1331 env->hostmaster_string(), in Parse()
1332 OneByteString(env->isolate(), soa_out->hostmaster)).Check(); in Parse()
1333 soa_record->Set(env->context(), in Parse()
1334 env->serial_string(), in Parse()
1336 env->isolate(), soa_out->serial)).Check(); in Parse()
1337 soa_record->Set(env->context(), in Parse()
1338 env->refresh_string(), in Parse()
1339 Integer::New(env->isolate(), soa_out->refresh)).Check(); in Parse()
1340 soa_record->Set(env->context(), in Parse()
1341 env->retry_string(), in Parse()
1342 Integer::New(env->isolate(), soa_out->retry)).Check(); in Parse()
1343 soa_record->Set(env->context(), in Parse()
1344 env->expire_string(), in Parse()
1345 Integer::New(env->isolate(), soa_out->expire)).Check(); in Parse()
1346 soa_record->Set(env->context(), in Parse()
1347 env->minttl_string(), in Parse()
1349 env->isolate(), soa_out->minttl)).Check(); in Parse()
1353 wrap->CallOnComplete(soa_record); in Parse()
1377 wrap->channel()->cares_channel(), in Send()
1382 wrap->MakeCallbackPointer()); in Send()
1389 if (UNLIKELY(!response->is_host)) in Parse()
1392 struct hostent* host = response->host.get(); in Parse()
1394 Environment* env = wrap->env(); in Parse() local
1395 HandleScope handle_scope(env->isolate()); in Parse()
1396 Context::Scope context_scope(env->context()); in Parse()
1397 wrap->CallOnComplete(HostentToNames(env, host)); in Parse()
1404 Environment* env = Environment::GetCurrent(args); in Query() local
1409 CHECK(args[0]->IsObject()); in Query()
1410 CHECK(args[1]->IsString()); in Query()
1416 node::Utf8Value name(env->isolate(), string); in Query()
1417 channel->ModifyActivityQueryCount(1); in Query()
1418 int err = wrap->Send(*name); in Query()
1420 channel->ModifyActivityQueryCount(-1); in Query()
1432 static_cast<GetAddrInfoReqWrap*>(req->data)}; in AfterGetAddrInfo()
1433 Environment* env = req_wrap->env(); in AfterGetAddrInfo() local
1435 HandleScope handle_scope(env->isolate()); in AfterGetAddrInfo()
1436 Context::Scope context_scope(env->context()); in AfterGetAddrInfo()
1439 Integer::New(env->isolate(), status), in AfterGetAddrInfo()
1440 Null(env->isolate()) in AfterGetAddrInfo()
1444 const bool verbatim = req_wrap->verbatim(); in AfterGetAddrInfo()
1447 Local<Array> results = Array::New(env->isolate()); in AfterGetAddrInfo()
1449 auto add = [&] (bool want_ipv4, bool want_ipv6) -> Maybe<bool> { in AfterGetAddrInfo()
1450 for (auto p = res; p != nullptr; p = p->ai_next) { in AfterGetAddrInfo()
1451 CHECK_EQ(p->ai_socktype, SOCK_STREAM); in AfterGetAddrInfo()
1454 if (want_ipv4 && p->ai_family == AF_INET) { in AfterGetAddrInfo()
1456 &(reinterpret_cast<struct sockaddr_in*>(p->ai_addr)->sin_addr)); in AfterGetAddrInfo()
1457 } else if (want_ipv6 && p->ai_family == AF_INET6) { in AfterGetAddrInfo()
1459 &(reinterpret_cast<struct sockaddr_in6*>(p->ai_addr)->sin6_addr)); in AfterGetAddrInfo()
1465 if (uv_inet_ntop(p->ai_family, addr, ip, sizeof(ip))) in AfterGetAddrInfo()
1468 Local<String> s = OneByteString(env->isolate(), ip); in AfterGetAddrInfo()
1469 if (results->Set(env->context(), n, s).IsNothing()) in AfterGetAddrInfo()
1485 argv[0] = Integer::New(env->isolate(), UV_EAI_NODATA); in AfterGetAddrInfo()
1498 req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); in AfterGetAddrInfo()
1507 static_cast<GetNameInfoReqWrap*>(req->data)}; in AfterGetNameInfo()
1508 Environment* env = req_wrap->env(); in AfterGetNameInfo() local
1510 HandleScope handle_scope(env->isolate()); in AfterGetNameInfo()
1511 Context::Scope context_scope(env->context()); in AfterGetNameInfo()
1514 Integer::New(env->isolate(), status), in AfterGetNameInfo()
1515 Null(env->isolate()), in AfterGetNameInfo()
1516 Null(env->isolate()) in AfterGetNameInfo()
1521 Local<String> js_hostname = OneByteString(env->isolate(), hostname); in AfterGetNameInfo()
1522 Local<String> js_service = OneByteString(env->isolate(), service); in AfterGetNameInfo()
1533 req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); in AfterGetNameInfo()
1537 decltype(static_cast<ares_addr_port_node*>(nullptr)->addr);
1564 Environment* env = Environment::GetCurrent(args); in GetAddrInfo() local
1566 CHECK(args[0]->IsObject()); in GetAddrInfo()
1567 CHECK(args[1]->IsString()); in GetAddrInfo()
1568 CHECK(args[2]->IsInt32()); in GetAddrInfo()
1569 CHECK(args[4]->IsBoolean()); in GetAddrInfo()
1571 node::Utf8Value hostname(env->isolate(), args[1]); in GetAddrInfo()
1574 if (args[3]->IsInt32()) { in GetAddrInfo()
1575 flags = args[3].As<Int32>()->Value(); in GetAddrInfo()
1580 switch (args[2].As<Int32>()->Value()) { in GetAddrInfo()
1594 auto req_wrap = std::make_unique<GetAddrInfoReqWrap>(env, in GetAddrInfo()
1596 args[4]->IsTrue()); in GetAddrInfo()
1610 int err = req_wrap->Dispatch(uv_getaddrinfo, in GetAddrInfo()
1624 Environment* env = Environment::GetCurrent(args); in GetNameInfo() local
1626 CHECK(args[0]->IsObject()); in GetNameInfo()
1627 CHECK(args[1]->IsString()); in GetNameInfo()
1628 CHECK(args[2]->IsUint32()); in GetNameInfo()
1630 node::Utf8Value ip(env->isolate(), args[1]); in GetNameInfo()
1631 const unsigned port = args[2]->Uint32Value(env->context()).FromJust(); in GetNameInfo()
1637 auto req_wrap = std::make_unique<GetNameInfoReqWrap>(env, req_wrap_obj); in GetNameInfo()
1643 int err = req_wrap->Dispatch(uv_getnameinfo, in GetNameInfo()
1656 Environment* env = Environment::GetCurrent(args); in GetServers() local
1660 Local<Array> server_array = Array::New(env->isolate()); in GetServers()
1664 int r = ares_get_servers_ports(channel->cares_channel(), &servers); in GetServers()
1670 for (uint32_t i = 0; cur != nullptr; ++i, cur = cur->next) { in GetServers()
1673 const void* caddr = static_cast<const void*>(&cur->addr); in GetServers()
1674 int err = uv_inet_ntop(cur->family, caddr, ip, sizeof(ip)); in GetServers()
1678 OneByteString(env->isolate(), ip), in GetServers()
1679 Integer::New(env->isolate(), cur->udp_port) in GetServers()
1682 if (server_array->Set(env->context(), i, in GetServers()
1683 Array::New(env->isolate(), ret, arraysize(ret))) in GetServers()
1694 Environment* env = Environment::GetCurrent(args); in SetServers() local
1698 if (channel->active_query_count()) { in SetServers()
1702 CHECK(args[0]->IsArray()); in SetServers()
1706 uint32_t len = arr->Length(); in SetServers()
1709 int rv = ares_set_servers(channel->cares_channel(), nullptr); in SetServers()
1719 CHECK(arr->Get(env->context(), i).ToLocalChecked()->IsArray()); in SetServers()
1722 Local<Array>::Cast(arr->Get(env->context(), i).ToLocalChecked()); in SetServers()
1724 CHECK(elm->Get(env->context(), in SetServers()
1725 0).ToLocalChecked()->Int32Value(env->context()).FromJust()); in SetServers()
1726 CHECK(elm->Get(env->context(), 1).ToLocalChecked()->IsString()); in SetServers()
1727 CHECK(elm->Get(env->context(), in SetServers()
1728 2).ToLocalChecked()->Int32Value(env->context()).FromJust()); in SetServers()
1730 int fam = elm->Get(env->context(), 0) in SetServers()
1731 .ToLocalChecked()->Int32Value(env->context()).FromJust(); in SetServers()
1732 node::Utf8Value ip(env->isolate(), in SetServers()
1733 elm->Get(env->context(), 1).ToLocalChecked()); in SetServers()
1734 int port = elm->Get(env->context(), 2) in SetServers()
1735 .ToLocalChecked()->Int32Value(env->context()).FromJust(); in SetServers()
1739 cur->tcp_port = cur->udp_port = port; in SetServers()
1742 cur->family = AF_INET; in SetServers()
1743 err = uv_inet_pton(AF_INET, *ip, &cur->addr); in SetServers()
1746 cur->family = AF_INET6; in SetServers()
1747 err = uv_inet_pton(AF_INET6, *ip, &cur->addr); in SetServers()
1756 cur->next = nullptr; in SetServers()
1759 last->next = cur; in SetServers()
1765 err = ares_set_servers_ports(channel->cares_channel(), &servers[0]); in SetServers()
1770 channel->set_is_servers_default(false); in SetServers()
1776 Environment* env = Environment::GetCurrent(args); in SetLocalAddress() local
1781 CHECK(args[0]->IsString()); in SetLocalAddress()
1796 ares_set_local_ip4(channel->cares_channel(), ReadUint32BE(addr0)); in SetLocalAddress()
1799 ares_set_local_ip6(channel->cares_channel(), addr0); in SetLocalAddress()
1802 THROW_ERR_INVALID_ARG_VALUE(env, "Invalid IP address."); in SetLocalAddress()
1806 if (!args[1]->IsUndefined()) { in SetLocalAddress()
1807 CHECK(args[1]->IsString()); in SetLocalAddress()
1812 THROW_ERR_INVALID_ARG_VALUE(env, "Cannot specify two IPv4 addresses."); in SetLocalAddress()
1815 ares_set_local_ip4(channel->cares_channel(), ReadUint32BE(addr1)); in SetLocalAddress()
1819 THROW_ERR_INVALID_ARG_VALUE(env, "Cannot specify two IPv6 addresses."); in SetLocalAddress()
1822 ares_set_local_ip6(channel->cares_channel(), addr1); in SetLocalAddress()
1825 THROW_ERR_INVALID_ARG_VALUE(env, "Invalid IP address."); in SetLocalAddress()
1832 ares_set_local_ip6(channel->cares_channel(), addr1); in SetLocalAddress()
1834 ares_set_local_ip4(channel->cares_channel(), 0); in SetLocalAddress()
1846 ares_cancel(channel->cares_channel()); in Cancel()
1851 Environment* env = Environment::GetCurrent(args); in StrError() local
1852 int code = args[0]->Int32Value(env->context()).FromJust(); in StrError()
1856 args.GetReturnValue().Set(OneByteString(env->isolate(), errmsg)); in StrError()
1864 if (host->h_addr_list != nullptr) { in safe_free_hostent()
1866 while (host->h_addr_list[idx]) { in safe_free_hostent()
1867 free(host->h_addr_list[idx++]); in safe_free_hostent()
1869 free(host->h_addr_list); in safe_free_hostent()
1870 host->h_addr_list = nullptr; in safe_free_hostent()
1873 if (host->h_aliases != nullptr) { in safe_free_hostent()
1875 while (host->h_aliases[idx]) { in safe_free_hostent()
1876 free(host->h_aliases[idx++]); in safe_free_hostent()
1878 free(host->h_aliases); in safe_free_hostent()
1879 host->h_aliases = nullptr; in safe_free_hostent()
1882 free(host->h_name); in safe_free_hostent()
1890 Environment* env = Environment::GetCurrent(context); in Initialize() local
1892 env->SetMethod(target, "getaddrinfo", GetAddrInfo); in Initialize()
1893 env->SetMethod(target, "getnameinfo", GetNameInfo); in Initialize()
1894 env->SetMethodNoSideEffect(target, "canonicalizeIP", CanonicalizeIP); in Initialize()
1896 env->SetMethod(target, "strerror", StrError); in Initialize()
1898 target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET"), in Initialize()
1899 Integer::New(env->isolate(), AF_INET)).Check(); in Initialize()
1900 target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "AF_INET6"), in Initialize()
1901 Integer::New(env->isolate(), AF_INET6)).Check(); in Initialize()
1902 target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), in Initialize()
1904 Integer::New(env->isolate(), AF_UNSPEC)).Check(); in Initialize()
1905 target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), in Initialize()
1907 Integer::New(env->isolate(), AI_ADDRCONFIG)).Check(); in Initialize()
1908 target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), in Initialize()
1910 Integer::New(env->isolate(), AI_ALL)).Check(); in Initialize()
1911 target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), in Initialize()
1913 Integer::New(env->isolate(), AI_V4MAPPED)).Check(); in Initialize()
1916 BaseObject::MakeLazilyInitializedJSTemplate(env); in Initialize()
1917 aiw->Inherit(AsyncWrap::GetConstructorTemplate(env)); in Initialize()
1918 env->SetConstructorFunction(target, "GetAddrInfoReqWrap", aiw); in Initialize()
1921 BaseObject::MakeLazilyInitializedJSTemplate(env); in Initialize()
1922 niw->Inherit(AsyncWrap::GetConstructorTemplate(env)); in Initialize()
1923 env->SetConstructorFunction(target, "GetNameInfoReqWrap", niw); in Initialize()
1926 BaseObject::MakeLazilyInitializedJSTemplate(env); in Initialize()
1927 qrw->Inherit(AsyncWrap::GetConstructorTemplate(env)); in Initialize()
1928 env->SetConstructorFunction(target, "QueryReqWrap", qrw); in Initialize()
1931 env->NewFunctionTemplate(ChannelWrap::New); in Initialize()
1932 channel_wrap->InstanceTemplate()->SetInternalFieldCount( in Initialize()
1934 channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env)); in Initialize()
1936 env->SetProtoMethod(channel_wrap, "queryAny", Query<QueryAnyWrap>); in Initialize()
1937 env->SetProtoMethod(channel_wrap, "queryA", Query<QueryAWrap>); in Initialize()
1938 env->SetProtoMethod(channel_wrap, "queryAaaa", Query<QueryAaaaWrap>); in Initialize()
1939 env->SetProtoMethod(channel_wrap, "queryCaa", Query<QueryCaaWrap>); in Initialize()
1940 env->SetProtoMethod(channel_wrap, "queryCname", Query<QueryCnameWrap>); in Initialize()
1941 env->SetProtoMethod(channel_wrap, "queryMx", Query<QueryMxWrap>); in Initialize()
1942 env->SetProtoMethod(channel_wrap, "queryNs", Query<QueryNsWrap>); in Initialize()
1943 env->SetProtoMethod(channel_wrap, "queryTxt", Query<QueryTxtWrap>); in Initialize()
1944 env->SetProtoMethod(channel_wrap, "querySrv", Query<QuerySrvWrap>); in Initialize()
1945 env->SetProtoMethod(channel_wrap, "queryPtr", Query<QueryPtrWrap>); in Initialize()
1946 env->SetProtoMethod(channel_wrap, "queryNaptr", Query<QueryNaptrWrap>); in Initialize()
1947 env->SetProtoMethod(channel_wrap, "querySoa", Query<QuerySoaWrap>); in Initialize()
1948 env->SetProtoMethod(channel_wrap, "getHostByAddr", Query<GetHostByAddrWrap>); in Initialize()
1950 env->SetProtoMethodNoSideEffect(channel_wrap, "getServers", GetServers); in Initialize()
1951 env->SetProtoMethod(channel_wrap, "setServers", SetServers); in Initialize()
1952 env->SetProtoMethod(channel_wrap, "setLocalAddress", SetLocalAddress); in Initialize()
1953 env->SetProtoMethod(channel_wrap, "cancel", Cancel); in Initialize()
1955 env->SetConstructorFunction(target, "ChannelWrap", channel_wrap); in Initialize()