From 3ef3a6b2acadc5546328a4d96e584dc4f7215af5 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Mon, 29 Apr 2013 17:06:39 +0000 Subject: [PATCH] --- src/ttrss.c | 6 ++--- src/ttrss_ws.c | 77 +++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/ttrss.c b/src/ttrss.c index b3b555e..ad78c0b 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -67,7 +67,7 @@ static void file_set_content(const char *path, const char *content) } } -static char *content_get_path(const struct headline *h) +static gchar *content_get_path(const struct headline *h) { const char *cache_dir; @@ -91,7 +91,7 @@ static int is_content_cached(const struct headline *h) else result = 1; - free(path); + g_free(path); return result; } @@ -111,7 +111,7 @@ char *ttrss_get_headline_content(struct headline *h) file_set_content(path, content); } - free(path); + g_free(path); return content; } diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index c4c2c4f..4b9c040 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -95,23 +95,23 @@ void ws_set_config(const char *url, const char *user, const char *pwd) struct json_object *ws_reply_get_content(struct json_object *rp) { - log_debug("ws_reply_get_content"); + log_debug("ws_reply_get_content"); return json_object_object_get(rp, "content"); } static const char *ws_reply_get_error(struct json_object *content) { - struct json_object *jerror; + struct json_object *jerror; - if (json_object_get_type(content) != json_type_object) - return NULL; + if (json_object_get_type(content) != json_type_object) + return NULL; - jerror = json_object_object_get(content, "error"); - - if (!jerror) - return NULL; + jerror = json_object_object_get(content, "error"); - return json_object_get_string(jerror); + if (!jerror) + return NULL; + + return json_object_get_string(jerror); } static struct json_object * @@ -128,13 +128,13 @@ execute(struct http_session *sess, struct json_object *rq, char **err) content = ws_reply_get_content(rp); if (content) { - str = ws_reply_get_error(content); + str = ws_reply_get_error(content); if (str) { - *err = strdup(str); + *err = strdup(str); content = NULL; } else { - json_object_get(content); + json_object_get(content); } } @@ -338,30 +338,23 @@ int ws_update_headlines(struct feed *feed) } } -struct feed **ws_update_feeds(struct feed **feeds) +static struct feed ** +feeds_update(struct feed **feeds, struct json_object *jarray) { - struct json_object *rp, *rq, *jfeed, *j; int i, n, id; + struct json_object *jfeed, *j; + const char *url, *title; struct feed *feed, **tmp; - const char *title, *url; - - log_debug("ws_update_feeds()"); - rq = ws_request_new("getFeeds"); - - rp = ws_execute(rq); - - json_object_put(rq); - - if (rp) { - n = json_object_array_length(rp); + if (jarray) { + n = json_object_array_length(jarray); for (i = 0; i < n; i++) { - jfeed = json_object_array_get_idx(rp, i); + jfeed = json_object_array_get_idx(jarray, i); j = json_object_object_get(jfeed, "id"); id = json_object_get_int(j); - + feed = feeds_get_feed(feeds, id); if (!feed) { @@ -383,10 +376,34 @@ struct feed **ws_update_feeds(struct feed **feeds) ws_update_headlines(feed); } + } + + return feeds; +} + +struct feed **ws_update_feeds(struct feed **feeds) +{ + struct json_object *rp, *rq; + + log_debug("ws_update_feeds()"); + + rq = ws_request_new("getFeeds"); + ws_request_add_att_int(rq, "cat_id", 0); + + rp = ws_execute(rq); + + if (rp) { + feeds = feeds_update(feeds, rp); + json_object_put(rp); + } + + ws_request_add_att_int(rq, "cat_id", -3); + rp = ws_execute(rq); + json_object_put(rq); + + if (rp) { + feeds = feeds_update(feeds, rp); json_object_put(rp); - } else { - feeds_free(feeds); - feeds = NULL; } log_debug("ws_update_feeds() done"); -- 2.7.4