+ 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;
+ cached_ddts = NULL;
+ }
+
+ url = create_ddts_query(binary_url, last_t);
+
+ json = get_json_object(url);
+
+ free(url);
+
+ if (json) {
+ retrieved_ddts = json_object_to_daily_download_totals(json);
+
+ ddts = ddts_merge(cached_ddts, retrieved_ddts);
+
+ json_object_put(json);
+ j_ddts = ddts_to_json_for_cache(ddts);
+ fcache_put(key, json_object_get_string(j_ddts));
+ json_object_put(j_ddts);
+ } else {
+ ddts = NULL;
+ }
+
+ free(key);
+ if (ddts != cached_ddts)
+ daily_download_total_list_free(cached_ddts);
+ daily_download_total_list_free(retrieved_ddts);
+
+ return ddts;