s3: Remove some unnecessary variables from libsmb/conn_cache.c
[ira/wip.git] / source3 / libsmb / conncache.c
index 05344f4071d344f3ba06829efc6478d7732024dd..c4c53d068100942e6def75ed67ce607a16e12842 100644 (file)
@@ -7,7 +7,8 @@
    Copyright (C) Andrew Bartlett       2002
    Copyright (C) Gerald (Jerry) Carter         2003
    Copyright (C) Marc VanHeyningen      2008
-   
+   Copyright (C) Volker Lendecke       2009
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
  */
 
 
-/**
- * prefix used for all entries put into the general cache
- */
-static const char NEGATIVE_CONN_CACHE_PREFIX[] = "NEG_CONN_CACHE";
-
 /**
  * Marshalls the domain and server name into the key for the gencache
  * record
@@ -53,15 +49,16 @@ static const char NEGATIVE_CONN_CACHE_PREFIX[] = "NEG_CONN_CACHE";
  */
 static char *negative_conn_cache_keystr(const char *domain, const char *server)
 {
-       const char NEGATIVE_CONN_CACHE_KEY_FMT[] = "%s/%s,%s";
        char *keystr = NULL;
 
-       SMB_ASSERT(domain != NULL);
+       if (domain == NULL) {
+               return NULL;
+       }
        if (server == NULL)
                server = "";
 
-       keystr = talloc_asprintf(talloc_tos(),NEGATIVE_CONN_CACHE_KEY_FMT,
-                                NEGATIVE_CONN_CACHE_PREFIX, domain, server);
+       keystr = talloc_asprintf(talloc_tos(), "NEG_CONN_CACHE/%s,%s",
+                                domain, server);
        if (keystr == NULL) {
                DEBUG(0, ("negative_conn_cache_keystr: malloc error\n"));
        }
@@ -100,13 +97,16 @@ static char *negative_conn_cache_valuestr(NTSTATUS status)
  */
 static NTSTATUS negative_conn_cache_valuedecode(const char *value)
 {
-       NTSTATUS result = NT_STATUS_OK;
+       unsigned int v = NT_STATUS_V(NT_STATUS_INTERNAL_ERROR);;
 
-       SMB_ASSERT(value != NULL);
-       if (sscanf(value, "%x", &(NT_STATUS_V(result))) != 1)
-               DEBUG(0, ("negative_conn_cache_valuestr: unable to parse "
+       if (value != NULL) {
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+       if (sscanf(value, "%x", &v) != 1) {
+               DEBUG(0, ("negative_conn_cache_valuedecode: unable to parse "
                          "value field '%s'\n", value));
-       return result;
+       }
+       return NT_STATUS(v);
 }
 
 /**
@@ -143,7 +143,7 @@ NTSTATUS check_negative_conn_cache( const char *domain, const char *server)
        if (key == NULL)
                goto done;
 
-       if (gencache_get(key, &value, (time_t *) NULL))
+       if (gencache_get(key, &value, NULL))
                result = negative_conn_cache_valuedecode(value);
  done:
        DEBUG(9,("check_negative_conn_cache returning result %d for domain %s "
@@ -177,7 +177,7 @@ void delete_negative_conn_cache(const char *domain, const char *server)
 
 
 /**
- * Add an entry to the failed conneciton cache
+ * Add an entry to the failed connection cache
  *
  * @param[in] domain
  * @param[in] server may be a FQDN or an IP addr in printable form
@@ -189,7 +189,10 @@ void add_failed_connection_entry(const char *domain, const char *server,
        char *key = NULL;
        char *value = NULL;
 
-       SMB_ASSERT(!NT_STATUS_IS_OK(result));
+       if (NT_STATUS_IS_OK(result)) {
+               /* Nothing failed here */
+               return;
+       }
 
        key = negative_conn_cache_keystr(domain, server);
        if (key == NULL) {
@@ -204,8 +207,7 @@ void add_failed_connection_entry(const char *domain, const char *server,
        }
 
        if (gencache_set(key, value,
-                        time((time_t *) NULL)
-                        + FAILED_CONNECTION_CACHE_TIMEOUT))
+                        time(NULL) + FAILED_CONNECTION_CACHE_TIMEOUT))
                DEBUG(9,("add_failed_connection_entry: added domain %s (%s) "
                          "to failed conn cache\n", domain, server ));
        else
@@ -246,10 +248,10 @@ void flush_negative_conn_cache_for_domain(const char *domain)
                goto done;
        }
 
-       gencache_iterate(delete_matches, (void *) NULL, key_pattern);
+       gencache_iterate(delete_matches, NULL, key_pattern);
        DEBUG(8, ("flush_negative_conn_cache_for_domain: flushed domain %s\n",
                  domain));
-       
+
  done:
        TALLOC_FREE(key_pattern);
        return;