Date: Mon, 16 Jul 2007 01:26:17 GMT From: Fredrik Lindberg <fli@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123571 for review Message-ID: <200707160126.l6G1QHsf090847@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123571 Change 123571 by fli@fli_nexus on 2007/07/16 01:26:07 - Add record_type_find() which returns the given record type - Change record_res_find() to find an exact match to a resource exists. - Add some convenient macros to traverse types and resources. - Style fixes. Affected files ... .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/record.c#3 edit .. //depot/projects/soc2007/fli-mdns_sd/mdnsd/record.h#3 edit Differences ... ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/record.c#3 (text+ko) ==== @@ -28,11 +28,17 @@ #include <stdint.h> #include <string.h> +#include "debug.h" +#include "log.h" #include "record.h" -#include "log.h" + +#define record_aquire(r) (r)->r_refcnt++; \ + dprintf(DEBUG_REC, "Refcount on r=%x increased to %d",\ + r, (r)->r_refcnt); -#define record_aquire(r) (r)->r_refcnt++; -#define record_type_aquire(rt) (rt)->rt_refcnt++; +#define record_type_aquire(rt) (rt)->rt_refcnt++; \ + dprintf(DEBUG_REC, "Refcount on rt=%x increased to %d",\ + rt, (rt)->rt_refcnt); /* * Initialize a record set for `class' @@ -84,7 +90,7 @@ * recs - Record set * r - Pointer to record * name - Resource name - * flags - RECORD_NOALLOC will supress memory allocation + * flags - RECORD_NOALLOC will supress memory allocation */ int record_get(struct records *recs, struct record **r, int flags, char *name) @@ -123,7 +129,8 @@ *r = rec; } record_aquire(*r); - dprintf(DEBUG_REC, "Record aquired r=%x, refcnt=%d", *r, (*r)->r_refcnt); + dprintf(DEBUG_REC, "Record aquired r=%x, name=%s, refcnt=%d", + *r, (*r)->r_name, (*r)->r_refcnt); return (0); } @@ -152,7 +159,8 @@ dprintf(DEBUG_REC, "References cleared on r=%x, removed", r); } else { - dprintf(DEBUG_REC, "Record released r=%x, refs=%d", r, r->r_refcnt); + dprintf(DEBUG_REC, "Record released r=%x, refs=%d", + r, r->r_refcnt); } } @@ -198,7 +206,7 @@ * Get a record type for a record, will be intialized if needed * r - Record * rt - Pointer to the new record type - * flags - RECORD_NOALLOC will supress memory allocation + * flags - RECORD_NOALLOC will supress memory allocation * type - DNS type */ int @@ -327,6 +335,12 @@ dprintf(DEBUG_REC, "Resource rr=%x removed, rt=%x", rr, rt); } +/* + * Set resource data on a resource record + * rr - Resource record + * data - Data pointer + * dlen - Length of data + */ void record_res_setdata(struct record_res *rr, void *data, size_t dlen) { @@ -347,7 +361,8 @@ * type - Resource type */ struct record_res * -record_res_find(struct records *recs, char *name, uint16_t type) +record_res_find(struct records *recs, char *name, uint16_t type, char *data, + size_t dlen) { struct record *r; struct record_type *rt; @@ -368,10 +383,35 @@ if (rt == NULL) return (NULL); - rr = TAILQ_FIRST(&rt->rt_list); + TAILQ_FOREACH(rr, &rt->rt_list, rr_next) { + if (rr->rr_len == dlen) + if (memcmp(rr->rr_data, data, dlen) == 0) + break; + } return (rr); } +struct record_type * +record_type_find(struct records *recs, char *name, uint16_t type) +{ + struct record *r; + struct record_type *rt; + size_t len; + + MDNS_INIT_ASSERT(recs, r_magic); + + len = strlen(name); + r = hashtbl_find(&recs->r_recs, name, len); + if (r == NULL) + return (NULL); + + TAILQ_FOREACH(rt, &r->r_list, rt_next) { + if (rt->rt_type == type) + break; + } + return (rt); +} + static void rec_walk(__unused struct hashtbl *ht, __unused const void *key, __unused size_t keylen, void *data, void *arg) @@ -426,7 +466,8 @@ rr = rr_head = TAILQ_FIRST(&rt->rt_list); } else { - rr_tmp = TAILQ_NEXT(TAILQ_NEXT(rr_prev, rr_next), rr_next); + rr_tmp = TAILQ_NEXT( + TAILQ_NEXT(rr_prev, rr_next), rr_next); if (rr_tmp != NULL && rr_tmp != rr_next) rr = rr_tmp; else ==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/record.h#3 (text+ko) ==== @@ -71,7 +71,7 @@ struct record *rt_record; void *rt_parent; TAILQ_ENTRY(record_type) rt_next; - int rt_type; + uint16_t rt_type; int rt_flags; size_t rt_refcnt; TAILQ_HEAD(record_res_head, record_res) rt_list; @@ -111,7 +111,9 @@ int record_res_add(struct record *, struct record_res **, int, uint16_t, void *, size_t); void record_res_del(struct record_res *); -struct record_res * record_res_find(struct records *, char *, uint16_t); +struct record_res * record_res_find(struct records *, char *, uint16_t, + char *, size_t); +struct record_type * record_type_find(struct records *, char *, uint16_t); void record_res_setdata(struct record_res *, void *, size_t); typedef void (*record_foreach)(struct record *, void *); @@ -132,4 +134,13 @@ #define record_res_setparent(x, y) __getparent(x, rr_parent) = y #define record_res_getparent(x) __getparent(x, rr_parent) +#define record_type_foreach(rr, rt) \ + TAILQ_FOREACH(rr, &((rt)->rt_list), rr_next) +#define record_type_first(rt) TAILQ_FIRST(&(rt)->rt_list) +#define record_type_next(rr) TAILQ_NEXT((rr), rr_next) +#define record_foreach(rt, r) \ + TAILQ_FOREACH(rt, &((r)->r_list), rt_next) +#define record_first(r) TAILQ_FIRST(&(r)->r_list) +#define record_next(r) TAILQ_NEXT((r), rt_next) + #endif /* _RECORD_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707160126.l6G1QHsf090847>