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,
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,
121 struct binary_package_publishing_history * *
122 json_object_to_binary_package_publishing_history_list(json_object *o)
124 json_object *o_entries;
126 struct binary_package_publishing_history **entries;
127 struct binary_package_publishing_history *h;
128 const struct distro_arch_series *distro;
130 o_entries = json_object_object_get(o, "entries");
135 n = json_object_array_length(o_entries);
138 (sizeof(struct binary_package_publishing_history *)*(n+1));
140 for (i = 0, i2 = 0; i < n; i++) {
141 h = json_object_to_binary_package_publishing_history
142 (json_object_array_get_idx(o_entries, i));
144 if (!h->architecture_specific) {
145 distro = get_distro_arch_series
146 (h->distro_arch_series_link);
148 if (!distro->is_nominated_arch_indep) {
149 binary_package_publishing_history_free(h);
162 struct daily_download_total *
163 json_object_to_daily_download_total(const char *d, json_object *o_c)
165 struct daily_download_total *result;
167 result = malloc(sizeof(struct daily_download_total));
168 result->count = json_object_get_int(o_c);
170 strptime(d, "%FT%T%z", &result->date);
175 static int json_object_get_fields_count(json_object *o)
179 json_object_object_foreach(o, key, val)
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);