From 6357936028a407d891ab3a444ff745eb12c016b8 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 9 Aug 2002 14:15:08 +0000 Subject: [PATCH] Various cleanups for accounting of sent bytes. Crash bug in stats fixed. svn path=/trunk/icecast/; revision=3779 --- src/connection.c | 22 ++++++++++++++++------ src/stats.c | 1 - src/xslt.c | 14 ++++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/connection.c b/src/connection.c index 6faea842..e5933bbd 100644 --- a/src/connection.c +++ b/src/connection.c @@ -459,12 +459,14 @@ static void *_handle_connection(void *arg) /* If the file exists, then transform it, otherwise, write a 404 error */ if (stat(fullPath, &statbuf) == 0) { DEBUG0("Stats request, sending XSL transformed stats"); - sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"); + bytes = sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"); + if(bytes > 0) client->con->sent_bytes = bytes; stats_transform_xslt(client, fullPath); } else { - sock_write(client->con->sock, "HTTP/1.0 404 File Not Found\r\nContent-Type: text/html\r\n\r\n"\ + bytes = sock_write(client->con->sock, "HTTP/1.0 404 File Not Found\r\nContent-Type: text/html\r\n\r\n"\ "The file you requested could not be found.\r\n"); + if(bytes > 0) client->con->sent_bytes = bytes; } client_destroy(client); continue; @@ -486,7 +488,12 @@ static void *_handle_connection(void *arg) node = avl_get_first(global.source_tree); while (node) { s = (source_t *)node->key; - sock_write(client->con->sock, "%s\r\n", s->mount); + bytes = sock_write(client->con->sock, "%s\r\n", s->mount); + if(bytes > 0) + client->con->sent_bytes += bytes; + else + break; + node = avl_get_next(node); } avl_tree_unlock(global.source_tree); @@ -531,20 +538,23 @@ static void *_handle_connection(void *arg) if (parser->req_type == httpp_req_get) { client->respcode = 200; - sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: %s\r\n", format_get_mimetype(source->format->type)); + bytes = sock_write(client->con->sock, "HTTP/1.0 200 OK\r\nContent-Type: %s\r\n", format_get_mimetype(source->format->type)); + if(bytes > 0) client->con->sent_bytes += bytes; /* iterate through source http headers and send to client */ avl_tree_rlock(source->parser->vars); node = avl_get_first(source->parser->vars); while (node) { var = (http_var_t *)node->key; if (strcasecmp(var->name, "ice-password") && !strncasecmp("ice-", var->name, 4)) { - sock_write(client->con->sock, "%s: %s\r\n", var->name, var->value); + bytes = sock_write(client->con->sock, "%s: %s\r\n", var->name, var->value); + if(bytes > 0) client->con->sent_bytes += bytes; } node = avl_get_next(node); } avl_tree_unlock(source->parser->vars); - sock_write(client->con->sock, "\r\n"); + bytes = sock_write(client->con->sock, "\r\n"); + if(bytes > 0) client->con->sent_bytes += bytes; sock_set_blocking(client->con->sock, SOCK_NONBLOCK); } diff --git a/src/stats.c b/src/stats.c index 8e336a2b..befe565b 100644 --- a/src/stats.c +++ b/src/stats.c @@ -823,7 +823,6 @@ void stats_sendxml(client_t *client) src_nodes = snd; } if (buff) free(buff); - client_destroy(client); } static int _compare_stats(void *arg, void *a, void *b) diff --git a/src/xslt.c b/src/xslt.c index d9bbad91..8ecd1fea 100644 --- a/src/xslt.c +++ b/src/xslt.c @@ -32,7 +32,7 @@ void transformXSLT(xmlDocPtr doc, char *xslfilename, client_t *client) xmlDocPtr res; xsltStylesheetPtr cur; const char *params[16 + 1]; - size_t count,nBytes; + size_t count,bytes; params[0] = NULL; @@ -41,7 +41,10 @@ void transformXSLT(xmlDocPtr doc, char *xslfilename, client_t *client) cur = xsltParseStylesheetFile(xslfilename); if (cur == NULL) { - sock_write_string(client->con->sock, (char *)"Could not parse XSLT file"); + bytes = sock_write_string(client->con->sock, + (char *)"Could not parse XSLT file"); + if(bytes > 0) client->con->sent_bytes += bytes; + return; } @@ -52,9 +55,12 @@ void transformXSLT(xmlDocPtr doc, char *xslfilename, client_t *client) count = xsltSaveResultTo(outputBuffer, res, cur); /* Add null byte to end. */ - nBytes = xmlOutputBufferWrite(outputBuffer, 1, ""); + bytes = xmlOutputBufferWrite(outputBuffer, 1, ""); - sock_write_string(client->con->sock, (char *)outputBuffer->buffer->content); + if(sock_write_string(client->con->sock, + (char *)outputBuffer->buffer->content)) + client->con->sent_bytes += bytes; + xmlFree(outputBuffer); xsltFreeStylesheet(cur);