chiark / gitweb /
update copyright dates
[adns.git] / src / types.c
index d39e341e11a06a067ff76e6fc0f8e5b7df384e88..b369322d778c071594d972d8706d905a1c2641d9 100644 (file)
@@ -3,12 +3,11 @@
  * - RR-type-specific code, and the machinery to call it
  */
 /*
- *  This file is
- *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
- *
- *  It is part of adns, which is
- *    Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>
- *    Copyright (C) 1999-2000 Tony Finch <dot@dotat.at>
+ *  This file is part of adns, which is
+ *    Copyright (C) 1997-2000,2003,2006  Ian Jackson
+ *    Copyright (C) 1999-2000,2003,2006  Tony Finch
+ *    Copyright (C) 1991 Massachusetts Institute of Technology
+ *  (See the file INSTALL for full details.)
  *  
  *  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 +63,8 @@
  * _rp                        (pa)
  * _soa                       (pa,mf,cs)
  * _srv*                      (qdpl,(pap),pa,mf,di,(csp),cs,postsort)
+ * _byteblock                 (mf)
+ * _opaque                    (pa,cs)
  * _flat                      (mf)
  *
  * within each section:
@@ -908,7 +909,7 @@ static adns_status pap_mailbox822(const parseinfo *pai,
 
 static adns_status pap_mailbox(const parseinfo *pai, int *cbyte_io, int max,
                               char **mb_r) {
-  if (pai->qu->typei->type & adns__qtf_mail822) {
+  if (pai->qu->typei->typekey & adns__qtf_mail822) {
     return pap_mailbox822(pai, cbyte_io, max, mb_r);
   } else {
     return pap_domain(pai, cbyte_io, max, mb_r, pdf_quoteok);
@@ -1143,8 +1144,6 @@ static void postsort_srv(adns_state ads, void *array, int nrrs,
         workend < arrayend && (rr=(void*)workend)->priority == cpriority;
         workend += typei->rrsz) {
       totalweight += rr->weight;
-fprintf(stderr,"(postsort_srv priority %d weight %d)\n",
-       cpriority, rr->weight);
     }
 
     /* Now workbegin..(workend-1) incl. are exactly all of the RRs of
@@ -1159,12 +1158,6 @@ fprintf(stderr,"(postsort_srv priority %d weight %d)\n",
       
       randval= nrand48(ads->rand48xsubi);
       randval %= (totalweight + 1);
-fprintf(stderr,"(postsort_srv totalweight %d randval %ld  %ld..%ld<%ld)\n",
-       totalweight,randval,
-       (unsigned long)(workbegin - (char*)array) / typei->rrsz,
-       (unsigned long)(workend - (char*)array) / typei->rrsz,
-       (unsigned long)(arrayend - (char*)array) / typei->rrsz
-       );
         /* makes it into 0..totalweight inclusive; with 2^10 RRs,
         * totalweight must be <= 2^26 so probability nonuniformity is
         * no worse than 1 in 2^(31-26) ie 1 in 2^5, ie
@@ -1174,10 +1167,6 @@ fprintf(stderr,"(postsort_srv totalweight %d randval %ld  %ld..%ld<%ld)\n",
       for (search=workbegin, runtotal=0;
           (runtotal += (rr=(void*)search)->weight) < randval;
           search += typei->rrsz);
-fprintf(stderr,"(postsort_srv search %ld runtotal %d)\n",
-       (unsigned long)(search - (char*)array) / typei->rrsz,
-       runtotal
-       );
       assert(search < arrayend);
       totalweight -= rr->weight;
       if (search != workbegin) {
@@ -1194,6 +1183,56 @@ fprintf(stderr,"(postsort_srv search %ld runtotal %d)\n",
    */
 }
 
+/*
+ * _byteblock   (mf)
+ */
+
+static void mf_byteblock(adns_query qu, void *datap) {
+  adns_rr_byteblock *rrp= datap;
+  void *bytes= rrp->data;
+  adns__makefinal_block(qu,&bytes,rrp->len);
+  rrp->data= bytes;
+}
+
+/*
+ * _opaque   (pa,cs)
+ */
+
+static adns_status pa_opaque(const parseinfo *pai, int cbyte,
+                            int max, void *datap) {
+  adns_rr_byteblock *rrp= datap;
+
+  rrp->len= max - cbyte;
+  rrp->data= adns__alloc_interim(pai->qu, rrp->len);
+  if (!rrp->data) R_NOMEM;
+  memcpy(rrp->data, pai->dgram + cbyte, rrp->len);
+  return adns_s_ok;
+}
+
+static adns_status cs_opaque(vbuf *vb, const void *datap) {
+  const adns_rr_byteblock *rrp= datap;
+  char buf[10];
+  int l;
+  unsigned char *p;
+
+  sprintf(buf,"\\# %d",rrp->len);
+  CSP_ADDSTR(buf);
+  
+  for (l= rrp->len, p= rrp->data;
+       l>=4;
+       l -= 4, p += 4) {
+    sprintf(buf," %02x%02x%02x%02x",p[0],p[1],p[2],p[3]);
+    CSP_ADDSTR(buf);
+  }
+  for (;
+       l>0;
+       l--, p++) {
+    sprintf(buf," %02x",*p);
+    CSP_ADDSTR(buf);
+  }
+  return adns_s_ok;
+}
+  
 /*
  * _flat   (mf)
  */
@@ -1246,15 +1285,20 @@ DEEP_TYPE(soa,    "SOA","822",  soa,     pa_soa,     0,        cs_soa        ),
 DEEP_TYPE(rp,     "RP", "822",  strpair, pa_rp,      0,        cs_rp         ),
 };
 
+static const typeinfo typeinfo_unknown=
+DEEP_TYPE(unknown,0, "unknown",byteblock,pa_opaque,  0,        cs_opaque     );
+
 const typeinfo *adns__findtype(adns_rrtype type) {
   const typeinfo *begin, *end, *mid;
 
+  if (type & adns_r_unknown) return &typeinfo_unknown;
+
   begin= typeinfos;  end= typeinfos+(sizeof(typeinfos)/sizeof(typeinfo));
 
   while (begin < end) {
     mid= begin + ((end-begin)>>1);
-    if (mid->type == type) return mid;
-    if (type > mid->type) begin= mid+1;
+    if (mid->typekey == type) return mid;
+    if (type > mid->typekey) begin= mid+1;
     else end= mid;
   }
   return 0;