]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/acl/cache.c
Merge from branch-2-1
[netatalk.git] / libatalk / acl / cache.c
index 0d60d9857169f011f230a7514d53acb53f1e58e7..4c640ac25ff425a0e27724e804749fd93ceed916 100644 (file)
@@ -1,5 +1,4 @@
 /*
-  $Id: cache.c,v 1.5 2010-04-23 10:31:40 franklahm Exp $
   Copyright (c) 2008,2009 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
@@ -49,22 +48,19 @@ static int dumpcache() {
     int i;
     int ret = 0;
     cacheduser_t *entry;
-    char *uuidstring = NULL;
     char timestr[200];
     struct tm *tmp = NULL;
 
     for ( i=0 ; i<256; i++) {
         if ((entry = namecache[i]) != NULL) {
             do {
-                uuid_bin2string(entry->uuid, &uuidstring);
                 tmp = localtime(&entry->creationtime);
                 if (tmp == NULL)
                     continue;
                 if (strftime(timestr, 200, "%c", tmp) == 0)
                     continue;
                 LOG(log_debug9, logtype_default, "namecache{%d}: name:%s, uuid:%s, type: %s, cached: %s",
-                    i, entry->name, uuidstring, uuidtype[entry->type], timestr);
-                free(uuidstring);
+                    i, entry->name, uuid_bin2string(entry->uuid), uuidtype[entry->type], timestr);
             } while ((entry = entry->next) != NULL);
         }
     }
@@ -72,15 +68,14 @@ static int dumpcache() {
     for ( i=0; i<256; i++) {
         if ((entry = uuidcache[i]) != NULL) {
             do {
-                uuid_bin2string(entry->uuid, &uuidstring);
+
                 tmp = localtime(&entry->creationtime);
                 if (tmp == NULL)
                     continue;
                 if (strftime(timestr, 200, "%c", tmp) == 0)
                     continue;
                 LOG(log_debug9, logtype_default, "uuidcache{%d}: uuid:%s, name:%s, type: %s, cached: %s",
-                    i, uuidstring, entry->name, uuidtype[entry->type], timestr);
-                free(uuidstring);
+                    i, uuid_bin2string(entry->uuid), entry->name, uuidtype[entry->type], timestr);
             } while ((entry = entry->next) != NULL);
         }
     }
@@ -103,7 +98,7 @@ static unsigned char hashstring(unsigned char *str) {
     return index;
 }
 
-/* hash uuid_t into unsigned char */
+/* hash atalk_uuid_t into unsigned char */
 static unsigned char hashuuid(uuidp_t uuid) {
     unsigned char index = 83;
     int i;
@@ -195,6 +190,9 @@ cleanup:
     return ret;
 }
 
+/* 
+ * Caller provides buffer uuid for result
+ */
 int search_cachebyname( const char *name, uuidtype_t type, uuidp_t uuid) {
     int ret;
     unsigned char hash;
@@ -221,8 +219,10 @@ int search_cachebyname( const char *name, uuidtype_t type, uuidp_t uuid) {
                 /* remove item */
                 if (entry->prev) /* 2nd to last in queue */
                     entry->prev->next = entry->next;
-                else        /* queue head */
-                    namecache[hash] = entry->next;
+                else  { /* queue head */
+                    if ((namecache[hash] = entry->next) != NULL)
+                        namecache[hash]->prev = NULL;
+                }
                 free(entry->name);
                 free(entry->uuid);
                 free(entry);
@@ -246,6 +246,9 @@ int search_cachebyname( const char *name, uuidtype_t type, uuidp_t uuid) {
     return -1;
 }
 
+/* 
+ * Caller must free allocated name
+ */
 int search_cachebyuuid( uuidp_t uuidp, char **name, uuidtype_t *type) {
     int ret;
     unsigned char hash;
@@ -267,11 +270,13 @@ int search_cachebyuuid( uuidp_t uuidp, char **name, uuidtype_t *type) {
         if (ret == 0) {
             tim = time(NULL);
             if ((tim - entry->creationtime) > CACHESECONDS) {
-                LOG(log_info, logtype_default, "search_cachebyuuid: expired: name:\'%s\' in queue {%d}", entry->name, hash);
-                if (entry->prev)
+                LOG(log_debug, logtype_default, "search_cachebyuuid: expired: name:\'%s\' in queue {%d}", entry->name, hash);
+                if (entry->prev) /* 2nd to last in queue */
                     entry->prev->next = entry->next;
-                else
-                    uuidcache[hash] = entry->next;
+                else { /* queue head  */
+                    if ((uuidcache[hash] = entry->next) != NULL)
+                        uuidcache[hash]->prev = NULL;
+                }
                 free(entry->name);
                 free(entry->uuid);
                 free(entry);