} else {
log_debug("ttrss_get_headline_content: cache miss");
content = ws_get_article_content(h->id);
- cache_put(h, content);
+ cache_put(h->id, content);
}
return content;
return feeds_get_headline(data, id);
}
+static void get_article_content_cbk(int id, const char *content)
+{
+ printf("get_article_content_cbk %d\n", id);
+
+ if (content)
+ cache_put(id, content);
+}
+
void ttrs_download_headline_content(struct feed **feeds)
{
struct feed **fcur;
(*fcur)->title);
while (hcur && *hcur) {
- if (!cache_exists(*hcur))
- free(ttrss_get_headline_content(*hcur));
+ if (!cache_exists(*hcur)) {
+ ws_async_get_article_content
+ ((*hcur)->id, get_article_content_cbk);
+ }
hcur++;
}
}
return cache_dir;
}
-static gchar *content_get_path(const struct headline *h)
+static gchar *content_get_path(int id)
{
const char *cache_dir;
cache_dir = get_cache_dir();
if (cache_dir)
- return g_strdup_printf("%s/%d", cache_dir, h->id);
+ return g_strdup_printf("%s/%d", cache_dir, id);
return NULL;
}
}
}
-void cache_put(const struct headline *h, const char *content)
+void cache_put(int id, const char *content)
{
char *path;
- path = content_get_path(h);
+ path = content_get_path(id);
if (path) {
pthread_mutex_lock(&lock);
char *path;
int result;
- path = content_get_path(h);
+ path = content_get_path(h->id);
pthread_mutex_lock(&lock);
if (stat(path, &s) == -1)
char *content, *path;
- path = content_get_path(h);
+ path = content_get_path(h->id);
if (path) {
pthread_mutex_lock(&lock);
content = file_get_content(path);
int cache_exists(const struct headline *h);
char *cache_get(const struct headline *h);
-void cache_put(const struct headline *h, const char *content);
+void cache_put(int id, const char *content);
#endif
return result;
}
-char *ws_get_article_content(int id)
+struct json_object *ws_request_new_get_article_content(int id)
{
- struct json_object *rp, *rq, *content, *item;
- char *str;
+ struct json_object *rq;
rq = ws_request_new("getArticle");
ws_request_add_att_int(rq, "article_id", id);
- rp = ws_execute(rq);
-
- json_object_put(rq);
+ return rq;
+}
- str = NULL;
+const char *ws_reply_get_article_content(struct json_object *rp)
+{
+ struct json_object *item, *content;
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));
+ return json_object_get_string(content);
}
+ }
- json_object_put(rp);
+ return NULL;
+}
+
+char *ws_get_article_content(int id)
+{
+ struct json_object *rp, *rq;
+ const char *content;
+ char *str;
+
+ rq = ws_request_new("getArticle");
+ ws_request_add_att_int(rq, "article_id", id);
+
+ rp = ws_execute(rq);
+
+ json_object_put(rq);
+
+ if (rp) {
+ content = ws_reply_get_article_content(rp);
+
+ if (content) {
+ str = strdup(content);
+ json_object_put(rp);
+ return str;
+ }
}
- return str;
+ return NULL;
}
int ws_update_headlines(struct feed *feed)
rq = ws_request_new("getHeadlines");
ws_request_add_att_int(rq, "feed_id", feed->id);
- ws_request_add_att_bool(rq, "show_excerpt", 1);
rp = ws_execute(rq);
h = headline_new(hid, url, title);
j = json_object_object_get(jheadline,
- "excerpt");
- h->excerpt = strdup(json_object_get_string(j));
-
- j = json_object_object_get(jheadline,
"updated");
h->date = json_object_get_int(j);
int ws_update_headlines(struct feed *feed);
char *ws_get_article_content(int id);
void ws_set_article_unread(int id, int unread);
+
struct json_object *ws_request_new_set_article_unread(int id, int unread);
+struct json_object *ws_request_new_get_article_content(int id);
+const char *ws_reply_get_article_content(struct json_object *);
#endif
* 02110-1301 USA
*/
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
json_object_put(rp);
cur++;
- usleep(100000);
+ usleep(500000);
}
free(tmp);
}
log_debug("ws_async_set_article_unread(%d,%d) done", id, unread);
}
+
+struct cbk_data {
+ int id;
+ void (*callback)(int id, const char *);
+};
+
+void async_article_content_cbk(struct json_object *rp, void *userdata)
+{
+ struct cbk_data *data;
+
+ data = userdata;
+
+ log_debug("async_article_content_cbk %d\n", data->id);
+
+ if (data->callback)
+ data->callback(data->id, ws_reply_get_article_content(rp));
+
+ free(data);
+}
+
+
+void
+ws_async_get_article_content(int id, void (*callback)(int id, const char *))
+{
+ struct json_object *rq;
+ struct cbk_data *data;
+
+ rq = ws_request_new_get_article_content(id);
+
+ data = malloc(sizeof(struct cbk_data));
+ data->id = id;
+ data->callback = callback;
+
+ add_async_request(rq, async_article_content_cbk, data);
+}
#include "ttrss_ws.h"
void ws_async_set_article_unread(int id, int unread);
+void
+ws_async_get_article_content(int id, void (*callback)(int id, const char *));
#endif