summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
authorerdgeist <>2007-12-04 23:57:29 +0000
committererdgeist <>2007-12-04 23:57:29 +0000
commit31d876d53dfdafc4370b7c23febbb6978b271a77 (patch)
tree8ccc3959e75f5e61c5bf4acd6f96367c8793afca /ot_http.c
parenta146a328856a1f8b5099064f0262a34d5623021b (diff)
Count invalid requests
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c25
1 files changed, 16 insertions, 9 deletions
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
79 } 79 }
80} 80}
81 81
82#define HTTPERROR_400 return http_issue_error( client_socket, "400 Invalid Request", "This server only understands GET." ) 82#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
83#define HTTPERROR_400_PARAM return http_issue_error( client_socket, "400 Invalid Request", "Invalid parameter" ) 83#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM )
84#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, "400 Invalid Request", "This server only delivers compact results." ) 84#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
85#define HTTPERROR_403_IP return http_issue_error( client_socket, "403 Access Denied", "Your ip address is not allowed to administrate this server." ) 85#define HTTPERROR_403_IP return http_issue_error( client_socket, CODE_HTTPERROR_403_IP )
86#define HTTPERROR_404 return http_issue_error( client_socket, "404 Not Found", "No such file or directory." ) 86#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
87#define HTTPERROR_500 return http_issue_error( client_socket, "500 Internal Server Error", "A server error has occured. Please retry later." ) 87#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
88ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) { 88ssize_t http_issue_error( const int64 client_socket, int code ) {
89 char *error_code[] = { "400 Invalid Request", "400 Invalid Request", "400 Invalid Request",
90 "403 Access Denied", "404 Not Found", "500 Internal Server Error" };
91 char *title = error_code[code];
92
89 size_t reply_size = sprintf( static_outbuf, 93 size_t reply_size = sprintf( static_outbuf,
90 "HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n", 94 "HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n",
91 title, strlen(message)+strlen(title)+16-4,title+4); 95 title, 2*strlen(title)+16-4,title+4);
92#ifdef _DEBUG_HTTPERROR 96#ifdef _DEBUG_HTTPERROR
93 fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request ); 97 fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request );
94#endif 98#endif
99 stats_issue_event( EVENT_FAILED, 1, code );
95 http_senddata( client_socket, static_outbuf, reply_size); 100 http_senddata( client_socket, static_outbuf, reply_size);
96 return -2; 101 return -2;
97} 102}
@@ -237,6 +242,8 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
237 mode = TASK_STATS_SLASH24S; 242 mode = TASK_STATS_SLASH24S;
238 else if( !byte_diff(data,4,"tpbs")) 243 else if( !byte_diff(data,4,"tpbs"))
239 mode = TASK_STATS_TPB; 244 mode = TASK_STATS_TPB;
245 else if( !byte_diff(data,4,"herr"))
246 mode = TASK_STATS_HTTPERRORS;
240 else 247 else
241 HTTPERROR_400_PARAM; 248 HTTPERROR_400_PARAM;
242 break; 249 break;
@@ -518,7 +525,7 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
518 break; 525 break;
519#endif 526#endif
520 case 5: /* stats ? */ 527 case 5: /* stats ? */
521 if( byte_diff(data,5,"stats")) HTTPERROR_404; 528 if( byte_diff( data, 5, "stats") ) HTTPERROR_404;
522 reply_size = http_handle_stats( client_socket, c, recv_header, recv_length ); 529 reply_size = http_handle_stats( client_socket, c, recv_header, recv_length );
523 break; 530 break;
524 default: 531 default: