From ef49fb417f582ec837cde6b551a0bf0cfafe3d4d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 3 Mar 2021 12:52:21 +0100 Subject: Use cJSON instead of the existing json library --- src/rss.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'src/rss.c') diff --git a/src/rss.c b/src/rss.c index 8d56236..29a7708 100644 --- a/src/rss.c +++ b/src/rss.c @@ -6,7 +6,7 @@ #include "buffer.h" #include "episode.h" #include "rss_html_common.h" -#include "json.h" +#include "../depends/cJSON.h" #include "alloc.h" #include #include @@ -435,31 +435,23 @@ int add_rss(const char *name, char *url, char *rss_config_dir, const char *start static int is_item_already_downloaded(const char *title, const char *link, TrackedRss *tracked_rss) { /* TODO: Optimize this... */ - struct json_value_s *downloaded_json = json_object_get_field_by_name(tracked_rss->json_data, "downloaded"); - if(downloaded_json && downloaded_json->type == json_type_array) { - struct json_array_s *downloaded_json_array = json_value_as_array(downloaded_json); - struct json_array_element_s *downloaded_item = downloaded_json_array->start; - for(; downloaded_item; downloaded_item = downloaded_item->next) { - struct json_object_s *downloaded_obj = json_value_as_object(downloaded_item->value); - if(!downloaded_obj) - continue; - - struct json_value_s *download_title_value = json_object_get_field_by_name(downloaded_obj, "title"); - struct json_value_s *download_url_value = json_object_get_field_by_name(downloaded_obj, "url"); - - struct json_string_s *download_title_str = NULL; - struct json_string_s *download_url_str = NULL; + cJSON *downloaded_json = cJSON_GetObjectItemCaseSensitive(tracked_rss->json_data, "downloaded"); + if(!cJSON_IsArray(downloaded_json)) + return 0; - if(download_title_value) - download_title_str = json_value_as_string(download_title_value); + cJSON *downloaded_item = NULL; + cJSON_ArrayForEach(downloaded_item, downloaded_json) { + if(!cJSON_IsObject(downloaded_item)) + continue; - if(download_url_value) - download_url_str = json_value_as_string(download_url_value); + cJSON *download_title_value = cJSON_GetObjectItemCaseSensitive(downloaded_item, "title"); + cJSON *download_url_value = cJSON_GetObjectItemCaseSensitive(downloaded_item, "url"); - if((download_title_str && strcmp(download_title_str->string, title) == 0) || (download_url_str && strcmp(download_url_str->string, link) == 0)) - return 1; - } + if((cJSON_IsString(download_title_value) && strcmp(download_title_value->valuestring, title) == 0) + || (cJSON_IsString(download_url_value) && strcmp(download_url_value->valuestring, link) == 0)) + return 1; } + return 0; } -- cgit v1.2.3