[exim-cvs] Constification

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Exim Git Commits Mailing List
Datum:  
To: exim-cvs
Betreff: [exim-cvs] Constification
Gitweb: https://git.exim.org/exim.git/commitdiff/ecb371298ce4ab016d055de06cff252098e6e603
Commit:     ecb371298ce4ab016d055de06cff252098e6e603
Parent:     a19b9248eb5ec0414ccc4d214055e2c99debaba5
Author:     Thomas Noll <tn@???>
AuthorDate: Wed Sep 15 16:29:41 2021 +0100
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Wed Sep 15 16:29:41 2021 +0100


    Constification
---
 doc/doc-txt/ChangeLog |  5 +++++
 src/src/expand.c      |  4 ++--
 src/src/filter.c      | 53 +++++++++++++++++++++++++++------------------------
 src/src/functions.h   |  7 ++++---
 src/src/globals.c     |  2 +-
 src/src/local_scan.h  |  7 ++++---
 src/src/parse.c       |  3 ++-
 src/src/rfc2047.c     |  6 +++---
 8 files changed, 49 insertions(+), 38 deletions(-)


diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index 63f3578..6215613 100644
--- a/doc/doc-txt/ChangeLog
+++ b/doc/doc-txt/ChangeLog
@@ -13,6 +13,11 @@ JH/01 Move the wait-for-next-tick (needed for unique messmage IDs) from
 JH/02 Move from using the pcre library to pcre2.  The former is no longer
       being developed or supported (by the original developer).


+JH/03 Constification work in the filters module required a major version
+      bump for the local-scan API.  Specifically, the "headers_charset"
+      global which is visible via the API is now const and may therefore
+      not be modified by local-scan code.
+


 Exim version 4.95
 -----------------
diff --git a/src/src/expand.c b/src/src/expand.c
index 88d4e75..3d48301 100644
--- a/src/src/expand.c
+++ b/src/src/expand.c
@@ -1593,7 +1593,7 @@ Returns:        NULL if the header does not exist, else a pointer to a new
 */


 static uschar *
-find_header(uschar *name, int *newsize, unsigned flags, uschar *charset)
+find_header(uschar *name, int *newsize, unsigned flags, const uschar *charset)
 {
 BOOL found = !name;
 int len = name ? Ustrlen(name) : 0;
@@ -4592,7 +4592,7 @@ while (*s)
       unsigned flags = *name == 'r' ? FH_WANT_RAW
               : *name == 'l' ? FH_WANT_RAW|FH_WANT_LIST
               : 0;
-      uschar * charset = *name == 'b' ? NULL : headers_charset;
+      const uschar * charset = *name == 'b' ? NULL : headers_charset;


       s = read_header_name(name, sizeof(name), s);
       value = find_header(name, &newsize, flags, charset);
diff --git a/src/src/filter.c b/src/src/filter.c
index dfcc802..1dbae43 100644
--- a/src/src/filter.c
+++ b/src/src/filter.c
@@ -1993,16 +1993,19 @@ while (commands)
     s = expargs[0];


     if (filter_test != FTEST_NONE)
-      printf("Headers %s \"%s\"\n", (subtype == TRUE)? "add" :
-        (subtype == FALSE)? "remove" : "charset", string_printing(s));
+      printf("Headers %s \"%s\"\n",
+        subtype == TRUE ? "add"
+        : subtype == FALSE ? "remove"
+        : "charset",
+        string_printing(s));


     if (subtype == TRUE)
       {
       while (isspace(*s)) s++;
-      if (s[0] != 0)
+      if (*s)
         {
-        header_add(htype_other, "%s%s", s, (s[Ustrlen(s)-1] == '\n')?
-          "" : "\n");
+        header_add(htype_other, "%s%s", s,
+          s[Ustrlen(s)-1] == '\n' ? "" : "\n");
         header_last->type = header_checkname(header_last, FALSE);
         if (header_last->type >= 'a') header_last->type = htype_other;
         }
@@ -2020,7 +2023,7 @@ while (commands)
     /* This setting lasts only while the filter is running; on exit, the
     variable is reset to the previous value. */


-    else headers_charset = s;    /*XXX loses track of const */
+    else headers_charset = s;
     }
       break;


@@ -2043,18 +2046,18 @@ while (commands)
       ff_name = US"freeze";
       ff_ret = FF_FREEZE;


-      DEFERFREEZEFAIL:
-      fmsg = expargs[0];        /*XXX loses track of const */
-      if (Ustrlen(fmsg) > 1024) Ustrcpy(fmsg + 1000, US" ... (truncated)");
-      fmsg = US string_printing(fmsg);
-      *error_pointer = fmsg;
+    DEFERFREEZEFAIL:
+      *error_pointer = fmsg = US string_printing(Ustrlen(expargs[0]) > 1024
+    ? string_sprintf("%.1000s ... (truncated)", expargs[0])
+    : string_copy(expargs[0]));


       if (filter_test != FTEST_NONE)
     {
     indent();
     printf("%c%s text \"%s\"\n", toupper(ff_name[0]), ff_name+1, fmsg);
     }
-      else DEBUG(D_filter) debug_printf_indent("Filter: %s \"%s\"\n", ff_name, fmsg);
+      else
+        DEBUG(D_filter) debug_printf_indent("Filter: %s \"%s\"\n", ff_name, fmsg);
       return ff_ret;


     case finish_command:
@@ -2064,19 +2067,19 @@ while (commands)
     printf("%sinish\n", (commands->seen)? "Seen f" : "F");
     }
       else
-    {
     DEBUG(D_filter) debug_printf_indent("Filter: %sfinish\n",
-      (commands->seen)? " Seen " : "");
-    }
+      commands->seen ? " Seen " : "");
       finish_obeyed = TRUE;
-      return filter_delivered? FF_DELIVERED : FF_NOTDELIVERED;
+      return filter_delivered ? FF_DELIVERED : FF_NOTDELIVERED;


     case if_command:
     {
     uschar *save_address = filter_thisaddress;
     int ok = FF_DELIVERED;
     condition_value = test_condition(commands->args[0].c, TRUE);
-    if (*error_pointer != NULL) ok = FF_ERROR; else
+    if (*error_pointer)
+      ok = FF_ERROR;
+    else
       {
       output_indent += 2;
       ok = interpret_commands(commands->args[condition_value? 1:2].f,
@@ -2084,7 +2087,7 @@ while (commands)
       output_indent -= 2;
       }
     filter_thisaddress = save_address;
-    if (finish_obeyed || (ok != FF_DELIVERED && ok != FF_NOTDELIVERED))
+    if (finish_obeyed  ||  ok != FF_DELIVERED && ok != FF_NOTDELIVERED)
       return ok;
     }
       break;
@@ -2096,7 +2099,7 @@ while (commands)


     case mail_command:
     case vacation_command:
-    if (return_path == NULL || return_path[0] == 0)
+    if (!return_path || !*return_path)
       {
       if (filter_test != FTEST_NONE)
         printf("%s command ignored because return_path is empty\n",
@@ -2126,10 +2129,10 @@ while (commands)


     for (i = 0; i < MAILARGS_STRING_COUNT; i++)
       {
-      uschar *p;
+      const uschar *p;
       const uschar *s = expargs[i];


-      if (s == NULL) continue;
+      if (!s) continue;


       if (i != mailarg_index_text) for (p = s; *p != 0; p++)
         {
@@ -2161,12 +2164,12 @@ while (commands)


           else
         {
-        uschar *pp;
+        const uschar *pp;
         for (pp = p + 1;; pp++)
           {
           c = *pp;
           if (c == ':' && pp != p + 1) break;
-          if (c == 0 || c == ':' || isspace(*pp))
+          if (!c || c == ':' || isspace(c))
             {
             *error_pointer = string_sprintf("\\n not followed by space or "
               "valid header name in \"%.1024s\" in %s command",
@@ -2196,7 +2199,7 @@ while (commands)
         commands->noerror ? " (noerror)" : "");
       for (i = 1; i < MAILARGS_STRING_COUNT; i++)
         {
-        uschar *arg = commands->args[i].u;
+        const uschar *arg = commands->args[i].u;
         if (arg)
           {
           int len = Ustrlen(mailargs[i]);
@@ -2505,7 +2508,7 @@ filter_interpret(uschar *filter, int options, address_item **generated,
 int i;
 int yield = FF_ERROR;
 uschar *ptr = filter;
-uschar *save_headers_charset = headers_charset;
+const uschar *save_headers_charset = headers_charset;
 filter_cmd *commands = NULL;
 filter_cmd **lastcmdptr = &commands;


diff --git a/src/src/functions.h b/src/src/functions.h
index a519988..4342406 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -378,7 +378,8 @@ extern uschar *parse_find_address_end(const uschar *, BOOL);
 extern const uschar *parse_find_at(const uschar *);
 extern const uschar *parse_fix_phrase(const uschar *, int);
 extern const uschar *parse_message_id(const uschar *, uschar **, uschar **);
-extern const uschar *parse_quote_2047(const uschar *, int, uschar *, BOOL);
+extern const uschar *parse_quote_2047(const uschar *, int, const uschar *,
+                      BOOL);
 extern const uschar *parse_date_time(const uschar *str, time_t *t);
 extern void priv_drop_temp(const uid_t, const gid_t);
 extern void priv_restore(void);
@@ -444,8 +445,8 @@ extern header_line *rewrite_header(header_line *,
 extern const uschar *rewrite_one(const uschar *, int, BOOL *, BOOL, uschar *,
                  rewrite_rule *);
 extern void    rewrite_test(const uschar *);
-extern uschar *rfc2047_decode2(uschar *, BOOL, uschar *, int, int *, int *,
-                 uschar **);
+extern uschar *rfc2047_decode2(uschar *, BOOL, const uschar *, int, int *,
+                     int *, uschar **);
 extern int     route_address(address_item *, address_item **, address_item **,
                  address_item **, address_item **, int);
 extern int     route_check_prefix(const uschar *, const uschar *, unsigned *);
diff --git a/src/src/globals.c b/src/src/globals.c
index 7dfbc76..1926913 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -953,7 +953,7 @@ volatile sig_atomic_t had_command_timeout = 0;
 volatile sig_atomic_t had_command_sigterm = 0;
 volatile sig_atomic_t had_data_timeout    = 0;
 volatile sig_atomic_t had_data_sigint     = 0;
-uschar *headers_charset        = US HEADERS_CHARSET;
+const uschar *headers_charset  = US HEADERS_CHARSET;
 int     header_insert_maxlen   = 64 * 1024;
 header_line  *header_last      = NULL;
 header_line  *header_list      = NULL;
diff --git a/src/src/local_scan.h b/src/src/local_scan.h
index cb50a68..3efe949 100644
--- a/src/src/local_scan.h
+++ b/src/src/local_scan.h
@@ -40,7 +40,7 @@ ABI is changed in a non backward compatible way. The minor number is increased
 each time a new feature is added (in a way that doesn't break backward
 compatibility). */


-#define LOCAL_SCAN_ABI_VERSION_MAJOR 4
+#define LOCAL_SCAN_ABI_VERSION_MAJOR 5
 #define LOCAL_SCAN_ABI_VERSION_MINOR 1
 #define LOCAL_SCAN_ABI_VERSION \
   LOCAL_SCAN_ABI_VERSION_MAJOR.LOCAL_SCAN_ABI_VERSION_MINOR
@@ -160,7 +160,7 @@ extern unsigned int debug_selector;    /* Debugging bits */
 extern int     body_linecount;         /* Line count in body */
 extern int     body_zerocount;         /* Binary zero count in body */
 extern uschar *expand_string_message;  /* Error info for failing expansion */
-extern uschar *headers_charset;        /* Charset for RFC 2047 decoding */
+extern const uschar *headers_charset;  /* Charset for RFC 2047 decoding */
 extern header_line *header_last;       /* Final header */
 extern header_line *header_list;       /* First header */
 extern BOOL    host_checking;          /* Set when checking a host */
@@ -198,7 +198,8 @@ extern int     lss_match_address(uschar *, uschar *, BOOL);
 extern int     lss_match_host(uschar *, uschar *, uschar *);
 extern void    receive_add_recipient(uschar *, int);
 extern BOOL    receive_remove_recipient(uschar *);
-extern uschar *rfc2047_decode(uschar *, BOOL, uschar *, int, int *, uschar **);
+extern uschar *rfc2047_decode(uschar *, BOOL, const uschar *, int, int *,
+                  uschar **);
 extern int     smtp_fflush(void);
 extern void    smtp_printf(const char *, BOOL, ...) PRINTF_FUNCTION(1,3);
 extern void    smtp_vprintf(const char *, BOOL, va_list);
diff --git a/src/src/parse.c b/src/src/parse.c
index 58f8941..352f07d 100644
--- a/src/src/parse.c
+++ b/src/src/parse.c
@@ -863,7 +863,8 @@ Returns:       pointer to the original string, if no quoting needed, or
 */


 const uschar *
-parse_quote_2047(const uschar *string, int len, uschar *charset, BOOL fold)
+parse_quote_2047(const uschar *string, int len, const uschar *charset,
+  BOOL fold)
 {
 const uschar * s = string;
 int hlen, l;
diff --git a/src/src/rfc2047.c b/src/src/rfc2047.c
index 6c46102..c3cf4db 100644
--- a/src/src/rfc2047.c
+++ b/src/src/rfc2047.c
@@ -186,8 +186,8 @@ Returns:         the decoded, converted string, or NULL on error; if there are
 */


uschar *
-rfc2047_decode2(uschar *string, BOOL lencheck, uschar *target, int zeroval,
- int *lenptr, int *sizeptr, uschar **error)
+rfc2047_decode2(uschar *string, BOOL lencheck, const uschar *target,
+ int zeroval, int *lenptr, int *sizeptr, uschar **error)
{
int size = Ustrlen(string);
size_t dlen;
@@ -336,7 +336,7 @@ return string_from_gstring(yield);
argument. */

uschar *
-rfc2047_decode(uschar *string, BOOL lencheck, uschar *target, int zeroval,
+rfc2047_decode(uschar *string, BOOL lencheck, const uschar *target, int zeroval,
int *lenptr, uschar **error)
{
return rfc2047_decode2(string, lencheck, target, zeroval, lenptr, NULL, error);