+ qu->search_vb.used= qu->search_origlen;
+ if (nextentry) {
+ if (!adns__vbuf_append(&qu->search_vb,".",1) ||
+ !adns__vbuf_appendstr(&qu->search_vb,nextentry))
+ goto x_nomemory;
+ }
+
+ 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_nomemory:
+ stat= adns_s_nomemory;
+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;
+
+ if (!(qu->flags & adns_qf_owner)) return 1;
+
+ 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;
+}
+
+int adns_submit(adns_state ads,
+ const char *owner,
+ adns_rrtype type,
+ adns_queryflags flags,
+ void *context,
+ adns_query *query_r) {
+ int r, ol, ndots;
+ adns_status stat;
+ const typeinfo *typei;
+ struct timeval now;
+ adns_query qu;
+ const char *p;
+
+ adns__consistency(ads,0,cc_entex);
+
+ typei= adns__findtype(type);
+ if (!typei) return ENOSYS;
+
+ r= gettimeofday(&now,0); if (r) goto x_errno;
+ qu= query_alloc(ads,typei,flags,now); if (!qu) goto x_errno;
+
+ qu->ctx.ext= context;
+ qu->ctx.callback= 0;
+ memset(&qu->ctx.info,0,sizeof(qu->ctx.info));
+
+ *query_r= qu;
+
+ ol= strlen(owner);
+ if (!ol) { stat= adns_s_querydomaininvalid; goto x_adnsfail; }
+ if (ol>DNS_MAXDOMAIN+1) { stat= adns_s_querydomaintoolong; goto x_adnsfail; }
+
+ if (ol>=1 && owner[ol-1]=='.' && (ol<2 || owner[ol-2]!='\\')) {
+ flags &= ~adns_qf_search;
+ qu->flags= flags;
+ ol--;
+ }
+
+ if (flags & adns_qf_search) {
+ r= adns__vbuf_append(&qu->search_vb,owner,ol);
+ if (!r) { stat= adns_s_nomemory; goto x_adnsfail; }
+
+ for (ndots=0, p=owner; (p= strchr(p,'.')); p++, ndots++);
+ qu->search_doneabs= (ndots >= ads->searchndots) ? -1 : 0;
+ qu->search_origlen= ol;
+ adns__search_next(ads,qu,now);