Description: Replace deprecated function calls
 json_object_object_get that were deprecated with the release of json-c 0.12
Origin: upstream, https://github.com/akrennmair/newsbeuter/commit/0adf49fb86abf334f33dd925541771e741caeac4

--- a/src/feedhq_api.cpp
+++ b/src/feedhq_api.cpp
@@ -131,29 +131,41 @@
 
 	// TODO: parse result
 
-	struct json_object * reply = json_tokener_parse(result.c_str());
+	json_object * reply = json_tokener_parse(result.c_str());
 	if (is_error(reply)) {
 		LOG(LOG_ERROR, "feedhq_api::get_subscribed_urls: failed to parse response as JSON.");
 		return urls;
 	}
 
-
-	struct json_object * subscription_obj = json_object_object_get(reply, "subscriptions");
-	struct array_list * subscriptions = json_object_get_array(subscription_obj);
+	json_object* subscription_obj {};
+	json_object_object_get_ex(reply, "subscriptions", &subscription_obj);
+	array_list * subscriptions = json_object_get_array(subscription_obj);
 
 	int len = array_list_length(subscriptions);
 
 	for (int i=0; i<len; i++) {
 		std::vector<std::string> tags;
-		struct json_object * sub = json_object_array_get_idx(subscription_obj, i);
+		json_object * sub = json_object_array_get_idx(subscription_obj, i);
+
+		json_object* id_str {};
+		json_object_object_get_ex(sub, "id", &id_str);
+		const char * id = json_object_get_string(id_str);
+
+		json_object* title_str {};
+		json_object_object_get_ex(sub, "title", &title_str);
+		const char * title = json_object_get_string(title_str);
 
-		const char * id = json_object_get_string(json_object_object_get(sub, "id"));
-		const char * title = json_object_get_string(json_object_object_get(sub, "title"));
 		tags.push_back(std::string("~") + title);
 
 		char * escaped_id = curl_easy_escape(handle, id, 0);
 
-		urls.push_back(tagged_feedurl(utils::strprintf("%s%s%s?n=%u", cfg->get_configvalue("feedhq-url").c_str(), FEEDHQ_FEED_PREFIX, escaped_id, cfg->get_configvalue_as_int("feedhq-min-items")), tags));
+		auto url = utils::strprintf(
+				"%s%s%s?n=%u",
+				cfg->get_configvalue("feedhq-url").c_str(),
+				FEEDHQ_FEED_PREFIX,
+				escaped_id,
+				cfg->get_configvalue_as_int("feedhq-min-items"));
+		urls.push_back(tagged_feedurl(url, tags));
 
 		curl_free(escaped_id);
 	}
--- a/src/newsblur_api.cpp
+++ b/src/newsblur_api.cpp
@@ -24,11 +24,11 @@
 }
 
 bool newsblur_api::authenticate() {
-	json_object * response;
-	json_object * status;
+	json_object * response {};
+	json_object * status {};
 
 	response = newsblur_api::query_api("/api/login", &auth_info);
-	status = json_object_object_get(response, "authenticated");
+	json_object_object_get_ex(response, "authenticated", &status);
 	bool result = json_object_get_boolean(status);
 	LOG(LOG_INFO, "newsblur_api::authenticate: authentication resulted in %u, cached in %s", result, cfg->get_configvalue("cookie-cache").c_str());
 	return result;
@@ -39,22 +39,23 @@
 
 	json_object * response = query_api("/reader/feeds", NULL);
 
-	json_object * feeds = json_object_object_get(response, "feeds");
+	json_object * feeds {};
+	json_object_object_get_ex(response, "feeds", &feeds);
 
 	json_object_iterator it = json_object_iter_begin(feeds);
 	json_object_iterator itEnd = json_object_iter_end(feeds);
 
 	while (!json_object_iter_equal(&it, &itEnd)) {
 		const char * feed_id = json_object_iter_peek_name(&it);
-		json_object * node;
+		json_object * node {};
 		rsspp::feed current_feed;
 
 		current_feed.rss_version = rsspp::NEWSBLUR_JSON;
 
 		json_object * feed_json = json_object_iter_peek_value(&it);
-		node = json_object_object_get(feed_json, "feed_title");
+		json_object_object_get_ex(feed_json, "feed_title", &node);
 		current_feed.title = json_object_get_string(node);
-		node = json_object_object_get(feed_json, "feed_link");
+		json_object_object_get_ex(feed_json, "feed_link", &node);
 		current_feed.link = json_object_get_string(node);
 
 		known_feeds[feed_id] = current_feed;
@@ -73,11 +74,12 @@
 }
 
 bool request_successfull(json_object * payload) {
-	json_object * result = json_object_object_get(payload, "result");
-	if (result == NULL)
+	json_object * result {};
+	if(json_object_object_get_ex(payload, "result", &result) == FALSE) {
 		return false;
-
-	return !strcmp("ok", json_object_get_string(result));
+	} else {
+		return !strcmp("ok", json_object_get_string(result));
+	}
 }
 
 bool newsblur_api::mark_all_read(const std::string& feed_url) {
@@ -132,9 +134,10 @@
 		if (!query_result)
 			return f;
 
-		json_object * stories = json_object_object_get(query_result, "stories");
-
-		if (!stories) {
+		json_object * stories {};
+		if(json_object_object_get_ex(query_result, "stories", &stories)
+				== FALSE)
+		{
 			LOG(LOG_ERROR, "newsblur_api::fetch_feed: request returned no stories");
 			return f;
 		}
@@ -150,44 +153,71 @@
 
 		for (int i = 0; i < items_size; i++) {
 			struct json_object * item_obj = (struct json_object *)array_list_get_idx(items, i);
-			const char * article_id = json_object_get_string(json_object_object_get(item_obj, "id"));
-			const char * title = json_object_get_string(json_object_object_get(item_obj, "story_title"));
-			const char * link = json_object_get_string(json_object_object_get(item_obj, "story_permalink"));
-			const char * content = json_object_get_string(json_object_object_get(item_obj, "story_content"));
-			const char * pub_date = json_object_get_string(json_object_object_get(item_obj, "story_date"));
-			bool read_status = json_object_get_int(json_object_object_get(item_obj, "read_status"));
 
 			rsspp::item item;
 
-			if (title)
-				item.title = title;
+			json_object* node {};
 
-			if (link)
-				item.link = link;
+			if(json_object_object_get_ex(item_obj, "story_title", &node)
+					== TRUE)
+			{
+				item.title = json_object_get_string(node);
+			}
 
-			if (content)
-				item.content_encoded = content;
+			if(json_object_object_get_ex(item_obj, "story_permalink", &node)
+					== TRUE)
+			{
+				item.link = json_object_get_string(node);
+			}
 
+			if(json_object_object_get_ex(item_obj, "story_content", &node)
+					== TRUE)
+			{
+				item.content_encoded = json_object_get_string(node);
+			}
+
+			const char * article_id {};
+			if(json_object_object_get_ex(item_obj, "id", &node) == TRUE) {
+				article_id = json_object_get_string(node);
+			}
 			item.guid = id + ID_SEPARATOR + article_id;
 
-			if (read_status == 0) {
-				item.labels.push_back("newsblur:unread");
-			} else if (read_status == 1) {
-				item.labels.push_back("newsblur:read");
+			if(json_object_object_get_ex(item_obj, "read_status", &node)
+					== TRUE)
+			{
+				if (! static_cast<bool>(json_object_get_int(node))) {
+					item.labels.push_back("newsblur:unread");
+				} else {
+					item.labels.push_back("newsblur:read");
+				}
 			}
 
-			item.pubDate_ts = parse_date(pub_date);
-			char rfc822_date[128];
-			strftime(rfc822_date, sizeof(rfc822_date), "%a, %d %b %Y %H:%M:%S %z", gmtime(&item.pubDate_ts));
-			item.pubDate = rfc822_date;
+			if(json_object_object_get_ex(item_obj, "story_date", &node)
+					== TRUE)
+			{
+				const char* pub_date = json_object_get_string(node);
+				item.pubDate_ts = parse_date(pub_date);
+
+				char rfc822_date[128];
+				strftime(
+						rfc822_date,
+						sizeof(rfc822_date),
+						"%a, %d %b %Y %H:%M:%S %z",
+						gmtime(&item.pubDate_ts));
+				item.pubDate = rfc822_date;
+			}
 
 			f.items.push_back(item);
 		}
 	}
 
-	std::sort(f.items.begin(), f.items.end(), [](const rsspp::item& a, const rsspp::item& b) {
-		return a.pubDate_ts > b.pubDate_ts;
+	std::sort(
+		f.items.begin(),
+		f.items.end(),
+		[](const rsspp::item& a, const rsspp::item& b) {
+			return a.pubDate_ts > b.pubDate_ts;
 	});
+
 	return f;
 }
 
--- a/src/oldreader_api.cpp
+++ b/src/oldreader_api.cpp
@@ -140,7 +140,8 @@
 	}
 
 
-	struct json_object * subscription_obj = json_object_object_get(reply, "subscriptions");
+	struct json_object * subscription_obj {};
+	json_object_object_get_ex(reply, "subscriptions", &subscription_obj);
 	struct array_list * subscriptions = json_object_get_array(subscription_obj);
 
 	int len = array_list_length(subscriptions);
@@ -149,8 +150,14 @@
 		std::vector<std::string> tags;
 		struct json_object * sub = json_object_array_get_idx(subscription_obj, i);
 
-		const char * id = json_object_get_string(json_object_object_get(sub, "id"));
-		const char * title = json_object_get_string(json_object_object_get(sub, "title"));
+		json_object* node {};
+
+		json_object_object_get_ex(sub, "id", &node);
+		const char * id = json_object_get_string(node);
+
+		json_object_object_get_ex(sub, "title", &node);
+		const char * title = json_object_get_string(node);
+
 		tags.push_back(std::string("~") + title);
 
 		urls.push_back(tagged_feedurl(utils::strprintf("%s%s?n=%u", OLDREADER_FEED_PREFIX, id, cfg->get_configvalue_as_int("oldreader-min-items")), tags));
--- a/src/ttrss_api.cpp
+++ b/src/ttrss_api.cpp
@@ -79,15 +79,14 @@
 	args["password"] = pass.c_str();
 	auth_info = utils::strprintf("%s:%s", user.c_str(), pass.c_str());
 	auth_info_ptr = auth_info.c_str();
-	struct json_object * content = run_op("login", args);
+	json_object * content = run_op("login", args);
 
 	if (content == NULL)
 		return "";
 
-	std::string sid;
-
-	struct json_object * session_id = json_object_object_get(content, "session_id");
-	sid = json_object_get_string(session_id);
+	json_object * session_id {};
+	json_object_object_get_ex(content, "session_id", &session_id);
+	std::string sid = json_object_get_string(session_id);
 
 	json_object_put(content);
 
@@ -112,26 +111,29 @@
 
 	LOG(LOG_DEBUG, "ttrss_api::run_op(%s,...): post=%s reply = %s", op.c_str(), req_data.c_str(), result.c_str());
 
-	struct json_object * reply = json_tokener_parse(result.c_str());
+	json_object * reply = json_tokener_parse(result.c_str());
 	if (is_error(reply)) {
 		LOG(LOG_ERROR, "ttrss_api::run_op: reply failed to parse: %s", result.c_str());
 		return NULL;
 	}
 
-	struct json_object * status = json_object_object_get(reply, "status");
+	json_object* status {};
+	json_object_object_get_ex(reply, "status", &status);
 	if (is_error(status)) {
 		LOG(LOG_ERROR, "ttrss_api::run_op: no status code");
 		return NULL;
 	}
 
-	struct json_object * content = json_object_object_get(reply, "content");
+	json_object* content {};
+	json_object_object_get_ex(reply, "content", &content);
 	if (is_error(content)) {
 		LOG(LOG_ERROR, "ttrss_api::run_op: no content part in answer from server");
 		return NULL;
 	}
 
 	if (json_object_get_int(status) != 0) {
-		struct json_object * error = json_object_object_get(content, "error");
+		json_object* error {};
+		json_object_object_get_ex(content, "error", &error);
 		if ((strcmp(json_object_get_string(error), "NOT_LOGGED_IN") == 0) && try_login) {
 			json_object_put(reply);
 			if (authenticate())
@@ -255,47 +257,61 @@
 
 	for (int i=0; i<items_size; i++) {
 		struct json_object * item_obj = (struct json_object *)array_list_get_idx(items, i);
-		int id = json_object_get_int(json_object_object_get(item_obj, "id"));
-		const char * title = json_object_get_string(json_object_object_get(item_obj, "title"));
-		const char * link = json_object_get_string(json_object_object_get(item_obj, "link"));
-		const char * content = json_object_get_string(json_object_object_get(item_obj, "content"));
-		time_t updated = (time_t)json_object_get_int(json_object_object_get(item_obj, "updated"));
-		json_bool unread = json_object_get_boolean(json_object_object_get(item_obj, "unread"));
-		struct json_object * attachments = json_object_object_get(item_obj, "attachments");
 
 		rsspp::item item;
 
-		if (title)
-			item.title = title;
+		json_object* node {};
+
+		if(json_object_object_get_ex(item_obj, "title", &node) == TRUE) {
+			item.title = json_object_get_string(node);
+		}
 
-		if (link)
-			item.link = link;
+		if(json_object_object_get_ex(item_obj, "link", &node) == TRUE) {
+			item.link = json_object_get_string(node);
+		}
 
-		if (content)
-			item.content_encoded = content;
+		if(json_object_object_get_ex(item_obj, "content", &node) == TRUE) {
+			item.content_encoded = json_object_get_string(node);
+		}
 
-		if (attachments) {
+		json_object * attachments {};
+		if(json_object_object_get_ex(item_obj, "attachments", &attachments)
+				== TRUE)
+		{
 			struct array_list * attachments_list = json_object_get_array(attachments);
 			int attachments_size = array_list_length(attachments_list);
 			if (attachments_size > 0) {
-				struct json_object * attachment = (struct json_object *)array_list_get_idx(attachments_list, 0);
-				const char * content_url = json_object_get_string(json_object_object_get(attachment, "content_url"));
-				const char * content_type = json_object_get_string(json_object_object_get(attachment, "content_type"));
-				if (content_url)
-					item.enclosure_url = content_url;
-				if (content_type)
-					item.enclosure_type = content_type;
+				json_object* attachment =
+					(json_object*)array_list_get_idx(attachments_list, 0);
+
+				if(json_object_object_get_ex(attachment, "content_url", &node)
+						== TRUE)
+				{
+					item.enclosure_url = json_object_get_string(node);
+				}
+
+				if(json_object_object_get_ex(attachment, "content_type", &node)
+						== TRUE)
+				{
+					item.enclosure_type = json_object_get_string(node);
+				}
 			}
 		}
 
+		json_object_object_get_ex(item_obj, "id", &node);
+		int id = json_object_get_int(node);
 		item.guid = utils::strprintf("%d", id);
 
+		json_object_object_get_ex(item_obj, "unread", &node);
+		json_bool unread = json_object_get_boolean(node);
 		if (unread) {
 			item.labels.push_back("ttrss:unread");
 		} else {
 			item.labels.push_back("ttrss:read");
 		}
 
+		json_object_object_get_ex(item_obj, "updated", &node);
+		time_t updated = (time_t)json_object_get_int(node);
 		char rfc822_date[128];
 		strftime(rfc822_date, sizeof(rfc822_date), "%a, %d %b %Y %H:%M:%S %z", gmtime(&updated));
 		item.pubDate = rfc822_date;
@@ -312,20 +328,23 @@
 	return f;
 }
 
-void ttrss_api::fetch_feeds_per_category(struct json_object * cat, std::vector<tagged_feedurl>& feeds) {
+void ttrss_api::fetch_feeds_per_category(
+		json_object * cat, std::vector<tagged_feedurl>& feeds)
+{
 	const char * cat_name = NULL;
-	struct json_object * cat_title_obj = NULL;
+	json_object * cat_title_obj {};
 	int cat_id;
 
 	if (cat) {
-		struct json_object * cat_id_obj = json_object_object_get(cat, "id");
+		json_object* cat_id_obj {};
+		json_object_object_get_ex(cat, "id", &cat_id_obj);
 		cat_id = json_object_get_int(cat_id_obj);
 
 		// ignore special categories, for now
 		if(cat_id < 0)
 			return;
 
-		cat_title_obj = json_object_object_get(cat, "title");
+		json_object_object_get_ex(cat, "title", &cat_title_obj);
 		cat_name = json_object_get_string(cat_title_obj);
 		LOG(LOG_DEBUG, "ttrss_api::fetch_feeds_per_category: id = %d title = %s", cat_id, cat_name);
 	} else {
@@ -349,16 +368,26 @@
 	for (int j=0; j<feed_list_size; j++) {
 		struct json_object * feed = (struct json_object *)array_list_get_idx(feed_list, j);
 
-		int feed_id = json_object_get_int(json_object_object_get(feed, "id"));
-		const char * feed_title = json_object_get_string(json_object_object_get(feed, "title"));
-		const char * feed_url = json_object_get_string(json_object_object_get(feed, "feed_url"));
+		json_object* node {};
+
+		json_object_object_get_ex(feed, "id", &node);
+		int feed_id = json_object_get_int(node);
+
+		json_object_object_get_ex(feed, "title", &node);
+		const char * feed_title = json_object_get_string(node);
+
+		json_object_object_get_ex(feed, "feed_url", &node);
+		const char * feed_url = json_object_get_string(node);
 
 		std::vector<std::string> tags;
 		tags.push_back(std::string("~") + feed_title);
+
 		if (cat_name) {
 			tags.push_back(cat_name);
 		}
-		feeds.push_back(tagged_feedurl(utils::strprintf("%s#%d", feed_url, feed_id), tags));
+
+		auto url = utils::strprintf("%s#%d", feed_url, feed_id);
+		feeds.push_back(tagged_feedurl(url, tags));
 
 		// TODO: cache feed_id -> feed_url (or feed_url -> feed_id ?)
 	}
