Merge branch 'collectd-5.7' into collectd-5.8
[collectd.git] / src / teamspeak2.c
index 5b583b8..4d68f61 100644 (file)
@@ -71,14 +71,14 @@ static int tss2_add_vserver(int vserver_port) {
   /* Check port range */
   if ((vserver_port <= 0) || (vserver_port > 65535)) {
     ERROR("teamspeak2 plugin: VServer port is invalid: %i", vserver_port);
-    return (-1);
+    return -1;
   }
 
   /* Allocate memory */
   entry = calloc(1, sizeof(*entry));
   if (entry == NULL) {
     ERROR("teamspeak2 plugin: calloc failed.");
-    return (-1);
+    return -1;
   }
 
   /* Save data */
@@ -100,7 +100,7 @@ static int tss2_add_vserver(int vserver_port) {
 
   INFO("teamspeak2 plugin: Registered new vserver: %i", vserver_port);
 
-  return (0);
+  return 0;
 } /* int tss2_add_vserver */
 
 static void tss2_submit_gauge(const char *plugin_instance, const char *type,
@@ -108,14 +108,10 @@ static void tss2_submit_gauge(const char *plugin_instance, const char *type,
   /*
    * Submits a gauge value to the collectd daemon
    */
-  value_t values[1];
   value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].gauge = value;
-
-  vl.values = values;
+  vl.values = &(value_t){.gauge = value};
   vl.values_len = 1;
-  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
   sstrncpy(vl.plugin, "teamspeak2", sizeof(vl.plugin));
 
   if (plugin_instance != NULL)
@@ -134,15 +130,13 @@ static void tss2_submit_io(const char *plugin_instance, const char *type,
   /*
    * Submits the io rx/tx tuple to the collectd daemon
    */
-  value_t values[2];
   value_list_t vl = VALUE_LIST_INIT;
-
-  values[0].derive = rx;
-  values[1].derive = tx;
+  value_t values[] = {
+      {.derive = rx}, {.derive = tx},
+  };
 
   vl.values = values;
-  vl.values_len = 2;
-  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
+  vl.values_len = STATIC_ARRAY_SIZE(values);
   sstrncpy(vl.plugin, "teamspeak2", sizeof(vl.plugin));
 
   if (plugin_instance != NULL)
@@ -188,7 +182,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
       *ret_read_fh = global_read_fh;
     if (ret_write_fh != NULL)
       *ret_write_fh = global_write_fh;
-    return (0);
+    return 0;
   }
 
   /* Get all addrs for this hostname */
@@ -201,7 +195,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
                        &ai_hints, &ai_head);
   if (status != 0) {
     ERROR("teamspeak2 plugin: getaddrinfo failed: %s", gai_strerror(status));
-    return (-1);
+    return -1;
   }
 
   /* Try all given hosts until we can connect to one */
@@ -237,7 +231,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
 
   /* Check if we really got connected */
   if (sd < 0)
-    return (-1);
+    return -1;
 
   /* Create file objects from sockets */
   global_read_fh = fdopen(sd, "r");
@@ -246,7 +240,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
     ERROR("teamspeak2 plugin: fdopen failed: %s",
           sstrerror(errno, errbuf, sizeof(errbuf)));
     close(sd);
-    return (-1);
+    return -1;
   }
 
   global_write_fh = fdopen(sd, "w");
@@ -255,7 +249,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
     ERROR("teamspeak2 plugin: fdopen failed: %s",
           sstrerror(errno, errbuf, sizeof(errbuf)));
     tss2_close_socket();
-    return (-1);
+    return -1;
   }
 
   { /* Check that the server correctly identifies itself. */
@@ -276,7 +270,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
             "to server. Expected ``[TS]'', got ``%s''.",
             buffer);
       tss2_close_socket();
-      return (-1);
+      return -1;
     }
     DEBUG("teamspeak2 plugin: Server send correct banner, connected!");
   }
@@ -286,7 +280,7 @@ static int tss2_get_socket(FILE **ret_read_fh, FILE **ret_write_fh) {
     *ret_read_fh = global_read_fh;
   if (ret_write_fh != NULL)
     *ret_write_fh = global_write_fh;
-  return (0);
+  return 0;
 } /* int tss2_get_socket */
 
 static int tss2_send_request(FILE *fh, const char *request) {
@@ -299,11 +293,11 @@ static int tss2_send_request(FILE *fh, const char *request) {
   if (status < 0) {
     ERROR("teamspeak2 plugin: fputs failed.");
     tss2_close_socket();
-    return (-1);
+    return -1;
   }
   fflush(fh);
 
-  return (0);
+  return 0;
 } /* int tss2_send_request */
 
 static int tss2_receive_line(FILE *fh, char *buffer, int buffer_size) {
@@ -322,11 +316,11 @@ static int tss2_receive_line(FILE *fh, char *buffer, int buffer_size) {
     ERROR("teamspeak2 plugin: fgets failed: %s",
           sstrerror(errno, errbuf, sizeof(errbuf)));
     tss2_close_socket();
-    return (-1);
+    return -1;
   }
 
   buffer[buffer_size - 1] = 0;
-  return (0);
+  return 0;
 } /* int tss2_receive_line */
 
 static int tss2_select_vserver(FILE *read_fh, FILE *write_fh,
@@ -339,31 +333,31 @@ static int tss2_select_vserver(FILE *read_fh, FILE *write_fh,
   int status;
 
   /* Send request */
-  ssnprintf(command, sizeof(command), "sel %i\r\n", vserver->port);
+  snprintf(command, sizeof(command), "sel %i\r\n", vserver->port);
 
   status = tss2_send_request(write_fh, command);
   if (status != 0) {
     ERROR("teamspeak2 plugin: tss2_send_request (%s) failed.", command);
-    return (-1);
+    return -1;
   }
 
   /* Get answer */
   status = tss2_receive_line(read_fh, response, sizeof(response));
   if (status != 0) {
     ERROR("teamspeak2 plugin: tss2_receive_line failed.");
-    return (-1);
+    return -1;
   }
   response[sizeof(response) - 1] = 0;
 
   /* Check answer */
   if ((strncasecmp("OK", response, 2) == 0) &&
       ((response[2] == 0) || (response[2] == '\n') || (response[2] == '\r')))
-    return (0);
+    return 0;
 
   ERROR("teamspeak2 plugin: Command ``%s'' failed. "
         "Response received from server was: ``%s''.",
         command, response);
-  return (-1);
+  return -1;
 } /* int tss2_select_vserver */
 
 static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
@@ -379,7 +373,7 @@ static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
   status = tss2_send_request(write_fh, "gapl\r\n");
   if (status != 0) {
     ERROR("teamspeak2 plugin: tss2_send_request (gapl) failed.");
-    return (-1);
+    return -1;
   }
 
   while (42) {
@@ -393,7 +387,7 @@ static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
       read_fh = NULL;
       write_fh = NULL;
       ERROR("teamspeak2 plugin: tss2_receive_line failed.");
-      return (-1);
+      return -1;
     }
     buffer[sizeof(buffer) - 1] = 0;
 
@@ -424,7 +418,7 @@ static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
       break;
     } else if (strncasecmp("ERROR", buffer, 5) == 0) {
       ERROR("teamspeak2 plugin: Server returned an error: %s", buffer);
-      return (-1);
+      return -1;
     } else {
       WARNING("teamspeak2 plugin: Server returned unexpected string: %s",
               buffer);
@@ -432,7 +426,7 @@ static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
   }
 
   *ret_value = packet_loss;
-  return (0);
+  return 0;
 } /* int tss2_vserver_gapl */
 
 static int tss2_read_vserver(vserver_list_t *vserver) {
@@ -461,7 +455,7 @@ static int tss2_read_vserver(vserver_list_t *vserver) {
   status = tss2_get_socket(&read_fh, &write_fh);
   if (status != 0) {
     ERROR("teamspeak2 plugin: tss2_get_socket failed.");
-    return (-1);
+    return -1;
   }
 
   if (vserver == NULL) {
@@ -469,20 +463,20 @@ static int tss2_read_vserver(vserver_list_t *vserver) {
     status = tss2_send_request(write_fh, "gi\r\n");
   } else {
     /* Request server information */
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "vserver%i",
-              vserver->port);
+    snprintf(plugin_instance, sizeof(plugin_instance), "vserver%i",
+             vserver->port);
 
     /* Select the server */
     status = tss2_select_vserver(read_fh, write_fh, vserver);
     if (status != 0)
-      return (status);
+      return status;
 
     status = tss2_send_request(write_fh, "si\r\n");
   }
 
   if (status != 0) {
     ERROR("teamspeak2 plugin: tss2_send_request failed.");
-    return (-1);
+    return -1;
   }
 
   /* Loop until break */
@@ -622,8 +616,8 @@ static int tss2_read_vserver(vserver_list_t *vserver) {
     tss2_submit_gauge(plugin_instance, "gauge", "servers", servers);
 
   if (valid == 0)
-    return (-1);
-  return (0);
+    return -1;
+  return 0;
 } /* int tss2_read_vserver */
 
 static int tss2_config(const char *key, const char *value) {
@@ -636,7 +630,7 @@ static int tss2_config(const char *key, const char *value) {
     temp = strdup(value);
     if (temp == NULL) {
       ERROR("teamspeak2 plugin: strdup failed.");
-      return (1);
+      return 1;
     }
     sfree(config_host);
     config_host = temp;
@@ -646,7 +640,7 @@ static int tss2_config(const char *key, const char *value) {
     temp = strdup(value);
     if (temp == NULL) {
       ERROR("teamspeak2 plugin: strdup failed.");
-      return (1);
+      return 1;
     }
     sfree(config_port);
     config_port = temp;
@@ -656,10 +650,10 @@ static int tss2_config(const char *key, const char *value) {
 
     status = tss2_add_vserver(atoi(value));
     if (status != 0)
-      return (1);
+      return 1;
   } else {
     /* Unknown variable found */
-    return (-1);
+    return -1;
   }
 
   return 0;
@@ -696,8 +690,8 @@ static int tss2_read(void) {
   }
 
   if (success == 0)
-    return (-1);
-  return (0);
+    return -1;
+  return 0;
 } /* int tss2_read */
 
 static int tss2_shutdown(void) {
@@ -722,7 +716,7 @@ static int tss2_shutdown(void) {
   sfree(config_host);
   sfree(config_port);
 
-  return (0);
+  return 0;
 } /* int tss2_shutdown */
 
 void module_register(void) {
@@ -734,5 +728,3 @@ void module_register(void) {
   plugin_register_read("teamspeak2", tss2_read);
   plugin_register_shutdown("teamspeak2", tss2_shutdown);
 } /* void module_register */
-
-/* vim: set sw=4 ts=4 : */