[misc] Change json_drilldown to _select and fix error case

This commit is contained in:
ejurgensen 2020-02-16 21:29:43 +01:00
parent 70f0ff1f61
commit 18cf2dbbbf
3 changed files with 7 additions and 6 deletions

View File

@ -840,7 +840,7 @@ response_jparse_discogs(char **artwork_url, json_object *response, int max_w, in
else
key = "cover_image";
image = JPARSE_DRILLDOWN(response, "results", key);
image = JPARSE_SELECT(response, "results", key);
if (!image || json_object_get_type(image) != json_type_string)
return ONLINE_SOURCE_PARSE_NOT_FOUND;
@ -859,7 +859,7 @@ response_jparse_musicbrainz(char **artwork_url, json_object *response, int max_w
json_object *id;
const char *s;
id = JPARSE_DRILLDOWN(response, "release-groups", "id");
id = JPARSE_SELECT(response, "release-groups", "id");
if (!id || json_object_get_type(id) != json_type_string)
return ONLINE_SOURCE_PARSE_NOT_FOUND;
@ -888,7 +888,7 @@ response_jparse_spotify(char **artwork_url, json_object *response, int max_w, in
int image_count;
int i;
images = JPARSE_DRILLDOWN(response, "albums", "items", "images");
images = JPARSE_SELECT(response, "albums", "items", "images");
if (!images || json_object_get_type(images) != json_type_array)
return ONLINE_SOURCE_PARSE_INVALID;

View File

@ -33,11 +33,12 @@
#include "logger.h"
json_object *
jparse_drilldown(json_object *haystack, const char *keys[])
jparse_select(json_object *haystack, const char *keys[])
{
json_object *needle;
json_bool found;
needle = NULL;
while (*keys)
{
found = json_object_object_get_ex(haystack, *keys, &needle);

View File

@ -35,10 +35,10 @@
// Convenience macro so that instead of calling jparse with an array of keys
// to follow, you can call JPARSE_DRILLDOWN(haystack, "key1", "key2"...)
#define JPARSE_DRILLDOWN(haystack, ...) jparse_drilldown(haystack, (const char *[]){__VA_ARGS__, NULL})
#define JPARSE_SELECT(haystack, ...) jparse_select(haystack, (const char *[]){__VA_ARGS__, NULL})
json_object *
jparse_drilldown(json_object *haystack, const char *keys[]);
jparse_select(json_object *haystack, const char *keys[]);
void
jparse_free(json_object *haystack);