aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-12-24 16:02:26 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-12-25 05:02:58 +0100
commit25bb7a978d9585065be263a6f1ae2d2653d9bf58 (patch)
tree89a0268341d398db1354a799012fc79c488b8682 /degesch.c
parent7d531a9bbf01e15573c4a5b9d6a06bd20eb2f983 (diff)
downloadxK-25bb7a978d9585065be263a6f1ae2d2653d9bf58.tar.gz
xK-25bb7a978d9585065be263a6f1ae2d2653d9bf58.tar.xz
xK-25bb7a978d9585065be263a6f1ae2d2653d9bf58.zip
degesch: refactoring
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/degesch.c b/degesch.c
index ba624de..9cd3882 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2156,18 +2156,8 @@ log_message_attributed (void *user_data, const char *quote, const char *fmt,
input_show (&ctx->input);
}
-static void
-apply_attribute_change (struct config_item *item, int id)
-{
- struct app_context *ctx = item->user_data;
- free (ctx->attrs[id]);
- ctx->attrs[id] = xstrdup (item->type == CONFIG_ITEM_NULL
- ? ctx->attrs_defaults[id]
- : item->value.string.str);
-}
-
-static void
-on_config_attribute_change (struct config_item *item)
+static ssize_t
+attr_by_name (const char *name)
{
static const char *table[ATTR_COUNT] =
{
@@ -2177,11 +2167,23 @@ on_config_attribute_change (struct config_item *item)
};
for (size_t i = 0; i < N_ELEMENTS (table); i++)
- if (!strcmp (item->schema->name, table[i]))
- {
- apply_attribute_change (item, i);
- return;
- }
+ if (!strcmp (name, table[i]))
+ return i;
+ return -1;
+}
+
+static void
+on_config_attribute_change (struct config_item *item)
+{
+ struct app_context *ctx = item->user_data;
+ ssize_t id = attr_by_name (item->schema->name);
+ if (id != -1)
+ {
+ free (ctx->attrs[id]);
+ ctx->attrs[id] = xstrdup (item->type == CONFIG_ITEM_NULL
+ ? ctx->attrs_defaults[id]
+ : item->value.string.str);
+ }
}
static void