From 33a9982c76489add2a4a49f4d16f7273895c526d Mon Sep 17 00:00:00 2001 From: pwpiwi Date: Fri, 10 Nov 2017 23:09:08 +0100 Subject: [PATCH] dump only leaf TLV data --- client/emv/dump.h | 1 + client/emv/emvcore.c | 6 ++++-- client/emv/tlv.c | 3 ++- client/emv/tlv.h | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/client/emv/dump.h b/client/emv/dump.h index ad69ea83..567a134f 100644 --- a/client/emv/dump.h +++ b/client/emv/dump.h @@ -17,6 +17,7 @@ #define DUMP_H #include +#include void dump_buffer_simple(const unsigned char *ptr, size_t len, FILE *f); void dump_buffer(const unsigned char *ptr, size_t len, FILE *f, int level); diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index 8dc93259..63a69baa 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -10,9 +10,11 @@ #include "emvcore.h" -static bool print_cb(void *data, const struct tlv *tlv, int level) { +static bool print_cb(void *data, const struct tlv *tlv, int level, bool is_leaf) { emv_tag_dump(tlv, stdout, level); - dump_buffer(tlv->value, tlv->len, stdout, level); + if (is_leaf) { + dump_buffer(tlv->value, tlv->len, stdout, level); + } return true; } diff --git a/client/emv/tlv.c b/client/emv/tlv.c index 7feaa9aa..24125cc7 100644 --- a/client/emv/tlv.c +++ b/client/emv/tlv.c @@ -317,7 +317,8 @@ void tlvdb_visit(const struct tlvdb *tlvdb, tlv_cb cb, void *data, int level) for (; tlvdb; tlvdb = next) { next = tlvdb->next; - cb(data, &tlvdb->tag, level); + bool is_leaf = (tlvdb->children == NULL); + cb(data, &tlvdb->tag, level, is_leaf); tlvdb_visit(tlvdb->children, cb, data, level+1); } } diff --git a/client/emv/tlv.h b/client/emv/tlv.h index 187781f8..5a573566 100644 --- a/client/emv/tlv.h +++ b/client/emv/tlv.h @@ -31,7 +31,7 @@ struct tlv { }; struct tlvdb; -typedef bool (*tlv_cb)(void *data, const struct tlv *tlv, int level); +typedef bool (*tlv_cb)(void *data, const struct tlv *tlv, int level, bool is_leaf); struct tlvdb *tlvdb_fixed(tlv_tag_t tag, size_t len, const unsigned char *value); struct tlvdb *tlvdb_external(tlv_tag_t tag, size_t len, const unsigned char *value); -- 2.39.5