save bpph list into file cache
[ppastats.git] / src / lp_ws.c
index 2044371..a813b33 100644 (file)
@@ -20,6 +20,7 @@
 #include <libintl.h>
 #define _(String) gettext(String)
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -60,10 +61,9 @@ static json_object *get_json_object(const char *url)
 
 struct bpph **get_bpph_list(const char *archive_url, const char *pkg_status)
 {
-       struct json_object *o_next;
-       char *url;
-       json_object *o;
-       void **result = NULL;
+       char *url, *bpph_key;
+       struct bpph **result = NULL;
+       struct json_object *o, *bpph_json, *o_next;
 
        url = malloc(strlen(archive_url)+
                     strlen(QUERY_GET_PUBLISHED_BINARIES)+
@@ -86,8 +86,9 @@ struct bpph **get_bpph_list(const char *archive_url, const char *pkg_status)
                if (!o)
                        break;
 
-               result = list_append_list(result,
-                                         (void **)json_object_to_bpph_list(o));
+               result = (struct bpph **)list_append_list
+                       ((void **)result,
+                        (void **)json_object_to_bpph_list(o));
 
                o_next = json_object_object_get(o, "next_collection_link");
 
@@ -97,7 +98,16 @@ struct bpph **get_bpph_list(const char *archive_url, const char *pkg_status)
                json_object_put(o);
        }
 
-       return (struct bpph **)result;
+       bpph_json = bpph_list_to_json(result);
+
+       bpph_key = malloc(strlen(archive_url + 7) + strlen("/bpph") + 1);
+       sprintf(bpph_key, "%s/bpph", archive_url + 7);
+       fcache_put(bpph_key, json_object_to_json_string(bpph_json));
+
+       json_object_put(bpph_json);
+       free(bpph_key);
+
+       return result;
 }
 
 int get_download_count(const char *archive_url)