Lines Matching defs:lookup
9 /* $Id: lookup.c,v 1.21 2007/06/18 23:47:40 tbox Exp $ */
23 #include <dns/lookup.h>
55 static void lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event);
59 dns_lookup_t *lookup = event->ev_arg;
64 REQUIRE(VALID_LOOKUP(lookup));
65 REQUIRE(lookup->task == task);
67 REQUIRE(fevent->fetch == lookup->fetch);
69 lookup_find(lookup, fevent);
73 start_fetch(dns_lookup_t *lookup) {
77 * The caller must be holding the lookup's lock.
80 REQUIRE(lookup->fetch == NULL);
82 result = dns_resolver_createfetch(lookup->view->resolver,
83 dns_fixedname_name(&lookup->name),
84 lookup->type,
86 lookup->task, fetch_done, lookup,
87 &lookup->rdataset,
88 &lookup->sigrdataset,
89 &lookup->fetch);
95 build_event(dns_lookup_t *lookup) {
101 name = isc_mem_get(lookup->mctx, sizeof(dns_name_t));
107 result = dns_name_dup(dns_fixedname_name(&lookup->name),
108 lookup->mctx, name);
112 if (dns_rdataset_isassociated(&lookup->rdataset)) {
113 rdataset = isc_mem_get(lookup->mctx, sizeof(dns_rdataset_t));
119 dns_rdataset_clone(&lookup->rdataset, rdataset);
122 if (dns_rdataset_isassociated(&lookup->sigrdataset)) {
123 sigrdataset = isc_mem_get(lookup->mctx,
130 dns_rdataset_clone(&lookup->sigrdataset, sigrdataset);
133 lookup->event->name = name;
134 lookup->event->rdataset = rdataset;
135 lookup->event->sigrdataset = sigrdataset;
142 dns_name_free(name, lookup->mctx);
143 isc_mem_put(lookup->mctx, name, sizeof(dns_name_t));
148 isc_mem_put(lookup->mctx, rdataset, sizeof(dns_rdataset_t));
154 view_find(dns_lookup_t *lookup, dns_name_t *foundname) {
156 dns_name_t *name = dns_fixedname_name(&lookup->name);
159 if (lookup->type == dns_rdatatype_rrsig)
162 type = lookup->type;
164 result = dns_view_find(lookup->view, name, type, 0, 0, ISC_FALSE,
165 &lookup->event->db, &lookup->event->node,
166 foundname, &lookup->rdataset,
167 &lookup->sigrdataset);
172 lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) {
185 REQUIRE(VALID_LOOKUP(lookup));
187 LOCK(&lookup->lock);
190 name = dns_fixedname_name(&lookup->name);
193 lookup->restarts++;
197 if (event == NULL && !lookup->canceled) {
200 INSIST(!dns_rdataset_isassociated(&lookup->rdataset));
202 (&lookup->sigrdataset));
205 if (lookup->event->node != NULL) {
206 INSIST(lookup->event->db != NULL);
207 dns_db_detachnode(lookup->event->db,
208 &lookup->event->node);
210 if (lookup->event->db != NULL)
211 dns_db_detach(&lookup->event->db);
212 result = view_find(lookup, fname);
218 if (lookup->event->node != NULL) {
219 INSIST(lookup->event->db != NULL);
220 dns_db_detachnode(lookup->event->db,
221 &lookup->event->node);
223 if (lookup->event->db != NULL)
224 dns_db_detach(&lookup->event->db);
225 result = start_fetch(lookup);
233 dns_resolver_destroyfetch(&lookup->fetch);
234 INSIST(event->rdataset == &lookup->rdataset);
235 INSIST(event->sigrdataset == &lookup->sigrdataset);
242 if (lookup->canceled)
247 result = build_event(lookup);
251 dns_db_attach(event->db, &lookup->event->db);
253 dns_db_attachnode(lookup->event->db,
255 &lookup->event->node);
259 * Copy the CNAME's target into the lookup's
262 result = dns_rdataset_first(&lookup->rdataset);
265 dns_rdataset_current(&lookup->rdataset, &rdata);
284 result = dns_rdataset_first(&lookup->rdataset);
287 dns_rdataset_current(&lookup->rdataset, &rdata);
310 if (dns_rdataset_isassociated(&lookup->rdataset))
311 dns_rdataset_disassociate(&lookup->rdataset);
312 if (dns_rdataset_isassociated(&lookup->sigrdataset))
313 dns_rdataset_disassociate(&lookup->sigrdataset);
327 if (want_restart && lookup->restarts == MAX_RESTARTS) {
336 lookup->event->result = result;
337 lookup->event->ev_sender = lookup;
338 isc_task_sendanddetach(&lookup->task,
339 (isc_event_t **)&lookup->event);
340 dns_view_detach(&lookup->view);
343 UNLOCK(&lookup->lock);
381 dns_lookup_t *lookup;
384 lookup = isc_mem_get(mctx, sizeof(*lookup));
385 if (lookup == NULL)
387 lookup->mctx = NULL;
388 isc_mem_attach(mctx, &lookup->mctx);
389 lookup->options = options;
391 ievent = isc_event_allocate(mctx, lookup, DNS_EVENT_LOOKUPDONE,
392 action, arg, sizeof(*lookup->event));
397 lookup->event = (dns_lookupevent_t *)ievent;
398 lookup->event->ev_destroy = levent_destroy;
399 lookup->event->ev_destroy_arg = mctx;
400 lookup->event->result = ISC_R_FAILURE;
401 lookup->event->name = NULL;
402 lookup->event->rdataset = NULL;
403 lookup->event->sigrdataset = NULL;
404 lookup->event->db = NULL;
405 lookup->event->node = NULL;
407 lookup->task = NULL;
408 isc_task_attach(task, &lookup->task);
410 result = isc_mutex_init(&lookup->lock);
414 dns_fixedname_init(&lookup->name);
416 result = dns_name_copy(name, dns_fixedname_name(&lookup->name), NULL);
420 lookup->type = type;
421 lookup->view = NULL;
422 dns_view_attach(view, &lookup->view);
423 lookup->fetch = NULL;
424 lookup->restarts = 0;
425 lookup->canceled = ISC_FALSE;
426 dns_rdataset_init(&lookup->rdataset);
427 dns_rdataset_init(&lookup->sigrdataset);
428 lookup->magic = LOOKUP_MAGIC;
430 *lookupp = lookup;
432 lookup_find(lookup, NULL);
437 DESTROYLOCK(&lookup->lock);
440 ievent = (isc_event_t *)lookup->event;
442 lookup->event = NULL;
444 isc_task_detach(&lookup->task);
447 isc_mem_putanddetach(&mctx, lookup, sizeof(*lookup));
453 dns_lookup_cancel(dns_lookup_t *lookup) {
454 REQUIRE(VALID_LOOKUP(lookup));
456 LOCK(&lookup->lock);
458 if (!lookup->canceled) {
459 lookup->canceled = ISC_TRUE;
460 if (lookup->fetch != NULL) {
461 INSIST(lookup->view != NULL);
462 dns_resolver_cancelfetch(lookup->fetch);
466 UNLOCK(&lookup->lock);
471 dns_lookup_t *lookup;
474 lookup = *lookupp;
475 REQUIRE(VALID_LOOKUP(lookup));
476 REQUIRE(lookup->event == NULL);
477 REQUIRE(lookup->task == NULL);
478 REQUIRE(lookup->view == NULL);
479 if (dns_rdataset_isassociated(&lookup->rdataset))
480 dns_rdataset_disassociate(&lookup->rdataset);
481 if (dns_rdataset_isassociated(&lookup->sigrdataset))
482 dns_rdataset_disassociate(&lookup->sigrdataset);
484 DESTROYLOCK(&lookup->lock);
485 lookup->magic = 0;
486 isc_mem_putanddetach(&lookup->mctx, lookup, sizeof(*lookup));