ccan: import ccan/json_out and ccan/json_escape.

These are generalized from our internal implementations.

The main difference is that 'struct json_escaped' is now 'struct
json_escape', so we replace that immediately.

The difference between lightningd's json-writing ringbuffer and the
more generic ccan/json_out is that the latter has a better API and
handles escaping transparently if something slips through (though
it does offer direct accessors so you can mess things up yourself!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-06-12 10:08:54 +09:30
parent 26cdf9d3dc
commit 220449e1cd
45 changed files with 1159 additions and 194 deletions

View File

@@ -1,10 +1,10 @@
#include <arpa/inet.h>
#include <ccan/json_escape/json_escape.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <ccan/tal/str/str.h>
#include <common/json.h>
#include <common/json_command.h>
#include <common/json_escaped.h>
#include <common/json_helpers.h>
#include <common/jsonrpc_errors.h>
#include <common/memleak.h>
@@ -349,7 +349,7 @@ void json_add_literal(struct json_stream *result, const char *fieldname,
void json_add_string(struct json_stream *result, const char *fieldname, const char *value TAKES)
{
struct json_escaped *esc = json_partial_escape(NULL, value);
struct json_escape *esc = json_partial_escape(NULL, value);
json_add_member(result, fieldname, "\"%s\"", esc->s);
tal_free(esc);
@@ -380,7 +380,7 @@ void json_add_tx(struct json_stream *result,
}
void json_add_escaped_string(struct json_stream *result, const char *fieldname,
const struct json_escaped *esc TAKES)
const struct json_escape *esc TAKES)
{
json_add_member(result, fieldname, "\"%s\"", esc->s);
if (taken(esc))