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
27 char *time_to_str(time_t t)
38 str = malloc(strlen("YYYY-MM-DDThh:mm:ss") + 1);
39 ret = strftime(str, strlen("YYYY-MM-DDThh:mm:ss") + 1, "%FT%T", tm);
48 struct distro_series *distro_series_new(const char *name,
51 const char *displayname)
53 struct distro_series *d;
55 d = malloc(sizeof(struct distro_series));
57 d->name = strdup(name);
58 d->version = strdup(version);
59 d->title = strdup(title);
60 d->displayname = strdup(displayname);
65 void distro_series_free(struct distro_series *d)
77 void bpph_free(struct bpph *b)
80 free(b->binary_package_name);
81 free(b->binary_package_version);
82 free(b->distro_arch_series_link);
89 struct bpph *bpph_new(const char *binary_package_name,
90 const char *binary_package_version,
91 const char *distro_arch_series_link,
92 const char *self_link,
94 int architecture_specific,
99 h = malloc(sizeof(struct bpph));
101 h->binary_package_name = strdup(binary_package_name);
102 h->binary_package_version = strdup(binary_package_version);
103 h->distro_arch_series_link = strdup(distro_arch_series_link);
104 h->self_link = strdup(self_link);
105 h->architecture_specific = architecture_specific;
106 h->status = strdup(status);
107 h->date_created = date_created;
112 void bpph_list_free(struct bpph **list)
114 struct bpph **l_cur = list;
124 char *get_archive_url(const char *owner, const char *ppa)
126 char *url = malloc(strlen(URL_BASE_LP)
129 +strlen("/+archive/")
133 strcpy(url, URL_BASE_LP);
136 strcat(url, "/+archive/");
142 struct distro_arch_series *distro_arch_series_new(const char *display_name,
144 const char *architecture_tag,
145 int is_nominated_arch_indep,
146 const char *distroseries_link)
148 struct distro_arch_series *d;
150 d = malloc(sizeof(struct distro_arch_series));
152 d->display_name = strdup(display_name);
153 d->title = strdup(title);
154 d->architecture_tag = strdup(architecture_tag);
155 d->is_nominated_arch_indep = is_nominated_arch_indep;
156 d->distroseries_link = strdup(distroseries_link);
161 void distro_arch_series_free(struct distro_arch_series *d)
163 free(d->display_name);
165 free(d->architecture_tag);
166 free(d->distroseries_link);
171 void distro_arch_series_list_free(struct distro_arch_series **list)
175 distro_arch_series_free(*list);
182 void daily_download_total_list_free(struct daily_download_total **list)
185 struct daily_download_total **cur = list;
196 struct bpph **bpph_list_add(struct bpph **list, struct bpph *new)
198 struct bpph **cur, *bpph;
201 for (cur = list; *cur; cur++) {
204 if (!strcmp(bpph->self_link, new->self_link))
208 return (struct bpph **)list_add((void **)list, new);
211 struct bpph **bpph_list_append_list(struct bpph **list1, struct bpph **list2)
218 for (cur = list2; *cur; cur++)
219 list1 = bpph_list_add(list1, *cur);
224 time_t ddts_get_last_date(struct daily_download_total **ddts)
226 struct daily_download_total **cur;
233 for(cur = ddts; *cur; cur++) {
234 t = mktime(&(*cur)->date);
242 int ddts_length(struct daily_download_total **ddts)
245 struct daily_download_total **cur;
250 for(cur = ddts; *cur; cur++)
257 struct daily_download_total **add_total
258 (struct daily_download_total **totals, struct daily_download_total *total)
260 struct daily_download_total **cur;
261 struct daily_download_total *item;
268 if (item->date.tm_year == total->date.tm_year &&
269 item->date.tm_mon == total->date.tm_mon &&
270 item->date.tm_mday == total->date.tm_mday) {
271 item->count = total->count;
279 item = malloc(sizeof(struct daily_download_total));
280 memcpy(item, total, sizeof(struct daily_download_total));
282 return (struct daily_download_total **)
283 list_add((void **)totals, (void *)item);
287 struct daily_download_total **
288 ddts_merge(struct daily_download_total **ddts1,
289 struct daily_download_total **ddts2)
291 struct daily_download_total **ddts, **cur, **tmp;
294 ddts = malloc((ddts_length(ddts1) + 1) * sizeof(struct daily_download_total *));
295 memcpy(ddts, ddts1, (ddts_length(ddts1) + 1) * sizeof(void *));
297 ddts = malloc(sizeof(struct daily_download_total *));
302 for(cur = ddts2; *cur; cur++) {
303 tmp = add_total(ddts, *cur);
312 int ddts_get_count(struct daily_download_total **ddts)
314 struct daily_download_total **cur;
318 for (cur = ddts; *cur; cur++)