+static int ts_config_add_meta_delete(ts_key_list_t **dest, /* {{{ */
+ const oconfig_item_t *ci) {
+ ts_key_list_t *entry = NULL;
+
+ entry = calloc(1, sizeof(*entry));
+ if (entry == NULL) {
+ ERROR("ts_config_add_meta_delete: calloc failed.");
+ return -ENOMEM;
+ }
+
+ if (cf_util_get_string(ci, &entry->key) != 0) {
+ ts_key_list_free(entry);
+ return -1; /* An error has already been reported. */
+ }
+
+ if (strlen(entry->key) == 0) {
+ ERROR("Target `set': The `%s' option does not accept empty string as "
+ "first argument.",
+ ci->key);
+ ts_key_list_free(entry);
+ return -1;
+ }
+
+ entry->next = *dest;
+ *dest = entry;
+
+ return 0;
+} /* }}} int ts_config_add_meta_delete */
+
+static void ts_subst(char *dest, size_t size, const char *string, /* {{{ */
+ const value_list_t *vl) {
+ char temp[DATA_MAX_NAME_LEN];
+
+ /* Initialize the field with the template. */
+ sstrncpy(dest, string, size);
+
+ if (strchr(dest, '%') == NULL)
+ return;
+
+#define REPLACE_FIELD(t, v) \
+ if (subst_string(temp, sizeof(temp), dest, t, v) != NULL) \
+ sstrncpy(dest, temp, size);
+ REPLACE_FIELD("%{host}", vl->host);
+ REPLACE_FIELD("%{plugin}", vl->plugin);
+ REPLACE_FIELD("%{plugin_instance}", vl->plugin_instance);
+ REPLACE_FIELD("%{type}", vl->type);
+ REPLACE_FIELD("%{type_instance}", vl->type_instance);
+
+ if (vl->meta != NULL) {
+ char **meta_toc = NULL;
+ int status = meta_data_toc(vl->meta, &meta_toc);
+ if (status <= 0)
+ return;
+ size_t meta_entries = (size_t)status;
+
+ for (size_t i = 0; i < meta_entries; i++) {
+ char meta_name[DATA_MAX_NAME_LEN];
+ char *value_str;
+ const char *key = meta_toc[i];
+
+ snprintf(meta_name, sizeof(meta_name), "%%{meta:%s}", key);
+ if (meta_data_as_string(vl->meta, key, &value_str) != 0)
+ continue;
+
+ REPLACE_FIELD(meta_name, value_str);
+ sfree(value_str);
+ }
+
+ strarray_free(meta_toc, (size_t)meta_entries);
+ }
+} /* }}} int ts_subst */
+
+static int ts_destroy(void **user_data) /* {{{ */