fixed code style
[prss.git] / src / ttrss_ws.c
index 4b9c040..e9680f4 100644 (file)
@@ -103,6 +103,8 @@ static const char *ws_reply_get_error(struct json_object *content)
 {
        struct json_object *jerror;
 
+       log_debug("ws_reply_get_error");
+
        if (json_object_get_type(content) != json_type_object)
                return NULL;
 
@@ -131,8 +133,11 @@ execute(struct http_session *sess, struct json_object *rq, char **err)
                        str = ws_reply_get_error(content);
 
                        if (str) {
-                               *err = strdup(str);
+                               log_debug("execute() err=%s", str);
                                content = NULL;
+
+                               if (err)
+                                       *err = strdup(str);
                        } else {
                                json_object_get(content);
                        }
@@ -141,6 +146,8 @@ execute(struct http_session *sess, struct json_object *rq, char **err)
                json_object_put(rp);
        }
 
+       log_debug("execute() done");
+
        return content;
 }
 
@@ -245,7 +252,6 @@ int ws_open_session()
                        session_id = NULL;
                        result = 0;
                }
-               result = 1;
        } else {
                result =  0;
        }
@@ -253,32 +259,56 @@ int ws_open_session()
        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)
@@ -290,7 +320,6 @@ 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);
 
@@ -315,10 +344,6 @@ int ws_update_headlines(struct feed *feed)
                                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);
 
@@ -331,6 +356,12 @@ int ws_update_headlines(struct feed *feed)
                        j = json_object_object_get(jheadline, "unread");
                        h->unread = json_object_get_boolean(j);
                }
+
+               if (!feed->headlines) {
+                       feed->headlines = malloc(sizeof(struct headline *));
+                       *(feed->headlines) = NULL;
+               }
+
                json_object_put(rp);
                return 1;
        } else {