From owner-p4-projects@FreeBSD.ORG Mon Jul 16 00:37:04 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9B94516A406; Mon, 16 Jul 2007 00:37:04 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 28D9F16A402 for ; Mon, 16 Jul 2007 00:37:04 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 193EF13C491 for ; Mon, 16 Jul 2007 00:37:04 +0000 (UTC) (envelope-from fli@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l6G0b3ko077281 for ; Mon, 16 Jul 2007 00:37:03 GMT (envelope-from fli@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l6G0b3sd077278 for perforce@freebsd.org; Mon, 16 Jul 2007 00:37:03 GMT (envelope-from fli@FreeBSD.org) Date: Mon, 16 Jul 2007 00:37:03 GMT Message-Id: <200707160037.l6G0b3sd077278@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to fli@FreeBSD.org using -f From: Fredrik Lindberg To: Perforce Change Reviews Cc: Subject: PERFORCE change 123559 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2007 00:37:05 -0000 http://perforce.freebsd.org/chv.cgi?CH=123559 Change 123559 by fli@fli_nexus on 2007/07/16 00:36:36 - Style fixes - Make search functions return cache_res {} instead of record_res {} Affected files ... .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/cache.c#3 edit Differences ... ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/cache.c#3 (text+ko) ==== @@ -53,7 +53,6 @@ TAILQ_INSERT_HEAD(&c->c_list, cr, cr_next); } else { - while (cr->cr_ttl_rel >= cr2->cr_ttl_rel) { cr->cr_ttl_rel -= cr2->cr_ttl_rel; cr3 = TAILQ_NEXT(cr2, cr_next); @@ -116,7 +115,7 @@ if (--cr->cr_ttl_rel > 0) return; - /* Remove entries with the same ttl */ + /* Remove entries with the same ttl */ do { rr = &cr->cr_res; cache_del(c, rr); @@ -143,13 +142,13 @@ struct cache_res *cr; int rval; - rr = record_res_find(&c->c_recs, rrset->r_name, rrset->r_type); - if (rr != NULL) { - rt = rr->rr_type; - TAILQ_FOREACH(rr, &rt->rt_list, rr_next) { - if (rr->rr_len == rrset->r_datalen) - if (memcmp(rr->rr_data, rrset->r_data, rr->rr_len) == 0) - break; + rr = NULL; + rt = record_type_find(&c->c_recs, rrset->r_name, rrset->r_type); + if (rt != NULL) { + record_type_foreach(rr, rt) { + if (rr->rr_len == rrset->r_datalen && + memcmp(rr->rr_data, rrset->r_data, rr->rr_len) == 0) + break; } } @@ -157,17 +156,18 @@ cache_set_ttl(c, rr, rrset->r_ttl); dprintf(DEBUG_CACHE, "TTL set to %d on name=%s, type=%d, rdatalen=%d", - rrset->r_ttl, rrset->r_name, rrset->r_type, rrset->r_datalen); + rrset->r_ttl, rrset->r_name, rrset->r_type, + rrset->r_datalen); rval = 1; if (new != NULL) - *new = rr; + *new = rr; } else if (rrset->r_ttl > 0) { record_get(&c->c_recs, &r, 0, rrset->r_name); cr = malloc(sizeof(struct cache_res)); rr = &cr->cr_res; - record_res_add(r, &rr, RECORD_NOALLOC, rrset->r_type, rrset->r_data, - rrset->r_datalen); + record_res_add(r, &rr, RECORD_NOALLOC, rrset->r_type, + rrset->r_data, rrset->r_datalen); record_res_setparent(&cr->cr_res, cr); cr->cr_ttl_abs = rrset->r_ttl; cr->cr_ttl_rel = rrset->r_ttl; @@ -176,7 +176,8 @@ enqueue_ttl(c, cr); dprintf(DEBUG_CACHE, "Record added to cache name=%s, type=%d, ttl=%d, dlen=%d", - rrset->r_name, rrset->r_type, rrset->r_ttl, rrset->r_datalen); + rrset->r_name, rrset->r_type, rrset->r_ttl, + rrset->r_datalen); rval = 0; if (new != NULL) *new = &cr->cr_res; @@ -202,10 +203,9 @@ MDNS_INIT_ASSERT(rr, rr_magic); cr = record_res_getparent(rr); - dprintf(DEBUG_CACHE, - "Removed %s from cache, type=%d, dlen=%d, attl=%d, rttl=%d, cached=%d", - r->r_name, rt->rt_type, rr->rr_len, cr->cr_ttl_abs, cr->cr_ttl_rel, - rtime - cr->cr_ctime); + dprintf(DEBUG_CACHE, "Removed %s from cache, type=%d, dlen=%d," + "attl=%d, rttl=%d, cached=%d", r->r_name, rt->rt_type, rr->rr_len, + cr->cr_ttl_abs, cr->cr_ttl_rel, rtime - cr->cr_ctime); MDNS_INIT_ASSERT(cr, cr_magic); dequeue_ttl(c, cr); @@ -221,25 +221,35 @@ * name - Resource name * type - Resource type */ -struct record_res * +struct cache_res * cache_find(struct cache *c, char *name, uint16_t type) { struct record_res *rr; + struct record_type *rt; + + rt = record_type_find(&c->c_recs, name, type); + if (rt == NULL) + return (NULL); - MDNS_INIT_ASSERT(rr, rr_magic); - rr = record_res_find(&c->c_recs, name, type); - return (rr); + rr = record_type_first(rt); + return (record_res_getparent(rr)); } /* * Given a resource record, return the next if multiple resources * are available per (name,type) pair. */ -struct record_res * -cache_find_next(struct record_res *rr) +struct cache_res * +cache_find_next(struct cache_res *cr) { + struct record_res *rr; - return (TAILQ_NEXT(rr, rr_next)); + rr = &cr->cr_res; + rr = record_type_next(rr); + if (rr != NULL) + return (record_res_getparent(rr)); + else + return (NULL); } /* @@ -257,12 +267,11 @@ struct record_type *rt; time_t cur; - rr = record_res_find(&c->c_recs, name, type); - if (rr == NULL) + rt = record_type_find(&c->c_recs, name, type); + if (rt == NULL) return; - MDNS_INIT_ASSERT(rr, rr_magic); - rt = rr->rr_type; + MDNS_INIT_ASSERT(rt, rt_magic); cur = time(NULL); TAILQ_FOREACH_SAFE(rr, &rt->rt_list, rr_next, rr2) { cr = record_res_getparent(rr);