chiark / gitweb /
+ * Referrals with RD+RA set, or RCODE=Refused, don't generate warnings,
[adns.git] / src / general.c
index 12e5983efcec7593e93ffd42f5c3ce39c4341815..ae1f05f96056826a944c7070f6fe74fc6b4c02e8 100644 (file)
@@ -4,7 +4,12 @@
  * - vbuf handling
  */
 /*
  * - vbuf handling
  */
 /*
- *  This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson
+ *  This file is
+ *    Copyright (C) 1997-2000 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 Tony Finch <dot@dotat.at>
  *  
  *  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
  *  
  *  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
@@ -22,7 +27,7 @@
  */
 
 #include <stdlib.h>
  */
 
 #include <stdlib.h>
-#include <string.h>
+#include <unistd.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -42,7 +47,11 @@ void adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
       (!(ads->iflags & adns_if_debug) && (!prevent || (ads->iflags & prevent))))
     return;
 
       (!(ads->iflags & adns_if_debug) && (!prevent || (ads->iflags & prevent))))
     return;
 
-  fprintf(ads->diagfile,"adns%s: ",pfx);
+  if (ads->iflags & adns_if_logpid) {
+    fprintf(ads->diagfile,"adns%s [%ld]: ",pfx,(long)getpid());
+  } else {
+    fprintf(ads->diagfile,"adns%s: ",pfx);
+  }
 
   vfprintf(ads->diagfile,fmt,al);
 
 
   vfprintf(ads->diagfile,fmt,al);
 
@@ -59,6 +68,7 @@ void adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
     if (qu->typei && qu->typei->fmtname)
       fprintf(ads->diagfile,"(%s)",qu->typei->fmtname);
     bef=", "; aft=")\n";
     if (qu->typei && qu->typei->fmtname)
       fprintf(ads->diagfile,"(%s)",qu->typei->fmtname);
     bef=", "; aft=")\n";
+    adns__vbuf_free(&vb);
   }
   
   if (serv>=0) {
   }
   
   if (serv>=0) {
@@ -200,6 +210,7 @@ adns_status adns_rr_info(adns_rrtype type,
   return st;
 }
 
   return st;
 }
 
+
 #define SINFO(n,s) { adns_s_##n, #n, s }
 
 static const struct sinfo {
 #define SINFO(n,s) { adns_s_##n, #n, s }
 
 static const struct sinfo {
@@ -226,17 +237,17 @@ static const struct sinfo {
   SINFO(  rcodeunknown,        "Nameserver sent unknown response code"         ),
   
   SINFO(  inconsistent,        "Inconsistent resource records in DNS"          ),
   SINFO(  rcodeunknown,        "Nameserver sent unknown response code"         ),
   
   SINFO(  inconsistent,        "Inconsistent resource records in DNS"          ),
-  SINFO(  prohibitedcname,     "DNS data refers to an alias"                   ),
+  SINFO(  prohibitedcname,     "DNS alias found where canonical name wanted"   ),
   SINFO(  answerdomaininvalid, "Found syntactically invalid domain name"       ),
   SINFO(  answerdomaintoolong, "Found overly-long domain name"                 ),
   SINFO(  invaliddata,         "Found invalid DNS data"                        ),
 
   SINFO(  querydomainwrong,    "Domain invalid for particular DNS query type"  ),
   SINFO(  querydomaininvalid,  "Domain name is syntactically invalid"          ),
   SINFO(  answerdomaininvalid, "Found syntactically invalid domain name"       ),
   SINFO(  answerdomaintoolong, "Found overly-long domain name"                 ),
   SINFO(  invaliddata,         "Found invalid DNS data"                        ),
 
   SINFO(  querydomainwrong,    "Domain invalid for particular DNS query type"  ),
   SINFO(  querydomaininvalid,  "Domain name is syntactically invalid"          ),
-  SINFO(  querydomaintoolong,  "Domain name is too long"                       ),
+  SINFO(  querydomaintoolong,  "Domain name or component is too long"          ),
 
   SINFO(  nxdomain,            "No such domain"                                ),
 
   SINFO(  nxdomain,            "No such domain"                                ),
-  SINFO(  nodata,              "No such data"                                  ),
+  SINFO(  nodata,              "No such data"                                  )
 };
 
 static int si_compar(const void *key, const void *elem) {
 };
 
 static int si_compar(const void *key, const void *elem) {
@@ -264,6 +275,43 @@ const char *adns_errabbrev(adns_status st) {
   return si->abbrev;
 }
 
   return si->abbrev;
 }
 
+
+#define STINFO(max) { adns_s_max_##max, #max }
+
+static const struct stinfo {
+  adns_status stmax;
+  const char *abbrev;
+} stinfos[]= {
+  { adns_s_ok, "ok" },
+  STINFO(  localfail   ),
+  STINFO(  remotefail  ),
+  STINFO(  tempfail    ),
+  STINFO(  misconfig   ),
+  STINFO(  misquery    ),
+  STINFO(  permfail    )
+};
+
+static int sti_compar(const void *key, const void *elem) {
+  const adns_status *st= key;
+  const struct stinfo *sti= elem;
+
+  adns_status here, min, max;
+
+  here= *st;
+  min= (sti==stinfos) ? 0 : sti[-1].stmax+1;
+  max= sti->stmax;
+  
+  return here < min  ? -1 : here > max ? 1 : 0;
+}
+
+const char *adns_errtypeabbrev(adns_status st) {
+  const struct stinfo *sti;
+
+  sti= bsearch(&st,stinfos,sizeof(stinfos)/sizeof(*stinfos),sizeof(*stinfos),sti_compar);
+  return sti->abbrev;
+}
+
+
 void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
                 int (*needswap)(void *context, const void *a, const void *b),
                 void *context) {
 void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
                 int (*needswap)(void *context, const void *a, const void *b),
                 void *context) {