2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00:00

Lots of duplicate code removed

+tcp mode bug fixed
This commit is contained in:
Michael Sawyer 2000-07-13 18:52:58 +00:00
parent 4250285838
commit c5ec9b45bb
3 changed files with 225 additions and 434 deletions

View File

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dig.c,v 1.62 2000/07/13 01:22:33 mws Exp $ */
/* $Id: dig.c,v 1.63 2000/07/13 18:52:55 mws Exp $ */
#include <config.h>
#include <stdlib.h>
@ -556,13 +556,13 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
isc_boolean_t have_host = ISC_FALSE;
dig_server_t *srv = NULL;
dig_lookup_t *lookup = NULL;
static dig_lookup_t *default_lookup = NULL;
char *batchname = NULL;
char batchline[MXNAME];
char address[MXNAME];
FILE *fp = NULL;
int bargc;
char *bargv[16];
char bargv0[sizeof("dig")];
int i, n;
int adrs[4];
int rc;
@ -575,8 +575,16 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
* otherwise make it apply to the latest host. This is
* a bit different than the previous versions, but should
* form a consistent user interface.
*
* First, create a "default lookup" which won't actually be used
* anywhere, except for cloning into new lookups
*/
if (!is_batchfile)
default_lookup = make_empty_lookup();
lookup = default_lookup;
rc = argc;
rv = argv;
for (rc--, rv++; rc > 0; rc--, rv++) {
@ -589,42 +597,26 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
if (srv == NULL)
fatal("Memory allocation failure");
strncpy(srv->servername, &rv[0][1], MXNAME-1);
if (is_batchfile && have_host) {
if (!lookup->use_my_server_list) {
ISC_LIST_INIT(lookup->
my_server_list);
lookup->use_my_server_list =
ISC_TRUE;
}
ISC_LIST_APPEND(lookup->my_server_list,
srv, link);
} else {
ISC_LIST_APPEND(server_list, srv, link);
if (!lookup->use_my_server_list) {
ISC_LIST_INIT(lookup->
my_server_list);
lookup->use_my_server_list =
ISC_TRUE;
}
ISC_LIST_APPEND(lookup->my_server_list,
srv, link);
} else if ((strcmp(rv[0], "+vc") == 0)
&& (!is_batchfile)) {
if (have_host)
lookup->tcp_mode = ISC_TRUE;
else
tcpmode = ISC_TRUE;
lookup->tcp_mode = ISC_TRUE;
} else if ((strcmp(rv[0], "+novc") == 0)
&& (!is_batchfile)) {
if (have_host)
lookup->tcp_mode = ISC_FALSE;
else
tcpmode = ISC_FALSE;
lookup->tcp_mode = ISC_FALSE;
} else if ((strcmp(rv[0], "+tcp") == 0)
&& (!is_batchfile)) {
if (have_host)
lookup->tcp_mode = ISC_TRUE;
else
tcpmode = ISC_TRUE;
lookup->tcp_mode = ISC_TRUE;
} else if ((strcmp(rv[0], "+notcp") == 0)
&& (!is_batchfile)) {
if (have_host)
lookup->tcp_mode = ISC_FALSE;
else
tcpmode = ISC_FALSE;
lookup->tcp_mode = ISC_FALSE;
} else if (strncmp(rv[0], "+domain=", 8) == 0) {
/* Global option always */
strncpy(fixeddomain, &rv[0][8], MXNAME);
@ -634,15 +626,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
} else if (strncmp(rv[0], "+nosea", 6) == 0) {
usesearch = ISC_FALSE;
} else if (strncmp(rv[0], "+defn", 5) == 0) {
if (have_host)
lookup->defname = ISC_TRUE;
else
defname = ISC_TRUE;
lookup->defname = ISC_TRUE;
} else if (strncmp(rv[0], "+nodefn", 7) == 0) {
if (have_host)
lookup->defname = ISC_FALSE;
else
defname = ISC_FALSE;
lookup->defname = ISC_FALSE;
} else if (strncmp(rv[0], "+time=", 6) == 0) {
/* Global option always */
timeout = atoi(&rv[0][6]);
@ -656,150 +642,71 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
timeout = 1;
debug("timeout set to %d", timeout);
} else if (strncmp(rv[0], "+tries=", 7) == 0) {
if (have_host) {
lookup->retries = atoi(&rv[0][7]);
if (lookup->retries <= 0)
lookup->retries = 1;
} else {
tries = atoi(&rv[0][7]);
if (tries <= 0)
tries = 1;
}
lookup->retries = atoi(&rv[0][7]);
if (lookup->retries <= 0)
lookup->retries = 1;
} else if (strncmp(rv[0], "+buf=", 5) == 0) {
if (have_host) {
lookup->udpsize = atoi(&rv[0][5]);
if (lookup->udpsize <= 0)
lookup->udpsize = 0;
if (lookup->udpsize > COMMSIZE)
lookup->udpsize = COMMSIZE;
} else {
bufsize = atoi(&rv[0][5]);
if (bufsize <= 0)
bufsize = 0;
if (bufsize > COMMSIZE)
bufsize = COMMSIZE;
}
lookup->udpsize = atoi(&rv[0][5]);
if (lookup->udpsize <= 0)
lookup->udpsize = 0;
if (lookup->udpsize > COMMSIZE)
lookup->udpsize = COMMSIZE;
} else if (strncmp(rv[0], "+bufsize=", 9) == 0) {
if (have_host) {
lookup->udpsize = atoi(&rv[0][9]);
if (lookup->udpsize <= 0)
lookup->udpsize = 0;
if (lookup->udpsize > COMMSIZE)
lookup->udpsize = COMMSIZE;
} else {
bufsize = atoi(&rv[0][9]);
if (bufsize <= 0)
bufsize = 0;
if (bufsize > COMMSIZE)
bufsize = COMMSIZE;
}
lookup->udpsize = atoi(&rv[0][9]);
if (lookup->udpsize <= 0)
lookup->udpsize = 0;
if (lookup->udpsize > COMMSIZE)
lookup->udpsize = COMMSIZE;
} else if (strncmp(rv[0], "+ndots=", 7) == 0) {
/* Global option always */
ndots = atoi(&rv[0][7]);
if (ndots < 0)
ndots = 0;
} else if (strncmp(rv[0], "+rec", 4) == 0) {
if (have_host)
lookup->recurse = ISC_TRUE;
else
recurse = ISC_TRUE;
lookup->recurse = ISC_TRUE;
} else if (strncmp(rv[0], "+norec", 6) == 0) {
if (have_host)
lookup->recurse = ISC_FALSE;
else
recurse = ISC_FALSE;
lookup->recurse = ISC_FALSE;
} else if (strncmp(rv[0], "+aa", 3) == 0) {
if (have_host)
lookup->aaonly = ISC_TRUE;
else
aaonly = ISC_TRUE;
lookup->aaonly = ISC_TRUE;
} else if (strncmp(rv[0], "+noaa", 5) == 0) {
if (have_host)
lookup->aaonly = ISC_FALSE;
else
aaonly = ISC_FALSE;
lookup->aaonly = ISC_FALSE;
} else if (strncmp(rv[0], "+adf", 4) == 0) {
if (have_host)
lookup->adflag = ISC_TRUE;
else
adflag = ISC_TRUE;
lookup->adflag = ISC_TRUE;
} else if (strncmp(rv[0], "+noadf", 6) == 0) {
if (have_host)
lookup->adflag = ISC_FALSE;
else
adflag = ISC_FALSE;
lookup->adflag = ISC_FALSE;
} else if (strncmp(rv[0], "+cd", 3) == 0) {
if (have_host)
lookup->cdflag = ISC_TRUE;
else
cdflag = ISC_TRUE;
lookup->cdflag = ISC_TRUE;
} else if (strncmp(rv[0], "+nocd", 5) == 0) {
if (have_host)
lookup->cdflag = ISC_FALSE;
else
cdflag = ISC_FALSE;
lookup->cdflag = ISC_FALSE;
} else if (strncmp(rv[0], "+ns", 3) == 0) {
if (have_host) {
lookup->ns_search_only = ISC_TRUE;
lookup->trace_root = ISC_TRUE;
lookup->recurse = ISC_FALSE;
lookup->identify = ISC_TRUE;
lookup->stats = ISC_FALSE;
if (!forcecomment)
lookup->comments = ISC_FALSE;
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_FALSE;
lookup->section_question = ISC_FALSE;
} else {
ns_search_only = ISC_TRUE;
recurse = ISC_FALSE;
identify = ISC_TRUE;
stats = ISC_FALSE;
if (!forcecomment)
comments = ISC_FALSE;
section_additional = ISC_FALSE;
section_authority = ISC_FALSE;
section_question = ISC_FALSE;
}
lookup->ns_search_only = ISC_TRUE;
lookup->trace_root = ISC_TRUE;
lookup->recurse = ISC_FALSE;
lookup->identify = ISC_TRUE;
lookup->stats = ISC_FALSE;
if (!forcecomment)
lookup->comments = ISC_FALSE;
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_FALSE;
lookup->section_question = ISC_FALSE;
} else if (strncmp(rv[0], "+nons", 6) == 0) {
if (have_host)
lookup->ns_search_only = ISC_FALSE;
else
ns_search_only = ISC_FALSE;
lookup->ns_search_only = ISC_FALSE;
} else if (strncmp(rv[0], "+tr", 3) == 0) {
if (have_host) {
lookup->trace = ISC_TRUE;
lookup->trace_root = ISC_TRUE;
lookup->recurse = ISC_FALSE;
lookup->identify = ISC_TRUE;
if (!forcecomment) {
lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE;
}
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_TRUE;
lookup->section_question = ISC_FALSE;
show_details = ISC_TRUE;
} else {
trace = ISC_TRUE;
recurse = ISC_FALSE;
identify = ISC_TRUE;
if (!forcecomment) {
comments = ISC_FALSE;
stats = ISC_FALSE;
}
section_additional = ISC_FALSE;
section_authority = ISC_TRUE;
section_question = ISC_FALSE;
show_details = ISC_TRUE;
lookup->trace = ISC_TRUE;
lookup->trace_root = ISC_TRUE;
lookup->recurse = ISC_FALSE;
lookup->identify = ISC_TRUE;
if (!forcecomment) {
lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE;
}
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_TRUE;
lookup->section_question = ISC_FALSE;
show_details = ISC_TRUE;
} else if (strncmp(rv[0], "+notr", 6) == 0) {
if (have_host) {
lookup->trace = ISC_FALSE;
lookup->trace_root = ISC_FALSE;
}
else
trace = ISC_FALSE;
lookup->trace = ISC_FALSE;
lookup->trace_root = ISC_FALSE;
} else if (strncmp(rv[0], "+det", 4) == 0) {
show_details = ISC_TRUE;
} else if (strncmp(rv[0], "+nodet", 6) == 0) {
@ -811,156 +718,81 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
} else if (strncmp(rv[0], "+sho", 4) == 0) {
short_form = ISC_TRUE;
printcmd = ISC_FALSE;
if (have_host) {
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_FALSE;
lookup->section_question = ISC_FALSE;
if (!forcecomment) {
lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE;
}
} else {
section_additional = ISC_FALSE;
section_authority = ISC_FALSE;
section_question = ISC_FALSE;
if (!forcecomment) {
comments = ISC_FALSE;
stats = ISC_FALSE;
}
lookup->section_additional = ISC_FALSE;
lookup->section_authority = ISC_FALSE;
lookup->section_question = ISC_FALSE;
if (!forcecomment) {
lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE;
}
} else if (strncmp(rv[0], "+nosho", 6) == 0) {
short_form = ISC_FALSE;
} else if (strncmp(rv[0], "+id", 3) == 0) {
if (have_host)
lookup->identify = ISC_TRUE;
else
identify = ISC_TRUE;
lookup->identify = ISC_TRUE;
} else if (strncmp(rv[0], "+noid", 5) == 0) {
if (have_host)
lookup->identify = ISC_FALSE;
else
identify = ISC_FALSE;
lookup->identify = ISC_FALSE;
} else if (strncmp(rv[0], "+com", 4) == 0) {
if (have_host)
lookup->comments = ISC_TRUE;
else
comments = ISC_TRUE;
lookup->comments = ISC_TRUE;
forcecomment = ISC_TRUE;
} else if (strncmp(rv[0], "+nocom", 6) == 0) {
if (have_host) {
lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE;
} else {
comments = ISC_FALSE;
stats = ISC_FALSE;
}
lookup->comments = ISC_FALSE;
lookup->stats = ISC_FALSE;
forcecomment = ISC_FALSE;
} else if (strncmp(rv[0], "+sta", 4) == 0) {
if (have_host)
lookup->stats = ISC_TRUE;
else
stats = ISC_TRUE;
lookup->stats = ISC_TRUE;
} else if (strncmp(rv[0], "+nosta", 6) == 0) {
if (have_host)
lookup->stats = ISC_FALSE;
else
stats = ISC_FALSE;
lookup->stats = ISC_FALSE;
} else if (strncmp(rv[0], "+qr", 3) == 0) {
qr = ISC_TRUE;
} else if (strncmp(rv[0], "+noqr", 5) == 0) {
qr = ISC_FALSE;
} else if (strncmp(rv[0], "+que", 4) == 0) {
if (have_host)
lookup->section_question = ISC_TRUE;
else
section_question = ISC_TRUE;
lookup->section_question = ISC_TRUE;
} else if (strncmp(rv[0], "+noque", 6) == 0) {
if (have_host)
lookup->section_question = ISC_FALSE;
else
section_question = ISC_FALSE;
lookup->section_question = ISC_FALSE;
} else if (strncmp(rv[0], "+ans", 4) == 0) {
if (have_host)
lookup->section_answer = ISC_TRUE;
else
section_answer = ISC_TRUE;
lookup->section_answer = ISC_TRUE;
} else if (strncmp(rv[0], "+noans", 6) == 0) {
if (have_host)
lookup->section_answer = ISC_FALSE;
else
section_answer = ISC_FALSE;
lookup->section_answer = ISC_FALSE;
} else if (strncmp(rv[0], "+add", 4) == 0) {
if (have_host)
lookup->section_additional = ISC_TRUE;
else
section_additional = ISC_TRUE;
lookup->section_additional = ISC_TRUE;
} else if (strncmp(rv[0], "+noadd", 6) == 0) {
if (have_host)
lookup->section_additional = ISC_FALSE;
else
section_additional = ISC_FALSE;
lookup->section_additional = ISC_FALSE;
} else if (strncmp(rv[0], "+aut", 4) == 0) {
if (have_host)
lookup->section_authority = ISC_TRUE;
else
section_authority = ISC_TRUE;
lookup->section_authority = ISC_TRUE;
} else if (strncmp(rv[0], "+noaut", 6) == 0) {
if (have_host)
lookup->section_authority = ISC_FALSE;
else
section_authority = ISC_FALSE;
} else if (strncmp(rv[0], "+all", 4) == 0) {
if (have_host) {
lookup->section_question = ISC_TRUE;
lookup->section_authority = ISC_TRUE;
lookup->section_answer = ISC_TRUE;
lookup->section_additional = ISC_TRUE;
lookup->comments = ISC_TRUE;
} else {
section_question = ISC_TRUE;
section_authority = ISC_TRUE;
section_answer = ISC_TRUE;
section_additional = ISC_TRUE;
comments = ISC_TRUE;
}
lookup->section_question = ISC_TRUE;
lookup->section_authority = ISC_TRUE;
lookup->section_answer = ISC_TRUE;
lookup->section_additional = ISC_TRUE;
lookup->comments = ISC_TRUE;
} else if (strncmp(rv[0], "+noall", 6) == 0) {
if (have_host) {
lookup->section_question = ISC_FALSE;
lookup->section_authority = ISC_FALSE;
lookup->section_answer = ISC_FALSE;
lookup->section_additional = ISC_FALSE;
lookup->comments = ISC_FALSE;
} else {
section_question = ISC_FALSE;
section_authority = ISC_FALSE;
section_answer = ISC_FALSE;
section_additional = ISC_FALSE;
comments = ISC_FALSE;
}
lookup->section_question = ISC_FALSE;
lookup->section_authority = ISC_FALSE;
lookup->section_answer = ISC_FALSE;
lookup->section_additional = ISC_FALSE;
lookup->comments = ISC_FALSE;
} else if (strncmp(rv[0], "-c", 2) == 0) {
if (have_host) {
if (rv[0][2] != 0) {
strncpy(lookup->rctext, &rv[0][2],
MXRD);
} else {
strncpy(lookup->rctext, rv[1],
MXRD);
rv++;
rc--;
}
if (rv[0][2] != 0) {
strncpy(lookup->rctext, &rv[0][2],
MXRD);
} else {
strncpy(lookup->rctext, rv[1],
MXRD);
rv++;
rc--;
}
} else if (strncmp(rv[0], "-t", 2) == 0) {
if (have_host) {
if (rv[0][2] != 0) {
strncpy(lookup->rttext, &rv[0][2],
MXRD);
} else {
strncpy(lookup->rttext, rv[1],
MXRD);
rv++;
rc--;
}
if (rv[0][2] != 0) {
strncpy(lookup->rttext, &rv[0][2],
MXRD);
} else {
strncpy(lookup->rttext, rv[1],
MXRD);
rv++;
rc--;
}
} else if (strncmp(rv[0], "-f", 2) == 0) {
if (rv[0][2] != 0) {
@ -1031,12 +863,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
&adrs[2], &adrs[3]);
if (n == 0)
show_usage();
lookup = isc_mem_allocate(mctx,
sizeof(struct dig_lookup));
if (lookup == NULL)
fatal("Memory allocation failure");
lookup->pending = ISC_FALSE;
lookup->textname[0] = 0;
lookup = clone_lookup(default_lookup, ISC_TRUE);
for (i = n - 1; i >= 0; i--) {
snprintf(batchline, MXNAME/8, "%d.",
adrs[i]);
@ -1044,50 +873,25 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
}
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
debug("looking up %s", lookup->textname);
lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only);
strcpy(lookup->rttext, "ptr");
strcpy(lookup->rctext, "in");
lookup->namespace[0] = 0;
lookup->sendspace = NULL;
lookup->sendmsg = NULL;
lookup->name = NULL;
lookup->oname = NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->querysig = NULL;
lookup->use_my_server_list = ISC_FALSE;
lookup->trace = trace;
lookup->trace_root = ISC_TF(trace || ns_search_only);
lookup->ns_search_only = ns_search_only;
lookup->doing_xfr = ISC_FALSE;
lookup->ixfr_serial = 0;
lookup->defname = ISC_FALSE;
lookup->identify = identify;
lookup->recurse = recurse;
lookup->aaonly = aaonly;
lookup->adflag = adflag;
lookup->cdflag = cdflag;
lookup->retries = tries;
lookup->udpsize = bufsize;
lookup->nsfound = 0;
lookup->comments = comments;
lookup->tcp_mode = tcpmode;
lookup->stats = stats;
lookup->section_question = section_question;
lookup->section_answer = section_answer;
lookup->section_authority = section_authority;
lookup->section_additional = section_additional;
lookup->new_search = ISC_TRUE;
ISC_LIST_INIT(lookup->q);
lookup->origin = NULL;
ISC_LIST_INIT(lookup->my_server_list);
ISC_LIST_APPEND(lookup_list, lookup, link);
have_host = ISC_TRUE;
rv++;
rc--;
} else {
/*
* If we decide to allow query type and class
* to be specified (without -t and -c options)
* before a host is given, all that needs to
* happen is the have_host test here get removed.
* Nothing should break by doing this.
*/
if (have_host) {
ENSURE(lookup != NULL);
if (strncmp(rv[0], "ixfr=", 5) == 0) {
strcpy(lookup->rttext, "ixfr");
lookup->ixfr_serial =
@ -1103,49 +907,12 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
continue;
}
}
lookup = isc_mem_allocate(mctx,
sizeof(struct dig_lookup));
if (lookup == NULL)
fatal("Memory allocation failure");
lookup->pending = ISC_FALSE;
lookup=clone_lookup(default_lookup, ISC_TRUE);
strncpy(lookup->textname, rv[0], MXNAME-1);
lookup->rttext[0] = 0;
lookup->rctext[0] = 0;
lookup->namespace[0] = 0;
lookup->sendspace = NULL;
lookup->sendmsg = NULL;
lookup->name = NULL;
lookup->oname = NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->querysig = NULL;
lookup->use_my_server_list = ISC_FALSE;
lookup->doing_xfr = ISC_FALSE;
lookup->ixfr_serial = 0;
lookup->defname = ISC_FALSE;
lookup->trace_root = ISC_TF(trace || ns_search_only);
lookup->trace = trace;
lookup->ns_search_only = ns_search_only;
lookup->identify = identify;
lookup->recurse = recurse;
lookup->aaonly = aaonly;
lookup->adflag = adflag;
lookup->cdflag = cdflag;
lookup->retries = tries;
lookup->udpsize = bufsize;
lookup->nsfound = 0;
lookup->comments = comments;
lookup->tcp_mode = tcpmode;
lookup->stats = stats;
lookup->section_question = section_question;
lookup->section_answer = section_answer;
lookup->section_authority = section_authority;
lookup->section_additional = section_additional;
lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only);
lookup->new_search = ISC_TRUE;
ISC_LIST_INIT(lookup->q);
ISC_LIST_APPEND(lookup_list, lookup, link);
lookup->origin = NULL;
ISC_LIST_INIT(lookup->my_server_list);
have_host = ISC_TRUE;
debug("looking up %s", lookup->textname);
@ -1168,63 +935,19 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
bargv[bargc] = strtok(NULL, " \t\r\n");
}
/*
* This silliness (instead of ``bargv[0] = "dig";'')
* dances around the const string issue. If in
* the future the 2nd argument to strncpy() is made
* longer than three characters, don't forget to resize
* bargv0 to accommodate it.
*/
strncpy(bargv0, "dig", sizeof(bargv0));
bargv[0] = bargv0;
bargv[0] = argv[0];
reorder_args(bargc, (char **)bargv);
parse_args(ISC_TRUE, bargc, (char **)bargv);
}
}
if (lookup_list.head == NULL) {
lookup = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
if (lookup == NULL)
fatal("Memory allocation failure");
lookup->pending = ISC_FALSE;
lookup->rctext[0] = 0;
lookup->namespace[0] = 0;
lookup->sendspace = NULL;
lookup->sendmsg = NULL;
lookup->name = NULL;
lookup->oname = NULL;
lookup->timer = NULL;
lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->querysig = NULL;
lookup->use_my_server_list = ISC_FALSE;
lookup->doing_xfr = ISC_FALSE;
lookup->ixfr_serial = 0;
lookup->defname = ISC_FALSE;
lookup->trace_root = ISC_TF(trace || ns_search_only);
lookup->trace = trace;
lookup->ns_search_only = ns_search_only;
lookup->identify = identify;
lookup->recurse = recurse;
lookup->aaonly = aaonly;
lookup->adflag = adflag;
lookup->cdflag = cdflag;
lookup->retries = tries;
lookup->udpsize = bufsize;
lookup->nsfound = 0;
lookup->comments = comments;
lookup->tcp_mode = tcpmode;
lookup->stats = stats;
lookup->section_question = section_question;
lookup->section_answer = section_answer;
lookup->section_authority = section_authority;
lookup->section_additional = section_additional;
lookup=clone_lookup(default_lookup, ISC_TRUE);
lookup->trace_root = ISC_TF(lookup->trace ||
lookup->ns_search_only);
lookup->new_search = ISC_TRUE;
ISC_LIST_INIT(lookup->q);
ISC_LIST_INIT(lookup->my_server_list);
strcpy(lookup->textname, ".");
strcpy(lookup->rttext, "NS");
lookup->rctext[0] = 0;
ISC_LIST_APPEND(lookup_list, lookup, link);
}
if (!is_batchfile)

View File

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dighost.c,v 1.81 2000/07/13 02:14:17 mws Exp $ */
/* $Id: dighost.c,v 1.82 2000/07/13 18:52:57 mws Exp $ */
/*
* Notice to programmers: Do not use this code as an example of how to
@ -231,32 +231,71 @@ istype(char *text) {
}
dig_lookup_t *
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
make_empty_lookup(void) {
dig_lookup_t *looknew;
dig_server_t *s, *srv;
debug("requeue_lookup()");
debug("make_lookup()");
INSIST(!free_now);
lookup_counter++;
if (lookup_counter > LOOKUP_LIMIT)
fatal("Too many lookups");
looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup));
if (looknew == NULL)
fatal("Memory allocation failure in %s:%d",
__FILE__, __LINE__);
looknew->pending = ISC_FALSE;
strncpy(looknew->textname, lookold-> textname, MXNAME);
strncpy(looknew->rttext, lookold-> rttext, 32);
strncpy(looknew->rctext, lookold-> rctext, 32);
looknew->namespace[0] = 0;
looknew->pending = ISC_TRUE;
looknew->textname[0]=0;
looknew->rttext[0]=0;
looknew->rctext[0]=0;
looknew->sendspace = NULL;
looknew->sendmsg = NULL;
looknew->name = NULL;
looknew->oname = NULL;
looknew->timer = NULL;
looknew->xfr_q = NULL;
looknew->doing_xfr = ISC_FALSE;
looknew->ixfr_serial = ISC_FALSE;
looknew->defname = ISC_FALSE;
looknew->trace = ISC_FALSE;
looknew->trace_root = ISC_FALSE;
looknew->identify = ISC_FALSE;
looknew->udpsize = 0;
looknew->recurse = ISC_TRUE;
looknew->aaonly = ISC_FALSE;
looknew->adflag = ISC_FALSE;
looknew->cdflag = ISC_FALSE;
looknew->ns_search_only = ISC_FALSE;
looknew->origin = NULL;
looknew->querysig = NULL;
looknew->retries = tries;
looknew->nsfound = 0;
looknew->tcp_mode = ISC_FALSE;
looknew->comments = ISC_TRUE;
looknew->stats = ISC_TRUE;
looknew->section_question = ISC_TRUE;
looknew->section_answer = ISC_TRUE;
looknew->section_authority = ISC_TRUE;
looknew->section_additional = ISC_TRUE;
looknew->new_search = ISC_FALSE;
ISC_LIST_INIT(looknew->my_server_list);
ISC_LIST_INIT(looknew->q);
looknew->use_my_server_list = ISC_FALSE;
return (looknew);
}
dig_lookup_t *
clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
dig_lookup_t *looknew;
dig_server_t *s, *srv;
debug("clone_lookup()");
INSIST(!free_now);
looknew = make_empty_lookup();
INSIST(looknew != NULL);
strncpy(looknew->textname, lookold-> textname, MXNAME);
strncpy(looknew->rttext, lookold-> rttext, 32);
strncpy(looknew->rctext, lookold-> rctext, 32);
looknew->doing_xfr = lookold->doing_xfr;
looknew->ixfr_serial = lookold->ixfr_serial;
looknew->defname = lookold->defname;
@ -269,10 +308,6 @@ requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
looknew->adflag = lookold->adflag;
looknew->cdflag = lookold->cdflag;
looknew->ns_search_only = lookold->ns_search_only;
looknew->origin = NULL;
looknew->querysig = NULL;
looknew->retries = tries;
looknew->nsfound = 0;
looknew->tcp_mode = lookold->tcp_mode;
looknew->comments = lookold->comments;
looknew->stats = lookold->stats;
@ -280,11 +315,7 @@ requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
looknew->section_answer = lookold->section_answer;
looknew->section_authority = lookold->section_authority;
looknew->section_additional = lookold->section_additional;
looknew->new_search = ISC_FALSE;
ISC_LIST_INIT(looknew->my_server_list);
ISC_LIST_INIT(looknew->q);
looknew->use_my_server_list = ISC_FALSE;
if (servers) {
looknew->use_my_server_list = lookold->use_my_server_list;
if (looknew->use_my_server_list) {
@ -303,6 +334,22 @@ requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
}
}
}
return (looknew);
}
dig_lookup_t *
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) {
dig_lookup_t *looknew;
debug("requeue_lookup()");
lookup_counter++;
if (lookup_counter > LOOKUP_LIMIT)
fatal("Too many lookups");
looknew = clone_lookup(lookold, servers);
INSIST(looknew != NULL);
debug("before insertion, init@%p "
"-> %p, new@%p -> %p",
lookold, lookold->link.next, looknew, looknew->link.next);
@ -629,6 +676,9 @@ add_question(dns_message_t *message, dns_name_t *name,
static void
check_if_done(void) {
debug("check_if_done()");
debug("sockcount=%d, recvcount=%d, sendcount=%d, list %s",
sockcount, recvcount, sendcount,
ISC_LIST_EMPTY(lookup_list)?"empty":"full");
if ((sockcount == 0) && (recvcount == 0) && (sendcount == 0)
&& ISC_LIST_EMPTY(lookup_list)) {
debug("shutting down");
@ -646,6 +696,8 @@ clear_query(dig_query_t *query) {
REQUIRE(query != NULL);
debug("clear_query(%p)",query);
lookup = query->lookup;
ISC_LIST_UNLINK(lookup->q, query, link);
if (ISC_LINK_LINKED(&query->recvbuf, link))
@ -668,8 +720,12 @@ try_clear_lookup(dig_lookup_t *lookup) {
REQUIRE(lookup != NULL);
if (ISC_LIST_HEAD(lookup->q) != NULL)
debug("try_clear_lookup(%p)", lookup);
if (ISC_LIST_HEAD(lookup->q) != NULL) {
debug("can't clear; query still pending.");
return (ISC_FALSE);
}
/*
* At this point, we know there are no queries on the lookup,
* so can make it go away also.
@ -1363,6 +1419,7 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) {
isc_region_t r;
isc_result_t result;
dig_query_t *query=NULL;
dig_lookup_t *l;
isc_uint16_t length;
REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE);
@ -1376,10 +1433,15 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) {
query = event->ev_arg;
recvcount--;
INSIST(recvcount >= 0);
if (sevent->result == ISC_R_CANCELED) {
query->working = ISC_FALSE;
isc_event_free(&event);
check_next_lookup(query->lookup);
l = query->lookup;
clear_query(query);
check_next_lookup(l);
return;
}
if (sevent->result != ISC_R_SUCCESS) {

View File

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dig.h,v 1.31 2000/07/13 01:22:38 mws Exp $ */
/* $Id: dig.h,v 1.32 2000/07/13 18:52:58 mws Exp $ */
#ifndef DIG_H
#define DIG_H
@ -209,6 +209,12 @@ free_lists(void);
dig_lookup_t *
requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
dig_lookup_t *
make_empty_lookup(void);
dig_lookup_t *
clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers);
/*
* Routines needed in dig.c and host.c.