tidying
[exim.git] / src / src / debug.c
index 44e0cee2e83bf98720169a68d000b21532afe17d..f7002b147a50e6aafe0a2eb9ab3166d967add775 100644 (file)
@@ -30,7 +30,16 @@ const uschar * rc_names[] = {                /* Mostly for debug output */
   [UNEXPECTED] =       US"UNEXPECTED",
   [CANCELLED] =                US"CANCELLED",
   [FAIL_SEND] =                US"FAIL_SEND",
-  [FAIL_DROP] =                US"FAIL_DROP"
+  [FAIL_DROP] =                US"FAIL_DROP",
+  [DANE] =             US"DANE",
+};
+
+const uschar * dns_rc_names[] = {
+  [DNS_SUCCEED] =      US"DNS_SUCCEED",
+  [DNS_NOMATCH] =      US"DNS_NOMATCH",
+  [DNS_NODATA] =       US"DNS_NODATA",
+  [DNS_AGAIN] =                US"DNS_AGAIN",
+  [DNS_FAIL] =         US"DNS_FAIL",
 };
 
 
@@ -43,8 +52,8 @@ hold the line-drawing characters that need to be printed on every line as it
 moves down the page. This function is used only in debugging circumstances. The
 output is done via debug_printf(). */
 
-#define tree_printlinesize 132   /* line size for printing */
-static uschar tree_printline[tree_printlinesize];
+#define TREE_PRINTLINESIZE 132   /* line size for printing */
+static uschar tree_printline[TREE_PRINTLINESIZE];
 
 /* Internal recursive subroutine.
 
@@ -57,12 +66,12 @@ Returns:     nothing
 */
 
 static void
-tree_printsub(tree_node *p, int pos, int barswitch)
+tree_printsub(tree_node * p, int pos, int barswitch)
 {
 if (p->right) tree_printsub(p->right, pos+2, 1);
-for (int i = 0; i <= pos-1; i++) debug_printf("%c", tree_printline[i]);
-debug_printf("-->%s [%d]\n", p->name, p->balance);
-tree_printline[pos] = barswitch? '|' : ' ';
+for (int i = 0; i <= pos-1; i++) debug_printf_indent(" %c", tree_printline[i]);
+debug_printf_indent(" -->%s [%d]\n", p->name, p->balance);
+tree_printline[pos] = barswitch ? '|' : ' ';
 if (p->left)
   {
   tree_printline[pos+2] = '|';
@@ -73,11 +82,12 @@ if (p->left)
 /* The external function, with just a tree node argument. */
 
 void
-debug_print_tree(tree_node *p)
+debug_print_tree(const char * title, tree_node * p)
 {
-for (int i = 0; i < tree_printlinesize; i++) tree_printline[i] = ' ';
-if (!p) debug_printf("Empty Tree\n"); else tree_printsub(p, 0, 0);
-debug_printf("---- End of tree ----\n");
+debug_printf_indent("%s:\n", title);
+for (int i = 0; i < TREE_PRINTLINESIZE; i++) tree_printline[i] = ' ';
+if (!p) debug_printf_indent(" Empty Tree\n"); else tree_printsub(p, 0, 0);
+debug_printf_indent("---- End of tree ----\n");
 }
 
 
@@ -328,48 +338,52 @@ if (fstat(fd, &s) == 0 && (s.st_mode & S_IFMT) == S_IFSOCK)
   gstring * g = NULL;
   int val;
   socklen_t vlen = sizeof(val);
-  struct sockaddr a;
+  struct sockaddr_storage a;
   socklen_t alen = sizeof(a);
   struct sockaddr_in * sinp = (struct sockaddr_in *)&a;
   struct sockaddr_in6 * sin6p = (struct sockaddr_in6 *)&a;
-  struct sockaddr_un * sa_unp = (struct sockaddr_un *)&a;
+  struct sockaddr_un * sunp = (struct sockaddr_un *)&a;
 
-  if (getsockname(fd, &a, &alen) == 0)
-    switch (sinp->sin_family)
+  if (getsockname(fd, (struct sockaddr*)&a, &alen) == 0)
+    switch (a.ss_family)
       {
       case AF_INET:
-       g = string_cat(g, US" domain AF_INET");
+       g = string_cat(g, US"domain AF_INET");
        g = string_fmt_append(g, " lcl [%s]:%u",
          inet_ntoa(sinp->sin_addr), ntohs(sinp->sin_port));
-       if (getpeername(fd, &a, &alen) == 0)
+       alen = sizeof(*sinp);
+       if (getpeername(fd, (struct sockaddr *)sinp, &alen) == 0)
          g = string_fmt_append(g, " rmt [%s]:%u",
            inet_ntoa(sinp->sin_addr), ntohs(sinp->sin_port));
        break;
       case AF_INET6:
        {
        uschar buf[46];
-       g = string_cat(g, US" domain AF_INET6");
+       g = string_cat(g, US"domain AF_INET6");
        g = string_fmt_append(g, " lcl [%s]:%u",
          inet_ntop(AF_INET6, &sin6p->sin6_addr, CS buf, sizeof(buf)),
          ntohs(sin6p->sin6_port));
-       if (getpeername(fd, &a, &alen) == 0)
+       alen = sizeof(*sin6p);
+       if (getpeername(fd, (struct sockaddr *)sin6p, &alen) == 0)
          g = string_fmt_append(g, " rmt [%s]:%u",
            inet_ntop(AF_INET6, &sin6p->sin6_addr, CS buf, sizeof(buf)),
            ntohs(sin6p->sin6_port));
        break;
        }
       case AF_UNIX:
-       g = string_cat(g, US" domain AF_UNIX");
-       g = string_fmt_append(g, " lcl %s%s",
-         sa_unp->sun_path[0] ? US"" : US"@",
-         sa_unp->sun_path[0] ? sa_unp->sun_path : sa_unp->sun_path+1);
-       if (getpeername(fd, &a, &alen) == 0)
-         g = string_fmt_append(g, " rmt %s%s",
-           sa_unp->sun_path[0] ? US"" : US"@",
-           sa_unp->sun_path[0] ? sa_unp->sun_path : sa_unp->sun_path+1);
-       break;
+        g = string_cat(g, US"domain AF_UNIX");
+        if (alen > sizeof(sa_family_t)) /* not unix(7) "unnamed socket" */
+          g = string_fmt_append(g, " lcl %s%s",
+            sunp->sun_path[0] ? US"" : US"@",
+            sunp->sun_path[0] ? sunp->sun_path : sunp->sun_path+1);
+        alen = sizeof(*sunp);
+        if (getpeername(fd, (struct sockaddr *)sunp, &alen) == 0)
+          g = string_fmt_append(g, " rmt %s%s",
+            sunp->sun_path[0] ? US"" : US"@",
+            sunp->sun_path[0] ? sunp->sun_path : sunp->sun_path+1);
+        break;
       default:
-       g = string_fmt_append(g, " domain %u", sinp->sin_family);
+       g = string_fmt_append(g, "domain %u", sinp->sin_family);
        break;
       }
   if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &val, &vlen) == 0)
@@ -384,7 +398,7 @@ if (fstat(fd, &s) == 0 && (s.st_mode & S_IFMT) == S_IFSOCK)
     {
     struct protoent * p = getprotobynumber(val);
     g = p
-      ? string_fmt_append(g, " proto %s\n", p->p_name)
+      ? string_fmt_append(g, " proto %s", p->p_name)
       : string_fmt_append(g, " proto %d", val);
     }
 #endif