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