From: Arran Cudbard-Bell Date: Tue, 22 Nov 2016 22:08:58 +0000 (-0500) Subject: Add type values for cf_data_* X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76898d21dab8de565f5328c33191de0831fe50bf;p=thirdparty%2Ffreeradius-server.git Add type values for cf_data_* --- diff --git a/src/include/conffile.h b/src/include/conffile.h index 4c5793e5ce8..11c0c3e0a8e 100644 --- a/src/include/conffile.h +++ b/src/include/conffile.h @@ -280,6 +280,17 @@ _Generic((_ct), \ #define PW_BASE_TYPE(_t) (0xff & (_t)) /* @} **/ +typedef enum { + CF_DATA_TYPE_DEFAULT = 0, + CF_DATA_TYPE_CLIENT, + CF_DATA_TYPE_HOME_SERVER_POOL, + CF_DATA_TYPE_UNLANG, + CF_DATA_TYPE_PROTOCOL, + CF_DATA_TYPE_MODULE_INSTANCE, + CF_DATA_TYPE_CONNECTION_POOL, + CF_DATA_TYPE_TLS +} cf_data_type_t; + #define FR_SIZE_COND_CHECK(_name, _var, _cond, _new)\ do {\ if (!(_cond)) {\ diff --git a/src/main/client.c b/src/main/client.c index 2feda85980e..4839b826019 100644 --- a/src/main/client.c +++ b/src/main/client.c @@ -264,7 +264,7 @@ bool client_add(RADCLIENT_LIST *clients, RADCLIENT *client) * If the client list already exists, use that. * Otherwise, create a new client list. */ - clients = cf_data_find(cs, 0, "clients"); + clients = cf_data_find(cs, CF_DATA_TYPE_CLIENT, "clients"); if (!clients) { clients = client_list_init(cs); if (!clients) { @@ -272,7 +272,8 @@ bool client_add(RADCLIENT_LIST *clients, RADCLIENT *client) return false; } - if (cf_data_add(cs, 0, "clients", clients, (void (*)(void *)) client_list_free) < 0) { + if (cf_data_add(cs, CF_DATA_TYPE_CLIENT, + "clients", clients, (void (*)(void *)) client_list_free) < 0) { ERROR("Failed to associate clients with virtual server %s", client->server); client_list_free(clients); return false; @@ -692,7 +693,7 @@ RADCLIENT_LIST *client_list_parse_section(CONF_SECTION *section, UNUSED bool tls /* * Associate the clients structure with the section. */ - if (cf_data_add(section, 0, "clients", clients, NULL) < 0) { + if (cf_data_add(section, CF_DATA_TYPE_CLIENT, "clients", clients, NULL) < 0) { cf_log_err_cs(section, "Failed to associate clients with section %s", cf_section_name1(section)); client_list_free(clients); return NULL; diff --git a/src/main/conffile.c b/src/main/conffile.c index bc8d76840c0..a2a74c3137e 100644 --- a/src/main/conffile.c +++ b/src/main/conffile.c @@ -337,7 +337,7 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename) FILE *fp; top = cf_top_section(cs); - tree = cf_data_find(top, 0, "filename"); + tree = cf_data_find(top, CF_DATA_TYPE_DEFAULT, "filename"); if (!tree) return NULL; fp = fopen(filename, "r"); @@ -420,7 +420,7 @@ static bool cf_file_check(CONF_SECTION *cs, char const *filename, bool check_per int fd; top = cf_top_section(cs); - tree = cf_data_find(top, 0, "filename"); + tree = cf_data_find(top, CF_DATA_TYPE_DEFAULT, "filename"); if (!tree) return false; file = talloc(tree, cf_file_t); @@ -554,7 +554,7 @@ int cf_file_changed(CONF_SECTION *cs, rb_walker_t callback) rbtree_t *tree; top = cf_top_section(cs); - tree = cf_data_find(top, 0, "filename"); + tree = cf_data_find(top, CF_DATA_TYPE_DEFAULT, "filename"); if (!tree) return true; cb.rcode = CF_FILE_NONE; @@ -3101,7 +3101,7 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp, talloc_free(p); css->name2 = talloc_typed_strdup(css, buff[2]); - cf_data_add(css, 0, "if", cond, NULL); + cf_data_add(css, CF_DATA_TYPE_UNLANG, "if", cond, NULL); add_section: cf_item_add(this, &(css->item)); @@ -3549,7 +3549,7 @@ int cf_file_read(CONF_SECTION *cs, char const *filename) tree = rbtree_create(cs, filename_cmp, NULL, 0); if (!tree) return -1; - cf_data_add(cs, 0, "filename", tree, NULL); + cf_data_add(cs, CF_DATA_TYPE_DEFAULT, "filename", tree, NULL); /* * Allocate temporary buffers on the heap (so we don't use *all* the stack space) @@ -4363,7 +4363,7 @@ size_t cf_section_write(FILE *in_fp, CONF_SECTION *cs, int depth) * FIXME: check for "if" or "elsif". And if so, print * out the parsed condition, instead of the input text * - * cf_data_find(cs, 0, "if"); + * cf_data_find(cs, CF_DATA_TYPE_UNLANG, "if"); */ if (cs->name2) { @@ -4371,7 +4371,7 @@ size_t cf_section_write(FILE *in_fp, CONF_SECTION *cs, int depth) fputs(" ", fp); - c = cf_data_find(cs, 0, "if"); + c = cf_data_find(cs, CF_DATA_TYPE_UNLANG, "if"); if (c) { char buffer[1024]; diff --git a/src/main/interpreter.c b/src/main/interpreter.c index 1d8c3d8534f..d6da368713a 100644 --- a/src/main/interpreter.c +++ b/src/main/interpreter.c @@ -1199,7 +1199,7 @@ void unlang_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t action) * associated with sections. */ if (cs) { - instruction = cf_data_find(cs, 0, "unlang"); + instruction = cf_data_find(cs, CF_DATA_TYPE_UNLANG, "unlang"); if (!instruction) { REDEBUG("Failed to find pre-compiled unlang for section %s %s { ... }", cf_section_name1(cs), cf_section_name2(cs)); diff --git a/src/main/listen.c b/src/main/listen.c index e1b8bb32ec1..10766ec80bb 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -106,7 +106,7 @@ int listen_compile(CONF_SECTION *server, CONF_SECTION *cs) { rad_protocol_t const *proto; - proto = cf_data_find(cs, 0, "proto"); + proto = cf_data_find(cs, CF_DATA_TYPE_PROTOCOL, "proto"); if (!proto || !proto->compile) return 0; if (proto->compile(server, cs) < 0) { @@ -223,13 +223,13 @@ int listen_bootstrap(CONF_SECTION *server, CONF_SECTION *cs, char const *server_ return -1; } - if (cf_data_find(cs, 0, "proto") != NULL) { + if (cf_data_find(cs, CF_DATA_TYPE_PROTOCOL, "proto") != NULL) { cf_log_err_cs(cs, "Virtual server cannot have two protocols"); talloc_const_free(module); return -1; } - cf_data_add(cs, 0, "proto", proto, NULL); + cf_data_add(cs, CF_DATA_TYPE_PROTOCOL, "proto", proto, NULL); } /* diff --git a/src/main/modcall.c b/src/main/modcall.c index ee63bc7d594..65626469bf0 100644 --- a/src/main/modcall.c +++ b/src/main/modcall.c @@ -1546,7 +1546,7 @@ static unlang_t *compile_update(unlang_t *parent, unlang_compile_t *unlang_ctx, g->map = talloc_steal(g, head); #ifdef WITH_CONF_WRITE -// cf_data_add(cs, 0, "update", g->map, NULL); /* for output normalization */ +// cf_data_add(cs, CF_DATA_TYPE_UNLANG, "update", g->map, NULL); /* for output normalization */ #endif if (!pass2_fixup_update(g)) { @@ -1768,7 +1768,7 @@ static unlang_t *compile_children(unlang_group_t *g, UNUSED unlang_t *parent, un /* * Skip precompiled blocks. */ - if (cf_data_find(subcs, 0, "unlang")) continue; + if (cf_data_find(subcs, CF_DATA_TYPE_UNLANG, "unlang")) continue; /* * "actions" apply to the current group. @@ -2242,7 +2242,7 @@ static unlang_t *compile_if(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF return NULL; } - cond = cf_data_find(cs, 0, "if"); + cond = cf_data_find(cs, CF_DATA_TYPE_UNLANG, "if"); rad_assert(cond != NULL); if (cond->type == COND_TYPE_FALSE) { @@ -3036,7 +3036,7 @@ int unlang_compile(CONF_SECTION *cs, rlm_components_t component) /* * Associate the unlang with the configuration section. */ - cf_data_add(cs, 0, "unlang", c, NULL); + cf_data_add(cs, CF_DATA_TYPE_UNLANG, "unlang", c, NULL); dump_tree(c, c->debug_name); return 0; diff --git a/src/main/modules.c b/src/main/modules.c index fd2e52747c7..fb839672d68 100644 --- a/src/main/modules.c +++ b/src/main/modules.c @@ -172,12 +172,12 @@ int module_sibling_section_find(CONF_SECTION **out, CONF_SECTION *module, char c cp = cf_pair_find(module, name); if (!cp) return 0; - if (cf_data_find(module, 0, FIND_SIBLING_CF_KEY)) { + if (cf_data_find(module, CF_DATA_TYPE_CONNECTION_POOL, FIND_SIBLING_CF_KEY)) { cf_log_err_cp(cp, "Module reference loop found"); return -1; } - cf_data_add(module, 0, FIND_SIBLING_CF_KEY, &loop, NULL); + cf_data_add(module, CF_DATA_TYPE_CONNECTION_POOL, FIND_SIBLING_CF_KEY, &loop, NULL); /* * Item found, resolve it to a module instance. @@ -191,7 +191,7 @@ int module_sibling_section_find(CONF_SECTION **out, CONF_SECTION *module, char c * Remove the config data we added for loop * detection. */ - cf_data_remove(module, 0, FIND_SIBLING_CF_KEY); + cf_data_remove(module, CF_DATA_TYPE_CONNECTION_POOL, FIND_SIBLING_CF_KEY); if (!inst) { cf_log_err_cp(cp, "Unknown module instance \"%s\"", inst_name); @@ -308,7 +308,7 @@ fr_connection_pool_t *module_connection_pool_init(CONF_SECTION *module, * This allows modules to pass in the config sections * they would like to use the connection pool from. */ - pool = cf_data_find(cs, 0, CONNECTION_POOL_CF_KEY); + pool = cf_data_find(cs, CF_DATA_TYPE_CONNECTION_POOL, CONNECTION_POOL_CF_KEY); if (!pool) { DEBUG4("%s: No pool reference found for config item \"%s.pool\"", log_prefix, parent_name(cs)); pool = fr_connection_pool_init(cs, cs, opaque, c, a, log_prefix); @@ -317,7 +317,7 @@ fr_connection_pool_t *module_connection_pool_init(CONF_SECTION *module, fr_connection_pool_enable_triggers(pool, trigger_prefix, trigger_args); DEBUG4("%s: Adding pool reference %p to config item \"%s.pool\"", log_prefix, pool, parent_name(cs)); - cf_data_add(cs, 0, CONNECTION_POOL_CF_KEY, pool, NULL); + cf_data_add(cs, CF_DATA_TYPE_CONNECTION_POOL, CONNECTION_POOL_CF_KEY, pool, NULL); return pool; } fr_connection_pool_ref(pool); @@ -332,7 +332,7 @@ fr_connection_pool_t *module_connection_pool_init(CONF_SECTION *module, if (mycs != cs) { DEBUG4("%s: Copying pool reference %p from config item \"%s.pool\" to config item \"%s.pool\"", log_prefix, pool, parent_name(cs), parent_name(mycs)); - cf_data_add(mycs, 0, CONNECTION_POOL_CF_KEY, pool, NULL); + cf_data_add(mycs, CF_DATA_TYPE_CONNECTION_POOL, CONNECTION_POOL_CF_KEY, pool, NULL); } return pool; @@ -383,7 +383,7 @@ module_instance_t *module_find(CONF_SECTION *modules, char const *asked_name) instance_name = asked_name; if (instance_name[0] == '-') instance_name++; - return (module_instance_t *)cf_data_find(modules, 0, instance_name); + return (module_instance_t *)cf_data_find(modules, CF_DATA_TYPE_CONNECTION_POOL, instance_name); } /** Find an existing module instance and verify it implements the specified method @@ -886,7 +886,7 @@ static module_instance_t *module_bootstrap(CONF_SECTION *modules, CONF_SECTION * /* * Remember the module for later. */ - cf_data_add(modules, 0, instance->name, instance, NULL); + cf_data_add(modules, CF_DATA_TYPE_CONNECTION_POOL, instance->name, instance, NULL); return instance; } diff --git a/src/main/realms.c b/src/main/realms.c index 5f4834b81bd..4e35e80d672 100644 --- a/src/main/realms.c +++ b/src/main/realms.c @@ -596,7 +596,7 @@ bool realm_home_server_add(home_server_t *home) /* * Mark it as already processed */ - cf_data_add(home->cs, 0, "home_server", (void *)null_free, null_free); + cf_data_add(home->cs, CF_DATA_TYPE_HOME_SERVER_POOL, "home_server", (void *)null_free, null_free); return true; } @@ -1356,7 +1356,7 @@ static int server_pool_add(realm_config_t *rc, if (do_print) cf_log_info(cs, " }"); - cf_data_add(cs, 0, "home_server_pool", pool, NULL); + cf_data_add(cs, CF_DATA_TYPE_HOME_SERVER_POOL, "home_server_pool", pool, NULL); (void) talloc_steal(cs, pool); rad_assert(pool->server_type != 0); @@ -2232,7 +2232,7 @@ int realms_init(CONF_SECTION *config) /* * Pool was already loaded. */ - if (cf_data_find(cs, 0, "home_server_pool")) continue; + if (cf_data_find(cs, CF_DATA_TYPE_HOME_SERVER_POOL, "home_server_pool")) continue; type = pool_peek_type(config, cs); if (type == HOME_TYPE_INVALID) goto error; diff --git a/src/main/tls/conf.c b/src/main/tls/conf.c index 2de479678e9..0dbf2a9a73b 100644 --- a/src/main/tls/conf.c +++ b/src/main/tls/conf.c @@ -310,7 +310,7 @@ fr_tls_conf_t *tls_conf_parse_server(CONF_SECTION *cs) * If cs has already been parsed there should be a cached copy * of conf already stored, so just return that. */ - conf = cf_data_find(cs, 0, "tls-conf"); + conf = cf_data_find(cs, CF_DATA_TYPE_TLS, "tls-conf"); if (conf) { DEBUG("Using cached TLS configuration from previous invocation"); return conf; @@ -432,7 +432,7 @@ fr_tls_conf_t *tls_conf_parse_server(CONF_SECTION *cs) /* * Cache conf in cs in case we're asked to parse this again. */ - cf_data_add(cs, 0, "tls-conf", conf, NULL); + cf_data_add(cs, CF_DATA_TYPE_TLS, "tls-conf", conf, NULL); return conf; } @@ -442,7 +442,7 @@ fr_tls_conf_t *tls_conf_parse_client(CONF_SECTION *cs) fr_tls_conf_t *conf; uint32_t i; - conf = cf_data_find(cs, 0, "tls-conf"); + conf = cf_data_find(cs, CF_DATA_TYPE_TLS, "tls-conf"); if (conf) { DEBUG2("Using cached TLS configuration from previous invocation"); return conf;