summaryrefslogtreecommitdiff
path: root/ot_http.c
diff options
context:
space:
mode:
authorerdgeist <>2007-12-05 01:40:24 +0000
committererdgeist <>2007-12-05 01:40:24 +0000
commitbee364a6f33694b4d58f29f0de5ad630d392a031 (patch)
treefb5c9355bb0e7bbccc3b8288dfadfdbd275e7bc0 /ot_http.c
parent31d876d53dfdafc4370b7c23febbb6978b271a77 (diff)
/ can now be redirected to any URL
Diffstat (limited to 'ot_http.c')
-rw-r--r--ot_http.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/ot_http.c b/ot_http.c
index 4fbde78..cb517bb 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -32,6 +32,7 @@
32 32
33#define OT_MAXMULTISCRAPE_COUNT 64 33#define OT_MAXMULTISCRAPE_COUNT 64
34static ot_hash multiscrape_buf[OT_MAXMULTISCRAPE_COUNT]; 34static ot_hash multiscrape_buf[OT_MAXMULTISCRAPE_COUNT];
35extern char *g_redirecturl;
35 36
36enum { 37enum {
37 SUCCESS_HTTP_HEADER_LENGTH = 80, 38 SUCCESS_HTTP_HEADER_LENGTH = 80,
@@ -79,6 +80,7 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size
79 } 80 }
80} 81}
81 82
83#define HTTPERROR_302 return http_issue_error( client_socket, CODE_HTTPERROR_302 )
82#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 ) 84#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
83#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM ) 85#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, CODE_HTTPERROR_400_COMPACT ) 86#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
@@ -86,13 +88,16 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size
86#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 ) 88#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
87#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 ) 89#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
88ssize_t http_issue_error( const int64 client_socket, int code ) { 90ssize_t http_issue_error( const int64 client_socket, int code ) {
89 char *error_code[] = { "400 Invalid Request", "400 Invalid Request", "400 Invalid Request", 91 char *error_code[] = { "302 Found", "400 Invalid Request", "400 Invalid Request", "400 Invalid Request",
90 "403 Access Denied", "404 Not Found", "500 Internal Server Error" }; 92 "403 Access Denied", "404 Not Found", "500 Internal Server Error" };
91 char *title = error_code[code]; 93 char *title = error_code[code];
94 size_t reply_size;
95
96 if( code == CODE_HTTPERROR_302 )
97 reply_size = sprintf( static_outbuf, "HTTP/1.0 302 Found\r\nContent-Length: 0\r\nLocation: %s\r\n\r\n", g_redirecturl );
98 else
99 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<title>%s</title>\n", title, strlen(title)+16-4,title+4);
92 100
93 size_t reply_size = sprintf( static_outbuf,
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",
95 title, 2*strlen(title)+16-4,title+4);
96#ifdef _DEBUG_HTTPERROR 101#ifdef _DEBUG_HTTPERROR
97 fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request ); 102 fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request );
98#endif 103#endif
@@ -506,6 +511,7 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
506 len = scan_urlencoded_query( &c, data = c, SCAN_PATH ); 511 len = scan_urlencoded_query( &c, data = c, SCAN_PATH );
507 512
508 /* If parsing returned an error, leave with not found*/ 513 /* If parsing returned an error, leave with not found*/
514 if( g_redirecturl && ( len == -2 ) ) HTTPERROR_302;
509 if( len <= 0 ) HTTPERROR_404; 515 if( len <= 0 ) HTTPERROR_404;
510 516
511 /* This is the hardcore match for announce*/ 517 /* This is the hardcore match for announce*/