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)
94 struct bpph **l_cur = list;
104 char *get_archive_url(const char *owner, const char *ppa)
106 char *url = malloc(strlen(URL_BASE_LP)
109 +strlen("/+archive/")
113 strcpy(url, URL_BASE_LP);
116 strcat(url, "/+archive/");
122 struct distro_arch_series *distro_arch_series_new(const char *display_name,
124 const char *architecture_tag,
125 int is_nominated_arch_indep,
126 const char *distroseries_link)
128 struct distro_arch_series *d;
130 d = malloc(sizeof(struct distro_arch_series));
132 d->display_name = strdup(display_name);
133 d->title = strdup(title);
134 d->architecture_tag = strdup(architecture_tag);
135 d->is_nominated_arch_indep = is_nominated_arch_indep;
136 d->distroseries_link = strdup(distroseries_link);
141 void distro_arch_series_free(struct distro_arch_series *d)
143 free(d->display_name);
145 free(d->architecture_tag);
146 free(d->distroseries_link);
151 void distro_arch_series_list_free(struct distro_arch_series **list)
155 distro_arch_series_free(*list);
162 void daily_download_total_list_free(struct daily_download_total **list)
165 struct daily_download_total **cur = list;
176 struct bpph **bpph_list_add(struct bpph **list, struct bpph *new)
178 struct bpph **cur, *bpph, **result;
181 for (cur = list; *cur; cur++) {
184 if (!strcmp(bpph->self_link, new->self_link))
188 result = (struct bpph **)list_add((void **)list, new);
195 struct bpph **bpph_list_append_list(struct bpph **list1, struct bpph **list2)
202 for (cur = list2; *cur; cur++)
203 list1 = bpph_list_add(list1, *cur);
208 time_t ddts_get_last_date(struct daily_download_total **ddts)
210 struct daily_download_total **cur;
217 for (cur = ddts; *cur; cur++) {
218 t = mktime(&(*cur)->date);
226 int ddts_length(struct daily_download_total **ddts)
229 struct daily_download_total **cur;
234 for (cur = ddts; *cur; cur++)
240 static struct daily_download_total *ddt_clone(struct daily_download_total *ddt)
242 struct daily_download_total *new;
244 new = malloc(sizeof(struct daily_download_total));
246 new->date = ddt->date;
247 new->count = ddt->count;
252 static struct daily_download_total **
253 ddts_clone(struct daily_download_total **ddts)
256 struct daily_download_total **new;
258 n = ddts_length(ddts);
260 new = malloc((n + 1) * sizeof(struct daily_download_total *));
262 for (i = 0; i < n; i++)
263 new[i] = ddt_clone(ddts[i]);
271 Return a newly allocated list with an additional ddt.
274 static struct daily_download_total **add_ddt
275 (struct daily_download_total **totals, struct daily_download_total *total)
277 struct daily_download_total **cur, **ddts, **result;
278 struct daily_download_total *item;
285 if (item->date.tm_year == total->date.tm_year &&
286 item->date.tm_mon == total->date.tm_mon &&
287 item->date.tm_mday == total->date.tm_mday) {
288 item->count = total->count;
296 ddts = ddts_clone(totals);
298 result = (struct daily_download_total **)
299 list_add((void **)ddts, ddt_clone((void *)total));
306 struct daily_download_total **
307 ddts_merge(struct daily_download_total **ddts1,
308 struct daily_download_total **ddts2)
310 struct daily_download_total **ddts, **cur, **tmp;
313 ddts = ddts_clone(ddts1);
315 ddts = malloc(sizeof(struct daily_download_total *));
320 for (cur = ddts2; *cur; cur++) {
321 tmp = add_ddt(ddts, *cur);
323 daily_download_total_list_free(ddts);
331 int ddts_get_count(struct daily_download_total **ddts)
333 struct daily_download_total **cur;
337 for (cur = ddts; *cur; cur++)