chiark / gitweb /
Add a type hook for reporting the output record size.
[adns] / src / query.c
index 31adfc4e29f0c2560479030350b7f9d2ab1fcb73..30108f2a6b7a24e2e3f8196ce8dbb0f4d72f83c7 100644 (file)
@@ -83,7 +83,7 @@ static adns_query query_alloc(adns_state ads,
   qu->answer->expires= -1;
   qu->answer->nrrs= 0;
   qu->answer->rrs.untyped= 0;
-  qu->answer->rrsz= typei->rrsz;
+  qu->answer->rrsz= typei->getrrsz ? typei->getrrsz(type) : typei->rrsz;
 
   return qu;
 }
@@ -105,7 +105,9 @@ static void query_submit(adns_state ads, adns_query qu,
   qu->query_dglen= qu->vb.used;
   memcpy(qu->query_dgram,qu->vb.buf,qu->vb.used);
 
-  if (typei->query_send && !(qu->flags & adns__qf_senddirect))
+  if (flags & adns__qf_nosend)
+    ;
+  else if (typei->query_send && !(flags & adns__qf_senddirect))
     typei->query_send(qu,now);
   else
     adns__query_send(qu, now);
@@ -118,7 +120,7 @@ adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
                                  const qcontext *ctx) {
   adns_query qu;
 
-  qu= query_alloc(ads,typei,type,flags,now);
+  qu= query_alloc(ads,typei,type,flags & ~adns__qf_nosend,now);
   if (!qu) { adns__vbuf_free(qumsg_vb); return adns_s_nomemory; }
   *query_r= qu;
 
@@ -388,13 +390,22 @@ void *adns__alloc_preserved(adns_query qu, size_t sz) {
   return rv;
 }
 
-void adns__free_interim(adns_query qu, void *p) {
+static allocnode *alloc_info(adns_query qu, void *p, size_t *sz_r)
+{
   allocnode *an;
-  size_t sz;
 
-  if (!p) return;
+  if (!p || p == qu) { *sz_r = 0; return 0; }
   an = (allocnode *)((byte *)p - MEM_ROUND(sizeof(allocnode)));
-  sz = MEM_ROUND(an->sz);
+  *sz_r = MEM_ROUND(an->sz);
+  return an;
+}
+
+void adns__free_interim(adns_query qu, void *p) {
+  size_t sz;
+  allocnode *an = alloc_info(qu, p, &sz);
+
+  if (!an) return;
+  assert(!qu->final_allocspace);
   LIST_UNLINK(qu->allocations, an);
   free(an);
   qu->interim_allocd -= sz;
@@ -404,12 +415,11 @@ void *adns__alloc_mine(adns_query qu, size_t sz) {
   return alloc_common(qu,MEM_ROUND(sz));
 }
 
-void adns__transfer_interim(adns_query from, adns_query to,
-                           void *block, size_t sz) {
-  allocnode *an;
+void adns__transfer_interim(adns_query from, adns_query to, void *block) {
+  size_t sz;
+  allocnode *an = alloc_info(from, block, &sz);
 
-  if (!block) return;
-  an= (void*)((byte*)block - MEM_ROUND(sizeof(*an)));
+  if (!an) return;
 
   assert(!to->final_allocspace);
   assert(!from->final_allocspace);
@@ -417,7 +427,6 @@ void adns__transfer_interim(adns_query from, adns_query to,
   LIST_UNLINK(from->allocations,an);
   LIST_LINK_TAIL(to->allocations,an);
 
-  sz= MEM_ROUND(sz);
   from->interim_allocd -= sz;
   to->interim_allocd += sz;