projects
/
ppastats.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
next release will be 1.3.3
[ppastats.git]
/
src
/
fcache.c
diff --git
a/src/fcache.c
b/src/fcache.c
index
89c66d4
..
35e4512
100644
(file)
--- a/
src/fcache.c
+++ b/
src/fcache.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2011-201
2
jeanfi@gmail.com
+ * Copyright (C) 2011-201
4
jeanfi@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-25,9
+25,9
@@
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
-#include
"fcache.h"
-#include
"io.h"
-#include
"log.h"
+#include
<fcache.h>
+#include
<plog.h>
+#include
<pio.h>
static const char *cache_dir;
static const char *cache_dir;
@@
-59,12
+59,15
@@
static char *key_to_path(const char *key)
char *path;
const char *dir;
char *path;
const char *dir;
+ if (!key || !*key || *key != '/')
+ return NULL;
+
dir = get_cache_dir();
if (!dir)
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;
}
return path;
}
@@
-74,22
+77,24
@@
char *fcache_get(const char *key)
char *path, *content;
path = key_to_path(key);
char *path, *content;
path = key_to_path(key);
- if (!path)
+ if (!path) {
+ log_err(_("file cache, invalid key: %s"), key);
return NULL;
return NULL;
+ }
content = file_get_content(path);
content = file_get_content(path);
-
+
if (content)
log_debug(_("file cache hit %s"), key);
else
log_debug(_("file cache miss %s %s"), key, path);
if (content)
log_debug(_("file cache hit %s"), key);
else
log_debug(_("file cache miss %s %s"), key, path);
-
+
free(path);
free(path);
-
+
return content;
}
return content;
}
-
-void fcache_put(const char *key, char *value)
+
+void fcache_put(const char *key, c
onst c
har *value)
{
char *path, *dir, *tmp;
FILE *f;
{
char *path, *dir, *tmp;
FILE *f;