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
25 #include <json/json.h>
30 #include "ttrss_wsasync.h"
33 static struct feed **data;
34 static char *cache_dir;
36 static const char *get_cache_dir()
41 home = getenv("HOME");
46 cache_dir = path_append(home, ".prss/cache");
47 mkdirs(cache_dir, 0777);
53 static void file_set_content(const char *path, const char *content)
57 fp = fopen(path, "w");
59 fwrite(content, 1, strlen(content), fp);
64 char *ttrss_get_headline_content(struct headline *h)
66 const char *cache_dir;
69 cache_dir = get_cache_dir();
71 path = g_strdup_printf("%s/%d", cache_dir, h->id);
73 content = file_get_content(path);
76 content = ws_get_article_content(h->id);
77 file_set_content(path, content);
88 struct feed **ttrss_get_feeds()
90 data = ws_update_feeds(data);
95 struct headline **ttrss_feed_get_headlines(struct feed *f)
98 ws_update_headlines(f);
103 void ttrss_set_article_unread(int id, int unread)
105 log_debug("ttrss_set_article_unread(%d,%d)", id, unread);
107 ws_async_set_article_unread(id, unread);
109 log_debug("ttrss_set_article_unread(%d,%d)", id, unread);
112 void ttrss_set_config(const char *url, const char *user, const char *pwd)
116 ws_set_config(url, user, pwd);
119 struct feed *ttrss_get_feed(int id)
121 return feeds_get_feed(data, id);
124 struct headline *ttrss_get_headline(int id)
126 return feeds_get_headline(data, id);