X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fttrss_model.c;h=3cba7360eef94dc5d20cec558471bf1d117d2e9a;hb=09a826a93753ebb1b82fbc30574c034f084e02b8;hp=c67ad65192fa181df3d90e186d4764e1856838e2;hpb=3b14915e76fc7a05512e0523afd39556c0a14567;p=prss.git diff --git a/src/ttrss_model.c b/src/ttrss_model.c index c67ad65..3cba736 100644 --- a/src/ttrss_model.c +++ b/src/ttrss_model.c @@ -18,6 +18,7 @@ */ #include +#include #include #include "ttrss_model.h" @@ -81,8 +82,59 @@ struct headline *feed_get_headline(struct feed *feed, int id) return NULL; } +void headline_free(struct headline *headline) +{ + if (headline) { + free(headline->url); + free(headline->title); + free(headline->excerpt); + free(headline->content); + free(headline); + } +} + +struct headline *headline_new(int id, const char *url, const char *title) +{ + struct headline *h; + + h = malloc(sizeof(struct headline)); + h->id = id; + h->url = strdup(url); + h->title = strdup(title); + h->unread = -1; + h->excerpt = NULL; + h->content = NULL; + + return h; +} + void headlines_free(struct headline **headlines) { + struct headline **cur; + + if (headlines) { + cur = headlines; + while (*cur) { + headline_free(*cur); + cur++; + } + free(headlines); + } +} + +struct feed *feed_new(int id, const char *url, const char *title) +{ + struct feed *f; + + f = malloc(sizeof(struct feed)); + + f->id = id; + f->url = strdup(url); + f->title = strdup(title); + f->unread = -1; + f->headlines = NULL; + + return f; } void feed_free(struct feed *feed) @@ -110,3 +162,34 @@ void feeds_free(struct feed **feeds) free(feeds); } } + +struct feed *feeds_get_feed(struct feed **feeds, int id) +{ + struct feed **cur; + + if (feeds) + for (cur = feeds; *cur; cur++) + if ((*cur)->id == id) + return *cur; + + return NULL; +} + +struct headline *feeds_get_headline(struct feed **feeds, int id) +{ + struct headline *h; + + if (!feeds) + return NULL; + + while (*feeds) { + h = feed_get_headline(*feeds, id); + + if (h) + return h; + + feeds++; + } + + return NULL; +}