Check-in [730308bffd]
Overview
Comment:Added filename and line numbers to error messages. Began adding support for lists of options rather than just one option per item. libconfig 0.1.19
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | 0.1.19
Files: files | file ages | folders
SHA1: 730308bffd7be6879a2c9c32d1eb7ee867f0c7ef
User & Date: rkeene on 2005-09-30 08:27:32
Other Links: manifest | tags
Context
2005-10-18
16:00
Added missing error line/file information for conf_apache libconfig 0.1.20 check-in: b9a32192b7 user: rkeene tags: 0.1.20, trunk
2005-09-30
08:27
Added filename and line numbers to error messages. Began adding support for lists of options rather than just one option per item. libconfig 0.1.19 check-in: 730308bffd user: rkeene tags: 0.1.19, trunk
2005-07-18
11:54
Updated configure process on Win32 to use DLL base. Fixed "lc_cleanup" causing segfaults. check-in: 793852910f user: rkeene tags: 0.1.18, trunk
Changes

Modified Makefile.in from [e7001c02f6] to [53b907f18c].

13
14
15
16
17
18
19

20
21
22
23
24
25
26
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27







+







SHOBJFLAGS = @SHOBJFLAGS@
SHOBJLDFLAGS = @SHOBJLDFLAGS@
SHOBJEXT = @SHOBJEXT@
ARFLAGS = # @ARFLAGS@
AREXT = @AREXT@
PKGVERS = @PACKAGE_VERSION@
PKGVERSMAJOR = `echo $(PKGVERS) | cut -f 1 -d .`
EXEEXT = @EXEEXT@

prefix = @prefix@
mandir = @mandir@
sysconfdir = @sysconfdir@
datadir = @datadir@
exec_prefix = @exec_prefix@
bindir = @bindir@

Modified build/h-to-hin from [e6b4d57000] to [34a6b6eb8a].

1
2
3
4
5

6
7
8
9
1
2
3
4

5
6
7
8
9




-
+




#! /bin/sh

if [ libconfig.h -nt libconfig.h.in ]; then
	echo 'Updating libconfig.h.in ...'
	sed 's@^#  @!@;s@^ *$@|__BLANK_LINE__|@' libconfig.h | tr '|' "\n" > libconfig.h.in
	sed 's@^#  @!@;s@^ *$@:__BLANK_LINE__:@' libconfig.h | tr ':' "\n" > libconfig.h.in
else
	echo 'Updating libconfig.h ...'
	make libconfig.h
fi

Added build/test.conf version [9a98f498a7].















1
2
3
4
5
6
7
8
9
10
11
12
13
14
+
+
+
+
+
+
+
+
+
+
+
+
+
+


<section>
	test Bob was here
</section>

<somesection>
	Free yes, no
</somesection>

#<joe>
#</joe>

sally 3

Modified compat.h from [e7ac67c392] to [b6a11fd72e].

84
85
86
87
88
89
90




91
92




93
94
95
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103







+
+
+
+


+
+
+
+



#endif

#ifdef HAVE_OPENNET_H
#include <opennet.h>
#endif
#ifdef HAVE_LIBOPENNET
#define lc_fopen(path, mode) fopen_net(path, mode)
#define lc_fgets(buf, size, stream) fgets_net(buf, size, stream)
#define lc_feof(stream) feof_net(stream)
#define lc_fclose(stream) fclose_net(stream)
#define LC_FILE NETFILE
#else
#define lc_fopen(path, mode) fopen(path, mode)
#define lc_fgets(buf, size, stream) fgets(buf, size, stream)
#define lc_feof(stream) feof(stream)
#define lc_fclose(stream) fclose(stream)
#define LC_FILE FILE
#endif

#endif

Modified conf_apache.c from [cd77d73d2e] to [dfc17c3008].

77
78
79
80
81
82
83
84


85
86
87
88
89
90
91

92
93
94
95
96
97
98
99



100


101
102
103
104
105
106
107


108
109
110
111
112
113

114
115
116
117

118
119


120
121
122
123
124
125
126
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

122
123
124
125

126
127
128
129
130
131
132
133
134
135
136
137







-
+
+







+








+
+
+

+
+







+
+





-
+



-
+


+
+







		}
	}

	return(retval);
}

static int lc_process_conf_apache_file(const char *configfile, const char *pathprefix) {
	FILE *configfp = NULL;
	LC_FILE *configfp = NULL;
	const char *local_lc_errfile;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL, *tmp_ptr = NULL;
	char *lastsection = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1, lpcafret = -1;
	int invalid_section = 0, ignore_section = 0;
	int local_lc_errline;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	if (pathprefix != NULL) {
		/* Copy the prefix, if specified. */
		strncpy(qualifbuf, pathprefix, sizeof(qualifbuf) - 1);
	}

	local_lc_errfile = configfile;
	local_lc_errline = 0;

	if (configfile == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = lc_fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
		}
		if (feof(configfp)) {
		if (lc_feof(configfp)) {
			break;
		}

		local_lc_errline++;

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


167
168
169
170
171
172
173
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186







+
+








				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_errfile = local_lc_errfile;
					lc_errline = local_lc_errline;
					lc_errno = LC_ERR_BADFORMAT;

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

				lcpvret = lc_process_var(qualifbuf, NULL, NULL, LC_FLAGS_SECTIONEND);
228
229
230
231
232
233
234


235
236
237
238
239
240
241
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256







+
+








			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_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			}
			if (lcpvret == LC_CBRET_IGNORESECTION) {
				ignore_section = 1;
			}
			continue;
284
285
286
287
288
289
290


291
292
293
294
295
296
297
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314







+
+







		}

		cmd = linebuf_ptr;

		/* Handle special commands. */
		if (strcasecmp(cmd, "include") == 0) {
			if (value == NULL) {
				lc_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;
				lc_errno = LC_ERR_BADFORMAT;
				retval = -1;
#ifdef DEBUG
				fprintf(stderr, "Invalid include command.\n");
#endif
				continue;
			}
323
324
325
326
327
328
329


330
331
332
333
334
335
336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369







+
+













-
+







#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
			}
			lc_errfile = local_lc_errfile;
			lc_errline = local_lc_errline;
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}

		/* Remove the "cmd" part of the buffer. */
		tmp_ptr = strrchr(qualifbuf, '.');
		if (tmp_ptr == NULL) {
			tmp_ptr = qualifbuf;
		}
		*tmp_ptr = '\0';
	}

	fclose(configfp);
	lc_fclose(configfp);

	return(retval);
}

int lc_process_conf_apache(const char *appname, const char *configfile) {
	return(lc_process_conf_apache_file(configfile, NULL));
}

Modified conf_section.c from [f6fa72ff6b] to [291ca9d7b9].

8
9
10
11
12
13
14
15


16
17
18
19
20
21
22

23
24
25



26


27
28
29
30
31
32
33


34
35
36
37
38
39

40
41
42
43

44
45


46
47
48
49
50
51
52
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50
51

52
53
54
55
56
57
58
59
60
61
62
63







-
+
+







+



+
+
+

+
+







+
+





-
+



-
+


+
+







#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif

int lc_process_conf_section(const char *appname, const char *configfile) {
	FILE *configfp = NULL;
	LC_FILE *configfp = NULL;
	const char *local_lc_errfile;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
	char *currsection = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;
	int invalid_section = 1, ignore_section = 0;
	int local_lc_errline;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	local_lc_errfile = configfile;
	local_lc_errline = 0;

	if (appname == NULL || configfile == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = lc_fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
		}
		if (feof(configfp)) {
		if (lc_feof(configfp)) {
			break;
		}

		local_lc_errline++;

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


78
79
80
81
82
83
84
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97







+
+







			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
#ifdef DEBUG
				fprintf(stderr, "Invalid section: \"%s\"\n", currsection);
#endif
				invalid_section = 1;
				lc_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			} else {
				invalid_section = 0;
				ignore_section = 0;
			}

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
185
186
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201







+
+

















-
+



#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
			}
			lc_errfile = local_lc_errfile;
			lc_errline = local_lc_errline;
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}
	}

	/* Close any open section, and clean-up. */
	if (currsection != NULL) {
		lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
		if (lcpvret < 0) {
#ifdef DEBUG
			fprintf(stderr, "Invalid section terminating: \"%s\"\n", currsection);
#endif
		}
		free(currsection);
	}

	fclose(configfp);
	lc_fclose(configfp);

	return(retval);
}

Modified conf_space.c from [22b1310a4a] to [0072873b48].

8
9
10
11
12
13
14
15


16
17
18

19
20
21
22



23


24
25
26
27
28
29
30


31
32
33
34
35
36

37
38
39
40

41
42


43
44
45
46
47
48
49
8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48

49
50
51
52
53
54
55
56
57
58
59
60







-
+
+



+




+
+
+

+
+







+
+





-
+



-
+


+
+







#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif

int lc_process_conf_space(const char *appname, const char *configfile) {
	FILE *configfp = NULL;
	LC_FILE *configfp = NULL;
	const char *local_lc_errfile;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char *cmd = NULL, *value = NULL, *sep = NULL;
	char *fgetsret = NULL;
	int local_lc_errline;
	int lcpvret = -1;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	local_lc_errfile = configfile;
	local_lc_errline = 0;

	if (appname == NULL || configfile == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = lc_fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
		}
		if (feof(configfp)) {
		if (lc_feof(configfp)) {
			break;
		}

		local_lc_errline++;

		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
			*linebuf_ptr = '\0';
			linebuf_ptr--;
		}

80
81
82
83
84
85
86


87
88
89
90
91
92
93

94
95
96
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109







+
+






-
+



#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
			}
			lc_errfile = local_lc_errfile;
			lc_errline = local_lc_errline;
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}
	}

	fclose(configfp);
	lc_fclose(configfp);

	return(retval);
}

Modified configure.ac from [9c0f5749ef] to [e806c2cabd].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







AC_REVISION($Revision $)
AC_INIT(libconfig, 0.1.18)
AC_INIT(libconfig, 0.1.19)
AC_CONFIG_HEADER(config.h)

dnl Find out about the host OS
DC_CHK_OS_INFO

dnl Checks for programs.
AC_PROG_CC

Modified libconfig.c from [9adb43042b] to [341b40c218].

34
35
36
37
38
39
40

41

42
43
44
45

46
47
48
49
50


51
52
53
54





55
56
57
58

59
60
61
62

63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65

66
67
68
69

70
71
72
73





74
75
76
77
78
79
80
81







+

+



-
+





+
+



-
+
+
+
+
+



-
+



-
+



-
-
-
-
-
+








#ifdef HAVE_PWD_H
#include <pwd.h>
#endif

struct lc_varhandler_st *varhandlers = NULL;
lc_err_t lc_errno = LC_ERR_NONE;
const char *lc_errfile = NULL;
int lc_optind = 0;
int lc_errline = 0;

extern char **environ;

static int lc_process_var_string(void *data, const char *value) {
static int lc_process_var_string(void *data, const char *value, const char **endptr) {
	char **dataval;

	dataval = data;
	*dataval = strdup(value);

	*endptr = NULL;

	return(0);
}

static int lc_process_var_cidr(void *data, const char *value) {
static int lc_process_var_cidr(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_hostname6(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_hostname6(void *data, const char *value) {
static int lc_process_var_hostname4(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_hostname4(void *data, const char *value) {
static int lc_process_var_ip6(void *data, const char *value, const char **endptr) {
	return(-1);
}

static int lc_process_var_ip6(void *data, const char *value) {
	return(-1);
}

static int lc_process_var_ip4(void *data, const char *value) {
static int lc_process_var_ip4(void *data, const char *value, const char **endptr) {
	uint32_t *dataval, retval = 0;
	const char *dotptr = NULL;
	int tmpval = -1;
//	int dotcount

	dataval = data;

94
95
96
97
98
99
100


101
102
103
104

105
106
107
108

109
110
111
112
113

114
115
116
117

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
185
186
187
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113

114
115
116
117
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
185
186
187
188
189
190
191
192
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







+
+



-
+



-
+




-
+



-
+




-
+



-
+




-
+



-
+




-
+






+
+



-
+
+
+
+

+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
-
+
+







			break;
		}
		dotptr++;
	}

	*dataval = retval;

	*endptr = (char *) dotptr;

	return(0);
}

static int lc_process_var_longlong(void *data, const char *value) {
static int lc_process_var_longlong(void *data, const char *value, const char **endptr) {
	long long *dataval;

	dataval = data;
	*dataval = strtoll(value, NULL, 10);
	*dataval = strtoll(value, (char **) endptr, 10);

	return(0);
}

static int lc_process_var_long(void *data, const char *value) {
static int lc_process_var_long(void *data, const char *value, const char **endptr) {
	long *dataval;

	dataval = data;
	*dataval = strtoll(value, NULL, 10);
	*dataval = strtoll(value, (char **) endptr, 10);

	return(0);
}

static int lc_process_var_int(void *data, const char *value) {
static int lc_process_var_int(void *data, const char *value, const char **endptr) {
	int *dataval;

	dataval = data;
	*dataval = strtoll(value, NULL, 10);
	*dataval = strtoll(value, (char **) endptr, 10);

	return(0);
}

static int lc_process_var_short(void *data, const char *value) {
static int lc_process_var_short(void *data, const char *value, const char **endptr) {
	short *dataval;

	dataval = data;
	*dataval = strtoll(value, NULL, 10);
	*dataval = strtoll(value, (char **) endptr, 10);

	return(0);
}

static int lc_process_var_bool_byexistance(void *data, const char *value) {
static int lc_process_var_bool_byexistance(void *data, const char *value, const char **endptr) {
	int *dataval;

	dataval = data;

	*dataval = 1;

	*endptr = NULL;

	return(0);
}

static int lc_process_var_bool(void *data, const char *value) {
static int lc_process_var_bool(void *data, const char *value, const char **endptr) {
	char *trueval[] = {"enable", "true", "yes", "on", "y", "1"};
	char *falseval[] = {"disable", "false", "no", "off", "n", "0"};
	size_t chkvallen, vallen;
	int *dataval;
	int i;

	dataval = data;

	*dataval = -1;

	if (strcasecmp(value, "enable") == 0 ||
	    strcasecmp(value, "true") == 0 ||
	    strcasecmp(value, "yes") == 0 ||
	    strcasecmp(value, "on") == 0 ||
            strcasecmp(value, "y") == 0 ||
	    strcasecmp(value, "1") == 0) {
		*dataval = 1;
		return(0);
	} else if (strcasecmp(value, "disable") == 0 ||
	    strcasecmp(value, "false") == 0 ||
	    strcasecmp(value, "off") == 0 ||
	    strcasecmp(value, "no") == 0 ||
            strcasecmp(value, "n") == 0 ||
	    strcasecmp(value, "0") == 0) {
		*dataval = 0;
		return(0);
	vallen = strlen(value);

	for (i = 0; i < (sizeof(trueval) / sizeof(*trueval)); i++) {
		chkvallen = strlen(trueval[i]);

		/*
		 * Skip if there's no way we could find a match here.
		 */
		if (chkvallen > vallen) {
			continue;
		}

		/*
		 * Skip if there is no partial match.
		 */
		if (strncasecmp(value, trueval[i], chkvallen) != 0) {
			continue;
		}

		if (value[chkvallen] == '\0' || value[chkvallen] == ',' || \
		    value[chkvallen] == ' ') {
			/* Declare a winner and set the next token. */
			*endptr = value + chkvallen;
			*dataval = 1;
			return(0);
		}
	}

	for (i = 0; i < (sizeof(falseval) / sizeof(*falseval)); i++) {
		chkvallen = strlen(falseval[i]);

		/*
		 * Skip if there's no way we could find a match here.
		 */
		if (chkvallen > vallen) {
			continue;
		}

		/*
		 * Skip if there is no partial match.
		 */
		if (strncasecmp(value, falseval[i], chkvallen) != 0) {
			continue;
		}

		if (value[chkvallen] == '\0' || value[chkvallen] == ',' || \
		    value[chkvallen] == ' ') {
			/* Declare a winner and set the next token. */
			*endptr = value + chkvallen;
			*dataval = 0;
			return(0);
		}
	}

	lc_errno = LC_ERR_BADFORMAT;
	return(-1);
}

static long long lc_process_size(const char *value) {
	long long retval = -1;
static unsigned long long lc_process_size(const char *value, const char **endptr) {
	unsigned long long retval = 0;
	char *mult = NULL;

	retval = strtoll(value, &mult, 10);
	if (mult != NULL) {
		switch (tolower(mult[0])) {
			case 'p':
				retval *= 1125899906842624LLU;
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
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
336
337

338
339
340

341
342
343

344
345
346

347
348
349
350

351
352
353

354
355
356

357
358
359

360
361
362

363
364
365
366
367
368
369
370







-
+



-
+




-
+



-
+




-
+



-
+




-
+



-
+




-
+



-
+






+
+
+
+
+
+
+
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+



-
+


-
+


-
+


-
+


-
+







				break;
		}
	}

	return(retval);
}

static int lc_process_var_sizelonglong(void *data, const char *value) {
static int lc_process_var_sizelonglong(void *data, const char *value, const char **endptr) {
	long long *dataval;

	dataval = data;
	*dataval = lc_process_size(value);
	*dataval = lc_process_size(value, endptr);

	return(0);
}

static int lc_process_var_sizelong(void *data, const char *value) {
static int lc_process_var_sizelong(void *data, const char *value, const char **endptr) {
	long *dataval;

	dataval = data;
	*dataval = lc_process_size(value);
	*dataval = lc_process_size(value, endptr);

	return(0);
}

static int lc_process_var_sizeint(void *data, const char *value) {
static int lc_process_var_sizeint(void *data, const char *value, const char **endptr) {
	int *dataval;

	dataval = data;
	*dataval = lc_process_size(value);
	*dataval = lc_process_size(value, endptr);

	return(0);
}

static int lc_process_var_sizeshort(void *data, const char *value) {
static int lc_process_var_sizeshort(void *data, const char *value, const char **endptr) {
	short *dataval;

	dataval = data;
	*dataval = lc_process_size(value);
	*dataval = lc_process_size(value, endptr);

	return(0);
}

static int lc_process_var_sizesizet(void *data, const char *value) {
static int lc_process_var_sizesizet(void *data, const char *value, const char **endptr) {
	size_t *dataval;

	dataval = data;
	*dataval = lc_process_size(value);
	*dataval = lc_process_size(value, endptr);

	return(0);
}


static int lc_handle_type(lc_var_type_t type, const char *value, void *data) {
	const char *next;
	int is_list;

	is_list = type & LC_VAR_LIST;

	if (is_list == LC_VAR_LIST) {
	}

	switch (type) {
		case LC_VAR_STRING:
			return(lc_process_var_string(data, value));
			return(lc_process_var_string(data, value, &next));
			break;
		case LC_VAR_LONG_LONG:
			return(lc_process_var_longlong(data, value));
			return(lc_process_var_longlong(data, value, &next));
			break;
		case LC_VAR_LONG:
			return(lc_process_var_long(data, value));
			return(lc_process_var_long(data, value, &next));
			break;
		case LC_VAR_INT:
			return(lc_process_var_int(data, value));
			return(lc_process_var_int(data, value, &next));
			break;
		case LC_VAR_SHORT:
			return(lc_process_var_short(data, value));
			return(lc_process_var_short(data, value, &next));
			break;
		case LC_VAR_BOOL:
			return(lc_process_var_bool(data, value));
			return(lc_process_var_bool(data, value, &next));
			break;
		case LC_VAR_SIZE_LONG_LONG:
			return(lc_process_var_sizelonglong(data, value));
			return(lc_process_var_sizelonglong(data, value, &next));
			break;
		case LC_VAR_SIZE_LONG:
			return(lc_process_var_sizelong(data, value));
			return(lc_process_var_sizelong(data, value, &next));
			break;
		case LC_VAR_SIZE_INT:
			return(lc_process_var_sizeint(data, value));
			return(lc_process_var_sizeint(data, value, &next));
			break;
		case LC_VAR_SIZE_SHORT:
			return(lc_process_var_sizeshort(data, value));
			return(lc_process_var_sizeshort(data, value, &next));
			break;
		case LC_VAR_BOOL_BY_EXISTANCE:
			return(lc_process_var_bool_byexistance(data, value));
			return(lc_process_var_bool_byexistance(data, value, &next));
			break;
		case LC_VAR_SIZE_SIZE_T:
			return(lc_process_var_sizesizet(data, value));
			return(lc_process_var_sizesizet(data, value, &next));
			break;
		case LC_VAR_IP:
		case LC_VAR_IP4:
			return(lc_process_var_ip4(data, value));
			return(lc_process_var_ip4(data, value, &next));
			break;
		case LC_VAR_IP6:
			return(lc_process_var_ip6(data, value));
			return(lc_process_var_ip6(data, value, &next));
			break;
		case LC_VAR_HOSTNAME4:
			return(lc_process_var_hostname4(data, value));
			return(lc_process_var_hostname4(data, value, &next));
			break;
		case LC_VAR_HOSTNAME6:
			return(lc_process_var_hostname6(data, value));
			return(lc_process_var_hostname6(data, value, &next));
			break;
		case LC_VAR_CIDR:
			return(lc_process_var_cidr(data, value));
			return(lc_process_var_cidr(data, value, &next));
			break;
		case LC_VAR_TIME:
		case LC_VAR_DATE:
		case LC_VAR_FILENAME:
		case LC_VAR_DIRECTORY:
#ifdef DEBUG
			fprintf(stderr, "Not implemented yet!\n");
365
366
367
368
369
370
371


372
373
374
375
376
377



378
379
380
381


382
383
384
385
386
387
388
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451







+
+






+
+
+




+
+







	size_t appnamelen = 0;
	char varnamebuf[128] = {0};
	char **currvar;
	char *sep = NULL, *value = NULL, *cmd = NULL;
	char *ucase_appname = NULL, *ucase_appname_itr = NULL;
	char *lastcomponent_handler = NULL;
	int varnamelen = 0;
	char *local_lc_errfile;
	int local_lc_errline;

	/* Make sure we have an environment to screw with, if not,
	   no arguments were found to be in error */
	if (environ == NULL || appname == NULL) {
		return(0);
	}

	local_lc_errfile = "<environment>";
	local_lc_errline = 0;

	/* Allocate and create our uppercase appname. */
	ucase_appname = strdup(appname);
	if (ucase_appname == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_ENOMEM;
		return(-1);
	}
	for (ucase_appname_itr = ucase_appname; *ucase_appname_itr != '\0'; ucase_appname_itr++) {
		*ucase_appname_itr = toupper(*ucase_appname_itr);
	}

486
487
488
489
490
491
492





493
494
495
496


497
498
499
500
501
502
503
504
505


506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522

523
524
525
526
527
528
529
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601







+
+
+
+
+




+
+









+
+
















-
+







	char *lastcomponent_handler = NULL;
	char **newargv = NULL;
	char *usedargv = NULL;
	int cmdargidx = 0;
	int newargvidx = 0;
	int retval = 0, chkretval = 0;
	int ch = 0;
	char *local_lc_errfile;
	int local_lc_errline;

	local_lc_errfile = "<cmdline>";
	local_lc_errline = 0;

	/* Allocate "argc + 1" (+1 for the NULL terminator) elements. */
	newargv = malloc((argc + 1) * sizeof(*newargv));
	if (newargv == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_ENOMEM;
		return(-1);
	}
	newargv[newargvidx++] = argv[0];
	newargv[argc] = NULL;

	/* Allocate space to indicate which arguments have been used. */
	usedargv = malloc(argc * sizeof(*usedargv));
	if (usedargv == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_ENOMEM;
		free(newargv);
		return(-1);
	}
	for (cmdargidx = 0; cmdargidx < argc; cmdargidx++) {
		usedargv[cmdargidx] = 0;
	}

	for (cmdargidx = 1; cmdargidx < argc; cmdargidx++) {
		cmdarg = argv[cmdargidx];

		/* Make sure we have an argument here. */
		if (cmdarg == NULL) {
			break;
		}

		/* If the argument isn't an option, abort. */
		/* If the argument isn't an option, skip. */
		if (cmdarg[0] != '-') {
			continue;
		}

		/* Setup a pointer in the new array for the actual argument. */
		newargv[newargvidx++] = cmdarg;
		usedargv[cmdargidx] = 1;
581
582
583
584
585
586
587


588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607


608
609
610
611
612
613
614
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690







+
+




















+
+








				if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) {
					cmdoptarg = NULL;
				} else {
					cmdargidx++;
					if (cmdargidx >= argc) {
						fprintf(stderr, "Argument required.\n");
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;
						lc_errno = LC_ERR_BADFORMAT;
						free(usedargv);
						free(newargv);
						return(-1);
					}
					cmdoptarg = argv[cmdargidx];
					newargv[newargvidx++] = cmdoptarg;
					usedargv[cmdargidx] = 1;
				}

				chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
				if (chkretval < 0) {
					retval = -1;
				}

				break;
			}

			if (handler == NULL) {
				fprintf(stderr, "Unknown option: --%s\n", cmdarg);
				lc_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;
				lc_errno = LC_ERR_INVCMD;
				free(usedargv);
				free(newargv);
				return(-1);
			}
		} else {
			for (; *cmdarg != '\0'; cmdarg++) {
629
630
631
632
633
634
635


636
637
638
639
640
641
642
643
644
645
646
647


648
649
650
651
652
653
654
655


656
657
658
659
660
661
662
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744







+
+












+
+








+
+








					if (handler->type == LC_VAR_NONE || handler->type == LC_VAR_BOOL_BY_EXISTANCE) {
						cmdoptarg = NULL;
					} else {
						cmdargidx++;
						if (cmdargidx >= argc) {
							fprintf(stderr, "Argument required.\n");
							lc_errfile = local_lc_errfile;
							lc_errline = local_lc_errline;
							lc_errno = LC_ERR_BADFORMAT;
							free(usedargv);
							free(newargv);
							return(-1);
						}
						cmdoptarg = argv[cmdargidx];
						newargv[newargvidx++] = cmdoptarg;
						usedargv[cmdargidx] = 1;
					}

					chkretval = lc_handle(handler, handler->var, NULL, cmdoptarg, LC_FLAGS_CMDLINE);
					if (chkretval < 0) {
						lc_errfile = local_lc_errfile;
						lc_errline = local_lc_errline;
						retval = -1;
					}

					break;
				}

				if (handler == NULL) {
					fprintf(stderr, "Unknown option: -%c\n", ch);
					lc_errfile = local_lc_errfile;
					lc_errline = local_lc_errline;
					lc_errno = LC_ERR_INVCMD;
					free(usedargv);
					free(newargv);
					return(-1);
				}
			}
		}
937
938
939
940
941
942
943

944

945
946
947
948

949
950
951

952
953
954

955
956
957

958
959
960

961
962
963

964
965
966

967
968
969

970
971
972







973
974
975
976
977
978










979
1019
1020
1021
1022
1023
1024
1025
1026

1027
1028
1029
1030

1031
1032
1033

1034
1035
1036

1037
1038
1039

1040
1041
1042

1043
1044
1045

1046
1047
1048

1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062






1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073







+
-
+



-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+



+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


	lc_errno = LC_ERR_NONE;

	return(retval);
}

char *lc_geterrstr(void) {
	static char retval[512];
	char *retval = NULL;
	char *errmsg = NULL;

	switch (lc_errno) {
		case LC_ERR_NONE:
			retval = "Success";
			errmsg = "Success";
			break;
		case LC_ERR_INVCMD:
			retval = "Invalid command";
			errmsg = "Invalid command or option";
			break;
		case LC_ERR_INVSECTION:
			retval = "Invalid section";
			errmsg = "Invalid section";
			break;
		case LC_ERR_INVDATA:
			retval = "Invalid application data (internal error)";
			errmsg = "Invalid application data (internal error)";
			break;
		case LC_ERR_BADFORMAT:
			retval = "Bad data specified or incorrect format.";
			errmsg = "Bad data specified or incorrect format.";
			break;
		case LC_ERR_CANTOPEN:
			retval = "Can't open file.";
			errmsg = "Can't open file.";
			break;
		case LC_ERR_CALLBACK:
			retval = "Error return from application handler.";
			errmsg = "Error return from application handler.";
			break;
		case LC_ERR_ENOMEM:
			retval = "Insuffcient memory.";
			errmsg = "Insuffcient memory.";
			break;
	}

	/*
	 * This is not part of the switch statement so we will get warnings
	 * about unhandled enum values.
	 */
	if (errmsg == NULL) {
		errmsg = "Unknown error";
	}
	lc_errno = LC_ERR_NONE;

	if (retval != NULL) {
		return(retval);
	}
	return("Unknown error");

	if (lc_errfile == NULL) {
		snprintf(retval, sizeof(retval), "%s:%i: %s", "<no file>", lc_errline, errmsg);
	} else {
		snprintf(retval, sizeof(retval), "%s:%i: %s", lc_errfile, lc_errline, errmsg);
	}

	retval[sizeof(retval) - 1] = '\0';

	return(retval);
}

Modified libconfig.h.in from [46fa13e1cf] to [6dd0b27349].

1
2
3
4
5
6





7
8
9
10
11
12
13
1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17


-



+
+
+
+
+







!ifndef _RSK_LIBCONFIG_H
!define _RSK_LIBCONFIG_H

!ifdef __cplusplus
extern "C" {
!endif

__BLANK_LINE__

!define LC_VAR_LIST 0x80

__BLANK_LINE__

typedef enum {
        LC_CONF_SECTION,
        LC_CONF_APACHE,
        LC_CONF_COLON,
        LC_CONF_EQUAL,
35
36
37
38
39
40
41
42
43
44
45
46
47






48
49
50
51
52
53
54
39
40
41
42
43
44
45






46
47
48
49
50
51
52
53
54
55
56
57
58







-
-
-
-
-
-
+
+
+
+
+
+







        LC_VAR_TIME,
        LC_VAR_DATE,
        LC_VAR_SECTION,
        LC_VAR_SECTIONSTART,
        LC_VAR_SECTIONEND,
        LC_VAR_BOOL_BY_EXISTANCE,
        LC_VAR_SIZE_SIZE_T,
	LC_VAR_CIDR,
	LC_VAR_IP,
	LC_VAR_IP4,
	LC_VAR_IP6,
	LC_VAR_HOSTNAME4,
	LC_VAR_HOSTNAME6,
        LC_VAR_CIDR,
        LC_VAR_IP,
        LC_VAR_IP4,
        LC_VAR_IP6,
        LC_VAR_HOSTNAME4,
        LC_VAR_HOSTNAME6,
} lc_var_type_t;

__BLANK_LINE__

typedef enum {
        LC_FLAGS_VAR,
        LC_FLAGS_CMDLINE,
87
88
89
90
91
92
93

94
95
96
97
98
91
92
93
94
95
96
97
98
99
100
101

102







+



-

!define LC_CBRET_ERROR (-1)

__BLANK_LINE__

extern int lc_optind;

__BLANK_LINE__

!ifdef __cplusplus
}
!endif

!endif

Modified libconfig_private.h from [0dfd11fd0f] to [8f8355315c].

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15






+
+







#ifndef _RSK_LIBCONFIG_PRIVATE_H
#define _RSK_LIBCONFIG_PRIVATE_H

#include "libconfig.h"

extern lc_err_t lc_errno;
extern int lc_errline;
extern const char *lc_errfile;

int lc_process_var(const char *var, const char *varargs, const char *value, lc_flags_t flags);

struct lc_varhandler_st;

struct lc_varhandler_st {
	struct lc_varhandler_st *_next;

Modified test-lc.c from [5bdc823df0] to [ae325a3444].

32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
48
49
50
51






52
53
54
55
56
57


58
59
60
61
62
63
64
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70







-
+











-
+
+
+
+
+
+

-




+
+







int main(int argc, char **argv) {
	char *joeval = NULL;
	size_t xval = -1;
	int onoff = -1;
	int lcpret = -1;
	int i = 0;
	int onoff2 = 0;
	uint32_t ipaddr;
	uint32_t ipaddr = 0;

	lc_register_var("Section", LC_VAR_SECTION, NULL, 0);
	lc_register_var("Somesection", LC_VAR_SECTION, NULL, 0);
	lc_register_var("Section.Test", LC_VAR_STRING, &joeval, 'j');
	lc_register_var("bob", LC_VAR_SIZE_SIZE_T, &xval, 's');
	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
	lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
	lc_register_var("ipaddr", LC_VAR_IP, &ipaddr, 'i');
	lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
	lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
	lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
	lcpret = lc_process_file("testapp", "http://10.8.0.2/test.conf", LC_CONF_APACHE);
	lcpret = lc_process_file("testapp", "build/test.conf", LC_CONF_APACHE);
	if (lcpret < 0) {
		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
	lc_cleanup();
	if (lcpret < 0) {
		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	lc_cleanup();

	if (joeval != NULL) {
		fprintf(stderr, "joeval = \"%s\"\n", joeval);
	} else {
		fprintf(stderr, "joeval = \"(null)\"\n");
	}
	fprintf(stderr, "xval = %llu\n", (unsigned long long) xval);