log.h \
ttrss.c \
ttrss.h \
+ ttrss_cache.c \
+ ttrss_cache.h \
ttrss_model.c \
ttrss_model.h \
ttrss_ws.c \
PROGRAMS = $(bin_PROGRAMS)
am_prss_OBJECTS = main.$(OBJEXT) http.$(OBJEXT) io.$(OBJEXT) \
list.$(OBJEXT) log.$(OBJEXT) ttrss.$(OBJEXT) \
- ttrss_model.$(OBJEXT) ttrss_ws.$(OBJEXT) \
+ ttrss_cache.$(OBJEXT) ttrss_model.$(OBJEXT) ttrss_ws.$(OBJEXT) \
ttrss_wsasync.$(OBJEXT) url.$(OBJEXT) webbrowser.$(OBJEXT)
prss_OBJECTS = $(am_prss_OBJECTS)
prss_LDADD = $(LDADD)
log.h \
ttrss.c \
ttrss.h \
+ ttrss_cache.c \
+ ttrss_cache.h \
ttrss_model.c \
ttrss_model.h \
ttrss_ws.c \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_cache.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_model.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_ws.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_wsasync.Po@am__quote@
void update()
{
- struct feed **feeds;
+ struct feed **feeds, **cur;
GtkListStore *model, *headline_model;
GtkTreeIter iter;
char *title;
gtk_list_store_clear(headline_model);
log_debug("update(): clear feed tree done.");
feeds = ttrss_get_feeds();
- while (feeds && *feeds) {
- title = feed_get_formated_title(*feeds);
+ cur = feeds;
+ while (cur && *cur) {
+ title = feed_get_formated_title(*cur);
gtk_list_store_append(model, &iter);
gtk_list_store_set(model,
&iter,
COL_FEED_TITLE, title,
- COL_FEED_ID, (*feeds)->id,
+ COL_FEED_ID, (*cur)->id,
-1);
g_free(title);
- feeds++;
+ cur++;
}
ttrs_download_headline_content(feeds);
#include <sys/stat.h>
#include <unistd.h>
-
#include <glib.h>
#include <json/json.h>
#include "http.h"
#include "io.h"
#include "log.h"
+#include "ttrss_cache.h"
#include "ttrss_wsasync.h"
#include "url.h"
static struct feed **data;
-static char *cache_dir;
-
-static const char *get_cache_dir()
-{
- char *home;
-
- if (!cache_dir) {
- home = getenv("HOME");
-
- if (!home)
- return NULL;
-
- cache_dir = path_append(home, ".prss/cache");
- mkdirs(cache_dir, 0777);
- }
-
- return cache_dir;
-}
-
-static void file_set_content(const char *path, const char *content)
-{
- FILE *fp;
-
- log_debug("file_set_content(): path=%s", path);
-
- fp = fopen(path, "w");
- if (fp) {
- fwrite(content, 1, strlen(content), fp);
- fclose(fp);
- }
-}
-
-static gchar *content_get_path(const struct headline *h)
-{
- const char *cache_dir;
-
- cache_dir = get_cache_dir();
- if (cache_dir)
- return g_strdup_printf("%s/%d", cache_dir, h->id);
-
- return NULL;
-}
-
-static int is_content_cached(const struct headline *h)
-{
- struct stat s;
- char *path;
- int result;
-
- path = content_get_path(h);
-
- if (stat(path, &s) == -1)
- result = 0;
- else
- result = 1;
-
- g_free(path);
-
- return result;
-}
-
char *ttrss_get_headline_content(struct headline *h)
{
- char *path, *content;
+ char *content;
- path = content_get_path(h);
- if (path)
- content = file_get_content(path);
- else
- content = NULL;
+ content = cache_get(h);
- if (!content) {
+ if (content) {
+ log_debug("ttrss_get_headline_content: cache hit");
+ } else {
+ log_debug("ttrss_get_headline_content: cache miss");
content = ws_get_article_content(h->id);
- file_set_content(path, content);
+ cache_put(h, content);
}
- g_free(path);
-
return content;
}
struct feed **fcur;
struct headline **hcur;
+ log_debug("ttrs_download_headline_content");
+
for (fcur = feeds; *fcur; fcur++) {
hcur = ttrss_feed_get_headlines(*fcur);
+ log_debug("ttrs_download_headline_content(): %s",
+ (*fcur)->title);
+
while (hcur && *hcur) {
- if (!is_content_cached(*hcur))
+ if (!cache_exists(*hcur))
free(ttrss_get_headline_content(*hcur));
hcur++;
}
--- /dev/null
+/*
+ * Copyright (C) 2010-2013 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "io.h"
+#include "log.h"
+#include "ttrss_cache.h"
+
+static char *cache_dir;
+
+static const char *get_cache_dir()
+{
+ char *home;
+
+ if (!cache_dir) {
+ home = getenv("HOME");
+
+ if (!home)
+ return NULL;
+
+ cache_dir = path_append(home, ".prss/cache");
+ mkdirs(cache_dir, 0777);
+ }
+
+ return cache_dir;
+}
+
+static gchar *content_get_path(const struct headline *h)
+{
+ const char *cache_dir;
+
+ cache_dir = get_cache_dir();
+ if (cache_dir)
+ return g_strdup_printf("%s/%d", cache_dir, h->id);
+
+ return NULL;
+}
+
+static void file_set_content(const char *path, const char *content)
+{
+ FILE *fp;
+
+ log_debug("file_set_content(): path=%s", path);
+
+ fp = fopen(path, "w");
+ if (fp) {
+ fwrite(content, 1, strlen(content), fp);
+ fclose(fp);
+ }
+}
+
+void cache_put(const struct headline *h, const char *content)
+{
+ char *path;
+
+ path = content_get_path(h);
+
+ if (path)
+ file_set_content(path, content);
+
+ g_free(path);
+}
+
+int cache_exists(const struct headline *h)
+{
+ struct stat s;
+ char *path;
+ int result;
+
+ path = content_get_path(h);
+
+ if (stat(path, &s) == -1)
+ result = 0;
+ else
+ result = 1;
+
+ g_free(path);
+
+ return result;
+}
+
+char *cache_get(const struct headline *h)
+{
+ char *content, *path;
+
+ path = content_get_path(h);
+ if (path)
+ content = file_get_content(path);
+ else
+ content = NULL;
+
+ g_free(path);
+
+ return content;
+}
--- /dev/null
+/*
+ * Copyright (C) 2010-2013 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef _TTRSS_CACHE_H_
+#define _TTRSS_CACHE_H_
+
+#include "ttrss_model.h"
+
+int cache_exists(const struct headline *h);
+char *cache_get(const struct headline *h);
+void cache_put(const struct headline *h, const char *content);
+
+#endif