summaryrefslogtreecommitdiff
path: root/librpc
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-08-09 16:37:52 +1000
committerAndrew Bartlett <abartlet@samba.org>2010-08-14 11:58:13 +1000
commit3828c76c76e4e9ce7bdb33bc4871f5cf571cc18b (patch)
tree835b1e9da49815679bc16d8606955f2b0214146e /librpc
parent7bb5d353e84fa2998ae03fb7ecff1c59685dd9b7 (diff)
downloadsamba-3828c76c76e4e9ce7bdb33bc4871f5cf571cc18b.tar.gz
samba-3828c76c76e4e9ce7bdb33bc4871f5cf571cc18b.tar.bz2
samba-3828c76c76e4e9ce7bdb33bc4871f5cf571cc18b.zip
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>
Diffstat (limited to 'librpc')
-rw-r--r--librpc/ndr/libndr.h1
-rw-r--r--librpc/ndr/ndr.c20
-rw-r--r--librpc/ndr/ndr_basic.c49
3 files changed, 64 insertions, 6 deletions
diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index d5091a6619..9134efa174 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -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)
diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c
index 1600d51c1c..3f553a7cbc 100644
--- a/librpc/ndr/ndr.c
+++ b/librpc/ndr/ndr.c
@@ -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");
+ }
}
/*
diff --git a/librpc/ndr/ndr_basic.c b/librpc/ndr/ndr_basic.c
index d0d58b0884..0becf38f7b 100644
--- a/librpc/ndr/ndr_basic.c
+++ b/librpc/ndr/ndr_basic.c
@@ -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);
}
}