1 /*************************************************
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
8 /* This module contains code to initialize things from the
9 environment and the arguments. */
16 /*************************************************
17 * Decode stripchart config *
18 *************************************************/
20 /* First determine how many are requested, then compile the
21 regular expressions and save the title strings. Note that
22 stripchart_number is initialized to 1 or 2 to count the always-
23 present queue stripchart, and the optional size-monitoring
26 static void decode_stripchart_config(uschar *s)
30 /* Loop: first time just counts, second time does the
33 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);
73 stripchart_regex[indx] = pcre_compile(CS buffer, PCRE_COPT,
74 (const char **)&error, &offset, NULL);
75 if (stripchart_regex[indx] == NULL)
77 printf("regular expression error: %s at offset %d "
78 "while compiling %s\n", error, offset, buffer);
82 else stripchart_title[indx] = string_copy(buffer);
85 /* Advance past the delimiter and flip the first/second flag */
91 /* On the first pass, we now know the number of stripcharts. Get
92 store for holding the pointers to the regular expressions and
97 stripchart_number += count;
98 stripchart_regex = (pcre **)store_malloc(stripchart_number * sizeof(pcre *));
99 stripchart_title = (uschar **)store_malloc(stripchart_number * sizeof(uschar *));
105 /*************************************************
107 *************************************************/
109 void init(int argc, uschar **argv)
116 argc = argc; /* These are currently unused. */
119 /* Deal with simple values in the environment. */
121 s = US getenv("ACTION_OUTPUT");
124 if (Ustrcmp(s, "no") == 0) action_output = FALSE;
125 if (Ustrcmp(s, "yes") == 0) action_output = TRUE;
128 s = US getenv("ACTION_QUEUE_UPDATE");
131 if (Ustrcmp(s, "no") == 0) action_queue_update = FALSE;
132 if (Ustrcmp(s, "yes") == 0) action_queue_update = TRUE;
135 s = US getenv("BODY_MAX");
136 if (s != NULL && (x = Uatoi(s)) != 0) body_max = x;
138 s = US getenv("EXIM_PATH");
139 if (s != NULL) exim_path = string_copy(s);
141 s = US getenv("EXIMON_EXIM_CONFIG");
142 if (s != NULL) alternate_config = string_copy(s);
144 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 != NULL && (x = Uatoi(s)) != 0) log_depth = x;
159 s = US getenv("LOG_FILE_NAME");
160 if (s != NULL) log_file = string_copy(s);
162 s = US getenv("LOG_FONT");
163 if (s != NULL) log_font = string_copy(s);
165 s = US getenv("LOG_WIDTH");
166 if (s != NULL && (x = Uatoi(s)) != 0) log_width = x;
168 s = US getenv("MENU_EVENT");
169 if (s != NULL) menu_event = string_copy(s);
171 s = US getenv("MIN_HEIGHT");
172 if (s != NULL && (x = Uatoi(s)) > 0) min_height = x;
174 s = US getenv("MIN_WIDTH");
175 if (s != NULL && (x = Uatoi(s)) > 0) min_width = x;
177 s = US getenv("QUALIFY_DOMAIN");
178 if (s != NULL) qualify_domain = string_copy(s);
179 else qualify_domain = US""; /* Don't want NULL */
181 s = US getenv("QUEUE_DEPTH");
182 if (s != NULL && (x = Uatoi(s)) != 0) queue_depth = x;
184 s = US getenv("QUEUE_FONT");
185 if (s != NULL) queue_font = string_copy(s);
187 s = US getenv("QUEUE_INTERVAL");
188 if (s != NULL && (x = Uatoi(s)) != 0) queue_update = x;
190 s = US getenv("QUEUE_MAX_ADDRESSES");
191 if (s != NULL && (x = Uatoi(s)) != 0) queue_max_addresses = x;
193 s = US getenv("QUEUE_WIDTH");
194 if (s != NULL && (x = Uatoi(s)) != 0) queue_width = x;
196 s = US getenv("SPOOL_DIRECTORY");
197 if (s != NULL) spool_directory = string_copy(s);
199 s = US getenv("START_SMALL");
200 if (s != NULL && Ustrcmp(s, "yes") == 0) start_small = 1;
202 s = US getenv("TEXT_DEPTH");
203 if (s != NULL && (x = Uatoi(s)) != 0) text_depth = x;
205 s = US getenv("WINDOW_TITLE");
206 if (s != NULL) window_title = string_copy(s);
208 /* Deal with stripchart configuration. First see if we are monitoring
209 the size of a partition, then deal with log stripcharts in a separate
212 s = US getenv("SIZE_STRIPCHART");
213 if (s != NULL && *s != 0)
216 stripchart_varstart++;
217 size_stripchart = string_copy(s);
218 s = US getenv("SIZE_STRIPCHART_NAME");
219 if (s != NULL && *s != 0) size_stripchart_name = string_copy(s);
222 s = US getenv("LOG_STRIPCHARTS");
223 if (s != NULL) decode_stripchart_config(s);
225 s = US getenv("STRIPCHART_INTERVAL");
226 if (s != NULL && (x = Uatoi(s)) != 0) stripchart_update = x;
228 s = US getenv("QUEUE_STRIPCHART_NAME");
229 queue_stripchart_name = (s != NULL)? string_copy(s) : US"queue";
231 /* Compile the regex for matching yyyy-mm-dd at the start of a string. */
233 yyyymmdd_regex = pcre_compile("^\\d{4}-\\d\\d-\\d\\d\\s", PCRE_COPT,
234 (const char **)&error, &erroroffset, NULL);
237 /* End of em_init.c */