tidying
[exim.git] / src / src / readconf.c
index df3fe823cbf527541eaef8457136576f5852992f..70ce78f1f3a5c6b766445959a96f3c2886627308 100644 (file)
@@ -372,7 +372,9 @@ static optionlist optionlist_config[] = {
   { "write_rejectlog",          opt_bool,        &write_rejectlog }
 };
 
+#ifndef MACRO_PREDEF
 static int optionlist_config_size = nelem(optionlist_config);
+#endif
 
 
 #ifdef MACRO_PREDEF
@@ -395,7 +397,7 @@ options_from_list(optionlist_auths, optionlist_auths_size, US"AUTHENTICATORS", N
 
 for (ai = auths_available; ai->driver_name[0]; ai++)
   {
-  spf(buf, sizeof(buf), "_DRIVER_AUTHENTICATOR_%T", ai->driver_name);
+  spf(buf, sizeof(buf), US"_DRIVER_AUTHENTICATOR_%T", ai->driver_name);
   builtin_macro_create(buf);
   options_from_list(ai->options, (unsigned)*ai->options_count, US"AUTHENTICATOR", ai->driver_name);
   }
@@ -563,7 +565,7 @@ for (r = routers; r; r = r->next)
   for (i = 0; i < *ri->options_count; i++)
     {
     if ((ri->options[i].type & opt_mask) != opt_stringptr) continue;
-    if (p == (char *)(r->options_block) + (long int)(ri->options[i].value))
+    if (p == CS (r->options_block) + (long int)(ri->options[i].value))
       return US ri->options[i].name;
     }
   }
@@ -576,8 +578,8 @@ for (t = transports; t; t = t->next)
     optionlist * op = &ti->options[i];
     if ((op->type & opt_mask) != opt_stringptr) continue;
     if (p == (  op->type & opt_public
-            ? (char *)t
-            : (char *)t->options_block
+            ? CS t
+            : CS t->options_block
             )
             + (long int)op->value)
        return US op->name;
@@ -981,10 +983,8 @@ for (;;)
           "absolute path \"%s\"", ss);
       else
         {
-        int offset = 0;
-        int size = 0;
-        ss = string_append(NULL, &size, &offset, 3, config_directory, "/", ss);
-        ss[offset] = '\0';  /* string_append() does not zero terminate the string! */
+       gstring * g = string_append(NULL, 3, config_directory, "/", ss);
+       ss = string_from_gstring(g);
         }
 
     if (include_if_exists != 0 && (Ustat(ss, &statbuf) != 0)) continue;
@@ -1272,7 +1272,7 @@ ol = find_option(name2, oltop, last);
 if (ol == NULL) log_write(0, LOG_MAIN|LOG_PANIC_DIE,
   "Exim internal error: missing set flag for %s", name);
 return (data_block == NULL)? (BOOL *)(ol->value) :
-  (BOOL *)((uschar *)data_block + (long int)(ol->value));
+  (BOOL *)(US data_block + (long int)(ol->value));
 }
 
 
@@ -1697,16 +1697,19 @@ switch (type)
       int    sep_i = -(int)sep_o;
       const uschar * list = sptr;
       uschar * s;
-      uschar * list_o = *str_target;
-      int size = 0, len = 0;
+      gstring * list_o = NULL;
 
-      if (list_o)
-       size = (len = Ustrlen(list_o)) + 1;
+      if (*str_target)
+       {
+       list_o = string_get(Ustrlen(*str_target) + Ustrlen(sptr));
+       list_o = string_cat(list_o, *str_target);
+       }
 
       while ((s = string_nextinlist(&list, &sep_i, NULL, 0)))
-       list_o = string_append_listele(list_o, &size, &len, sep_o, s);
+       list_o = string_append_listele(list_o, sep_o, s);
+
       if (list_o)
-       *str_target = string_copy_malloc(list_o);
+       *str_target = string_copy_malloc(string_from_gstring(list_o));
       }
     else
       {
@@ -1745,8 +1748,8 @@ switch (type)
         }
       else
         {
-        chain = (rewrite_rule **)((uschar *)data_block + (long int)(ol2->value));
-        flagptr = (int *)((uschar *)data_block + (long int)(ol3->value));
+        chain = (rewrite_rule **)(US data_block + (long int)(ol2->value));
+        flagptr = (int *)(US data_block + (long int)(ol3->value));
         }
 
       while ((p = string_nextinlist(CUSS &sptr, &sep, big_buffer, BIG_BUFFER_SIZE)))
@@ -1778,7 +1781,7 @@ switch (type)
       if (data_block == NULL)
         *((uschar **)(ol2->value)) = ss;
       else
-        *((uschar **)((uschar *)data_block + (long int)(ol2->value))) = ss;
+        *((uschar **)(US data_block + (long int)(ol2->value))) = ss;
 
       if (ss != NULL)
         {
@@ -1797,7 +1800,7 @@ switch (type)
     if (data_block == NULL)
       *((uid_t *)(ol->value)) = uid;
     else
-      *((uid_t *)((uschar *)data_block + (long int)(ol->value))) = uid;
+      *((uid_t *)(US data_block + (long int)(ol->value))) = uid;
 
     /* Set the flag indicating a fixed value is set */
 
@@ -1819,7 +1822,7 @@ switch (type)
         if (data_block == NULL)
           *((gid_t *)(ol2->value)) = pw->pw_gid;
         else
-          *((gid_t *)((uschar *)data_block + (long int)(ol2->value))) = pw->pw_gid;
+          *((gid_t *)(US data_block + (long int)(ol2->value))) = pw->pw_gid;
         *set_flag = TRUE;
         }
       }
@@ -1841,7 +1844,7 @@ switch (type)
       if (data_block == NULL)
         *((uschar **)(ol2->value)) = ss;
       else
-        *((uschar **)((uschar *)data_block + (long int)(ol2->value))) = ss;
+        *((uschar **)(US data_block + (long int)(ol2->value))) = ss;
 
       if (ss != NULL)
         {
@@ -1859,7 +1862,7 @@ switch (type)
     if (data_block == NULL)
       *((gid_t *)(ol->value)) = gid;
     else
-      *((gid_t *)((uschar *)data_block + (long int)(ol->value))) = gid;
+      *((gid_t *)(US data_block + (long int)(ol->value))) = gid;
     *(get_set_flag(name, oltop, last, data_block)) = TRUE;
     break;
 
@@ -1889,7 +1892,7 @@ switch (type)
       if (data_block == NULL)
         *((uid_t **)(ol->value)) = list;
       else
-        *((uid_t **)((uschar *)data_block + (long int)(ol->value))) = list;
+        *((uid_t **)(US data_block + (long int)(ol->value))) = list;
 
       p = op;
       while (count-- > 1)
@@ -1930,7 +1933,7 @@ switch (type)
       if (data_block == NULL)
         *((gid_t **)(ol->value)) = list;
       else
-        *((gid_t **)((uschar *)data_block + (long int)(ol->value))) = list;
+        *((gid_t **)(US data_block + (long int)(ol->value))) = list;
 
       p = op;
       while (count-- > 1)
@@ -1966,7 +1969,7 @@ switch (type)
       if (data_block == NULL)
         *((uschar **)(ol2->value)) = sptr;
       else
-        *((uschar **)((uschar *)data_block + (long int)(ol2->value))) = sptr;
+        *((uschar **)(US data_block + (long int)(ol2->value))) = sptr;
       freesptr = FALSE;
       break;
       }
@@ -2004,7 +2007,7 @@ switch (type)
     int bit = 1 << ((ol->type >> 16) & 31);
     int *ptr = (data_block == NULL)?
       (int *)(ol->value) :
-      (int *)((uschar *)data_block + (long int)ol->value);
+      (int *)(US data_block + (long int)ol->value);
     if (boolvalue) *ptr |= bit; else *ptr &= ~bit;
     break;
     }
@@ -2014,7 +2017,7 @@ switch (type)
   if (data_block == NULL)
     *((BOOL *)(ol->value)) = boolvalue;
   else
-    *((BOOL *)((uschar *)data_block + (long int)(ol->value))) = boolvalue;
+    *((BOOL *)(US data_block + (long int)(ol->value))) = boolvalue;
 
   /* Verify fudge */
 
@@ -2027,7 +2030,7 @@ switch (type)
       if (data_block == NULL)
         *((BOOL *)(ol2->value)) = boolvalue;
       else
-        *((BOOL *)((uschar *)data_block + (long int)(ol2->value))) = boolvalue;
+        *((BOOL *)(US data_block + (long int)(ol2->value))) = boolvalue;
       }
     }
 
@@ -2042,7 +2045,7 @@ switch (type)
       if (data_block == NULL)
         *((BOOL *)(ol2->value)) = TRUE;
       else
-        *((BOOL *)((uschar *)data_block + (long int)(ol2->value))) = TRUE;
+        *((BOOL *)(US data_block + (long int)(ol2->value))) = TRUE;
       }
     }
   break;
@@ -2105,7 +2108,7 @@ switch (type)
   if (data_block == NULL)
     *((int *)(ol->value)) = value;
   else
-    *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
+    *((int *)(US data_block + (long int)(ol->value))) = value;
   break;
 
   /*  Integer held in K: again, allow octal and hex formats, and suffixes K, M
@@ -2155,7 +2158,7 @@ switch (type)
   if (data_block == NULL)
     *((int *)(ol->value)) = value;
   else
-    *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
+    *((int *)(US data_block + (long int)(ol->value))) = value;
   break;
 
   /*  Fixed-point number: held to 3 decimal places. */
@@ -2196,7 +2199,7 @@ switch (type)
   if (data_block == NULL)
     *((int *)(ol->value)) = value;
   else
-    *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
+    *((int *)(US data_block + (long int)(ol->value))) = value;
   break;
 
   /* There's a special routine to read time values. */
@@ -2209,7 +2212,7 @@ switch (type)
   if (data_block == NULL)
     *((int *)(ol->value)) = value;
   else
-    *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
+    *((int *)(US data_block + (long int)(ol->value))) = value;
   break;
 
   /* A time list is a list of colon-separated times, with the first
@@ -2221,7 +2224,7 @@ switch (type)
     int count = 0;
     int *list = (data_block == NULL)?
       (int *)(ol->value) :
-      (int *)((uschar *)data_block + (long int)(ol->value));
+      (int *)(US data_block + (long int)(ol->value));
 
     if (*s != 0) for (count = 1; count <= list[0] - 2; count++)
       {
@@ -2298,10 +2301,10 @@ t /= 24;
 d = t % 7;
 w = t/7;
 
-if (w > 0) { sprintf(CS p, "%dw", w); while (*p) p++; }
-if (d > 0) { sprintf(CS p, "%dd", d); while (*p) p++; }
-if (h > 0) { sprintf(CS p, "%dh", h); while (*p) p++; }
-if (m > 0) { sprintf(CS p, "%dm", m); while (*p) p++; }
+if (w > 0) p += sprintf(CS p, "%dw", w);
+if (d > 0) p += sprintf(CS p, "%dd", d);
+if (h > 0) p += sprintf(CS p, "%dh", h);
+if (m > 0) p += sprintf(CS p, "%dm", m);
 if (s > 0 || p == time_buffer) sprintf(CS p, "%ds", s);
 
 return time_buffer;
@@ -2371,7 +2374,7 @@ if (options_block != NULL)
   {
   if ((ol->type & opt_public) == 0)
     options_block = (void *)(((driver_instance *)options_block)->options_block);
-  value = (void *)((uschar *)options_block + (long int)value);
+  value = (void *)(US options_block + (long int)value);
   }
 
 switch(ol->type & opt_mask)
@@ -2460,7 +2463,7 @@ switch(ol->type & opt_mask)
       {
       void *value2 = ol2->value;
       if (options_block != NULL)
-        value2 = (void *)((uschar *)options_block + (long int)value2);
+        value2 = (void *)(US options_block + (long int)value2);
       s = *((uschar **)value2);
       if (!no_labels) printf("%s = ", name);
       printf("%s\n", (s == NULL)? US"" : string_printing(s));
@@ -2494,7 +2497,7 @@ switch(ol->type & opt_mask)
       {
       void *value2 = ol2->value;
       if (options_block != NULL)
-        value2 = (void *)((uschar *)options_block + (long int)value2);
+        value2 = (void *)(US options_block + (long int)value2);
       s = *((uschar **)value2);
       if (!no_labels) printf("%s = ", name);
       printf("%s\n", (s == NULL)? US"" : string_printing(s));
@@ -2589,7 +2592,7 @@ switch(ol->type & opt_mask)
     {
     void *value2 = ol2->value;
     if (options_block != NULL)
-      value2 = (void *)((uschar *)options_block + (long int)value2);
+      value2 = (void *)(US options_block + (long int)value2);
     s = *((uschar **)value2);
     if (s != NULL)
       {
@@ -3198,25 +3201,24 @@ if (config_file)
       /* relative configuration file name: working dir + / + basename(filename) */
 
       uschar buf[PATH_MAX];
-      int offset = 0;
-      int size = 0;
+      gstring * g;
 
       if (os_getcwd(buf, PATH_MAX) == NULL)
         {
         perror("exim: getcwd");
         exit(EXIT_FAILURE);
         }
-      config_main_directory = string_cat(NULL, &size, &offset, buf);
+      g = string_cat(NULL, buf);
 
       /* If the dir does not end with a "/", append one */
-      if (config_main_directory[offset-1] != '/')
-        config_main_directory = string_catn(config_main_directory, &size, &offset, US"/", 1);
+      if (g->s[g->ptr-1] != '/')
+        g = string_catn(g, US"/", 1);
 
       /* If the config file contains a "/", extract the directory part */
       if (last_slash)
-        config_main_directory = string_catn(config_main_directory, &size, &offset, filename, last_slash - filename);
+        g = string_catn(g, filename, last_slash - filename);
 
-      config_main_directory[offset] = '\0';
+      config_main_directory = string_from_gstring(g);
     }
   config_directory = config_main_directory;
   }
@@ -3269,9 +3271,8 @@ if (trusted_config && Ustrcmp(filename, US"/dev/null"))
 letter. If we see something starting with an upper case letter, it is taken as
 a macro definition. */
 
-while ((s = get_config_line()) != NULL)
+while ((s = get_config_line()))
   {
-
   if (config_lineno == 1 && Ustrstr(s, "\xef\xbb\xbf") == s)
     log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
       "found unexpected BOM (Byte Order Mark)");
@@ -3439,7 +3440,7 @@ if (*log_file_path != 0)
 openlog(). Default is LOG_MAIL set in globals.c. Allow the user to omit the
 leading "log_". */
 
-if (syslog_facility_str != NULL)
+if (syslog_facility_str)
   {
   int i;
   uschar *s = syslog_facility_str;
@@ -3449,27 +3450,22 @@ if (syslog_facility_str != NULL)
     s += 4;
 
   for (i = 0; i < syslog_list_size; i++)
-    {
     if (strcmpic(s, syslog_list[i].name) == 0)
       {
       syslog_facility = syslog_list[i].value;
       break;
       }
-    }
 
   if (i >= syslog_list_size)
-    {
     log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
       "failed to interpret syslog_facility \"%s\"", syslog_facility_str);
-    }
   }
 
 /* Expand pid_file_path */
 
 if (*pid_file_path != 0)
   {
-  s = expand_string(pid_file_path);
-  if (s == NULL)
+  if (!(s = expand_string(pid_file_path)))
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to expand pid_file_path "
       "\"%s\": %s", pid_file_path, expand_string_message);
   pid_file_path = s;
@@ -3477,7 +3473,7 @@ if (*pid_file_path != 0)
 
 /* Set default value of process_log_path */
 
-if (process_log_path == NULL || *process_log_path =='\0')
+if (!process_log_path || *process_log_path =='\0')
   process_log_path = string_sprintf("%s/exim-process.info", spool_directory);
 
 /* Compile the regex for matching a UUCP-style "From_" line in an incoming
@@ -3487,23 +3483,19 @@ regex_From = regex_must_compile(uucp_from_pattern, FALSE, TRUE);
 
 /* Unpick the SMTP rate limiting options, if set */
 
-if (smtp_ratelimit_mail != NULL)
-  {
+if (smtp_ratelimit_mail)
   unpick_ratelimit(smtp_ratelimit_mail, &smtp_rlm_threshold,
     &smtp_rlm_base, &smtp_rlm_factor, &smtp_rlm_limit);
-  }
 
-if (smtp_ratelimit_rcpt != NULL)
-  {
+if (smtp_ratelimit_rcpt)
   unpick_ratelimit(smtp_ratelimit_rcpt, &smtp_rlr_threshold,
     &smtp_rlr_base, &smtp_rlr_factor, &smtp_rlr_limit);
-  }
 
 /* The qualify domains default to the primary host name */
 
-if (qualify_domain_sender == NULL)
+if (!qualify_domain_sender)
   qualify_domain_sender = primary_hostname;
-if (qualify_domain_recipient == NULL)
+if (!qualify_domain_recipient)
   qualify_domain_recipient = qualify_domain_sender;
 
 /* Setting system_filter_user in the configuration sets the gid as well if a
@@ -3512,7 +3504,7 @@ name is given, but a numerical value does not. */
 if (system_filter_uid_set && !system_filter_gid_set)
   {
   struct passwd *pw = getpwuid(system_filter_uid);
-  if (pw == NULL)
+  if (!pw)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Failed to look up uid %ld",
       (long int)system_filter_uid);
   system_filter_gid = pw->pw_gid;
@@ -3522,14 +3514,14 @@ if (system_filter_uid_set && !system_filter_gid_set)
 /* If the errors_reply_to field is set, check that it is syntactically valid
 and ensure it contains a domain. */
 
-if (errors_reply_to != NULL)
+if (errors_reply_to)
   {
   uschar *errmess;
   int start, end, domain;
   uschar *recipient = parse_extract_address(errors_reply_to, &errmess,
     &start, &end, &domain, FALSE);
 
-  if (recipient == NULL)
+  if (!recipient)
     log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
       "error in errors_reply_to (%s): %s", errors_reply_to, errmess);
 
@@ -3551,12 +3543,13 @@ if (smtp_accept_max == 0 &&
 so that it can be computed from the host name, for example. We do this last
 so as to ensure that everything else is set up before the expansion. */
 
-if (host_number_string != NULL)
+if (host_number_string)
   {
   long int n;
   uschar *end;
   uschar *s = expand_string(host_number_string);
-  if (s == NULL)
+
+  if (!s)
     log_write(0, LOG_MAIN|LOG_PANIC_DIE,
         "failed to expand localhost_number \"%s\": %s",
         host_number_string, expand_string_message);
@@ -3575,11 +3568,10 @@ if (host_number_string != NULL)
 #ifdef SUPPORT_TLS
 /* If tls_verify_hosts is set, tls_verify_certificates must also be set */
 
-if ((tls_verify_hosts != NULL || tls_try_verify_hosts != NULL) &&
-     tls_verify_certificates == NULL)
+if ((tls_verify_hosts || tls_try_verify_hosts) && !tls_verify_certificates)
   log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
     "tls_%sverify_hosts is set, but tls_verify_certificates is not set",
-    (tls_verify_hosts != NULL)? "" : "try_");
+    tls_verify_hosts ? "" : "try_");
 
 /* This also checks that the library linkage is working and we can call
 routines in it, so call even if tls_require_ciphers is unset */
@@ -3642,7 +3634,7 @@ init_driver(driver_instance *d, driver_info *drivers_available,
 driver_info *dd;
 
 for (dd = drivers_available; dd->driver_name[0] != 0;
-     dd = (driver_info *)(((uschar *)dd) + size_of_info))
+     dd = (driver_info *)((US dd) + size_of_info))
   {
   if (Ustrcmp(d->driver_name, dd->driver_name) == 0)
     {
@@ -3855,7 +3847,7 @@ for (ol = d->info->options; ol < d->info->options + count; ol++)
   int type = ol->type & opt_mask;
   if (type != opt_stringptr) continue;
   options_block = ((ol->type & opt_public) == 0)? d->options_block : (void *)d;
-  value = *(uschar **)((uschar *)options_block + (long int)(ol->value));
+  value = *(uschar **)(US options_block + (long int)(ol->value));
   if (value != NULL && (ss = Ustrstr(value, s)) != NULL)
     {
     if (ss <= value || (ss[-1] != '$' && ss[-1] != '{') ||
@@ -3931,14 +3923,14 @@ else if (len == 7 && strncmpic(pp, US"timeout", len) == 0)
     static int values[] =
       { 'A',   'M',    RTEF_CTOUT,  RTEF_CTOUT|'A', RTEF_CTOUT|'M' };
 
-    for (i = 0; i < sizeof(extras)/sizeof(uschar *); i++)
+    for (i = 0; i < nelem(extras); i++)
       if (strncmpic(x, extras[i], xlen) == 0)
         {
         *more_errno = values[i];
         break;
         }
 
-    if (i >= sizeof(extras)/sizeof(uschar *))
+    if (i >= nelem(extras))
       if (strncmpic(x, US"DNS", xlen) == 0)
         log_write(0, LOG_MAIN|LOG_PANIC, "\"timeout_dns\" is no longer "
           "available in retry rules (it has never worked) - treated as "
@@ -4334,7 +4326,7 @@ while(next_section[0] != 0)
   {
   int bit;
   int first = 0;
-  int last = sizeof(section_list) / sizeof(uschar *);
+  int last = nelem(section_list);
   int mid = last/2;
   int n = Ustrlen(next_section);
 
@@ -4390,6 +4382,7 @@ save_config_position(const uschar *file, int line)
 this operates on a global (static) list that holds all the pre-parsed
 config lines, we do no further processing here, output formatting and
 honouring of <hide> or macros will be done during output */
+
 static void
 save_config_line(const uschar* line)
 {