[exim-cvs] Use separate routine for translating return-codes…

Inizio della pagina
Delete this message
Reply to this message
Autore: Exim Git Commits Mailing List
Data:  
To: exim-cvs
Oggetto: [exim-cvs] Use separate routine for translating return-codes to printable strings
Gitweb: https://git.exim.org/exim.git/commitdiff/9c5e54499afef5167bee6ecdcbf8dd5f023f51e0
Commit:     9c5e54499afef5167bee6ecdcbf8dd5f023f51e0
Parent:     9e160d8100cd15517a3444c1ad8ab81e51399582
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sat Feb 2 15:32:50 2019 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sat Feb 2 15:37:57 2019 +0000


    Use separate routine for translating return-codes to printable strings
---
 src/src/debug.c           | 31 +++++++++++++++++++++++++++++++
 src/src/deliver.c         | 14 ++------------
 src/src/functions.h       |  1 +
 src/src/macros.h          |  4 +++-
 src/src/transports/smtp.c | 21 +++++++++------------
 5 files changed, 46 insertions(+), 25 deletions(-)


diff --git a/src/src/debug.c b/src/src/debug.c
index 2ddf229..eb62157 100644
--- a/src/src/debug.c
+++ b/src/src/debug.c
@@ -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];
+}
+
+



diff --git a/src/src/deliver.c b/src/src/deliver.c
index 307989d..ebb6477 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -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
diff --git a/src/src/functions.h b/src/src/functions.h
index 853a5fd..8d2632c 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -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 *);
diff --git a/src/src/macros.h b/src/src/macros.h
index 185ea6a..0c54f96 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -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 */
diff --git a/src/src/transports/smtp.c b/src/src/transports/smtp.c
index a4f44bc..8d51ce5 100644
--- a/src/src/transports/smtp.c
+++ b/src/src/transports/smtp.c
@@ -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 */