json_tok_len, json_tok_contents: rename to json_tok_full_len and json_tok_full

These are only supposed to be used when you want the token contents including
surrounding "".  We should use this when reporting errors, but usually
we just want to access the tok members directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-12-16 15:18:06 +10:30
parent 465d5d5649
commit 12731c4a60
12 changed files with 32 additions and 32 deletions

View File

@ -363,7 +363,7 @@ int main(int argc, char *argv[])
if (!json_tok_streq(resp, id, idstr))
errx(ERROR_TALKING_TO_LIGHTNINGD,
"Incorrect 'id' in response: %.*s",
json_tok_len(id), json_tok_contents(resp, id));
json_tok_full_len(id), json_tok_full(resp, id));
if (!error || json_tok_is_null(resp, error)) {
// if we have specific help command
@ -374,8 +374,8 @@ int main(int argc, char *argv[])
human_readable(resp, result, '\n');
else
printf("%.*s\n",
json_tok_len(result),
json_tok_contents(resp, result));
json_tok_full_len(result),
json_tok_full(resp, result));
tal_free(lightning_dir);
tal_free(rpc_filename);
tal_free(ctx);
@ -384,7 +384,7 @@ int main(int argc, char *argv[])
}
printf("%.*s\n",
json_tok_len(error), json_tok_contents(resp, error));
json_tok_full_len(error), json_tok_full(resp, error));
tal_free(lightning_dir);
tal_free(rpc_filename);
tal_free(ctx);

View File

@ -12,7 +12,7 @@
#include <stdio.h>
#include <string.h>
const char *json_tok_contents(const char *buffer, const jsmntok_t *t)
const char *json_tok_full(const char *buffer, const jsmntok_t *t)
{
if (t->type == JSMN_STRING)
return buffer + t->start - 1;
@ -20,7 +20,7 @@ const char *json_tok_contents(const char *buffer, const jsmntok_t *t)
}
/* Include " if it's a string. */
int json_tok_len(const jsmntok_t *t)
int json_tok_full_len(const jsmntok_t *t)
{
if (t->type == JSMN_STRING)
return t->end - t->start + 2;

View File

@ -15,10 +15,10 @@ struct json_escaped;
struct short_channel_id;
/* Include " if it's a string. */
const char *json_tok_contents(const char *buffer, const jsmntok_t *t);
const char *json_tok_full(const char *buffer, const jsmntok_t *t);
/* Include " if it's a string. */
int json_tok_len(const jsmntok_t *t);
int json_tok_full_len(const jsmntok_t *t);
/* Is this a string equal to str? */
bool json_tok_streq(const char *buffer, const jsmntok_t *tok, const char *str);

View File

@ -646,8 +646,8 @@ static bool process_getblock(struct bitcoin_cli *bcli)
&txid))
fatal("%s: had bad txid (%.*s)?",
bcli_args(tmpctx, bcli),
txidtok->end - txidtok->start,
bcli->output + txidtok->start);
json_tok_full_len(txidtok),
json_tok_full(bcli->output, txidtok));
go->cb = cb;
/* Now get the raw tx output. */

View File

@ -111,8 +111,8 @@ static void json_connect(struct command *cmd,
if (!json_to_pubkey(buffer, idtok, &id)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"id %.*s not valid",
idtok->end - idtok->start,
buffer + idtok->start);
json_tok_full_len(idtok),
json_tok_full(buffer, idtok));
return;
}

View File

@ -474,8 +474,8 @@ static void json_dev_query_scids(struct command *cmd,
if (!json_to_short_channel_id(buffer, t, &scids[i])) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"scid %zu '%.*s' is not an scid",
i, t->end - t->start,
buffer + t->start);
i, json_tok_full_len(t),
json_tok_full(buffer, t));
return;
}
}

View File

@ -114,7 +114,7 @@ bool json_tok_pubkey(struct command *cmd, const char *name,
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a pubkey, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start);
name, json_tok_full_len(tok), json_tok_full(buffer, tok));
return false;
}
@ -143,7 +143,7 @@ bool json_tok_short_channel_id(struct command *cmd, const char *name,
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a short channel id, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start);
name, json_tok_full_len(tok), json_tok_full(buffer, tok));
return false;
}
@ -178,7 +178,7 @@ bool json_tok_feerate_style(struct command *cmd, const char *name,
name,
json_feerate_style_name(FEERATE_PER_KSIPA),
json_feerate_style_name(FEERATE_PER_KBYTE),
tok->end - tok->start, buffer + tok->start);
json_tok_full_len(tok), json_tok_full(buffer, tok));
return false;
}

View File

@ -332,8 +332,8 @@ static void json_help(struct command *cmd,
}
command_fail(cmd, JSONRPC2_METHOD_NOT_FOUND,
"Unknown command '%.*s'",
cmdtok->end - cmdtok->start,
buffer + cmdtok->start);
json_tok_full_len(cmdtok),
json_tok_full(buffer, cmdtok));
return;
}
@ -539,8 +539,8 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
c->pending = false;
c->have_json_stream = false;
c->id = tal_strndup(c,
json_tok_contents(jcon->buffer, id),
json_tok_len(id));
json_tok_full(jcon->buffer, id),
json_tok_full_len(id));
c->mode = CMD_NORMAL;
list_add_tail(&jcon->commands, &c->list);
tal_add_destructor(c, destroy_command);
@ -561,8 +561,8 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
if (!c->json_cmd) {
command_fail(c, JSONRPC2_METHOD_NOT_FOUND,
"Unknown command '%.*s'",
method->end - method->start,
jcon->buffer + method->start);
json_tok_full_len(method),
json_tok_full(jcon->buffer, method));
return;
}
if (c->json_cmd->deprecated && !deprecated_apis) {

View File

@ -719,7 +719,8 @@ bool json_tok_loglevel(struct command *cmd, const char *name,
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be 'io', 'debug', 'info', or "
"'unusual', not '%.*s'",
name, tok->end - tok->start, buffer + tok->start);
name,
json_tok_full_len(tok), json_tok_full(buffer, tok));
return false;
}
return true;

View File

@ -1099,8 +1099,8 @@ static void json_listconfigs(struct command *cmd,
if (configtok && !response) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Unknown config option '%.*s'",
configtok->end - configtok->start,
buffer + configtok->start);
json_tok_full_len(configtok),
json_tok_full(buffer, configtok));
return;
}
json_object_end(response);

View File

@ -886,8 +886,7 @@ command_find_channel(struct command *cmd,
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Given id is not a channel ID or "
"short channel ID: '%.*s'",
tok->end - tok->start,
buffer + tok->start);
json_tok_full_len(tok), json_tok_full(buffer, tok));
return NULL;
}
}

View File

@ -259,8 +259,8 @@ static void plugin_log_handle(struct plugin *plugin, const jsmntok_t *paramstok)
plugin_kill(plugin,
"Unknown log-level %.*s, valid values are "
"\"debug\", \"info\", \"warn\", or \"error\".",
json_tok_len(leveltok),
json_tok_contents(plugin->buffer, leveltok));
json_tok_full_len(leveltok),
json_tok_full(plugin->buffer, leveltok));
return;
}
@ -293,8 +293,8 @@ static void plugin_notification_handle(struct plugin *plugin,
plugin_log_handle(plugin, paramstok);
} else {
plugin_kill(plugin, "Unknown notification method %.*s",
json_tok_len(methtok),
json_tok_contents(plugin->buffer, methtok));
json_tok_full_len(methtok),
json_tok_full(plugin->buffer, methtok));
}
}