Check-in [c3d71a3b91]
Overview
Comment:Exposed lc_handle_type() function to public (needs documentation) Updated lc_register_callback documentation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c3d71a3b91475a74fe062297922a37343f630e65
User & Date: rkeene on 2006-12-17 02:49:01
Other Links: manifest | tags
Context
2006-12-17
03:04
Added an "ADDR" var type (since it was already documented) Removed brain-dead (void *) to type casts in lc_handle_...() check-in: e07808cac6 user: rkeene tags: trunk
02:49
Exposed lc_handle_type() function to public (needs documentation) Updated lc_register_callback documentation check-in: c3d71a3b91 user: rkeene tags: trunk
00:11
Updated libconfig to reset lc_errno at the start of each function check-in: c8032b5a5e user: rkeene tags: trunk
Changes

Modified lc_register_callback.3.in from [caede5b68d] to [9235a07e28].

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
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







-
-
-
-
-
















-
+

-
+







int callback_ifmodule(const char *shortvar, const char *var,
                      const char *arguments, const char *value,
                      lc_flags_t flags, void *extra) {
	if (flags == LC_FLAGS_SECTIONEND) {
		return(LC_CBRET_OKAY);
	}

	if (flags != LC_FLAGS_SECTIONSTART) {
		lc_seterrstr("IfModule can only be used as a \\
		              section.");
		return(LC_CBRET_ERROR);
	}
	if (arguments == NULL) {
		lc_seterrstr("You must specify an argument to \\
		              IfModule.");
		return(LC_CBRET_ERROR);
	}

	printf("IfModule %s\\n", arguments);

	if (strcasecmp(arguments, "MyModule") == 0) {
		return(LC_CBRET_IGNORESECTION);
	}

	return(LC_CBRET_OKAY);
}

int main(int argc, char **argv) {
	int lc_rc_ret = 0, lc_p_ret;
	int lc_rc_ret, lc_p_ret;

	lc_rc_ret = lc_register_callback("*.IfModule", 0, LC_VAR_NONE,
	lc_rc_ret = lc_register_callback("*.IfModule", 0, LC_VAR_SECTION,
	                                 callback_ifmodule, NULL);

	if (lc_rc_ret != 0) {
		fprintf(stderr, "Error registering callback.\\n");
		return(EXIT_FAILURE);
	}

Modified libconfig.c from [3125d83cbc] to [bc792aa0c5].

296
297
298
299
300
301
302
303
304

305
306
307
308
309
310

311
312
313
314
315
316
317
296
297
298
299
300
301
302


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317







-
-
+






+








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

	return(0);
}


static int lc_handle_type(lc_var_type_t type, const char *value, void *data) {
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) {
		/* XXX */
	}

	switch (type) {
		case LC_VAR_STRING:
			return(lc_process_var_string(data, value, &next));
			break;
		case LC_VAR_LONG_LONG:
373
374
375
376
377
378
379

380

381
382
383
384
385
386
387
373
374
375
376
377
378
379
380

381
382
383
384
385
386
387
388







+
-
+







			return(-1);
		case LC_VAR_NONE:
		case LC_VAR_UNKNOWN:
		case LC_VAR_SECTION:
		case LC_VAR_SECTIONSTART:
		case LC_VAR_SECTIONEND:
			return(0);
		case LC_VAR_LIST:
			break;
			return(0);
	}

	return(-1);
}

static int lc_handle(struct lc_varhandler_st *handler, const char *var, const char *varargs, const char *value, lc_flags_t flags) {
	const char *localvar = NULL;
397
398
399
400
401
402
403



404
405
406
407
408
409
410
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414







+
+
+







	} else {
		localvar = NULL;
	}

	switch (handler->mode) {
		case LC_MODE_CALLBACK:
			if (handler->callback != NULL) {
				lc_errno = LC_ERR_NONE;
				lc_err_usererrmsg = NULL;

				retval = handler->callback(localvar, var, varargs, value, flags, handler->extra);
				if (retval < 0) {
					lc_errno = LC_ERR_CALLBACK;
				}
				return(retval);
			}
			break;

Modified libconfig.h.in from [a51c1e0b82] to [14f8a60094].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1
2
3
4
5
6
7
8




9
10
11
12
13
14
15








-
-
-
-







!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,
        LC_CONF_SPACE,
        LC_CONF_XML
45
46
47
48
49
50
51

52
53
54
55
56
57
58
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55







+







        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_LIST = 0x80
} lc_var_type_t;

__BLANK_LINE__

typedef enum {
        LC_FLAGS_VAR,
        LC_FLAGS_CMDLINE,
79
80
81
82
83
84
85

86
87
88
89
90
91
92
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90







+







int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra);
int lc_register_callback(const char *var, char opt, lc_var_type_t type, int (*callback)(const char *, const char *, const char *, const char *, lc_flags_t, void *), void *extra);
int lc_register_var(const char *var, lc_var_type_t type, void *data, char opt);
lc_err_t lc_geterrno(void);
void lc_seterrstr(const char *usererrstr);
char *lc_geterrstr(void);
int lc_process_file(const char *appname, const char *pathname, lc_conf_type_t type);
int lc_handle_type(lc_var_type_t type, const char *value, void *data);
void lc_cleanup(void);

__BLANK_LINE__

!define LC_CBRET_IGNORESECTION (255)
!define LC_CBRET_OKAY (0)
!define LC_CBRET_ERROR (-1)