-
- return v;
-}
-
-char *ws_login()
-{
- struct json_object *rq, *rp, *j;
- char *str;
-
- rq = ws_request_new("login");
- ws_request_add_att_str(rq, "user", session_user);
- ws_request_add_att_str(rq, "password", session_pwd);
-
- rp = ws_execute(rq);
- json_object_put(rq);
-
- if (rp) {
- j = json_object_object_get(rp, "session_id");
- str = strdup(json_object_get_string(j));
-
- json_object_put(rp);
- } else {
- str = NULL;
- }
-
- return str;
-}
-
-int ws_open_session()
-{
- int version, result;
-
- if (session_id)
- free(session_id);
-
- session_id = ws_login();
-
- if (session_id) {
- version = ws_get_api_version();
- printf("API version: %d\n", version);
-
- if (version > 0) {
- result = 1;
- } else {
- free(session_id);
- session_id = NULL;
- result = 0;
- }
- } else {
- result = 0;
- }
-
- return result;
-}
-
-char *ws_get_article_content(int id)
-{
- struct json_object *rp, *rq, *content, *item;
- char *str;
-
- rq = ws_request_new("getArticle");
- ws_request_add_att_int(rq, "article_id", id);
-
- rp = ws_execute(rq);
-
- json_object_put(rq);
-
- str = NULL;
-
- 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));
- }
-
- json_object_put(rp);
- }
-
- return str;
-}
-
-int ws_update_headlines(struct feed *feed)
-{
- struct json_object *rp, *rq, *jheadline, *j;
- int i, n, err, hid;
- struct headline *h, **tmp;
-
- rq = ws_request_new("getHeadlines");
- ws_request_add_att_int(rq, "feed_id", feed->id);
-
- rp = ws_execute(rq);
-
- json_object_put(rq);
-
- if (rp) {
- n = json_object_array_length(rp);
- for (i = 0; i < n; i++) {
- jheadline = json_object_array_get_idx(rp, i);
-
- j = json_object_object_get(jheadline, "id");
- hid = json_object_get_int(j);
- h = feed_get_headline(feed, hid);
-
- if (!h) {
- h = malloc(sizeof(struct headline));
- h->id = hid;
- h->excerpt = NULL;
- h->content = NULL;
- h->title = NULL;
- h->url = NULL;
-
- tmp = headlines_add(feed->headlines, h);
- if (feed->headlines)
- free(feed->headlines);
- feed->headlines = tmp;
- }
-
- if (!h->title) {
- j = json_object_object_get(jheadline, "title");
- h->title = strdup(json_object_get_string(j));
- }
-
- if (!h->url) {
- j = json_object_object_get(jheadline, "link");
- h->url = strdup(json_object_get_string(j));
- }
-
- j = json_object_object_get(jheadline, "unread");
- h->unread = json_object_get_boolean(j);
- }
- err = 0;
- } else {
- err = 1;
- }
-
- json_object_put(rp);
- return !err;