1 /*************************************************
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* Copyright (c) The Exim Maintainers 2020 - 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
9 /* This module contains code to initialize things from the
10 environment and the arguments. */
17 /*************************************************
18 * Decode stripchart config *
19 *************************************************/
21 /* First determine how many are requested, then compile the
22 regular expressions and save the title strings. Note that
23 stripchart_number is initialized to 1 or 2 to count the always-
24 present queue stripchart, and the optional size-monitoring
27 static void decode_stripchart_config(uschar *s)
31 /* Loop: first time just counts, second time does the
34 for (i = 0; i <= 1; i++)
40 if (*p == '/') p++; /* allow optional / at start */
42 /* This loops for all the substrings, using the first flag
43 to determine whether each is the first or second of the pairs. */
48 /* Handle continuations */
51 while (*(++p) == ' ' || *p == '\t');
55 /* Find the end of the string and count if first string */
58 while (*p && *p != '/') p++;
61 /* Take action on the second time round. */
66 int indx = count + stripchart_varstart - 1;
67 Ustrncpy(buffer, pp, p-pp);
74 if (!(stripchart_regex[indx] =
75 pcre2_compile((PCRE2_SPTR)buffer,
76 PCRE2_ZERO_TERMINATED, PCRE_COPT,
77 &err, &offset, NULL)))
80 pcre2_get_error_message(err, errbuf, sizeof(errbuf));
81 printf("regular expression error: %s at offset %ld "
82 "while compiling %s\n", errbuf, (long)offset, buffer);
86 else stripchart_title[indx] = string_copy(buffer);
89 /* Advance past the delimiter and flip the first/second flag */
95 /* On the first pass, we now know the number of stripcharts. Get
96 store for holding the pointers to the regular expressions and
101 stripchart_number += count;
102 stripchart_regex = (pcre2_code **)store_malloc(stripchart_number * sizeof(pcre2_code *));
103 stripchart_title = (uschar **)store_malloc(stripchart_number * sizeof(uschar *));
109 /*************************************************
111 *************************************************/
113 void init(int argc, uschar **argv)
119 argc = argc; /* These are currently unused. */
122 /* Deal with simple values in the environment. */
124 if ((s = US getenv("ACTION_OUTPUT")))
126 if (Ustrcmp(s, "no") == 0) action_output = FALSE;
127 if (Ustrcmp(s, "yes") == 0) action_output = TRUE;
130 if ((s = US getenv("ACTION_QUEUE_UPDATE")))
132 if (Ustrcmp(s, "no") == 0) action_queue_update = FALSE;
133 if (Ustrcmp(s, "yes") == 0) action_queue_update = TRUE;
136 s = US getenv("BODY_MAX");
137 if (s && (x = Uatoi(s)) != 0) body_max = x;
139 if ((s = US getenv("EXIM_PATH")))
140 exim_path = string_copy(s);
142 if ((s = US getenv("EXIMON_EXIM_CONFIG")))
143 alternate_config = string_copy(s);
145 if ((s = US getenv("LOG_BUFFER")))
148 if (sscanf(CS s, "%d%c", &x, c) > 0)
150 if (c[0] == 'K' || c[0] == 'k') x *= 1024;
151 if (x < 1024) x = 1024;
156 s = US getenv("LOG_DEPTH");
157 if (s && (x = Uatoi(s)) != 0) log_depth = x;
159 if ((s = US getenv("LOG_FILE_NAME")))
160 log_file = string_copy(s);
162 if ((s = US getenv("LOG_FONT")))
163 log_font = string_copy(s);
165 s = US getenv("LOG_WIDTH");
166 if (s && (x = Uatoi(s)) != 0) log_width = x;
168 if ((s = US getenv("MENU_EVENT")))
169 menu_event = string_copy(s);
171 s = US getenv("MIN_HEIGHT");
172 if (s && (x = Uatoi(s)) > 0) min_height = x;
174 s = US getenv("MIN_WIDTH");
175 if (s && (x = Uatoi(s)) > 0) min_width = x;
177 if ((s = US getenv("QUALIFY_DOMAIN")))
178 qualify_domain = string_copy(s);
180 qualify_domain = US""; /* Don't want NULL */
182 s = US getenv("QUEUE_DEPTH");
183 if (s && (x = Uatoi(s)) != 0) queue_depth = x;
185 if ((s = US getenv("QUEUE_FONT")))
186 queue_font = string_copy(s);
188 s = US getenv("QUEUE_INTERVAL");
189 if (s && (x = Uatoi(s)) != 0) queue_update = x;
191 s = US getenv("QUEUE_MAX_ADDRESSES");
192 if (s && (x = Uatoi(s)) != 0) queue_max_addresses = x;
194 s = US getenv("QUEUE_WIDTH");
195 if (s && (x = Uatoi(s)) != 0) queue_width = x;
197 if ((s = US getenv("SPOOL_DIRECTORY")))
198 spool_directory = string_copy(s);
200 s = US getenv("START_SMALL");
201 if (s && Ustrcmp(s, "yes") == 0) start_small = 1;
203 s = US getenv("TEXT_DEPTH");
204 if (s && (x = Uatoi(s)) != 0) text_depth = x;
206 if ((s = US getenv("WINDOW_TITLE")))
207 window_title = string_copy(s);
209 /* Deal with stripchart configuration. First see if we are monitoring
210 the size of a partition, then deal with log stripcharts in a separate
213 s = US getenv("SIZE_STRIPCHART");
217 stripchart_varstart++;
218 size_stripchart = string_copy(s);
219 s = US getenv("SIZE_STRIPCHART_NAME");
220 if (s != NULL && *s != 0) size_stripchart_name = string_copy(s);
223 if ((s = US getenv("LOG_STRIPCHARTS")))
224 decode_stripchart_config(s);
226 s = US getenv("STRIPCHART_INTERVAL");
227 if (s && (x = Uatoi(s)) != 0) stripchart_update = x;
229 s = US getenv("QUEUE_STRIPCHART_NAME");
230 queue_stripchart_name = s ? string_copy(s) : US"queue";
232 /* Compile the regex for matching yyyy-mm-dd at the start of a string. */
234 yyyymmdd_regex = pcre2_compile((PCRE2_SPTR)"^\\d{4}-\\d\\d-\\d\\d\\s",
235 PCRE2_ZERO_TERMINATED, PCRE_COPT, &x, &erroroffset, NULL);
238 /* End of em_init.c */