Made ASN.1 memory dump also display printable characters.

git-svn-id: https://origsvn.digium.com/svn/libpri/branches/1.4@848 2fbb986a-6c06-0410-b554-c9c1f0a7f128
This commit is contained in:
Richard Mudgett 2009-06-03 22:51:42 +00:00
parent 2176bd7fa3
commit 47830a68aa

View File

@ -33,6 +33,7 @@
#include <stdio.h>
#include <ctype.h>
#include "compat.h"
#include "libpri.h"
@ -41,6 +42,26 @@
/* ------------------------------------------------------------------- */
/*!
* \internal
* \brief Dump the memory contents indicated in printable characters. (Helper function.)
*
* \param ctrl D channel controller for any diagnostic messages.
* \param start Dump memory starting position.
* \param end Dump memory ending position. (Not included in dump.)
*
* \return Nothing
*/
static void asn1_dump_mem_helper(struct pri *ctrl, const unsigned char *start,
const unsigned char *end)
{
pri_message(ctrl, " - \"");
for (; start < end; ++start) {
pri_message(ctrl, "%c", (isprint(*start)) ? *start : '~');
}
pri_message(ctrl, "\"\n");
}
/*!
* \internal
* \brief Dump the memory contents indicated.
@ -55,10 +76,12 @@
static void asn1_dump_mem(struct pri *ctrl, unsigned indent, const unsigned char *pos,
unsigned length)
{
const unsigned char *seg_start;
const unsigned char *end;
unsigned delimiter;
unsigned count;
seg_start = pos;
end = pos + length;
if (pos < end) {
delimiter = '<';
@ -71,12 +94,14 @@ static void asn1_dump_mem(struct pri *ctrl, unsigned indent, const unsigned char
if (end <= pos) {
break;
}
pri_message(ctrl, "\n");
asn1_dump_mem_helper(ctrl, seg_start, pos);
seg_start = pos;
}
} else {
pri_message(ctrl, "%*s<", indent, "");
}
pri_message(ctrl, ">\n");
pri_message(ctrl, ">");
asn1_dump_mem_helper(ctrl, seg_start, end);
}
/*!