servport.c ntlm.h smbbyteorder.h smbdes.h smbmd4.h \
smbencrypt.h smbdes.c smbencrypt.c smbmd4.c smbutil.c \
libesmtp/gethostbyname.h libesmtp/gethostbyname.c \
- smbtypes.h fm_getaddrinfo.c tls.c rfc822valid.c
+ smbtypes.h fm_getaddrinfo.c tls.c rfc822valid.c \
+ xmalloc.h sdump.h sdump.c
libfm_a_LIBADD= $(EXTRAOBJ)
libfm_a_DEPENDENCIES= $(EXTRAOBJ)
LDADD = libfm.a @LIBINTL@ $(LIBOBJS)
void interface_note_activity(struct hostdata *);
int interface_approve(struct hostdata *, flag domonitor);
-/* xmalloc.c */
-#if defined(HAVE_VOIDPOINTER)
-#define XMALLOCTYPE void
-#else
-#define XMALLOCTYPE char
-#endif
-XMALLOCTYPE *xmalloc(size_t);
-XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t);
-#define xfree(p) { if (p) { free(p); } (p) = 0; }
-char *xstrdup(const char *);
+#include "xmalloc.h"
/* protocol driver and methods */
int doPOP2 (struct query *);
--- /dev/null
+/* sdump.c -- library to allocate a printable version of a string */
+/** \file sdump.c
+ * \author Matthias Andree
+ * \date 2009
+ */
+
+#include <ctype.h> /* for isprint() */
+#include <stdio.h> /* for sprintf() */
+#include <stdlib.h> /* for size_t */
+#include "xmalloc.h" /* for xmalloc() */
+
+#include "sdump.h" /* for prototype */
+
+/** sdump converts a byte string \a in of size \a len into a printable
+ * string and returns a pointer to the memory region.
+ * \returns a pointer to a xmalloc()ed string that the caller must
+ * free() after use. This function causes program abort on failure. */
+char *sdump(const char *in, size_t len)
+{
+ size_t outlen = 0, i;
+ char *out, *oi;
+
+ for (i = 0; i < len; i++) {
+ outlen += isprint((unsigned char)in[i]) ? 1 : 4;
+ }
+
+ oi = out = (char *)xmalloc(outlen + 1);
+ for (i = 0; i < len; i++) {
+ if (isprint((unsigned char)in[i])) {
+ *(oi++) = in[i];
+ } else {
+ oi += sprintf(oi, "\\x%02X", in[i]);
+ }
+ }
+ *oi = '\0';
+ return out;
+}
--- /dev/null
+#ifndef SDUMP_H
+#define SDUMP_H
+
+#include <stdlib.h>
+
+char *sdump(const char *in, size_t len);
+
+#endif
--- /dev/null
+/* xmalloc.h -- split out of fetchmail.h */
+
+#ifndef XMALLOC_H
+#define XMALLOC_H
+
+#include "config.h"
+
+/* xmalloc.c */
+#if defined(HAVE_VOIDPOINTER)
+#define XMALLOCTYPE void
+#else
+#define XMALLOCTYPE char
+#endif
+XMALLOCTYPE *xmalloc(size_t);
+XMALLOCTYPE *xrealloc(/*@null@*/ XMALLOCTYPE *, size_t);
+#define xfree(p) { if (p) { free(p); } (p) = 0; }
+char *xstrdup(const char *);
+
+#endif