v0.0.6
[ppastats.git] / trunk / src / lp.c
diff --git a/trunk/src/lp.c b/trunk/src/lp.c
new file mode 100644 (file)
index 0000000..f3d0610
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+    Copyright (C) 2011 jeanfi@gmail.com
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301 USA
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "lp.h"
+
+struct distro_series *distro_series_new(const char *name,
+                                       const char *version,
+                                       const char *title,
+                                       const char *displayname)
+{
+       struct distro_series *d;
+
+       d = malloc(sizeof(struct distro_series));
+
+       d->name = strdup(name);
+       d->version = strdup(version);
+       d->title = strdup(title);
+       d->displayname = strdup(displayname);
+
+       return d;
+}
+
+void distro_series_free(struct distro_series *d)
+{
+       if (d) {
+               free(d->name);
+               free(d->version);
+               free(d->title);
+               free(d->displayname);
+
+               free(d);
+       }
+}
+
+void
+binary_package_publishing_history_free \
+(struct binary_package_publishing_history *b)
+{
+       if (b) {
+               free(b->binary_package_name);
+               free(b->binary_package_version);
+               free(b->distro_arch_series_link);
+               free(b->self_link);
+               free(b);
+       }
+}
+
+struct binary_package_publishing_history *
+binary_package_publishing_history_new(const char *binary_package_name,
+                                     const char *binary_package_version,
+                                     const char *distro_arch_series_link,
+                                     const char *self_link,
+                                     int architecture_specific)
+{
+       struct binary_package_publishing_history *b;
+
+       b = malloc(sizeof(struct binary_package_publishing_history));
+
+       b->binary_package_name = strdup(binary_package_name);
+       b->binary_package_version = strdup(binary_package_version);
+       b->distro_arch_series_link = strdup(distro_arch_series_link);
+       b->self_link = strdup(self_link);
+       b->architecture_specific = architecture_specific;
+
+       return b;
+}
+
+void
+binary_package_publishing_history_list_free\
+(struct binary_package_publishing_history **list)
+{
+       struct binary_package_publishing_history **l_cur = list;
+
+       while (*l_cur) {
+               binary_package_publishing_history_free(*l_cur);
+               l_cur++;
+       }
+
+       free(list);
+}
+
+char *get_archive_url(const char *owner, const char *ppa)
+{
+       char *url = malloc(strlen(URL_BASE_LP)
+                          +strlen("/~")
+                          +strlen(owner)
+                          +strlen("/+archive/")
+                          +strlen(ppa)
+                          +1);
+
+       strcpy(url, URL_BASE_LP);
+       strcat(url, "/~");
+       strcat(url, owner);
+       strcat(url, "/+archive/");
+       strcat(url, ppa);
+
+       return url;
+}
+
+struct distro_arch_series *distro_arch_series_new(const char *display_name,
+                                                 const char *title,
+                                                 const char *architecture_tag,
+                                                 int is_nominated_arch_indep,
+                                                 const char *distroseries_link)
+{
+       struct distro_arch_series *d;
+
+       d = malloc(sizeof(struct distro_arch_series));
+
+       d->display_name = strdup(display_name);
+       d->title = strdup(title);
+       d->architecture_tag = strdup(architecture_tag);
+       d->is_nominated_arch_indep = is_nominated_arch_indep;
+       d->distroseries_link = strdup(distroseries_link);
+
+       return d;
+}
+
+void distro_arch_series_free(struct distro_arch_series *d)
+{
+       free(d->display_name);
+       free(d->title);
+       free(d->architecture_tag);
+       free(d->distroseries_link);
+
+       free(d);
+}
+
+void distro_arch_series_list_free(struct distro_arch_series **list)
+{
+       if (list) {
+               while (*list) {
+                       distro_arch_series_free(*list);
+                       list++;
+               }
+               free(list);
+       }
+}
+
+void daily_download_total_list_free(struct daily_download_total **list)
+{
+       if (list) {
+               struct daily_download_total **cur = list;
+
+               while (*cur) {
+                       free(*cur);
+                       cur++;
+               }
+
+               free(list);
+       }
+}
+