diff --git a/common.c b/common.c index b104e0e..21634d4 100644 --- a/common.c +++ b/common.c @@ -1014,7 +1014,7 @@ enum config_item_type CONFIG_ITEM_STRING_ARRAY ///< Comma-separated list of strings }; -struct config_item_ +struct config_item { enum config_item_type type; ///< Type of the item union @@ -1040,10 +1040,10 @@ struct config_schema /// Check if the new value can be accepted. /// In addition to this, "type" and having a default is considered. - bool (*validate) (const struct config_item_ *, struct error **e); + bool (*validate) (const struct config_item *, struct error **e); /// The value has changed - void (*on_change) (struct config_item_ *); + void (*on_change) (struct config_item *); }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1073,7 +1073,7 @@ config_item_type_is_string (enum config_item_type type) } static void -config_item_free (struct config_item_ *self) +config_item_free (struct config_item *self) { switch (self->type) { @@ -1089,7 +1089,7 @@ config_item_free (struct config_item_ *self) } static void -config_item_destroy (struct config_item_ *self) +config_item_destroy (struct config_item *self) { config_item_free (self); free (self); @@ -1098,7 +1098,7 @@ config_item_destroy (struct config_item_ *self) /// Doesn't do any validations or handle schemas, just moves source data /// to the target item and destroys the source item static void -config_item_move (struct config_item_ *self, struct config_item_ *source) +config_item_move (struct config_item *self, struct config_item *source) { // Not quite sure how to handle that hard_assert (!source->schema); @@ -1109,40 +1109,40 @@ config_item_move (struct config_item_ *self, struct config_item_ *source) free (source); } -static struct config_item_ * +static struct config_item * config_item_new (enum config_item_type type) { - struct config_item_ *self = xcalloc (1, sizeof *self); + struct config_item *self = xcalloc (1, sizeof *self); self->type = type; return self; } -static struct config_item_ * +static struct config_item * config_item_null (void) { return config_item_new (CONFIG_ITEM_NULL); } -static struct config_item_ * +static struct config_item * config_item_boolean (bool b) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_BOOLEAN); + struct config_item *self = config_item_new (CONFIG_ITEM_BOOLEAN); self->value.boolean = b; return self; } -static struct config_item_ * +static struct config_item * config_item_integer (int64_t i) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_INTEGER); + struct config_item *self = config_item_new (CONFIG_ITEM_INTEGER); self->value.integer = i; return self; } -static struct config_item_ * +static struct config_item * config_item_string (const struct str *s) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_STRING); + struct config_item *self = config_item_new (CONFIG_ITEM_STRING); str_init (&self->value.string); hard_assert (utf8_validate (self->value.string.str, self->value.string.len)); @@ -1150,29 +1150,29 @@ config_item_string (const struct str *s) return self; } -static struct config_item_ * +static struct config_item * config_item_string_from_cstr (const char *s) { struct str tmp; str_init (&tmp); str_append (&tmp, s); - struct config_item_ *self = config_item_string (&tmp); + struct config_item *self = config_item_string (&tmp); str_free (&tmp); return self; } -static struct config_item_ * +static struct config_item * config_item_string_array (const struct str *s) { - struct config_item_ *self = config_item_string (s); + struct config_item *self = config_item_string (s); self->type = CONFIG_ITEM_STRING_ARRAY; return self; } -static struct config_item_ * +static struct config_item * config_item_object (void) { - struct config_item_ *self = config_item_new (CONFIG_ITEM_OBJECT); + struct config_item *self = config_item_new (CONFIG_ITEM_OBJECT); str_map_init (&self->value.object); self->value.object.free = (void (*)(void *)) config_item_destroy; return self; @@ -1192,7 +1192,7 @@ config_schema_accepts_type } static bool -config_item_validate_by_schema (struct config_item_ *self, +config_item_validate_by_schema (struct config_item *self, struct config_schema *schema, struct error **e) { struct error *error = NULL; @@ -1211,7 +1211,7 @@ config_item_validate_by_schema (struct config_item_ *self, } static bool -config_item_set_from (struct config_item_ *self, struct config_item_ *source, +config_item_set_from (struct config_item *self, struct config_item *source, struct error **e) { struct config_schema *schema = self->schema; @@ -1238,8 +1238,8 @@ config_item_set_from (struct config_item_ *self, struct config_item_ *source, return true; } -static struct config_item_ * -config_item_get (struct config_item_ *self, const char *path, struct error **e) +static struct config_item * +config_item_get (struct config_item *self, const char *path, struct error **e) { hard_assert (self->type == CONFIG_ITEM_OBJECT); @@ -1247,7 +1247,7 @@ config_item_get (struct config_item_ *self, const char *path, struct error **e) str_vector_init (&v); split_str (path, '.', &v); - struct config_item_ *result = NULL; + struct config_item *result = NULL; size_t i = 0; while (true) { @@ -1277,7 +1277,7 @@ struct config_writer }; static void config_item_write_object_innards - (struct config_writer *self, struct config_item_ *object); + (struct config_writer *self, struct config_item *object); static void config_item_write_string (struct str *output, const struct str *s) @@ -1299,7 +1299,7 @@ config_item_write_string (struct str *output, const struct str *s) static void config_item_write_object - (struct config_writer *self, struct config_item_ *value) + (struct config_writer *self, struct config_item *value) { char indent[self->indent + 1]; memset (indent, '\t', self->indent); @@ -1318,7 +1318,7 @@ config_item_write_object } static void -config_item_write_value (struct config_writer *self, struct config_item_ *value) +config_item_write_value (struct config_writer *self, struct config_item *value) { switch (value->type) { @@ -1345,7 +1345,7 @@ config_item_write_value (struct config_writer *self, struct config_item_ *value) static void config_item_write_kv_pair (struct config_writer *self, - const char *key, struct config_item_ *value) + const char *key, struct config_item *value) { char indent[self->indent + 1]; memset (indent, '\t', self->indent); @@ -1362,20 +1362,20 @@ config_item_write_kv_pair (struct config_writer *self, static void config_item_write_object_innards - (struct config_writer *self, struct config_item_ *object) + (struct config_writer *self, struct config_item *object) { hard_assert (object->type == CONFIG_ITEM_OBJECT); struct str_map_iter iter; str_map_iter_init (&iter, &object->value.object); - struct config_item_ *value; + struct config_item *value; while ((value = str_map_iter_next (&iter))) config_item_write_kv_pair (self, iter.link->key, value); } static void -config_item_write (struct config_item_ *value, +config_item_write (struct config_item *value, bool object_innards, struct str *output) { struct config_writer writer = { .output = output, .indent = 0 }; @@ -1769,13 +1769,13 @@ config_parser_expect #define EXPECT(token) config_parser_expect (self, token, err) #define SKIP_NL() do {} while (ACCEPT (CONFIG_T_NEWLINE)) -static struct config_item_ *config_parser_parse_object +static struct config_item *config_parser_parse_object (struct config_parser *self, jmp_buf out); -static struct config_item_ * +static struct config_item * config_parser_parse_value (struct config_parser *self, jmp_buf out) { - struct config_item_ *volatile result = NULL; + struct config_item *volatile result = NULL; jmp_buf err; if (setjmp (err)) @@ -1810,7 +1810,7 @@ config_parser_parse_value (struct config_parser *self, jmp_buf out) /// Parse a single "key = value" assignment into @a object static bool config_parser_parse_kv_pair (struct config_parser *self, - struct config_item_ *object, jmp_buf out) + struct config_item *object, jmp_buf out) { char *volatile key = NULL; jmp_buf err; @@ -1851,10 +1851,10 @@ config_parser_parse_kv_pair (struct config_parser *self, } /// Parse the inside of an object definition -static struct config_item_ * +static struct config_item * config_parser_parse_object (struct config_parser *self, jmp_buf out) { - struct config_item_ *volatile object = config_item_object (); + struct config_item *volatile object = config_item_object (); jmp_buf err; if (setjmp (err)) @@ -1877,14 +1877,14 @@ config_parser_parse_object (struct config_parser *self, jmp_buf out) /// Parse a configuration snippet either as an object or a bare value. /// If it's the latter (@a single_value_only), no newlines may follow. -static struct config_item_ * +static struct config_item * config_item_parse (const char *script, size_t len, bool single_value_only, struct error **e) { struct config_parser parser; config_parser_init (&parser, script, len); - struct config_item_ *volatile object = NULL; + struct config_item *volatile object = NULL; jmp_buf err; if (setjmp (err)) @@ -1916,14 +1916,14 @@ end: } /// Clone an item. Schema assignments aren't retained. -struct config_item_ * -config_item_clone (struct config_item_ *self) +struct config_item * +config_item_clone (struct config_item *self) { // Oh well, it saves code struct str tmp; str_init (&tmp); config_item_write (self, false, &tmp); - struct config_item_ *result = + struct config_item *result = config_item_parse (tmp.str, tmp.len, true, NULL); str_free (&tmp); return result; @@ -1933,9 +1933,9 @@ config_item_clone (struct config_item_ *self) static void config_schema_initialize_item (struct config_schema *schema, - struct config_item_ *parent, void *user_data) + struct config_item *parent, void *user_data) { - struct config_item_ *item = + struct config_item *item = str_map_find (&parent->value.object, schema->name); bool replace = true; @@ -1981,7 +1981,7 @@ config_schema_initialize_item (struct config_schema *schema, static void config_schema_apply_to_object (struct config_schema *schema_array, - struct config_item_ *object, void *user_data) + struct config_item *object, void *user_data) { hard_assert (object->type == CONFIG_ITEM_OBJECT); while (schema_array->name) @@ -1989,14 +1989,14 @@ config_schema_apply_to_object (struct config_schema *schema_array, } static void -config_schema_call_changed (struct config_item_ *item) +config_schema_call_changed (struct config_item *item) { if (item->type == CONFIG_ITEM_OBJECT) { struct str_map_iter iter; str_map_iter_init (&iter, &item->value.object); - struct config_item_ *child; + struct config_item *child; while ((child = str_map_iter_next (&iter))) config_schema_call_changed (child); } @@ -2009,7 +2009,7 @@ config_schema_call_changed (struct config_item_ *item) // XXX: this doesn't necessarily have to be well designed at all typedef void (*config_module_load_fn) - (struct config_item_ *subtree, void *user_data); + (struct config_item *subtree, void *user_data); struct config_module { @@ -2035,7 +2035,7 @@ config_module_destroy (struct config_module *self) struct config { struct str_map modules; ///< Toplevel modules - struct config_item_ *root; ///< CONFIG_ITEM_OBJECT + struct config_item *root; ///< CONFIG_ITEM_OBJECT }; static void @@ -2067,7 +2067,7 @@ config_register_module (struct config *self, } static void -config_load (struct config *self, struct config_item_ *root) +config_load (struct config *self, struct config_item *root) { hard_assert (root->type == CONFIG_ITEM_OBJECT); self->root = root; @@ -2078,7 +2078,7 @@ config_load (struct config *self, struct config_item_ *root) struct config_module *module; while ((module = str_map_iter_next (&iter))) { - struct config_item_ *subtree = str_map_find + struct config_item *subtree = str_map_find (&root->value.object, module->name); // Silently fix inputs that only a lunatic user could create if (!subtree || subtree->type != CONFIG_ITEM_OBJECT) diff --git a/degesch.c b/degesch.c index 875eead..3896d74 100644 --- a/degesch.c +++ b/degesch.c @@ -1112,7 +1112,7 @@ struct server char *name; ///< Server identifier struct buffer *buffer; ///< The buffer for this server - struct config_item_ *config; ///< Configuration root + struct config_item *config; ///< Configuration root // Connection: @@ -1473,25 +1473,25 @@ static void refresh_prompt (struct app_context *ctx); // --- Configuration ----------------------------------------------------------- static void -on_config_debug_mode_change (struct config_item_ *item) +on_config_debug_mode_change (struct config_item *item) { g_debug_mode = item->value.boolean; } static void -on_config_show_all_prefixes_change (struct config_item_ *item) +on_config_show_all_prefixes_change (struct config_item *item) { struct app_context *ctx = item->user_data; ctx->show_all_prefixes = item->value.boolean; refresh_prompt (ctx); } -static void on_config_attribute_change (struct config_item_ *item); -static void on_config_logging_change (struct config_item_ *item); +static void on_config_attribute_change (struct config_item *item); +static void on_config_logging_change (struct config_item *item); #define TRIVIAL_BOOLEAN_ON_CHANGE(name) \ static void \ - on_config_ ## name ## _change (struct config_item_ *item) \ + on_config_ ## name ## _change (struct config_item *item) \ { \ struct app_context *ctx = item->user_data; \ ctx->name = item->value.boolean; \ @@ -1504,7 +1504,7 @@ TRIVIAL_BOOLEAN_ON_CHANGE (beep_on_highlight) static bool config_validate_nonjunk_string - (const struct config_item_ *item, struct error **e) + (const struct config_item *item, struct error **e) { if (item->type == CONFIG_ITEM_NULL) return true; @@ -1525,7 +1525,7 @@ config_validate_nonjunk_string static bool config_validate_addresses - (const struct config_item_ *item, struct error **e) + (const struct config_item *item, struct error **e) { if (item->type == CONFIG_ITEM_NULL) return true; @@ -1548,7 +1548,7 @@ config_validate_addresses static bool config_validate_nonnegative - (const struct config_item_ *item, struct error **e) + (const struct config_item *item, struct error **e) { if (item->type == CONFIG_ITEM_NULL) return true; @@ -1722,13 +1722,13 @@ static struct config_schema g_config_attributes[] = // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static void -load_config_behaviour (struct config_item_ *subtree, void *user_data) +load_config_behaviour (struct config_item *subtree, void *user_data) { config_schema_apply_to_object (g_config_behaviour, subtree, user_data); } static void -load_config_attributes (struct config_item_ *subtree, void *user_data) +load_config_attributes (struct config_item *subtree, void *user_data) { config_schema_apply_to_object (g_config_attributes, subtree, user_data); } @@ -1747,9 +1747,9 @@ register_config_modules (struct app_context *ctx) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static const char * -get_config_string (struct config_item_ *root, const char *key) +get_config_string (struct config_item *root, const char *key) { - struct config_item_ *item = config_item_get (root, key, NULL); + struct config_item *item = config_item_get (root, key, NULL); hard_assert (item); if (item->type == CONFIG_ITEM_NULL) return NULL; @@ -1759,12 +1759,12 @@ get_config_string (struct config_item_ *root, const char *key) static bool set_config_string - (struct config_item_ *root, const char *key, const char *value) + (struct config_item *root, const char *key, const char *value) { - struct config_item_ *item = config_item_get (root, key, NULL); + struct config_item *item = config_item_get (root, key, NULL); hard_assert (item); - struct config_item_ *new_ = config_item_string_from_cstr (value); + struct config_item *new_ = config_item_string_from_cstr (value); struct error *e = NULL; if (config_item_set_from (item, new_, &e)) return true; @@ -1776,17 +1776,17 @@ set_config_string } static int64_t -get_config_integer (struct config_item_ *root, const char *key) +get_config_integer (struct config_item *root, const char *key) { - struct config_item_ *item = config_item_get (root, key, NULL); + struct config_item *item = config_item_get (root, key, NULL); hard_assert (item && item->type == CONFIG_ITEM_INTEGER); return item->value.integer; } static bool -get_config_boolean (struct config_item_ *root, const char *key) +get_config_boolean (struct config_item *root, const char *key) { - struct config_item_ *item = config_item_get (root, key, NULL); + struct config_item *item = config_item_get (root, key, NULL); hard_assert (item && item->type == CONFIG_ITEM_BOOLEAN); return item->value.boolean; } @@ -2020,7 +2020,7 @@ log_message_attributed (void *user_data, const char *quote, const char *fmt, } static void -apply_attribute_change (struct config_item_ *item, int id) +apply_attribute_change (struct config_item *item, int id) { struct app_context *ctx = item->user_data; free (ctx->attrs[id]); @@ -2030,7 +2030,7 @@ apply_attribute_change (struct config_item_ *item, int id) } static void -on_config_attribute_change (struct config_item_ *item) +on_config_attribute_change (struct config_item *item) { static const char *table[ATTR_COUNT] = { @@ -3055,7 +3055,7 @@ buffer_close_log_file (struct buffer *buffer) } static void -on_config_logging_change (struct config_item_ *item) +on_config_logging_change (struct config_item *item) { struct app_context *ctx = item->user_data; ctx->logging = item->value.boolean; @@ -6737,11 +6737,11 @@ struct config_dump_data }; static void config_dump_item - (struct config_item_ *item, struct config_dump_data *data); + (struct config_item *item, struct config_dump_data *data); static void config_dump_children - (struct config_item_ *object, struct config_dump_data *data) + (struct config_item *object, struct config_dump_data *data) { hard_assert (object->type == CONFIG_ITEM_OBJECT); @@ -6754,7 +6754,7 @@ config_dump_children struct str_map_iter iter; str_map_iter_init (&iter, &object->value.object); - struct config_item_ *child; + struct config_item *child; while ((child = str_map_iter_next (&iter))) { level.name = iter.link->key; @@ -6766,7 +6766,7 @@ config_dump_children } static void -config_dump_item (struct config_item_ *item, struct config_dump_data *data) +config_dump_item (struct config_item *item, struct config_dump_data *data) { // Empty objects will show as such if (item->type == CONFIG_ITEM_OBJECT @@ -6817,7 +6817,7 @@ config_dump_item (struct config_item_ *item, struct config_dump_data *data) } static void -config_dump (struct config_item_ *root, struct str_vector *output) +config_dump (struct config_item *root, struct str_vector *output) { struct config_dump_data data; data.head = NULL; @@ -6908,7 +6908,7 @@ check_server_name_for_addition (struct app_context *ctx, const char *name) static struct server * server_add (struct app_context *ctx, - const char *name, struct config_item_ *subtree) + const char *name, struct config_item *subtree) { hard_assert (!str_map_find (&ctx->servers, name)); @@ -6947,7 +6947,7 @@ server_add_new (struct app_context *ctx, const char *name) // of manual edits to the configuration, though, and they're not really // going to break anything. They only cause surprises when loading. struct str_map *servers = get_servers_config (ctx); - struct config_item_ *subtree = config_item_object (); + struct config_item *subtree = config_item_object (); str_map_set (servers, name, subtree); struct server *s = server_add (ctx, name, subtree); @@ -7259,7 +7259,7 @@ handle_command_buffer (struct handler_args *a) static bool replace_string_array - (struct config_item_ *item, struct str_vector *array, struct error **e) + (struct config_item *item, struct str_vector *array, struct error **e) { char *changed = join_str_vector (array, ','); struct str tmp = { .str = changed, .len = strlen (changed) }; @@ -7271,7 +7271,7 @@ replace_string_array static bool handle_command_set_add - (struct config_item_ *item, const char *value, struct error **e) + (struct config_item *item, const char *value, struct error **e) { bool result = false; struct str_vector items; @@ -7294,7 +7294,7 @@ handle_command_set_add static bool handle_command_set_remove - (struct config_item_ *item, const char *value, struct error **e) + (struct config_item *item, const char *value, struct error **e) { bool result = false; struct str_vector items; @@ -7318,9 +7318,9 @@ handle_command_set_remove static void handle_command_set_assign_item (struct app_context *ctx, - char *key, struct config_item_ *new_, bool add, bool remove) + char *key, struct config_item *new_, bool add, bool remove) { - struct config_item_ *item = + struct config_item *item = config_item_get (ctx->config.root, key, NULL); hard_assert (item); @@ -7369,7 +7369,7 @@ handle_command_set_assign return false; struct error *e = NULL; - struct config_item_ *new_ = + struct config_item *new_ = config_item_parse (arguments, strlen (arguments), true, &e); if (e) { @@ -7447,7 +7447,7 @@ show_aliases_list (struct app_context *ctx) struct str_map_iter iter; str_map_iter_init (&iter, aliases); - struct config_item_ *alias; + struct config_item *alias; while ((alias = str_map_iter_next (&iter))) { struct str definition; @@ -7473,7 +7473,7 @@ handle_command_alias (struct handler_args *a) if (!*a->arguments) return false; - struct config_item_ *alias = config_item_string_from_cstr (a->arguments); + struct config_item *alias = config_item_string_from_cstr (a->arguments); struct str definition; str_init (&definition); @@ -8263,7 +8263,7 @@ g_command_handlers[] = static bool try_handle_command_help_option (struct app_context *ctx, const char *name) { - struct config_item_ *item = + struct config_item *item = config_item_get (ctx->config.root, name, NULL); if (!item) return false; @@ -8465,7 +8465,7 @@ static bool expand_alias (struct app_context *ctx, const char *alias_name, char *input, struct str_vector *commands) { - struct config_item_ *entry = + struct config_item *entry = str_map_find (get_aliases_config (ctx), alias_name); if (!entry) return false; @@ -8715,7 +8715,7 @@ complete_command (struct app_context *ctx, struct completion *data, struct str_map_iter iter; str_map_iter_init (&iter, get_aliases_config (ctx)); - struct config_item_ *alias; + struct config_item *alias; while ((alias = str_map_iter_next (&iter))) { if (!strncasecmp_ascii (word, iter.link->key, word_len)) @@ -9470,10 +9470,10 @@ read_file (const char *filename, struct str *output, struct error **e) return false; } -static struct config_item_ * +static struct config_item * load_configuration_file (const char *filename, struct error **e) { - struct config_item_ *root = NULL; + struct config_item *root = NULL; struct str data; str_init (&data); @@ -9544,7 +9544,7 @@ load_default_aliases (struct app_context *ctx) static void load_configuration (struct app_context *ctx) { - struct config_item_ *root = NULL; + struct config_item *root = NULL; struct error *e = NULL; char *filename = resolve_filename @@ -9587,7 +9587,7 @@ load_servers (struct app_context *ctx) struct str_map_iter iter; str_map_iter_init (&iter, get_servers_config (ctx)); - struct config_item_ *subtree; + struct config_item *subtree; while ((subtree = str_map_iter_next (&iter))) { const char *name = iter.link->key;