2 * Copyright (C) 2010-2013 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <sys/types.h>
28 #include <json/json.h>
33 #include "ttrss_cache.h"
34 #include "ttrss_wsasync.h"
37 static struct feed **data;
38 char *ttrss_get_headline_content(struct headline *h)
42 content = cache_get(h);
45 log_debug("ttrss_get_headline_content: cache hit");
47 log_debug("ttrss_get_headline_content: cache miss");
48 content = ws_get_article_content(h->id);
49 cache_put(h->id, content);
55 struct feed **ttrss_get_feeds()
57 data = ws_update_feeds(data);
62 struct headline **ttrss_feed_get_headlines(struct feed *f)
65 ws_update_headlines(f);
70 void ttrss_set_article_unread(int id, int unread)
72 log_debug("ttrss_set_article_unread(%d,%d)", id, unread);
74 ws_async_set_article_unread(id, unread);
76 log_debug("ttrss_set_article_unread(%d,%d)", id, unread);
79 void ttrss_set_config(const char *url, const char *user, const char *pwd)
83 ws_set_config(url, user, pwd);
86 struct feed *ttrss_get_feed(int id)
88 return feeds_get_feed(data, id);
91 struct headline *ttrss_get_headline(int id)
93 return feeds_get_headline(data, id);
96 static void get_article_content_cbk(int id, const char *content)
98 printf("get_article_content_cbk %d\n", id);
101 cache_put(id, content);
104 void ttrs_download_headline_content(struct feed **feeds)
107 struct headline **hcur;
109 log_debug("ttrs_download_headline_content");
111 for (fcur = feeds; *fcur; fcur++) {
112 hcur = ttrss_feed_get_headlines(*fcur);
114 log_debug("ttrs_download_headline_content(): %s",
117 while (hcur && *hcur) {
118 if (!cache_exists(*hcur)) {
119 ws_async_get_article_content
120 ((*hcur)->id, get_article_content_cbk);