Lines Matching defs:q
131 context_query_delete(struct ctx_query* q)
133 if(!q) return;
134 ub_resolve_free(q->res);
135 free(q->msg);
136 free(q);
160 struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
161 if(!q) return NULL;
163 if(!find_id(ctx, &q->querynum)) {
165 free(q);
169 q->node.key = &q->querynum;
170 q->async = (cb != NULL || cb_event != NULL);
171 q->cb = cb;
172 q->cb_event = cb_event;
173 q->cb_arg = cbarg;
174 q->res = (struct ub_result*)calloc(1, sizeof(*q->res));
175 if(!q->res) {
176 free(q);
179 q->res->qname = strdup(name);
180 if(!q->res->qname) {
181 free(q->res);
182 free(q);
185 q->res->qtype = rrtype;
186 q->res->qclass = rrclass;
190 if(q->async)
192 (void)rbtree_insert(&ctx->queries, &q->node);
194 return q;
240 context_serialize_new_query(struct ctx_query* q, uint32_t* len)
250 size_t slen = strlen(q->res->qname) + 1/*end of string*/;
255 sldns_write_uint32(p+sizeof(uint32_t), (uint32_t)q->querynum);
256 sldns_write_uint32(p+2*sizeof(uint32_t), (uint32_t)q->res->qtype);
257 sldns_write_uint32(p+3*sizeof(uint32_t), (uint32_t)q->res->qclass);
258 memmove(p+4*sizeof(uint32_t), q->res->qname, slen);
265 struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
266 if(!q) return NULL;
268 free(q);
272 q->querynum = (int)sldns_read_uint32(p+sizeof(uint32_t));
273 q->node.key = &q->querynum;
274 q->async = 1;
275 q->res = (struct ub_result*)calloc(1, sizeof(*q->res));
276 if(!q->res) {
277 free(q);
280 q->res->qtype = (int)sldns_read_uint32(p+2*sizeof(uint32_t));
281 q->res->qclass = (int)sldns_read_uint32(p+3*sizeof(uint32_t));
282 q->res->qname = strdup((char*)(p+4*sizeof(uint32_t)));
283 if(!q->res->qname) {
284 free(q->res);
285 free(q);
291 (void)rbtree_insert(&ctx->queries, &q->node);
292 return q;
298 struct ctx_query* q;
305 q = (struct ctx_query*)rbtree_search(&ctx->queries, &querynum);
306 if(!q) {
309 log_assert(q->async);
310 return q;
314 context_serialize_answer(struct ctx_query* q, int err, sldns_buffer* pkt,
330 size_t wlen = (pkt&&q->res->why_bogus)?strlen(q->res->why_bogus)+1:0;
336 sldns_write_uint32(p+sizeof(uint32_t), (uint32_t)q->querynum);
338 sldns_write_uint32(p+3*sizeof(uint32_t), (uint32_t)q->msg_security);
339 sldns_write_uint32(p+4*sizeof(uint32_t), (uint32_t)q->res->was_ratelimited);
342 memmove(p+size_of_uint32s, q->res->why_bogus, wlen);
354 struct ctx_query* q = NULL ;
360 q = (struct ctx_query*)rbtree_search(&ctx->queries, &id);
361 if(!q) return NULL;
363 q->msg_security = sldns_read_uint32(p+3*sizeof(uint32_t));
364 q->res->was_ratelimited = (int)sldns_read_uint32(p+4*sizeof(uint32_t));
368 q->res->why_bogus = (char*)memdup(
370 if(!q->res->why_bogus) {
372 q->msg_len = 0;
374 return q;
376 q->res->why_bogus[wlen-1] = 0; /* zero terminated for sure */
379 q->msg_len = len - size_of_uint32s - wlen;
380 q->msg = (uint8_t*)memdup(p+size_of_uint32s+wlen,
381 q->msg_len);
382 if(!q->msg) {
384 q->msg_len = 0;
386 return q;
389 return q;
393 context_serialize_cancel(struct ctx_query* q, uint32_t* len)
402 sldns_write_uint32(p+sizeof(uint32_t), (uint32_t)q->querynum);
409 struct ctx_query* q;
414 q = (struct ctx_query*)rbtree_search(&ctx->queries, &id);
415 return q;