Diff

Differences From Artifact [7fcfcb69c1]:

To Artifact [1a96ee97b6]:


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163

164
165
166
167
168
169
170
171
172

173

174
175
176
177
178
179
180
			break;
		}

		/* Remove trailing crap (but not spaces). */
		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
			*linebuf_ptr = '\0';
			*linebuf_ptr--;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ' || *linebuf_ptr == '\t') {
			*linebuf_ptr++;
		}

		/* Handle section header. */
		if (linebuf_ptr[0] == '<' && linebuf_ptr[strlen(linebuf_ptr) - 1] == '>') {
			/* Remove < and > from around the data. */
			linebuf_ptr[strlen(linebuf_ptr) - 1] = '\0';
			*linebuf_ptr++;

			/* Lowercase the command part of the section. */
			tmp_ptr = linebuf_ptr;
			while (*tmp_ptr != '\0' && *tmp_ptr != ' ') {
				*tmp_ptr = tolower(*tmp_ptr);
				*tmp_ptr++;
			}

			/* If this is a close section command, handle it */
			if (linebuf_ptr[0] == '/') {
				*linebuf_ptr++;
				cmd = linebuf_ptr; 

				/* Find the last section closed. */
				tmp_ptr = strrchr(qualifbuf, '.');
				if (tmp_ptr == NULL) {
					lastsection = qualifbuf;
					tmp_ptr = qualifbuf;
				} else {
					lastsection = tmp_ptr + 1;
				}

				if (strcmp(cmd, lastsection) != 0) {

					PRINTERR_D("Section closing does not match last opened section.");
					PRINTERR_D("Last opened = \"%s\", Closing = \"%s\"", lastsection, cmd);

					retval = -1;
					lc_errno = LC_ERR_BADFORMAT;

					/* For this error, we abort immediately. */
					break;
				}

				lcpvret = lc_process_var(qualifbuf, NULL, NULL, LC_FLAGS_SECTIONEND);
				if (lcpvret < 0) {

					PRINTERR_D("Invalid section terminating: \"%s\"", qualifbuf);

				}

				/* Remove the "lastsection" part.. */
				*tmp_ptr = '\0';

				/* We just sucessfully closed the last section opened,
				   we must be in a valid section now since we only open







|





|






|





|




|












>
|
|
>









>
|
>







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
			break;
		}

		/* Remove trailing crap (but not spaces). */
		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
			*linebuf_ptr = '\0';
			linebuf_ptr--;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ' || *linebuf_ptr == '\t') {
			linebuf_ptr++;
		}

		/* Handle section header. */
		if (linebuf_ptr[0] == '<' && linebuf_ptr[strlen(linebuf_ptr) - 1] == '>') {
			/* Remove < and > from around the data. */
			linebuf_ptr[strlen(linebuf_ptr) - 1] = '\0';
			linebuf_ptr++;

			/* Lowercase the command part of the section. */
			tmp_ptr = linebuf_ptr;
			while (*tmp_ptr != '\0' && *tmp_ptr != ' ') {
				*tmp_ptr = tolower(*tmp_ptr);
				tmp_ptr++;
			}

			/* If this is a close section command, handle it */
			if (linebuf_ptr[0] == '/') {
				linebuf_ptr++;
				cmd = linebuf_ptr; 

				/* Find the last section closed. */
				tmp_ptr = strrchr(qualifbuf, '.');
				if (tmp_ptr == NULL) {
					lastsection = qualifbuf;
					tmp_ptr = qualifbuf;
				} else {
					lastsection = tmp_ptr + 1;
				}

				if (strcmp(cmd, lastsection) != 0) {
#ifdef DEBUG
					fprintf(stderr, "Section closing does not match last opened section.\n");
					fprintf(stderr, "Last opened = \"%s\", Closing = \"%s\"\n", lastsection, cmd);
#endif
					retval = -1;
					lc_errno = LC_ERR_BADFORMAT;

					/* For this error, we abort immediately. */
					break;
				}

				lcpvret = lc_process_var(qualifbuf, NULL, NULL, LC_FLAGS_SECTIONEND);
				if (lcpvret < 0) {
#ifdef DEBUG
					fprintf(stderr, "Invalid section terminating: \"%s\"\n", qualifbuf);
#endif
				}

				/* Remove the "lastsection" part.. */
				*tmp_ptr = '\0';

				/* We just sucessfully closed the last section opened,
				   we must be in a valid section now since we only open
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

227

228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245

246
247
248

249

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282

283

284
285
286
287
288

289

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307

308
309

310

311
312
313
314
315
316
317

			/* Parse out any argument passed. */
			sep = strpbrk(linebuf_ptr, " \t");

			if (sep != NULL) {
				cmdend = sep;
				/* Delete space at the end of the command. */
				*cmdend--; /* It currently derefs to the seperator.. */
				while (*cmdend <= ' ') {
					*cmdend = '\0';
					*cmdend--;
				}

				/* Delete the seperator char and any leading space. */
				*sep = '\0';
				*sep++;
				while (*sep == ' ' || *sep == '\t') {
					*sep++;
				}
				value = sep;
			} else {
				/* XXX: should this be "" or NULL ? */
				value = "";
			}

			cmd = linebuf_ptr;

			if (qualifbuf[0] != '\0') {
				strncat(qualifbuf, ".", sizeof(qualifbuf) - strlen(qualifbuf) - 1);
			}
			strncat(qualifbuf, cmd, sizeof(qualifbuf) - strlen(qualifbuf) - 1);

			lcpvret = lc_process_var(qualifbuf, value, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {

				PRINTERR_D("Invalid section: \"%s\"", qualifbuf);

				invalid_section = 1;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			}
			if (lcpvret == LC_CBRET_IGNORESECTION) {
				ignore_section = 1;
			}
			continue;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == '#' || *linebuf_ptr == '\0') {
			continue;
		}

		/* Don't handle things for a section that doesn't exist. */
		if (invalid_section == 1) {

			PRINTERR_D("Ignoring line (because invalid section): %s", linebuf);

			continue;
		}
		if (ignore_section == 1) {

			PRINTERR_D("Ignoring line (because ignored section): %s", linebuf);

			continue;
		}

		/* Find the command and the data in the line. */
		sep = strpbrk(linebuf_ptr, " \t");
		if (sep != NULL) {
			cmdend = sep;

			/* Delete space at the end of the command. */
			*cmdend--; /* It currently derefs to the seperator.. */
			while (*cmdend <= ' ') {
				*cmdend = '\0';
				*cmdend--;
			}

			/* Delete the seperator char and any leading space. */
			*sep = '\0';
			*sep++;
			while (*sep == ' ' || *sep == '\t') {
				*sep++;
			}
			value = sep;
		} else {
			value = NULL;
		}

		cmd = linebuf_ptr;

		/* Handle special commands. */
		if (strcasecmp(cmd, "include") == 0) {
			if (value == NULL) {
				lc_errno = LC_ERR_BADFORMAT;
				retval = -1;

				PRINTERR_D("Invalid include command.");

				continue;
			}

			lpcafret = lc_process_conf_apache_include(value, qualifbuf);
			if (lpcafret < 0) {

				PRINTERR_D("Error in included file.");

				retval = -1;
			}
			continue;
		}

		/* Create the fully qualified variable name. */
		if (qualifbuf[0] != '\0') {
			strncat(qualifbuf, ".", sizeof(qualifbuf) - strlen(qualifbuf) - 1);
		}
		strncat(qualifbuf, cmd, sizeof(qualifbuf) - strlen(qualifbuf) - 1);

		/* Call the parent and tell them we have data. */
		save_lc_errno = lc_errno;
		lc_errno = LC_ERR_NONE;
		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			if (lc_errno == LC_ERR_NONE) {

				PRINTERR_D("Invalid command: \"%s\"", cmd);

				lc_errno = LC_ERR_INVCMD;
			} else {

				PRINTERR_D("Error processing command (command was valid, but an error occured, errno was set)");

			}
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}

		/* Remove the "cmd" part of the buffer. */







|


|




|

|
















>
|
>

















>
|
>



>
|
>









|


|




|

|













>
|
>





>
|
>

















>
|
>


>
|
>







197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

			/* Parse out any argument passed. */
			sep = strpbrk(linebuf_ptr, " \t");

			if (sep != NULL) {
				cmdend = sep;
				/* Delete space at the end of the command. */
				cmdend--; /* It currently derefs to the seperator.. */
				while (*cmdend <= ' ') {
					*cmdend = '\0';
					cmdend--;
				}

				/* Delete the seperator char and any leading space. */
				*sep = '\0';
				sep++;
				while (*sep == ' ' || *sep == '\t') {
					sep++;
				}
				value = sep;
			} else {
				/* XXX: should this be "" or NULL ? */
				value = "";
			}

			cmd = linebuf_ptr;

			if (qualifbuf[0] != '\0') {
				strncat(qualifbuf, ".", sizeof(qualifbuf) - strlen(qualifbuf) - 1);
			}
			strncat(qualifbuf, cmd, sizeof(qualifbuf) - strlen(qualifbuf) - 1);

			lcpvret = lc_process_var(qualifbuf, value, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
#ifdef DEBUG
				fprintf(stderr, "Invalid section: \"%s\"\n", qualifbuf);
#endif
				invalid_section = 1;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			}
			if (lcpvret == LC_CBRET_IGNORESECTION) {
				ignore_section = 1;
			}
			continue;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == '#' || *linebuf_ptr == '\0') {
			continue;
		}

		/* Don't handle things for a section that doesn't exist. */
		if (invalid_section == 1) {
#ifdef DEBUG
			fprintf(stderr, "Ignoring line (because invalid section): %s\n", linebuf);
#endif
			continue;
		}
		if (ignore_section == 1) {
#ifdef DEBUG
			fprintf(stderr, "Ignoring line (because ignored section): %s\n", linebuf);
#endif
			continue;
		}

		/* Find the command and the data in the line. */
		sep = strpbrk(linebuf_ptr, " \t");
		if (sep != NULL) {
			cmdend = sep;

			/* Delete space at the end of the command. */
			cmdend--; /* It currently derefs to the seperator.. */
			while (*cmdend <= ' ') {
				*cmdend = '\0';
				cmdend--;
			}

			/* Delete the seperator char and any leading space. */
			*sep = '\0';
			sep++;
			while (*sep == ' ' || *sep == '\t') {
				sep++;
			}
			value = sep;
		} else {
			value = NULL;
		}

		cmd = linebuf_ptr;

		/* Handle special commands. */
		if (strcasecmp(cmd, "include") == 0) {
			if (value == NULL) {
				lc_errno = LC_ERR_BADFORMAT;
				retval = -1;
#ifdef DEBUG
				fprintf(stderr, "Invalid include command.\n");
#endif
				continue;
			}

			lpcafret = lc_process_conf_apache_include(value, qualifbuf);
			if (lpcafret < 0) {
#ifdef DEBUG
				fprintf(stderr, "Error in included file.\n");
#endif
				retval = -1;
			}
			continue;
		}

		/* Create the fully qualified variable name. */
		if (qualifbuf[0] != '\0') {
			strncat(qualifbuf, ".", sizeof(qualifbuf) - strlen(qualifbuf) - 1);
		}
		strncat(qualifbuf, cmd, sizeof(qualifbuf) - strlen(qualifbuf) - 1);

		/* Call the parent and tell them we have data. */
		save_lc_errno = lc_errno;
		lc_errno = LC_ERR_NONE;
		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			if (lc_errno == LC_ERR_NONE) {
#ifdef DEBUG
				fprintf(stderr, "Invalid command: \"%s\"\n", cmd);
#endif
				lc_errno = LC_ERR_INVCMD;
			} else {
#ifdef DEBUG
				fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
#endif
			}
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}

		/* Remove the "cmd" part of the buffer. */