diff options
Diffstat (limited to 'source3/utils/net_cache.c')
-rw-r--r-- | source3/utils/net_cache.c | 56 |
1 files changed, 18 insertions, 38 deletions
diff --git a/source3/utils/net_cache.c b/source3/utils/net_cache.c index 93c4f1aa1d..359c06d1aa 100644 --- a/source3/utils/net_cache.c +++ b/source3/utils/net_cache.c @@ -34,34 +34,15 @@ * (print_cache_entry) and to flush it (delete_cache_entry). * Both of them are defined by first arg of gencache_iterate() routine. */ -static void print_cache_entry(const char* keystr, const char* datastr, - const time_t timeout, void* dptr) +static void print_cache_entry(const char* keystr, const char* datastr, const time_t timeout) { - char* timeout_str; - time_t now_t = time(NULL); - struct tm timeout_tm, *now_tm; - /* localtime returns statically allocated pointer, so timeout_tm - has to be copied somewhere else */ - memcpy(&timeout_tm, localtime(&timeout), sizeof(struct tm)); - now_tm = localtime(&now_t); - - /* form up timeout string depending whether it's today's date or not */ - if (timeout_tm.tm_year != now_tm->tm_year || - timeout_tm.tm_mon != now_tm->tm_mon || - timeout_tm.tm_mday != now_tm->tm_mday) { - - timeout_str = asctime(&timeout_tm); - timeout_str[strlen(timeout_str) - 1] = '\0'; /* remove tailing CR */ - } else - asprintf(&timeout_str, "%.2d:%.2d:%.2d", timeout_tm.tm_hour, - timeout_tm.tm_min, timeout_tm.tm_sec); - - d_printf("Key: %s\t Timeout: %s\t Value: %s %s\n", keystr, - timeout_str, datastr, timeout > now_t ? "": "(expired)"); + char* timeout_str = ctime(&timeout); + timeout_str[strlen(timeout_str) - 1] = '\0'; + d_printf("Key: %s\t\t Value: %s\t\t Timeout: %s %s\n", keystr, datastr, + timeout_str, timeout > time(NULL) ? "": "(expired)"); } -static void delete_cache_entry(const char* keystr, const char* datastr, - const time_t timeout, void* dptr) +static void delete_cache_entry(const char* keystr, const char* datastr, const time_t timeout) { if (!gencache_del(keystr)) d_printf("Couldn't delete entry! key = %s", keystr); @@ -125,7 +106,7 @@ static time_t parse_timeout(const char* timeout_str) /** - * Add an entry to the cache. If it does exist, then set it. + * Add an entry to the cache * * @param argv key, value and timeout are passed in command line * @return 0 on success, otherwise failure @@ -151,12 +132,12 @@ static int net_cache_add(int argc, const char **argv) return -1; } - if (gencache_set(keystr, datastr, timeout)) { + if (gencache_add(keystr, datastr, timeout)) { d_printf("New cache entry stored successfully.\n"); gencache_shutdown(); return 0; - } - + } + d_printf("Entry couldn't be added. Perhaps there's already such a key.\n"); gencache_shutdown(); return -1; @@ -164,8 +145,7 @@ static int net_cache_add(int argc, const char **argv) /** - * Set new value of an existing entry in the cache. Fail If the entry doesn't - * exist. + * Set new value of an existing entry in the cache * * @param argv key being searched and new value and timeout to set in the entry * @return 0 on success, otherwise failure @@ -191,7 +171,7 @@ static int net_cache_set(int argc, const char **argv) return -1; } - if (gencache_set_only(keystr, datastr, timeout)) { + if (gencache_set(keystr, datastr, timeout)) { d_printf("Cache entry set successfully.\n"); gencache_shutdown(); return 0; @@ -221,7 +201,7 @@ static int net_cache_del(int argc, const char **argv) if(gencache_del(keystr)) { d_printf("Entry deleted.\n"); return 0; - } + } d_printf("Couldn't delete specified entry\n"); return -1; @@ -246,9 +226,9 @@ static int net_cache_get(int argc, const char **argv) } if (gencache_get(keystr, &valuestr, &timeout)) { - print_cache_entry(keystr, valuestr, timeout, NULL); + print_cache_entry(keystr, valuestr, timeout); return 0; - } + } d_printf("Failed to find entry\n"); return -1; @@ -271,7 +251,7 @@ static int net_cache_search(int argc, const char **argv) } pattern = argv[0]; - gencache_iterate(print_cache_entry, NULL, pattern); + gencache_iterate(print_cache_entry, pattern); return 0; } @@ -285,7 +265,7 @@ static int net_cache_search(int argc, const char **argv) static int net_cache_list(int argc, const char **argv) { const char* pattern = "*"; - gencache_iterate(print_cache_entry, NULL, pattern); + gencache_iterate(print_cache_entry, pattern); gencache_shutdown(); return 0; } @@ -300,7 +280,7 @@ static int net_cache_list(int argc, const char **argv) static int net_cache_flush(int argc, const char **argv) { const char* pattern = "*"; - gencache_iterate(delete_cache_entry, NULL, pattern); + gencache_iterate(delete_cache_entry, pattern); gencache_shutdown(); return 0; } |