ea10ab8953f4dc924288e77353d673c609b21154
11 static adns_query
allocquery(adns_state ads
, const char *owner
, int ol
,
12 int id
, adns_rrtype type
,
13 adns_queryflags flags
, const qcontext
*ctx
) {
14 /* Query message used is the one assembled in ads->rqbuf */
17 qu
= malloc(sizeof(*qu
)+ol
+1+ads
->rqbuf
.used
); if (!qu
) return 0;
19 qu
->next
= qu
->back
= qu
->parent
= 0;
20 LIST_INIT(qu
->children
);
21 qu
->siblings
.next
= qu
->siblings
.back
= 0;
23 adns__vbuf_init(&qu
->answer
);
28 qu
->udpsent
= qu
->tcpfailed
= 0;
29 timerclear(&qu
->timeout
);
30 memcpy(&qu
->context
,ctx
,sizeof(qu
->context
));
31 memcpy(qu
->owner
,owner
,ol
); qu
->owner
[ol
]= 0;
32 qu
->querymsg
= qu
->owner
+ol
+1;
33 memcpy(qu
->owner
+ol
+1,ads
->rqbuf
.buf
,ads
->rqbuf
.used
);
34 qu
->querylen
= ads
->rqbuf
.used
;
38 static int failsubmit(adns_state ads
, const qcontext
*ctx
, adns_query
*query_r
,
39 adns_rrtype type
, adns_queryflags flags
,
40 int id
, adns_status stat
) {
44 qu
= allocquery(ads
,0,0,id
,type
,flags
,ctx
); if (!qu
) return errno
;
45 adns__query_fail(ads
,qu
,stat
);
50 int adns_submit(adns_state ads
,
53 adns_queryflags flags
,
55 adns_query
*query_r
) {
65 r
= gettimeofday(&now
,0); if (r
) return errno
;
68 if (ol
<=1 || ol
>MAXDNAME
+1)
69 return failsubmit(ads
,context
,query_r
,type
,flags
,id
,adns_s_invaliddomain
);
70 if (owner
[ol
-1]=='.' && owner
[ol
-2]!='\\') { flags
&= ~adns_qf_search
; ol
--; }
72 stat
= adns__mkquery(ads
,owner
,ol
,id
,type
,flags
);
73 if (stat
) return failsubmit(ads
,context
,query_r
,type
,flags
,id
,stat
);
75 qu
= allocquery(ads
,owner
,ol
,id
,type
,flags
,context
); if (!qu
) return errno
;
76 adns__query_udp(ads
,qu
,now
);
77 adns__autosys(ads
,now
);
83 int adns_synchronous(adns_state ads
,
86 adns_queryflags flags
,
87 adns_answer
**answer_r
) {
91 r
= adns_submit(ads
,owner
,type
,flags
,0,&qu
);
95 r
= adns_wait(ads
,&qu
,answer_r
,0);
97 if (r
) adns_cancel(ads
,qu
);
101 void adns_cancel(adns_state ads
, adns_query query
) {