X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=blobdiff_plain;f=src%2Fttrss_ws.c;h=94f0feee6324d7a0e8bc868f4cde024117ffe281;hp=3b979c8ee899f5f78a0b837a557205cc1e374933;hb=4e2d7bd36f2aada1e8c5addb204525294c4725e0;hpb=ba047027e5c6b1f6e2ec6ae5846a37f5c44dc412 diff --git a/src/ttrss_ws.c b/src/ttrss_ws.c index 3b979c8..94f0fee 100644 --- a/src/ttrss_ws.c +++ b/src/ttrss_ws.c @@ -17,12 +17,14 @@ * 02110-1301 USA */ +#include #include #include #include #include "http.h" +#include "log.h" #include "ttrss_ws.h" #include "url.h" @@ -141,14 +143,15 @@ char *ws_login() rp = ws_execute(rq); json_object_put(rq); + str = NULL; if (rp) { j = json_object_object_get(rp, "session_id"); - str = strdup(json_object_get_string(j)); + + if (j) + str = strdup(json_object_get_string(j)); json_object_put(rp); - } else { - str = NULL; - } + } return str; } @@ -164,7 +167,7 @@ int ws_open_session() if (session_id) { version = ws_get_api_version(); - printf("API version: %d\n", version); + log_debug("API version= %d", version); if (version > 0) { result = 1; @@ -211,7 +214,7 @@ char *ws_get_article_content(int id) int ws_update_headlines(struct feed *feed) { struct json_object *rp, *rq, *jheadline, *j; - int i, n, err, hid; + int i, n, hid; struct headline *h, **tmp; const char *title, *url; @@ -249,13 +252,11 @@ int ws_update_headlines(struct feed *feed) j = json_object_object_get(jheadline, "unread"); h->unread = json_object_get_boolean(j); } - err = 0; + json_object_put(rp); + return 1; } else { - err = 1; + return 0; } - - json_object_put(rp); - return !err; } struct feed **ws_update_feeds(struct feed **feeds) @@ -265,7 +266,7 @@ struct feed **ws_update_feeds(struct feed **feeds) struct feed *feed, **tmp; const char *title, *url; - printf("ttrss_get_feeds\n"); + log_debug("ws_update_feeds()"); rq = ws_request_new("getFeeds"); @@ -295,21 +296,39 @@ struct feed **ws_update_feeds(struct feed **feeds) tmp = feeds_add(feeds, feed); free(feeds); feeds = tmp; - } else { - printf("found!\n"); } j = json_object_object_get(jfeed, "unread"); feed->unread = json_object_get_int(j); } + json_object_put(rp); } else { feeds_free(feeds); feeds = NULL; } - json_object_put(rp); - - printf("ttrss_get_feeds ended\n"); + log_debug("ws_update_feeds() done"); return feeds; } + +void ws_set_article_unread(int id, int unread) +{ + struct json_object *rp, *rq; + + log_debug("ws_set_article_unread(%d,%d)", id, unread); + + rq = ws_request_new("updateArticle"); + json_object_object_add(rq, "article_ids", json_object_new_int(id)); + json_object_object_add(rq, "field", json_object_new_int(2)); + json_object_object_add(rq, "mode", json_object_new_int(unread)); + + rp = ws_execute(rq); + + json_object_put(rq); + + if (rp) + json_object_put(rp); + + log_debug("ws_set_article_unread(%d,%d) done", id, unread); +}