typedef struct cacheduser {
unsigned long uid; /* for future use */
uuidtype_t type;
- uuidp_t uuid;
+ unsigned char *uuid;
char *name;
time_t creationtime;
struct cacheduser *prev;
int add_cachebyname( const char *inname, const uuidp_t inuuid, const uuidtype_t type, const unsigned long uid _U_) {
int ret = 0;
char *name = NULL;
- uuidp_t uuid;
+ unsigned char *uuid = NULL;
cacheduser_t *cacheduser = NULL;
- cacheduser_t *entry;
unsigned char hash;
#ifdef DEBUG
/* get hash */
hash = hashstring((unsigned char *)name);
- /* insert cache entry into cache array */
- if (namecache[hash] == NULL) { /* this queue is empty */
+ /* insert cache entry into cache array at head of queue */
+ if (namecache[hash] == NULL) {
+ /* this queue is empty */
+ namecache[hash] = cacheduser;
+ } else {
+ cacheduser->next = namecache[hash];
+ namecache[hash]->prev = cacheduser;
namecache[hash] = cacheduser;
- } else { /* queue is not empty, search end of queue*/
- entry = namecache[hash];
- while( entry->next != NULL)
- entry = entry->next;
- cacheduser->prev = entry;
- entry->next = cacheduser;
}
cleanup:
/*
* Caller provides buffer uuid for result
*/
-int search_cachebyname( const char *name, uuidtype_t type, uuidp_t uuid) {
+int search_cachebyname( const char *name, uuidtype_t type, unsigned char *uuid) {
int ret;
unsigned char hash;
cacheduser_t *entry;
hash = hashstring((unsigned char *)name);
- if (! namecache[hash])
+ if (namecache[hash] == NULL)
return -1;
entry = namecache[hash];
if ((tim - entry->creationtime) > CACHESECONDS) {
LOG(log_debug, logtype_default, "search_cachebyname: expired: name:\'%s\' in queue {%d}", entry->name, hash);
/* remove item */
- if (entry->prev) /* 2nd to last in queue */
+ if (entry->prev) {
+ /* 2nd to last in queue */
entry->prev->next = entry->next;
- else { /* queue head */
+ if (entry->next)
+ /* not the last element */
+ entry->next->prev = entry->prev;
+ } else {
+ /* queue head */
if ((namecache[hash] = entry->next) != NULL)
namecache[hash]->prev = NULL;
}
tim = time(NULL);
if ((tim - entry->creationtime) > CACHESECONDS) {
LOG(log_debug, logtype_default, "search_cachebyuuid: expired: name:\'%s\' in queue {%d}", entry->name, hash);
- if (entry->prev) /* 2nd to last in queue */
+ if (entry->prev) {
+ /* 2nd to last in queue */
entry->prev->next = entry->next;
- else { /* queue head */
+ if (entry->next)
+ /* not the last element */
+ entry->next->prev = entry->prev;
+ } else {
+ /* queue head */
if ((uuidcache[hash] = entry->next) != NULL)
uuidcache[hash]->prev = NULL;
}
int add_cachebyuuid( uuidp_t inuuid, const char *inname, uuidtype_t type, const unsigned long uid _U_) {
int ret = 0;
char *name = NULL;
- uuidp_t uuid;
+ unsigned char *uuid = NULL;
cacheduser_t *cacheduser = NULL;
cacheduser_t *entry;
unsigned char hash;
/* get hash */
hash = hashuuid(uuid);
- /* insert cache entry into cache array */
- if (uuidcache[hash] == NULL) { /* this queue is empty */
+ /* insert cache entry into cache array at head of queue */
+ if (uuidcache[hash] == NULL) {
+ /* this queue is empty */
+ uuidcache[hash] = cacheduser;
+ } else {
+ cacheduser->next = uuidcache[hash];
+ uuidcache[hash]->prev = cacheduser;
uuidcache[hash] = cacheduser;
- } else { /* queue is not empty, search end of queue*/
- entry = uuidcache[hash];
- while( entry->next != NULL)
- entry = entry->next;
- cacheduser->prev = entry;
- entry->next = cacheduser;
}
cleanup: