b8c24f17f98e5e4faa121b812a3fd4bb224385d4
[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);
63         }
64 }
65
66 struct bpph *bpph_new(const char *binary_package_name,
67                       const char *binary_package_version,
68                       const char *distro_arch_series_link,
69                       const char *self_link,
70                       int architecture_specific)
71 {
72         struct bpph *h;
73
74         h = malloc(sizeof(struct bpph));
75
76         h->binary_package_name = strdup(binary_package_name);
77         h->binary_package_version = strdup(binary_package_version);
78         h->distro_arch_series_link = strdup(distro_arch_series_link);
79         h->self_link = strdup(self_link);
80         h->architecture_specific = architecture_specific;
81
82         return h;
83 }
84
85 void bpph_list_free(struct bpph **list)
86 {
87         struct bpph **l_cur = list;
88
89         while (*l_cur) {
90                 bpph_free(*l_cur);
91                 l_cur++;
92         }
93
94         free(list);
95 }
96
97 char *get_archive_url(const char *owner, const char *ppa)
98 {
99         char *url = malloc(strlen(URL_BASE_LP)
100                            +strlen("/~")
101                            +strlen(owner)
102                            +strlen("/+archive/")
103                            +strlen(ppa)
104                            +1);
105
106         strcpy(url, URL_BASE_LP);
107         strcat(url, "/~");
108         strcat(url, owner);
109         strcat(url, "/+archive/");
110         strcat(url, ppa);
111
112         return url;
113 }
114
115 struct distro_arch_series *distro_arch_series_new(const char *display_name,
116                                                   const char *title,
117                                                   const char *architecture_tag,
118                                                   int is_nominated_arch_indep,
119                                                   const char *distroseries_link)
120 {
121         struct distro_arch_series *d;
122
123         d = malloc(sizeof(struct distro_arch_series));
124
125         d->display_name = strdup(display_name);
126         d->title = strdup(title);
127         d->architecture_tag = strdup(architecture_tag);
128         d->is_nominated_arch_indep = is_nominated_arch_indep;
129         d->distroseries_link = strdup(distroseries_link);
130
131         return d;
132 }
133
134 void distro_arch_series_free(struct distro_arch_series *d)
135 {
136         free(d->display_name);
137         free(d->title);
138         free(d->architecture_tag);
139         free(d->distroseries_link);
140
141         free(d);
142 }
143
144 void distro_arch_series_list_free(struct distro_arch_series **list)
145 {
146         if (list) {
147                 while (*list) {
148                         distro_arch_series_free(*list);
149                         list++;
150                 }
151                 free(list);
152         }
153 }
154
155 void daily_download_total_list_free(struct daily_download_total **list)
156 {
157         if (list) {
158                 struct daily_download_total **cur = list;
159
160                 while (*cur) {
161                         free(*cur);
162                         cur++;
163                 }
164
165                 free(list);
166         }
167 }
168