-adns_status adns__mkquery(adns_state ads, const char *owner, int ol, int id,
- adns_rrtype type, adns_queryflags flags) {
- /* Assembles a query packet in ads->rqbuf. */
- int ll, c, nlabs;
- byte label[255], *rqp;
- const char *p, *pe;
-
-#define MKQUERY_ADDB(b) *rqp++= (b)
-#define MKQUERY_ADDW(w) (MKQUERY_ADDB(((w)>>8)&0x0ff), MKQUERY_ADDB((w)&0x0ff))
-
- if (!adns__vbuf_ensure(&ads->rqbuf,DNSHDRSIZE+strlen(owner)+1+5))
- return adns_s_nolocalmem;
- rqp= ads->rqbuf.buf;
-
- MKQUERY_ADDW(id);
- MKQUERY_ADDB(0x01); /* QR=Q(0), OPCODE=QUERY(0000), !AA, !TC, RD */
- MKQUERY_ADDB(0x00); /* !RA, Z=000, RCODE=NOERROR(0000) */
- MKQUERY_ADDW(1); /* QDCOUNT=1 */
- MKQUERY_ADDW(0); /* ANCOUNT=0 */
- MKQUERY_ADDW(0); /* NSCOUNT=0 */
- MKQUERY_ADDW(0); /* ARCOUNT=0 */
- p= owner; pe= owner+ol;
- nlabs= 0;
- if (!*p) return adns_s_invaliddomain;
- do {
- ll= 0;
- while (p!=pe && (c= *p++)!='.') {
- if (c=='\\') {
- if (!(flags & adns_qf_anyquote)) return adns_s_invaliddomain;
- if (ctype_digit(p[0])) {
- if (ctype_digit(p[1]) && ctype_digit(p[2])) {
- c= (*p++ - '0')*100 + (*p++ - '0')*10 + (*p++ - '0');
- if (c >= 256) return adns_s_invaliddomain;
- } else {
- return adns_s_invaliddomain;
- }
- } else if (!(c= *p++)) {
- return adns_s_invaliddomain;
- }
- }
- if (!(flags & adns_qf_anyquote)) {
- if (ctype_digit(c) || c == '-') {
- if (!ll) return adns_s_invaliddomain;
- } else if ((c < 'a' || c > 'z') && (c < 'A' && c > 'Z')) {
- return adns_s_invaliddomain;
- }
- }
- if (ll == sizeof(label)) return adns_s_invaliddomain;
- label[ll++]= c;
+int adns__internal_submit(adns_state ads, adns_query *query_r,
+ const typeinfo *typei, vbuf *qumsg_vb, int id,
+ adns_queryflags flags, struct timeval now,
+ adns_status failstat, const qcontext *ctx) {
+ adns_query qu;
+
+ qu= malloc(sizeof(*qu)); if (!qu) goto x_nomemory;
+ qu->answer= malloc(sizeof(*qu->answer)); if (!qu->answer) goto x_freequ_nomemory;
+
+ qu->ads= ads;
+ qu->state= query_udp;
+ qu->back= qu->next= qu->parent= 0;
+ LIST_INIT(qu->children);
+ qu->siblings.next= qu->siblings.back= 0;
+ qu->allocations= 0;
+ qu->interim_allocd= 0;
+ qu->final_allocspace= 0;
+
+ qu->typei= typei;
+ adns__vbuf_init(&qu->vb);
+
+ qu->cname_dgram= 0;
+ qu->cname_dglen= qu->cname_begin= 0;
+
+ qu->id= id;
+ qu->flags= flags;
+ qu->udpretries= 0;
+ qu->udpnextserver= 0;
+ qu->udpsent= qu->tcpfailed= 0;
+ timerclear(&qu->timeout);
+ memcpy(&qu->context,ctx,sizeof(qu->context));
+
+ qu->answer->status= adns_s_ok;
+ qu->answer->cname= 0;
+ qu->answer->type= typei->type;
+ qu->answer->nrrs= 0;
+ qu->answer->rrs= 0;
+ qu->answer->rrsz= typei->rrsz;
+
+ *query_r= qu;
+
+ qu->query_dglen= qumsg_vb->used;
+ if (qumsg_vb->used) {
+ qu->query_dgram= malloc(qumsg_vb->used);
+ if (!qu->query_dgram) {
+ adns__query_fail(qu,adns_s_nolocalmem);
+ return adns_s_ok;