mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
tools/generate-wire.py: wirestring type for handing strings.
A convenient alias for char *, though we don't allow control characters so our logs can't be fooled with embedded \n. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
9a6c36a568
commit
b7db06b577
@ -33,6 +33,7 @@ varlen_structs = [
|
||||
'failed_htlc',
|
||||
'utxo',
|
||||
'bitcoin_tx',
|
||||
'wirestring',
|
||||
]
|
||||
|
||||
class FieldType(object):
|
||||
|
@ -206,6 +206,27 @@ void fromwire_pad(const u8 **cursor, size_t *max, size_t num)
|
||||
fromwire(cursor, max, NULL, num);
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't allow control chars except spaces: we only use this for stuff
|
||||
* from subdaemons, who shouldn't do that.
|
||||
*/
|
||||
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < *max; i++) {
|
||||
if ((*cursor)[i] == '\0') {
|
||||
char *str = tal_arr(ctx, char, i + 1);
|
||||
fromwire(cursor, max, str, i + 1);
|
||||
return str;
|
||||
}
|
||||
if ((*cursor)[i] < ' ')
|
||||
break;
|
||||
}
|
||||
fromwire_fail(cursor, max);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
REGISTER_TYPE_TO_STRING(short_channel_id, short_channel_id_to_str);
|
||||
REGISTER_TYPE_TO_HEXSTR(channel_id);
|
||||
|
||||
|
@ -151,6 +151,11 @@ void towire_pad(u8 **pptr, size_t num)
|
||||
memset(*pptr + oldsize, 0, num);
|
||||
}
|
||||
|
||||
void towire_wirestring(u8 **pptr, const char *str)
|
||||
{
|
||||
towire(pptr, str, strlen(str) + 1);
|
||||
}
|
||||
|
||||
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
|
||||
{
|
||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
||||
|
@ -21,6 +21,9 @@ struct bitcoin_txid;
|
||||
struct preimage;
|
||||
struct ripemd160;
|
||||
|
||||
/* Makes generate-wire.py work */
|
||||
typedef char wirestring;
|
||||
|
||||
void derive_channel_id(struct channel_id *channel_id,
|
||||
struct bitcoin_txid *txid, u16 txout);
|
||||
|
||||
@ -55,6 +58,7 @@ void towire_bool(u8 **pptr, bool v);
|
||||
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
|
||||
|
||||
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx);
|
||||
void towire_wirestring(u8 **pptr, const char *str);
|
||||
|
||||
const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n);
|
||||
u8 fromwire_u8(const u8 **cursor, size_t *max);
|
||||
@ -86,6 +90,7 @@ void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd
|
||||
void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
|
||||
|
||||
void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num);
|
||||
char *fromwire_wirestring(const tal_t *ctx, const u8 **cursor, size_t *max);
|
||||
|
||||
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
||||
const u8 **cursor, size_t *max);
|
||||
|
Loading…
Reference in New Issue
Block a user