Use separate routine for translating return-codes to printable strings
authorJeremy Harris <jgh146exb@wizmail.org>
Sat, 2 Feb 2019 15:32:50 +0000 (15:32 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Sat, 2 Feb 2019 15:37:57 +0000 (15:37 +0000)
src/src/debug.c
src/src/deliver.c
src/src/functions.h
src/src/macros.h
src/src/transports/smtp.c

index 2ddf22907a083e6a9c31b091898e3d11c098b738..eb62157def1dfc6a90d4830225bf2279cf0d288d 100644 (file)
@@ -14,6 +14,26 @@ static int     debug_prefix_length = 0;
 
 
 
+const uschar * rc_names[] = {          /* Mostly for debug output */
+  [OK] =               US"OK",
+  [DEFER] =            US"DEFER",
+  [FAIL] =             US"FAIL",
+  [ERROR] =            US"ERROR",
+  [FAIL_FORCED] =      US"FAIL_FORCED",
+  [DECLINE] =          US"DECLINE",
+  [PASS] =             US"PASS",
+  [DISCARD] =          US"DISCARD",
+  [SKIP] =             US"SKIP",
+  [REROUTED] =         US"REROUTED",
+  [PANIC] =            US"PANIC",
+  [BAD64] =            US"BAD64",
+  [UNEXPECTED] =       US"UNEXPECTED",
+  [CANCELLED] =                US"CANCELLED",
+  [FAIL_SEND] =                US"FAIL_SEND",
+  [FAIL_DROP] =                US"FAIL_DROP"
+};
+
+
 /*************************************************
 *               Print tree                       *
 *************************************************/
@@ -127,6 +147,17 @@ debug_printf("%s uid=%ld gid=%ld euid=%ld egid=%ld\n", s,
   (long int)getegid());
 }
 
+/************************************************/
+
+/* Give a string for a return-code */
+
+const uschar *
+rc_to_string(int rc)
+{
+return rc < 0 || rc >= nelem(rc_names) ? US"?" : rc_names[rc];
+}
+
+
 
 
 
index 307989d408099ce0a538a8aae1c4bbd0088620bb..ebb64778c9dc7e74da348107ed0559d213ff2f0c 100644 (file)
@@ -3104,12 +3104,7 @@ while (addr_local)
 
         DEBUG(D_deliver|D_transport)
           debug_printf("%s shadow transport returned %s for %s\n",
-            stp->name,
-            sresult == OK ?    "OK" :
-            sresult == DEFER ? "DEFER" :
-            sresult == FAIL ?  "FAIL" :
-            sresult == PANIC ? "PANIC" : "?",
-            shadow_addr->address);
+            stp->name, rc_to_string(sresult), shadow_addr->address);
         }
 
       DEBUG(D_deliver|D_transport)
@@ -3138,12 +3133,7 @@ while (addr_local)
 
     DEBUG(D_deliver|D_transport)
       debug_printf("%s transport returned %s for %s\n",
-        tp->name,
-        result == OK ?    "OK" :
-        result == DEFER ? "DEFER" :
-        result == FAIL ?  "FAIL" :
-        result == PANIC ? "PANIC" : "?",
-        addr2->address);
+        tp->name, rc_to_string(result), addr2->address);
 
     /* If there is a retry_record, or if delivery is deferred, build a retry
     item for setting a new retry time or deleting the old retry record from
index 853a5fd80b8b79d5ea7044ccb72522c50112f9fe..8d2632c4b34bfe7769436b685368248575952cde 100644 (file)
@@ -357,6 +357,7 @@ extern void    queue_count(void);
 extern void    queue_run(uschar *, uschar *, BOOL);
 
 extern int     random_number(int);
+extern const uschar *rc_to_string(int);
 extern int     rda_interpret(redirect_block *, int, uschar *, uschar *,
                  uschar *, uschar *, uschar *, ugid_block *, address_item **,
                  uschar **, error_block **, int *, uschar *);
index 185ea6aff5c5b632e39e4275ac8045432cf21da4..0c54f969ce21657c5c03fcdb5c72eacf1d0c7e21 100644 (file)
@@ -278,7 +278,9 @@ and some additional values are used only by non-driver functions.
 
 OK, FAIL, DEFER, ERROR, and FAIL_FORCED are also declared in local_scan.h for
 use in the local_scan() function and in ${dlfunc loaded functions. Do not
-change them unilaterally. */
+change them unilaterally.
+
+Use rc_names[] for debug strings. */
 
 #define  OK            0    /* Successful match */
 #define  DEFER         1    /* Defer - some problem */
index a4f44bcada668231eccbd5f1629b00fdf953eb84..8d51ce5b680fe5f390004e915725a4db3393b318 100644 (file)
@@ -2039,7 +2039,7 @@ if (!continue_hostname)
          case FAIL_FORCED:     break;
          default:              set_errno_nohost(sx->addrlist, ERRNO_DNSDEFER,
                                  string_sprintf("DANE error: tlsa lookup %s",
-                                   rc == DEFER ? "DEFER" : "FAIL"),
+                                   rc_to_string(rc)),
                                  rc, FALSE);
 # ifndef DISABLE_EVENT
                                (void) event_raise(sx->conn_args.tblock->event_action,
@@ -4702,7 +4702,6 @@ retry_non_continued:
     {
     int rc;
     int host_af;
-    uschar *rs;
     BOOL host_is_expired = FALSE;
     BOOL message_defer = FALSE;
     BOOL some_deferred = FALSE;
@@ -4890,11 +4889,14 @@ retry_non_continued:
     treated separately. */
 
     host_af = Ustrchr(host->address, ':') == NULL ? AF_INET : AF_INET6;
-    if ((rs = ob->interface) && *rs)
       {
-      if (!smtp_get_interface(rs, host_af, addrlist, &interface, tid))
-       return FALSE;
-      pistring = string_sprintf("%s/%s", pistring, interface);
+      uschar * s = ob->interface;
+      if (s && *s)
+       {
+       if (!smtp_get_interface(s, host_af, addrlist, &interface, tid))
+         return FALSE;
+       pistring = string_sprintf("%s/%s", pistring, interface);
+       }
       }
 
     /* The first time round the outer loop, check the status of the host by
@@ -5139,14 +5141,9 @@ retry_non_continued:
 
     /* Delivery attempt finished */
 
-    rs = rc == OK ? US"OK"
-       : rc == DEFER ? US"DEFER"
-       : rc == ERROR ? US"ERROR"
-       : US"?";
-
     set_process_info("delivering %s: just tried %s [%s]%s for %s%s: result %s",
       message_id, host->name, host->address, pistring, addrlist->address,
-      addrlist->next ? " (& others)" : "", rs);
+      addrlist->next ? " (& others)" : "", rc_to_string(rc));
 
     /* Release serialization if set up */