use JSON_TYPE_* enum - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit e8fb7f182b86a5d29310497d145f1dba48d3e7a2 (DIR) parent a5e2f07cb75a19578454e096f2c9f77cebc30084 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Wed, 30 Mar 2022 00:02:27 +0200 use JSON_TYPE_* enum Diffstat: M reddit/reddit.c | 40 ++++++++++++++++---------------- M youtube/youtube.c | 70 ++++++++++++++++---------------- 2 files changed, 55 insertions(+), 55 deletions(-) --- (DIR) diff --git a/reddit/reddit.c b/reddit/reddit.c @@ -88,9 +88,9 @@ reddit_list_processnode(struct json_node *nodes, size_t depth, const char *value struct tm *tm; if (depth == 3 && - nodes[0].type == TYPE_OBJECT && - nodes[1].type == TYPE_OBJECT && - nodes[2].type == TYPE_STRING && + nodes[0].type == JSON_TYPE_OBJECT && + nodes[1].type == JSON_TYPE_OBJECT && + nodes[2].type == JSON_TYPE_STRING && !strcmp(nodes[0].name, "") && !strcmp(nodes[1].name, "data")) { if (!strcmp(nodes[2].name, "before")) { @@ -105,11 +105,11 @@ reddit_list_processnode(struct json_node *nodes, size_t depth, const char *value /* new item */ if (depth == 5 && - nodes[0].type == TYPE_OBJECT && - nodes[1].type == TYPE_OBJECT && - nodes[2].type == TYPE_ARRAY && - nodes[3].type == TYPE_OBJECT && - nodes[4].type == TYPE_OBJECT && + nodes[0].type == JSON_TYPE_OBJECT && + nodes[1].type == JSON_TYPE_OBJECT && + nodes[2].type == JSON_TYPE_ARRAY && + nodes[3].type == JSON_TYPE_OBJECT && + nodes[4].type == JSON_TYPE_OBJECT && !strcmp(nodes[0].name, "") && !strcmp(nodes[1].name, "data") && !strcmp(nodes[2].name, "children") && @@ -124,11 +124,11 @@ reddit_list_processnode(struct json_node *nodes, size_t depth, const char *value item = &(r->items[r->nitems - 1]); if (depth >= 5 && - nodes[0].type == TYPE_OBJECT && - nodes[1].type == TYPE_OBJECT && - nodes[2].type == TYPE_ARRAY && - nodes[3].type == TYPE_OBJECT && - nodes[4].type == TYPE_OBJECT && + nodes[0].type == JSON_TYPE_OBJECT && + nodes[1].type == JSON_TYPE_OBJECT && + nodes[2].type == JSON_TYPE_ARRAY && + nodes[3].type == JSON_TYPE_OBJECT && + nodes[4].type == JSON_TYPE_OBJECT && !strcmp(nodes[0].name, "") && !strcmp(nodes[1].name, "data") && !strcmp(nodes[2].name, "children") && @@ -137,11 +137,11 @@ reddit_list_processnode(struct json_node *nodes, size_t depth, const char *value if (depth == 6) { node = &nodes[5]; switch (node->type) { - case TYPE_BOOL: + case JSON_TYPE_BOOL: if (!strcmp(node->name, "is_video")) item->is_video = value[0] == 't'; break; - case TYPE_NUMBER: + case JSON_TYPE_NUMBER: if (!strcmp(node->name, "ups")) item->ups = strtol(value, NULL, 10); else if (!strcmp(node->name, "downs")) @@ -155,7 +155,7 @@ reddit_list_processnode(struct json_node *nodes, size_t depth, const char *value memcpy(&(item->created_tm), tm, sizeof(*tm)); } break; - case TYPE_STRING: + case JSON_TYPE_STRING: if (!strcmp(node->name, "name")) strlcpy(item->name, value, sizeof(item->name)); else if (!strcmp(node->name, "title")) @@ -179,21 +179,21 @@ reddit_list_processnode(struct json_node *nodes, size_t depth, const char *value break; } } else if (depth == 8 && - nodes[5].type == TYPE_OBJECT && - nodes[6].type == TYPE_OBJECT && + nodes[5].type == JSON_TYPE_OBJECT && + nodes[6].type == JSON_TYPE_OBJECT && (!strcmp(nodes[5].name, "media") || !strcmp(nodes[5].name, "secure_media")) && !strcmp(nodes[6].name, "reddit_video")) { node = &nodes[7]; switch (node->type) { - case TYPE_NUMBER: + case JSON_TYPE_NUMBER: /* prefer "insecure" */ if (nodes[5].name[0] == 's' && item->duration) break; if (!strcmp(node->name, "duration")) item->duration = strtol(value, NULL, 10); break; - case TYPE_STRING: + case JSON_TYPE_STRING: /* prefer "insecure" */ if (nodes[5].name[0] == 's' && item->dash_url[0]) break; (DIR) diff --git a/youtube/youtube.c b/youtube/youtube.c @@ -90,9 +90,9 @@ processnode(struct json_node *nodes, size_t depth, const char *value, /* new item, structures can be very deep, just check the end for: (items|contents)[].videoRenderer objects */ if (depth >= 3 && - nodes[depth - 3].type == TYPE_ARRAY && - nodes[depth - 2].type == TYPE_OBJECT && - nodes[depth - 1].type == TYPE_OBJECT && + nodes[depth - 3].type == JSON_TYPE_ARRAY && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_OBJECT && (!strcmp(nodes[depth - 3].name, "items") || !strcmp(nodes[depth - 3].name, "contents")) && !strcmp(nodes[depth - 1].name, "videoRenderer")) { @@ -105,10 +105,10 @@ processnode(struct json_node *nodes, size_t depth, const char *value, item = &(r->items[r->nitems - 1]); if (depth >= 4 && - nodes[depth - 4].type == TYPE_ARRAY && - nodes[depth - 3].type == TYPE_OBJECT && - nodes[depth - 2].type == TYPE_OBJECT && - nodes[depth - 1].type == TYPE_STRING && + nodes[depth - 4].type == JSON_TYPE_ARRAY && + nodes[depth - 3].type == JSON_TYPE_OBJECT && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_STRING && (!strcmp(nodes[depth - 4].name, "items") || !strcmp(nodes[depth - 4].name, "contents")) && !strcmp(nodes[depth - 2].name, "videoRenderer") && @@ -117,13 +117,13 @@ processnode(struct json_node *nodes, size_t depth, const char *value, } if (depth >= 7 && - nodes[depth - 7].type == TYPE_ARRAY && - nodes[depth - 6].type == TYPE_OBJECT && - nodes[depth - 5].type == TYPE_OBJECT && - nodes[depth - 4].type == TYPE_OBJECT && - nodes[depth - 3].type == TYPE_ARRAY && - nodes[depth - 2].type == TYPE_OBJECT && - nodes[depth - 1].type == TYPE_STRING && + nodes[depth - 7].type == JSON_TYPE_ARRAY && + nodes[depth - 6].type == JSON_TYPE_OBJECT && + nodes[depth - 5].type == JSON_TYPE_OBJECT && + nodes[depth - 4].type == JSON_TYPE_OBJECT && + nodes[depth - 3].type == JSON_TYPE_ARRAY && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_STRING && (!strcmp(nodes[depth - 7].name, "items") || !strcmp(nodes[depth - 7].name, "contents")) && !strcmp(nodes[depth - 5].name, "videoRenderer") && @@ -135,11 +135,11 @@ processnode(struct json_node *nodes, size_t depth, const char *value, } if (depth >= 5 && - nodes[depth - 5].type == TYPE_ARRAY && - nodes[depth - 4].type == TYPE_OBJECT && - nodes[depth - 3].type == TYPE_OBJECT && - nodes[depth - 2].type == TYPE_OBJECT && - nodes[depth - 1].type == TYPE_STRING && + nodes[depth - 5].type == JSON_TYPE_ARRAY && + nodes[depth - 4].type == JSON_TYPE_OBJECT && + nodes[depth - 3].type == JSON_TYPE_OBJECT && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_STRING && (!strcmp(nodes[depth - 5].name, "items") || !strcmp(nodes[depth - 5].name, "contents")) && !strcmp(nodes[depth - 3].name, "videoRenderer") && @@ -157,15 +157,15 @@ processnode(struct json_node *nodes, size_t depth, const char *value, } if (depth >= 9 && - nodes[depth - 9].type == TYPE_ARRAY && - nodes[depth - 8].type == TYPE_OBJECT && - nodes[depth - 7].type == TYPE_OBJECT && - nodes[depth - 6].type == TYPE_OBJECT && - nodes[depth - 5].type == TYPE_ARRAY && - nodes[depth - 4].type == TYPE_OBJECT && - nodes[depth - 3].type == TYPE_OBJECT && - nodes[depth - 2].type == TYPE_OBJECT && - nodes[depth - 1].type == TYPE_STRING && + nodes[depth - 9].type == JSON_TYPE_ARRAY && + nodes[depth - 8].type == JSON_TYPE_OBJECT && + nodes[depth - 7].type == JSON_TYPE_OBJECT && + nodes[depth - 6].type == JSON_TYPE_OBJECT && + nodes[depth - 5].type == JSON_TYPE_ARRAY && + nodes[depth - 4].type == JSON_TYPE_OBJECT && + nodes[depth - 3].type == JSON_TYPE_OBJECT && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_STRING && (!strcmp(nodes[depth - 9].name, "items") || !strcmp(nodes[depth - 9].name, "contents")) && !strcmp(nodes[depth - 7].name, "videoRenderer") && @@ -179,13 +179,13 @@ processnode(struct json_node *nodes, size_t depth, const char *value, } if (depth >= 7 && - nodes[depth - 7].type == TYPE_ARRAY && - nodes[depth - 6].type == TYPE_OBJECT && - nodes[depth - 5].type == TYPE_OBJECT && - nodes[depth - 4].type == TYPE_OBJECT && - nodes[depth - 3].type == TYPE_ARRAY && - nodes[depth - 2].type == TYPE_OBJECT && - nodes[depth - 1].type == TYPE_STRING && + nodes[depth - 7].type == JSON_TYPE_ARRAY && + nodes[depth - 6].type == JSON_TYPE_OBJECT && + nodes[depth - 5].type == JSON_TYPE_OBJECT && + nodes[depth - 4].type == JSON_TYPE_OBJECT && + nodes[depth - 3].type == JSON_TYPE_ARRAY && + nodes[depth - 2].type == JSON_TYPE_OBJECT && + nodes[depth - 1].type == JSON_TYPE_STRING && (!strcmp(nodes[depth - 7].name, "items") || !strcmp(nodes[depth - 7].name, "contents")) && !strcmp(nodes[depth - 5].name, "videoRenderer") &&