2 * Copyright (C) 2011-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #define _(String) gettext(String)
26 #include <json/json.h>
38 QUERY_GET_PUBLISHED_BINARIES = "?ws.op=getPublishedBinaries&ws.size=150";
39 static const char *QUERY_GET_DOWNLOAD_COUNT = "?ws.op=getDownloadCount";
41 QUERY_GET_DAILY_DOWNLOAD_TOTALS = "?ws.op=getDailyDownloadTotals";
43 static json_object *get_json_object(const char *url)
45 json_object *obj = NULL;
48 body = get_url_content(url, 0);
51 obj = json_tokener_parse(body);
61 #define json_object_to_bpph_list \
62 json_object_to_binary_package_publishing_history_list
64 struct binary_package_publishing_history * *
65 get_binary_package_publishing_history_list(const char *archive_url,
66 const char *pkg_status)
68 struct json_object *o_next;
73 url = malloc(strlen(archive_url)+
74 strlen(QUERY_GET_PUBLISHED_BINARIES)+
75 (pkg_status ? strlen("&status=")+strlen(pkg_status) : 0)+
78 strcpy(url, archive_url);
79 strcat(url, QUERY_GET_PUBLISHED_BINARIES);
82 strcat(url, "&status=");
83 strcat(url, pkg_status);
87 o = get_json_object(url);
94 result = list_append_list(result,
95 (void **)json_object_to_bpph_list(o));
97 o_next = json_object_object_get(o, "next_collection_link");
100 url = strdup(json_object_get_string(o_next));
105 return (struct binary_package_publishing_history **)result;
108 int get_download_count(const char *archive_url)
110 int n = strlen(archive_url) + strlen(QUERY_GET_DOWNLOAD_COUNT) + 1;
111 char *url = malloc(n);
115 strcpy(url, archive_url);
116 strcat(url, QUERY_GET_DOWNLOAD_COUNT);
118 obj = get_json_object(url);
124 result = json_object_get_int(obj);
126 json_object_put(obj);
131 const struct distro_arch_series *get_distro_arch_series(const char *url)
134 const struct distro_arch_series *distro;
137 distro = cache_get(url);
139 return (struct distro_arch_series *)distro;
141 content = get_url_content(url, 1);
146 obj = json_tokener_parse(content);
153 distro = json_object_to_distro_arch_series(obj);
155 json_object_put(obj);
157 cache_put(url, distro, (void (*)(void *))&distro_arch_series_free);
162 const struct distro_series *get_distro_series(const char *url)
165 const struct distro_series *distro;
168 distro = cache_get(url);
170 return (struct distro_series *)distro;
172 content = get_url_content(url, 1);
177 obj = json_tokener_parse(content);
184 distro = json_object_to_distro_series(obj);
186 json_object_put(obj);
188 cache_put(url, distro, (void (*)(void *))&distro_series_free);
193 struct daily_download_total **get_daily_download_totals(const char *binary_url)
197 struct daily_download_total **result = NULL;
199 url = malloc(strlen(binary_url)+
200 strlen(QUERY_GET_DAILY_DOWNLOAD_TOTALS)+1);
202 strcpy(url, binary_url);
203 strcat(url, QUERY_GET_DAILY_DOWNLOAD_TOTALS);
205 obj = get_json_object(url);
208 result = json_object_to_daily_download_totals(obj);
209 json_object_put(obj);