2 Copyright (C) 2011 jeanfi@gmail.com
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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 binary_package_publishing_history *
31 json_object_to_binary_package_publishing_history(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;
39 binary_package_name = json_object_get_string
40 (json_object_object_get(o, "binary_package_name"));
42 binary_package_version = json_object_get_string
43 (json_object_object_get(o, "binary_package_version"));
45 distro_arch_series_link = json_object_get_string
46 (json_object_object_get(o, "distro_arch_series_link"));
48 self_link = json_object_get_string
49 (json_object_object_get(o, "self_link"));
51 if (json_object_get_boolean
52 (json_object_object_get(o, "architecture_specific")))
53 architecture_specific = 1;
55 architecture_specific = 0;
57 return binary_package_publishing_history_new(binary_package_name,
58 binary_package_version,
59 distro_arch_series_link,
61 architecture_specific);
64 struct distro_arch_series *json_object_to_distro_arch_series(json_object *o)
66 const char *display_name;
68 const char *architecture_tag;
69 boolean is_nominated_arch_indep;
70 const char *distroseries_link;
73 display_name = json_object_get_string
74 (json_object_object_get(o, "display_name"));
76 title = json_object_get_string
77 (json_object_object_get(o, "title"));
79 architecture_tag = json_object_get_string
80 (json_object_object_get(o, "architecture_tag"));
82 distroseries_link = json_object_get_string
83 (json_object_object_get(o, "distroseries_link"));
85 is_nominated_arch_indep = json_object_get_boolean
86 (json_object_object_get(o, "is_nominated_arch_indep"));
88 return distro_arch_series_new(display_name,
91 is_nominated_arch_indep,
95 struct distro_series *json_object_to_distro_series(json_object *o)
97 const char *displayname;
102 displayname = json_object_get_string
103 (json_object_object_get(o, "displayname"));
105 title = json_object_get_string
106 (json_object_object_get(o, "title"));
108 version = json_object_get_string
109 (json_object_object_get(o, "version"));
111 name = json_object_get_string
112 (json_object_object_get(o, "name"));
114 return distro_series_new(name,
120 struct binary_package_publishing_history * *
121 json_object_to_binary_package_publishing_history_list(json_object *o)
123 json_object *o_entries;
125 struct binary_package_publishing_history **entries;
126 struct binary_package_publishing_history *h;
127 const struct distro_arch_series *distro;
129 o_entries = json_object_object_get(o, "entries");
134 n = json_object_array_length(o_entries);
137 (sizeof(struct binary_package_publishing_history *)*(n+1));
139 for (i = 0, i2 = 0; i < n; i++) {
140 h = json_object_to_binary_package_publishing_history
141 (json_object_array_get_idx(o_entries, i));
143 if (!h->architecture_specific) {
144 distro = get_distro_arch_series
145 (h->distro_arch_series_link);
147 if (!distro->is_nominated_arch_indep) {
148 binary_package_publishing_history_free(h);
161 struct daily_download_total *
162 json_object_to_daily_download_total(const char *d, json_object *o_c)
164 struct daily_download_total *result;
166 result = malloc(sizeof(struct daily_download_total));
167 result->count = json_object_get_int(o_c);
169 strptime(d, "%FT%T%z", &result->date);
174 static int json_object_get_fields_count(json_object *o)
178 json_object_object_foreach(o, key, val)
184 struct daily_download_total * *
185 json_object_to_daily_download_totals(json_object *o)
188 struct daily_download_total **result;
190 n = json_object_get_fields_count(o);
193 (sizeof(struct daily_download_total *)*(n+1));
196 json_object_object_foreach(o, key, val) {
197 result[i] = json_object_to_daily_download_total(key, val);