From: Jean-Philippe Orsini Date: Tue, 17 May 2011 22:27:20 +0000 (+0000) Subject: added support of next_collection for bpph X-Git-Tag: v1.3.0~166 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=ppastats.git;a=commitdiff_plain;h=9412dc53bab346c119e4d1502e65cd7c68487d30 added support of next_collection for bpph --- diff --git a/src/lp_ws.c b/src/lp_ws.c index 09e9ede..2370d36 100644 --- a/src/lp_ws.c +++ b/src/lp_ws.c @@ -24,6 +24,7 @@ #include #include "cache.h" +#include "list.h" #include "lp_ws.h" #include "lp_json.h" #include "ppastats.h" @@ -115,38 +116,72 @@ static json_object *get_json_object(const char *url) return NULL; } +static void **list_add_list(void **list1, void **list2) +{ + int n1, n2, n; + void **list; + + n1 = list_length(list1); + n2 = list_length(list2); + + n = n1 + n2 + 1; + + list = malloc(sizeof(void *)*(n+1)); + + memcpy(list, list1, n1*sizeof(void *)); + memcpy(list+n1, list2, n2*sizeof(void *)); + + list[n1+n2] = NULL; + + free(list1); + + return list; +} + +#define json_object_to_bpph_list \ +json_object_to_binary_package_publishing_history_list + struct binary_package_publishing_history * * get_binary_package_publishing_history_list(const char *archive_url, const char *package_status) { + struct json_object *o_next; char *url = malloc(strlen(archive_url)+ strlen(QUERY_GET_PUBLISHED_BINARIES)+ strlen("&status=")+ 9+ 1); json_object *o; - struct binary_package_publishing_history **result; + void **result = NULL; strcpy(url, archive_url); strcat(url, QUERY_GET_PUBLISHED_BINARIES); - if (package_status) { strcat(url, "&status="); strcat(url, package_status); } - o = get_json_object(url); - free(url); + while (url) { + o = get_json_object(url); + free(url); + url = NULL; - if (!o) - return NULL; + if (!o) + break; - result = json_object_to_binary_package_publishing_history_list(o); + result = list_add_list(result, + (void **)json_object_to_bpph_list(o)); - json_object_put(o); + o_next = json_object_object_get(o, "next_collection_link"); - return result; + if (o_next) + url = strdup(json_object_get_string(o_next)); + + json_object_put(o); + } + + return (struct binary_package_publishing_history **)result; } int get_download_count(const char *archive_url)