mirror of
https://github.com/samba-team/samba.git
synced 2025-03-29 02:50:28 +03:00
ndr: allow ndr_print to print DATA_BLOB
this prints DATA_BLOB structures using the ndr->print() calls Signed-off-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
7bb5d353e8
commit
3828c76c76
@ -105,6 +105,7 @@ struct ndr_print {
|
||||
struct ndr_token_list *switch_list;
|
||||
void (*print)(struct ndr_print *, const char *, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
void *private_data;
|
||||
bool no_newline;
|
||||
};
|
||||
|
||||
#define LIBNDR_FLAG_BIGENDIAN (1<<0)
|
||||
|
@ -176,6 +176,12 @@ _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format,
|
||||
return;
|
||||
}
|
||||
|
||||
if (ndr->no_newline) {
|
||||
DEBUGADD(1,("%s", s));
|
||||
free(s);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0;i<ndr->depth;i++) {
|
||||
DEBUGADD(1,(" "));
|
||||
}
|
||||
@ -189,17 +195,21 @@ _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format,
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
for (i=0;i<ndr->depth;i++) {
|
||||
ndr->private_data = talloc_asprintf_append_buffer(
|
||||
(char *)ndr->private_data, " ");
|
||||
if (!ndr->no_newline) {
|
||||
for (i=0;i<ndr->depth;i++) {
|
||||
ndr->private_data = talloc_asprintf_append_buffer(
|
||||
(char *)ndr->private_data, " ");
|
||||
}
|
||||
}
|
||||
|
||||
va_start(ap, format);
|
||||
ndr->private_data = talloc_vasprintf_append_buffer((char *)ndr->private_data,
|
||||
format, ap);
|
||||
va_end(ap);
|
||||
ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
|
||||
"\n");
|
||||
if (!ndr->no_newline) {
|
||||
ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
|
||||
"\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1021,11 +1021,58 @@ _PUBLIC_ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name,
|
||||
ndr->depth--;
|
||||
}
|
||||
|
||||
static void ndr_print_asc(struct ndr_print *ndr, const uint8_t *buf, int len)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<len;i++)
|
||||
ndr->print(ndr, "%c", isprint(buf[i])?buf[i]:'.');
|
||||
}
|
||||
|
||||
/*
|
||||
ndr_print version of dump_data()
|
||||
*/
|
||||
static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
ndr->no_newline = true;
|
||||
|
||||
for (i=0;i<len;) {
|
||||
if (i%16 == 0 && i<len) {
|
||||
ndr->print(ndr, "[%04X] ",i);
|
||||
}
|
||||
|
||||
ndr->print(ndr, "%02X ",(int)buf[i]);
|
||||
i++;
|
||||
if (i%8 == 0) ndr->print(ndr," ");
|
||||
if (i%16 == 0) {
|
||||
ndr_print_asc(ndr,&buf[i-16],8); ndr->print(ndr," ");
|
||||
ndr_print_asc(ndr,&buf[i-8],8); ndr->print(ndr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (i%16) {
|
||||
int n;
|
||||
n = 16 - (i%16);
|
||||
ndr->print(ndr, " ");
|
||||
if (n>8) ndr->print(ndr," ");
|
||||
while (n--) ndr->print(ndr," ");
|
||||
n = MIN(8,i%16);
|
||||
ndr_print_asc(ndr,&buf[i-(i%16)],n); ndr->print(ndr, " ");
|
||||
n = (i%16) - n;
|
||||
if (n>0) ndr_print_asc(ndr,&buf[i-n],n);
|
||||
ndr->print(ndr,"\n");
|
||||
}
|
||||
|
||||
ndr->no_newline = false;
|
||||
}
|
||||
|
||||
|
||||
_PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
|
||||
{
|
||||
ndr->print(ndr, "%-25s: DATA_BLOB length=%u", name, (unsigned)r.length);
|
||||
if (r.length) {
|
||||
dump_data(10, r.data, r.length);
|
||||
ndr_dump_data(ndr, r.data, r.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user