int port;
struct vserver_list_s *next;
} vserver_list_t;
-static vserver_list_t *server_list = NULL;
+static vserver_list_t *server_list;
/* Host data */
-static char *config_host = NULL;
-static char *config_port = NULL;
+static char *config_host;
+static char *config_port;
-static FILE *global_read_fh = NULL;
-static FILE *global_write_fh = NULL;
+static FILE *global_read_fh;
+static FILE *global_write_fh;
/* Config data */
static const char *config_keys[] = {"Host", "Port", "Server"};
/* 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 */
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,
*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 */
&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 */
/* Create socket */
sd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (sd < 0) {
- char errbuf[1024];
- WARNING("teamspeak2 plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("teamspeak2 plugin: socket failed: %s", STRERRNO);
continue;
}
/* Try to connect */
status = connect(sd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- char errbuf[1024];
- WARNING("teamspeak2 plugin: connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ WARNING("teamspeak2 plugin: connect failed: %s", STRERRNO);
close(sd);
sd = -1;
continue;
/* Check if we really got connected */
if (sd < 0)
- return (-1);
+ return -1;
/* Create file objects from sockets */
global_read_fh = fdopen(sd, "r");
if (global_read_fh == NULL) {
- char errbuf[1024];
- ERROR("teamspeak2 plugin: fdopen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("teamspeak2 plugin: fdopen failed: %s", STRERRNO);
close(sd);
- return (-1);
+ return -1;
}
global_write_fh = fdopen(sd, "w");
if (global_write_fh == NULL) {
- char errbuf[1024];
- ERROR("teamspeak2 plugin: fdopen failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("teamspeak2 plugin: fdopen failed: %s", STRERRNO);
tss2_close_socket();
- return (-1);
+ return -1;
}
{ /* Check that the server correctly identifies itself. */
"to server. Expected ``[TS]'', got ``%s''.",
buffer);
tss2_close_socket();
- return (-1);
+ return -1;
}
DEBUG("teamspeak2 plugin: Server send correct banner, connected!");
}
*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) {
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) {
*/
temp = fgets(buffer, buffer_size, fh);
if (temp == NULL) {
- char errbuf[1024];
- ERROR("teamspeak2 plugin: fgets failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("teamspeak2 plugin: fgets failed: %s", STRERRNO);
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,
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,
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) {
read_fh = NULL;
write_fh = NULL;
ERROR("teamspeak2 plugin: tss2_receive_line failed.");
- return (-1);
+ return -1;
}
buffer[sizeof(buffer) - 1] = 0;
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);
}
*ret_value = packet_loss;
- return (0);
+ return 0;
} /* int tss2_vserver_gapl */
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) {
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 */
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) {
temp = strdup(value);
if (temp == NULL) {
ERROR("teamspeak2 plugin: strdup failed.");
- return (1);
+ return 1;
}
sfree(config_host);
config_host = temp;
temp = strdup(value);
if (temp == NULL) {
ERROR("teamspeak2 plugin: strdup failed.");
- return (1);
+ return 1;
}
sfree(config_port);
config_port = temp;
status = tss2_add_vserver(atoi(value));
if (status != 0)
- return (1);
+ return 1;
} else {
/* Unknown variable found */
- return (-1);
+ return -1;
}
return 0;
}
if (success == 0)
- return (-1);
- return (0);
+ return -1;
+ return 0;
} /* int tss2_read */
static int tss2_shutdown(void) {
sfree(config_host);
sfree(config_port);
- return (0);
+ return 0;
} /* int tss2_shutdown */
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 : */