#include "fcache.h"
#include "http.h"
#include "list.h"
-#include "log.h"
#include "lp_ws.h"
#include "lp_json.h"
+#include <plog.h>
#include "ppastats.h"
+#include <ptime.h>
/** Default ws.size value for the getPublishedBinaries request. */
static const int DEFAULT_WS_SIZE = 150;
}
if (last)
- return time_to_str(last);
+ return time_to_ISO8601_time(&last);
else
return NULL;
}
return distro;
}
-char *date_to_str(struct tm tm)
-{
- char *str;
-
- str = malloc(4 + 1 + 2 + 1 + 2 + 1);
-
- strftime(str, 11, "%Y-%m-%d", &tm);
-
- return str;
-}
-
/*
Convert ddts older than 4 weeks to the same JSON representation than
the LP one. Newer ddts are not stored in the cache because the data
d = difftime(tv->tv_sec, t);
if (d > 4 * 7 * 24 * 60 * 60) { /* older than 4 weeks */
- date = date_to_str(ddt->date);
+ date = tm_to_ISO8601_date(&ddt->date);
json_object_object_add(j_ddts,
date,
json_object_new_int(ddt->count));
return j_ddts;
}
-static char *time_t_to_str(time_t t)
-{
- struct tm *tm;
- char *str;
-
- tm = gmtime(&t);
-
- str = date_to_str(*tm);
-
- return str;
-}
-
char *create_ddts_query(const char *binary_url, time_t st)
{
char *q;
char *sdate;
if (st) {
- sdate = time_t_to_str(st);
+ sdate = time_to_ISO8601_date(&st);
q = malloc(strlen(binary_url)
+ strlen(QUERY_GET_DAILY_DOWNLOAD_TOTALS)
key = get_ddts_list_cache_key(binary_url);
content = fcache_get(key);
- if (content)
+ if (content) {
json = json_tokener_parse(content);
- else
+ free(content);
+ } else {
json = NULL;
+ }
if (json) {
cached_ddts = json_object_to_daily_download_totals(json);
+ json_object_put(json);
last_t = ddts_get_last_date(cached_ddts);
} else {
last_t = 0;
}
free(key);
- free(cached_ddts);
- free(retrieved_ddts);
+ if (ddts != cached_ddts)
+ daily_download_total_list_free(cached_ddts);
+ daily_download_total_list_free(retrieved_ddts);
return ddts;
}