+ free(tv);
+
+ 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);
+
+ 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);
+ else
+ json = NULL;
+
+ if (json) {
+ cached_ddts = json_object_to_daily_download_totals(json);
+ last_t = ddts_get_last_date(cached_ddts);
+ } else {
+ last_t = 0;
+ cached_ddts = NULL;
+ }
+
+ url = create_ddts_query(binary_url, last_t);
+
+ json = get_json_object(url);
+