summaryrefslogtreecommitdiff
path: root/src/stats.c
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@banu.com>2008-12-01 15:01:11 +0000
committerMukund Sivaraman <muks@banu.com>2008-12-01 15:01:11 +0000
commita257703e59163b4f38c38f549179b8e45ac68c63 (patch)
treed056783c13f4adb25c133899f5d750a2b7123a2f /src/stats.c
parent448c19077c195fafd244539eeb5315773261fcaf (diff)
downloadtinyproxy-a257703e59163b4f38c38f549179b8e45ac68c63.tar.gz
tinyproxy-a257703e59163b4f38c38f549179b8e45ac68c63.zip
Reformat code to GNU coding style
This is a commit which simply ran all C source code files through GNU indent. No other modifications were made.
Diffstat (limited to '')
-rw-r--r--src/stats.c195
1 files changed, 98 insertions, 97 deletions
diff --git a/src/stats.c b/src/stats.c
index 1b958ce..25a053d 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -33,12 +33,13 @@
#include "stats.h"
#include "utils.h"
-struct stat_s {
- unsigned long int num_reqs;
- unsigned long int num_badcons;
- unsigned long int num_open;
- unsigned long int num_refused;
- unsigned long int num_denied;
+struct stat_s
+{
+ unsigned long int num_reqs;
+ unsigned long int num_badcons;
+ unsigned long int num_open;
+ unsigned long int num_refused;
+ unsigned long int num_denied;
};
static struct stat_s *stats;
@@ -47,83 +48,82 @@ static struct stat_s *stats;
* Initialize the statistics information to zero.
*/
void
-init_stats(void)
+init_stats (void)
{
- stats = malloc_shared_memory(sizeof(struct stat_s));
- if (stats == MAP_FAILED)
- return;
+ stats = malloc_shared_memory (sizeof (struct stat_s));
+ if (stats == MAP_FAILED)
+ return;
- memset(stats, 0, sizeof(struct stat_s));
+ memset (stats, 0, sizeof (struct stat_s));
}
/*
* Display the statics of the tinyproxy server.
*/
int
-showstats(struct conn_s *connptr)
+showstats (struct conn_s *connptr)
{
- static char *msg =
- "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
- "<html>\n"
- "<head><title>%s version %s run-time statistics</title></head>\n"
- "<body>\n"
- "<h1>%s version %s run-time statistics</h1>\n"
- "<p>\n"
- "Number of open connections: %lu<br />\n"
- "Number of requests: %lu<br />\n"
- "Number of bad connections: %lu<br />\n"
- "Number of denied connections: %lu<br />\n"
- "Number of refused connections due to high load: %lu\n"
- "</p>\n"
- "<hr />\n"
- "<p><em>Generated by %s version %s.</em></p>\n"
- "</body>\n"
- "</html>\n";
-
- char *message_buffer;
- char opens[16], reqs[16], badconns[16], denied[16], refused[16];
- FILE *statfile;
-
- snprintf(opens, sizeof(opens), "%lu", stats->num_open);
- snprintf(reqs, sizeof(reqs), "%lu", stats->num_reqs);
- snprintf(badconns, sizeof(badconns), "%lu", stats->num_badcons);
- snprintf(denied, sizeof(denied), "%lu", stats->num_denied);
- snprintf(refused, sizeof(refused), "%lu", stats->num_refused);
-
- if (!config.statpage || (!(statfile = fopen(config.statpage, "r")))) {
- message_buffer = safemalloc(MAXBUFFSIZE);
- if (!message_buffer)
- return -1;
-
- snprintf(message_buffer, MAXBUFFSIZE, msg,
- PACKAGE, VERSION, PACKAGE, VERSION,
- stats->num_open,
- stats->num_reqs,
- stats->num_badcons, stats->num_denied,
- stats->num_refused,
- PACKAGE, VERSION);
-
- if (send_http_message(connptr, 200, "OK", message_buffer) < 0) {
- safefree(message_buffer);
- return -1;
- }
-
- safefree(message_buffer);
- return 0;
- }
-
- add_error_variable(connptr, "opens", opens);
- add_error_variable(connptr, "reqs", reqs);
- add_error_variable(connptr, "badconns", badconns);
- add_error_variable(connptr, "deniedconns", denied);
- add_error_variable(connptr, "refusedconns", refused);
- add_standard_vars(connptr);
- send_http_headers(connptr, 200, "Statistic requested");
- send_html_file(statfile, connptr);
- fclose(statfile);
-
- return 0;
+ static char *msg =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
+ "<html>\n"
+ "<head><title>%s version %s run-time statistics</title></head>\n"
+ "<body>\n"
+ "<h1>%s version %s run-time statistics</h1>\n"
+ "<p>\n"
+ "Number of open connections: %lu<br />\n"
+ "Number of requests: %lu<br />\n"
+ "Number of bad connections: %lu<br />\n"
+ "Number of denied connections: %lu<br />\n"
+ "Number of refused connections due to high load: %lu\n"
+ "</p>\n"
+ "<hr />\n"
+ "<p><em>Generated by %s version %s.</em></p>\n" "</body>\n" "</html>\n";
+
+ char *message_buffer;
+ char opens[16], reqs[16], badconns[16], denied[16], refused[16];
+ FILE *statfile;
+
+ snprintf (opens, sizeof (opens), "%lu", stats->num_open);
+ snprintf (reqs, sizeof (reqs), "%lu", stats->num_reqs);
+ snprintf (badconns, sizeof (badconns), "%lu", stats->num_badcons);
+ snprintf (denied, sizeof (denied), "%lu", stats->num_denied);
+ snprintf (refused, sizeof (refused), "%lu", stats->num_refused);
+
+ if (!config.statpage || (!(statfile = fopen (config.statpage, "r"))))
+ {
+ message_buffer = safemalloc (MAXBUFFSIZE);
+ if (!message_buffer)
+ return -1;
+
+ snprintf (message_buffer, MAXBUFFSIZE, msg,
+ PACKAGE, VERSION, PACKAGE, VERSION,
+ stats->num_open,
+ stats->num_reqs,
+ stats->num_badcons, stats->num_denied,
+ stats->num_refused, PACKAGE, VERSION);
+
+ if (send_http_message (connptr, 200, "OK", message_buffer) < 0)
+ {
+ safefree (message_buffer);
+ return -1;
+ }
+
+ safefree (message_buffer);
+ return 0;
+ }
+
+ add_error_variable (connptr, "opens", opens);
+ add_error_variable (connptr, "reqs", reqs);
+ add_error_variable (connptr, "badconns", badconns);
+ add_error_variable (connptr, "deniedconns", denied);
+ add_error_variable (connptr, "refusedconns", refused);
+ add_standard_vars (connptr);
+ send_http_headers (connptr, 200, "Statistic requested");
+ send_html_file (statfile, connptr);
+ fclose (statfile);
+
+ return 0;
}
/*
@@ -131,28 +131,29 @@ showstats(struct conn_s *connptr)
* stats.h
*/
int
-update_stats(status_t update_level)
+update_stats (status_t update_level)
{
- switch (update_level) {
- case STAT_BADCONN:
- ++stats->num_badcons;
- break;
- case STAT_OPEN:
- ++stats->num_open;
- ++stats->num_reqs;
- break;
- case STAT_CLOSE:
- --stats->num_open;
- break;
- case STAT_REFUSE:
- ++stats->num_refused;
- break;
- case STAT_DENIED:
- ++stats->num_denied;
- break;
- default:
- return -1;
- }
-
- return 0;
+ switch (update_level)
+ {
+ case STAT_BADCONN:
+ ++stats->num_badcons;
+ break;
+ case STAT_OPEN:
+ ++stats->num_open;
+ ++stats->num_reqs;
+ break;
+ case STAT_CLOSE:
+ --stats->num_open;
+ break;
+ case STAT_REFUSE:
+ ++stats->num_refused;
+ break;
+ case STAT_DENIED:
+ ++stats->num_denied;
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
}