Line data Source code
1 : #include "http_minipot_session_respond.h" 2 : #include <minipot_utils.h> 3 : #include <stdlib.h> 4 : #include "http_minipot_session_utils.h" 5 : #include "log.h" 6 : 7 : #define URI_TOO_LONG_PART1 "HTTP/1.1 414 Request-URI Too Long\r\nDate: " 8 : // IMPORTANT - when changing length of the body - the Content-Length header value MUST BE changed accordingly !!! 9 : #define URI_TOO_LONG_PART2 "\r\nServer: Apache/2.4\r\nContent-Length: 254\r\n\ 10 : Connection: close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n\ 11 : <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>414 Request-URI Too Long</title>\n\ 12 : </head><body>\n<h1>Request-URI Too Long</h1>\n<p>The requested URL\'s length exceeds the capacity\nlimit for this server.<br />\n</p>\n<hr>\n</body></html>\n" 13 : 14 : #define BAD_REQ_PART1 "HTTP/1.1 400 Bad Request\r\nDate: " 15 : // IMPORTANT - when changing length of the body - the Content-Length header value MUST BE changed accordingly !!! 16 : #define BAD_REQ_PART2 "\r\nServer: Apache/2.4\r\nContent-Length: 231\r\nConnection: close\r\n\ 17 : Content-Type: text/html; charset=iso-8859-1\r\n\r\n\ 18 : <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>400 Bad Request</title>\n\ 19 : </head><body>\n<h1>Bad Request</h1>\n<p>Your browser sent a request that this server could not understand.<br />\n</p>\n<hr>\n</body></html>\n" 20 : 21 : #define UNAUTH_REQ_PART1 "HTTP/1.1 401 Unauthorized\r\nDate: " 22 : // IMPORTANT - when changing length of the body - the Content-Length header value MUST BE changed accordingly !!! 23 : #define UNAUTH_REQ_PART2 "\r\nServer: Apache/2.4\r\nWWW-Authenticate: Basic realm=\"Authentication Required\"\r\n\ 24 : Content-Length: 386\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n\ 25 : <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>401 Unauthorized</title>\n</head><body>\n<h1>Unauthorized</h1>\n<p>\ 26 : This server could not verify that you\nare authorized to access the document\nrequested. Either you supplied the wrong\n\ 27 : credentials (e.g., bad password), or your\nbrowser doesn\'t understand how to supply\nthe credentials required.</p>\n<hr>\n</body></html>\n" 28 : 29 0 : int http_send_bad_req(struct http_minipot_session *s) { 30 0 : MINIPOT_TRACE_FUNC_FD(s->parent.fd); 31 0 : char *time_str = time2str(time(NULL)); 32 0 : char *mesg = NULL; 33 0 : asprintf(&mesg, "%s%s%s", BAD_REQ_PART1, time_str, BAD_REQ_PART2); 34 0 : int ret = minipot_send_all(s->parent.fd, mesg, strlen(mesg)); 35 0 : free(time_str); 36 0 : free(mesg); 37 0 : return ret; 38 : } 39 : 40 0 : int http_send_uri_too_long(struct http_minipot_session *s) { 41 0 : MINIPOT_TRACE_FUNC_FD(s->parent.fd); 42 0 : char *time_str = time2str(time(NULL)); 43 0 : char *mesg = NULL; 44 0 : asprintf(&mesg, "%s%s%s", URI_TOO_LONG_PART1, time_str, URI_TOO_LONG_PART2); 45 0 : int ret = minipot_send_all(s->parent.fd, mesg, strlen(mesg)); 46 0 : free(time_str); 47 0 : free(mesg); 48 0 : return ret; 49 : } 50 : 51 0 : int http_send_unauth(struct http_minipot_session *s) { 52 0 : MINIPOT_TRACE_FUNC_FD(s->parent.fd); 53 0 : char *time_str = time2str(time(NULL)); 54 0 : char *mesg = NULL; 55 0 : asprintf(&mesg, "%s%s%s", UNAUTH_REQ_PART1, time_str, UNAUTH_REQ_PART2); 56 0 : int ret = minipot_send_all(s->parent.fd, mesg, strlen(mesg)); 57 0 : free(time_str); 58 0 : free(mesg); 59 0 : return ret; 60 : }