#define _XOPEN_SOURCE
#include <time.h>
-
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <time.h>
#include "lp_json.h"
#include "lp_ws.h"
-struct bpph *json_object_to_bpph(json_object *o)
+static struct bpph *json_to_bpph(json_object *o)
{
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 *date_created;
+ struct bpph *bpph;
binary_package_name = json_object_get_string
(json_object_object_get(o, "binary_package_name"));
else
architecture_specific = 0;
- return bpph_new(binary_package_name,
- binary_package_version,
- distro_arch_series_link,
- self_link,
- architecture_specific);
+ bpph = bpph_new(binary_package_name,
+ binary_package_version,
+ distro_arch_series_link,
+ self_link,
+ architecture_specific);
+
+ date_created = json_object_get_string
+ (json_object_object_get(o, "date_created"));
+ if (date_created) {
+ bpph->date_created.tm_isdst = -1;
+ strptime(date_created, "%FT%T%z", &bpph->date_created);
+ }
+
+ return bpph;
+}
+
+static json_object *bpph_to_json(struct bpph *bpph)
+{
+ json_object *json;
+ char *date;
+
+ json = json_object_new_object();
+
+ json_object_object_add
+ (json,
+ "binary_package_name",
+ json_object_new_string(bpph->binary_package_name));
+
+ json_object_object_add
+ (json,
+ "binary_package_version",
+ json_object_new_string(bpph->binary_package_version));
+
+ json_object_object_add
+ (json,
+ "distro_arch_series_link",
+ json_object_new_string(bpph->distro_arch_series_link));
+
+ json_object_object_add
+ (json,
+ "architecture_specific",
+ json_object_new_boolean(bpph->architecture_specific));
+
+ date = malloc(strlen("YY-MM-DDThh:mm:ss+xxx") + 1);
+ strftime(date,
+ strlen("YY-MM-DDThh:mm:ss+xxx") + 1,
+ "%FT%T%z",
+ &bpph->date_created);
+
+ json_object_object_add
+ (json,
+ "date_created",
+ json_object_new_string(date));
+
+ free(date);
+
+ return json;
}
struct distro_arch_series *json_object_to_distro_arch_series(json_object *o)
boolean is_nominated_arch_indep;
const char *distroseries_link;
-
display_name = json_object_get_string
(json_object_object_get(o, "display_name"));
(sizeof(struct bpph *)*(n+1));
for (i = 0, i2 = 0; i < n; i++) {
- h = json_object_to_bpph(json_object_array_get_idx(o_entries,
- i));
+ h = json_to_bpph(json_object_array_get_idx(o_entries,
+ i));
if (!h->architecture_specific) {
distro = get_distro_arch_series
return entries;
}
+json_object *bpph_list_to_json(struct bpph **list)
+{
+ json_object *result, *entries;
+ struct bpph **cur;
+
+ result = json_object_new_object();
+
+ entries = json_object_new_array();
+ json_object_object_add(result, "entries", entries);
+
+ for (cur = list; *cur; cur++)
+ json_object_array_add(entries, bpph_to_json(*cur));
+
+ return result;
+}
+
struct daily_download_total *
json_object_to_daily_download_total(const char *d, json_object *o_c)
{
#include <libintl.h>
#define _(String) gettext(String)
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct bpph **get_bpph_list(const char *archive_url, const char *pkg_status)
{
- struct json_object *o_next;
- char *url;
- json_object *o;
- void **result = NULL;
+ char *url, *bpph_key;
+ struct bpph **result = NULL;
+ struct json_object *o, *bpph_json, *o_next;
url = malloc(strlen(archive_url)+
strlen(QUERY_GET_PUBLISHED_BINARIES)+
if (!o)
break;
- result = list_append_list(result,
- (void **)json_object_to_bpph_list(o));
+ result = (struct bpph **)list_append_list
+ ((void **)result,
+ (void **)json_object_to_bpph_list(o));
o_next = json_object_object_get(o, "next_collection_link");
json_object_put(o);
}
- return (struct bpph **)result;
+ bpph_json = bpph_list_to_json(result);
+
+ bpph_key = malloc(strlen(archive_url + 7) + strlen("/bpph") + 1);
+ sprintf(bpph_key, "%s/bpph", archive_url + 7);
+ fcache_put(bpph_key, json_object_to_json_string(bpph_json));
+
+ json_object_put(bpph_json);
+ free(bpph_key);
+
+ return result;
}
int get_download_count(const char *archive_url)