General improvements; add cancel routine.
[adns] / src / general.c
index 3f4c8c8..211b6d2 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include <arpa/inet.h>
 
@@ -46,7 +47,7 @@ void adns__vdiag(adns_state ads, const char *pfx, adns_initflags prevent,
     adns__vbuf_init(&vb);
     fprintf(stderr,"%sQNAME=%s, QTYPE=%s",
            bef,
-           adns__diag_domain(qu->ads,-1,0, &vb,qu->flags,
+           adns__diag_domain(qu->ads,-1,0, &vb,
                              qu->query_dgram,qu->query_dglen,DNS_HDRSIZE),
            qu->typei ? qu->typei->rrtname : "<unknown>");
     if (qu->typei && qu->typei->fmtname)
@@ -138,11 +139,11 @@ void adns__vbuf_free(vbuf *vb) {
 
 /* Additional diagnostic functions */
 
-const char *adns__diag_domain(adns_state ads, int serv, adns_query qu, vbuf *vb,
-                             int flags, const byte *dgram, int dglen, int cbyte) {
+const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
+                             vbuf *vb, const byte *dgram, int dglen, int cbyte) {
   adns_status st;
 
-  st= adns__parse_domain(ads,serv,qu,vb, flags,dgram,dglen,&cbyte,dglen);
+  st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok, dgram,dglen,&cbyte,dglen);
   if (st == adns_s_nolocalmem) {
     return "<cannot report domain... out of memory>";
   }
@@ -238,3 +239,19 @@ const char *adns_strerror(adns_status st) {
   snprintf(buf,sizeof(buf),"code %d",st);
   return buf;
 }
+
+void adns__isort(void *array, int nobjs, int sz, void *tempbuf,
+                int (*needswap)(const void *a, const void *b)) {
+  byte *data= array;
+  int i, place;
+
+  for (i=0; i<nobjs; i++) {
+    for (place= i; place>0 && needswap(data + (place-1)*sz, data + i*sz); place--);
+
+    if (place != i) {
+      memcpy(tempbuf, data + i*sz, sz);
+      memmove(data + (place+1)*sz, data + place*sz, (i-place)*sz);
+      memcpy(data + place*sz, tempbuf, sz);
+    }
+  }
+}