#define DUMP_H
#include <stdio.h>
+#include <stdbool.h>
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);
#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;
}
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);
}
}
};
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);