(1) Typo in redirect router; (2) Update version number; (3) Update
[exim.git] / src / exim_monitor / em_init.c
CommitLineData
c988f1f4 1/* $Cambridge: exim/src/exim_monitor/em_init.c,v 1.2 2005/01/04 10:00:42 ph10 Exp $ */
059ec3d9
PH
2
3/*************************************************
4* Exim monitor *
5*************************************************/
6
c988f1f4 7/* Copyright (c) University of Cambridge 1995 - 2005 */
059ec3d9
PH
8/* See the file NOTICE for conditions of use and distribution. */
9
10/* This module contains code to initialize things from the
11environment and the arguments. */
12
13
14#include "em_hdr.h"
15
16
17
18/*************************************************
19* Decode stripchart config *
20*************************************************/
21
22/* First determine how many are requested, then compile the
23regular expressions and save the title strings. Note that
24stripchart_number is initialized to 1 or 2 to count the always-
25present queue stripchart, and the optional size-monitoring
26stripchart. */
27
28static void decode_stripchart_config(uschar *s)
29{
30int i;
31
32/* Loop: first time just counts, second time does the
33work. */
34
35for (i = 0; i <= 1; i++)
36
37 {
38 int first = 1;
39 int count = 0;
40 uschar *p = s;
41
42 if (*p == '/') p++; /* allow optional / at start */
43
44 /* This loops for all the substrings, using the first flag
45 to determine whether each is the first or second of the pairs. */
46
47 while (*p)
48 {
49 uschar *pp;
50 /* Handle continuations */
51 if (*p == '\n')
52 {
53 while (*(++p) == ' ' || *p == '\t');
54 if (*p == '/') p++;
55 }
56
57 /* Find the end of the string and count if first string */
58
59 pp = p;
60 while (*p && *p != '/') p++;
61 if (first) count++;
62
63 /* Take action on the second time round. */
64
65 if (i != 0)
66 {
67 uschar buffer[256];
68 int indx = count + stripchart_varstart - 1;
69 Ustrncpy(buffer, pp, p-pp);
70 buffer[p-pp] = 0;
71 if (first)
72 {
73 int offset;
74 const uschar *error;
75 stripchart_regex[indx] = pcre_compile(CS buffer, PCRE_COPT,
76 (const char **)&error, &offset, NULL);
77 if (stripchart_regex[indx] == NULL)
78 {
79 printf("regular expression error: %s at offset %d "
80 "while compiling %s\n", error, offset, buffer);
81 exit(99);
82 }
83 }
84 else stripchart_title[indx] = string_copy(buffer);
85 }
86
87 /* Advance past the delimiter and flip the first/second flag */
88
89 p++;
90 first = !first;
91 }
92
93 /* On the first pass, we now know the number of stripcharts. Get
94 store for holding the pointers to the regular expressions and
95 title strings. */
96
97 if (i == 0)
98 {
99 stripchart_number += count;
100 stripchart_regex = (pcre **)store_malloc(stripchart_number * sizeof(pcre *));
101 stripchart_title = (uschar **)store_malloc(stripchart_number * sizeof(uschar *));
102 }
103 }
104}
105
106
107/*************************************************
108* Initialize *
109*************************************************/
110
111void init(int argc, uschar **argv)
112{
113int x;
114int erroroffset;
115uschar *s;
116const uschar *error;
117
118argc = argc; /* These are currently unused. */
119argv = argv;
120
121/* Deal with simple values in the environment. */
122
123s = US getenv("ACTION_OUTPUT");
124if (s != NULL)
125 {
126 if (Ustrcmp(s, "no") == 0) action_output = FALSE;
127 if (Ustrcmp(s, "yes") == 0) action_output = TRUE;
128 }
129
130s = US getenv("ACTION_QUEUE_UPDATE");
131if (s != NULL)
132 {
133 if (Ustrcmp(s, "no") == 0) action_queue_update = FALSE;
134 if (Ustrcmp(s, "yes") == 0) action_queue_update = TRUE;
135 }
136
137s = US getenv("BODY_MAX");
138if (s != NULL && (x = Uatoi(s)) != 0) body_max = x;
139
140s = US getenv("EXIM_PATH");
141if (s != NULL) exim_path = string_copy(s);
142
143s = US getenv("EXIMON_EXIM_CONFIG");
144if (s != NULL) alternate_config = string_copy(s);
145
146s = US getenv("LOG_BUFFER");
147if (s != NULL)
148 {
149 uschar c[1];
150 if (sscanf(CS s, "%d%c", &x, c) > 0)
151 {
152 if (c[0] == 'K' || c[0] == 'k') x *= 1024;
153 if (x < 1024) x = 1024;
154 log_buffer_size = x;
155 }
156 }
157
158s = US getenv("LOG_DEPTH");
159if (s != NULL && (x = Uatoi(s)) != 0) log_depth = x;
160
161s = US getenv("LOG_FILE_NAME");
162if (s != NULL) log_file = string_copy(s);
163
164s = US getenv("LOG_FONT");
165if (s != NULL) log_font = string_copy(s);
166
167s = US getenv("LOG_WIDTH");
168if (s != NULL && (x = Uatoi(s)) != 0) log_width = x;
169
170s = US getenv("MENU_EVENT");
171if (s != NULL) menu_event = string_copy(s);
172
173s = US getenv("MIN_HEIGHT");
174if (s != NULL && (x = Uatoi(s)) > 0) min_height = x;
175
176s = US getenv("MIN_WIDTH");
177if (s != NULL && (x = Uatoi(s)) > 0) min_width = x;
178
179s = US getenv("QUALIFY_DOMAIN");
180if (s != NULL) qualify_domain = string_copy(s);
181 else qualify_domain = US""; /* Don't want NULL */
182
183s = US getenv("QUEUE_DEPTH");
184if (s != NULL && (x = Uatoi(s)) != 0) queue_depth = x;
185
186s = US getenv("QUEUE_FONT");
187if (s != NULL) queue_font = string_copy(s);
188
189s = US getenv("QUEUE_INTERVAL");
190if (s != NULL && (x = Uatoi(s)) != 0) queue_update = x;
191
192s = US getenv("QUEUE_MAX_ADDRESSES");
193if (s != NULL && (x = Uatoi(s)) != 0) queue_max_addresses = x;
194
195s = US getenv("QUEUE_WIDTH");
196if (s != NULL && (x = Uatoi(s)) != 0) queue_width = x;
197
198s = US getenv("SPOOL_DIRECTORY");
199if (s != NULL) spool_directory = string_copy(s);
200
201s = US getenv("START_SMALL");
202if (s != NULL && Ustrcmp(s, "yes") == 0) start_small = 1;
203
204s = US getenv("TEXT_DEPTH");
205if (s != NULL && (x = Uatoi(s)) != 0) text_depth = x;
206
207s = US getenv("WINDOW_TITLE");
208if (s != NULL) window_title = string_copy(s);
209
210/* Deal with stripchart configuration. First see if we are monitoring
211the size of a partition, then deal with log stripcharts in a separate
212function */
213
214s = US getenv("SIZE_STRIPCHART");
215if (s != NULL && *s != 0)
216 {
217 stripchart_number++;
218 stripchart_varstart++;
219 size_stripchart = string_copy(s);
220 s = US getenv("SIZE_STRIPCHART_NAME");
221 if (s != NULL && *s != 0) size_stripchart_name = string_copy(s);
222 }
223
224s = US getenv("LOG_STRIPCHARTS");
225if (s != NULL) decode_stripchart_config(s);
226
227s = US getenv("STRIPCHART_INTERVAL");
228if (s != NULL && (x = Uatoi(s)) != 0) stripchart_update = x;
229
230s = US getenv("QUEUE_STRIPCHART_NAME");
231queue_stripchart_name = (s != NULL)? string_copy(s) : US"queue";
232
233/* Compile the regex for matching yyyy-mm-dd at the start of a string. */
234
235yyyymmdd_regex = pcre_compile("^\\d{4}-\\d\\d-\\d\\d\\s", PCRE_COPT,
236 (const char **)&error, &erroroffset, NULL);
237}
238
239/* End of em_init.c */