From 31d876d53dfdafc4370b7c23febbb6978b271a77 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 4 Dec 2007 23:57:29 +0000 Subject: Count invalid requests --- ot_http.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'ot_http.c') diff --git a/ot_http.c b/ot_http.c index aad29f6..4fbde78 100644 --- a/ot_http.c +++ b/ot_http.c @@ -79,19 +79,24 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size } } -#define HTTPERROR_400 return http_issue_error( client_socket, "400 Invalid Request", "This server only understands GET." ) -#define HTTPERROR_400_PARAM return http_issue_error( client_socket, "400 Invalid Request", "Invalid parameter" ) -#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, "400 Invalid Request", "This server only delivers compact results." ) -#define HTTPERROR_403_IP return http_issue_error( client_socket, "403 Access Denied", "Your ip address is not allowed to administrate this server." ) -#define HTTPERROR_404 return http_issue_error( client_socket, "404 Not Found", "No such file or directory." ) -#define HTTPERROR_500 return http_issue_error( client_socket, "500 Internal Server Error", "A server error has occured. Please retry later." ) -ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) { +#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 ) +#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM ) +#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT ) +#define HTTPERROR_403_IP return http_issue_error( client_socket, CODE_HTTPERROR_403_IP ) +#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 ) +#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 ) +ssize_t http_issue_error( const int64 client_socket, int code ) { + char *error_code[] = { "400 Invalid Request", "400 Invalid Request", "400 Invalid Request", + "403 Access Denied", "404 Not Found", "500 Internal Server Error" }; + char *title = error_code[code]; + size_t reply_size = sprintf( static_outbuf, "HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n