only save useful att for bpph
[ppastats.git] / src / lp.c
1 /*
2  * Copyright (C) 2011-2012 jeanfi@gmail.com
3  *
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.
8  *
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.
13  *
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
17  * 02110-1301 USA
18  */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "lp.h"
25
26 struct distro_series *distro_series_new(const char *name,
27                                         const char *version,
28                                         const char *title,
29                                         const char *displayname)
30 {
31         struct distro_series *d;
32
33         d = malloc(sizeof(struct distro_series));
34
35         d->name = strdup(name);
36         d->version = strdup(version);
37         d->title = strdup(title);
38         d->displayname = strdup(displayname);
39
40         return d;
41 }
42
43 void distro_series_free(struct distro_series *d)
44 {
45         if (d) {
46                 free(d->name);
47                 free(d->version);
48                 free(d->title);
49                 free(d->displayname);
50
51                 free(d);
52         }
53 }
54
55 void bpph_free(struct bpph *b)
56 {
57         if (b) {
58                 free(b->binary_package_name);
59                 free(b->binary_package_version);
60                 free(b->distro_arch_series_link);
61                 free(b->self_link);
62                 free(b->status);
63                 free(b);
64         }
65 }
66
67 struct bpph *bpph_new(const char *binary_package_name,
68                       const char *binary_package_version,
69                       const char *distro_arch_series_link,
70                       const char *self_link,
71                       int architecture_specific)
72 {
73         struct bpph *h;
74
75         h = malloc(sizeof(struct bpph));
76
77         h->binary_package_name = strdup(binary_package_name);
78         h->binary_package_version = strdup(binary_package_version);
79         h->distro_arch_series_link = strdup(distro_arch_series_link);
80         h->self_link = strdup(self_link);
81         h->architecture_specific = architecture_specific;
82         h->status = NULL;
83         h->date_created.tm_isdst = -1;
84
85         return h;
86 }
87
88 void bpph_list_free(struct bpph **list)
89 {
90         struct bpph **l_cur = list;
91
92         while (*l_cur) {
93                 bpph_free(*l_cur);
94                 l_cur++;
95         }
96
97         free(list);
98 }
99
100 char *get_archive_url(const char *owner, const char *ppa)
101 {
102         char *url = malloc(strlen(URL_BASE_LP)
103                            +strlen("/~")
104                            +strlen(owner)
105                            +strlen("/+archive/")
106                            +strlen(ppa)
107                            +1);
108
109         strcpy(url, URL_BASE_LP);
110         strcat(url, "/~");
111         strcat(url, owner);
112         strcat(url, "/+archive/");
113         strcat(url, ppa);
114
115         return url;
116 }
117
118 struct distro_arch_series *distro_arch_series_new(const char *display_name,
119                                                   const char *title,
120                                                   const char *architecture_tag,
121                                                   int is_nominated_arch_indep,
122                                                   const char *distroseries_link)
123 {
124         struct distro_arch_series *d;
125
126         d = malloc(sizeof(struct distro_arch_series));
127
128         d->display_name = strdup(display_name);
129         d->title = strdup(title);
130         d->architecture_tag = strdup(architecture_tag);
131         d->is_nominated_arch_indep = is_nominated_arch_indep;
132         d->distroseries_link = strdup(distroseries_link);
133
134         return d;
135 }
136
137 void distro_arch_series_free(struct distro_arch_series *d)
138 {
139         free(d->display_name);
140         free(d->title);
141         free(d->architecture_tag);
142         free(d->distroseries_link);
143
144         free(d);
145 }
146
147 void distro_arch_series_list_free(struct distro_arch_series **list)
148 {
149         if (list) {
150                 while (*list) {
151                         distro_arch_series_free(*list);
152                         list++;
153                 }
154                 free(list);
155         }
156 }
157
158 void daily_download_total_list_free(struct daily_download_total **list)
159 {
160         if (list) {
161                 struct daily_download_total **cur = list;
162
163                 while (*cur) {
164                         free(*cur);
165                         cur++;
166                 }
167
168                 free(list);
169         }
170 }
171