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
30 struct bpph *json_object_to_bpph(json_object *o)
32 const char *binary_package_name;
33 const char *binary_package_version;
34 const char *distro_arch_series_link;
35 const char *self_link;
36 int architecture_specific;
38 binary_package_name = json_object_get_string
39 (json_object_object_get(o, "binary_package_name"));
41 binary_package_version = json_object_get_string
42 (json_object_object_get(o, "binary_package_version"));
44 distro_arch_series_link = json_object_get_string
45 (json_object_object_get(o, "distro_arch_series_link"));
47 self_link = json_object_get_string
48 (json_object_object_get(o, "self_link"));
50 if (json_object_get_boolean
51 (json_object_object_get(o, "architecture_specific")))
52 architecture_specific = 1;
54 architecture_specific = 0;
56 return bpph_new(binary_package_name,
57 binary_package_version,
58 distro_arch_series_link,
60 architecture_specific);
63 struct distro_arch_series *json_object_to_distro_arch_series(json_object *o)
65 const char *display_name;
67 const char *architecture_tag;
68 boolean is_nominated_arch_indep;
69 const char *distroseries_link;
72 display_name = json_object_get_string
73 (json_object_object_get(o, "display_name"));
75 title = json_object_get_string
76 (json_object_object_get(o, "title"));
78 architecture_tag = json_object_get_string
79 (json_object_object_get(o, "architecture_tag"));
81 distroseries_link = json_object_get_string
82 (json_object_object_get(o, "distroseries_link"));
84 is_nominated_arch_indep = json_object_get_boolean
85 (json_object_object_get(o, "is_nominated_arch_indep"));
87 return distro_arch_series_new(display_name,
90 is_nominated_arch_indep,
94 struct distro_series *json_object_to_distro_series(json_object *o)
96 const char *displayname;
101 displayname = json_object_get_string
102 (json_object_object_get(o, "displayname"));
104 title = json_object_get_string
105 (json_object_object_get(o, "title"));
107 version = json_object_get_string
108 (json_object_object_get(o, "version"));
110 name = json_object_get_string
111 (json_object_object_get(o, "name"));
113 return distro_series_new(name,
119 struct bpph **json_object_to_bpph_list(json_object *o)
121 json_object *o_entries;
123 struct bpph **entries, *h;
124 const struct distro_arch_series *distro;
126 o_entries = json_object_object_get(o, "entries");
131 n = json_object_array_length(o_entries);
134 (sizeof(struct bpph *)*(n+1));
136 for (i = 0, i2 = 0; i < n; i++) {
137 h = json_object_to_bpph(json_object_array_get_idx(o_entries,
140 if (!h->architecture_specific) {
141 distro = get_distro_arch_series
142 (h->distro_arch_series_link);
144 if (!distro || !distro->is_nominated_arch_indep) {
158 struct daily_download_total *
159 json_object_to_daily_download_total(const char *d, json_object *o_c)
161 struct daily_download_total *result;
163 result = malloc(sizeof(struct daily_download_total));
164 result->count = json_object_get_int(o_c);
166 strptime(d, "%FT%T%z", &result->date);
171 static int json_object_get_fields_count(json_object *o)
174 struct lh_entry *entry;
176 entry = json_object_get_object(o)->head;
185 struct daily_download_total * *
186 json_object_to_daily_download_totals(json_object *o)
189 struct daily_download_total **result;
191 n = json_object_get_fields_count(o);
194 (sizeof(struct daily_download_total *)*(n+1));
197 json_object_object_foreach(o, key, val) {
198 result[i] = json_object_to_daily_download_total(key, val);