Browse Source

lightningd: restore ' ' before '}' for older pylightning.

It needs this in compat mode to detect old (pre-0.6.3) end of JSON.
But it always does the first command in compat mode.

This was never really reliable, since the first command could be to
a plugin for which we simply pass through the JSON (though, carefully
appending the expected '\n\n' if not already there).

Reported-by: @laanwj
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pull/2938/head
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
841fba7295
  1. 9
      lightningd/json_stream.c
  2. 6
      lightningd/json_stream.h
  3. 6
      lightningd/jsonrpc.c

9
lightningd/json_stream.c

@ -160,6 +160,15 @@ void json_object_end(struct json_stream *js)
js_oom(js); js_oom(js);
} }
void json_object_compat_end(struct json_stream *js)
{
/* In 0.7.1 we upgraded pylightning to no longer need this. */
#ifdef COMPAT_V070
json_stream_append(js, " ", 1);
#endif
json_object_end(js);
}
void json_add_member(struct json_stream *js, void json_add_member(struct json_stream *js,
const char *fieldname, const char *fieldname,
bool quote, bool quote,

6
lightningd/json_stream.h

@ -65,10 +65,12 @@ bool json_stream_still_writing(const struct json_stream *js);
void json_array_start(struct json_stream *js, const char *fieldname); void json_array_start(struct json_stream *js, const char *fieldname);
/* '"fieldname" : { ' or '{ ' if fieldname is NULL */ /* '"fieldname" : { ' or '{ ' if fieldname is NULL */
void json_object_start(struct json_stream *ks, const char *fieldname); void json_object_start(struct json_stream *ks, const char *fieldname);
/* ' ], ' */ /* '],' */
void json_array_end(struct json_stream *js); void json_array_end(struct json_stream *js);
/* ' }, ' */ /* '},' */
void json_object_end(struct json_stream *js); void json_object_end(struct json_stream *js);
/* ' },' */
void json_object_compat_end(struct json_stream *js);
/** /**
* json_stream_append - literally insert this string into the json_stream. * json_stream_append - literally insert this string into the json_stream.

6
lightningd/jsonrpc.c

@ -455,7 +455,7 @@ struct command_result *command_success(struct command *cmd,
assert(cmd); assert(cmd);
assert(cmd->json_stream == result); assert(cmd->json_stream == result);
json_object_end(result); json_object_end(result);
json_object_end(result); json_object_compat_end(result);
return command_raw_complete(cmd, result); return command_raw_complete(cmd, result);
} }
@ -466,7 +466,7 @@ struct command_result *command_failed(struct command *cmd,
assert(cmd->json_stream == result); assert(cmd->json_stream == result);
/* Have to close error */ /* Have to close error */
json_object_end(result); json_object_end(result);
json_object_end(result); json_object_compat_end(result);
return command_raw_complete(cmd, result); return command_raw_complete(cmd, result);
} }
@ -512,7 +512,7 @@ static void json_command_malformed(struct json_connection *jcon,
json_add_member(js, "code", false, "%d", JSONRPC2_INVALID_REQUEST); json_add_member(js, "code", false, "%d", JSONRPC2_INVALID_REQUEST);
json_add_string(js, "message", error); json_add_string(js, "message", error);
json_object_end(js); json_object_end(js);
json_object_end(js); json_object_compat_end(js);
json_stream_close(js, NULL); json_stream_close(js, NULL);
} }

Loading…
Cancel
Save