Home | History | Annotate | Download | only in c-ares

Lines Matching full:channel

79 static int init_by_options(ares_channel channel, const struct ares_options *options,
81 static int init_by_environment(ares_channel channel);
82 static int init_by_resolv_conf(ares_channel channel);
83 static int init_by_defaults(ares_channel channel);
89 static int set_search(ares_channel channel, const char *str);
90 static int set_options(ares_channel channel, const char *str);
98 static int config_domain(ares_channel channel, char *str);
99 static int config_lookup(ares_channel channel, const char *str,
120 ares_channel channel;
142 channel = malloc(sizeof(struct ares_channeldata));
143 if (!channel) {
153 channel->flags = -1;
154 channel->timeout = -1;
155 channel->tries = -1;
156 channel->ndots = -1;
157 channel->rotate = -1;
158 channel->udp_port = -1;
159 channel->tcp_port = -1;
160 channel->socket_send_buffer_size = -1;
161 channel->socket_receive_buffer_size = -1;
162 channel->nservers = -1;
163 channel->ndomains = -1;
164 channel->nsort = -1;
165 channel->tcp_connection_generation = 0;
166 channel->lookups = NULL;
167 channel->domains = NULL;
168 channel->sortlist = NULL;
169 channel->servers = NULL;
170 channel->sock_state_cb = NULL;
171 channel->sock_state_cb_data = NULL;
172 channel->sock_create_cb = NULL;
173 channel->sock_create_cb_data = NULL;
175 channel->last_server = 0;
176 channel->last_timeout_processed = (time_t)now.tv_sec;
178 memset(&channel->local_dev_name, 0, sizeof(channel->local_dev_name));
179 channel->local_ip4 = 0;
180 memset(&channel->local_ip6, 0, sizeof(channel->local_ip6));
183 ares__init_list_head(&(channel->all_queries));
186 ares__init_list_head(&(channel->queries_by_qid[i]));
190 ares__init_list_head(&(channel->queries_by_timeout[i]));
198 status = init_by_options(channel, options, optmask);
204 status = init_by_environment(channel);
210 status = init_by_resolv_conf(channel);
220 status = init_by_defaults(channel);
228 status = init_id_key(&channel->id_key, ARES_ID_KEY_LEN);
230 channel->next_id = ares__generate_new_id(&channel->id_key);
239 if (channel->servers)
240 free(channel->servers);
241 if (channel->domains)
243 for (i = 0; i < channel->ndomains; i++)
244 free(channel->domains[i]);
245 free(channel->domains);
247 if (channel->sortlist)
248 free(channel->sortlist);
249 if(channel->lookups)
250 free(channel->lookups);
251 free(channel);
256 if ((channel->flags & ARES_FLAG_PRIMARY) && channel->nservers > 1)
257 channel->nservers = 1;
259 ares__init_servers_state(channel);
261 *channelptr = channel;
265 /* ares_dup() duplicates a channel handle with all its options and returns a
266 new channel handle */
283 /* Then create the new channel with those options */
321 /* Save options from initialized channel */
322 int ares_save_options(ares_channel channel, struct ares_options *options,
331 if (!ARES_CONFIG_CHECK(channel))
334 /* Traditionally the optmask wasn't saved in the channel struct so it was
341 (channel->optmask & ARES_OPT_ROTATE);
344 options->flags = channel->flags;
348 options->timeout = channel->timeout;
349 options->tries = channel->tries;
350 options->ndots = channel->ndots;
351 options->udp_port = (unsigned short)channel->udp_port;
352 options->tcp_port = (unsigned short)channel->tcp_port;
353 options->sock_state_cb = channel->sock_state_cb;
354 options->sock_state_cb_data = channel->sock_state_cb_data;
357 if (channel->nservers) {
358 for (i = 0; i < channel->nservers; i++)
360 if (channel->servers[i].addr.family == AF_INET)
367 for (i = j = 0; i < channel->nservers; i++)
369 if (channel->servers[i].addr.family == AF_INET)
371 &channel->servers[i].addr.addrV4,
372 sizeof(channel->servers[i].addr.addrV4));
379 if (channel->ndomains) {
380 options->domains = malloc(channel->ndomains * sizeof(char *));
384 for (i = 0; i < channel->ndomains; i++)
387 options->domains[i] = strdup(channel->domains[i]);
392 options->ndomains = channel->ndomains;
395 if (channel->lookups) {
396 options->lookups = strdup(channel->lookups);
397 if (!options->lookups && channel->lookups)
402 if (channel->nsort) {
403 options->sortlist = malloc(channel->nsort * sizeof(struct apattern));
406 for (i = 0; i < channel->nsort; i++)
407 options->sortlist[i] = channel->sortlist[i];
409 options->nsort = channel->nsort;
414 static int init_by_options(ares_channel channel,
421 if ((optmask & ARES_OPT_FLAGS) && channel->flags == -1)
422 channel->flags = options->flags;
423 if ((optmask & ARES_OPT_TIMEOUTMS) && channel->timeout == -1)
424 channel->timeout = options->timeout;
425 else if ((optmask & ARES_OPT_TIMEOUT) && channel->timeout == -1)
426 channel->timeout = options->timeout * 1000;
427 if ((optmask & ARES_OPT_TRIES) && channel->tries == -1)
428 channel->tries = options->tries;
429 if ((optmask & ARES_OPT_NDOTS) && channel->ndots == -1)
430 channel->ndots = options->ndots;
431 if ((optmask & ARES_OPT_ROTATE) && channel->rotate == -1)
432 channel->rotate = 1;
433 if ((optmask & ARES_OPT_UDP_PORT) && channel->udp_port == -1)
434 channel->udp_port = options->udp_port;
435 if ((optmask & ARES_OPT_TCP_PORT) && channel->tcp_port == -1)
436 channel->tcp_port = options->tcp_port;
437 if ((optmask & ARES_OPT_SOCK_STATE_CB) && channel->sock_state_cb == NULL)
439 channel->sock_state_cb = options->sock_state_cb;
440 channel->sock_state_cb_data = options->sock_state_cb_data;
443 && channel->socket_send_buffer_size == -1)
444 channel->socket_send_buffer_size = options->socket_send_buffer_size;
446 && channel->socket_receive_buffer_size == -1)
447 channel->socket_receive_buffer_size = options->socket_receive_buffer_size;
450 if ((optmask & ARES_OPT_SERVERS) && channel->nservers == -1)
455 channel->servers =
457 if (!channel->servers)
461 channel->servers[i].addr.family = AF_INET;
462 memcpy(&channel->servers[i].addr.addrV4,
464 sizeof(channel->servers[i].addr.addrV4));
467 channel->nservers = options->nservers;
470 /* Copy the domains, if given. Keep channel->ndomains consistent so
473 if ((optmask & ARES_OPT_DOMAINS) && channel->ndomains == -1)
478 channel->domains = malloc(options->ndomains * sizeof(char *));
479 if (!channel->domains)
483 channel->ndomains = i;
484 channel->domains[i] = strdup(options->domains[i]);
485 if (!channel->domains[i])
489 channel->ndomains = options->ndomains;
493 if ((optmask & ARES_OPT_LOOKUPS) && !channel->lookups)
495 channel->lookups = strdup(options->lookups);
496 if (!channel->lookups)
501 if ((optmask & ARES_OPT_SORTLIST) && (channel->nsort == -1) &&
503 channel->sortlist = malloc(options->nsort * sizeof(struct apattern));
504 if (!channel->sortlist)
507 channel->sortlist[i] = options->sortlist[i];
508 channel->nsort = options->nsort;
511 channel->optmask = optmask;
516 static int init_by_environment(ares_channel channel)
522 if (localdomain && channel->ndomains == -1)
524 status = set_search(channel, localdomain);
532 status = set_options(channel, res_options);
788 static int init_by_resolv_conf(ares_channel channel)
830 if (channel->nservers > -1) /* don't override ARES_OPT_SERVER */
978 if (ARES_CONFIG_CHECK(channel))
986 status = config_domain(channel, p);
987 else if ((p = try_config(line, "lookup", ';')) && !channel->lookups)
988 status = config_lookup(channel, p, "bind", "file");
990 status = set_search(channel, p);
992 channel->nservers == -1)
995 channel->nsort == -1)
998 status = set_options(channel, p);
1021 if ((status == ARES_EOF) && (!channel->lookups)) {
1027 if ((p = try_config(line, "hosts:", '\0')) && !channel->lookups)
1029 (void)config_lookup(channel, p, "dns", "files");
1049 if ((status == ARES_EOF) && (!channel->lookups)) {
1055 if ((p = try_config(line, "order", '\0')) && !channel->lookups)
1057 (void)config_lookup(channel, p, "bind", "hosts");
1077 if ((status == ARES_EOF) && (!channel->lookups)) {
1083 if ((p = try_config(line, "hosts=", '\0')) && !channel->lookups)
1085 (void)config_lookup(channel, p, "bind", "local");
1127 channel->servers = servers;
1128 channel->nservers = nservers;
1134 channel->sortlist = sortlist;
1135 channel->nsort = nsort;
1141 static int init_by_defaults(ares_channel channel)
1149 if (channel->flags == -1)
1150 channel->flags = 0;
1151 if (channel->timeout == -1)
1152 channel->timeout = DEFAULT_TIMEOUT;
1153 if (channel->tries == -1)
1154 channel->tries = DEFAULT_TRIES;
1155 if (channel->ndots == -1)
1156 channel->ndots = 1;
1157 if (channel->rotate == -1)
1158 channel->rotate = 0;
1159 if (channel->udp_port == -1)
1160 channel->udp_port = htons(NAMESERVER_PORT);
1161 if (channel->tcp_port == -1)
1162 channel->tcp_port = htons(NAMESERVER_PORT);
1164 if (channel->nservers == -1) {
1166 channel->servers = malloc(sizeof(struct server_state));
1167 if (!channel->servers) {
1171 channel->servers[0].addr.family = AF_INET;
1172 channel->servers[0].addr.addrV4.s_addr = htonl(INADDR_LOOPBACK);
1173 channel->nservers = 1;
1185 if (channel->ndomains == -1) {
1191 channel->ndomains = 0; /* default to none */
1224 channel->domains = malloc(sizeof(char *));
1225 if (!channel->domains) {
1229 channel->domains[0] = strdup(dot + 1);
1230 if (!channel->domains[0]) {
1234 channel->ndomains = 1;
1239 if (channel->nsort == -1) {
1240 channel->sortlist = NULL;
1241 channel->nsort = 0;
1244 if (!channel->lookups) {
1245 channel->lookups = strdup("fb");
1246 if (!channel->lookups)
1252 if(channel->servers)
1253 free(channel->servers);
1255 if(channel->domains && channel->domains[0])
1256 free(channel->domains[0]);
1257 if(channel->domains)
1258 free(channel->domains);
1259 if(channel->lookups)
1260 free(channel->lookups);
1270 static int config_domain(ares_channel channel, char *str)
1279 return set_search(channel, str);
1290 static int config_lookup(ares_channel channel, const char *str,
1314 channel->lookups = strdup(lookups);
1315 return (channel->lookups) ? ARES_SUCCESS : ARES_ENOMEM;
1466 static int set_search(ares_channel channel, const char *str)
1471 if(channel->ndomains != -1) {
1473 for(n=0; n < channel->ndomains; n++)
1474 free(channel->domains[n]);
1475 free(channel->domains);
1476 channel->domains = NULL;
1477 channel->ndomains = -1;
1494 channel->ndomains = 0;
1498 channel->domains = malloc(n * sizeof(char *));
1499 if (!channel->domains)
1507 channel->ndomains = n;
1511 channel->domains[n] = malloc(q - p + 1);
1512 if (!channel->domains[n])
1514 memcpy(channel->domains[n], p, q - p);
1515 channel->domains[n][q - p] = 0;
1521 channel->ndomains = n;
1526 static int set_options(ares_channel channel, const char *str)
1537 if (val && channel->ndots == -1)
1538 channel->ndots = aresx_sltosi(strtol(val, NULL, 10));
1540 if (val && channel->timeout == -1)
1541 channel->timeout = aresx_sltosi(strtol(val, NULL, 10));
1543 if (val && channel->tries == -1)
1544 channel->tries = aresx_sltosi(strtol(val, NULL, 10));
1546 if (val && channel->rotate == -1)
1547 channel->rotate = 1;
1755 void ares_set_local_ip4(ares_channel channel, unsigned int local_ip)
1757 channel->local_ip4 = local_ip;
1761 void ares_set_local_ip6(ares_channel channel,
1764 memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
1768 void ares_set_local_dev(ares_channel channel,
1771 strncpy(channel->local_dev_name, local_dev_name,
1772 sizeof(channel->local_dev_name));
1773 channel->local_dev_name[sizeof(channel->local_dev_name) - 1] = 0;
1777 void ares_set_socket_callback(ares_channel channel,
1781 channel->sock_create_cb = cb;
1782 channel->sock_create_cb_data = data;
1785 void ares__init_servers_state(ares_channel channel)
1790 for (i = 0; i < channel->nservers; i++)
1792 server = &channel->servers[i];
1795 server->tcp_connection_generation = ++channel->tcp_connection_generation;
1803 server->channel = channel;