added is_nominated_arch_dep info
[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 <string.h>
23
24 #include "lp.h"
25
26 void
27 binary_package_publishing_history_free(struct binary_package_publishing_history *b)
28 {
29         if (b) {
30                 free(b->binary_package_name);
31                 free(b->binary_package_version);
32                 free(b->distro_arch_series_link);
33                 free(b->self_link);
34                 free(b);
35         }
36 }
37
38 struct binary_package_publishing_history *
39 binary_package_publishing_history_new(const char *binary_package_name,
40                                       const char *binary_package_version,
41                                       const char *distro_arch_series_link,
42                                       const char *self_link)
43 {
44         struct binary_package_publishing_history *b;
45
46         b = malloc(sizeof(struct binary_package_publishing_history));
47
48         b->binary_package_name = strdup(binary_package_name);
49         b->binary_package_version = strdup(binary_package_version);
50         b->distro_arch_series_link = strdup(distro_arch_series_link);
51         b->self_link = strdup(self_link);
52
53         return b;
54 }
55
56 void
57 binary_package_publishing_history_list_free(struct binary_package_publishing_history **list)
58 {
59         struct binary_package_publishing_history **l_cur = list;
60
61         while (*l_cur) {
62                 binary_package_publishing_history_free(*l_cur);
63                 l_cur++;
64         }
65
66         free(list);
67 }
68
69 char *get_archive_url(const char *owner, const char *ppa)
70 {
71         char *url = malloc(strlen(URL_BASE_LP)
72                            +strlen("/~")
73                            +strlen(owner)
74                            +strlen("/+archive/")
75                            +strlen(ppa)
76                            +1);
77
78         strcpy(url, URL_BASE_LP);
79         strcat(url, "/~");
80         strcat(url, owner);
81         strcat(url, "/+archive/");
82         strcat(url, ppa);
83
84         return url;
85 }
86
87 struct distro_arch_series *distro_arch_series_new(const char *display_name,
88                                                   const char *title,
89                                                   const char *architecture_tag,
90                                                   int is_nominated_arch_indep)
91 {
92         struct distro_arch_series *d;
93
94         d = malloc(sizeof(struct distro_arch_series));
95
96         d->display_name = strdup(display_name);
97         d->title = strdup(title);
98         d->architecture_tag = strdup(architecture_tag);
99         d->is_nominated_arch_indep = is_nominated_arch_indep;
100
101         return d;
102 }
103
104 void distro_arch_series_free(struct distro_arch_series *d)
105 {
106         free(d->display_name);
107         free(d->title);
108         free(d->architecture_tag);
109
110         free(d);
111 }
112
113 void distro_arch_series_list_free(struct distro_arch_series **list)
114 {
115         if (list) {
116                 while (*list) {
117                         distro_arch_series_free(*list);
118                         list++;
119                 }
120                 free(list);
121         }
122 }
123
124 void daily_download_total_list_free(struct daily_download_total **list)
125 {
126         if (list) {
127                 struct daily_download_total **cur = list;
128
129                 while (*cur) {
130                         free(*cur);
131                         cur++;
132                 }
133
134                 free(list);
135         }
136 }
137
138 int list_length(void **list)
139 {
140         int n;
141
142         n = 0;
143         while (*list) {
144                 list++;
145                 n++;
146         }
147
148         return n;
149 }
150