diff options
Diffstat (limited to 'sapi/cli')
-rw-r--r-- | sapi/cli/cli.h | 10 | ||||
-rw-r--r-- | sapi/cli/config.m4 | 4 | ||||
-rw-r--r-- | sapi/cli/config.w32 | 8 | ||||
-rw-r--r-- | sapi/cli/generate_mime_type_map.php | 88 | ||||
-rw-r--r-- | sapi/cli/mime_type_map.h | 1025 | ||||
-rw-r--r-- | sapi/cli/php_cli.c | 365 | ||||
-rw-r--r-- | sapi/cli/php_cli_process_title.c | 12 | ||||
-rw-r--r-- | sapi/cli/php_cli_process_title.h | 2 | ||||
-rw-r--r-- | sapi/cli/php_cli_server.c | 642 | ||||
-rw-r--r-- | sapi/cli/php_cli_server.h | 7 | ||||
-rw-r--r-- | sapi/cli/php_http_parser.c | 16 | ||||
-rw-r--r-- | sapi/cli/php_http_parser.h | 1 | ||||
-rw-r--r-- | sapi/cli/ps_title.c | 44 | ||||
-rw-r--r-- | sapi/cli/ps_title.h | 2 | ||||
-rw-r--r-- | sapi/cli/tests/005.phpt | 18 | ||||
-rw-r--r-- | sapi/cli/tests/006.phpt | 17 | ||||
-rw-r--r-- | sapi/cli/tests/008.phpt | 5 | ||||
-rw-r--r-- | sapi/cli/tests/bug43177.phpt | 5 | ||||
-rw-r--r-- | sapi/cli/tests/bug61977.phpt | 2 | ||||
-rw-r--r-- | sapi/cli/tests/bug70006.phpt | 18 | ||||
-rw-r--r-- | sapi/cli/tests/bug71005.phpt | 46 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_015.phpt | 6 | ||||
-rw-r--r-- | sapi/cli/tests/php_cli_server_020.phpt | 40 |
23 files changed, 1775 insertions, 608 deletions
diff --git a/sapi/cli/cli.h b/sapi/cli/cli.h index eac121bcfa..ea373c2595 100644 --- a/sapi/cli/cli.h +++ b/sapi/cli/cli.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -30,12 +30,12 @@ #endif -extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS_DC); +extern PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length); typedef struct { - size_t (*cli_shell_write)(const char *str, uint str_length TSRMLS_DC); - int (*cli_shell_ub_write)(const char *str, uint str_length TSRMLS_DC); - int (*cli_shell_run)(TSRMLS_D); + size_t (*cli_shell_write)(const char *str, size_t str_length); + size_t (*cli_shell_ub_write)(const char *str, size_t str_length); + int (*cli_shell_run)(void); } cli_shell_callbacks_t; extern PHP_CLI_API cli_shell_callbacks_t *php_cli_get_shell_callbacks(); diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 index 1a585c327a..04db2fecee 100644 --- a/sapi/cli/config.m4 +++ b/sapi/cli/config.m4 @@ -31,7 +31,7 @@ if test "$PHP_CLI" != "no"; then SAPI_CLI_PATH=sapi/cli/php dnl Select SAPI - PHP_SELECT_SAPI(cli, program, php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c,, '$(SAPI_CLI_PATH)') + PHP_SELECT_SAPI(cli, program, php_cli.c php_http_parser.c php_cli_server.c ps_title.c php_cli_process_title.c, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1, '$(SAPI_CLI_PATH)') case $host_alias in *aix*) @@ -45,7 +45,7 @@ if test "$PHP_CLI" != "no"; then BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_BINARY_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" ;; *netware*) - BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -Lnetware -lphp5lib -o \$(SAPI_CLI_PATH)" + BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -Lnetware -lphp7lib -o \$(SAPI_CLI_PATH)" ;; *) BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" diff --git a/sapi/cli/config.w32 b/sapi/cli/config.w32 index adcbb2b496..664394c8a6 100644 --- a/sapi/cli/config.w32 +++ b/sapi/cli/config.w32 @@ -6,16 +6,16 @@ ARG_ENABLE('crt-debug', 'Enable CRT memory dumps for debugging sent to STDERR', ARG_ENABLE('cli-win32', 'Build console-less CLI version of PHP', 'no'); if (PHP_CLI == "yes") { - SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c php_cli_process_title.c ps_title.c', 'php.exe'); + SAPI('cli', 'php_cli.c php_http_parser.c php_cli_server.c php_cli_process_title.c ps_title.c', 'php.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); ADD_FLAG("LIBS_CLI", "ws2_32.lib"); if (PHP_CRT_DEBUG == "yes") { ADD_FLAG("CFLAGS_CLI", "/D PHP_WIN32_DEBUG_HEAP"); } - ADD_FLAG("LDFLAGS_CLI", "/stack:8388608"); + ADD_FLAG("LDFLAGS_CLI", "/stack:67108864"); } if (PHP_CLI_WIN32 == "yes") { - SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe'); - ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:8388608"); + SAPI('cli_win32', 'cli_win32.c php_cli_process_title.c ps_title.c', 'php-win.exe', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); + ADD_FLAG("LDFLAGS_CLI_WIN32", "/stack:67108864"); } diff --git a/sapi/cli/generate_mime_type_map.php b/sapi/cli/generate_mime_type_map.php new file mode 100644 index 0000000000..402be0070c --- /dev/null +++ b/sapi/cli/generate_mime_type_map.php @@ -0,0 +1,88 @@ +#!/usr/bin/env php +<?php + +// Check if we are being given a mime.types file or if we should use the +// default URL. +$source = count($_SERVER['argv']) > 1 ? $_SERVER['argv'][1] : 'https://raw.githubusercontent.com/apache/httpd/trunk/docs/conf/mime.types'; + +// See if we can actually load it. +$types = @file($source); +if ($types === false) { + fprintf(STDERR, "Error: unable to read $source\n"); + exit(1); +} + +// Remove comments and flip into an extensions array. +$extensions = []; +array_walk($types, function ($line) use (&$extensions) { + $line = trim($line); + if ($line && $line[0] != '#') { + $fields = preg_split('/\s+/', $line); + if (count($fields) > 1) { + $mime = array_shift($fields); + foreach ($fields as $extension) { + $extensions[$extension] = $mime; + } + } + } +}); + +$additional_mime_maps = [ + "map" => "application/json", // from commit: a0d62f08ae8cbebc88e5c92e08fca8d0cdc7309d +]; + +foreach($additional_mime_maps as $ext => $mime) { + if (!isset($extensions[$ext])) { + $extensions[$ext] = $mime; + } else { + printf(STDERR, "Ignored exist mime type: $ext => $mime\n"); + } +} + +?> +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2016 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Moriyoshi Koizumi <moriyoshi@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* This is a generated file. Rather than modifying it, please run + * "php generate_mime_type_map.php > mime_type_map.h" to regenerate the file. */ + +#ifndef PHP_CLI_SERVER_MIME_TYPE_MAP_H +#define PHP_CLI_SERVER_MIME_TYPE_MAP_H + +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_ext_mime_type_pair mime_type_map[] = { +<?php foreach ($extensions as $extension => $mime): ?> + { "<?= addcslashes($extension, "\0..\37!@\@\177..\377") ?>", "<?= addcslashes($mime, "\0..\37!@\@\177..\377") ?>" }, +<?php endforeach ?> + { NULL, NULL } +}; + +#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/sapi/cli/mime_type_map.h b/sapi/cli/mime_type_map.h new file mode 100644 index 0000000000..0afa501429 --- /dev/null +++ b/sapi/cli/mime_type_map.h @@ -0,0 +1,1025 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2016 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Moriyoshi Koizumi <moriyoshi@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* This is a generated file. Rather than modifying it, please run + * "php generate_mime_type_map.php > mime_type_map.h" to regenerate the file. */ + +#ifndef PHP_CLI_SERVER_MIME_TYPE_MAP_H +#define PHP_CLI_SERVER_MIME_TYPE_MAP_H + +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_ext_mime_type_pair mime_type_map[] = { + { "ez", "application/andrew-inset" }, + { "aw", "application/applixware" }, + { "atom", "application/atom+xml" }, + { "atomcat", "application/atomcat+xml" }, + { "atomsvc", "application/atomsvc+xml" }, + { "ccxml", "application/ccxml+xml" }, + { "cdmia", "application/cdmi-capability" }, + { "cdmic", "application/cdmi-container" }, + { "cdmid", "application/cdmi-domain" }, + { "cdmio", "application/cdmi-object" }, + { "cdmiq", "application/cdmi-queue" }, + { "cu", "application/cu-seeme" }, + { "davmount", "application/davmount+xml" }, + { "dbk", "application/docbook+xml" }, + { "dssc", "application/dssc+der" }, + { "xdssc", "application/dssc+xml" }, + { "ecma", "application/ecmascript" }, + { "emma", "application/emma+xml" }, + { "epub", "application/epub+zip" }, + { "exi", "application/exi" }, + { "pfr", "application/font-tdpfr" }, + { "gml", "application/gml+xml" }, + { "gpx", "application/gpx+xml" }, + { "gxf", "application/gxf" }, + { "stk", "application/hyperstudio" }, + { "ink", "application/inkml+xml" }, + { "inkml", "application/inkml+xml" }, + { "ipfix", "application/ipfix" }, + { "jar", "application/java-archive" }, + { "ser", "application/java-serialized-object" }, + { "class", "application/java-vm" }, + { "js", "application/javascript" }, + { "json", "application/json" }, + { "jsonml", "application/jsonml+json" }, + { "lostxml", "application/lost+xml" }, + { "hqx", "application/mac-binhex40" }, + { "cpt", "application/mac-compactpro" }, + { "mads", "application/mads+xml" }, + { "mrc", "application/marc" }, + { "mrcx", "application/marcxml+xml" }, + { "ma", "application/mathematica" }, + { "nb", "application/mathematica" }, + { "mb", "application/mathematica" }, + { "mathml", "application/mathml+xml" }, + { "mbox", "application/mbox" }, + { "mscml", "application/mediaservercontrol+xml" }, + { "metalink", "application/metalink+xml" }, + { "meta4", "application/metalink4+xml" }, + { "mets", "application/mets+xml" }, + { "mods", "application/mods+xml" }, + { "m21", "application/mp21" }, + { "mp21", "application/mp21" }, + { "mp4s", "application/mp4" }, + { "doc", "application/msword" }, + { "dot", "application/msword" }, + { "mxf", "application/mxf" }, + { "bin", "application/octet-stream" }, + { "dms", "application/octet-stream" }, + { "lrf", "application/octet-stream" }, + { "mar", "application/octet-stream" }, + { "so", "application/octet-stream" }, + { "dist", "application/octet-stream" }, + { "distz", "application/octet-stream" }, + { "pkg", "application/octet-stream" }, + { "bpk", "application/octet-stream" }, + { "dump", "application/octet-stream" }, + { "elc", "application/octet-stream" }, + { "deploy", "application/octet-stream" }, + { "oda", "application/oda" }, + { "opf", "application/oebps-package+xml" }, + { "ogx", "application/ogg" }, + { "omdoc", "application/omdoc+xml" }, + { "onetoc", "application/onenote" }, + { "onetoc2", "application/onenote" }, + { "onetmp", "application/onenote" }, + { "onepkg", "application/onenote" }, + { "oxps", "application/oxps" }, + { "xer", "application/patch-ops-error+xml" }, + { "pdf", "application/pdf" }, + { "pgp", "application/pgp-encrypted" }, + { "asc", "application/pgp-signature" }, + { "sig", "application/pgp-signature" }, + { "prf", "application/pics-rules" }, + { "p10", "application/pkcs10" }, + { "p7m", "application/pkcs7-mime" }, + { "p7c", "application/pkcs7-mime" }, + { "p7s", "application/pkcs7-signature" }, + { "p8", "application/pkcs8" }, + { "ac", "application/pkix-attr-cert" }, + { "cer", "application/pkix-cert" }, + { "crl", "application/pkix-crl" }, + { "pkipath", "application/pkix-pkipath" }, + { "pki", "application/pkixcmp" }, + { "pls", "application/pls+xml" }, + { "ai", "application/postscript" }, + { "eps", "application/postscript" }, + { "ps", "application/postscript" }, + { "cww", "application/prs.cww" }, + { "pskcxml", "application/pskc+xml" }, + { "rdf", "application/rdf+xml" }, + { "rif", "application/reginfo+xml" }, + { "rnc", "application/relax-ng-compact-syntax" }, + { "rl", "application/resource-lists+xml" }, + { "rld", "application/resource-lists-diff+xml" }, + { "rs", "application/rls-services+xml" }, + { "gbr", "application/rpki-ghostbusters" }, + { "mft", "application/rpki-manifest" }, + { "roa", "application/rpki-roa" }, + { "rsd", "application/rsd+xml" }, + { "rss", "application/rss+xml" }, + { "rtf", "application/rtf" }, + { "sbml", "application/sbml+xml" }, + { "scq", "application/scvp-cv-request" }, + { "scs", "application/scvp-cv-response" }, + { "spq", "application/scvp-vp-request" }, + { "spp", "application/scvp-vp-response" }, + { "sdp", "application/sdp" }, + { "setpay", "application/set-payment-initiation" }, + { "setreg", "application/set-registration-initiation" }, + { "shf", "application/shf+xml" }, + { "smi", "application/smil+xml" }, + { "smil", "application/smil+xml" }, + { "rq", "application/sparql-query" }, + { "srx", "application/sparql-results+xml" }, + { "gram", "application/srgs" }, + { "grxml", "application/srgs+xml" }, + { "sru", "application/sru+xml" }, + { "ssdl", "application/ssdl+xml" }, + { "ssml", "application/ssml+xml" }, + { "tei", "application/tei+xml" }, + { "teicorpus", "application/tei+xml" }, + { "tfi", "application/thraud+xml" }, + { "tsd", "application/timestamped-data" }, + { "plb", "application/vnd.3gpp.pic-bw-large" }, + { "psb", "application/vnd.3gpp.pic-bw-small" }, + { "pvb", "application/vnd.3gpp.pic-bw-var" }, + { "tcap", "application/vnd.3gpp2.tcap" }, + { "pwn", "application/vnd.3m.post-it-notes" }, + { "aso", "application/vnd.accpac.simply.aso" }, + { "imp", "application/vnd.accpac.simply.imp" }, + { "acu", "application/vnd.acucobol" }, + { "atc", "application/vnd.acucorp" }, + { "acutc", "application/vnd.acucorp" }, + { "air", "application/vnd.adobe.air-application-installer-package+zip" }, + { "fcdt", "application/vnd.adobe.formscentral.fcdt" }, + { "fxp", "application/vnd.adobe.fxp" }, + { "fxpl", "application/vnd.adobe.fxp" }, + { "xdp", "application/vnd.adobe.xdp+xml" }, + { "xfdf", "application/vnd.adobe.xfdf" }, + { "ahead", "application/vnd.ahead.space" }, + { "azf", "application/vnd.airzip.filesecure.azf" }, + { "azs", "application/vnd.airzip.filesecure.azs" }, + { "azw", "application/vnd.amazon.ebook" }, + { "acc", "application/vnd.americandynamics.acc" }, + { "ami", "application/vnd.amiga.ami" }, + { "apk", "application/vnd.android.package-archive" }, + { "cii", "application/vnd.anser-web-certificate-issue-initiation" }, + { "fti", "application/vnd.anser-web-funds-transfer-initiation" }, + { "atx", "application/vnd.antix.game-component" }, + { "mpkg", "application/vnd.apple.installer+xml" }, + { "m3u8", "application/vnd.apple.mpegurl" }, + { "swi", "application/vnd.aristanetworks.swi" }, + { "iota", "application/vnd.astraea-software.iota" }, + { "aep", "application/vnd.audiograph" }, + { "mpm", "application/vnd.blueice.multipass" }, + { "bmi", "application/vnd.bmi" }, + { "rep", "application/vnd.businessobjects" }, + { "cdxml", "application/vnd.chemdraw+xml" }, + { "mmd", "application/vnd.chipnuts.karaoke-mmd" }, + { "cdy", "application/vnd.cinderella" }, + { "cla", "application/vnd.claymore" }, + { "rp9", "application/vnd.cloanto.rp9" }, + { "c4g", "application/vnd.clonk.c4group" }, + { "c4d", "application/vnd.clonk.c4group" }, + { "c4f", "application/vnd.clonk.c4group" }, + { "c4p", "application/vnd.clonk.c4group" }, + { "c4u", "application/vnd.clonk.c4group" }, + { "c11amc", "application/vnd.cluetrust.cartomobile-config" }, + { "c11amz", "application/vnd.cluetrust.cartomobile-config-pkg" }, + { "csp", "application/vnd.commonspace" }, + { "cdbcmsg", "application/vnd.contact.cmsg" }, + { "cmc", "application/vnd.cosmocaller" }, + { "clkx", "application/vnd.crick.clicker" }, + { "clkk", "application/vnd.crick.clicker.keyboard" }, + { "clkp", "application/vnd.crick.clicker.palette" }, + { "clkt", "application/vnd.crick.clicker.template" }, + { "clkw", "application/vnd.crick.clicker.wordbank" }, + { "wbs", "application/vnd.criticaltools.wbs+xml" }, + { "pml", "application/vnd.ctc-posml" }, + { "ppd", "application/vnd.cups-ppd" }, + { "car", "application/vnd.curl.car" }, + { "pcurl", "application/vnd.curl.pcurl" }, + { "dart", "application/vnd.dart" }, + { "rdz", "application/vnd.data-vision.rdz" }, + { "uvf", "application/vnd.dece.data" }, + { "uvvf", "application/vnd.dece.data" }, + { "uvd", "application/vnd.dece.data" }, + { "uvvd", "application/vnd.dece.data" }, + { "uvt", "application/vnd.dece.ttml+xml" }, + { "uvvt", "application/vnd.dece.ttml+xml" }, + { "uvx", "application/vnd.dece.unspecified" }, + { "uvvx", "application/vnd.dece.unspecified" }, + { "uvz", "application/vnd.dece.zip" }, + { "uvvz", "application/vnd.dece.zip" }, + { "fe_launch", "application/vnd.denovo.fcselayout-link" }, + { "dna", "application/vnd.dna" }, + { "mlp", "application/vnd.dolby.mlp" }, + { "dpg", "application/vnd.dpgraph" }, + { "dfac", "application/vnd.dreamfactory" }, + { "kpxx", "application/vnd.ds-keypoint" }, + { "ait", "application/vnd.dvb.ait" }, + { "svc", "application/vnd.dvb.service" }, + { "geo", "application/vnd.dynageo" }, + { "mag", "application/vnd.ecowin.chart" }, + { "nml", "application/vnd.enliven" }, + { "esf", "application/vnd.epson.esf" }, + { "msf", "application/vnd.epson.msf" }, + { "qam", "application/vnd.epson.quickanime" }, + { "slt", "application/vnd.epson.salt" }, + { "ssf", "application/vnd.epson.ssf" }, + { "es3", "application/vnd.eszigno3+xml" }, + { "et3", "application/vnd.eszigno3+xml" }, + { "ez2", "application/vnd.ezpix-album" }, + { "ez3", "application/vnd.ezpix-package" }, + { "fdf", "application/vnd.fdf" }, + { "mseed", "application/vnd.fdsn.mseed" }, + { "seed", "application/vnd.fdsn.seed" }, + { "dataless", "application/vnd.fdsn.seed" }, + { "gph", "application/vnd.flographit" }, + { "ftc", "application/vnd.fluxtime.clip" }, + { "fm", "application/vnd.framemaker" }, + { "frame", "application/vnd.framemaker" }, + { "maker", "application/vnd.framemaker" }, + { "book", "application/vnd.framemaker" }, + { "fnc", "application/vnd.frogans.fnc" }, + { "ltf", "application/vnd.frogans.ltf" }, + { "fsc", "application/vnd.fsc.weblaunch" }, + { "oas", "application/vnd.fujitsu.oasys" }, + { "oa2", "application/vnd.fujitsu.oasys2" }, + { "oa3", "application/vnd.fujitsu.oasys3" }, + { "fg5", "application/vnd.fujitsu.oasysgp" }, + { "bh2", "application/vnd.fujitsu.oasysprs" }, + { "ddd", "application/vnd.fujixerox.ddd" }, + { "xdw", "application/vnd.fujixerox.docuworks" }, + { "xbd", "application/vnd.fujixerox.docuworks.binder" }, + { "fzs", "application/vnd.fuzzysheet" }, + { "txd", "application/vnd.genomatix.tuxedo" }, + { "ggb", "application/vnd.geogebra.file" }, + { "ggt", "application/vnd.geogebra.tool" }, + { "gex", "application/vnd.geometry-explorer" }, + { "gre", "application/vnd.geometry-explorer" }, + { "gxt", "application/vnd.geonext" }, + { "g2w", "application/vnd.geoplan" }, + { "g3w", "application/vnd.geospace" }, + { "gmx", "application/vnd.gmx" }, + { "kml", "application/vnd.google-earth.kml+xml" }, + { "kmz", "application/vnd.google-earth.kmz" }, + { "gqf", "application/vnd.grafeq" }, + { "gqs", "application/vnd.grafeq" }, + { "gac", "application/vnd.groove-account" }, + { "ghf", "application/vnd.groove-help" }, + { "gim", "application/vnd.groove-identity-message" }, + { "grv", "application/vnd.groove-injector" }, + { "gtm", "application/vnd.groove-tool-message" }, + { "tpl", "application/vnd.groove-tool-template" }, + { "vcg", "application/vnd.groove-vcard" }, + { "hal", "application/vnd.hal+xml" }, + { "zmm", "application/vnd.handheld-entertainment+xml" }, + { "hbci", "application/vnd.hbci" }, + { "les", "application/vnd.hhe.lesson-player" }, + { "hpgl", "application/vnd.hp-hpgl" }, + { "hpid", "application/vnd.hp-hpid" }, + { "hps", "application/vnd.hp-hps" }, + { "jlt", "application/vnd.hp-jlyt" }, + { "pcl", "application/vnd.hp-pcl" }, + { "pclxl", "application/vnd.hp-pclxl" }, + { "sfd-hdstx", "application/vnd.hydrostatix.sof-data" }, + { "mpy", "application/vnd.ibm.minipay" }, + { "afp", "application/vnd.ibm.modcap" }, + { "listafp", "application/vnd.ibm.modcap" }, + { "list3820", "application/vnd.ibm.modcap" }, + { "irm", "application/vnd.ibm.rights-management" }, + { "sc", "application/vnd.ibm.secure-container" }, + { "icc", "application/vnd.iccprofile" }, + { "icm", "application/vnd.iccprofile" }, + { "igl", "application/vnd.igloader" }, + { "ivp", "application/vnd.immervision-ivp" }, + { "ivu", "application/vnd.immervision-ivu" }, + { "igm", "application/vnd.insors.igm" }, + { "xpw", "application/vnd.intercon.formnet" }, + { "xpx", "application/vnd.intercon.formnet" }, + { "i2g", "application/vnd.intergeo" }, + { "qbo", "application/vnd.intu.qbo" }, + { "qfx", "application/vnd.intu.qfx" }, + { "rcprofile", "application/vnd.ipunplugged.rcprofile" }, + { "irp", "application/vnd.irepository.package+xml" }, + { "xpr", "application/vnd.is-xpr" }, + { "fcs", "application/vnd.isac.fcs" }, + { "jam", "application/vnd.jam" }, + { "rms", "application/vnd.jcp.javame.midlet-rms" }, + { "jisp", "application/vnd.jisp" }, + { "joda", "application/vnd.joost.joda-archive" }, + { "ktz", "application/vnd.kahootz" }, + { "ktr", "application/vnd.kahootz" }, + { "karbon", "application/vnd.kde.karbon" }, + { "chrt", "application/vnd.kde.kchart" }, + { "kfo", "application/vnd.kde.kformula" }, + { "flw", "application/vnd.kde.kivio" }, + { "kon", "application/vnd.kde.kontour" }, + { "kpr", "application/vnd.kde.kpresenter" }, + { "kpt", "application/vnd.kde.kpresenter" }, + { "ksp", "application/vnd.kde.kspread" }, + { "kwd", "application/vnd.kde.kword" }, + { "kwt", "application/vnd.kde.kword" }, + { "htke", "application/vnd.kenameaapp" }, + { "kia", "application/vnd.kidspiration" }, + { "kne", "application/vnd.kinar" }, + { "knp", "application/vnd.kinar" }, + { "skp", "application/vnd.koan" }, + { "skd", "application/vnd.koan" }, + { "skt", "application/vnd.koan" }, + { "skm", "application/vnd.koan" }, + { "sse", "application/vnd.kodak-descriptor" }, + { "lasxml", "application/vnd.las.las+xml" }, + { "lbd", "application/vnd.llamagraphics.life-balance.desktop" }, + { "lbe", "application/vnd.llamagraphics.life-balance.exchange+xml" }, + { "123", "application/vnd.lotus-1-2-3" }, + { "apr", "application/vnd.lotus-approach" }, + { "pre", "application/vnd.lotus-freelance" }, + { "nsf", "application/vnd.lotus-notes" }, + { "org", "application/vnd.lotus-organizer" }, + { "scm", "application/vnd.lotus-screencam" }, + { "lwp", "application/vnd.lotus-wordpro" }, + { "portpkg", "application/vnd.macports.portpkg" }, + { "mcd", "application/vnd.mcd" }, + { "mc1", "application/vnd.medcalcdata" }, + { "cdkey", "application/vnd.mediastation.cdkey" }, + { "mwf", "application/vnd.mfer" }, + { "mfm", "application/vnd.mfmp" }, + { "flo", "application/vnd.micrografx.flo" }, + { "igx", "application/vnd.micrografx.igx" }, + { "mif", "application/vnd.mif" }, + { "daf", "application/vnd.mobius.daf" }, + { "dis", "application/vnd.mobius.dis" }, + { "mbk", "application/vnd.mobius.mbk" }, + { "mqy", "application/vnd.mobius.mqy" }, + { "msl", "application/vnd.mobius.msl" }, + { "plc", "application/vnd.mobius.plc" }, + { "txf", "application/vnd.mobius.txf" }, + { "mpn", "application/vnd.mophun.application" }, + { "mpc", "application/vnd.mophun.certificate" }, + { "xul", "application/vnd.mozilla.xul+xml" }, + { "cil", "application/vnd.ms-artgalry" }, + { "cab", "application/vnd.ms-cab-compressed" }, + { "xls", "application/vnd.ms-excel" }, + { "xlm", "application/vnd.ms-excel" }, + { "xla", "application/vnd.ms-excel" }, + { "xlc", "application/vnd.ms-excel" }, + { "xlt", "application/vnd.ms-excel" }, + { "xlw", "application/vnd.ms-excel" }, + { "xlam", "application/vnd.ms-excel.addin.macroenabled.12" }, + { "xlsb", "application/vnd.ms-excel.sheet.binary.macroenabled.12" }, + { "xlsm", "application/vnd.ms-excel.sheet.macroenabled.12" }, + { "xltm", "application/vnd.ms-excel.template.macroenabled.12" }, + { "eot", "application/vnd.ms-fontobject" }, + { "chm", "application/vnd.ms-htmlhelp" }, + { "ims", "application/vnd.ms-ims" }, + { "lrm", "application/vnd.ms-lrm" }, + { "thmx", "application/vnd.ms-officetheme" }, + { "cat", "application/vnd.ms-pki.seccat" }, + { "stl", "application/vnd.ms-pki.stl" }, + { "ppt", "application/vnd.ms-powerpoint" }, + { "pps", "application/vnd.ms-powerpoint" }, + { "pot", "application/vnd.ms-powerpoint" }, + { "ppam", "application/vnd.ms-powerpoint.addin.macroenabled.12" }, + { "pptm", "application/vnd.ms-powerpoint.presentation.macroenabled.12" }, + { "sldm", "application/vnd.ms-powerpoint.slide.macroenabled.12" }, + { "ppsm", "application/vnd.ms-powerpoint.slideshow.macroenabled.12" }, + { "potm", "application/vnd.ms-powerpoint.template.macroenabled.12" }, + { "mpp", "application/vnd.ms-project" }, + { "mpt", "application/vnd.ms-project" }, + { "docm", "application/vnd.ms-word.document.macroenabled.12" }, + { "dotm", "application/vnd.ms-word.template.macroenabled.12" }, + { "wps", "application/vnd.ms-works" }, + { "wks", "application/vnd.ms-works" }, + { "wcm", "application/vnd.ms-works" }, + { "wdb", "application/vnd.ms-works" }, + { "wpl", "application/vnd.ms-wpl" }, + { "xps", "application/vnd.ms-xpsdocument" }, + { "mseq", "application/vnd.mseq" }, + { "mus", "application/vnd.musician" }, + { "msty", "application/vnd.muvee.style" }, + { "taglet", "application/vnd.mynfc" }, + { "nlu", "application/vnd.neurolanguage.nlu" }, + { "ntf", "application/vnd.nitf" }, + { "nitf", "application/vnd.nitf" }, + { "nnd", "application/vnd.noblenet-directory" }, + { "nns", "application/vnd.noblenet-sealer" }, + { "nnw", "application/vnd.noblenet-web" }, + { "ngdat", "application/vnd.nokia.n-gage.data" }, + { "n-gage", "application/vnd.nokia.n-gage.symbian.install" }, + { "rpst", "application/vnd.nokia.radio-preset" }, + { "rpss", "application/vnd.nokia.radio-presets" }, + { "edm", "application/vnd.novadigm.edm" }, + { "edx", "application/vnd.novadigm.edx" }, + { "ext", "application/vnd.novadigm.ext" }, + { "odc", "application/vnd.oasis.opendocument.chart" }, + { "otc", "application/vnd.oasis.opendocument.chart-template" }, + { "odb", "application/vnd.oasis.opendocument.database" }, + { "odf", "application/vnd.oasis.opendocument.formula" }, + { "odft", "application/vnd.oasis.opendocument.formula-template" }, + { "odg", "application/vnd.oasis.opendocument.graphics" }, + { "otg", "application/vnd.oasis.opendocument.graphics-template" }, + { "odi", "application/vnd.oasis.opendocument.image" }, + { "oti", "application/vnd.oasis.opendocument.image-template" }, + { "odp", "application/vnd.oasis.opendocument.presentation" }, + { "otp", "application/vnd.oasis.opendocument.presentation-template" }, + { "ods", "application/vnd.oasis.opendocument.spreadsheet" }, + { "ots", "application/vnd.oasis.opendocument.spreadsheet-template" }, + { "odt", "application/vnd.oasis.opendocument.text" }, + { "odm", "application/vnd.oasis.opendocument.text-master" }, + { "ott", "application/vnd.oasis.opendocument.text-template" }, + { "oth", "application/vnd.oasis.opendocument.text-web" }, + { "xo", "application/vnd.olpc-sugar" }, + { "dd2", "application/vnd.oma.dd2+xml" }, + { "oxt", "application/vnd.openofficeorg.extension" }, + { "pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" }, + { "sldx", "application/vnd.openxmlformats-officedocument.presentationml.slide" }, + { "ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow" }, + { "potx", "application/vnd.openxmlformats-officedocument.presentationml.template" }, + { "xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, + { "xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template" }, + { "docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, + { "dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template" }, + { "mgp", "application/vnd.osgeo.mapguide.package" }, + { "dp", "application/vnd.osgi.dp" }, + { "esa", "application/vnd.osgi.subsystem" }, + { "pdb", "application/vnd.palm" }, + { "pqa", "application/vnd.palm" }, + { "oprc", "application/vnd.palm" }, + { "paw", "application/vnd.pawaafile" }, + { "str", "application/vnd.pg.format" }, + { "ei6", "application/vnd.pg.osasli" }, + { "efif", "application/vnd.picsel" }, + { "wg", "application/vnd.pmi.widget" }, + { "plf", "application/vnd.pocketlearn" }, + { "pbd", "application/vnd.powerbuilder6" }, + { "box", "application/vnd.previewsystems.box" }, + { "mgz", "application/vnd.proteus.magazine" }, + { "qps", "application/vnd.publishare-delta-tree" }, + { "ptid", "application/vnd.pvi.ptid1" }, + { "qxd", "application/vnd.quark.quarkxpress" }, + { "qxt", "application/vnd.quark.quarkxpress" }, + { "qwd", "application/vnd.quark.quarkxpress" }, + { "qwt", "application/vnd.quark.quarkxpress" }, + { "qxl", "application/vnd.quark.quarkxpress" }, + { "qxb", "application/vnd.quark.quarkxpress" }, + { "bed", "application/vnd.realvnc.bed" }, + { "mxl", "application/vnd.recordare.musicxml" }, + { "musicxml", "application/vnd.recordare.musicxml+xml" }, + { "cryptonote", "application/vnd.rig.cryptonote" }, + { "cod", "application/vnd.rim.cod" }, + { "rm", "application/vnd.rn-realmedia" }, + { "rmvb", "application/vnd.rn-realmedia-vbr" }, + { "link66", "application/vnd.route66.link66+xml" }, + { "st", "application/vnd.sailingtracker.track" }, + { "see", "application/vnd.seemail" }, + { "sema", "application/vnd.sema" }, + { "semd", "application/vnd.semd" }, + { "semf", "application/vnd.semf" }, + { "ifm", "application/vnd.shana.informed.formdata" }, + { "itp", "application/vnd.shana.informed.formtemplate" }, + { "iif", "application/vnd.shana.informed.interchange" }, + { "ipk", "application/vnd.shana.informed.package" }, + { "twd", "application/vnd.simtech-mindmapper" }, + { "twds", "application/vnd.simtech-mindmapper" }, + { "mmf", "application/vnd.smaf" }, + { "teacher", "application/vnd.smart.teacher" }, + { "sdkm", "application/vnd.solent.sdkm+xml" }, + { "sdkd", "application/vnd.solent.sdkm+xml" }, + { "dxp", "application/vnd.spotfire.dxp" }, + { "sfs", "application/vnd.spotfire.sfs" }, + { "sdc", "application/vnd.stardivision.calc" }, + { "sda", "application/vnd.stardivision.draw" }, + { "sdd", "application/vnd.stardivision.impress" }, + { "smf", "application/vnd.stardivision.math" }, + { "sdw", "application/vnd.stardivision.writer" }, + { "vor", "application/vnd.stardivision.writer" }, + { "sgl", "application/vnd.stardivision.writer-global" }, + { "smzip", "application/vnd.stepmania.package" }, + { "sm", "application/vnd.stepmania.stepchart" }, + { "sxc", "application/vnd.sun.xml.calc" }, + { "stc", "application/vnd.sun.xml.calc.template" }, + { "sxd", "application/vnd.sun.xml.draw" }, + { "std", "application/vnd.sun.xml.draw.template" }, + { "sxi", "application/vnd.sun.xml.impress" }, + { "sti", "application/vnd.sun.xml.impress.template" }, + { "sxm", "application/vnd.sun.xml.math" }, + { "sxw", "application/vnd.sun.xml.writer" }, + { "sxg", "application/vnd.sun.xml.writer.global" }, + { "stw", "application/vnd.sun.xml.writer.template" }, + { "sus", "application/vnd.sus-calendar" }, + { "susp", "application/vnd.sus-calendar" }, + { "svd", "application/vnd.svd" }, + { "sis", "application/vnd.symbian.install" }, + { "sisx", "application/vnd.symbian.install" }, + { "xsm", "application/vnd.syncml+xml" }, + { "bdm", "application/vnd.syncml.dm+wbxml" }, + { "xdm", "application/vnd.syncml.dm+xml" }, + { "tao", "application/vnd.tao.intent-module-archive" }, + { "pcap", "application/vnd.tcpdump.pcap" }, + { "cap", "application/vnd.tcpdump.pcap" }, + { "dmp", "application/vnd.tcpdump.pcap" }, + { "tmo", "application/vnd.tmobile-livetv" }, + { "tpt", "application/vnd.trid.tpt" }, + { "mxs", "application/vnd.triscape.mxs" }, + { "tra", "application/vnd.trueapp" }, + { "ufd", "application/vnd.ufdl" }, + { "ufdl", "application/vnd.ufdl" }, + { "utz", "application/vnd.uiq.theme" }, + { "umj", "application/vnd.umajin" }, + { "unityweb", "application/vnd.unity" }, + { "uoml", "application/vnd.uoml+xml" }, + { "vcx", "application/vnd.vcx" }, + { "vsd", "application/vnd.visio" }, + { "vst", "application/vnd.visio" }, + { "vss", "application/vnd.visio" }, + { "vsw", "application/vnd.visio" }, + { "vis", "application/vnd.visionary" }, + { "vsf", "application/vnd.vsf" }, + { "wbxml", "application/vnd.wap.wbxml" }, + { "wmlc", "application/vnd.wap.wmlc" }, + { "wmlsc", "application/vnd.wap.wmlscriptc" }, + { "wtb", "application/vnd.webturbo" }, + { "nbp", "application/vnd.wolfram.player" }, + { "wpd", "application/vnd.wordperfect" }, + { "wqd", "application/vnd.wqd" }, + { "stf", "application/vnd.wt.stf" }, + { "xar", "application/vnd.xara" }, + { "xfdl", "application/vnd.xfdl" }, + { "hvd", "application/vnd.yamaha.hv-dic" }, + { "hvs", "application/vnd.yamaha.hv-script" }, + { "hvp", "application/vnd.yamaha.hv-voice" }, + { "osf", "application/vnd.yamaha.openscoreformat" }, + { "osfpvg", "application/vnd.yamaha.openscoreformat.osfpvg+xml" }, + { "saf", "application/vnd.yamaha.smaf-audio" }, + { "spf", "application/vnd.yamaha.smaf-phrase" }, + { "cmp", "application/vnd.yellowriver-custom-menu" }, + { "zir", "application/vnd.zul" }, + { "zirz", "application/vnd.zul" }, + { "zaz", "application/vnd.zzazz.deck+xml" }, + { "vxml", "application/voicexml+xml" }, + { "wgt", "application/widget" }, + { "hlp", "application/winhlp" }, + { "wsdl", "application/wsdl+xml" }, + { "wspolicy", "application/wspolicy+xml" }, + { "7z", "application/x-7z-compressed" }, + { "abw", "application/x-abiword" }, + { "ace", "application/x-ace-compressed" }, + { "dmg", "application/x-apple-diskimage" }, + { "aab", "application/x-authorware-bin" }, + { "x32", "application/x-authorware-bin" }, + { "u32", "application/x-authorware-bin" }, + { "vox", "application/x-authorware-bin" }, + { "aam", "application/x-authorware-map" }, + { "aas", "application/x-authorware-seg" }, + { "bcpio", "application/x-bcpio" }, + { "torrent", "application/x-bittorrent" }, + { "blb", "application/x-blorb" }, + { "blorb", "application/x-blorb" }, + { "bz", "application/x-bzip" }, + { "bz2", "application/x-bzip2" }, + { "boz", "application/x-bzip2" }, + { "cbr", "application/x-cbr" }, + { "cba", "application/x-cbr" }, + { "cbt", "application/x-cbr" }, + { "cbz", "application/x-cbr" }, + { "cb7", "application/x-cbr" }, + { "vcd", "application/x-cdlink" }, + { "cfs", "application/x-cfs-compressed" }, + { "chat", "application/x-chat" }, + { "pgn", "application/x-chess-pgn" }, + { "nsc", "application/x-conference" }, + { "cpio", "application/x-cpio" }, + { "csh", "application/x-csh" }, + { "deb", "application/x-debian-package" }, + { "udeb", "application/x-debian-package" }, + { "dgc", "application/x-dgc-compressed" }, + { "dir", "application/x-director" }, + { "dcr", "application/x-director" }, + { "dxr", "application/x-director" }, + { "cst", "application/x-director" }, + { "cct", "application/x-director" }, + { "cxt", "application/x-director" }, + { "w3d", "application/x-director" }, + { "fgd", "application/x-director" }, + { "swa", "application/x-director" }, + { "wad", "application/x-doom" }, + { "ncx", "application/x-dtbncx+xml" }, + { "dtb", "application/x-dtbook+xml" }, + { "res", "application/x-dtbresource+xml" }, + { "dvi", "application/x-dvi" }, + { "evy", "application/x-envoy" }, + { "eva", "application/x-eva" }, + { "bdf", "application/x-font-bdf" }, + { "gsf", "application/x-font-ghostscript" }, + { "psf", "application/x-font-linux-psf" }, + { "otf", "application/x-font-otf" }, + { "pcf", "application/x-font-pcf" }, + { "snf", "application/x-font-snf" }, + { "ttf", "application/x-font-ttf" }, + { "ttc", "application/x-font-ttf" }, + { "pfa", "application/x-font-type1" }, + { "pfb", "application/x-font-type1" }, + { "pfm", "application/x-font-type1" }, + { "afm", "application/x-font-type1" }, + { "woff", "application/font-woff" }, + { "arc", "application/x-freearc" }, + { "spl", "application/x-futuresplash" }, + { "gca", "application/x-gca-compressed" }, + { "ulx", "application/x-glulx" }, + { "gnumeric", "application/x-gnumeric" }, + { "gramps", "application/x-gramps-xml" }, + { "gtar", "application/x-gtar" }, + { "hdf", "application/x-hdf" }, + { "install", "application/x-install-instructions" }, + { "iso", "application/x-iso9660-image" }, + { "jnlp", "application/x-java-jnlp-file" }, + { "latex", "application/x-latex" }, + { "lzh", "application/x-lzh-compressed" }, + { "lha", "application/x-lzh-compressed" }, + { "mie", "application/x-mie" }, + { "prc", "application/x-mobipocket-ebook" }, + { "mobi", "application/x-mobipocket-ebook" }, + { "application", "application/x-ms-application" }, + { "lnk", "application/x-ms-shortcut" }, + { "wmd", "application/x-ms-wmd" }, + { "wmz", "application/x-msmetafile" }, + { "xbap", "application/x-ms-xbap" }, + { "mdb", "application/x-msaccess" }, + { "obd", "application/x-msbinder" }, + { "crd", "application/x-mscardfile" }, + { "clp", "application/x-msclip" }, + { "exe", "application/x-msdownload" }, + { "dll", "application/x-msdownload" }, + { "com", "application/x-msdownload" }, + { "bat", "application/x-msdownload" }, + { "msi", "application/x-msdownload" }, + { "mvb", "application/x-msmediaview" }, + { "m13", "application/x-msmediaview" }, + { "m14", "application/x-msmediaview" }, + { "wmf", "application/x-msmetafile" }, + { "emf", "application/x-msmetafile" }, + { "emz", "application/x-msmetafile" }, + { "mny", "application/x-msmoney" }, + { "pub", "application/x-mspublisher" }, + { "scd", "application/x-msschedule" }, + { "trm", "application/x-msterminal" }, + { "wri", "application/x-mswrite" }, + { "nc", "application/x-netcdf" }, + { "cdf", "application/x-netcdf" }, + { "nzb", "application/x-nzb" }, + { "p12", "application/x-pkcs12" }, + { "pfx", "application/x-pkcs12" }, + { "p7b", "application/x-pkcs7-certificates" }, + { "spc", "application/x-pkcs7-certificates" }, + { "p7r", "application/x-pkcs7-certreqresp" }, + { "rar", "application/x-rar-compressed" }, + { "ris", "application/x-research-info-systems" }, + { "sh", "application/x-sh" }, + { "shar", "application/x-shar" }, + { "swf", "application/x-shockwave-flash" }, + { "xap", "application/x-silverlight-app" }, + { "sql", "application/x-sql" }, + { "sit", "application/x-stuffit" }, + { "sitx", "application/x-stuffitx" }, + { "srt", "application/x-subrip" }, + { "sv4cpio", "application/x-sv4cpio" }, + { "sv4crc", "application/x-sv4crc" }, + { "t3", "application/x-t3vm-image" }, + { "gam", "application/x-tads" }, + { "tar", "application/x-tar" }, + { "tcl", "application/x-tcl" }, + { "tex", "application/x-tex" }, + { "tfm", "application/x-tex-tfm" }, + { "texinfo", "application/x-texinfo" }, + { "texi", "application/x-texinfo" }, + { "obj", "application/x-tgif" }, + { "ustar", "application/x-ustar" }, + { "src", "application/x-wais-source" }, + { "der", "application/x-x509-ca-cert" }, + { "crt", "application/x-x509-ca-cert" }, + { "fig", "application/x-xfig" }, + { "xlf", "application/x-xliff+xml" }, + { "xpi", "application/x-xpinstall" }, + { "xz", "application/x-xz" }, + { "z1", "application/x-zmachine" }, + { "z2", "application/x-zmachine" }, + { "z3", "application/x-zmachine" }, + { "z4", "application/x-zmachine" }, + { "z5", "application/x-zmachine" }, + { "z6", "application/x-zmachine" }, + { "z7", "application/x-zmachine" }, + { "z8", "application/x-zmachine" }, + { "xaml", "application/xaml+xml" }, + { "xdf", "application/xcap-diff+xml" }, + { "xenc", "application/xenc+xml" }, + { "xhtml", "application/xhtml+xml" }, + { "xht", "application/xhtml+xml" }, + { "xml", "application/xml" }, + { "xsl", "application/xml" }, + { "dtd", "application/xml-dtd" }, + { "xop", "application/xop+xml" }, + { "xpl", "application/xproc+xml" }, + { "xslt", "application/xslt+xml" }, + { "xspf", "application/xspf+xml" }, + { "mxml", "application/xv+xml" }, + { "xhvml", "application/xv+xml" }, + { "xvml", "application/xv+xml" }, + { "xvm", "application/xv+xml" }, + { "yang", "application/yang" }, + { "yin", "application/yin+xml" }, + { "zip", "application/zip" }, + { "adp", "audio/adpcm" }, + { "au", "audio/basic" }, + { "snd", "audio/basic" }, + { "mid", "audio/midi" }, + { "midi", "audio/midi" }, + { "kar", "audio/midi" }, + { "rmi", "audio/midi" }, + { "mp4a", "audio/mp4" }, + { "mpga", "audio/mpeg" }, + { "mp2", "audio/mpeg" }, + { "mp2a", "audio/mpeg" }, + { "mp3", "audio/mpeg" }, + { "m2a", "audio/mpeg" }, + { "m3a", "audio/mpeg" }, + { "oga", "audio/ogg" }, + { "ogg", "audio/ogg" }, + { "spx", "audio/ogg" }, + { "s3m", "audio/s3m" }, + { "sil", "audio/silk" }, + { "uva", "audio/vnd.dece.audio" }, + { "uvva", "audio/vnd.dece.audio" }, + { "eol", "audio/vnd.digital-winds" }, + { "dra", "audio/vnd.dra" }, + { "dts", "audio/vnd.dts" }, + { "dtshd", "audio/vnd.dts.hd" }, + { "lvp", "audio/vnd.lucent.voice" }, + { "pya", "audio/vnd.ms-playready.media.pya" }, + { "ecelp4800", "audio/vnd.nuera.ecelp4800" }, + { "ecelp7470", "audio/vnd.nuera.ecelp7470" }, + { "ecelp9600", "audio/vnd.nuera.ecelp9600" }, + { "rip", "audio/vnd.rip" }, + { "weba", "audio/webm" }, + { "aac", "audio/x-aac" }, + { "aif", "audio/x-aiff" }, + { "aiff", "audio/x-aiff" }, + { "aifc", "audio/x-aiff" }, + { "caf", "audio/x-caf" }, + { "flac", "audio/x-flac" }, + { "mka", "audio/x-matroska" }, + { "m3u", "audio/x-mpegurl" }, + { "wax", "audio/x-ms-wax" }, + { "wma", "audio/x-ms-wma" }, + { "ram", "audio/x-pn-realaudio" }, + { "ra", "audio/x-pn-realaudio" }, + { "rmp", "audio/x-pn-realaudio-plugin" }, + { "wav", "audio/x-wav" }, + { "xm", "audio/xm" }, + { "cdx", "chemical/x-cdx" }, + { "cif", "chemical/x-cif" }, + { "cmdf", "chemical/x-cmdf" }, + { "cml", "chemical/x-cml" }, + { "csml", "chemical/x-csml" }, + { "xyz", "chemical/x-xyz" }, + { "bmp", "image/bmp" }, + { "cgm", "image/cgm" }, + { "g3", "image/g3fax" }, + { "gif", "image/gif" }, + { "ief", "image/ief" }, + { "jpeg", "image/jpeg" }, + { "jpg", "image/jpeg" }, + { "jpe", "image/jpeg" }, + { "ktx", "image/ktx" }, + { "png", "image/png" }, + { "btif", "image/prs.btif" }, + { "sgi", "image/sgi" }, + { "svg", "image/svg+xml" }, + { "svgz", "image/svg+xml" }, + { "tiff", "image/tiff" }, + { "tif", "image/tiff" }, + { "psd", "image/vnd.adobe.photoshop" }, + { "uvi", "image/vnd.dece.graphic" }, + { "uvvi", "image/vnd.dece.graphic" }, + { "uvg", "image/vnd.dece.graphic" }, + { "uvvg", "image/vnd.dece.graphic" }, + { "sub", "text/vnd.dvb.subtitle" }, + { "djvu", "image/vnd.djvu" }, + { "djv", "image/vnd.djvu" }, + { "dwg", "image/vnd.dwg" }, + { "dxf", "image/vnd.dxf" }, + { "fbs", "image/vnd.fastbidsheet" }, + { "fpx", "image/vnd.fpx" }, + { "fst", "image/vnd.fst" }, + { "mmr", "image/vnd.fujixerox.edmics-mmr" }, + { "rlc", "image/vnd.fujixerox.edmics-rlc" }, + { "mdi", "image/vnd.ms-modi" }, + { "wdp", "image/vnd.ms-photo" }, + { "npx", "image/vnd.net-fpx" }, + { "wbmp", "image/vnd.wap.wbmp" }, + { "xif", "image/vnd.xiff" }, + { "webp", "image/webp" }, + { "3ds", "image/x-3ds" }, + { "ras", "image/x-cmu-raster" }, + { "cmx", "image/x-cmx" }, + { "fh", "image/x-freehand" }, + { "fhc", "image/x-freehand" }, + { "fh4", "image/x-freehand" }, + { "fh5", "image/x-freehand" }, + { "fh7", "image/x-freehand" }, + { "ico", "image/x-icon" }, + { "sid", "image/x-mrsid-image" }, + { "pcx", "image/x-pcx" }, + { "pic", "image/x-pict" }, + { "pct", "image/x-pict" }, + { "pnm", "image/x-portable-anymap" }, + { "pbm", "image/x-portable-bitmap" }, + { "pgm", "image/x-portable-graymap" }, + { "ppm", "image/x-portable-pixmap" }, + { "rgb", "image/x-rgb" }, + { "tga", "image/x-tga" }, + { "xbm", "image/x-xbitmap" }, + { "xpm", "image/x-xpixmap" }, + { "xwd", "image/x-xwindowdump" }, + { "eml", "message/rfc822" }, + { "mime", "message/rfc822" }, + { "igs", "model/iges" }, + { "iges", "model/iges" }, + { "msh", "model/mesh" }, + { "mesh", "model/mesh" }, + { "silo", "model/mesh" }, + { "dae", "model/vnd.collada+xml" }, + { "dwf", "model/vnd.dwf" }, + { "gdl", "model/vnd.gdl" }, + { "gtw", "model/vnd.gtw" }, + { "mts", "model/vnd.mts" }, + { "vtu", "model/vnd.vtu" }, + { "wrl", "model/vrml" }, + { "vrml", "model/vrml" }, + { "x3db", "model/x3d+binary" }, + { "x3dbz", "model/x3d+binary" }, + { "x3dv", "model/x3d+vrml" }, + { "x3dvz", "model/x3d+vrml" }, + { "x3d", "model/x3d+xml" }, + { "x3dz", "model/x3d+xml" }, + { "appcache", "text/cache-manifest" }, + { "ics", "text/calendar" }, + { "ifb", "text/calendar" }, + { "css", "text/css" }, + { "csv", "text/csv" }, + { "html", "text/html" }, + { "htm", "text/html" }, + { "n3", "text/n3" }, + { "txt", "text/plain" }, + { "text", "text/plain" }, + { "conf", "text/plain" }, + { "def", "text/plain" }, + { "list", "text/plain" }, + { "log", "text/plain" }, + { "in", "text/plain" }, + { "dsc", "text/prs.lines.tag" }, + { "rtx", "text/richtext" }, + { "sgml", "text/sgml" }, + { "sgm", "text/sgml" }, + { "tsv", "text/tab-separated-values" }, + { "t", "text/troff" }, + { "tr", "text/troff" }, + { "roff", "text/troff" }, + { "man", "text/troff" }, + { "me", "text/troff" }, + { "ms", "text/troff" }, + { "ttl", "text/turtle" }, + { "uri", "text/uri-list" }, + { "uris", "text/uri-list" }, + { "urls", "text/uri-list" }, + { "vcard", "text/vcard" }, + { "curl", "text/vnd.curl" }, + { "dcurl", "text/vnd.curl.dcurl" }, + { "scurl", "text/vnd.curl.scurl" }, + { "mcurl", "text/vnd.curl.mcurl" }, + { "fly", "text/vnd.fly" }, + { "flx", "text/vnd.fmi.flexstor" }, + { "gv", "text/vnd.graphviz" }, + { "3dml", "text/vnd.in3d.3dml" }, + { "spot", "text/vnd.in3d.spot" }, + { "jad", "text/vnd.sun.j2me.app-descriptor" }, + { "wml", "text/vnd.wap.wml" }, + { "wmls", "text/vnd.wap.wmlscript" }, + { "s", "text/x-asm" }, + { "asm", "text/x-asm" }, + { "c", "text/x-c" }, + { "cc", "text/x-c" }, + { "cxx", "text/x-c" }, + { "cpp", "text/x-c" }, + { "h", "text/x-c" }, + { "hh", "text/x-c" }, + { "dic", "text/x-c" }, + { "f", "text/x-fortran" }, + { "for", "text/x-fortran" }, + { "f77", "text/x-fortran" }, + { "f90", "text/x-fortran" }, + { "java", "text/x-java-source" }, + { "opml", "text/x-opml" }, + { "p", "text/x-pascal" }, + { "pas", "text/x-pascal" }, + { "nfo", "text/x-nfo" }, + { "etx", "text/x-setext" }, + { "sfv", "text/x-sfv" }, + { "uu", "text/x-uuencode" }, + { "vcs", "text/x-vcalendar" }, + { "vcf", "text/x-vcard" }, + { "3gp", "video/3gpp" }, + { "3g2", "video/3gpp2" }, + { "h261", "video/h261" }, + { "h263", "video/h263" }, + { "h264", "video/h264" }, + { "jpgv", "video/jpeg" }, + { "jpm", "video/jpm" }, + { "jpgm", "video/jpm" }, + { "mj2", "video/mj2" }, + { "mjp2", "video/mj2" }, + { "mp4", "video/mp4" }, + { "mp4v", "video/mp4" }, + { "mpg4", "video/mp4" }, + { "mpeg", "video/mpeg" }, + { "mpg", "video/mpeg" }, + { "mpe", "video/mpeg" }, + { "m1v", "video/mpeg" }, + { "m2v", "video/mpeg" }, + { "ogv", "video/ogg" }, + { "qt", "video/quicktime" }, + { "mov", "video/quicktime" }, + { "uvh", "video/vnd.dece.hd" }, + { "uvvh", "video/vnd.dece.hd" }, + { "uvm", "video/vnd.dece.mobile" }, + { "uvvm", "video/vnd.dece.mobile" }, + { "uvp", "video/vnd.dece.pd" }, + { "uvvp", "video/vnd.dece.pd" }, + { "uvs", "video/vnd.dece.sd" }, + { "uvvs", "video/vnd.dece.sd" }, + { "uvv", "video/vnd.dece.video" }, + { "uvvv", "video/vnd.dece.video" }, + { "dvb", "video/vnd.dvb.file" }, + { "fvt", "video/vnd.fvt" }, + { "mxu", "video/vnd.mpegurl" }, + { "m4u", "video/vnd.mpegurl" }, + { "pyv", "video/vnd.ms-playready.media.pyv" }, + { "uvu", "video/vnd.uvvu.mp4" }, + { "uvvu", "video/vnd.uvvu.mp4" }, + { "viv", "video/vnd.vivo" }, + { "webm", "video/webm" }, + { "f4v", "video/x-f4v" }, + { "fli", "video/x-fli" }, + { "flv", "video/x-flv" }, + { "m4v", "video/x-m4v" }, + { "mkv", "video/x-matroska" }, + { "mk3d", "video/x-matroska" }, + { "mks", "video/x-matroska" }, + { "mng", "video/x-mng" }, + { "asf", "video/x-ms-asf" }, + { "asx", "video/x-ms-asf" }, + { "vob", "video/x-ms-vob" }, + { "wm", "video/x-ms-wm" }, + { "wmv", "video/x-ms-wmv" }, + { "wmx", "video/x-ms-wmx" }, + { "wvx", "video/x-ms-wvx" }, + { "avi", "video/x-msvideo" }, + { "movie", "video/x-sgi-movie" }, + { "smv", "video/x-smv" }, + { "ice", "x-conference/x-cooltalk" }, + { "map", "application/json" }, + { NULL, NULL } +}; + +#endif /* PHP_CLI_SERVER_MIME_TYPE_MAP_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 40a41e544d..907f629c01 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -77,7 +77,6 @@ #include "zend_compile.h" #include "zend_execute.h" #include "zend_highlight.h" -#include "zend_indent.h" #include "zend_exceptions.h" #include "php_getopt.h" @@ -95,17 +94,24 @@ # include "win32/select.h" #endif +#if defined(PHP_WIN32) && defined(HAVE_OPENSSL) +# include "openssl/applink.c" +#endif + PHPAPI extern char *php_ini_opened_path; PHPAPI extern char *php_ini_scanned_path; PHPAPI extern char *php_ini_scanned_files; +#if defined(PHP_WIN32) && defined(ZTS) +ZEND_TSRMLS_CACHE_DEFINE(); +#endif + #ifndef O_BINARY #define O_BINARY 0 #endif #define PHP_MODE_STANDARD 1 #define PHP_MODE_HIGHLIGHT 2 -#define PHP_MODE_INDENT 3 #define PHP_MODE_LINT 4 #define PHP_MODE_STRIP 5 #define PHP_MODE_CLI_DIRECT 6 @@ -173,58 +179,58 @@ const opt_struct OPTIONS[] = { {'-', 0, NULL} /* end of args */ }; -static int print_module_info(zend_module_entry *module TSRMLS_DC) /* {{{ */ +static int print_module_info(zval *element) /* {{{ */ { + zend_module_entry *module = (zend_module_entry*)Z_PTR_P(element); php_printf("%s\n", module->name); return ZEND_HASH_APPLY_KEEP; } /* }}} */ -static int module_name_cmp(const void *a, const void *b TSRMLS_DC) /* {{{ */ +static int module_name_cmp(const void *a, const void *b) /* {{{ */ { - Bucket *f = *((Bucket **) a); - Bucket *s = *((Bucket **) b); + Bucket *f = (Bucket *) a; + Bucket *s = (Bucket *) b; - return strcasecmp(((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); + return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name, + ((zend_module_entry *)Z_PTR(s->val))->name); } /* }}} */ -static void print_modules(TSRMLS_D) /* {{{ */ +static void print_modules(void) /* {{{ */ { HashTable sorted_registry; - zend_module_entry tmp; - zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); - zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); - zend_hash_apply(&sorted_registry, (apply_func_t) print_module_info TSRMLS_CC); + zend_hash_init(&sorted_registry, 50, NULL, NULL, 0); + zend_hash_copy(&sorted_registry, &module_registry, NULL); + zend_hash_sort(&sorted_registry, module_name_cmp, 0); + zend_hash_apply(&sorted_registry, print_module_info); zend_hash_destroy(&sorted_registry); } /* }}} */ -static int print_extension_info(zend_extension *ext, void *arg TSRMLS_DC) /* {{{ */ +static int print_extension_info(zend_extension *ext, void *arg) /* {{{ */ { php_printf("%s\n", ext->name); return ZEND_HASH_APPLY_KEEP; } /* }}} */ -static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC) /* {{{ */ +static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s) /* {{{ */ { return strcmp(((zend_extension *)(*f)->data)->name, ((zend_extension *)(*s)->data)->name); } /* }}} */ -static void print_extensions(TSRMLS_D) /* {{{ */ +static void print_extensions(void) /* {{{ */ { zend_llist sorted_exts; zend_llist_copy(&sorted_exts, &zend_extensions); sorted_exts.dtor = NULL; - zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC); - zend_llist_apply(&sorted_exts, (llist_apply_func_t) print_extension_info TSRMLS_CC); + zend_llist_sort(&sorted_exts, extension_name_cmp); + zend_llist_apply(&sorted_exts, (llist_apply_func_t) print_extension_info); zend_llist_destroy(&sorted_exts); } /* }}} */ @@ -233,7 +239,7 @@ static void print_extensions(TSRMLS_D) /* {{{ */ #define STDOUT_FILENO 1 #endif -static inline int sapi_cli_select(int fd TSRMLS_DC) +static inline int sapi_cli_select(int fd) { fd_set wfd, dfd; struct timeval tv; @@ -244,7 +250,7 @@ static inline int sapi_cli_select(int fd TSRMLS_DC) PHP_SAFE_FD_SET(fd, &wfd); - tv.tv_sec = FG(default_socket_timeout); + tv.tv_sec = (long)FG(default_socket_timeout); tv.tv_usec = 0; ret = php_select(fd+1, &dfd, &wfd, &dfd, &tv); @@ -252,17 +258,17 @@ static inline int sapi_cli_select(int fd TSRMLS_DC) return ret != -1; } -PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +PHP_CLI_API size_t sapi_cli_single_write(const char *str, size_t str_length) /* {{{ */ { #ifdef PHP_WRITE_STDOUT - long ret; + zend_long ret; #else size_t ret; #endif if (cli_shell_callbacks.cli_shell_write) { size_t shell_wrote; - shell_wrote = cli_shell_callbacks.cli_shell_write(str, str_length TSRMLS_CC); + shell_wrote = cli_shell_callbacks.cli_shell_write(str, str_length); if (shell_wrote > -1) { return shell_wrote; } @@ -271,7 +277,7 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS #ifdef PHP_WRITE_STDOUT do { ret = write(STDOUT_FILENO, str, str_length); - } while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO TSRMLS_CC)); + } while (ret <= 0 && errno == EAGAIN && sapi_cli_select(STDOUT_FILENO)); if (ret <= 0) { return 0; @@ -285,10 +291,10 @@ PHP_CLI_API size_t sapi_cli_single_write(const char *str, uint str_length TSRMLS } /* }}} */ -static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_ub_write(const char *str, size_t str_length) /* {{{ */ { const char *ptr = str; - uint remaining = str_length; + size_t remaining = str_length; size_t ret; if (!str_length) { @@ -296,8 +302,8 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ } if (cli_shell_callbacks.cli_shell_ub_write) { - int ub_wrote; - ub_wrote = cli_shell_callbacks.cli_shell_ub_write(str, str_length TSRMLS_CC); + size_t ub_wrote; + ub_wrote = cli_shell_callbacks.cli_shell_ub_write(str, str_length); if (ub_wrote > -1) { return ub_wrote; } @@ -305,7 +311,7 @@ static int sapi_cli_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ while (remaining > 0) { - ret = sapi_cli_single_write(ptr, remaining TSRMLS_CC); + ret = sapi_cli_single_write(ptr, remaining); if (!ret) { #ifndef PHP_CLI_WIN32_NO_CONSOLE php_handle_aborted_connection(); @@ -336,47 +342,47 @@ static void sapi_cli_flush(void *server_context) /* {{{ */ static char *php_self = ""; static char *script_filename = ""; -static void sapi_cli_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */ +static void sapi_cli_register_variables(zval *track_vars_array) /* {{{ */ { - unsigned int len; + size_t len; char *docroot = ""; /* In CGI mode, we consider the environment to be a part of the server * variables */ - php_import_environment_variables(track_vars_array TSRMLS_CC); + php_import_environment_variables(track_vars_array); /* Build the special-case PHP_SELF variable for the CLI version */ len = strlen(php_self); - if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, len, &len TSRMLS_CC)) { - php_register_variable("PHP_SELF", php_self, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, len, &len)) { + php_register_variable("PHP_SELF", php_self, track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &php_self, len, &len TSRMLS_CC)) { - php_register_variable("SCRIPT_NAME", php_self, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &php_self, len, &len)) { + php_register_variable("SCRIPT_NAME", php_self, track_vars_array); } /* filenames are empty for stdin */ len = strlen(script_filename); - if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &script_filename, len, &len TSRMLS_CC)) { - php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &script_filename, len, &len)) { + php_register_variable("SCRIPT_FILENAME", script_filename, track_vars_array); } - if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &script_filename, len, &len TSRMLS_CC)) { - php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &script_filename, len, &len)) { + php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array); } /* just make it available */ len = 0U; - if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len TSRMLS_CC)) { - php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len)) { + php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array); } } /* }}} */ -static void sapi_cli_log_message(char *message TSRMLS_DC) /* {{{ */ +static void sapi_cli_log_message(char *message) /* {{{ */ { fprintf(stderr, "%s\n", message); } /* }}} */ -static int sapi_cli_deactivate(TSRMLS_D) /* {{{ */ +static int sapi_cli_deactivate(void) /* {{{ */ { fflush(stdout); if(SG(request_info).argv0) { @@ -387,19 +393,19 @@ static int sapi_cli_deactivate(TSRMLS_D) /* {{{ */ } /* }}} */ -static char* sapi_cli_read_cookies(TSRMLS_D) /* {{{ */ +static char* sapi_cli_read_cookies(void) /* {{{ */ { return NULL; } /* }}} */ -static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */ +static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s) /* {{{ */ { return 0; } /* }}} */ -static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */ +static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */ { /* We do nothing here, this function is needed to prevent that the fallback * header handling is called. */ @@ -407,7 +413,7 @@ static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* } /* }}} */ -static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) /* {{{ */ +static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context) /* {{{ */ { } /* }}} */ @@ -425,10 +431,8 @@ static int php_cli_startup(sapi_module_struct *sapi_module) /* {{{ */ /* overwriteable ini defaults must be set in sapi_cli_ini_defaults() */ #define INI_DEFAULT(name,value)\ - Z_SET_REFCOUNT(tmp, 0);\ - Z_UNSET_ISREF(tmp); \ - ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0);\ - zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);\ + ZVAL_NEW_STR(&tmp, zend_string_init(value, sizeof(value)-1, 1));\ + zend_hash_str_update(configuration_hash, name, sizeof(name)-1, &tmp);\ static void sapi_cli_ini_defaults(HashTable *configuration_hash) { @@ -468,7 +472,7 @@ static sapi_module_struct cli_sapi_module = { sapi_cli_log_message, /* Log message */ NULL, /* Get request time */ NULL, /* Child terminate */ - + STANDARD_SAPI_MODULE_PROPERTIES }; /* }}} */ @@ -498,7 +502,7 @@ static void php_cli_usage(char *argv0) } else { prog = "php"; } - + printf( "Usage: %s [options] [-f] <file> [--] [args...]\n" " %s [options] -r <code> [--] [args...]\n" " %s [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]\n" @@ -513,7 +517,7 @@ static void php_cli_usage(char *argv0) " -a Run interactively\n" #endif " -c <path>|<file> Look for php.ini file in this directory\n" - " -n No php.ini file will be used\n" + " -n No configuration (ini) files will be used\n" " -d foo[=bar] Define INI entry foo with value 'bar'\n" " -e Generate extended information for debugger/profiler\n" " -f <file> Parse and execute <file>.\n" @@ -551,31 +555,24 @@ static void php_cli_usage(char *argv0) static php_stream *s_in_process = NULL; -static void cli_register_file_handles(TSRMLS_D) /* {{{ */ +static void cli_register_file_handles(void) /* {{{ */ { - zval *zin, *zout, *zerr; + zval zin, zout, zerr; php_stream *s_in, *s_out, *s_err; php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL; zend_constant ic, oc, ec; - - MAKE_STD_ZVAL(zin); - MAKE_STD_ZVAL(zout); - MAKE_STD_ZVAL(zerr); s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in); s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out); s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err); if (s_in==NULL || s_out==NULL || s_err==NULL) { - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); if (s_in) php_stream_close(s_in); if (s_out) php_stream_close(s_out); if (s_err) php_stream_close(s_err); return; } - + #if PHP_DEBUG /* do not close stdout and stderr */ s_out->flags |= PHP_STREAM_FLAG_NO_CLOSE; @@ -584,34 +581,27 @@ static void cli_register_file_handles(TSRMLS_D) /* {{{ */ s_in_process = s_in; - php_stream_to_zval(s_in, zin); - php_stream_to_zval(s_out, zout); - php_stream_to_zval(s_err, zerr); - - ic.value = *zin; + php_stream_to_zval(s_in, &zin); + php_stream_to_zval(s_out, &zout); + php_stream_to_zval(s_err, &zerr); + + ZVAL_COPY_VALUE(&ic.value, &zin); ic.flags = CONST_CS; - ic.name = zend_strndup(ZEND_STRL("STDIN")); - ic.name_len = sizeof("STDIN"); + ic.name = zend_string_init("STDIN", sizeof("STDIN")-1, 1); ic.module_number = 0; - zend_register_constant(&ic TSRMLS_CC); + zend_register_constant(&ic); - oc.value = *zout; + ZVAL_COPY_VALUE(&oc.value, &zout); oc.flags = CONST_CS; - oc.name = zend_strndup(ZEND_STRL("STDOUT")); - oc.name_len = sizeof("STDOUT"); + oc.name = zend_string_init("STDOUT", sizeof("STDOUT")-1, 1); oc.module_number = 0; - zend_register_constant(&oc TSRMLS_CC); + zend_register_constant(&oc); - ec.value = *zerr; + ZVAL_COPY_VALUE(&ec.value, &zerr); ec.flags = CONST_CS; - ec.name = zend_strndup(ZEND_STRL("STDERR")); - ec.name_len = sizeof("STDERR"); + ec.name = zend_string_init("STDERR", sizeof("STDERR")-1, 1); ec.module_number = 0; - zend_register_constant(&ec TSRMLS_CC); - - FREE_ZVAL(zin); - FREE_ZVAL(zout); - FREE_ZVAL(zerr); + zend_register_constant(&ec); } /* }}} */ @@ -619,7 +609,7 @@ static const char *param_mode_conflict = "Either execute direct code, process st /* {{{ cli_seek_file_begin */ -static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno TSRMLS_DC) +static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, int *lineno) { int c; @@ -643,8 +633,8 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, /* handle situations where line is terminated by \r\n */ if (c == '\r') { if (fgetc(file_handle->handle.fp) != '\n') { - long pos = ftell(file_handle->handle.fp); - fseek(file_handle->handle.fp, pos - 1, SEEK_SET); + zend_long pos = zend_ftell(file_handle->handle.fp); + zend_fseek(file_handle->handle.fp, pos - 1, SEEK_SET); } } *lineno = 2; @@ -656,7 +646,7 @@ static int cli_seek_file_begin(zend_file_handle *file_handle, char *script_file, } /* }}} */ -static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ +static int do_cli(int argc, char **argv) /* {{{ */ { int c; zend_file_handle file_handle; @@ -675,51 +665,53 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ int hide_argv = 0; zend_try { - + CG(in_compilation) = 0; /* not initialized but needed for several options */ - EG(uninitialized_zval_ptr) = NULL; while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) { switch (c) { case 'i': /* php info & quit */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { goto err; } request_started = 1; - php_print_info(0xFFFFFFFF TSRMLS_CC); - php_output_end_all(TSRMLS_C); + php_print_info(0xFFFFFFFF); + php_output_end_all(); exit_status = (c == '?' && argc > 1 && !strchr(argv[1], c)); goto out; case 'v': /* show php version & quit */ - php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2016 The PHP Group\n%s", + php_printf("PHP %s (%s) (built: %s %s) ( %s)\nCopyright (c) 1997-2016 The PHP Group\n%s", PHP_VERSION, cli_sapi_module.name, __DATE__, __TIME__, -#if ZEND_DEBUG && defined(HAVE_GCOV) - "(DEBUG GCOV)", -#elif ZEND_DEBUG - "(DEBUG)", -#elif defined(HAVE_GCOV) - "(GCOV)", +#if ZTS + "ZTS " #else - "", + "NTS " +#endif +#if ZEND_DEBUG + "DEBUG " #endif +#ifdef HAVE_GCOV + "GCOV " +#endif + , get_zend_version() ); - sapi_deactivate(TSRMLS_C); + sapi_deactivate(); goto out; case 'm': /* list compiled in modules */ - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { goto err; } request_started = 1; php_printf("[PHP Modules]\n"); - print_modules(TSRMLS_C); + print_modules(); php_printf("\n[Zend Modules]\n"); - print_extensions(TSRMLS_C); + print_extensions(); php_printf("\n"); - php_output_end_all(TSRMLS_C); + php_output_end_all(); exit_status=0; goto out; @@ -783,16 +775,6 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ behavior=PHP_MODE_LINT; break; -#if 0 /* not yet operational, see also below ... */ - case '': /* generate indented source mode*/ - if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN) { - param_error = "Source indenting only works for files.\n"; - break; - } - behavior=PHP_MODE_INDENT; - break; -#endif - case 'q': /* do not generate HTTP headers */ /* This is default so NOP */ break; @@ -810,7 +792,7 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ behavior=PHP_MODE_CLI_DIRECT; exec_direct=php_optarg; break; - + case 'R': if (behavior == PHP_MODE_PROCESS_STDIN) { if (exec_run || script_file) { @@ -918,20 +900,18 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ fflush(stdout); } - CG(interactive) = interactive; - /* only set script_file if not set already and not in direct mode and not at end of parameter list */ - if (argc > php_optind - && !script_file - && behavior!=PHP_MODE_CLI_DIRECT - && behavior!=PHP_MODE_PROCESS_STDIN - && strcmp(argv[php_optind-1],"--")) + if (argc > php_optind + && !script_file + && behavior!=PHP_MODE_CLI_DIRECT + && behavior!=PHP_MODE_PROCESS_STDIN + && strcmp(argv[php_optind-1],"--")) { script_file=argv[php_optind]; php_optind++; } if (script_file) { - if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) { + if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) { goto err; } else { char real_path[MAXPATHLEN]; @@ -962,7 +942,7 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ argv[php_optind-1] = (char*)file_handle.filename; SG(request_info).argv=argv+php_optind-1; - if (php_request_startup(TSRMLS_C)==FAILURE) { + if (php_request_startup()==FAILURE) { *arg_excp = arg_free; fclose(file_handle.handle.fp); PUTS("Could not startup.\n"); @@ -979,24 +959,24 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } } - zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); + zend_is_auto_global_str(ZEND_STRL("_SERVER")); PG(during_request_startup) = 0; switch (behavior) { case PHP_MODE_STANDARD: if (strcmp(file_handle.filename, "-")) { - cli_register_file_handles(TSRMLS_C); + cli_register_file_handles(); } if (interactive && cli_shell_callbacks.cli_shell_run) { - exit_status = cli_shell_callbacks.cli_shell_run(TSRMLS_C); + exit_status = cli_shell_callbacks.cli_shell_run(); } else { - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); exit_status = EG(exit_status); } break; case PHP_MODE_LINT: - exit_status = php_lint_script(&file_handle TSRMLS_CC); + exit_status = php_lint_script(&file_handle); if (exit_status==SUCCESS) { zend_printf("No syntax errors detected in %s\n", file_handle.filename); } else { @@ -1004,8 +984,8 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } break; case PHP_MODE_STRIP: - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { - zend_strip(TSRMLS_C); + if (open_file_for_scanning(&file_handle)==SUCCESS) { + zend_strip(); } goto out; break; @@ -1013,87 +993,72 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ { zend_syntax_highlighter_ini syntax_highlighter_ini; - if (open_file_for_scanning(&file_handle TSRMLS_CC)==SUCCESS) { + if (open_file_for_scanning(&file_handle)==SUCCESS) { php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini TSRMLS_CC); + zend_highlight(&syntax_highlighter_ini); } goto out; } break; -#if 0 - /* Zeev might want to do something with this one day */ - case PHP_MODE_INDENT: - open_file_for_scanning(&file_handle TSRMLS_CC); - zend_indent(); - zend_file_handle_dtor(file_handle.handle TSRMLS_CC); - goto out; - break; -#endif case PHP_MODE_CLI_DIRECT: - cli_register_file_handles(TSRMLS_C); - if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1 TSRMLS_CC) == FAILURE) { + cli_register_file_handles(); + if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1) == FAILURE) { exit_status=254; } break; - + case PHP_MODE_PROCESS_STDIN: { char *input; size_t len, index = 0; - zval *argn, *argi; + zval argn, argi; - cli_register_file_handles(TSRMLS_C); + cli_register_file_handles(); - if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1 TSRMLS_CC) == FAILURE) { + if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin code", 1) == FAILURE) { exit_status=254; } - ALLOC_ZVAL(argi); - Z_TYPE_P(argi) = IS_LONG; - Z_LVAL_P(argi) = index; - INIT_PZVAL(argi); - zend_hash_update(&EG(symbol_table), "argi", sizeof("argi"), &argi, sizeof(zval *), NULL); + ZVAL_LONG(&argi, index); + zend_hash_str_update(&EG(symbol_table), "argi", sizeof("argi")-1, &argi); while (exit_status == SUCCESS && (input=php_stream_gets(s_in_process, NULL, 0)) != NULL) { len = strlen(input); - while (len-- && (input[len]=='\n' || input[len]=='\r')) { + while (len > 0 && len-- && (input[len]=='\n' || input[len]=='\r')) { input[len] = '\0'; } - ALLOC_ZVAL(argn); - Z_TYPE_P(argn) = IS_STRING; - Z_STRLEN_P(argn) = ++len; - Z_STRVAL_P(argn) = estrndup(input, len); - INIT_PZVAL(argn); - zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn, sizeof(zval *), NULL); - Z_LVAL_P(argi) = ++index; + ZVAL_STRINGL(&argn, input, len); + zend_hash_str_update(&EG(symbol_table), "argn", sizeof("argn")-1, &argn); + Z_LVAL(argi) = ++index; if (exec_run) { - if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) == FAILURE) { + if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1) == FAILURE) { exit_status=254; } } else { if (script_file) { - if (cli_seek_file_begin(&file_handle, script_file, &lineno TSRMLS_CC) != SUCCESS) { + if (cli_seek_file_begin(&file_handle, script_file, &lineno) != SUCCESS) { exit_status = 1; } else { CG(start_lineno) = lineno; - php_execute_script(&file_handle TSRMLS_CC); + php_execute_script(&file_handle); exit_status = EG(exit_status); } } } efree(input); } - if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1 TSRMLS_CC) == FAILURE) { + if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code", 1) == FAILURE) { exit_status=254; } break; } + case PHP_MODE_REFLECTION_FUNCTION: case PHP_MODE_REFLECTION_CLASS: case PHP_MODE_REFLECTION_EXTENSION: case PHP_MODE_REFLECTION_ZEND_EXTENSION: { zend_class_entry *pce = NULL; - zval *arg, *ref; + zval arg, ref; zend_execute_data execute_data; switch (behavior) { @@ -1116,25 +1081,24 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ pce = reflection_zend_extension_ptr; break; } - - MAKE_STD_ZVAL(arg); - ZVAL_STRING(arg, reflection_what, 1); - ALLOC_ZVAL(ref); - object_init_ex(ref, pce); - INIT_PZVAL(ref); + + ZVAL_STRING(&arg, reflection_what); + object_init_ex(&ref, pce); memset(&execute_data, 0, sizeof(zend_execute_data)); EG(current_execute_data) = &execute_data; - EX(function_state).function = pce->constructor; - zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, arg); + zend_call_method_with_1_params(&ref, pce, &pce->constructor, "__construct", NULL, &arg); if (EG(exception)) { - zval *msg = zend_read_property(zend_exception_get_default(TSRMLS_C), EG(exception), "message", sizeof("message")-1, 0 TSRMLS_CC); + zval tmp, *msg, rv; + + ZVAL_OBJ(&tmp, EG(exception)); + msg = zend_read_property(zend_ce_exception, &tmp, "message", sizeof("message")-1, 0, &rv); zend_printf("Exception: %s\n", Z_STRVAL_P(msg)); - zval_ptr_dtor(&EG(exception)); + zval_ptr_dtor(&tmp); EG(exception) = NULL; } else { - zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, ref); + zend_call_method_with_1_params(NULL, reflection_ptr, NULL, "export", NULL, &ref); } zval_ptr_dtor(&ref); zval_ptr_dtor(&arg); @@ -1143,11 +1107,11 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ } case PHP_MODE_REFLECTION_EXT_INFO: { - int len = strlen(reflection_what); + int len = (int)strlen(reflection_what); char *lcname = zend_str_tolower_dup(reflection_what, len); zend_module_entry *module; - if (zend_hash_find(&module_registry, lcname, len+1, (void**)&module) == FAILURE) { + if ((module = zend_hash_str_find_ptr(&module_registry, lcname, len)) == NULL) { if (!strcmp(reflection_what, "main")) { display_ini_entries(NULL); } else { @@ -1155,12 +1119,13 @@ static int do_cli(int argc, char **argv TSRMLS_DC) /* {{{ */ exit_status = 1; } } else { - php_info_print_module(module TSRMLS_CC); + php_info_print_module(module); } - + efree(lcname); break; } + case PHP_MODE_SHOW_INI_CONFIG: { zend_printf("Configuration File (php.ini) Path: %s\n", PHP_CONFIG_FILE_PATH); @@ -1184,8 +1149,8 @@ out: } return exit_status; err: - sapi_deactivate(TSRMLS_C); - zend_ini_deactivate(TSRMLS_C); + sapi_deactivate(); + zend_ini_deactivate(); exit_status = 1; goto out; } @@ -1199,9 +1164,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine int main(int argc, char *argv[]) #endif { -#ifdef ZTS - void ***tsrm_ls; -#endif #ifdef PHP_CLI_WIN32_NO_CONSOLE int argc = __argc; char **argv = __argv; @@ -1257,7 +1219,12 @@ int main(int argc, char *argv[]) #ifdef ZTS tsrm_startup(1, 1, 0, NULL); - tsrm_ls = ts_resource(0); + (void)ts_resource(0); + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + +#ifdef ZEND_SIGNALS + zend_signal_startup(); #endif #ifdef PHP_WIN32 @@ -1280,7 +1247,7 @@ int main(int argc, char *argv[]) break; case 'd': { /* define ini entries on command line */ - int len = strlen(php_optarg); + int len = (int)strlen(php_optarg); char *val; if ((val = strchr(php_optarg, '='))) { @@ -1288,11 +1255,11 @@ int main(int argc, char *argv[]) if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (val - php_optarg); + ini_entries_len += (int)(val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"", 1); ini_entries_len++; memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (val - php_optarg); + ini_entries_len += len - (int)(val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); ini_entries_len += sizeof("\n\0\"") - 2; } else { @@ -1365,7 +1332,7 @@ exit_loop: goto out; } module_started = 1; - + /* -e option */ if (use_extended_info) { CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO; @@ -1375,10 +1342,10 @@ exit_loop: #ifndef PHP_CLI_WIN32_NO_CONSOLE if (sapi_module == &cli_sapi_module) { #endif - exit_status = do_cli(argc, argv TSRMLS_CC); + exit_status = do_cli(argc, argv); #ifndef PHP_CLI_WIN32_NO_CONSOLE } else { - exit_status = do_cli_server(argc, argv TSRMLS_CC); + exit_status = do_cli_server(argc, argv); } #endif } zend_end_try(); @@ -1390,7 +1357,7 @@ out: free(ini_entries); } if (module_started) { - php_module_shutdown(TSRMLS_C); + php_module_shutdown(); } if (sapi_started) { sapi_shutdown(); diff --git a/sapi/cli/php_cli_process_title.c b/sapi/cli/php_cli_process_title.c index 4cb0118b96..9323e5e99a 100644 --- a/sapi/cli/php_cli_process_title.c +++ b/sapi/cli/php_cli_process_title.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -31,10 +31,10 @@ PHP_FUNCTION(cli_set_process_title) { char *title = NULL; - int title_len; + size_t title_len; int rc; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &title, &title_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &title, &title_len) == FAILURE) { return; } @@ -43,7 +43,7 @@ PHP_FUNCTION(cli_set_process_title) RETURN_TRUE; } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc)); + php_error_docref(NULL, E_WARNING, "cli_set_process_title had an error: %s", ps_title_errno(rc)); RETURN_FALSE; } /* }}} */ @@ -62,11 +62,11 @@ PHP_FUNCTION(cli_get_process_title) rc = get_ps_title(&length, &title); if (rc != PS_TITLE_SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc)); + php_error_docref(NULL, E_WARNING, "cli_get_process_title had an error: %s", ps_title_errno(rc)); RETURN_NULL(); } - RETURN_STRINGL(title, length, 1); + RETURN_STRINGL(title, length); } /* }}} */ diff --git a/sapi/cli/php_cli_process_title.h b/sapi/cli/php_cli_process_title.h index 44037e8d39..f0a7e23b27 100644 --- a/sapi/cli/php_cli_process_title.h +++ b/sapi/cli/php_cli_process_title.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 82bd573b56..f94ac74741 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -68,11 +68,11 @@ #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" #include "zend_highlight.h" -#include "zend_indent.h" #include "zend_exceptions.h" #include "php_getopt.h" @@ -91,12 +91,8 @@ # define SOCK_EADDRINUSE WSAEADDRINUSE #endif -#ifndef S_ISDIR -#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) -#endif - #include "ext/standard/file.h" /* for php_set_sock_blocking() :-( */ -#include "ext/standard/php_smart_str.h" +#include "zend_smart_str.h" #include "ext/standard/html.h" #include "ext/standard/url.h" /* for php_raw_url_decode() */ #include "ext/standard/php_string.h" /* for php_dirname() */ @@ -104,6 +100,7 @@ #include "php_http_parser.h" #include "php_cli_server.h" +#include "mime_type_map.h" #include "php_cli_process_title.h" @@ -138,7 +135,7 @@ typedef struct php_cli_server_request { size_t content_len; const char *ext; size_t ext_len; - struct stat sb; + zend_stat_t sb; } php_cli_server_request; typedef struct php_cli_server_chunk { @@ -194,6 +191,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,61 +199,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" }, - { 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" }, - { 451, "Unavailable For Legal Reasons"}, - { 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>" }, @@ -263,71 +206,15 @@ 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 } -}; - +#if HAVE_UNISTD_H static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED; +#endif static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len); static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len); static void php_cli_server_buffer_append(php_cli_server_buffer *buffer, php_cli_server_chunk *chunk); -static void php_cli_server_logf(const char *format TSRMLS_DC, ...); -static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message TSRMLS_DC); +static void php_cli_server_logf(const char *format, ...); +static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message); ZEND_DECLARE_MODULE_GLOBALS(cli_server); @@ -372,9 +259,9 @@ int php_cli_server_get_system_time(char *buf) { } #endif -static void char_ptr_dtor_p(char **p) /* {{{ */ +static void char_ptr_dtor_p(zval *zv) /* {{{ */ { - pefree(*p, 1); + pefree(Z_PTR_P(zv), 1); } /* }}} */ static char *get_last_error() /* {{{ */ @@ -384,8 +271,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; @@ -398,12 +285,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; @@ -442,11 +327,11 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int } smart_str_appendl_ex(buffer, "HTTP", 4, persistent); smart_str_appendc_ex(buffer, '/', persistent); - smart_str_append_generic_ex(buffer, protocol_version / 100, persistent, int, _unsigned); + smart_str_append_long_ex(buffer, protocol_version / 100, persistent); smart_str_appendc_ex(buffer, '.', persistent); - smart_str_append_generic_ex(buffer, protocol_version % 100, persistent, int, _unsigned); + smart_str_append_long_ex(buffer, protocol_version % 100, persistent); smart_str_appendc_ex(buffer, ' ', persistent); - smart_str_append_generic_ex(buffer, response_code, persistent, int, _unsigned); + smart_str_append_long_ex(buffer, response_code, persistent); smart_str_appendc_ex(buffer, ' ', persistent); smart_str_appends_ex(buffer, get_status_string(response_code), persistent); smart_str_appendl_ex(buffer, "\r\n", 2, persistent); @@ -455,37 +340,29 @@ static void append_http_status_line(smart_str *buffer, int protocol_version, int static void append_essential_headers(smart_str* buffer, php_cli_server_client *client, int persistent) /* {{{ */ { { - char **val; - if (SUCCESS == zend_hash_find(&client->request.headers, "host", sizeof("host"), (void**)&val)) { + char *val; + if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "host", sizeof("host")-1))) { smart_str_appendl_ex(buffer, "Host", sizeof("Host") - 1, persistent); smart_str_appendl_ex(buffer, ": ", sizeof(": ") - 1, persistent); - smart_str_appends_ex(buffer, *val, persistent); + smart_str_appends_ex(buffer, val, persistent); smart_str_appendl_ex(buffer, "\r\n", 2, persistent); } } 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) /* {{{ */ { php_cli_server_client *client; HashTable *headers; - char *key; - uint key_len; - char **value_pointer; - HashPosition pos; + zend_string *key; + char *value; + zval tmp; if (zend_parse_parameters_none() == FAILURE) { return; @@ -496,19 +373,17 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */ array_init_size(return_value, zend_hash_num_elements(headers)); - zend_hash_internal_pointer_reset_ex(headers, &pos); - while (zend_hash_get_current_data_ex(headers, (void **)&value_pointer, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(headers, &key, &key_len, NULL, 0, &pos); - add_assoc_string_ex(return_value, key, key_len, *value_pointer, 1); - zend_hash_move_forward_ex(headers, &pos); - } + ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, value) { + ZVAL_STRING(&tmp, value); + zend_symtable_update(Z_ARRVAL_P(return_value), key, &tmp); + } ZEND_HASH_FOREACH_END(); } /* }}} */ -static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS_DC) /* {{{ */ +static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{{ */ { char *s, *p; - int len; + ptrdiff_t len; ALLOCA_FLAG(use_heap) if (h->header_len > 0) { @@ -525,7 +400,7 @@ static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS do { p++; } while (*p == ' ' || *p == '\t'); - add_assoc_stringl_ex(return_value, s, len+1, p, h->header_len - (p - h->header), 1); + add_assoc_stringl_ex(return_value, s, (uint)len, p, h->header_len - (p - h->header)); free_alloca(s, use_heap); } } @@ -539,18 +414,15 @@ PHP_FUNCTION(apache_response_headers) /* {{{ */ return; } - if (!&SG(sapi_headers).headers) { - RETURN_FALSE; - } array_init(return_value); - zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value TSRMLS_CC); + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value); } /* }}} */ /* {{{ cli_server module */ -static void cli_server_init_globals(zend_cli_server_globals *cg TSRMLS_DC) +static void cli_server_init_globals(zend_cli_server_globals *cg) { cg->color = 0; } @@ -611,7 +483,7 @@ static int sapi_cli_server_startup(sapi_module_struct *sapi_module) /* {{{ */ return SUCCESS; } /* }}} */ -static int sapi_cli_server_ub_write(const char *str, uint str_length TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_server_ub_write(const char *str, size_t str_length) /* {{{ */ { php_cli_server_client *client = SG(server_context); if (!client) { @@ -623,29 +495,28 @@ static int sapi_cli_server_ub_write(const char *str, uint str_length TSRMLS_DC) static void sapi_cli_server_flush(void *server_context) /* {{{ */ { php_cli_server_client *client = server_context; - TSRMLS_FETCH(); if (!client) { return; } - if (client->sock < 0) { + if (!ZEND_VALID_SOCKET(client->sock)) { php_handle_aborted_connection(); return; } if (!SG(headers_sent)) { - sapi_send_headers(TSRMLS_C); + sapi_send_headers(); SG(headers_sent) = 1; } } /* }}} */ -static int sapi_cli_server_discard_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */{ +static int sapi_cli_server_discard_headers(sapi_headers_struct *sapi_headers) /* {{{ */{ return SAPI_HEADER_SENT_SUCCESSFULLY; } /* }}} */ -static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */ +static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */ { php_cli_server_client *client = SG(server_context); smart_str buffer = { 0 }; @@ -675,24 +546,24 @@ static int sapi_cli_server_send_headers(sapi_headers_struct *sapi_headers TSRMLS } smart_str_appendl(&buffer, "\r\n", 2); - php_cli_server_client_send_through(client, buffer.c, buffer.len); + php_cli_server_client_send_through(client, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s)); smart_str_free(&buffer); return SAPI_HEADER_SENT_SUCCESSFULLY; } /* }}} */ -static char *sapi_cli_server_read_cookies(TSRMLS_D) /* {{{ */ +static char *sapi_cli_server_read_cookies(void) /* {{{ */ { php_cli_server_client *client = SG(server_context); - char **val; - if (FAILURE == zend_hash_find(&client->request.headers, "cookie", sizeof("cookie"), (void**)&val)) { + char *val; + if (NULL == (val = zend_hash_str_find_ptr(&client->request.headers, "cookie", sizeof("cookie")-1))) { return NULL; } - return *val; + return val; } /* }}} */ -static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* {{{ */ +static size_t sapi_cli_server_read_post(char *buf, size_t count_bytes) /* {{{ */ { php_cli_server_client *client = SG(server_context); if (client->request.content) { @@ -705,27 +576,27 @@ static int sapi_cli_server_read_post(char *buf, uint count_bytes TSRMLS_DC) /* { return 0; } /* }}} */ -static void sapi_cli_server_register_variable(zval *track_vars_array, const char *key, const char *val TSRMLS_DC) /* {{{ */ +static void sapi_cli_server_register_variable(zval *track_vars_array, const char *key, const char *val) /* {{{ */ { char *new_val = (char *)val; - uint new_val_len; + size_t new_val_len; if (NULL == val) { return; } - if (sapi_module.input_filter(PARSE_SERVER, (char*)key, &new_val, strlen(val), &new_val_len TSRMLS_CC)) { - php_register_variable_safe((char *)key, new_val, new_val_len, track_vars_array TSRMLS_CC); + if (sapi_module.input_filter(PARSE_SERVER, (char*)key, &new_val, strlen(val), &new_val_len)) { + php_register_variable_safe((char *)key, new_val, new_val_len, track_vars_array); } } /* }}} */ -static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { +static int sapi_cli_server_register_entry_cb(char **entry, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { zval *track_vars_array = va_arg(args, zval *); - if (hash_key->nKeyLength) { + if (hash_key->key) { char *real_key, *key; uint i; - key = estrndup(hash_key->arKey, hash_key->nKeyLength); - for(i=0; i<hash_key->nKeyLength; i++) { + key = estrndup(ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key)); + for(i=0; i<ZSTR_LEN(hash_key->key); i++) { if (key[i] == '-') { key[i] = '_'; } else { @@ -734,9 +605,9 @@ static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_arg } spprintf(&real_key, 0, "%s_%s", "HTTP", key); if (strcmp(key, "CONTENT_TYPE") == 0 || strcmp(key, "CONTENT_LENGTH") == 0) { - sapi_cli_server_register_variable(track_vars_array, key, *entry TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, key, *entry); } - sapi_cli_server_register_variable(track_vars_array, real_key, *entry TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, real_key, *entry); efree(key); efree(real_key); } @@ -745,10 +616,10 @@ static int sapi_cli_server_register_entry_cb(char **entry TSRMLS_DC, int num_arg } /* }}} */ -static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) /* {{{ */ +static void sapi_cli_server_register_variables(zval *track_vars_array) /* {{{ */ { php_cli_server_client *client = SG(server_context); - sapi_cli_server_register_variable(track_vars_array, "DOCUMENT_ROOT", client->server->document_root TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "DOCUMENT_ROOT", client->server->document_root); { char *tmp; if ((tmp = strrchr(client->addr_str, ':'))) { @@ -757,61 +628,61 @@ static void sapi_cli_server_register_variables(zval *track_vars_array TSRMLS_DC) port[7] = '\0'; strncpy(addr, client->addr_str, tmp - client->addr_str); addr[tmp - client->addr_str] = '\0'; - sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", addr TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "REMOTE_PORT", port TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", addr); + sapi_cli_server_register_variable(track_vars_array, "REMOTE_PORT", port); } else { - sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", client->addr_str TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "REMOTE_ADDR", client->addr_str); } } { char *tmp; spprintf(&tmp, 0, "PHP %s Development Server", PHP_VERSION); - sapi_cli_server_register_variable(track_vars_array, "SERVER_SOFTWARE", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_SOFTWARE", tmp); efree(tmp); } { char *tmp; spprintf(&tmp, 0, "HTTP/%d.%d", client->request.protocol_version / 100, client->request.protocol_version % 100); - sapi_cli_server_register_variable(track_vars_array, "SERVER_PROTOCOL", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_PROTOCOL", tmp); efree(tmp); } - sapi_cli_server_register_variable(track_vars_array, "SERVER_NAME", client->server->host TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_NAME", client->server->host); { char *tmp; spprintf(&tmp, 0, "%i", client->server->port); - sapi_cli_server_register_variable(track_vars_array, "SERVER_PORT", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SERVER_PORT", tmp); efree(tmp); } - sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method TSRMLS_CC); - sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "REQUEST_URI", client->request.request_uri); + sapi_cli_server_register_variable(track_vars_array, "REQUEST_METHOD", SG(request_info).request_method); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_NAME", client->request.vpath); if (SG(request_info).path_translated) { - sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", SG(request_info).path_translated); } else if (client->server->router) { char *temp; spprintf(&temp, 0, "%s/%s", client->server->document_root, client->server->router); - sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", temp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "SCRIPT_FILENAME", temp); efree(temp); } if (client->request.path_info) { - sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "PATH_INFO", client->request.path_info); } if (client->request.path_info_len) { char *tmp; spprintf(&tmp, 0, "%s%s", client->request.vpath, client->request.path_info); - sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", tmp TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", tmp); efree(tmp); } else { - sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "PHP_SELF", client->request.vpath); } if (client->request.query_string) { - sapi_cli_server_register_variable(track_vars_array, "QUERY_STRING", client->request.query_string TSRMLS_CC); + sapi_cli_server_register_variable(track_vars_array, "QUERY_STRING", client->request.query_string); } - zend_hash_apply_with_arguments(&client->request.headers TSRMLS_CC, (apply_func_args_t)sapi_cli_server_register_entry_cb, 1, track_vars_array); + zend_hash_apply_with_arguments(&client->request.headers, (apply_func_args_t)sapi_cli_server_register_entry_cb, 1, track_vars_array); } /* }}} */ -static void sapi_cli_server_log_message(char *msg TSRMLS_DC) /* {{{ */ +static void sapi_cli_server_log_message(char *msg) /* {{{ */ { char buf[52]; @@ -870,7 +741,7 @@ static int php_cli_server_poller_ctor(php_cli_server_poller *poller) /* {{{ */ return SUCCESS; } /* }}} */ -static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, int fd) /* {{{ */ +static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, php_socket_t fd) /* {{{ */ { if (mode & POLLIN) { PHP_SAFE_FD_SET(fd, &poller->rfds); @@ -883,7 +754,7 @@ static void php_cli_server_poller_add(php_cli_server_poller *poller, int mode, i } } /* }}} */ -static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode, int fd) /* {{{ */ +static void php_cli_server_poller_remove(php_cli_server_poller *poller, int mode, php_socket_t fd) /* {{{ */ { if (mode & POLLIN) { PHP_SAFE_FD_CLR(fd, &poller->rfds); @@ -911,7 +782,7 @@ static int php_cli_server_poller_poll(php_cli_server_poller *poller, struct time 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)) /* {{{ */ +static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, void *opaque, int(*callback)(void *, php_socket_t fd, int events)) /* {{{ */ { int retval = SUCCESS; #ifdef PHP_WIN32 @@ -919,7 +790,6 @@ static int php_cli_server_poller_iter_on_active(php_cli_server_poller *poller, v SOCKET fd; int events; } entries[FD_SETSIZE * 2]; - php_socket_t fd = 0; size_t i; struct socket_entry *n = entries, *m; @@ -1062,7 +932,7 @@ static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, return chunk; } /* }}} */ -static php_cli_server_chunk *php_cli_server_chunk_heap_new(char *block, char *buf, size_t len) /* {{{ */ +static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *buf, size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1); if (!chunk) { @@ -1108,12 +978,20 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen size_t _nbytes_sent_total = 0; for (chunk = sender->buffer.first; chunk; chunk = next) { +#ifdef PHP_WIN32 + int nbytes_sent; +#else ssize_t nbytes_sent; +#endif next = chunk->next; switch (chunk->type) { case PHP_CLI_SERVER_CHUNK_HEAP: +#ifdef PHP_WIN32 + nbytes_sent = send(fd, chunk->data.heap.p, (int)chunk->data.heap.len, 0); +#else nbytes_sent = send(fd, chunk->data.heap.p, chunk->data.heap.len, 0); +#endif if (nbytes_sent < 0) { *nbytes_sent_total = _nbytes_sent_total; return php_socket_errno(); @@ -1132,7 +1010,11 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen break; case PHP_CLI_SERVER_CHUNK_IMMORTAL: +#ifdef PHP_WIN32 + nbytes_sent = send(fd, chunk->data.immortal.p, (int)chunk->data.immortal.len, 0); +#else nbytes_sent = send(fd, chunk->data.immortal.p, chunk->data.immortal.len, 0); +#endif if (nbytes_sent < 0) { *nbytes_sent_total = _nbytes_sent_total; return php_socket_errno(); @@ -1157,14 +1039,21 @@ static int php_cli_server_content_sender_send(php_cli_server_content_sender *sen static int php_cli_server_content_sender_pull(php_cli_server_content_sender *sender, int fd, size_t *nbytes_read) /* {{{ */ { +#ifdef PHP_WIN32 + int _nbytes_read; +#else ssize_t _nbytes_read; +#endif php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(131072); +#ifdef PHP_WIN32 + _nbytes_read = read(fd, chunk->data.heap.p, (unsigned int)chunk->data.heap.len); +#else _nbytes_read = read(fd, chunk->data.heap.p, chunk->data.heap.len); +#endif if (_nbytes_read < 0) { char *errstr = get_last_error(); - TSRMLS_FETCH(); - php_cli_server_logf("%s" TSRMLS_CC, errstr); + php_cli_server_logf("%s", errstr); pefree(errstr, 1); php_cli_server_chunk_dtor(chunk); pefree(chunk, 1); @@ -1186,7 +1075,7 @@ static int php_cli_is_output_tty() /* {{{ */ } /* }}} */ #endif -static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message TSRMLS_DC) /* {{{ */ +static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message) /* {{{ */ { int color = 0, effective_status = status; char *basic_buf, *message_buf = "", *error_buf = ""; @@ -1252,9 +1141,9 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu } if (color) { - php_cli_server_logf("\x1b[3%dm%s%s%s\x1b[0m" TSRMLS_CC, color, basic_buf, message_buf, error_buf); + php_cli_server_logf("\x1b[3%dm%s%s%s\x1b[0m", color, basic_buf, message_buf, error_buf); } else { - php_cli_server_logf("%s%s%s" TSRMLS_CC, basic_buf, message_buf, error_buf); + php_cli_server_logf("%s%s%s", basic_buf, message_buf, error_buf); } efree(basic_buf); @@ -1266,15 +1155,12 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu } } /* }}} */ -static void php_cli_server_logf(const char *format TSRMLS_DC, ...) /* {{{ */ +static void php_cli_server_logf(const char *format, ...) /* {{{ */ { char *buf = NULL; va_list ap; -#ifdef ZTS - va_start(ap, tsrm_ls); -#else + va_start(ap, format); -#endif vspprintf(&buf, 0, format, ap); va_end(ap); @@ -1283,19 +1169,19 @@ static void php_cli_server_logf(const char *format TSRMLS_DC, ...) /* {{{ */ } if (sapi_module.log_message) { - sapi_module.log_message(buf TSRMLS_CC); + sapi_module.log_message(buf); } efree(buf); } /* }}} */ -static int php_network_listen_socket(const char *host, int *port, int socktype, int *af, socklen_t *socklen, char **errstr TSRMLS_DC) /* {{{ */ +static php_socket_t php_network_listen_socket(const char *host, int *port, int socktype, int *af, socklen_t *socklen, zend_string **errstr) /* {{{ */ { - int retval = SOCK_ERR; + php_socket_t retval = SOCK_ERR; int err = 0; struct sockaddr *sa = NULL, **p, **sal; - int num_addrs = php_network_getaddresses(host, socktype, &sal, errstr TSRMLS_CC); + int num_addrs = php_network_getaddresses(host, socktype, &sal, errstr); if (num_addrs == 0) { return -1; } @@ -1400,11 +1286,11 @@ out: php_network_freeaddresses(sal); } if (err) { - if (retval >= 0) { + if (ZEND_VALID_SOCKET(retval)) { closesocket(retval); } if (errstr) { - *errstr = php_socket_strerror(err, NULL, 0); + *errstr = php_socket_error_str(err); } return SOCK_ERR; } @@ -1413,6 +1299,9 @@ out: static int php_cli_server_request_ctor(php_cli_server_request *req) /* {{{ */ { +#ifdef ZTS +ZEND_TSRMLS_CACHE_UPDATE(); +#endif req->protocol_version = 0; req->request_uri = NULL; req->request_uri_len = 0; @@ -1424,7 +1313,7 @@ static int php_cli_server_request_ctor(php_cli_server_request *req) /* {{{ */ req->path_info_len = 0; req->query_string = NULL; req->query_string_len = 0; - zend_hash_init(&req->headers, 0, NULL, (void(*)(void*))char_ptr_dtor_p, 1); + zend_hash_init(&req->headers, 0, NULL, char_ptr_dtor_p, 1); zend_hash_init(&req->headers_original_case, 0, NULL, NULL, 1); req->content = NULL; req->content_len = 0; @@ -1459,7 +1348,7 @@ static void php_cli_server_request_dtor(php_cli_server_request *req) /* {{{ */ static void php_cli_server_request_translate_vpath(php_cli_server_request *request, const char *document_root, size_t document_root_len) /* {{{ */ { - struct stat sb; + zend_stat_t sb; static const char *index_files[] = { "index.php", "index.html", NULL }; char *buf = safe_pemalloc(1, request->vpath_len, 1 + document_root_len + 1 + sizeof("index.html"), 1); char *p = buf, *prev_path = NULL, *q, *vpath; @@ -1496,7 +1385,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque *p = '\0'; q = p; while (q > buf) { - if (!stat(buf, &sb)) { + if (!zend_stat(buf, &sb)) { if (sb.st_mode & S_IFDIR) { const char **file = index_files; if (q[-1] != DEFAULT_SLASH) { @@ -1505,7 +1394,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque while (*file) { size_t l = strlen(*file); memmove(q, *file, l + 1); - if (!stat(buf, &sb) && (sb.st_mode & S_IFREG)) { + if (!zend_stat(buf, &sb) && (sb.st_mode & S_IFREG)) { q += l; break; } @@ -1578,7 +1467,7 @@ static void normalize_vpath(char **retval, size_t *retval_len, const char *vpath return; } - decoded_vpath_end = decoded_vpath + php_raw_url_decode(decoded_vpath, vpath_len); + decoded_vpath_end = decoded_vpath + php_raw_url_decode(decoded_vpath, (int)vpath_len); #ifdef PHP_WIN32 { @@ -1707,13 +1596,12 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p } { /* strip off the colon */ - char *orig_header_name = estrndup(client->current_header_name, client->current_header_name_len); + zend_string *orig_header_name = zend_string_init(client->current_header_name, client->current_header_name_len, 1); char *lc_header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); - - zend_hash_add(&client->request.headers, lc_header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL); - zend_hash_add(&client->request.headers_original_case, orig_header_name, client->current_header_name_len + 1, &value, sizeof(char *), NULL); + zend_hash_str_add_ptr(&client->request.headers, lc_header_name, client->current_header_name_len, value); + zend_hash_add_ptr(&client->request.headers_original_case, orig_header_name, value); efree(lc_header_name); - efree(orig_header_name); + zend_string_release(orig_header_name); } if (client->current_header_name_allocated) { @@ -1773,7 +1661,7 @@ static int php_cli_server_client_read_request_on_message_complete(php_http_parse return 0; } -static int php_cli_server_client_read_request(php_cli_server_client *client, char **errstr TSRMLS_DC) +static int php_cli_server_client_read_request(php_cli_server_client *client, char **errstr) { char buf[16384]; static const php_http_parser_settings settings = { @@ -1831,9 +1719,19 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha static size_t php_cli_server_client_send_through(php_cli_server_client *client, const char *str, size_t str_len) /* {{{ */ { struct timeval tv = { 10, 0 }; - ssize_t nbytes_left = str_len; +#ifdef PHP_WIN32 + int nbytes_left = (int)str_len; +#else + ssize_t nbytes_left = (ssize_t)str_len; +#endif do { - ssize_t nbytes_sent = send(client->sock, str + str_len - nbytes_left, nbytes_left, 0); +#ifdef PHP_WIN32 + int nbytes_sent; +#else + ssize_t nbytes_sent; +#endif + + nbytes_sent = send(client->sock, str + str_len - nbytes_left, nbytes_left, 0); if (nbytes_sent < 0) { int err = php_socket_errno(); if (err == SOCK_EAGAIN) { @@ -1862,7 +1760,7 @@ static size_t php_cli_server_client_send_through(php_cli_server_client *client, static void php_cli_server_client_populate_request_info(const php_cli_server_client *client, sapi_request_info *request_info) /* {{{ */ { - char **val; + char *val; request_info->request_method = php_http_method_str(client->request.request_method); request_info->proto_num = client->request.protocol_version; @@ -1871,8 +1769,8 @@ static void php_cli_server_client_populate_request_info(const php_cli_server_cli request_info->query_string = client->request.query_string; request_info->content_length = client->request.content_len; request_info->auth_user = request_info->auth_password = request_info->auth_digest = NULL; - if (SUCCESS == zend_hash_find(&client->request.headers, "content-type", sizeof("content-type"), (void**)&val)) { - request_info->content_type = *val; + if (NULL != (val = zend_hash_str_find_ptr(&client->request.headers, "content-type", sizeof("content-type")-1))) { + request_info->content_type = val; } } /* }}} */ @@ -1880,19 +1778,19 @@ static void destroy_request_info(sapi_request_info *request_info) /* {{{ */ { } /* }}} */ -static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_server *server, int client_sock, struct sockaddr *addr, socklen_t addr_len TSRMLS_DC) /* {{{ */ +static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_server *server, php_socket_t client_sock, struct sockaddr *addr, socklen_t addr_len) /* {{{ */ { client->server = server; client->sock = client_sock; client->addr = addr; client->addr_len = addr_len; { - char *addr_str = 0; - long addr_str_len = 0; - php_network_populate_name_from_sockaddr(addr, addr_len, &addr_str, &addr_str_len, NULL, 0 TSRMLS_CC); - client->addr_str = pestrndup(addr_str, addr_str_len, 1); - client->addr_str_len = addr_str_len; - efree(addr_str); + zend_string *addr_str = 0; + + php_network_populate_name_from_sockaddr(addr, addr_len, &addr_str, NULL, 0); + client->addr_str = pestrndup(ZSTR_VAL(addr_str), ZSTR_LEN(addr_str), 1); + client->addr_str_len = ZSTR_LEN(addr_str); + zend_string_release(addr_str); } php_http_parser_init(&client->parser, PHP_HTTP_REQUEST); client->request_read = 0; @@ -1922,18 +1820,17 @@ static void php_cli_server_client_dtor(php_cli_server_client *client) /* {{{ */ } } /* }}} */ -static void php_cli_server_close_connection(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static void php_cli_server_close_connection(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { #ifdef DEBUG - php_cli_server_logf("%s Closing" TSRMLS_CC, client->addr_str); + php_cli_server_logf("%s Closing", client->addr_str); #endif zend_hash_index_del(&server->clients, client->sock); } /* }}} */ -static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server_client *client, int status TSRMLS_DC) /* {{{ */ +static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server_client *client, int status) /* {{{ */ { - char *escaped_request_uri = NULL; - size_t escaped_request_uri_len; + zend_string *escaped_request_uri = NULL; const char *status_string = get_status_string(status); const char *content_template = get_template_string(status); char *errstr = get_last_error(); @@ -1942,7 +1839,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_content_sender_ctor(&client->content_sender); client->content_sender_initialized = 1; - escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, &escaped_request_uri_len, 0, ENT_QUOTES, NULL, 0 TSRMLS_CC); + escaped_request_uri = php_escape_html_entities_ex((unsigned char *)client->request.request_uri, client->request.request_uri_len, 0, ENT_QUOTES, NULL, 0); { static const char prologue_template[] = "<!doctype html><html><head><title>%d %s</title>"; @@ -1950,7 +1847,7 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server if (!chunk) { goto fail; } - snprintf(chunk->data.heap.p, chunk->data.heap.len, prologue_template, status, status_string, escaped_request_uri); + snprintf(chunk->data.heap.p, chunk->data.heap.len, prologue_template, status, status_string, ZSTR_VAL(escaped_request_uri)); chunk->data.heap.len = strlen(chunk->data.heap.p); php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } @@ -1970,11 +1867,11 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } { - php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(content_template) + escaped_request_uri_len + 3 + strlen(status_string) + 1); + php_cli_server_chunk *chunk = php_cli_server_chunk_heap_new_self_contained(strlen(content_template) + ZSTR_LEN(escaped_request_uri) + 3 + strlen(status_string) + 1); if (!chunk) { goto fail; } - snprintf(chunk->data.heap.p, chunk->data.heap.len, content_template, status_string, escaped_request_uri); + snprintf(chunk->data.heap.p, chunk->data.heap.len, content_template, status_string, ZSTR_VAL(escaped_request_uri)); chunk->data.heap.len = strlen(chunk->data.heap.p); php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } @@ -1991,46 +1888,46 @@ static int php_cli_server_send_error_page(php_cli_server *server, php_cli_server php_cli_server_chunk *chunk; smart_str buffer = { 0 }; append_http_status_line(&buffer, client->request.protocol_version, status, 1); - if (!buffer.c) { + if (!buffer.s) { /* out of memory */ goto fail; } append_essential_headers(&buffer, client, 1); smart_str_appends_ex(&buffer, "Content-Type: text/html; charset=UTF-8\r\n", 1); smart_str_appends_ex(&buffer, "Content-Length: ", 1); - smart_str_append_generic_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1, size_t, _unsigned); + smart_str_append_unsigned_ex(&buffer, php_cli_server_buffer_size(&client->content_sender.buffer), 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); - chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len); + chunk = php_cli_server_chunk_heap_new(buffer.s, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s)); if (!chunk) { - smart_str_free_ex(&buffer, 1); + smart_str_free(&buffer); goto fail; } php_cli_server_buffer_prepend(&client->content_sender.buffer, chunk); } - php_cli_server_log_response(client, status, errstr ? errstr : "?" TSRMLS_CC); + php_cli_server_log_response(client, status, errstr ? errstr : "?"); php_cli_server_poller_add(&server->poller, POLLOUT, client->sock); if (errstr) { pefree(errstr, 1); } - efree(escaped_request_uri); + zend_string_free(escaped_request_uri); return SUCCESS; fail: if (errstr) { pefree(errstr, 1); } - efree(escaped_request_uri); + zend_string_free(escaped_request_uri); return FAILURE; } /* }}} */ -static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { if (strlen(client->request.path_translated) != client->request.path_translated_len) { /* can't handle paths that contain nul bytes */ - return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 400); } { zend_file_handle zfd; @@ -2040,22 +1937,22 @@ static int php_cli_server_dispatch_script(php_cli_server *server, php_cli_server zfd.free_filename = 0; zfd.opened_path = NULL; zend_try { - php_execute_script(&zfd TSRMLS_CC); + php_execute_script(&zfd); } zend_end_try(); } - php_cli_server_log_response(client, SG(sapi_headers).http_response_code, NULL TSRMLS_CC); + php_cli_server_log_response(client, SG(sapi_headers).http_response_code, NULL); return SUCCESS; } /* }}} */ -static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { int fd; int status = 200; if (client->request.path_translated && strlen(client->request.path_translated) != client->request.path_translated_len) { /* can't handle paths that contain nul bytes */ - return php_cli_server_send_error_page(server, client, 400 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 400); } #ifdef PHP_WIN32 @@ -2073,7 +1970,7 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv fd = client->request.path_translated ? open(client->request.path_translated, O_RDONLY): -1; if (fd < 0) { - return php_cli_server_send_error_page(server, client, 404 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 404); } php_cli_server_content_sender_ctor(&client->content_sender); @@ -2083,15 +1980,15 @@ 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"; } append_http_status_line(&buffer, client->request.protocol_version, status, 1); - if (!buffer.c) { + if (!buffer.s) { /* out of memory */ - php_cli_server_log_response(client, 500, NULL TSRMLS_CC); + php_cli_server_log_response(client, 500, NULL); return FAILURE; } append_essential_headers(&buffer, client, 1); @@ -2102,31 +1999,31 @@ static int php_cli_server_begin_send_static(php_cli_server *server, php_cli_serv } smart_str_appendl_ex(&buffer, "\r\n", 2, 1); smart_str_appends_ex(&buffer, "Content-Length: ", 1); - smart_str_append_generic_ex(&buffer, client->request.sb.st_size, 1, size_t, _unsigned); + smart_str_append_unsigned_ex(&buffer, client->request.sb.st_size, 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); smart_str_appendl_ex(&buffer, "\r\n", 2, 1); - chunk = php_cli_server_chunk_heap_new(buffer.c, buffer.c, buffer.len); + chunk = php_cli_server_chunk_heap_new(buffer.s, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s)); if (!chunk) { - smart_str_free_ex(&buffer, 1); - php_cli_server_log_response(client, 500, NULL TSRMLS_CC); + smart_str_free(&buffer); + php_cli_server_log_response(client, 500, NULL); return FAILURE; } php_cli_server_buffer_append(&client->content_sender.buffer, chunk); } - php_cli_server_log_response(client, 200, NULL TSRMLS_CC); + php_cli_server_log_response(client, 200, NULL); php_cli_server_poller_add(&server->poller, POLLOUT, client->sock); return SUCCESS; } /* }}} */ -static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */ - char **auth; +static int php_cli_server_request_startup(php_cli_server *server, php_cli_server_client *client) { /* {{{ */ + char *auth; php_cli_server_client_populate_request_info(client, &SG(request_info)); - if (SUCCESS == zend_hash_find(&client->request.headers, "authorization", sizeof("authorization"), (void**)&auth)) { - php_handle_auth_data(*auth TSRMLS_CC); + if (NULL != (auth = zend_hash_str_find_ptr(&client->request.headers, "authorization", sizeof("authorization")-1))) { + php_handle_auth_data(auth); } SG(sapi_headers).http_response_code = 200; - if (FAILURE == php_request_startup(TSRMLS_C)) { + if (FAILURE == php_request_startup()) { /* should never be happen */ destroy_request_info(&SG(request_info)); return FAILURE; @@ -2137,9 +2034,9 @@ static int php_cli_server_request_startup(php_cli_server *server, php_cli_server } /* }}} */ -static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) { /* {{{ */ +static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_server_client *client) { /* {{{ */ php_request_shutdown(0); - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); destroy_request_info(&SG(request_info)); SG(server_context) = NULL; SG(rfc1867_uploaded_files) = NULL; @@ -2147,7 +2044,7 @@ static int php_cli_server_request_shutdown(php_cli_server *server, php_cli_serve } /* }}} */ -static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { int decline = 0; zend_file_handle zfd; @@ -2165,10 +2062,12 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server zfd.opened_path = NULL; zend_try { - zval *retval = NULL; - if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, &retval, 1, &zfd)) { - if (retval) { - decline = Z_TYPE_P(retval) == IS_BOOL && !Z_LVAL_P(retval); + zval retval; + + ZVAL_UNDEF(&retval); + if (SUCCESS == zend_execute_scripts(ZEND_REQUIRE, &retval, 1, &zfd)) { + if (Z_TYPE(retval) != IS_UNDEF) { + decline = Z_TYPE(retval) == IS_FALSE; zval_ptr_dtor(&retval); } } else { @@ -2186,7 +2085,7 @@ static int php_cli_server_dispatch_router(php_cli_server *server, php_cli_server } /* }}} */ -static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { int is_static_file = 0; @@ -2196,33 +2095,33 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client } if (server->router || !is_static_file) { - if (FAILURE == php_cli_server_request_startup(server, client TSRMLS_CC)) { + if (FAILURE == php_cli_server_request_startup(server, client)) { SG(server_context) = NULL; - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); destroy_request_info(&SG(request_info)); return SUCCESS; } } if (server->router) { - if (!php_cli_server_dispatch_router(server, client TSRMLS_CC)) { - php_cli_server_request_shutdown(server, client TSRMLS_CC); + if (!php_cli_server_dispatch_router(server, client)) { + php_cli_server_request_shutdown(server, client); return SUCCESS; } } if (!is_static_file) { - if (SUCCESS == php_cli_server_dispatch_script(server, client TSRMLS_CC) - || SUCCESS != php_cli_server_send_error_page(server, client, 500 TSRMLS_CC)) { + if (SUCCESS == php_cli_server_dispatch_script(server, client) + || SUCCESS != php_cli_server_send_error_page(server, client, 500)) { if (SG(sapi_headers).http_response_code == 304) { SG(sapi_headers).send_default_content_type = 0; } - php_cli_server_request_shutdown(server, client TSRMLS_CC); + php_cli_server_request_shutdown(server, client); return SUCCESS; } } else { if (server->router) { - static int (*send_header_func)(sapi_headers_struct * TSRMLS_DC); + static int (*send_header_func)(sapi_headers_struct *); send_header_func = sapi_module.send_headers; /* do not generate default content type header */ SG(sapi_headers).send_default_content_type = 0; @@ -2233,8 +2132,8 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client SG(sapi_headers).send_default_content_type = 1; SG(rfc1867_uploaded_files) = NULL; } - if (SUCCESS != php_cli_server_begin_send_static(server, client TSRMLS_CC)) { - php_cli_server_close_connection(server, client TSRMLS_CC); + if (SUCCESS != php_cli_server_begin_send_static(server, client)) { + php_cli_server_close_connection(server, client); } SG(server_context) = NULL; return SUCCESS; @@ -2246,10 +2145,29 @@ static int php_cli_server_dispatch(php_cli_server *server, php_cli_server_client } /* }}} */ -static void php_cli_server_dtor(php_cli_server *server TSRMLS_DC) /* {{{ */ +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) /* {{{ */ { zend_hash_destroy(&server->clients); - if (server->server_sock >= 0) { + zend_hash_destroy(&server->extension_mime_types); + if (ZEND_VALID_SOCKET(server->server_sock)) { closesocket(server->server_sock); } if (server->host) { @@ -2263,19 +2181,21 @@ static void php_cli_server_dtor(php_cli_server *server TSRMLS_DC) /* {{{ */ } } /* }}} */ -static void php_cli_server_client_dtor_wrapper(php_cli_server_client **p) /* {{{ */ +static void php_cli_server_client_dtor_wrapper(zval *zv) /* {{{ */ { - closesocket((*p)->sock); - php_cli_server_poller_remove(&(*p)->server->poller, POLLIN | POLLOUT, (*p)->sock); - php_cli_server_client_dtor(*p); - pefree(*p, 1); + php_cli_server_client *p = Z_PTR_P(zv); + + closesocket(p->sock); + php_cli_server_poller_remove(&p->server->poller, POLLIN | POLLOUT, p->sock); + php_cli_server_client_dtor(p); + pefree(p, 1); } /* }}} */ -static int php_cli_server_ctor(php_cli_server *server, const char *addr, const char *document_root, const char *router TSRMLS_DC) /* {{{ */ +static int php_cli_server_ctor(php_cli_server *server, const char *addr, const char *document_root, const char *router) /* {{{ */ { int retval = SUCCESS; char *host = NULL; - char *errstr = NULL; + zend_string *errstr = NULL; char *_document_root = NULL; char *_router = NULL; int err = 0; @@ -2320,10 +2240,12 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c goto out; } - server_sock = php_network_listen_socket(host, &port, SOCK_STREAM, &server->address_family, &server->socklen, &errstr TSRMLS_CC); + server_sock = php_network_listen_socket(host, &port, SOCK_STREAM, &server->address_family, &server->socklen, &errstr); if (server_sock == SOCK_ERR) { - php_cli_server_logf("Failed to listen on %s:%d (reason: %s)" TSRMLS_CC, host, port, errstr ? errstr: "?"); - efree(errstr); + php_cli_server_logf("Failed to listen on %s:%d (reason: %s)", host, port, errstr ? ZSTR_VAL(errstr) : "?"); + if (errstr) { + zend_string_release(errstr); + } retval = FAILURE; goto out; } @@ -2339,7 +2261,7 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c server->host = host; server->port = port; - zend_hash_init(&server->clients, 0, NULL, (void(*)(void*))php_cli_server_client_dtor_wrapper, 1); + zend_hash_init(&server->clients, 0, NULL, php_cli_server_client_dtor_wrapper, 1); { size_t document_root_len = strlen(document_root); @@ -2366,6 +2288,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) { @@ -2385,20 +2312,20 @@ out: return retval; } /* }}} */ -static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { char *errstr = NULL; - int status = php_cli_server_client_read_request(client, &errstr TSRMLS_CC); + int status = php_cli_server_client_read_request(client, &errstr); if (status < 0) { - php_cli_server_logf("%s Invalid request (%s)" TSRMLS_CC, client->addr_str, errstr); + php_cli_server_logf("%s Invalid request (%s)", client->addr_str, errstr); efree(errstr); - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); return FAILURE; } else if (status == 1 && client->request.request_method == PHP_HTTP_NOT_IMPLEMENTED) { - return php_cli_server_send_error_page(server, client, 501 TSRMLS_CC); + return php_cli_server_send_error_page(server, client, 501); } else if (status == 1) { php_cli_server_poller_remove(&server->poller, POLLIN, client->sock); - php_cli_server_dispatch(server, client TSRMLS_CC); + php_cli_server_dispatch(server, client); } else { php_cli_server_poller_add(&server->poller, POLLIN, client->sock); } @@ -2406,13 +2333,13 @@ static int php_cli_server_recv_event_read_request(php_cli_server *server, php_cl return SUCCESS; } /* }}} */ -static int php_cli_server_send_event(php_cli_server *server, php_cli_server_client *client TSRMLS_DC) /* {{{ */ +static int php_cli_server_send_event(php_cli_server *server, php_cli_server_client *client) /* {{{ */ { if (client->content_sender_initialized) { if (client->file_fd >= 0 && !client->content_sender.buffer.first) { size_t nbytes_read; if (php_cli_server_content_sender_pull(&client->content_sender, client->file_fd, &nbytes_read)) { - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); return FAILURE; } if (nbytes_read == 0) { @@ -2424,12 +2351,12 @@ static int php_cli_server_send_event(php_cli_server *server, php_cli_server_clie size_t nbytes_sent; int err = php_cli_server_content_sender_send(&client->content_sender, client->sock, &nbytes_sent); if (err && err != SOCK_EAGAIN) { - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); return FAILURE; } } if (!client->content_sender.buffer.first && client->file_fd < 0) { - php_cli_server_close_connection(server, client TSRMLS_CC); + php_cli_server_close_connection(server, client); } } return SUCCESS; @@ -2437,20 +2364,14 @@ static int php_cli_server_send_event(php_cli_server *server, php_cli_server_clie /* }}} */ typedef struct php_cli_server_do_event_for_each_fd_callback_params { -#ifdef ZTS - void ***tsrm_ls; -#endif php_cli_server *server; - int(*rhandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC); - int(*whandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC); + int(*rhandler)(php_cli_server*, php_cli_server_client*); + int(*whandler)(php_cli_server*, php_cli_server_client*); } php_cli_server_do_event_for_each_fd_callback_params; -static int php_cli_server_do_event_for_each_fd_callback(void *_params, int fd, int event) /* {{{ */ +static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socket_t fd, int event) /* {{{ */ { php_cli_server_do_event_for_each_fd_callback_params *params = _params; -#ifdef ZTS - void ***tsrm_ls = params->tsrm_ls; -#endif php_cli_server *server = params->server; if (server->server_sock == fd) { php_cli_server_client *client = NULL; @@ -2461,50 +2382,47 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, int fd, i return FAILURE; } client_sock = accept(server->server_sock, sa, &socklen); - if (client_sock < 0) { + if (!ZEND_VALID_SOCKET(client_sock)) { char *errstr; errstr = php_socket_strerror(php_socket_errno(), NULL, 0); - php_cli_server_logf("Failed to accept a client (reason: %s)" TSRMLS_CC, errstr); + php_cli_server_logf("Failed to accept a client (reason: %s)", errstr); efree(errstr); pefree(sa, 1); return SUCCESS; } - if (SUCCESS != php_set_sock_blocking(client_sock, 0 TSRMLS_CC)) { + if (SUCCESS != php_set_sock_blocking(client_sock, 0)) { pefree(sa, 1); closesocket(client_sock); return SUCCESS; } - if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen TSRMLS_CC)) { - php_cli_server_logf("Failed to create a new request object" TSRMLS_CC); + if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) { + php_cli_server_logf("Failed to create a new request object"); pefree(sa, 1); closesocket(client_sock); return SUCCESS; } #ifdef DEBUG - php_cli_server_logf("%s Accepted" TSRMLS_CC, client->addr_str); + php_cli_server_logf("%s Accepted", client->addr_str); #endif - zend_hash_index_update(&server->clients, client_sock, &client, sizeof(client), NULL); - php_cli_server_recv_event_read_request(server, client TSRMLS_CC); + zend_hash_index_update_ptr(&server->clients, client_sock, client); + php_cli_server_recv_event_read_request(server, client); } else { - php_cli_server_client **client; - if (SUCCESS == zend_hash_index_find(&server->clients, fd, (void **)&client)) { + php_cli_server_client *client; + if (NULL != (client = zend_hash_index_find_ptr(&server->clients, fd))) { if (event & POLLIN) { - params->rhandler(server, *client TSRMLS_CC); + params->rhandler(server, client); } if (event & POLLOUT) { - params->whandler(server, *client TSRMLS_CC); + params->whandler(server, client); } } } return SUCCESS; } /* }}} */ -static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rhandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC), int(*whandler)(php_cli_server*, php_cli_server_client* TSRMLS_DC) TSRMLS_DC) /* {{{ */ +static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rhandler)(php_cli_server*, php_cli_server_client*), int(*whandler)(php_cli_server*, php_cli_server_client*)) /* {{{ */ { php_cli_server_do_event_for_each_fd_callback_params params = { -#ifdef ZTS - tsrm_ls, -#endif server, rhandler, whandler @@ -2513,7 +2431,7 @@ static void php_cli_server_do_event_for_each_fd(php_cli_server *server, int(*rha php_cli_server_poller_iter_on_active(&server->poller, ¶ms, php_cli_server_do_event_for_each_fd_callback); } /* }}} */ -static int php_cli_server_do_event_loop(php_cli_server *server TSRMLS_DC) /* {{{ */ +static int php_cli_server_do_event_loop(php_cli_server *server) /* {{{ */ { int retval = SUCCESS; while (server->is_running) { @@ -2522,14 +2440,14 @@ static int php_cli_server_do_event_loop(php_cli_server *server TSRMLS_DC) /* {{{ if (n > 0) { php_cli_server_do_event_for_each_fd(server, php_cli_server_recv_event_read_request, - php_cli_server_send_event TSRMLS_CC); + php_cli_server_send_event); } else if (n == 0) { /* do nothing */ } else { int err = php_socket_errno(); if (err != SOCK_EINTR) { char *errstr = php_socket_strerror(err, NULL, 0); - php_cli_server_logf("%s" TSRMLS_CC, errstr); + php_cli_server_logf("%s", errstr); efree(errstr); retval = FAILURE; goto out; @@ -2548,7 +2466,7 @@ static void php_cli_server_sigint_handler(int sig) /* {{{ */ } /* }}} */ -int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ +int do_cli_server(int argc, char **argv) /* {{{ */ { char *php_optarg = NULL; int php_optind = 1; @@ -2571,9 +2489,9 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ } if (document_root) { - struct stat sb; + zend_stat_t sb; - if (stat(document_root, &sb)) { + if (zend_stat(document_root, &sb)) { fprintf(stderr, "Directory %s does not exist.\n", document_root); return 1; } @@ -2599,7 +2517,7 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ router = argv[php_optind]; } - if (FAILURE == php_cli_server_ctor(&server, server_bind_address, document_root, router TSRMLS_CC)) { + if (FAILURE == php_cli_server_ctor(&server, server_bind_address, document_root, router)) { return 1; } sapi_module.phpinfo_as_text = 0; @@ -2621,8 +2539,8 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ #if defined(HAVE_SIGNAL_H) && defined(SIGINT) signal(SIGINT, php_cli_server_sigint_handler); #endif - php_cli_server_do_event_loop(&server TSRMLS_CC); - php_cli_server_dtor(&server TSRMLS_CC); + php_cli_server_do_event_loop(&server); + php_cli_server_dtor(&server); return 0; } /* }}} */ diff --git a/sapi/cli/php_cli_server.h b/sapi/cli/php_cli_server.h index 45cfa52d46..d1092f65e1 100644 --- a/sapi/cli/php_cli_server.h +++ b/sapi/cli/php_cli_server.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -25,14 +25,15 @@ extern const zend_function_entry server_additional_functions[]; extern sapi_module_struct cli_server_sapi_module; -extern int do_cli_server(int argc, char **argv TSRMLS_DC); +extern int do_cli_server(int argc, char **argv); ZEND_BEGIN_MODULE_GLOBALS(cli_server) short color; ZEND_END_MODULE_GLOBALS(cli_server) #ifdef ZTS -#define CLI_SERVER_G(v) TSRMG(cli_server_globals_id, zend_cli_server_globals *, v) +#define CLI_SERVER_G(v) ZEND_TSRMG(cli_server_globals_id, zend_cli_server_globals *, v) +ZEND_TSRMLS_CACHE_EXTERN(); #else #define CLI_SERVER_G(v) (cli_server_globals.v) #endif diff --git a/sapi/cli/php_http_parser.c b/sapi/cli/php_http_parser.c index 73c6d4c1fe..aa9f28638f 100644 --- a/sapi/cli/php_http_parser.c +++ b/sapi/cli/php_http_parser.c @@ -91,6 +91,7 @@ static const char *method_strings[] = , "MOVE" , "PROPFIND" , "PROPPATCH" + , "SEARCH" , "UNLOCK" , "REPORT" , "MKACTIVITY" @@ -325,7 +326,8 @@ size_t php_http_parser_execute (php_http_parser *parser, const char *data, size_t len) { - char c, ch; + char ch; + signed char c; const char *p = data, *pe; size_t to_read; @@ -588,7 +590,7 @@ size_t php_http_parser_execute (php_http_parser *parser, case 'O': parser->method = PHP_HTTP_OPTIONS; break; case 'P': parser->method = PHP_HTTP_POST; /* or PROPFIND or PROPPATCH or PUT */ break; case 'R': parser->method = PHP_HTTP_REPORT; break; - case 'S': parser->method = PHP_HTTP_SUBSCRIBE; break; + case 'S': parser->method = PHP_HTTP_SUBSCRIBE; /* or SEARCH */ break; case 'T': parser->method = PHP_HTTP_TRACE; break; case 'U': parser->method = PHP_HTTP_UNLOCK; /* or UNSUBSCRIBE */ break; default: parser->method = PHP_HTTP_NOT_IMPLEMENTED; break; @@ -596,7 +598,6 @@ size_t php_http_parser_execute (php_http_parser *parser, state = s_req_method; break; } - case s_req_method: { const char *matcher; @@ -637,6 +638,8 @@ size_t php_http_parser_execute (php_http_parser *parser, parser->method = PHP_HTTP_PUT; } else if (index == 1 && parser->method == PHP_HTTP_POST && ch == 'A') { parser->method = PHP_HTTP_PATCH; + } else if (index == 1 && parser->method == PHP_HTTP_SUBSCRIBE && ch == 'E') { + parser->method = PHP_HTTP_SEARCH; } else if (index == 2 && parser->method == PHP_HTTP_UNLOCK && ch == 'S') { parser->method = PHP_HTTP_UNSUBSCRIBE; } else if (index == 4 && parser->method == PHP_HTTP_PROPFIND && ch == 'P') { @@ -1438,7 +1441,9 @@ size_t php_http_parser_execute (php_http_parser *parser, } case s_body_identity: - to_read = MIN(pe - p, (size_t)parser->content_length); + assert(pe >= p); + + to_read = MIN((size_t)(pe - p), (size_t)parser->content_length); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; @@ -1522,8 +1527,9 @@ size_t php_http_parser_execute (php_http_parser *parser, case s_chunk_data: { assert(parser->flags & F_CHUNKED); + assert(pe >= p); - to_read = MIN(pe - p, (size_t)(parser->content_length)); + to_read = MIN((size_t)(pe - p), (size_t)(parser->content_length)); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); diff --git a/sapi/cli/php_http_parser.h b/sapi/cli/php_http_parser.h index 31502e213a..402e7e3c83 100644 --- a/sapi/cli/php_http_parser.h +++ b/sapi/cli/php_http_parser.h @@ -90,6 +90,7 @@ enum php_http_method , PHP_HTTP_MOVE , PHP_HTTP_PROPFIND , PHP_HTTP_PROPPATCH + , PHP_HTTP_SEARCH , PHP_HTTP_UNLOCK /* subversion */ , PHP_HTTP_REPORT diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c index 3db77f76dc..2d95e494aa 100644 --- a/sapi/cli/ps_title.c +++ b/sapi/cli/ps_title.c @@ -109,6 +109,8 @@ extern char** environ; static char windows_error_details[64]; static char ps_buffer[MAX_PATH]; static const size_t ps_buffer_size = MAX_PATH; +typedef BOOL (WINAPI *MySetConsoleTitle)(LPCTSTR); +typedef DWORD (WINAPI *MyGetConsoleTitle)(LPTSTR, DWORD); #elif defined(PS_USE_CLOBBER_ARGV) static char *ps_buffer; /* will point to argv area */ static size_t ps_buffer_size; /* space determined at run time */ @@ -125,11 +127,13 @@ static size_t ps_buffer_cur_len; /* actual string length in ps_buffer */ static int save_argc; static char** save_argv; -/* +/* * This holds the 'locally' allocated environ from the save_ps_args method. * This is subsequently free'd at exit. */ +#if defined(PS_USE_CLOBBER_ARGV) static char** frozen_environ, **new_environ; +#endif /* * Call this method early, before any code has used the original argv passed in @@ -311,7 +315,7 @@ const char* ps_title_errno(int rc) #ifdef PS_USE_WIN32 case PS_TITLE_WINDOWS_ERROR: - sprintf(windows_error_details, "Windows error code: %d", GetLastError()); + sprintf(windows_error_details, "Windows error code: %lu", GetLastError()); return windows_error_details; #endif } @@ -365,8 +369,22 @@ int set_ps_title(const char* title) #ifdef PS_USE_WIN32 { - if (!SetConsoleTitle(ps_buffer)) + MySetConsoleTitle set_title = NULL; + HMODULE hMod = LoadLibrary("kernel32.dll"); + + if (!hMod) { + return PS_TITLE_WINDOWS_ERROR; + } + + /* NOTE we don't use _UNICODE*/ + set_title = (MySetConsoleTitle)GetProcAddress(hMod, "SetConsoleTitleA"); + if (!set_title) { + return PS_TITLE_WINDOWS_ERROR; + } + + if (!set_title(ps_buffer)) { return PS_TITLE_WINDOWS_ERROR; + } } #endif /* PS_USE_WIN32 */ @@ -386,8 +404,24 @@ int get_ps_title(int *displen, const char** string) return rc; #ifdef PS_USE_WIN32 - if (!(ps_buffer_cur_len = GetConsoleTitle(ps_buffer, ps_buffer_size))) - return PS_TITLE_WINDOWS_ERROR; + { + MyGetConsoleTitle get_title = NULL; + HMODULE hMod = LoadLibrary("kernel32.dll"); + + if (!hMod) { + return PS_TITLE_WINDOWS_ERROR; + } + + /* NOTE we don't use _UNICODE*/ + get_title = (MyGetConsoleTitle)GetProcAddress(hMod, "GetConsoleTitleA"); + if (!get_title) { + return PS_TITLE_WINDOWS_ERROR; + } + + if (!(ps_buffer_cur_len = get_title(ps_buffer, (DWORD)ps_buffer_size))) { + return PS_TITLE_WINDOWS_ERROR; + } + } #endif *displen = (int)ps_buffer_cur_len; *string = ps_buffer; diff --git a/sapi/cli/ps_title.h b/sapi/cli/ps_title.h index d0bb2322c2..ee13cbe187 100644 --- a/sapi/cli/ps_title.h +++ b/sapi/cli/ps_title.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt index dff654a963..5a1e8b8fb1 100644 --- a/sapi/cli/tests/005.phpt +++ b/sapi/cli/tests/005.phpt @@ -40,7 +40,7 @@ string(183) "Class [ <internal:Core> class stdClass ] { } " -string(1418) "Class [ <internal:Core> class Exception ] { +string(1607) "Class [ <internal:Core> class Exception implements Throwable ] { - Constants [0] { } @@ -77,28 +77,28 @@ string(1418) "Class [ <internal:Core> class Exception ] { Method [ <internal:Core> public method __wakeup ] { } - Method [ <internal:Core> final public method getMessage ] { + Method [ <internal:Core, prototype Throwable> final public method getMessage ] { } - Method [ <internal:Core> final public method getCode ] { + Method [ <internal:Core, prototype Throwable> final public method getCode ] { } - Method [ <internal:Core> final public method getFile ] { + Method [ <internal:Core, prototype Throwable> final public method getFile ] { } - Method [ <internal:Core> final public method getLine ] { + Method [ <internal:Core, prototype Throwable> final public method getLine ] { } - Method [ <internal:Core> final public method getTrace ] { + Method [ <internal:Core, prototype Throwable> final public method getTrace ] { } - Method [ <internal:Core> final public method getPrevious ] { + Method [ <internal:Core, prototype Throwable> final public method getPrevious ] { } - Method [ <internal:Core> final public method getTraceAsString ] { + Method [ <internal:Core, prototype Throwable> final public method getTraceAsString ] { } - Method [ <internal:Core> public method __toString ] { + Method [ <internal:Core, prototype Throwable> public method __toString ] { } } } diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index 3d5c916e9c..b24da56660 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -25,7 +25,7 @@ string(44) "Exception: Extension unknown does not exist " string(37) "Exception: Extension does not exist " -string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] { +string(%d) "Extension [ <persistent> extension #%d pcre version %s ] { - INI { Entry [ pcre.backtrack_limit <ALL> ] @@ -34,9 +34,12 @@ string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] { Entry [ pcre.recursion_limit <ALL> ] Current = '%d' } + Entry [ pcre.jit <ALL> ] + Current = '%d' + } } - - Constants [14] { + - Constants [15] { Constant [ integer PREG_PATTERN_ORDER ] { 1 } Constant [ integer PREG_SET_ORDER ] { 2 } Constant [ integer PREG_OFFSET_CAPTURE ] { 256 } @@ -50,6 +53,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] { Constant [ integer PREG_RECURSION_LIMIT_ERROR ] { 3 } Constant [ integer PREG_BAD_UTF8_ERROR ] { 4 } Constant [ integer PREG_BAD_UTF8_OFFSET_ERROR ] { 5 } + Constant [ integer PREG_JIT_STACKLIMIT_ERROR ] { 6 } Constant [ string PCRE_VERSION ] { %s } } @@ -94,6 +98,15 @@ string(%d) "Extension [ <persistent> extension #%d pcre version <no_version> ] { Parameter #4 [ <optional> &$count ] } } + Function [ <internal:pcre> function preg_replace_callback_array ] { + + - Parameters [4] { + Parameter #0 [ <required> $pattern ] + Parameter #1 [ <required> $subject ] + Parameter #2 [ <optional> $limit ] + Parameter #3 [ <optional> &$count ] + } + } Function [ <internal:pcre> function preg_filter ] { - Parameters [5] { diff --git a/sapi/cli/tests/008.phpt b/sapi/cli/tests/008.phpt index e14338f5f5..0121d94a27 100644 --- a/sapi/cli/tests/008.phpt +++ b/sapi/cli/tests/008.phpt @@ -36,7 +36,10 @@ echo "Done\n"; --EXPECTF-- string(%d) " -Fatal error: Cannot access private property test::$pri in %s on line %d +Fatal error: Uncaught Error: Cannot access private property test::$pri in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d " string(33) "Could not open input file: wrong " diff --git a/sapi/cli/tests/bug43177.phpt b/sapi/cli/tests/bug43177.phpt index a97769cf8f..23af545908 100644 --- a/sapi/cli/tests/bug43177.phpt +++ b/sapi/cli/tests/bug43177.phpt @@ -11,7 +11,10 @@ php_cli_server_start(<<<'SCRIPT' ini_set('display_errors', 0); switch($_SERVER["REQUEST_URI"]) { case "/parse": - eval("this is a parse error"); + try { + eval("this is a parse error"); + } catch (ParseError $e) { + } echo "OK\n"; break; case "/fatal": diff --git a/sapi/cli/tests/bug61977.phpt b/sapi/cli/tests/bug61977.phpt index d897737c3c..218641a511 100644 --- a/sapi/cli/tests/bug61977.phpt +++ b/sapi/cli/tests/bug61977.phpt @@ -48,7 +48,7 @@ foo.html => Content-Type: text/html; charset=UTF-8 foo.htm => Content-Type: text/html; charset=UTF-8 foo.svg => Content-Type: image/svg+xml foo.css => Content-Type: text/css; charset=UTF-8 -foo.js => Content-Type: text/javascript; charset=UTF-8 +foo.js => Content-Type: application/javascript foo.png => Content-Type: image/png foo.webm => Content-Type: video/webm foo.ogv => Content-Type: video/ogg diff --git a/sapi/cli/tests/bug70006.phpt b/sapi/cli/tests/bug70006.phpt new file mode 100644 index 0000000000..855c9e1f80 --- /dev/null +++ b/sapi/cli/tests/bug70006.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #70006 (cli - function with default arg = STDOUT crash output) +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php + +function foo1($stream = STDOUT) +{ + //do nothing +} +foo1(); +?> +okey +--EXPECT-- +okey diff --git a/sapi/cli/tests/bug71005.phpt b/sapi/cli/tests/bug71005.phpt new file mode 100644 index 0000000000..3a60dcf42f --- /dev/null +++ b/sapi/cli/tests/bug71005.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #71005 (Segfault in php_cli_server_dispatch_router()) +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php + +$code = <<<'EOF' +set_exception_handler(function () { echo 'goodbye'; }); +throw new Exception; +EOF; + +include "php_cli_server.inc"; +php_cli_server_start($code); + +list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); +$port = intval($port) ?: 80; + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} + +if(fwrite($fp, <<<HEADER +GET / HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + echo fgets($fp); + } +} + +?> +--EXPECTF-- +HTTP/1.1 200 OK +Host: %s +Connection: close +X-Powered-By: PHP/%s +Content-type: text/html; charset=UTF-8 + +goodbye diff --git a/sapi/cli/tests/php_cli_server_015.phpt b/sapi/cli/tests/php_cli_server_015.phpt index e3d8c4170d..af0a3f65a8 100644 --- a/sapi/cli/tests/php_cli_server_015.phpt +++ b/sapi/cli/tests/php_cli_server_015.phpt @@ -46,4 +46,8 @@ X-Powered-By: PHP/%s Content-type: text/html; charset=UTF-8 <br /> -<b>Fatal error</b>: Call to undefined function non_exists_function() in <b>%ssyntax_error.php</b> on line <b>%s</b><br /> +<b>Fatal error</b>: Uncaught Error: Call to undefined function non_exists_function() in %ssyntax_error.php:%d +Stack trace: +#0 %sindex.php(%d): require() +#1 {main} + thrown in <b>%ssyntax_error.php</b> on line <b>%d</b><br /> diff --git a/sapi/cli/tests/php_cli_server_020.phpt b/sapi/cli/tests/php_cli_server_020.phpt new file mode 100644 index 0000000000..4ed673d380 --- /dev/null +++ b/sapi/cli/tests/php_cli_server_020.phpt @@ -0,0 +1,40 @@ +--TEST-- +Use SEARCH as a HTTP verb +--SKIPIF-- +<?php +include "skipif.inc"; +?> +--FILE-- +<?php +include "php_cli_server.inc"; +php_cli_server_start('var_dump($_SERVER["REQUEST_METHOD"]);'); + +list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); +$port = intval($port) ?: 80; + +$fp = fsockopen($host, $port, $errno, $errstr, 0.5); +if (!$fp) { + die("connect failed"); +} + +if(fwrite($fp, <<<HEADER +SEARCH / HTTP/1.1 +Host: {$host} + + +HEADER +)) { + while (!feof($fp)) { + echo fgets($fp); + } +} + +?> +--EXPECTF-- +HTTP/1.1 200 OK +Host: %s +Connection: close +X-Powered-By: PHP/%s +Content-type: text/html; charset=UTF-8 + +string(6) "SEARCH" |