[PATCH 2/3] librpc: Add NDR_PRINT_DEBUGC to ndr print to a debug class

Kai Blin kai at samba.org
Fri May 17 02:16:17 MDT 2013


Signed-off-by: Kai Blin <kai at samba.org>
---
 librpc/ndr/libndr.h  |  3 +++
 librpc/ndr/ndr.c     | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 librpc/wscript_build |  2 +-
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/librpc/ndr/libndr.h b/librpc/ndr/libndr.h
index 1bd284f..a950519 100644
--- a/librpc/ndr/libndr.h
+++ b/librpc/ndr/libndr.h
@@ -162,6 +162,7 @@ struct ndr_print {
 
 /* useful macro for debugging */
 #define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p)
+#define NDR_PRINT_DEBUGC(dbgc_class, type, p) ndr_print_debugc(dbgc_class, (ndr_print_fn_t)ndr_print_ ##type, #p, p)
 #define NDR_PRINT_UNION_DEBUG(type, level, p) ndr_print_union_debug((ndr_print_fn_t)ndr_print_ ##type, #p, level, p)
 #define NDR_PRINT_FUNCTION_DEBUG(type, flags, p) ndr_print_function_debug((ndr_print_function_t)ndr_print_ ##type, #type, flags, p)
 #define NDR_PRINT_BOTH_DEBUG(type, p) NDR_PRINT_FUNCTION_DEBUG(type, NDR_BOTH, p)
@@ -460,9 +461,11 @@ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx);
 DATA_BLOB ndr_push_blob(struct ndr_push *ndr);
 enum ndr_err_code ndr_push_expand(struct ndr_push *ndr, uint32_t extra_size);
 void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
+void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
 void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
 void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
 void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr);
+void ndr_print_debugc(int dbgc_class, ndr_print_fn_t fn, const char *name, void *ptr);
 void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr);
 void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr);
 char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr);
diff --git a/librpc/ndr/ndr.c b/librpc/ndr/ndr.c
index b77bfae..e86cf2f 100644
--- a/librpc/ndr/ndr.c
+++ b/librpc/ndr/ndr.c
@@ -165,6 +165,38 @@ _PUBLIC_ enum ndr_err_code ndr_push_expand(struct ndr_push *ndr, uint32_t extra_
 	return NDR_ERR_SUCCESS;
 }
 
+_PUBLIC_ void ndr_print_debugc_helper(struct ndr_print *ndr, const char *format, ...)
+{
+	va_list ap;
+	char *s = NULL;
+	uint32_t i;
+	int ret;
+	int dbgc_class;
+
+	va_start(ap, format);
+	ret = vasprintf(&s, format, ap);
+	va_end(ap);
+
+	if (ret == -1) {
+		return;
+	}
+
+	dbgc_class = *(int *)ndr->private_data;
+
+	if (ndr->no_newline) {
+		DEBUGADDC(dbgc_class, 1,("%s", s));
+		free(s);
+		return;
+	}
+
+	for (i=0;i<ndr->depth;i++) {
+		DEBUGADDC(dbgc_class, 1,("    "));
+	}
+
+	DEBUGADDC(dbgc_class, 1,("%s\n", s));
+	free(s);
+}
+
 _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) 
 {
 	va_list ap;
@@ -236,6 +268,25 @@ _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format,
 }
 
 /*
+  a useful helper function for printing idl structures via DEBUGC()
+*/
+_PUBLIC_ void ndr_print_debugc(int dbgc_class, ndr_print_fn_t fn, const char *name, void *ptr)
+{
+	struct ndr_print *ndr;
+
+	DEBUGC(dbgc_class, 1,(" "));
+
+	ndr = talloc_zero(NULL, struct ndr_print);
+	if (!ndr) return;
+	ndr->private_data = &dbgc_class;
+	ndr->print = ndr_print_debugc_helper;
+	ndr->depth = 1;
+	ndr->flags = 0;
+	fn(ndr, name, ptr);
+	talloc_free(ndr);
+}
+
+/*
   a useful helper function for printing idl structures via DEBUG()
 */
 _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
diff --git a/librpc/wscript_build b/librpc/wscript_build
index cc5d617..2017a29 100644
--- a/librpc/wscript_build
+++ b/librpc/wscript_build
@@ -642,7 +642,7 @@ bld.SAMBA_LIBRARY('ndr',
     public_deps='errors talloc samba-util',
     public_headers='gen_ndr/misc.h gen_ndr/ndr_misc.h ndr/libndr.h:ndr.h',
     header_path= [('*gen_ndr*', 'gen_ndr')],
-    vnum='0.0.1',
+    vnum='0.0.2',
     abi_directory='ABI',
     abi_match='ndr_* GUID_*',
     )
-- 
1.8.1.2



More information about the samba-technical mailing list