/*
- * Copyright (C) 2011-2014 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
+ Copyright (C) 2011-2014 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 <libintl.h>
#include <stdlib.h>
#include <string.h>
-#include "list.h"
-#include "lp_ws.h"
+#include <list.h>
+#include <lp_ws.h>
#include <plog.h>
-#include "ppastats.h"
+#include <ppastats.h>
static struct package_stats *get_package_stats(struct ppa_stats *stats,
const char *name)
return v;
}
+static void arch_stats_free(struct arch_stats *arch)
+{
+ free(arch->name);
+ free(arch);
+}
+
static struct distro_stats *distro_stats_new(const char *name)
{
struct distro_stats *d;
return d;
}
+static void distro_stats_free(struct distro_stats *distro)
+{
+ struct arch_stats **archs;
+
+ archs = distro->archs;
+ if (archs) {
+ while (*archs) {
+ arch_stats_free(*archs);
+ archs++;
+ }
+ free(distro->archs);
+ }
+
+ daily_download_total_list_free(distro->ddts);
+
+ free(distro->name);
+ free(distro);
+}
+
static struct distro_stats *get_distro_stats(struct version_stats *version,
const char *name)
{
- struct distro_stats **cur = version->distros;
- struct distro_stats *d;
- struct distro_stats **tmp;
+ struct distro_stats **cur, *d, **tmp;
+
+ cur = version->distros;
while (cur && *cur) {
d = *cur;
result = (struct daily_download_total **)list_add((void **)totals,
ddt_clone(total));
-
return result;
}
pkg_distro = distro_stats_new(distro_name);
tmp = (struct distro_stats **)list_add((void **)pkg->distros,
(void *)pkg_distro);
- free(pkg->distros);
+ if (pkg->distros != tmp)
+ free(pkg->distros);
pkg->distros = tmp;
}
pkg_distro->ddts = tmp_ddts;
}
+static struct ppa_stats *ppa_stats_new(const char *owner, const char *ppa_name)
+{
+ struct ppa_stats *ppa;
+
+ ppa = malloc(sizeof(struct ppa_stats));
+ ppa->name = strdup(ppa_name);
+ ppa->owner = strdup(owner);
+ ppa->packages = NULL;
+ ppa->daily_download_totals = NULL;
+ ppa->download_count = 0;
+
+ return ppa;
+}
+
struct ppa_stats *
create_ppa_stats(const char *owner,
const char *ppa_name,
exit(EXIT_FAILURE);
}
- ppa = malloc(sizeof(struct ppa_stats));
- ppa->name = strdup(ppa_name);
- ppa->owner = strdup(owner);
- ppa->packages = NULL;
- ppa->daily_download_totals = NULL;
- ppa->download_count = 0;
+ ppa = ppa_stats_new(owner, ppa_name);
for (h_cur = history; *h_cur; ++h_cur) {
h = *h_cur;
return ppa;
}
-static void arch_stats_free(struct arch_stats *arch)
-{
- free(arch->name);
- free(arch);
-}
-
-static void distro_stats_free(struct distro_stats *distro)
-{
- struct arch_stats **archs;
-
- archs = distro->archs;
- if (archs) {
- while (*archs) {
- arch_stats_free(*archs);
- archs++;
- }
- free(distro->archs);
- }
-
- free(distro->name);
- free(distro);
-}
-
static void distro_stats_list_free(struct distro_stats **distros)
{
+ struct distro_stats **cur;
+
if (distros) {
- while (*distros) {
- distro_stats_free(*distros);
- distros++;
+ cur = distros;
+ while (*cur) {
+ distro_stats_free(*cur);
+ cur++;
}
+ free(distros);
}
}
static void version_stats_free(struct version_stats *version)
{
- struct distro_stats **distros;
-
- distros = version->distros;
- if (distros) {
- while (*distros) {
- distro_stats_free(*distros);
- distros++;
- }
- free(version->distros);
- }
+ distro_stats_list_free(version->distros);
+ daily_download_total_list_free(version->daily_download_totals);
free(version->version);
free(version);
free(package->versions);
}
distro_stats_list_free(package->distros);
+ daily_download_total_list_free(package->daily_download_totals);
free(package->name);
free(package);
}