]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
common: Add a "data_source" return argument to parse_identifier_vl().
authorFlorian Forster <octo@google.com>
Thu, 30 Jul 2020 16:21:06 +0000 (18:21 +0200)
committerFlorian Forster <octo@google.com>
Thu, 30 Jul 2020 16:22:26 +0000 (18:22 +0200)
src/grpc.cc
src/mqtt.c
src/utils/cmds/putval.c
src/utils/common/common.c
src/utils/common/common.h

index d07acc82c3ccd93ee72a8207346ce82c7f8fc669..7161589d034dd69fc13775e59b667865cd184ba5 100644 (file)
@@ -456,7 +456,7 @@ private:
     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;
index b8a1bf32b170284c82062438c5bb795429c3fe6e..ff64d3c2ea0455cff240a60331950ff4b9557e68 100644 (file)
@@ -194,7 +194,7 @@ static void on_message(
   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);
index 1a6d114de6d87717c7ac74f86f83d4bc75f6f677..76078676c089be4f98a183dc47c975176219e138 100644 (file)
@@ -95,7 +95,7 @@ cmd_status_t cmd_parse_putval(size_t argc, char **argv,
   }
 
   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",
index 7562a243a06f68b08b0bd917558f870b0bcbcb6b..3b1d5dd5e34279ac99ee79dc8d5a888feb3f4d3f 100644 (file)
@@ -972,8 +972,8 @@ int parse_identifier(char *str, char **ret_host, char **ret_plugin,
   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;
 
@@ -995,6 +995,13 @@ int parse_identifier_vl(const char *str, value_list_t *vl) /* {{{ */
     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;
index 1cb0df7642b9cec8baf12faecb081dcdb016982b..16cfd076e6f6d832d8027fb416c630d592c97912 100644 (file)
@@ -328,7 +328,20 @@ int format_values(strbuf_t *buf, metric_t const *m, bool store_rates);
 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);