From 2ad1470b4ee020881347eff06adae5fc2d5de7eb Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Sun, 15 Mar 2015 21:23:44 +0100 Subject: [PATCH] char *getdns_pretty_print_list(getdns_list *list) Handy for debugging purposes --- src/dict.c | 26 ++++++++++++++++++++++++-- src/getdns/getdns_extra.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/dict.c b/src/dict.c index f97469b9..439ec0e6 100644 --- a/src/dict.c +++ b/src/dict.c @@ -598,7 +598,7 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent, * if an output error is encountered, a negative value */ static int -getdns_pp_list(gldns_buffer *buf, size_t indent, getdns_list *list, +getdns_pp_list(gldns_buffer *buf, size_t indent, const getdns_list *list, int for_namespaces) { size_t i, length, p = gldns_buffer_position(buf); @@ -901,7 +901,7 @@ getdns_pretty_print_dict(const struct getdns_dict *dict) if (!dict) return NULL; - buf = gldns_buffer_new(100); + buf = gldns_buffer_new(8192); if (!buf) return NULL; @@ -914,6 +914,28 @@ getdns_pretty_print_dict(const struct getdns_dict *dict) return ret; } /* getdns_pretty_print_dict */ +char * +getdns_pretty_print_list(const getdns_list *list) +{ + gldns_buffer *buf; + char *ret; + + if (!list) + return NULL; + + buf = gldns_buffer_new(4096); + if (!buf) + return NULL; + + if (getdns_pp_list(buf, 0, list, 0) < 0) { + gldns_buffer_free(buf); + return NULL; + } + ret = (char *) gldns_buffer_export(buf); + gldns_buffer_free(buf); + return ret; +} + getdns_return_t getdns_dict_remove_name(struct getdns_dict *this_dict, const char *name) { diff --git a/src/getdns/getdns_extra.h b/src/getdns/getdns_extra.h index a41a235a..874ef64d 100644 --- a/src/getdns/getdns_extra.h +++ b/src/getdns/getdns_extra.h @@ -187,6 +187,8 @@ getdns_context_get_edns_version(getdns_context *context, uint8_t* value); getdns_return_t getdns_context_get_edns_do_bit(getdns_context *context, uint8_t* value); +char *getdns_pretty_print_list(const getdns_list *some_list); + #ifdef __cplusplus } #endif