better code
[ppastats.git] / src / lp.c
index 9ba2eec..79fcce6 100644 (file)
--- a/src/lp.c
+++ b/src/lp.c
 #include <stdio.h>
 #include <string.h>
 
+#include "list.h"
 #include "lp.h"
 
+char *time_to_str(time_t t)
+{
+       char *str;
+       struct tm *tm;
+       size_t ret;
+
+       tm = localtime(&t);
+
+       if (!tm)
+               return NULL;
+
+       str = malloc(strlen("YYYY-MM-DDThh:mm:ss") + 1);
+       ret = strftime(str, strlen("YYYY-MM-DDThh:mm:ss") + 1, "%FT%T", tm);
+
+       if (ret)
+               return str;
+
+       free(str);
+       return NULL;
+}
+
 struct distro_series *distro_series_new(const char *name,
                                        const char *version,
                                        const char *title,
@@ -68,7 +90,9 @@ struct bpph *bpph_new(const char *binary_package_name,
                      const char *binary_package_version,
                      const char *distro_arch_series_link,
                      const char *self_link,
-                     int architecture_specific)
+                     const char *status,
+                     int architecture_specific,
+                     time_t date_created)
 {
        struct bpph *h;
 
@@ -79,8 +103,8 @@ struct bpph *bpph_new(const char *binary_package_name,
        h->distro_arch_series_link = strdup(distro_arch_series_link);
        h->self_link = strdup(self_link);
        h->architecture_specific = architecture_specific;
-       h->status = NULL;
-       h->date_created.tm_isdst = -1;
+       h->status = strdup(status);
+       h->date_created = date_created;
 
        return h;
 }
@@ -169,3 +193,30 @@ void daily_download_total_list_free(struct daily_download_total **list)
        }
 }
 
+struct bpph **bpph_list_add(struct bpph **list, struct bpph *new)
+{
+       struct bpph **cur, *bpph;
+
+       if (list)
+               for (cur = list; *cur; cur++) {
+                       bpph = *cur;
+
+                       if (!strcmp(bpph->self_link, new->self_link))
+                               return list;
+               }
+
+       return (struct bpph **)list_add((void **)list, new);
+}
+
+struct bpph **bpph_list_append_list(struct bpph **list1, struct bpph **list2)
+{
+       struct bpph **cur;
+
+       if (!list2)
+               return list1;
+
+       for (cur = list2; *cur; cur++)
+               list1 = bpph_list_add(list1, *cur);
+
+       return list1;
+}