Browse Source

common: infrastructure to construct warning messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
master
Rusty Russell 4 years ago
parent
commit
e6cefc4b00
  1. 37
      common/wire_error.c
  2. 24
      common/wire_error.h

37
common/wire_error.c

@ -42,6 +42,43 @@ u8 *towire_errorfmt(const tal_t *ctx,
return msg;
}
u8 *towire_warningfmtv(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt,
va_list ap)
{
/* BOLT #1:
*
* The channel is referred to by `channel_id`, unless `channel_id` is
* 0 (i.e. all bytes are 0), in which case it refers to all
* channels. */
static const struct channel_id all_channels;
char *estr;
u8 *msg;
estr = tal_vfmt(ctx, fmt, ap);
/* We need tal_len to work, so we use copy. */
msg = towire_warning(ctx, channel ? channel : &all_channels,
(u8 *)tal_dup_arr(estr, char, estr, strlen(estr), 0));
tal_free(estr);
return msg;
}
u8 *towire_warningfmt(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt, ...)
{
va_list ap;
u8 *msg;
va_start(ap, fmt);
msg = towire_warningfmtv(ctx, channel, fmt, ap);
va_end(ap);
return msg;
}
bool channel_id_is_all(const struct channel_id *channel_id)
{
return memeqzero(channel_id, sizeof(*channel_id));

24
common/wire_error.h

@ -32,6 +32,30 @@ u8 *towire_errorfmtv(const tal_t *ctx,
const char *fmt,
va_list ap);
/**
* towire_warningfmt - helper to turn string into WIRE_WARNING.
*
* @ctx: context to allocate from
* @channel: specific channel to complain about, or NULL for all.
* @fmt: format for warning.
*/
u8 *towire_warningfmt(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt, ...) PRINTF_FMT(3,4);
/**
* towire_warningfmtv - helper to turn string into WIRE_WARNING.
*
* @ctx: context to allocate from
* @channel: specific channel to complain about, or NULL for all.
* @fmt: format for warning.
* @ap: accumulated varargs.
*/
u8 *towire_warningfmtv(const tal_t *ctx,
const struct channel_id *channel,
const char *fmt,
va_list ap);
/* BOLT #1:
*
* The channel is referred to by `channel_id`, unless `channel_id` is 0

Loading…
Cancel
Save