use file cache for distros, refactoring http fcts
[ppastats.git] / src / fcache.c
index 89c66d4..1a4623c 100644 (file)
@@ -59,12 +59,15 @@ static char *key_to_path(const char *key)
        char *path;
        const char *dir;
 
+       if (!key || !*key || *key != '/')
+               return NULL;
+
        dir = get_cache_dir();
        if (!dir)
                return NULL;
 
-       path = malloc(strlen(dir) + 1 + strlen(key) + strlen("/data.json") + 1);
-       sprintf(path, "%s%s/data.json", dir, key);
+       path = malloc(strlen(dir) + 1 + strlen(key) + strlen("/data") + 1);
+       sprintf(path, "%s%s/data", dir, key);
 
        return path;
 }
@@ -74,8 +77,10 @@ char *fcache_get(const char *key)
        char *path, *content;
 
        path = key_to_path(key);
-       if (!path)
+       if (!path) {
+               log_err(_("file cache, invalid key: %s"), key);
                return NULL;
+       }
 
        content = file_get_content(path);