Commit 5adef99d authored by Per Cederqvist's avatar Per Cederqvist

Configuration file definitions: use a datatype struct, instead of

having separate "assigner" and "freer" fields in the parameter
definition table.
* src/server/conf-file.h (struct datatype): New struct.
(struct parameter): Move the assigner and freer fields to struct
datatype, and include a pointer to a const struct datatype.
* src/server/conf-file.c, src/server/conf-file.h
(cf_text_no): New constant struct.
(cf_conf_no): Ditto.
(cf_int): Ditto.
(cf_ulong): Ditto.
(cf_uint): Ditto.
(cf_string): Ditto.
(cf_bool): Ditto.
(cf_double): Ditto.
(cf_timeval): Ditto.
* src/server/conf-file.c (assign_defaults): Handle configuration
datatypes.
(configure_line): Ditto.
* src/server/server-config.c (assign_path): Removed.
(unassign_path): Removed.
(cf_path): New. Replaces assign_path and unassign_path.
(cf_log_param): New const struct.
(cf_jubel): New const struct.
(cf_ident_param): New const struct.
(parameters): Replaced all assigners and freers with the pointers
to the proper datatype structs.
(free_configuration): Handle configuration datatypes.
parent 8af205cf
2006-02-01 Per Cederqvist <ceder@lysator.liu.se>
Configuration file definitions: use a datatype struct, instead of
having separate "assigner" and "freer" fields in the parameter
definition table.
* src/server/conf-file.h (struct datatype): New struct.
(struct parameter): Move the assigner and freer fields to struct
datatype, and include a pointer to a const struct datatype.
* src/server/conf-file.c, src/server/conf-file.h
(cf_text_no): New constant struct.
(cf_conf_no): Ditto.
(cf_int): Ditto.
(cf_ulong): Ditto.
(cf_uint): Ditto.
(cf_string): Ditto.
(cf_bool): Ditto.
(cf_double): Ditto.
(cf_timeval): Ditto.
* src/server/conf-file.c (assign_defaults): Handle configuration
datatypes.
(configure_line): Ditto.
* src/server/server-config.c (assign_path): Removed.
(unassign_path): Removed.
(cf_path): New. Replaces assign_path and unassign_path.
(cf_log_param): New const struct.
(cf_jubel): New const struct.
(cf_ident_param): New const struct.
(parameters): Replaced all assigners and freers with the pointers
to the proper datatype structs.
(free_configuration): Handle configuration datatypes.
2006-01-04 Per Cederqvist <ceder@lysator.liu.se>
Made HACKING more future-proof.
......
......@@ -66,6 +66,43 @@
static int *assignment_count = NULL;
static int npar = 0;
const struct datatype cf_text_no = {
assign_text_no, NULL,
};
const struct datatype cf_conf_no = {
assign_conf_no, NULL
};
const struct datatype cf_int = {
assign_int, NULL
};
const struct datatype cf_ulong = {
assign_ulong, NULL
};
const struct datatype cf_uint = {
assign_uint, NULL
};
const struct datatype cf_string = {
assign_string, unassign_string
};
const struct datatype cf_bool = {
assign_bool, NULL
};
const struct datatype cf_double = {
assign_double, NULL
};
const struct datatype cf_timeval = {
assign_timeval, NULL
};
static void
init_init(const struct parameter *par)
{
......@@ -100,7 +137,7 @@ assign_defaults(const struct parameter *par,
}
else if (assignment_count[ix] == 0)
{
if ((*par[ix].assigner)(par[ix].default_val, &par[ix]) != OK)
if ((*par[ix].tp->assigner)(par[ix].default_val, &par[ix]) != OK)
{
kom_log ("default assigner failed for %s\n", par[ix].name);
(*err)++;
......@@ -195,7 +232,7 @@ configure_line(FILE *fp,
else
{
assignment_count[ix]++;
if ((*par[ix].assigner)(val, &par[ix]) != OK)
if ((*par[ix].tp->assigner)(val, &par[ix]) != OK)
{
kom_log ("assigner for %s failed\n", par[ix].name);
(*err)++;
......
......@@ -29,10 +29,16 @@
#ifndef CONF_FILE_INCLUDED
#define CONF_FILE_INCLUDED
struct parameter {
const char *name;
struct parameter;
struct datatype {
Success (*assigner)(const char *val, const struct parameter *par);
void (*freer)(const struct parameter *par);
};
struct parameter {
const char *name;
const struct datatype *tp;
int min_assignments;
int max_assignments; /* -1 == eternity */
const char *default_val; /* String, as read from the config file. */
......@@ -55,4 +61,14 @@ extern Success assign_timeval (const char *val, const struct parameter *par);
extern void unassign_string(const struct parameter *par);
extern const struct datatype cf_text_no;
extern const struct datatype cf_conf_no;
extern const struct datatype cf_int;
extern const struct datatype cf_ulong;
extern const struct datatype cf_uint;
extern const struct datatype cf_string;
extern const struct datatype cf_bool;
extern const struct datatype cf_double;
extern const struct datatype cf_timeval;
#endif
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment