chiark / gitweb /
_Submits_ but does not use the results from internally-generated queries.
[adns.git] / src / reply.c
index 87ee361f474622f215bd24ea371a21f76cca2a87..9d11607871b6acec51ae2ec6884c8d68a0170c3e 100644 (file)
@@ -32,13 +32,14 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   int flg_ra, flg_rd, flg_tc, flg_qr, opcode;
   int rrtype, rrclass, rdlength, rdstart;
   int anstart, nsstart, arstart;
-  int ownermatched, l, nrrs, place;
+  int ownermatched, l, nrrs;
   const typeinfo *typei;
   adns_query qu, nqu;
   dns_rcode rcode;
   adns_status st;
   vbuf tempvb;
   byte *newquery, *rrsdata;
+  parseinfo pai;
   
   if (dglen<DNS_HDRSIZE) {
     adns__diag(ads,serv,0,"received datagram too short for message header (%d)",dglen);
@@ -93,13 +94,13 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
     if (ads->iflags & adns_if_debug) {
       adns__vbuf_init(&tempvb);
       adns__debug(ads,serv,0,"reply not found, id %02x, query owner %s",
-                 id, adns__diag_domain(ads,serv,0,&tempvb,adns_qf_anyquote,
-                                       dgram,dglen,DNS_HDRSIZE));
+                 id, adns__diag_domain(ads,serv,0,&tempvb,dgram,dglen,DNS_HDRSIZE));
       adns__vbuf_free(&tempvb);
     }
     return;
   }
   anstart= qu->query_dglen;
+  arstart= -1;
 
   LIST_UNLINK(ads->timew,qu);
   /* We're definitely going to do something with this query now */
@@ -150,8 +151,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
     if (!ownermatched) {
       if (ads->iflags & adns_if_debug) {
        adns__debug(ads,serv,qu,"ignoring RR with an unexpected owner %s",
-                   adns__diag_domain(ads,serv,qu, &qu->vb,qu->flags,
-                                     dgram,dglen,rrstart));
+                   adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rrstart));
       }
       continue;
     }
@@ -160,7 +160,8 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
       if (!qu->cname_dgram) { /* Ignore second and subsequent CNAMEs */
        qu->cname_begin= rdstart;
        qu->cname_dglen= dglen;
-       st= adns__parse_domain(ads,serv,qu, &qu->vb,qu->flags,
+       st= adns__parse_domain(ads,serv,qu, &qu->vb,
+                              qu->flags & adns_qf_quoteok_cname ? pdf_quoteok : 0,
                               dgram,dglen, &rdstart,rdstart+rdlength);
        if (!qu->vb.used) goto x_truncated;
        if (st) { adns__query_fail(qu,st); return; }
@@ -180,8 +181,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,qu, &qu->vb,qu->flags,
-                                     dgram,dglen,rdstart),
+                   adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart),
                    qu->answer->cname);
       }
     } else if (rrtype == (qu->typei->type & adns__rrt_typemask)) {
@@ -258,18 +258,19 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
 
   typei= qu->typei;
   cbyte= anstart;
-  arstart= -1;
   rrsdata= qu->answer->rrs.bytes;
-  
-  if (typei->diff_needswap) {
-    if (!adns__vbuf_ensure(&qu->vb,typei->rrsz)) {
-      adns__query_fail(qu,adns_s_nolocalmem);
-      return;
-    }
-  }
-  nrrs= 0;
-  
-  for (rri=0; rri<ancount; rri++) {
+
+  pai.ads= qu->ads;
+  pai.qu= qu;
+  pai.serv= serv;
+  pai.dgram= dgram;
+  pai.dglen= dglen;
+  pai.nsstart= nsstart;
+  pai.nscount= nscount;
+  pai.arcount= arcount;
+  pai.now= now;
+
+  for (rri=0, nrrs=0; rri<ancount; rri++) {
     st= adns__findrr(qu,serv, dgram,dglen,&cbyte,
                     &rrtype,&rrclass,&rdlength,&rdstart,
                     &ownermatched);
@@ -278,24 +279,9 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
        rrtype != (qu->typei->type & adns__rrt_typemask) ||
        !ownermatched)
       continue;
-    st= typei->parse(qu,serv, dgram,dglen, rdstart,rdstart+rdlength,
-                    rrsdata+nrrs*typei->rrsz);
+    st= typei->parse(&pai, rdstart,rdstart+rdlength, rrsdata+nrrs*typei->rrsz);
     if (st) { adns__query_fail(qu,st); return; }
     if (rdstart==-1) goto x_truncated;
-
-    if (typei->diff_needswap) {
-      for (place= nrrs;
-          place>0 && typei->diff_needswap(rrsdata+(place-1)*typei->rrsz,
-                                          rrsdata+nrrs*typei->rrsz);
-          place--);
-      if (place != nrrs) {
-       memcpy(qu->vb.buf,rrsdata+nrrs*typei->rrsz,typei->rrsz);
-       memmove(rrsdata+(place+1)*typei->rrsz,
-               rrsdata+place*typei->rrsz,
-               (nrrs-place)*typei->rrsz);
-       memcpy(rrsdata+place*typei->rrsz,qu->vb.buf,typei->rrsz);
-      }
-    }
     nrrs++;
   }
   assert(nrrs==wantedrrs);