X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/adns/blobdiff_plain/7f702335acc642b53ec5f051403099e1d4512a4e..98db6da30a9aec13ba0840b0027b771cd6a7c4ce:/src/reply.c?ds=sidebyside diff --git a/src/reply.c b/src/reply.c index 0bcc3fa..337d3f8 100644 --- a/src/reply.c +++ b/src/reply.c @@ -1,4 +1,24 @@ -/**/ +/* + * reply.c + * - main handling and parsing routine for received datagrams + */ +/* + * This file is part of adns, which is Copyright (C) 1997, 1998 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include "internal.h" @@ -16,8 +36,6 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, adns_query qu, nqu; dns_rcode rcode; adns_status st; - vbuf vb; -#error init and free vb properly if (dgleniflags & adns_if_debug) { adns__debug(ads,serv,qu,"ignoring RR with an unexpected owner %s", - adns__diag_domain(ads,serv,&vb,qu->flags, + adns__diag_domain(ads,serv,&qu->vb,qu->flags, dgram,dglen,rrstart,dglen)); } continue; @@ -135,11 +153,12 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, qu->cname_begin= rdstart; qu->cname_dgram= dgram; qu->cname_dglen= dglen; - st= adns__parse_domain(ads,serv,&vb,qu->flags, + st= adns__parse_domain(ads,serv,&qu->vb,qu->flags, dgram,dglen, &rdstart,rdstart+rdlength); if (!vb.used) goto x_truncated; if (st) { adns__query_fail(ads,qu,st); return; } - qu->cname_str= adns__vbuf_extractstring(&vb); + qu->answer->cname= adns__savestring(qu); + if (!qu->answer->cname) return; /* If we find the answer section truncated after this point we restart * the query at the CNAME; if beforehand then we obviously have to use * TCP. If there is no truncation we can use the whole answer if @@ -147,7 +166,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, */ } else { adns__debug(ads,serv,qu,"ignoring duplicate CNAME (%s, as well as %s)", - adns__diag_domain(ads,serv,&vb,qu->flags, + adns__diag_domain(ads,serv,&qu->vb,qu->flags, dgram,dglen, rdstart,rdstart+rdlength), qu->cname_str); } @@ -217,15 +236,11 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, /* Now, we have some RRs which we wanted. */ - if (!adns__vbuf_ensure(&qu->ansbuf,qu->typei->rrsz*wantedrrs)) { - adns__query_fail(ads,qu,adns_s_nolocalmem); - return; - } + qu->ans->rrs= adns__alloc_interim(qu,qu->typei->rrsz*wantedrrs); + if (!qu->ans->rrs) return; cbyte= anstart; - currentrrs= 0; arstart= -1; - qu->ansbuf.used= 0; for (rri=0; rricname_dgram >= 0) { st= adns__findrr(ads,serv, dgram,dglen,&cbyte, @@ -241,11 +256,10 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, rrtype != (qu->typei->type & adns__rrt_typemask) || !ownermatched) continue; - assert(currentrrsansbuf.used += quj->typei->rrsz; - st= qu->typei->parse(ads,qu,serv,&vb, + assert(qu->ans->nrrstypei->parse(ads,qu,serv, dgram,dglen, &rdstart,rdstart+rdlength, - (void*)(qu->ansbuf.buf+qu->ansbuf.used)); + qu->ans->rrs.bytes+qu->ans->nrrs*quj->typei->rrsz); if (st) { adns__query_fail(ads,qu,st); return; } if (rdstart==-1) goto x_truncated; } @@ -260,16 +274,14 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, adns__query_finish(ads,qu,adns_s_ok); return; -x_truncated: + x_truncated: if (!flg_tc) { adns__diag(ads,serv,qu,"server sent datagram which points outside itself"); adns__query_fail(ads,qu,adns_s_serverfaulty); return; } if (qu->cname_dgram) { cname_recurse(ads,qu,adns_qf_usevc); return; } - ans= (adns_answer*)qu->ans.buf; - ans->nrrs= 0; - qu->ans.used= sizeof(adns_answer); + adns__reset_cnameonly(ads,qu); qu->flags |= adns_qf_usevc; adns__query_udp(ads,qu,now); }