X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fquery.c;h=f710d3e7baa32095c27030a6f7bbe897b52d3ab3;hb=32af6b2a02aa7e71b367b71a048bd2459e368c25;hp=f24dbd144cd14486ec0d35f41fa55e960097cb9b;hpb=ea1e31e326a99219a0a6edf28a75845b79b74893;p=adns.git diff --git a/src/query.c b/src/query.c index f24dbd1..f710d3e 100644 --- a/src/query.c +++ b/src/query.c @@ -5,7 +5,7 @@ * - query submission and cancellation (user-visible and internal) */ /* - * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,6 +64,7 @@ int adns__internal_submit(adns_state ads, adns_query *query_r, qu->udpsent= qu->tcpfailed= 0; timerclear(&qu->timeout); memcpy(&qu->ctx,ctx,sizeof(qu->ctx)); + qu->expires= now.tv_sec + MAXTTLBELIEVE; qu->answer->status= adns_s_ok; qu->answer->cname= 0; @@ -112,7 +113,7 @@ int adns_submit(adns_state ads, adns_query *query_r) { qcontext ctx; int id, r, ol; - vbuf vb; + vbuf vb, search_vb; adns_status stat; const typeinfo *typei; struct timeval now; @@ -130,9 +131,9 @@ int adns_submit(adns_state ads, adns__vbuf_init(&vb); ol= strlen(owner); - if (ol<=1 || ol>DNS_MAXDOMAIN+1) { stat= adns_s_querydomaintoolong; goto xit; } + if (ol>DNS_MAXDOMAIN+1) { stat= adns_s_querydomaintoolong; goto xit; } - if (owner[ol-1]=='.' && owner[ol-2]!='\\') { flags &= ~adns_qf_search; ol--; } + if (ol>=2 && owner[ol-1]=='.' && owner[ol-2]!='\\') { flags &= ~adns_qf_search; ol--; } stat= adns__mkquery(ads,&vb,&id, owner,ol, typei,flags); @@ -192,6 +193,8 @@ void adns__transfer_interim(adns_query from, adns_query to, void *block, size_t from->interim_allocd -= sz; to->interim_allocd += sz; + + if (to->expires > from->expires) to->expires= from->expires; } void *adns__alloc_final(adns_query qu, size_t sz) { @@ -255,6 +258,15 @@ void adns_cancel(adns_query qu) { free(qu); } +void adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now) { + time_t max; + + assert(ttl <= MAXTTLBELIEVE); + max= now.tv_sec + ttl; + if (qu->expires < max) return; + qu->expires= max; +} + static void makefinal_query(adns_query qu) { adns_answer *ans; int rrn; @@ -276,7 +288,7 @@ static void makefinal_query(adns_query qu) { for (rrn=0; rrnnrrs; rrn++) qu->typei->makefinal(qu, ans->rrs.bytes + rrn*ans->rrsz); } - + free_query_allocs(qu); return; @@ -300,9 +312,12 @@ void adns__query_done(adns_query qu) { return; } adns__isort(ans->rrs.bytes, ans->nrrs, ans->rrsz, - qu->vb.buf, qu->typei->diff_needswap); + qu->vb.buf, + (int(*)(void*, const void*, const void*))qu->typei->diff_needswap, + qu->ads); } + ans->expires= qu->expires; parent= qu->parent; if (parent) { LIST_UNLINK_PART(parent->children,qu,siblings.);