X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/32af6b2a02aa7e71b367b71a048bd2459e368c25..38b74824d7fe58823b870a3f5f0fdd236217dacd:/src/setup.c diff --git a/src/setup.c b/src/setup.c index 26a5cff..23a01d1 100644 --- a/src/setup.c +++ b/src/setup.c @@ -24,10 +24,13 @@ #include #include #include +#include #include #include #include +#include +#include #include #include "internal.h" @@ -129,7 +132,6 @@ static void ccf_search(adns_state ads, const char *fn, int lno, const char *buf) free(ads->searchlist); ads->nsearchlist= count; ads->searchlist= newptrs; - /* fixme: actually pay attention */ } static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *buf) { @@ -153,7 +155,7 @@ static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *bu continue; } - memcpy(tbuf,word,l); + memcpy(tbuf,word,l); tbuf[l]= 0; slash= strchr(tbuf,'/'); if (slash) *slash++= 0; @@ -204,8 +206,29 @@ static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *bu } static void ccf_options(adns_state ads, const char *fn, int lno, const char *buf) { + const char *word; + char *ep; + unsigned long v; + int l; + if (!buf) return; - adns__diag(ads,-1,0,"warning - `options' ignored fixme"); + + while (nextword(&buf,&word,&l)) { + if (l==5 && !memcmp(word,"debug",5)) { + ads->iflags |= adns_if_debug; + continue; + } + if (l>=6 && !memcmp(word,"ndots:",6)) { + v= strtoul(word+6,&ep,10); + if (l==6 || ep != word+l || v > INT_MAX) { + configparseerr(ads,fn,lno,"option `%.*s' malformed or has bad value",l,word); + continue; + } + ads->searchndots= v; + continue; + } + adns__diag(ads,-1,0,"%s:%d: unknown option `%.*s'", fn,lno, l,word); + } } static void ccf_clearnss(adns_state ads, const char *fn, int lno, const char *buf) { @@ -418,17 +441,20 @@ static int init_begin(adns_state *ads_r, adns_initflags flags, FILE *diagfile) { ads->iflags= flags; ads->diagfile= diagfile; + ads->configerrno= 0; LIST_INIT(ads->timew); LIST_INIT(ads->childw); LIST_INIT(ads->output); + ads->forallnext= 0; ads->nextid= 0x311f; ads->udpsocket= ads->tcpsocket= -1; adns__vbuf_init(&ads->tcpsend); adns__vbuf_init(&ads->tcprecv); ads->nservers= ads->nsortlist= ads->nsearchlist= ads->tcpserver= 0; + ads->searchndots= 1; ads->tcpstate= server_disconnected; - ads->searchlist= 0; timerclear(&ads->tcptimeout); + ads->searchlist= 0; *ads_r= ads; return 0; @@ -541,3 +567,42 @@ void adns_finish(adns_state ads) { adns__vbuf_free(&ads->tcprecv); free(ads); } + +void adns_forallqueries_begin(adns_state ads) { + ads->forallnext= + ads->timew.head ? ads->timew.head : + ads->childw.head ? ads->childw.head : + ads->output.head; +} + +adns_query adns_forallqueries_next(adns_state ads, void **context_r) { + adns_query qu, nqu; + + nqu= ads->forallnext; + for (;;) { + qu= nqu; + if (!qu) return 0; + if (qu->next) { + nqu= qu->next; + } else if (qu == ads->timew.tail) { + if (ads->childw.head) { + nqu= ads->childw.head; + } else { + nqu= ads->output.head; + } + } else if (qu == ads->childw.tail) { + nqu= ads->output.head; + } else { + nqu= 0; + } + if (!qu->parent) break; + } + ads->forallnext= nqu; + if (context_r) *context_r= qu->ctx.ext; + return qu; +} + +void adns__checkqueues(adns_state ads) { + adns_forallqueries_begin(ads); + while (adns_forallqueries_next(ads,0)); +}