retry on network failure during url fetch
[ppastats.git] / src / lp.c
1 /*
2     Copyright (C) 2011 jeanfi@gmail.com
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU 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
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "lp.h"
26
27 struct distro_series *distro_series_new(const char *name,
28                                         const char *version,
29                                         const char *title,
30                                         const char *displayname)
31 {
32         struct distro_series *d;
33
34         d = malloc(sizeof(struct distro_series));
35
36         d->name = strdup(name);
37         d->version = strdup(version);
38         d->title = strdup(title);
39         d->displayname = strdup(displayname);
40
41         return d;
42 }
43
44 void distro_series_free(struct distro_series *d)
45 {
46         if (d) {
47                 free(d->name);
48                 free(d->version);
49                 free(d->title);
50                 free(d->displayname);
51
52                 free(d);
53         }
54 }
55
56 void
57 binary_package_publishing_history_free \
58 (struct binary_package_publishing_history *b)
59 {
60         if (b) {
61                 free(b->binary_package_name);
62                 free(b->binary_package_version);
63                 free(b->distro_arch_series_link);
64                 free(b->self_link);
65                 free(b);
66         }
67 }
68
69 struct binary_package_publishing_history *
70 binary_package_publishing_history_new(const char *binary_package_name,
71                                       const char *binary_package_version,
72                                       const char *distro_arch_series_link,
73                                       const char *self_link,
74                                       int architecture_specific)
75 {
76         struct binary_package_publishing_history *b;
77
78         b = malloc(sizeof(struct binary_package_publishing_history));
79
80         b->binary_package_name = strdup(binary_package_name);
81         b->binary_package_version = strdup(binary_package_version);
82         b->distro_arch_series_link = strdup(distro_arch_series_link);
83         b->self_link = strdup(self_link);
84         b->architecture_specific = architecture_specific;
85
86         return b;
87 }
88
89 void
90 binary_package_publishing_history_list_free\
91 (struct binary_package_publishing_history **list)
92 {
93         struct binary_package_publishing_history **l_cur = list;
94
95         while (*l_cur) {
96                 binary_package_publishing_history_free(*l_cur);
97                 l_cur++;
98         }
99
100         free(list);
101 }
102
103 char *get_archive_url(const char *owner, const char *ppa)
104 {
105         char *url = malloc(strlen(URL_BASE_LP)
106                            +strlen("/~")
107                            +strlen(owner)
108                            +strlen("/+archive/")
109                            +strlen(ppa)
110                            +1);
111
112         strcpy(url, URL_BASE_LP);
113         strcat(url, "/~");
114         strcat(url, owner);
115         strcat(url, "/+archive/");
116         strcat(url, ppa);
117
118         return url;
119 }
120
121 struct distro_arch_series *distro_arch_series_new(const char *display_name,
122                                                   const char *title,
123                                                   const char *architecture_tag,
124                                                   int is_nominated_arch_indep,
125                                                   const char *distroseries_link)
126 {
127         struct distro_arch_series *d;
128
129         d = malloc(sizeof(struct distro_arch_series));
130
131         d->display_name = strdup(display_name);
132         d->title = strdup(title);
133         d->architecture_tag = strdup(architecture_tag);
134         d->is_nominated_arch_indep = is_nominated_arch_indep;
135         d->distroseries_link = strdup(distroseries_link);
136
137         return d;
138 }
139
140 void distro_arch_series_free(struct distro_arch_series *d)
141 {
142         free(d->display_name);
143         free(d->title);
144         free(d->architecture_tag);
145         free(d->distroseries_link);
146
147         free(d);
148 }
149
150 void distro_arch_series_list_free(struct distro_arch_series **list)
151 {
152         if (list) {
153                 while (*list) {
154                         distro_arch_series_free(*list);
155                         list++;
156                 }
157                 free(list);
158         }
159 }
160
161 void daily_download_total_list_free(struct daily_download_total **list)
162 {
163         if (list) {
164                 struct daily_download_total **cur = list;
165
166                 while (*cur) {
167                         free(*cur);
168                         cur++;
169                 }
170
171                 free(list);
172         }
173 }
174