Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jul 2007 00:37:03 GMT
From:      Fredrik Lindberg <fli@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 123559 for review
Message-ID:  <200707160037.l6G0b3sd077278@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707160037.l6G0b3sd077278>