Browse Source

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>
plugin-7
Rusty Russell 6 years ago
parent
commit
12731c4a60
  1. 8
      cli/lightning-cli.c
  2. 4
      common/json.c
  3. 4
      common/json.h
  4. 4
      lightningd/bitcoind.c
  5. 4
      lightningd/connect_control.c
  6. 4
      lightningd/gossip_control.c
  7. 6
      lightningd/json.c
  8. 12
      lightningd/jsonrpc.c
  9. 3
      lightningd/log.c
  10. 4
      lightningd/options.c
  11. 3
      lightningd/peer_control.c
  12. 8
      lightningd/plugin.c

8
cli/lightning-cli.c

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

4
common/json.c

@ -12,7 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.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) if (t->type == JSMN_STRING)
return buffer + t->start - 1; 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. */ /* 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) if (t->type == JSMN_STRING)
return t->end - t->start + 2; return t->end - t->start + 2;

4
common/json.h

@ -15,10 +15,10 @@ struct json_escaped;
struct short_channel_id; struct short_channel_id;
/* Include " if it's a string. */ /* 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. */ /* 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? */ /* Is this a string equal to str? */
bool json_tok_streq(const char *buffer, const jsmntok_t *tok, const char *str); bool json_tok_streq(const char *buffer, const jsmntok_t *tok, const char *str);

4
lightningd/bitcoind.c

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

4
lightningd/connect_control.c

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

4
lightningd/gossip_control.c

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

6
lightningd/json.c

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

12
lightningd/jsonrpc.c

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

3
lightningd/log.c

@ -719,7 +719,8 @@ bool json_tok_loglevel(struct command *cmd, const char *name,
command_fail(cmd, JSONRPC2_INVALID_PARAMS, command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be 'io', 'debug', 'info', or " "'%s' should be 'io', 'debug', 'info', or "
"'unusual', not '%.*s'", "'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 false;
} }
return true; return true;

4
lightningd/options.c

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

3
lightningd/peer_control.c

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

8
lightningd/plugin.c

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

Loading…
Cancel
Save