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 struct bpph **get_bpph_list(const char *archive_url, const char *pkg_status)
63 struct json_object *o_next;
68 url = malloc(strlen(archive_url)+
69 strlen(QUERY_GET_PUBLISHED_BINARIES)+
70 (pkg_status ? strlen("&status=")+strlen(pkg_status) : 0)+
73 strcpy(url, archive_url);
74 strcat(url, QUERY_GET_PUBLISHED_BINARIES);
77 strcat(url, "&status=");
78 strcat(url, pkg_status);
82 o = get_json_object(url);
89 result = list_append_list(result,
90 (void **)json_object_to_bpph_list(o));
92 o_next = json_object_object_get(o, "next_collection_link");
95 url = strdup(json_object_get_string(o_next));
100 return (struct bpph **)result;
103 int get_download_count(const char *archive_url)
105 int n = strlen(archive_url) + strlen(QUERY_GET_DOWNLOAD_COUNT) + 1;
106 char *url = malloc(n);
110 strcpy(url, archive_url);
111 strcat(url, QUERY_GET_DOWNLOAD_COUNT);
113 obj = get_json_object(url);
119 result = json_object_get_int(obj);
121 json_object_put(obj);
126 const struct distro_arch_series *get_distro_arch_series(const char *url)
129 const struct distro_arch_series *distro;
132 distro = cache_get(url);
134 return (struct distro_arch_series *)distro;
136 content = get_url_content(url, 1);
141 obj = json_tokener_parse(content);
148 distro = json_object_to_distro_arch_series(obj);
150 json_object_put(obj);
152 cache_put(url, distro, (void (*)(void *))&distro_arch_series_free);
157 const struct distro_series *get_distro_series(const char *url)
160 const struct distro_series *distro;
163 distro = cache_get(url);
165 return (struct distro_series *)distro;
167 content = get_url_content(url, 1);
172 obj = json_tokener_parse(content);
179 distro = json_object_to_distro_series(obj);
181 json_object_put(obj);
183 cache_put(url, distro, (void (*)(void *))&distro_series_free);
188 struct daily_download_total **get_daily_download_totals(const char *binary_url)
192 struct daily_download_total **result = NULL;
194 url = malloc(strlen(binary_url)+
195 strlen(QUERY_GET_DAILY_DOWNLOAD_TOTALS)+1);
197 strcpy(url, binary_url);
198 strcat(url, QUERY_GET_DAILY_DOWNLOAD_TOTALS);
200 obj = get_json_object(url);
203 result = json_object_to_daily_download_totals(obj);
204 json_object_put(obj);