X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flp_json.c;h=e217180062a6ba4a20c393f054b3d574660027a4;hb=cbe5f873c5f0306a7a5d2f431992dbbb6edbe332;hp=f6bbbcd5a295b2854c4fc67c8104e417cdd71824;hpb=9d12e96806e0833e6b859f622a29474ba01d54b3;p=ppastats.git diff --git a/src/lp_json.c b/src/lp_json.c index f6bbbcd..e217180 100644 --- a/src/lp_json.c +++ b/src/lp_json.c @@ -1,40 +1,41 @@ /* - 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 -*/ - + * Copyright (C) 2011-2012 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 + */ +#define _XOPEN_SOURCE_EXTENDED #define _XOPEN_SOURCE -#include - - #include #include +#include +#include #include "lp_json.h" #include "lp_ws.h" -struct binary_package_publishing_history * -json_object_to_binary_package_publishing_history(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; + const char *status; binary_package_name = json_object_get_string (json_object_object_get(o, "binary_package_name")); @@ -54,11 +55,70 @@ json_object_to_binary_package_publishing_history(json_object *o) else architecture_specific = 0; - return binary_package_publishing_history_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) + strptime(date_created, "%FT%T", &bpph->date_created); + + status = json_object_get_string(json_object_object_get(o, "status")); + if (status) + bpph->status = strdup(status); + + 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, + "self_link", + json_object_new_string(bpph->self_link)); + + json_object_object_add + (json, + "architecture_specific", + json_object_new_boolean(bpph->architecture_specific)); + + json_object_object_add + (json, "status", json_object_new_string(bpph->status)); + + date = malloc(strlen("YY-MM-DDThh:mm:ss+xxx") + 1); + strftime(date, + strlen("YY-MM-DDThh:mm:ss+xxx") + 1, + "%FT%T", + &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) @@ -69,7 +129,6 @@ 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")); @@ -102,14 +161,11 @@ struct distro_series *json_object_to_distro_series(json_object *o) displayname = json_object_get_string (json_object_object_get(o, "displayname")); - title = json_object_get_string - (json_object_object_get(o, "title")); + title = json_object_get_string(json_object_object_get(o, "title")); - version = json_object_get_string - (json_object_object_get(o, "version")); + version = json_object_get_string(json_object_object_get(o, "version")); - name = json_object_get_string - (json_object_object_get(o, "name")); + name = json_object_get_string(json_object_object_get(o, "name")); return distro_series_new(name, version, @@ -117,13 +173,11 @@ struct distro_series *json_object_to_distro_series(json_object *o) displayname); } -struct binary_package_publishing_history * * -json_object_to_binary_package_publishing_history_list(json_object *o) +struct bpph **json_object_to_bpph_list(json_object *o) { json_object *o_entries; int i, n, i2; - struct binary_package_publishing_history **entries; - struct binary_package_publishing_history *h; + struct bpph **entries, *h; const struct distro_arch_series *distro; o_entries = json_object_object_get(o, "entries"); @@ -134,18 +188,18 @@ json_object_to_binary_package_publishing_history_list(json_object *o) n = json_object_array_length(o_entries); entries = malloc - (sizeof(struct binary_package_publishing_history *)*(n+1)); + (sizeof(struct bpph *)*(n+1)); for (i = 0, i2 = 0; i < n; i++) { - h = json_object_to_binary_package_publishing_history - (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 (h->distro_arch_series_link); - if (!distro->is_nominated_arch_indep) { - binary_package_publishing_history_free(h); + if (!distro || !distro->is_nominated_arch_indep) { + bpph_free(h); continue ; } } @@ -158,6 +212,23 @@ json_object_to_binary_package_publishing_history_list(json_object *o) 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); + + if (list) + 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) {