char *name = NULL;
while (uc_iterator_next(iter, &name) == 0) {
value_list_t vl;
- if (parse_identifier_vl(name, &vl) != 0) {
+ if (parse_identifier_vl(name, &vl, NULL) != 0) {
status = grpc::Status(grpc::StatusCode::INTERNAL,
grpc::string("failed to parse identifier"));
break;
topic = strdup(msg->topic);
name = strip_prefix(topic);
- status = parse_identifier_vl(name, &vl);
+ status = parse_identifier_vl(name, &vl, NULL);
if (status != 0) {
ERROR("mqtt plugin: Unable to parse topic \"%s\".", topic);
sfree(topic);
}
char const *identifier = argv[0];
- int status = parse_identifier_vl(identifier, &vl);
+ int status = parse_identifier_vl(identifier, &vl, NULL);
if (status != 0) {
DEBUG("cmd_handle_putval: Cannot parse identifier `%s'.", identifier);
cmd_error(CMD_PARSE_ERROR, errhndl, "parse_identifier_vl(\"%s\"): %s",
return 0;
} /* int parse_identifier */
-int parse_identifier_vl(const char *str, value_list_t *vl) /* {{{ */
-{
+int parse_identifier_vl(const char *str, value_list_t *vl,
+ char **ret_data_source) {
if ((str == NULL) || (vl == NULL))
return EINVAL;
return status;
}
+ if (data_source != NULL) {
+ if (ret_data_source == NULL) {
+ return EINVAL;
+ }
+ *ret_data_source = strdup(data_source);
+ }
+
char *plugin_instance = strchr(plugin, '-');
if (plugin_instance != NULL) {
*plugin_instance = 0;
int parse_identifier(char *str, char **ret_host, char **ret_plugin,
char **ret_type, char **ret_data_source,
char *default_host);
-int parse_identifier_vl(const char *str, value_list_t *vl);
+
+/* parse_identifier_vl parses an identifier in the form
+ * "host/plugin[-inst]/type[-inst]/data_source" and stores the fields in a
+ * value_list_t. If vl->host is not empty, then it is used as the default value
+ * if a host name is omitted, i.e. the "plugin/type" format is accepted. If
+ * ret_data_source is not NULL, a four-part identifier is accepted and a
+ * pointer to the data source name is (optionally) stored and needs to be freed
+ * by the caller. If the provided format does not fit the provided arguments,
+ * e.g. a two-part format but no default host provided, or a four-part format
+ * but no ret_data_source pointer, then EINVAL is returned.
+ */
+int parse_identifier_vl(const char *str, value_list_t *vl,
+ char **ret_data_source);
+
int parse_value(const char *value, value_t *ret_value, int ds_type);
int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds);