svn commit: samba r25799 - in branches/SAMBA_4_0/source/lib/util: .
gd at samba.org
gd at samba.org
Fri Nov 2 11:33:54 GMT 2007
Author: gd
Date: 2007-11-02 11:33:53 +0000 (Fri, 02 Nov 2007)
New Revision: 25799
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25799
Log:
Add dump_data_skip_zeros() which omits 16 zero bytes in a row (if not at the
beginning or the end of a blob). Usefull when inspecting protocols that
exchange huge mostly empty blobs.
Guenther
Modified:
branches/SAMBA_4_0/source/lib/util/util.c
branches/SAMBA_4_0/source/lib/util/util.h
Changeset:
Modified: branches/SAMBA_4_0/source/lib/util/util.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util/util.c 2007-11-02 11:01:18 UTC (rev 25798)
+++ branches/SAMBA_4_0/source/lib/util/util.c 2007-11-02 11:33:53 UTC (rev 25799)
@@ -393,24 +393,55 @@
*
* The data is only written if the log level is at least level.
*/
-_PUBLIC_ void dump_data(int level, const uint8_t *buf,int len)
+static void _dump_data(int level, const uint8_t *buf, int len,
+ bool omit_zero_bytes)
{
int i=0;
+ const uint8_t empty[16];
+ bool skipped = false;
+
if (len<=0) return;
if (!DEBUGLVL(level)) return;
-
- DEBUGADD(level,("[%03X] ",i));
+
+ memset(&empty, '\0', 16);
+
for (i=0;i<len;) {
+
+ if (i%16 == 0) {
+ if ((omit_zero_bytes == true) &&
+ (i > 0) &&
+ (len > i+16) &&
+ (memcmp(&buf[i], &empty, 16) == 0))
+ {
+ i +=16;
+ continue;
+ }
+
+ if (i<len) {
+ DEBUGADD(level,("[%04X] ",i));
+ }
+ }
+
DEBUGADD(level,("%02X ",(int)buf[i]));
i++;
- if (i%8 == 0) DEBUGADD(level,(" "));
- if (i%16 == 0) {
+ if (i%8 == 0) DEBUGADD(level,(" "));
+ if (i%16 == 0) {
+
print_asc(level,&buf[i-16],8); DEBUGADD(level,(" "));
print_asc(level,&buf[i-8],8); DEBUGADD(level,("\n"));
- if (i<len) DEBUGADD(level,("[%03X] ",i));
+
+ if ((omit_zero_bytes == true) &&
+ (len > i+16) &&
+ (memcmp(&buf[i], &empty, 16) == 0)) {
+ if (!skipped) {
+ DEBUGADD(level,("skipping zero buffer bytes\n"));
+ skipped = true;
+ }
+ }
}
}
+
if (i%16) {
int n;
n = 16 - (i%16);
@@ -420,12 +451,35 @@
n = MIN(8,i%16);
print_asc(level,&buf[i-(i%16)],n); DEBUGADD(level,( " " ));
n = (i%16) - n;
- if (n>0) print_asc(level,&buf[i-n],n);
- DEBUGADD(level,("\n"));
- }
+ if (n>0) print_asc(level,&buf[i-n],n);
+ DEBUGADD(level,("\n"));
+ }
+
}
/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level.
+ */
+_PUBLIC_ void dump_data(int level, const uint8_t *buf, int len)
+{
+ return _dump_data(level, buf, len, false);
+}
+
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level.
+ * 16 zero bytes in a row are ommited
+ */
+_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len)
+{
+ return _dump_data(level, buf, len, true);
+}
+
+
+/**
malloc that aborts with smb_panic on fail or zero size.
**/
Modified: branches/SAMBA_4_0/source/lib/util/util.h
===================================================================
--- branches/SAMBA_4_0/source/lib/util/util.h 2007-11-02 11:01:18 UTC (rev 25798)
+++ branches/SAMBA_4_0/source/lib/util/util.h 2007-11-02 11:33:53 UTC (rev 25799)
@@ -656,6 +656,14 @@
_PUBLIC_ void dump_data(int level, const uint8_t *buf,int len);
/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level.
+ * 16 zero bytes in a row are ommited
+ */
+_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len);
+
+/**
malloc that aborts with smb_panic on fail or zero size.
**/
_PUBLIC_ void *smb_xmalloc(size_t size);
More information about the samba-cvs
mailing list