idnode: just a few bits of tidying up

This commit is contained in:
Adam Sutton 2013-09-17 09:21:02 +01:00
parent 89e3c813df
commit 1deda4c52e
2 changed files with 21 additions and 13 deletions

View file

@ -88,7 +88,6 @@ hex2bin(uint8_t *buf, size_t buflen, const char *str)
return 0;
}
/**
*
*/
@ -111,7 +110,7 @@ bin2hex(char *dst, size_t dstlen, const uint8_t *src, size_t srclen)
static int
in_cmp(const idnode_t *a, const idnode_t *b)
{
return memcmp(a->in_uuid, b->in_uuid, 16);
return memcmp(a->in_uuid, b->in_uuid, sizeof(a->in_uuid));
}
/* **************************************************************************
@ -145,12 +144,12 @@ idnode_insert(idnode_t *in, const char *uuid, const idclass_t *class)
idnode_t *c;
lock_assert(&global_lock);
if(uuid == NULL) {
if(read(randfd, in->in_uuid, 16) != 16) {
if(read(randfd, in->in_uuid, sizeof(in->in_uuid)) != sizeof(in->in_uuid)) {
perror("read(random for uuid)");
exit(1);
}
} else {
if(hex2bin(in->in_uuid, 16, uuid))
if(hex2bin(in->in_uuid, sizeof(in->in_uuid), uuid))
return -1;
}
@ -217,14 +216,19 @@ idnode_get_short_uuid (const idnode_t *in)
*
*/
const char *
idnode_uuid_as_str0(const idnode_t *in, char *b)
{
bin2hex(b, UUID_STR_LEN, in->in_uuid, sizeof(in->in_uuid));
return b;
}
const char *
idnode_uuid_as_str(const idnode_t *in)
{
static char ret[16][33];
static int p;
static char ret[16][UUID_STR_LEN];
static int p = 0;
char *b = ret[p];
bin2hex(b, 33, in->in_uuid, 16);
p = (p + 1) & 15;
return b;
p = (p + 1) % 16;
return idnode_uuid_as_str0(in, b);
}
/**
@ -406,7 +410,7 @@ idnode_find(const char *uuid, const idclass_t *idc)
idnode_t skel, *r;
tvhtrace("idnode", "find node %s class %s", uuid, idc ? idc->ic_class : NULL);
if(hex2bin(skel.in_uuid, 16, uuid))
if(hex2bin(skel.in_uuid, sizeof(skel.in_uuid), uuid))
return NULL;
r = RB_FIND(&idnodes, &skel, in_link, in_cmp);
if(r != NULL && idc != NULL) {

View file

@ -25,6 +25,9 @@
#include <regex.h>
#define UUID_STR_LEN 33 // inc NUL char
#define UUID_BIN_LEN 16
struct htsmsg;
typedef struct idnode idnode_t;
@ -59,9 +62,9 @@ typedef struct idclass {
* Node definition
*/
struct idnode {
uint8_t in_uuid[16]; ///< Unique ID
RB_ENTRY(idnode) in_link; ///< Global hash
const idclass_t *in_class; ///< Class definition
uint8_t in_uuid[UUID_BIN_LEN]; ///< Unique ID
RB_ENTRY(idnode) in_link; ///< Global hash
const idclass_t *in_class; ///< Class definition
};
/*
@ -111,6 +114,7 @@ int idnode_insert(idnode_t *in, const char *uuid, const idclass_t *idc);
void idnode_unlink(idnode_t *in);
uint32_t idnode_get_short_uuid (const idnode_t *in);
const char *idnode_uuid_as_str0 (const idnode_t *in, char *b);
const char *idnode_uuid_as_str (const idnode_t *in);
idnode_set_t *idnode_get_childs (idnode_t *in);
const char *idnode_get_title (idnode_t *in);