Introduction
Introduction Statistics Contact Development Disclaimer Help
sync json.{c,h} changes, add valuelen parameter - frontends - front-ends for so…
Log
Files
Refs
README
LICENSE
---
commit 74c6d298f57f895cc82d55b5da2a5d710156cb27
parent a9e2584bc6c2b314c4f1b6d6a5f4715161d64bc5
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 4 Apr 2023 18:51:43 +0200
sync json.{c,h} changes, add valuelen parameter
Diffstat:
M json.c | 16 +++++++++-------
M json.h | 2 +-
M reddit/reddit.c | 4 ++--
M twitch/twitch.c | 10 +++++-----
M youtube/youtube.c | 4 ++--
5 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/json.c b/json.c
@@ -8,6 +8,7 @@
#include "json.h"
+/* ctype-like macros, but always compatible with ASCII / UTF-8 */
#define ISDIGIT(c) (((unsigned)c) - '0' < 10)
#define ISXDIGIT(c) ((((unsigned)c) - '0' < 10) || ((unsigned)c | 32) - 'a' < …
@@ -118,7 +119,8 @@ capacity(char **value, size_t *sz, size_t cur, size_t inc)
int
parsejson(const char *s, size_t slen,
- void (*cb)(struct json_node *, size_t, const char *, void *), void *…
+ void (*cb)(struct json_node *, size_t, const char *, size_t, void *),
+ void *pp)
{
struct json_node nodes[JSON_MAX_NODE_DEPTH] = { { 0 } };
size_t depth = 0, p = 0, len, sz = 0;
@@ -231,7 +233,7 @@ escchr:
goto end;
memcpy(nodes[depth].name, str,…
} else {
- cb(nodes, depth + 1, str, pp);
+ cb(nodes, depth + 1, str, len …
}
break;
} else {
@@ -260,7 +262,7 @@ escchr:
expect = EXPECT_OBJECT_STRING;
}
- cb(nodes, depth + 1, "", pp);
+ cb(nodes, depth + 1, "", 0, pp);
depth++;
nodes[depth].index = 0;
@@ -295,7 +297,7 @@ escchr:
if (GETNEXT() != 'r' || GETNEXT() != 'u' || GETNEXT() …
JSON_INVALID();
nodes[depth].type = JSON_TYPE_BOOL;
- cb(nodes, depth + 1, "true", pp);
+ cb(nodes, depth + 1, "true", 4, pp);
expect = EXPECT_END;
break;
case 'f': /* false */
@@ -303,14 +305,14 @@ escchr:
GETNEXT() != 'e')
JSON_INVALID();
nodes[depth].type = JSON_TYPE_BOOL;
- cb(nodes, depth + 1, "false", pp);
+ cb(nodes, depth + 1, "false", 5, pp);
expect = EXPECT_END;
break;
case 'n': /* null */
if (GETNEXT() != 'u' || GETNEXT() != 'l' || GETNEXT() …
JSON_INVALID();
nodes[depth].type = JSON_TYPE_NULL;
- cb(nodes, depth + 1, "null", pp);
+ cb(nodes, depth + 1, "null", 4, pp);
expect = EXPECT_END;
break;
default: /* number */
@@ -325,7 +327,7 @@ escchr:
c != '+' && c != '-' && c != '.') ||
p + 1 >= sizeof(pri)) {
pri[p] = '\0';
- cb(nodes, depth + 1, pri, pp);
+ cb(nodes, depth + 1, pri, p, pp);
goto handlechr; /* do not read next ch…
} else {
pri[p++] = c;
diff --git a/json.h b/json.h
@@ -27,6 +27,6 @@ struct json_node {
};
int parsejson(const char *, size_t,
- void (*cb)(struct json_node *, size_t, const char *, void *),
+ void (*cb)(struct json_node *, size_t, const char *, size_t, voi…
void *);
#endif
diff --git a/reddit/reddit.c b/reddit/reddit.c
@@ -26,7 +26,7 @@ reddit_request(const char *path)
/* unmarshal JSON response, skip HTTP headers */
int
json_unmarshal(const char *data,
- void (*cb)(struct json_node *, size_t, const char *, void *),
+ void (*cb)(struct json_node *, size_t, const char *, size_t, void *),
void *pp)
{
const char *s;
@@ -79,7 +79,7 @@ reddit_list_data(const char *subreddit, int limit,
}
void
-reddit_list_processnode(struct json_node *nodes, size_t depth, const char *val…
+reddit_list_processnode(struct json_node *nodes, size_t depth, const char *val…
void *pp)
{
struct list_response *r = (struct list_response *)pp;
diff --git a/twitch/twitch.c b/twitch/twitch.c
@@ -32,7 +32,7 @@ twitch_request(const char *path)
/* unmarshal JSON response, skip HTTP headers */
int
json_unmarshal(const char *data,
- void (*cb)(struct json_node *, size_t, const char *, void *),
+ void (*cb)(struct json_node *, size_t, const char *, size_t, void *),
void *pp)
{
const char *s;
@@ -133,7 +133,7 @@ twitch_games_top_data(void)
}
void
-twitch_games_processnode(struct json_node *nodes, size_t depth, const char *va…
+twitch_games_processnode(struct json_node *nodes, size_t depth, const char *va…
void *pp)
{
struct games_response *r = (struct games_response *)pp;
@@ -218,7 +218,7 @@ twitch_games_bygameids(const char *param)
}
void
-twitch_streams_processnode(struct json_node *nodes, size_t depth, const char *…
+twitch_streams_processnode(struct json_node *nodes, size_t depth, const char *…
void *pp)
{
struct streams_response *r = (struct streams_response *)pp;
@@ -392,7 +392,7 @@ twitch_streams_users(struct streams_response *r)
}
void
-twitch_users_processnode(struct json_node *nodes, size_t depth, const char *va…
+twitch_users_processnode(struct json_node *nodes, size_t depth, const char *va…
void *pp)
{
struct users_response *r = (struct users_response *)pp;
@@ -485,7 +485,7 @@ twitch_users_bylogin(const char *login)
}
void
-twitch_videos_processnode(struct json_node *nodes, size_t depth, const char *v…
+twitch_videos_processnode(struct json_node *nodes, size_t depth, const char *v…
void *pp)
{
struct videos_response *r = (struct videos_response *)pp;
diff --git a/youtube/youtube.c b/youtube/youtube.c
@@ -148,7 +148,7 @@ extractjson_video(const char *s, const char **start, const …
}
static void
-processnode_search(struct json_node *nodes, size_t depth, const char *value,
+processnode_search(struct json_node *nodes, size_t depth, const char *value, s…
void *pp)
{
struct search_response *r = (struct search_response *)pp;
@@ -308,7 +308,7 @@ parse_search_response(const char *data)
}
static void
-processnode_video(struct json_node *nodes, size_t depth, const char *value,
+processnode_video(struct json_node *nodes, size_t depth, const char *value, si…
void *pp)
{
struct video_response *r = (struct video_response *)pp;
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.