diff options
Diffstat (limited to 'sapi')
-rw-r--r-- | sapi/cgi/cgi_main.c | 57 | ||||
-rw-r--r-- | sapi/cli/php_cli_server.c | 62 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_main.c | 58 |
3 files changed, 15 insertions, 162 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 283090d977..2bc7b047e5 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -69,6 +69,7 @@ #include "php_globals.h" #include "php_main.h" #include "fopen_wrappers.h" +#include "http_status_codes.h" #include "ext/standard/php_standard.h" #include "ext/standard/url.h" @@ -353,56 +354,6 @@ static void sapi_fcgi_flush(void *server_context) #define SAPI_CGI_MAX_HEADER_LENGTH 1024 -typedef struct _http_error { - int code; - const char* msg; -} http_error; - -static const http_error http_error_codes[] = { - {100, "Continue"}, - {101, "Switching Protocols"}, - {200, "OK"}, - {201, "Created"}, - {202, "Accepted"}, - {203, "Non-Authoritative Information"}, - {204, "No Content"}, - {205, "Reset Content"}, - {206, "Partial Content"}, - {300, "Multiple Choices"}, - {301, "Moved Permanently"}, - {302, "Moved Temporarily"}, - {303, "See Other"}, - {304, "Not Modified"}, - {305, "Use Proxy"}, - {400, "Bad Request"}, - {401, "Unauthorized"}, - {402, "Payment Required"}, - {403, "Forbidden"}, - {404, "Not Found"}, - {405, "Method Not Allowed"}, - {406, "Not Acceptable"}, - {407, "Proxy Authentication Required"}, - {408, "Request Time-out"}, - {409, "Conflict"}, - {410, "Gone"}, - {411, "Length Required"}, - {412, "Precondition Failed"}, - {413, "Request Entity Too Large"}, - {414, "Request-URI Too Large"}, - {415, "Unsupported Media Type"}, - {428, "Precondition Required"}, - {429, "Too Many Requests"}, - {431, "Request Header Fields Too Large"}, - {500, "Internal Server Error"}, - {501, "Not Implemented"}, - {502, "Bad Gateway"}, - {503, "Service Unavailable"}, - {504, "Gateway Time-out"}, - {505, "HTTP Version not supported"}, - {511, "Network Authentication Required"}, - {0, NULL} -}; - static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) { char buf[SAPI_CGI_MAX_HEADER_LENGTH]; @@ -453,7 +404,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos); } if (!has_status) { - http_error *err = (http_error*)http_error_codes; + http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map; while (err->code != 0) { if (err->code == SG(sapi_headers).http_response_code) { @@ -461,8 +412,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) } err++; } - if (err->msg) { - len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg); + if (err->str) { + len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str); } else { len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code); } diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index da690577d1..143d433d54 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -68,6 +68,7 @@ #include "zend_hash.h" #include "zend_modules.h" #include "fopen_wrappers.h" +#include "http_status_codes.h" #include "zend_compile.h" #include "zend_execute.h" @@ -203,55 +204,6 @@ typedef struct php_cli_server_http_response_status_code_pair { const char *str; } php_cli_server_http_response_status_code_pair; -static php_cli_server_http_response_status_code_pair status_map[] = { - { 100, "Continue" }, - { 101, "Switching Protocols" }, - { 200, "OK" }, - { 201, "Created" }, - { 202, "Accepted" }, - { 203, "Non-Authoritative Information" }, - { 204, "No Content" }, - { 205, "Reset Content" }, - { 206, "Partial Content" }, - { 300, "Multiple Choices" }, - { 301, "Moved Permanently" }, - { 302, "Found" }, - { 303, "See Other" }, - { 304, "Not Modified" }, - { 305, "Use Proxy" }, - { 307, "Temporary Redirect" }, - { 308, "Permanent Redirect" }, - { 400, "Bad Request" }, - { 401, "Unauthorized" }, - { 402, "Payment Required" }, - { 403, "Forbidden" }, - { 404, "Not Found" }, - { 405, "Method Not Allowed" }, - { 406, "Not Acceptable" }, - { 407, "Proxy Authentication Required" }, - { 408, "Request Timeout" }, - { 409, "Conflict" }, - { 410, "Gone" }, - { 411, "Length Required" }, - { 412, "Precondition Failed" }, - { 413, "Request Entity Too Large" }, - { 414, "Request-URI Too Long" }, - { 415, "Unsupported Media Type" }, - { 416, "Requested Range Not Satisfiable" }, - { 417, "Expectation Failed" }, - { 426, "Upgrade Required" }, - { 428, "Precondition Required" }, - { 429, "Too Many Requests" }, - { 431, "Request Header Fields Too Large" }, - { 500, "Internal Server Error" }, - { 501, "Not Implemented" }, - { 502, "Bad Gateway" }, - { 503, "Service Unavailable" }, - { 504, "Gateway Timeout" }, - { 505, "HTTP Version Not Supported" }, - { 511, "Network Authentication Required" }, -}; - static php_cli_server_http_response_status_code_pair template_map[] = { { 400, "<h1>%s</h1><p>Your browser sent a request that this server could not understand.</p>" }, { 404, "<h1>%s</h1><p>The requested resource <code class=\"url\">%s</code> was not found on this server.</p>" }, @@ -324,8 +276,8 @@ static char *get_last_error() /* {{{ */ static int status_comp(const void *a, const void *b) /* {{{ */ { - const php_cli_server_http_response_status_code_pair *pa = (const php_cli_server_http_response_status_code_pair *) a; - const php_cli_server_http_response_status_code_pair *pb = (const php_cli_server_http_response_status_code_pair *) b; + const http_response_status_code_pair *pa = (const http_response_status_code_pair *) a; + const http_response_status_code_pair *pb = (const http_response_status_code_pair *) b; if (pa->code < pb->code) { return -1; @@ -338,12 +290,10 @@ static int status_comp(const void *a, const void *b) /* {{{ */ static const char *get_status_string(int code) /* {{{ */ { - php_cli_server_http_response_status_code_pair needle, *result = NULL; - - needle.code = code; - needle.str = NULL; + http_response_status_code_pair needle = {code, NULL}, + *result = NULL; - result = bsearch(&needle, status_map, sizeof(status_map) / sizeof(needle), sizeof(needle), status_comp); + result = bsearch(&needle, http_status_map, http_status_map_len, sizeof(needle), status_comp); if (result) { return result->str; diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 62846b6ba9..4f5e2da7af 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -97,6 +97,8 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS; #include "php_getopt.h" +#include "http_status_codes.h" + #include "fastcgi.h" #include <php_config.h> @@ -341,56 +343,6 @@ static void sapi_cgibin_flush(void *server_context) #define SAPI_CGI_MAX_HEADER_LENGTH 1024 -typedef struct _http_error { - int code; - const char* msg; -} http_error; - -static const http_error http_error_codes[] = { - {100, "Continue"}, - {101, "Switching Protocols"}, - {200, "OK"}, - {201, "Created"}, - {202, "Accepted"}, - {203, "Non-Authoritative Information"}, - {204, "No Content"}, - {205, "Reset Content"}, - {206, "Partial Content"}, - {300, "Multiple Choices"}, - {301, "Moved Permanently"}, - {302, "Moved Temporarily"}, - {303, "See Other"}, - {304, "Not Modified"}, - {305, "Use Proxy"}, - {400, "Bad Request"}, - {401, "Unauthorized"}, - {402, "Payment Required"}, - {403, "Forbidden"}, - {404, "Not Found"}, - {405, "Method Not Allowed"}, - {406, "Not Acceptable"}, - {407, "Proxy Authentication Required"}, - {408, "Request Time-out"}, - {409, "Conflict"}, - {410, "Gone"}, - {411, "Length Required"}, - {412, "Precondition Failed"}, - {413, "Request Entity Too Large"}, - {414, "Request-URI Too Large"}, - {415, "Unsupported Media Type"}, - {428, "Precondition Required"}, - {429, "Too Many Requests"}, - {431, "Request Header Fields Too Large"}, - {500, "Internal Server Error"}, - {501, "Not Implemented"}, - {502, "Bad Gateway"}, - {503, "Service Unavailable"}, - {504, "Gateway Time-out"}, - {505, "HTTP Version not supported"}, - {511, "Network Authentication Required"}, - {0, NULL} -}; - static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) { char buf[SAPI_CGI_MAX_HEADER_LENGTH]; @@ -441,7 +393,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos); } if (!has_status) { - http_error *err = (http_error*)http_error_codes; + http_response_status_code_pair *err = (http_response_status_code_pair*)http_status_map; while (err->code != 0) { if (err->code == SG(sapi_headers).http_response_code) { @@ -449,8 +401,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) } err++; } - if (err->msg) { - len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg); + if (err->str) { + len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->str); } else { len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code); } |