chiark / gitweb /
Return owner if caller asks.
authorian <ian>
Sat, 17 Apr 1999 14:38:49 +0000 (14:38 +0000)
committerian <ian>
Sat, 17 Apr 1999 14:38:49 +0000 (14:38 +0000)
client/adnstest.c
src/adns.h
src/internal.h
src/query.c

index 6827cbd2787d2e0e9f867a1aa2002176f1d10af6..9828ee08bf8a290da3486ffa42ee55187089505f 100644 (file)
@@ -166,9 +166,11 @@ int main(int argc, char *const *argv) {
       ri= adns_rr_info(ans->type, &rrtn,&fmtn,&len, 0,0);
       fprintf(stdout, "%s type ",domain);
       dumptype(ri,rrtn,fmtn);
-      fprintf(stdout, " flags %d: %s; nrrs=%d; cname=%s; ttl=%ld\n",
+      fprintf(stdout, " flags %d: %s; nrrs=%d; cname=%s; owner=%s; ttl=%ld\n",
              qflags, adns_strerror(ans->status),
-             ans->nrrs, ans->cname ? ans->cname : "$",
+             ans->nrrs,
+             ans->cname ? ans->cname : "$",
+             ans->owner ? ans->owner : "$",
              (long)ans->expires - (long)now.tv_sec);
       if (ans->nrrs) {
        assert(!ri);
index 41bf699daea7b192013cf8098f1345c86cc1f37f..e70abd50c93e86a6583dba8e157fbc82b05be82a 100644 (file)
@@ -48,7 +48,7 @@ typedef enum {
 typedef enum {
   adns_qf_search=          0x000001, /* use the searchlist */
   adns_qf_usevc=           0x000002, /* use a virtual circuit (TCP connection) */
-  adns_qf_owner=           0x000004, /* fill in the owner field in the answer fixme:do */
+  adns_qf_owner=           0x000004, /* fill in the owner field in the answer */
   adns_qf_quoteok_query=   0x000010, /* allow quote-requiring chars in query domain */
   adns_qf_quoteok_cname=   0x000020, /* allow ... in CNAME we go via */
   adns_qf_quoteok_anshost= 0x000040, /* allow ... in answers expected to be hostnames */
@@ -196,7 +196,7 @@ typedef struct {
 typedef struct {
   adns_status status;
   char *cname; /* always NULL if query was for CNAME records */
-  char *owner; /* often NULL, depending on query flags */
+  char *owner; /* only set if requested in query flags */
   adns_rrtype type; /* guaranteed to be same as in query */
   time_t expires; /* expiry time, defined only if _s_ok, nxdomain or nodata. NOT TTL! */
   int nrrs, rrsz;
index 4ec3c3edd9957b0a99e449a6e275a54b78028cd6..5a58f9585454f07eff690b8da91c945988667516 100644 (file)
@@ -174,6 +174,8 @@ struct adns__query {
    * we found a cname (this corresponds to cname_dgram in the query
    * structure).  type is set from the word go.  nrrs and rrs
    * are set together, when we find how many rrs there are.
+   * owner is set during querying unless we're doing searchlist,
+   * in which case it is set only when we find an answer.
    */
   
   byte *cname_dgram;
@@ -189,8 +191,6 @@ struct adns__query {
    * absolute query yet (0=not yet, 1=done, -1=must do straight away,
    * but not done yet).  If flags doesn't have adns_qf_search then
    * the vbuf is initialised but empty and everything else is zero.
-   *
-   * fixme: actually implement this!
    */
   
   int id, flags, udpretries;
index c420fcf26716a77a39d515588c2bfca3fd2eac23..38bc3c2b29c70bc5f20c66a13f640a19363d7f49 100644 (file)
@@ -72,7 +72,7 @@ static adns_query query_alloc(adns_state ads, const typeinfo *typei,
   memset(&qu->ctx,0,sizeof(qu->ctx));
 
   qu->answer->status= adns_s_ok;
-  qu->answer->cname= 0;
+  qu->answer->cname= qu->answer->owner= 0;
   qu->answer->type= typei->type;
   qu->answer->expires= -1;
   qu->answer->nrrs= 0;
@@ -174,6 +174,20 @@ x_fail:
   adns__query_fail(qu,stat);
 }
 
+static int save_owner(adns_query qu, const char *owner, int ol) {
+  /* Returns 1 if OK, otherwise there was no memory. */
+  adns_answer *ans;
+
+  ans= qu->answer;
+  assert(!ans->owner);
+
+  ans->owner= adns__alloc_interim(qu,ol+1);  if (!ans->owner) return 0;
+
+  memcpy(ans->owner,owner,ol);
+  ans->owner[ol]= 0;
+  return 1;
+}
+
 int adns_submit(adns_state ads,
                const char *owner,
                adns_rrtype type,
@@ -214,6 +228,9 @@ int adns_submit(adns_state ads,
     qu->search_origlen= ol;
     adns__search_next(ads,qu,now);
   } else {
+    if (flags & adns_qf_owner) {
+      if (!save_owner(qu,owner,ol)) { stat= adns_s_nomemory; goto x_adnsfail; }
+    }
     query_simple(ads,qu, owner,ol, typei,flags, now);
   }
   return 0;
@@ -368,6 +385,7 @@ static void makefinal_query(adns_query qu) {
 
   qu->final_allocspace= (byte*)ans + MEM_ROUND(sizeof(*ans));
   adns__makefinal_str(qu,&ans->cname);
+  adns__makefinal_str(qu,&ans->owner);
   
   if (ans->nrrs) {
     adns__makefinal_block(qu, &ans->rrs.untyped, ans->nrrs*ans->rrsz);
@@ -393,6 +411,14 @@ void adns__query_done(adns_query qu) {
   qu->id= -1;
   ans= qu->answer;
 
+  if (qu->flags & adns_qf_owner && qu->flags & adns_qf_search &&
+      ans->status != adns_s_nomemory) {
+    if (!save_owner(qu, qu->search_vb.buf, qu->search_vb.used)) {
+      adns__query_fail(qu,adns_s_nomemory);
+      return;
+    }
+  }
+
   if (ans->nrrs && qu->typei->diff_needswap) {
     if (!adns__vbuf_ensure(&qu->vb,qu->typei->rrsz)) {
       adns__query_fail(qu,adns_s_nomemory);