X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=blobdiff_plain;f=src%2Fttrss.c;h=92285198f055f8b63cf942d690afec4068ca0f3c;hp=3649b071efb1f98dc70c5592b08659ca9aa47747;hb=c228345525be4912e6b5acec7525dc056313f315;hpb=0d88bb9ed245be97f3120dad9c3c1604cd9c4183 diff --git a/src/ttrss.c b/src/ttrss.c index 3649b07..9228519 100644 --- a/src/ttrss.c +++ b/src/ttrss.c @@ -37,9 +37,9 @@ static int list_length(void **list) if (!list) return 0; - + n = 0; - while(*list) { + while (*list) { n++; list++; } @@ -65,6 +65,11 @@ static void **list_add(void **list, void *item) return result; } +struct headline ** +headlines_add(struct headline **list, struct headline *h) +{ + return (struct headline **)list_add((void **)list, (void *)h); +} struct headline *feed_get_headline(struct feed *feed, int id) { @@ -236,22 +241,21 @@ char *ws_get_article_content(int id) rq = ws_request_new("getArticle"); ws_request_add_att_int(rq, "article_id", id); - + rp = ws_execute(rq); - + json_object_put(rq); str = NULL; if (rp) { item = json_object_array_get_idx(rp, 0); - + if (item) { content = json_object_object_get(item, "content"); - str = strdup(json_object_get_string(content)); } - + json_object_put(rp); } @@ -279,24 +283,30 @@ int ws_update_headlines(struct feed *feed) j = json_object_object_get(jheadline, "id"); hid = json_object_get_int(j); h = feed_get_headline(feed, hid); - + if (!h) { h = malloc(sizeof(struct headline)); h->id = hid; h->excerpt = NULL; h->content = NULL; - - tmp = (struct headline **)list_add((void **)feed->headlines, h); + h->title = NULL; + h->url = NULL; + + tmp = headlines_add(feed->headlines, h); if (feed->headlines) free(feed->headlines); feed->headlines = tmp; } - j = json_object_object_get(jheadline, "title"); - h->title = strdup(json_object_get_string(j)); + if (!h->title) { + j = json_object_object_get(jheadline, "title"); + h->title = strdup(json_object_get_string(j)); + } - j = json_object_object_get(jheadline, "link"); - h->url = strdup(json_object_get_string(j)); + if (!h->url) { + j = json_object_object_get(jheadline, "link"); + h->url = strdup(json_object_get_string(j)); + } j = json_object_object_get(jheadline, "unread"); h->unread = json_object_get_boolean(j); @@ -318,7 +328,6 @@ const char *ttrss_get_headline_content(struct headline *h) return h->content; } - struct feed **ttrss_get_feeds() { struct json_object *rp, *rq, *content, *jfeed, *j; @@ -392,7 +401,7 @@ void ttrss_set_article_unread(int id, int unread) json_object_object_add(rq, "mode", json_object_new_int(unread)); rp = http_json_get(session_url, rq); - + json_object_put(rq); json_object_put(rp); }