11 static adns_query
allocquery(adns_state ads
, const char *owner
, int ol
,
12 int id
, const typeinfo
*typei
,
13 adns_queryflags flags
, const qcontext
*ctx
) {
14 /* Query message used is the one assembled in ads->rqbuf */
18 qu
= malloc(sizeof(*qu
)+ol
+1+ads
->rqbuf
.used
); if (!qu
) return 0;
19 adns__vbuf_init(&qu
->ansbuf
);
22 qu
->next
= qu
->back
= qu
->parent
= 0;
23 LIST_INIT(qu
->children
);
24 qu
->siblings
.next
= qu
->siblings
.back
= 0;
30 qu
->udpsent
= qu
->tcpfailed
= 0;
31 timerclear(&qu
->timeout
);
32 memcpy(&qu
->context
,ctx
,sizeof(qu
->context
));
33 memcpy(qu
->owner
,owner
,ol
); qu
->owner
[ol
]= 0;
34 qu
->querymsg
= qu
->owner
+ol
+1;
35 memcpy(qu
->owner
+ol
+1,ads
->rqbuf
.buf
,ads
->rqbuf
.used
);
36 qu
->querylen
= ads
->rqbuf
.used
;
41 static int failsubmit(adns_state ads
, const qcontext
*ctx
, adns_query
*query_r
,
42 adns_queryflags flags
, int id
, adns_status stat
) {
46 qu
= allocquery(ads
,0,0,id
,0,flags
,ctx
); if (!qu
) return errno
;
47 adns__query_fail(ads
,qu
,stat
);
52 int adns_submit(adns_state ads
,
55 adns_queryflags flags
,
57 adns_query
*query_r
) {
63 const typeinfo
*typei
;
68 r
= gettimeofday(&now
,0); if (r
) return errno
;
70 typei
= adns__findtype(type
);
71 if (!typei
) return failsubmit(ads
,context
,query_r
,flags
,id
,adns_s_notimplemented
);
74 if (ol
<=1 || ol
>DNS_MAXDOMAIN
+1)
75 return failsubmit(ads
,context
,query_r
,flags
,id
,adns_s_invaliddomain
);
76 if (owner
[ol
-1]=='.' && owner
[ol
-2]!='\\') { flags
&= ~adns_qf_search
; ol
--; }
78 stat
= adns__mkquery(ads
,owner
,ol
,id
,typei
,flags
);
79 if (stat
) return failsubmit(ads
,context
,query_r
,flags
,id
,stat
);
81 qu
= allocquery(ads
,owner
,ol
,id
,typei
,flags
,&ctx
); if (!qu
) return errno
;
82 adns__query_udp(ads
,qu
,now
);
83 adns__autosys(ads
,now
);
89 int adns_synchronous(adns_state ads
,
92 adns_queryflags flags
,
93 adns_answer
**answer_r
) {
97 r
= adns_submit(ads
,owner
,type
,flags
,0,&qu
);
101 r
= adns_wait(ads
,&qu
,answer_r
,0);
103 if (r
) adns_cancel(ads
,qu
);
107 void adns_cancel(adns_state ads
, adns_query query
) {