X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fteamspeak2.c;h=4d68f61f0ee4f21865e2573452a7318de10cb1b5;hp=960d6464f694fe005b08628cfde2d7e68bccc132;hb=1159cb5d383c55a80a0db100b8f7aadcf44740a5;hpb=e4504c3cc5582ab915903e1b4ba010545ffc8354 diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 960d6464..4d68f61f 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -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, @@ -182,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 */ @@ -195,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 */ @@ -231,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"); @@ -240,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"); @@ -249,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. */ @@ -270,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!"); } @@ -280,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) { @@ -293,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) { @@ -316,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, @@ -333,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, @@ -373,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) { @@ -387,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; @@ -418,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); @@ -426,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) { @@ -455,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) { @@ -463,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 */ @@ -616,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) { @@ -630,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; @@ -640,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; @@ -650,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; @@ -690,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) { @@ -716,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) { @@ -728,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 : */