+static void query_simple(adns_state ads, adns_query qu,
+ const char *owner, int ol,
+ const typeinfo *typei, adns_queryflags flags,
+ struct timeval now) {
+ vbuf vb;
+ int id;
+ adns_status stat;
+
+ adns__vbuf_init(&vb);
+
+ stat= adns__mkquery(ads,&vb,&id, owner,ol, typei,flags);
+ if (stat) { adns__query_fail(qu,stat); return; }
+
+ query_submit(ads,qu, typei,&vb,id, flags,now);
+}
+
+void adns__search_next(adns_state ads, adns_query qu, struct timeval now) {
+ const char *nextentry;
+ adns_status stat;
+
+ if (qu->search_doneabs<0) {
+ nextentry= 0;
+ qu->search_doneabs= 1;
+ } else {
+ if (qu->search_pos >= ads->nsearchlist) {
+ if (qu->search_doneabs) {
+ stat= adns_s_nxdomain; goto x_fail;
+ return;
+ } else {
+ nextentry= 0;
+ qu->search_doneabs= 1;
+ }
+ } else {
+ nextentry= ads->searchlist[qu->search_pos++];
+ }
+ }
+
+ qu->search_vb.used= qu->search_origlen;
+ if (nextentry) {
+ if (!adns__vbuf_append(&qu->search_vb,".",1) ||
+ !adns__vbuf_appendstr(&qu->search_vb,nextentry)) {
+ stat= adns_s_nomemory; goto x_fail;
+ }
+ }
+
+ free(qu->query_dgram);
+ qu->query_dgram= 0; qu->query_dglen= 0;
+
+ query_simple(ads,qu, qu->search_vb.buf, qu->search_vb.used, qu->typei, qu->flags, now);
+ return;
+
+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_preserved(qu,ol+1); if (!ans->owner) return 0;
+
+ memcpy(ans->owner,owner,ol);
+ ans->owner[ol]= 0;
+ return 1;