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
31 static struct bpph *json_to_bpph(json_object *o)
33 const char *binary_package_name;
34 const char *binary_package_version;
35 const char *distro_arch_series_link;
36 const char *self_link;
37 int architecture_specific;
38 const char *date_created;
41 binary_package_name = json_object_get_string
42 (json_object_object_get(o, "binary_package_name"));
44 binary_package_version = json_object_get_string
45 (json_object_object_get(o, "binary_package_version"));
47 distro_arch_series_link = json_object_get_string
48 (json_object_object_get(o, "distro_arch_series_link"));
50 self_link = json_object_get_string
51 (json_object_object_get(o, "self_link"));
53 if (json_object_get_boolean
54 (json_object_object_get(o, "architecture_specific")))
55 architecture_specific = 1;
57 architecture_specific = 0;
59 bpph = bpph_new(binary_package_name,
60 binary_package_version,
61 distro_arch_series_link,
63 architecture_specific);
65 date_created = json_object_get_string
66 (json_object_object_get(o, "date_created"));
68 bpph->date_created.tm_isdst = -1;
69 strptime(date_created, "%FT%T%z", &bpph->date_created);
75 static json_object *bpph_to_json(struct bpph *bpph)
80 json = json_object_new_object();
82 json_object_object_add
84 "binary_package_name",
85 json_object_new_string(bpph->binary_package_name));
87 json_object_object_add
89 "binary_package_version",
90 json_object_new_string(bpph->binary_package_version));
92 json_object_object_add
94 "distro_arch_series_link",
95 json_object_new_string(bpph->distro_arch_series_link));
97 json_object_object_add
99 "architecture_specific",
100 json_object_new_boolean(bpph->architecture_specific));
102 date = malloc(strlen("YY-MM-DDThh:mm:ss+xxx") + 1);
104 strlen("YY-MM-DDThh:mm:ss+xxx") + 1,
106 &bpph->date_created);
108 json_object_object_add
111 json_object_new_string(date));
118 struct distro_arch_series *json_object_to_distro_arch_series(json_object *o)
120 const char *display_name;
122 const char *architecture_tag;
123 boolean is_nominated_arch_indep;
124 const char *distroseries_link;
126 display_name = json_object_get_string
127 (json_object_object_get(o, "display_name"));
129 title = json_object_get_string
130 (json_object_object_get(o, "title"));
132 architecture_tag = json_object_get_string
133 (json_object_object_get(o, "architecture_tag"));
135 distroseries_link = json_object_get_string
136 (json_object_object_get(o, "distroseries_link"));
138 is_nominated_arch_indep = json_object_get_boolean
139 (json_object_object_get(o, "is_nominated_arch_indep"));
141 return distro_arch_series_new(display_name,
144 is_nominated_arch_indep,
148 struct distro_series *json_object_to_distro_series(json_object *o)
150 const char *displayname;
155 displayname = json_object_get_string
156 (json_object_object_get(o, "displayname"));
158 title = json_object_get_string
159 (json_object_object_get(o, "title"));
161 version = json_object_get_string
162 (json_object_object_get(o, "version"));
164 name = json_object_get_string
165 (json_object_object_get(o, "name"));
167 return distro_series_new(name,
173 struct bpph **json_object_to_bpph_list(json_object *o)
175 json_object *o_entries;
177 struct bpph **entries, *h;
178 const struct distro_arch_series *distro;
180 o_entries = json_object_object_get(o, "entries");
185 n = json_object_array_length(o_entries);
188 (sizeof(struct bpph *)*(n+1));
190 for (i = 0, i2 = 0; i < n; i++) {
191 h = json_to_bpph(json_object_array_get_idx(o_entries,
194 if (!h->architecture_specific) {
195 distro = get_distro_arch_series
196 (h->distro_arch_series_link);
198 if (!distro || !distro->is_nominated_arch_indep) {
212 json_object *bpph_list_to_json(struct bpph **list)
214 json_object *result, *entries;
217 result = json_object_new_object();
219 entries = json_object_new_array();
220 json_object_object_add(result, "entries", entries);
222 for (cur = list; *cur; cur++)
223 json_object_array_add(entries, bpph_to_json(*cur));
228 struct daily_download_total *
229 json_object_to_daily_download_total(const char *d, json_object *o_c)
231 struct daily_download_total *result;
233 result = malloc(sizeof(struct daily_download_total));
234 result->count = json_object_get_int(o_c);
236 strptime(d, "%FT%T%z", &result->date);
241 static int json_object_get_fields_count(json_object *o)
244 struct lh_entry *entry;
246 entry = json_object_get_object(o)->head;
255 struct daily_download_total * *
256 json_object_to_daily_download_totals(json_object *o)
259 struct daily_download_total **result;
261 n = json_object_get_fields_count(o);
264 (sizeof(struct daily_download_total *)*(n+1));
267 json_object_object_foreach(o, key, val) {
268 result[i] = json_object_to_daily_download_total(key, val);