mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Merge branch 'master' into phpng
* master: (77 commits) NEWS entry for Fix potential segfault in dns_get_record() NEWS entry for "Fix potential segfault in dns_get_record()" NEWS entry for Fix potential segfault in dns_get_record( Fix potential segfault in dns_get_record() Revert "Add optional second arg to unserialize()" 5.5.15 now update NEWS Fix bug #66127 (Segmentation fault with ArrayObject unset) 5.4.31 next Add NEWS. This doesn't need UPGRADING (or an RFC), IMO. Fix broken test. Add a mime type map generation script and update the header. Move the mime type map out of php_cli_server.c for easier generation. Replace the CLI server's linear search for extensions with a hash table. fix test Remove unused included file NEWS NEWS NEWS Fixed Bug #67413 fileinfo: cdf_read_property_info insufficient boundary chec ... Conflicts: Zend/zend_closures.c Zend/zend_execute.c Zend/zend_vm_def.h Zend/zend_vm_execute.h ext/spl/spl_array.c ext/standard/basic_functions.c ext/standard/dns.c ext/standard/var.c
This commit is contained in:
commit
dd1c68e67f
74 changed files with 3228 additions and 3601 deletions
|
@ -104,6 +104,7 @@
|
|||
|
||||
#include "php_http_parser.h"
|
||||
#include "php_cli_server.h"
|
||||
#include "mime_type_map.h"
|
||||
|
||||
#include "php_cli_process_title.h"
|
||||
|
||||
|
@ -194,6 +195,7 @@ typedef struct php_cli_server {
|
|||
size_t router_len;
|
||||
socklen_t socklen;
|
||||
HashTable clients;
|
||||
HashTable extension_mime_types;
|
||||
} php_cli_server;
|
||||
|
||||
typedef struct php_cli_server_http_response_status_code_pair {
|
||||
|
@ -201,11 +203,6 @@ typedef struct php_cli_server_http_response_status_code_pair {
|
|||
const char *str;
|
||||
} php_cli_server_http_response_status_code_pair;
|
||||
|
||||
typedef struct php_cli_server_ext_mime_type_pair {
|
||||
const char *ext;
|
||||
const char *mime_type;
|
||||
} php_cli_server_ext_mime_type_pair;
|
||||
|
||||
static php_cli_server_http_response_status_code_pair status_map[] = {
|
||||
{ 100, "Continue" },
|
||||
{ 101, "Switching Protocols" },
|
||||
|
@ -260,64 +257,6 @@ static php_cli_server_http_response_status_code_pair template_map[] = {
|
|||
{ 501, "<h1>%s</h1><p>Request method not supported.</p>" }
|
||||
};
|
||||
|
||||
static php_cli_server_ext_mime_type_pair mime_type_map[] = {
|
||||
{ "html", "text/html" },
|
||||
{ "htm", "text/html" },
|
||||
{ "js", "text/javascript" },
|
||||
{ "css", "text/css" },
|
||||
{ "gif", "image/gif" },
|
||||
{ "jpg", "image/jpeg" },
|
||||
{ "jpeg", "image/jpeg" },
|
||||
{ "jpe", "image/jpeg" },
|
||||
{ "pdf", "application/pdf" },
|
||||
{ "png", "image/png" },
|
||||
{ "svg", "image/svg+xml" },
|
||||
{ "txt", "text/plain" },
|
||||
{ "webm", "video/webm" },
|
||||
{ "ogv", "video/ogg" },
|
||||
{ "ogg", "audio/ogg" },
|
||||
{ "3gp", "video/3gpp" }, /* This is standard video format used for MMS in phones */
|
||||
{ "apk", "application/vnd.android.package-archive" },
|
||||
{ "avi", "video/x-msvideo" },
|
||||
{ "bmp", "image/x-ms-bmp" },
|
||||
{ "csv", "text/comma-separated-values" },
|
||||
{ "doc", "application/msword" },
|
||||
{ "docx", "application/msword" },
|
||||
{ "flac", "audio/flac" },
|
||||
{ "gz", "application/x-gzip" },
|
||||
{ "gzip", "application/x-gzip" },
|
||||
{ "ics", "text/calendar" },
|
||||
{ "kml", "application/vnd.google-earth.kml+xml" },
|
||||
{ "kmz", "application/vnd.google-earth.kmz" },
|
||||
{ "m4a", "audio/mp4" },
|
||||
{ "mp3", "audio/mpeg" },
|
||||
{ "mp4", "video/mp4" },
|
||||
{ "mpg", "video/mpeg" },
|
||||
{ "mpeg", "video/mpeg" },
|
||||
{ "mov", "video/quicktime" },
|
||||
{ "odp", "application/vnd.oasis.opendocument.presentation" },
|
||||
{ "ods", "application/vnd.oasis.opendocument.spreadsheet" },
|
||||
{ "odt", "application/vnd.oasis.opendocument.text" },
|
||||
{ "oga", "audio/ogg" },
|
||||
{ "pdf", "application/pdf" },
|
||||
{ "pptx", "application/vnd.ms-powerpoint" },
|
||||
{ "pps", "application/vnd.ms-powerpoint" },
|
||||
{ "qt", "video/quicktime" },
|
||||
{ "swf", "application/x-shockwave-flash" },
|
||||
{ "tar", "application/x-tar" },
|
||||
{ "text", "text/plain" },
|
||||
{ "tif", "image/tiff" },
|
||||
{ "wav", "audio/wav" },
|
||||
{ "wmv", "video/x-ms-wmv" },
|
||||
{ "xls", "application/vnd.ms-excel" },
|
||||
{ "xlsx", "application/vnd.ms-excel" },
|
||||
{ "zip", "application/x-zip-compressed" },
|
||||
{ "xml", "application/xml" },
|
||||
{ "xsl", "application/xml" },
|
||||
{ "xsd", "application/xml" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED;
|
||||
|
||||
static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len);
|
||||
|
@ -463,16 +402,9 @@ static void append_essential_headers(smart_str* buffer, php_cli_server_client *c
|
|||
smart_str_appendl_ex(buffer, "Connection: close\r\n", sizeof("Connection: close\r\n") - 1, persistent);
|
||||
} /* }}} */
|
||||
|
||||
static const char *get_mime_type(const char *ext, size_t ext_len) /* {{{ */
|
||||
static const char *get_mime_type(const php_cli_server *server, const char *ext, size_t ext_len) /* {{{ */
|
||||
{
|
||||
php_cli_server_ext_mime_type_pair *pair;
|
||||
for (pair = mime_type_map; pair->ext; pair++) {
|
||||
size_t len = strlen(pair->ext);
|
||||
if (len == ext_len && memcmp(pair->ext, ext, len) == 0) {
|
||||
return pair->mime_type;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return (const char*)zend_hash_str_find_ptr(&server->extension_mime_types, ext, ext_len);
|
||||
} /* }}} */
|
||||
|
||||
PHP_FUNCTION(apache_request_headers) /* {{{ */
|
||||
|
@ -893,13 +825,11 @@ static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode
|
|||
#endif
|
||||
} /* }}} */
|
||||
|
||||
static int php_cli_server_poller_poll(php_cli_server_poller *poller, const struct timeval *tv) /* {{{ */
|
||||
static int php_cli_server_poller_poll(php_cli_server_poller *poller, struct timeval *tv) /* {{{ */
|
||||
{
|
||||
struct timeval t = *tv;
|
||||
|
||||
memmove(&poller->active.rfds, &poller->rfds, sizeof(poller->rfds));
|
||||
memmove(&poller->active.wfds, &poller->wfds, sizeof(poller->wfds));
|
||||
return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, &t);
|
||||
return php_select(poller->max_fd + 1, &poller->active.rfds, &poller->active.wfds, NULL, tv);
|
||||
} /* }}} */
|
||||
|
||||
static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, int fd, int events)) /* {{{ */
|
||||
|
@ -2043,7 +1973,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv
|
|||
{
|
||||
php_cli_server_chunk *chunk;
|
||||
smart_str buffer = { 0 };
|
||||
const char *mime_type = get_mime_type(client->request.ext, client->request.ext_len);
|
||||
const char *mime_type = get_mime_type(server, client->request.ext, client->request.ext_len);
|
||||
if (!mime_type) {
|
||||
mime_type = "application/octet-stream";
|
||||
}
|
||||
|
@ -2203,9 +2133,28 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
static int php_cli_server_mime_type_ctor(php_cli_server *server, const php_cli_server_ext_mime_type_pair *mime_type_map) /* {{{ */
|
||||
{
|
||||
const php_cli_server_ext_mime_type_pair *pair;
|
||||
|
||||
zend_hash_init(&server->extension_mime_types, 0, NULL, NULL, 1);
|
||||
|
||||
for (pair = mime_type_map; pair->ext; pair++) {
|
||||
size_t ext_len = 0, mime_type_len = 0;
|
||||
|
||||
ext_len = strlen(pair->ext);
|
||||
mime_type_len = strlen(pair->mime_type);
|
||||
|
||||
zend_hash_str_add_mem(&server->extension_mime_types, pair->ext, ext_len, (void*)pair->mime_type, mime_type_len + 1);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
} /* }}} */
|
||||
|
||||
static void php_cli_server_dtor(php_cli_server *server TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
zend_hash_destroy(&server->clients);
|
||||
zend_hash_destroy(&server->extension_mime_types);
|
||||
if (server->server_sock >= 0) {
|
||||
closesocket(server->server_sock);
|
||||
}
|
||||
|
@ -2325,6 +2274,11 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c
|
|||
server->router_len = 0;
|
||||
}
|
||||
|
||||
if (php_cli_server_mime_type_ctor(server, mime_type_map) == FAILURE) {
|
||||
retval = FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
server->is_running = 1;
|
||||
out:
|
||||
if (retval != SUCCESS) {
|
||||
|
@ -2476,7 +2430,7 @@ static int php_cli_server_do_event_loop(php_cli_server *server TSRMLS_DC) /* {{{
|
|||
{
|
||||
int retval = SUCCESS;
|
||||
while (server->is_running) {
|
||||
static const struct timeval tv = { 1, 0 };
|
||||
struct timeval tv = { 1, 0 };
|
||||
int n = php_cli_server_poller_poll(&server->poller, &tv);
|
||||
if (n > 0) {
|
||||
php_cli_server_do_event_for_each_fd(server,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue