2 * Copyright (C) 2011-2014 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
28 struct distro_series *distro_series_new(const char *name,
31 const char *displayname)
33 struct distro_series *d;
35 d = malloc(sizeof(struct distro_series));
37 d->name = strdup(name);
38 d->version = strdup(version);
39 d->title = strdup(title);
40 d->displayname = strdup(displayname);
45 void distro_series_free(struct distro_series *d)
57 void bpph_free(struct bpph *b)
60 free(b->binary_package_name);
61 free(b->binary_package_version);
62 free(b->distro_arch_series_link);
69 struct bpph *bpph_new(const char *binary_package_name,
70 const char *binary_package_version,
71 const char *distro_arch_series_link,
72 const char *self_link,
74 int architecture_specific,
79 h = malloc(sizeof(struct bpph));
81 h->binary_package_name = strdup(binary_package_name);
82 h->binary_package_version = strdup(binary_package_version);
83 h->distro_arch_series_link = strdup(distro_arch_series_link);
84 h->self_link = strdup(self_link);
85 h->architecture_specific = architecture_specific;
86 h->status = strdup(status);
87 h->date_created = date_created;
92 void bpph_list_free(struct bpph **list)
108 char *get_archive_url(const char *owner, const char *ppa)
110 char *url = malloc(strlen(URL_BASE_LP)
113 +strlen("/+archive/")
117 strcpy(url, URL_BASE_LP);
120 strcat(url, "/+archive/");
126 struct distro_arch_series *distro_arch_series_new(const char *display_name,
128 const char *architecture_tag,
129 int is_nominated_arch_indep,
130 const char *distroseries_link)
132 struct distro_arch_series *d;
134 d = malloc(sizeof(struct distro_arch_series));
136 d->display_name = strdup(display_name);
137 d->title = strdup(title);
138 d->architecture_tag = strdup(architecture_tag);
139 d->is_nominated_arch_indep = is_nominated_arch_indep;
140 d->distroseries_link = strdup(distroseries_link);
145 void distro_arch_series_free(struct distro_arch_series *d)
147 free(d->display_name);
149 free(d->architecture_tag);
150 free(d->distroseries_link);
155 void distro_arch_series_list_free(struct distro_arch_series **list)
157 struct distro_arch_series **cur;
162 distro_arch_series_free(*cur);
169 void daily_download_total_list_free(struct daily_download_total **list)
172 struct daily_download_total **cur = list;
183 struct bpph **bpph_list_add(struct bpph **list, struct bpph *new)
185 struct bpph **cur, *bpph, **result;
188 for (cur = list; *cur; cur++) {
191 if (!strcmp(bpph->self_link, new->self_link))
195 result = (struct bpph **)list_add((void **)list, new);
202 struct bpph **bpph_list_append_list(struct bpph **list1, struct bpph **list2)
209 for (cur = list2; *cur; cur++)
210 list1 = bpph_list_add(list1, *cur);
215 time_t ddts_get_last_date(struct daily_download_total **ddts)
217 struct daily_download_total **cur;
224 for (cur = ddts; *cur; cur++) {
225 t = mktime(&(*cur)->date);
233 int ddts_length(struct daily_download_total **ddts)
236 struct daily_download_total **cur;
241 for (cur = ddts; *cur; cur++)
247 struct daily_download_total *ddt_clone(struct daily_download_total *ddt)
249 struct daily_download_total *new;
251 new = malloc(sizeof(struct daily_download_total));
253 new->date = ddt->date;
254 new->count = ddt->count;
259 struct daily_download_total **
260 ddts_clone(struct daily_download_total **ddts)
263 struct daily_download_total **new;
265 n = ddts_length(ddts);
267 new = malloc((n + 1) * sizeof(struct daily_download_total *));
269 for (i = 0; i < n; i++)
270 new[i] = ddt_clone(ddts[i]);
278 Return a newly allocated list with an additional ddt.
281 static struct daily_download_total **add_ddt
282 (struct daily_download_total **totals, struct daily_download_total *total)
284 struct daily_download_total **cur, **ddts, **result;
285 struct daily_download_total *item;
292 if (item->date.tm_year == total->date.tm_year &&
293 item->date.tm_mon == total->date.tm_mon &&
294 item->date.tm_mday == total->date.tm_mday) {
295 item->count = total->count;
303 ddts = ddts_clone(totals);
305 result = (struct daily_download_total **)
306 list_add((void **)ddts, ddt_clone((void *)total));
313 struct daily_download_total **
314 ddts_merge(struct daily_download_total **ddts1,
315 struct daily_download_total **ddts2)
317 struct daily_download_total **ddts, **cur, **tmp;
320 ddts = ddts_clone(ddts1);
322 ddts = malloc(sizeof(struct daily_download_total *));
327 for (cur = ddts2; *cur; cur++) {
328 tmp = add_ddt(ddts, *cur);
330 daily_download_total_list_free(ddts);
338 int ddts_get_count(struct daily_download_total **ddts)
340 struct daily_download_total **cur;
344 for (cur = ddts; *cur; cur++)