mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
common: remove now-unused json_delve.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
09b18bf64f
commit
fd7d1a1cc0
3 changed files with 0 additions and 137 deletions
|
@ -719,42 +719,6 @@ void json_tok_remove(jsmntok_t **tokens,
|
|||
tal_resize(tokens, tal_count(*tokens) - remove_count);
|
||||
}
|
||||
|
||||
const jsmntok_t *json_delve(const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
const char *guide)
|
||||
{
|
||||
while (*guide) {
|
||||
const char *key;
|
||||
size_t len = strcspn(guide+1, ".[]");
|
||||
|
||||
key = tal_strndup(tmpctx, guide+1, len);
|
||||
switch (guide[0]) {
|
||||
case '.':
|
||||
if (tok->type != JSMN_OBJECT)
|
||||
return NULL;
|
||||
tok = json_get_member(buffer, tok, key);
|
||||
if (!tok)
|
||||
return NULL;
|
||||
break;
|
||||
case '[':
|
||||
if (tok->type != JSMN_ARRAY)
|
||||
return NULL;
|
||||
tok = json_get_arr(tok, atol(key));
|
||||
if (!tok)
|
||||
return NULL;
|
||||
/* Must be terminated */
|
||||
assert(guide[1+strlen(key)] == ']');
|
||||
len++;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
guide += len + 1;
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
/* talfmt take a ctx pointer and return NULL or a valid pointer.
|
||||
* fmt takes the argument, and returns a bool. */
|
||||
static bool handle_percent(const char *buffer,
|
||||
|
|
|
@ -152,11 +152,6 @@ jsmntok_t *json_tok_copy(const tal_t *ctx, const jsmntok_t *tok);
|
|||
void json_tok_remove(jsmntok_t **tokens,
|
||||
jsmntok_t *obj_or_array, const jsmntok_t *tok, size_t num);
|
||||
|
||||
/* Guide is a string with . for members, [] around indexes. */
|
||||
const jsmntok_t *json_delve(const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
const char *guide);
|
||||
|
||||
/* Guide is % for a token: each must be followed by JSON_SCAN(). */
|
||||
bool json_scan(const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
|
|
|
@ -178,101 +178,6 @@ static void test_json_tok_size(void)
|
|||
assert(!toks);
|
||||
}
|
||||
|
||||
static void test_json_delve(void)
|
||||
{
|
||||
const jsmntok_t *toks, *t;
|
||||
char *buf;
|
||||
|
||||
buf = "{\"1\":\"one\", \"2\":\"two\", \"3\":[\"three\", {\"deeper\": 17}]}";
|
||||
toks = json_parse_simple(tmpctx, buf, strlen(buf));
|
||||
assert(toks);
|
||||
assert(toks->size == 3);
|
||||
|
||||
t = json_delve(buf, toks, ".1");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_STRING);
|
||||
assert(json_tok_streq(buf, t, "one"));
|
||||
assert(t == toks+2);
|
||||
|
||||
t = json_delve(buf, toks, ".2");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_STRING);
|
||||
assert(json_tok_streq(buf, t, "two"));
|
||||
assert(t == toks+4);
|
||||
|
||||
t = json_delve(buf, toks, ".3");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_ARRAY);
|
||||
assert(t == toks+6);
|
||||
assert(t->size == 2);
|
||||
|
||||
t = json_delve(buf, toks, ".3[0]");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_STRING);
|
||||
assert(json_tok_streq(buf, t, "three"));
|
||||
assert(t == toks+7);
|
||||
|
||||
t = json_delve(buf, toks, ".3[1]");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_OBJECT);
|
||||
assert(t == toks+8);
|
||||
assert(t->size == 1);
|
||||
|
||||
t = json_delve(buf, toks, ".3[1].deeper");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_PRIMITIVE);
|
||||
assert(memeq(buf + t->start, t->end - t->start, "17", strlen("17")));
|
||||
assert(t == toks+10);
|
||||
|
||||
t = json_delve(buf, toks, ".4");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, "[0]");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".deeper");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".3[2]");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".3[2].deeper");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".3[0].deeper");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".3[1].deeper[0]");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".3[1][0]");
|
||||
assert(!t);
|
||||
|
||||
/* Now a real example. */
|
||||
buf = "{\n"
|
||||
" \"jsonrpc\": \"2.0\", \n"
|
||||
" \"method\": \"init\", \n"
|
||||
" \"id\": 1, \n"
|
||||
" \"params\": {\n"
|
||||
" \"options\": {\n"
|
||||
" }, \n"
|
||||
" \"configuration\": {\n"
|
||||
" \"lightning-dir\": \"/tmp/ltests-n2hyd543/test_pay_plugin_1/lightning-2/\", \n"
|
||||
" \"rpc-file\": \"lightning-rpc\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n";
|
||||
toks = json_parse_simple(tmpctx, buf, strlen(buf));
|
||||
assert(toks);
|
||||
assert(toks->size == 4);
|
||||
|
||||
t = json_delve(buf, toks, ".rpcfile");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".configuration.rpc-file");
|
||||
assert(!t);
|
||||
t = json_delve(buf, toks, ".params.configuration");
|
||||
assert(t);
|
||||
assert(t->size == 2);
|
||||
t = json_delve(buf, toks, ".params.configuration.rpc-file");
|
||||
assert(t);
|
||||
assert(t->type == JSMN_STRING);
|
||||
assert(json_tok_streq(buf, t, "lightning-rpc"));
|
||||
}
|
||||
|
||||
static void test_json_bad_utf8(void)
|
||||
{
|
||||
const jsmntok_t *toks;
|
||||
|
@ -308,7 +213,6 @@ int main(int argc, char *argv[])
|
|||
test_json_tok_size();
|
||||
test_json_tok_bitcoin_amount();
|
||||
test_json_tok_millionths();
|
||||
test_json_delve();
|
||||
test_json_bad_utf8();
|
||||
|
||||
common_shutdown();
|
||||
|
|
Loading…
Add table
Reference in a new issue