changeset 167:1540ba94d145

- Added dStr_printable() to dlib.
author jcid
date Mon, 07 Apr 2008 18:55:14 +0200
parents 9acc32678aea
children 291457f05a9d
files ChangeLog dlib/dlib.c dlib/dlib.h src/IO/IO.c src/IO/http.c src/capi.c
diffstat 6 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 07 00:01:25 2008 +0200
+++ b/ChangeLog	Mon Apr 07 18:55:14 2008 +0200
@@ -87,7 +87,7 @@
  - Fixed a bug in Html_parse_entity.
  - Fixed a bug in a_Url_cmp.
  - Fixed a bug in Cookies_parse_one. Set it to a single return point too!
- - Added dStr_memmem() to dlib.
+ - Added dStr_memmem() and dStr_printable() to dlib.
  - Fixed a decoding bug in the datauri dpi.
    Patches: place
 +- Fixed a problem with locally-installed dpis.
--- a/dlib/dlib.c	Mon Apr 07 00:01:25 2008 +0200
+++ b/dlib/dlib.c	Mon Apr 07 18:55:14 2008 +0200
@@ -435,6 +435,40 @@
 }
 
 /*
+ * Return a printable representation of the provided Dstr, limited to a length
+ * of roughly maxlen.
+ *
+ * This is NOT threadsafe.
+ */
+const char *dStr_printable(Dstr *in, int maxlen)
+{
+   int i;
+   static const char *const HEX = "0123456789ABCDEF";
+   static Dstr *out = NULL;
+
+   if (in == NULL)
+      return NULL;
+
+   if (out)
+      dStr_truncate(out, 0);
+   else
+      out = dStr_sized_new(in->len);
+
+   for (i = 0; (i < in->len) && (out->len < maxlen); ++i) {
+      if (isprint(in->str[i]) || (in->str[i] == '\n')) {
+         dStr_append_c(out, in->str[i]);
+      } else {
+         dStr_append_l(out, "\\x", 2);
+         dStr_append_c(out, HEX[(in->str[i] >> 4) & 15]);
+         dStr_append_c(out, HEX[in->str[i] & 15]);
+      }
+   }
+   if (out->len >= maxlen)
+      dStr_append(out, "...");
+   return out->str;
+}
+
+/*
  *- dList ---------------------------------------------------------------------
  */
 
--- a/dlib/dlib.h	Mon Apr 07 00:01:25 2008 +0200
+++ b/dlib/dlib.h	Mon Apr 07 18:55:14 2008 +0200
@@ -108,6 +108,7 @@
 void dStr_sprintfa (Dstr *ds, const char *format, ...);
 int  dStr_cmp(Dstr *ds1, Dstr *ds2);
 char *dStr_memmem(Dstr *haystack, Dstr *needle);
+const char *dStr_printable(Dstr *in, int maxlen);
 
 /*
  *-- dList --------------------------------------------------------------------
--- a/src/IO/IO.c	Mon Apr 07 00:01:25 2008 +0200
+++ b/src/IO/IO.c	Mon Apr 07 18:55:14 2008 +0200
@@ -354,9 +354,8 @@
          case OpAbort:
             io = Info->LocalKey;
             if (io->Buf->len > 0) {
-               /* MSG can be truncated by embedded NULLs */
                MSG_WARN("IO_write, closing with pending data not sent\n");
-               MSG_WARN(" \"%s\"\n", io->Buf->str);
+               MSG_WARN(" \"%s\"\n", dStr_printable(io->Buf, 2048));
             }
             /* close FD, remove from ValidIOs and remove its watch */
             IO_close_fd(io, IO_StopRdWr);
--- a/src/IO/http.c	Mon Apr 07 00:01:25 2008 +0200
+++ b/src/IO/http.c	Mon Apr 07 18:55:14 2008 +0200
@@ -278,8 +278,7 @@
    dStr_free(s_port, TRUE);
    dStr_free(full_path, TRUE);
    dStr_free(proxy_auth, TRUE);
-   /* debug msg will fail on embedded NULLs */
-   DEBUG_MSG(4, "Query:\n%s", query->str);
+   DEBUG_MSG(4, "Query:\n%s\n", dStr_printable(query, 8192));
    return query;
 }
 
--- a/src/capi.c	Mon Apr 07 00:01:25 2008 +0200
+++ b/src/capi.c	Mon Apr 07 18:55:14 2008 +0200
@@ -228,8 +228,7 @@
       MSG("Capi_dpi_verify_request: Permission Denied!\n");
       MSG("  URL_STR : %s\n", URL_STR(web->url));
       if (URL_FLAGS(web->url) & URL_Post) {
-         /* MSG will fail on embedded NULLs */
-         MSG("  URL_DATA: %s\n", URL_DATA(web->url)->str);
+         MSG("  URL_DATA: %s\n", dStr_printable(URL_DATA(web->url), 1024));
       }
    }
    return allow;