+ t = mktime(&(ddt->date));
+
+ d = difftime(tv->tv_sec, t);
+
+ if (d > 4 * 7 * 24 * 60 * 60) { /* older than 4 weeks */
+ date = tm_to_ISO8601_date(&ddt->date);
+ json_object_object_add(j_ddts,
+ date,
+ json_object_new_int(ddt->count));
+ free(date);
+ }
+
+ ddts++;
+ }
+
+ free(tv);
+
+ return j_ddts;
+}
+
+char *create_ddts_query(const char *binary_url, time_t st)
+{
+ char *q;
+ char *sdate;
+
+ if (st) {
+ sdate = time_to_ISO8601_date(&st);
+
+ q = malloc(strlen(binary_url)
+ + strlen(QUERY_GET_DAILY_DOWNLOAD_TOTALS)
+ + strlen("&start_date=YYYY-MM-DD")
+ + 1);
+ strcpy(q, binary_url);
+ strcat(q, QUERY_GET_DAILY_DOWNLOAD_TOTALS);
+ strcat(q, "&start_date=");
+ strcat(q, sdate);
+
+ free(sdate);
+ } else {
+ q = malloc(strlen(binary_url)
+ + strlen(QUERY_GET_DAILY_DOWNLOAD_TOTALS)
+ + 1);
+ strcpy(q, binary_url);
+ strcat(q, QUERY_GET_DAILY_DOWNLOAD_TOTALS);
+ }
+
+ return q;
+}
+
+struct daily_download_total **get_daily_download_totals(const char *binary_url)
+{
+ char *url, *key, *content;
+ json_object *j_ddts, *json;
+ struct daily_download_total **retrieved_ddts = NULL;
+ struct daily_download_total **cached_ddts;
+ struct daily_download_total **ddts;
+ time_t last_t;
+
+ key = get_ddts_list_cache_key(binary_url);
+
+ content = fcache_get(key);
+ if (content) {
+ json = json_tokener_parse(content);
+ free(content);
+ } else {
+ json = NULL;