X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=blobdiff_plain;f=src%2Fttrss.c;h=89fbd94bd4b6edf5047e7dd18a2806e1ecd2a117;hp=78884c1e37ba807391f6e6abc0e7ae8d376a4cd8;hb=6ad7426a45d5a4e76cbd67d2759b9f5e236443f6;hpb=a7e89c999775c195f8b7759f4c283fcedb041a9e diff --git a/src/ttrss.c b/src/ttrss.c index 78884c1..89fbd94 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -94,93 +94,115 @@ void ttrss_login(const char *url, const char *user, const char *password) json_object_put(rp); } -struct feed **ttrss_get_feeds() +static struct headline **get_headlines(int feed_id) { - struct json_object *rp, *rq, *content, *jfeed, *j; + struct json_object *rp, *rq, *content, *jheadline, *j; int i, n; - struct feed **feeds, *feed; + struct headline **headlines, *h; - rq = create_op("getFeeds"); + printf("get_headlines %d\n", feed_id); + + rq = create_op("getHeadlines"); + json_object_object_add(rq, "feed_id", json_object_new_int(feed_id)); + json_object_object_add(rq, "show_excerpt", json_object_new_boolean(1)); + json_object_object_add(rq, "show_content", json_object_new_boolean(1)); rp = post_json_object(session_url, rq); + json_object_put(rq); content = json_object_object_get(rp, "content"); if (content) { n = json_object_array_length(content); - - feeds = malloc((n+1) * sizeof(struct feed *)); + headlines = malloc((n+1)*sizeof(struct headline *)); for (i = 0; i < n; i++) { - jfeed = json_object_array_get_idx(content, i); + jheadline = json_object_array_get_idx(content, i); - feed = malloc(sizeof(struct feed)); + h = malloc(sizeof(struct headline)); - j = json_object_object_get(jfeed, "title"); - feed->title = strdup(json_object_get_string(j)); + j = json_object_object_get(jheadline, "title"); + h->title = strdup(json_object_get_string(j)); - j = json_object_object_get(jfeed, "feed_url"); - feed->url = strdup(json_object_get_string(j)); + j = json_object_object_get(jheadline, "excerpt"); + h->excerpt = strdup(json_object_get_string(j)); - j = json_object_object_get(jfeed, "id"); - feed->id = json_object_get_int(j); + j = json_object_object_get(jheadline, "content"); + h->content = strdup(json_object_get_string(j)); - feed->headlines = ttrss_get_headlines(feed->id); + j = json_object_object_get(jheadline, "unread"); + h->unread = json_object_get_boolean(j); - feeds[i] = feed; + headlines[i] = h; } - feeds[n] = NULL; + headlines[n] = NULL; } else { - feeds = NULL; + headlines = NULL; } json_object_put(rp); - return feeds; + printf("get_headlines %d end\n", feed_id); + + return headlines; } -struct headline **ttrss_get_headlines(int feed_id) +struct feed **ttrss_get_feeds() { - struct json_object *rp, *rq, *content, *jheadline, *j; + struct json_object *rp, *rq, *content, *jfeed, *j; int i, n; - struct headline **headlines, *h; + struct feed **feeds, *feed; - rq = create_op("getHeadlines"); - json_object_object_add(rq, "feed_id", json_object_new_int(feed_id)); - json_object_object_add(rq, "show_excerpt", json_object_new_boolean(1)); - json_object_object_add(rq, "show_content", json_object_new_boolean(1)); + printf("ttrss_get_feeds\n"); - rp = post_json_object(session_url, rq); + rq = create_op("getFeeds"); + rp = post_json_object(session_url, rq); json_object_put(rq); content = json_object_object_get(rp, "content"); if (content) { n = json_object_array_length(content); - headlines = malloc((n+1)*sizeof(struct headline *)); + + feeds = malloc((n+1) * sizeof(struct feed *)); for (i = 0; i < n; i++) { - jheadline = json_object_array_get_idx(content, i); + jfeed = json_object_array_get_idx(content, i); - h = malloc(sizeof(struct headline)); + feed = malloc(sizeof(struct feed)); - j = json_object_object_get(jheadline, "title"); - h->title = strdup(json_object_get_string(j)); + j = json_object_object_get(jfeed, "title"); + feed->title = strdup(json_object_get_string(j)); - j = json_object_object_get(jheadline, "excerpt"); - h->excerpt = strdup(json_object_get_string(j)); + j = json_object_object_get(jfeed, "feed_url"); + feed->url = strdup(json_object_get_string(j)); - j = json_object_object_get(jheadline, "content"); - h->content = strdup(json_object_get_string(j)); + j = json_object_object_get(jfeed, "id"); + feed->id = json_object_get_int(j); - headlines[i] = h; + j = json_object_object_get(jfeed, "unread"); + feed->unread = json_object_get_int(j); + + feed->headlines = NULL; + + feeds[i] = feed; } - headlines[n] = NULL; + feeds[n] = NULL; } else { - headlines = NULL; + feeds = NULL; } json_object_put(rp); - return headlines; + printf("ttrss_get_feeds ended\n"); + + return feeds; +} + +struct headline **ttrss_get_headlines(struct feed *f) +{ + if (!f->headlines) + f->headlines = get_headlines(f->id); + + return f->headlines; }