mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
common/json_stream: make json_add_jsonstr take a length.
This is useful when have have a jsmntok_t. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -199,13 +199,13 @@ static char *json_member_direct(struct json_stream *js,
|
|||||||
|
|
||||||
void json_add_jsonstr(struct json_stream *js,
|
void json_add_jsonstr(struct json_stream *js,
|
||||||
const char *fieldname,
|
const char *fieldname,
|
||||||
const char *jsonstr)
|
const char *jsonstr,
|
||||||
|
size_t jsonstrlen)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
size_t len = strlen(jsonstr);
|
|
||||||
|
|
||||||
p = json_member_direct(js, fieldname, len);
|
p = json_member_direct(js, fieldname, jsonstrlen);
|
||||||
memcpy(p, jsonstr, len);
|
memcpy(p, jsonstr, jsonstrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is where we read the json_stream and write it to conn */
|
/* This is where we read the json_stream and write it to conn */
|
||||||
|
|||||||
@@ -157,12 +157,13 @@ void json_add_escaped_string(struct json_stream *result,
|
|||||||
* JSON-formatted.
|
* JSON-formatted.
|
||||||
* @js: the json_stream.
|
* @js: the json_stream.
|
||||||
* @fieldname: fieldname (if in object), otherwise must be NULL.
|
* @fieldname: fieldname (if in object), otherwise must be NULL.
|
||||||
* @jsonstr: the JSON entity, must be non-NULL, a null-terminated
|
* @jsonstr: the JSON entity
|
||||||
* string that is already formatted in JSON.
|
* @jsonstrlen: the length of @jsonstr
|
||||||
*/
|
*/
|
||||||
void json_add_jsonstr(struct json_stream *js,
|
void json_add_jsonstr(struct json_stream *js,
|
||||||
const char *fieldname,
|
const char *fieldname,
|
||||||
const char *jsonstr);
|
const char *jsonstr,
|
||||||
|
size_t jsonstrlen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* json_stream_output - start writing out a json_stream to this conn.
|
* json_stream_output - start writing out a json_stream to this conn.
|
||||||
|
|||||||
@@ -578,7 +578,7 @@ static struct json_stream *json_start(struct command *cmd)
|
|||||||
|
|
||||||
json_object_start(js, NULL);
|
json_object_start(js, NULL);
|
||||||
json_add_string(js, "jsonrpc", "2.0");
|
json_add_string(js, "jsonrpc", "2.0");
|
||||||
json_add_jsonstr(js, "id", cmd->id);
|
json_add_jsonstr(js, "id", cmd->id, strlen(cmd->id));
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,13 +742,15 @@ static void rpc_command_hook_final(struct rpc_command_hook_payload *p STEALS)
|
|||||||
|
|
||||||
if (p->custom_result != NULL) {
|
if (p->custom_result != NULL) {
|
||||||
struct json_stream *s = json_start(p->cmd);
|
struct json_stream *s = json_start(p->cmd);
|
||||||
json_add_jsonstr(s, "result", p->custom_result);
|
json_add_jsonstr(s, "result",
|
||||||
|
p->custom_result, strlen(p->custom_result));
|
||||||
json_object_end(s);
|
json_object_end(s);
|
||||||
return was_pending(command_raw_complete(p->cmd, s));
|
return was_pending(command_raw_complete(p->cmd, s));
|
||||||
}
|
}
|
||||||
if (p->custom_error != NULL) {
|
if (p->custom_error != NULL) {
|
||||||
struct json_stream *s = json_start(p->cmd);
|
struct json_stream *s = json_start(p->cmd);
|
||||||
json_add_jsonstr(s, "error", p->custom_error);
|
json_add_jsonstr(s, "error",
|
||||||
|
p->custom_error, strlen(p->custom_error));
|
||||||
json_object_end(s);
|
json_object_end(s);
|
||||||
return was_pending(command_raw_complete(p->cmd, s));
|
return was_pending(command_raw_complete(p->cmd, s));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -499,7 +499,8 @@ multifundchannel_finished(struct multifundchannel_command *mfc)
|
|||||||
mfc->removeds[i].error_message);
|
mfc->removeds[i].error_message);
|
||||||
if (mfc->removeds[i].error_data)
|
if (mfc->removeds[i].error_data)
|
||||||
json_add_jsonstr(out, "data",
|
json_add_jsonstr(out, "data",
|
||||||
mfc->removeds[i].error_data);
|
mfc->removeds[i].error_data,
|
||||||
|
strlen(mfc->removeds[i].error_data));
|
||||||
json_object_end(out); /* End error object */
|
json_object_end(out); /* End error object */
|
||||||
json_object_end(out);
|
json_object_end(out);
|
||||||
}
|
}
|
||||||
@@ -1382,7 +1383,8 @@ perform_fundpsbt(struct multifundchannel_command *mfc, u32 feerate)
|
|||||||
&after_fundpsbt,
|
&after_fundpsbt,
|
||||||
&mfc_forward_error,
|
&mfc_forward_error,
|
||||||
mfc);
|
mfc);
|
||||||
json_add_jsonstr(req->js, "utxos", mfc->utxos_str);
|
json_add_jsonstr(req->js, "utxos",
|
||||||
|
mfc->utxos_str, strlen(mfc->utxos_str));
|
||||||
json_add_bool(req->js, "reservedok", false);
|
json_add_bool(req->js, "reservedok", false);
|
||||||
} else {
|
} else {
|
||||||
plugin_log(mfc->cmd->plugin, LOG_DBG,
|
plugin_log(mfc->cmd->plugin, LOG_DBG,
|
||||||
@@ -1814,7 +1816,8 @@ post_cleanup_redo_multifundchannel(struct multifundchannel_redo *redo)
|
|||||||
json_add_string(out, "method", failing_method);
|
json_add_string(out, "method", failing_method);
|
||||||
if (mfc->removeds[i].error_data)
|
if (mfc->removeds[i].error_data)
|
||||||
json_add_jsonstr(out, "data",
|
json_add_jsonstr(out, "data",
|
||||||
mfc->removeds[i].error_data);
|
mfc->removeds[i].error_data,
|
||||||
|
strlen(mfc->removeds[i].error_data));
|
||||||
|
|
||||||
/* Close 'data'. */
|
/* Close 'data'. */
|
||||||
json_object_end(out);
|
json_object_end(out);
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ static struct command_result *start_mw(struct multiwithdraw_command *mw)
|
|||||||
&mw_forward_error,
|
&mw_forward_error,
|
||||||
mw);
|
mw);
|
||||||
json_add_bool(req->js, "reservedok", false);
|
json_add_bool(req->js, "reservedok", false);
|
||||||
json_add_jsonstr(req->js, "utxos", mw->utxos);
|
json_add_jsonstr(req->js, "utxos", mw->utxos, strlen(mw->utxos));
|
||||||
} else {
|
} else {
|
||||||
plugin_log(mw->cmd->plugin, LOG_DBG,
|
plugin_log(mw->cmd->plugin, LOG_DBG,
|
||||||
"multiwithdraw %"PRIu64": fundpsbt.",
|
"multiwithdraw %"PRIu64": fundpsbt.",
|
||||||
|
|||||||
@@ -346,7 +346,9 @@ openchannel_finished(struct multifundchannel_command *mfc)
|
|||||||
json_add_node_id(out, "id", &dest->id);
|
json_add_node_id(out, "id", &dest->id);
|
||||||
json_add_string(out, "method", "openchannel_signed");
|
json_add_string(out, "method", "openchannel_signed");
|
||||||
if (dest->error_data)
|
if (dest->error_data)
|
||||||
json_add_jsonstr(out, "data", dest->error_data);
|
json_add_jsonstr(out, "data",
|
||||||
|
dest->error_data,
|
||||||
|
strlen(dest->error_data));
|
||||||
json_object_end(out);
|
json_object_end(out);
|
||||||
|
|
||||||
return mfc_finished(mfc, out);
|
return mfc_finished(mfc, out);
|
||||||
|
|||||||
Reference in New Issue
Block a user