summaryrefslogtreecommitdiff
path: root/source4/librpc/ndr/ndr.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-11 04:04:36 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-11 04:04:36 +0000
commitcecbf0cd8b99f7019a83def88baec889d6a06e6f (patch)
tree108181e24bac1a4fa10a55de40547d9177b488e8 /source4/librpc/ndr/ndr.c
parenta934f89549b3d23199d68b7dc3fc3ad16e86b9ad (diff)
downloadsamba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.tar.gz
samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.tar.bz2
samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.zip
automatically generate ndr_print_*() functions for every IDL
structure. This allows easy debug and test tool writing without having to write functions that print every element of complex structures. (This used to be commit 81d6181172e36c6fbae0907550a29511ce708574)
Diffstat (limited to 'source4/librpc/ndr/ndr.c')
-rw-r--r--source4/librpc/ndr/ndr.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c
index 2ab78d3d09..f7aead014c 100644
--- a/source4/librpc/ndr/ndr.c
+++ b/source4/librpc/ndr/ndr.c
@@ -243,3 +243,64 @@ buffers:
done:
return NT_STATUS_OK;
}
+
+
+/*
+ print a generic array
+*/
+void ndr_print_array(struct ndr_print *ndr, const char *name, void *base,
+ size_t elsize, uint32 count,
+ void (*print_fn)(struct ndr_print *, const char *, void *))
+{
+ int i;
+ char *p = base;
+ ndr->print(ndr, "%s: ARRAY(%d)", name, count);
+ ndr->depth++;
+ for (i=0;i<count;i++) {
+ char *idx=NULL;
+ asprintf(&idx, "[%d]", i);
+ if (idx) {
+ print_fn(ndr, idx, p);
+ free(idx);
+ }
+ p += elsize;
+ }
+ ndr->depth--;
+}
+
+
+
+static void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...)
+{
+ va_list ap;
+ char *s = NULL;
+ int i;
+
+ va_start(ap, format);
+ vasprintf(&s, format, ap);
+ va_end(ap);
+
+ for (i=0;i<ndr->depth;i++) {
+ DEBUG(0,(" "));
+ }
+
+ DEBUG(0,("%s\n", s));
+ free(s);
+}
+
+/*
+ a useful helper function for printing idl structures via DEBUG()
+*/
+void ndr_print_debug(void (*fn)(struct ndr_print *, const char *, void *),
+ const char *name,
+ void *ptr)
+{
+ struct ndr_print ndr;
+
+ ndr.mem_ctx = talloc_init("ndr_print_debug");
+ if (!ndr.mem_ctx) return;
+ ndr.print = ndr_print_debug_helper;
+ ndr.depth = 0;
+ fn(&ndr, name, ptr);
+ talloc_destroy(ndr.mem_ctx);
+}