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++)
241 struct daily_download_total **add_total
242 (struct daily_download_total **totals, struct daily_download_total *total)
244 struct daily_download_total **cur;
245 struct daily_download_total *item;
252 if (item->date.tm_year == total->date.tm_year &&
253 item->date.tm_mon == total->date.tm_mon &&
254 item->date.tm_mday == total->date.tm_mday) {
255 item->count = total->count;
263 item = malloc(sizeof(struct daily_download_total));
264 memcpy(item, total, sizeof(struct daily_download_total));
266 return (struct daily_download_total **)
267 list_add((void **)totals, (void *)item);
271 struct daily_download_total **
272 ddts_merge(struct daily_download_total **ddts1,
273 struct daily_download_total **ddts2)
275 struct daily_download_total **ddts, **cur, **tmp;
278 ddts = malloc((ddts_length(ddts1) + 1)
279 * sizeof(struct daily_download_total *));
280 memcpy(ddts, ddts1, (ddts_length(ddts1) + 1) * sizeof(void *));
282 ddts = malloc(sizeof(struct daily_download_total *));
287 for (cur = ddts2; *cur; cur++) {
288 tmp = add_total(ddts, *cur);
296 int ddts_get_count(struct daily_download_total **ddts)
298 struct daily_download_total **cur;
302 for (cur = ddts; *cur; cur++)