From: Michael Wallner Date: Thu, 5 Mar 2015 06:44:21 +0000 (+0100) Subject: split off pecl_http X-Git-Tag: v1.0.0RC1~4 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-apfd;a=commitdiff_plain;h=1e92ec497c976bab5ef610663f84600d735101c6 split off pecl_http --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42e064e --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +.deps +*.lo +*.la +.libs +acinclude.m4 +aclocal.m4 +autom4te.cache +build +config.guess +config.h +config.h.in +config.log +config.nice +config.status +config.sub +configure +configure.in +include +install-sh +libtool +ltmain.sh +Makefile +Makefile.fragments +Makefile.global +Makefile.objects +missing +mkinstalldirs +modules +run-tests.php +tests/*/*.diff +tests/*/*.out +tests/*/*.php +tests/*/*.exp +tests/*/*.log +tests/*/*.sh +php_apfd.o diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..0968dc2 --- /dev/null +++ b/CREDITS @@ -0,0 +1,2 @@ +apfd +Michael Wallner diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b49d8ed --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015, Michael Wallner . +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/config.m4 b/config.m4 new file mode 100644 index 0000000..6674c72 --- /dev/null +++ b/config.m4 @@ -0,0 +1,6 @@ +PHP_ARG_ENABLE(apfd, whether to enable apfd support, +[ --enable-apfd Enable always-populate-form-data support]) + +if test "$PHP_APFD" != "no"; then + PHP_NEW_EXTENSION(apfd, php_apfd.c, $ext_shared) +fi diff --git a/config.w32 b/config.w32 new file mode 100644 index 0000000..c4cab2e --- /dev/null +++ b/config.w32 @@ -0,0 +1,5 @@ +ARG_ENABLE("apfd", "enable apfd support", "no"); + +if (PHP_APFD != "no") { + EXTENSION("apfd", "php_apfd.c"); +} diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..16a0181 --- /dev/null +++ b/package.xml @@ -0,0 +1,69 @@ + + + apfd + pecl.php.net + Always Populate Form Data + + + Michael Wallner + mike + mike@php.net + yes + + 2015-03-01 + + 1.0.0 + 1.0.0 + + + stable + stable + + BSD, revised + + + + + + + + + + + + + + + + + + + + + 5.3.0 + + + 1.4.1 + + + + apfd + + + diff --git a/php_apfd.c b/php_apfd.c new file mode 100644 index 0000000..8270fcb --- /dev/null +++ b/php_apfd.c @@ -0,0 +1,112 @@ +/* + +--------------------------------------------------------------------+ + | PECL :: apfd | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2015, Michael Wallner | + +--------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" +#include "SAPI.h" +#include "php_apfd.h" + +PHP_RINIT_FUNCTION(apfd) +{ + /* populate form data on non-POST requests */ + if (SG(request_info).request_method && strcasecmp(SG(request_info).request_method, "POST") && SG(request_info).content_type && *SG(request_info).content_type) { + char *ct_str = zend_str_tolower_dup(SG(request_info).content_type, strlen(SG(request_info).content_type)); + size_t ct_end = strcspn(ct_str, ";, "); + sapi_post_entry *post_entry = NULL; + char delim; + + SG(request_info).content_type_dup = ct_str; + + delim = ct_str[ct_end]; + ct_str[ct_end] = '\0'; + + if (SUCCESS == zend_hash_find(&SG(known_post_content_types), ct_str, ct_end+1, (void *) &post_entry)) { + zval *files = PG(http_globals)[TRACK_VARS_FILES]; + + ct_str[ct_end] = delim; + + if (post_entry) { + SG(request_info).post_entry = post_entry; + + if (post_entry->post_reader) { + post_entry->post_reader(TSRMLS_C); + } + } + + if (sapi_module.default_post_reader) { + sapi_module.default_post_reader(TSRMLS_C); + } + + sapi_handle_post(PG(http_globals)[TRACK_VARS_POST] TSRMLS_CC); + + /* + * the rfc1867 handler is an awkward buddy + */ + if (files != PG(http_globals)[TRACK_VARS_FILES] && PG(http_globals)[TRACK_VARS_FILES]) { + Z_ADDREF_P(PG(http_globals)[TRACK_VARS_FILES]); + zend_hash_update(&EG(symbol_table), "_FILES", sizeof("_FILES"), &PG(http_globals)[TRACK_VARS_FILES], sizeof(zval *), NULL); + if (files) { + zval_ptr_dtor(&files); + } + } + } + + if (SG(request_info).content_type_dup) { + efree(SG(request_info).content_type_dup); + SG(request_info).content_type_dup = NULL; + } + } + + return SUCCESS; +} + +PHP_MINFO_FUNCTION(apfd) +{ + php_info_print_table_start(); + php_info_print_table_header(2, "apfd support", "enabled"); + php_info_print_table_end(); +} + +const zend_function_entry apfd_functions[] = { + {0} +}; + +zend_module_entry apfd_module_entry = { + STANDARD_MODULE_HEADER, + "apfd", + apfd_functions, + NULL, + NULL, + PHP_RINIT(apfd), + NULL, + PHP_MINFO(apfd), + PHP_APFD_VERSION, + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_APFD +ZEND_GET_MODULE(apfd) +#endif + +/* + * 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/php_apfd.h b/php_apfd.h new file mode 100644 index 0000000..e248688 --- /dev/null +++ b/php_apfd.h @@ -0,0 +1,43 @@ +/* + +--------------------------------------------------------------------+ + | PECL :: apfd | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2015, Michael Wallner | + +--------------------------------------------------------------------+ +*/ + +#ifndef PHP_APFD_H +#define PHP_APFD_H + +extern zend_module_entry apfd_module_entry; +#define phpext_apfd_ptr &apfd_module_entry + +#define PHP_APFD_VERSION "1.0.0" + +#ifdef PHP_WIN32 +# define PHP_APFD_API __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define PHP_APFD_API extern __attribute__ ((visibility("default"))) +#else +# define PHP_APFD_API extern +#endif + +#ifdef ZTS +# include "TSRM.h" +#endif + +#endif /* PHP_APFD_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/tests/001.phpt b/tests/001.phpt new file mode 100644 index 0000000..ed20f71 --- /dev/null +++ b/tests/001.phpt @@ -0,0 +1,22 @@ +--TEST-- +apfd +--SKIPIF-- + +--PUT-- +Content-Type: application/x-www-form-urlencoded +foo=bar&bar=foo +--FILE-- + +--EXPECT-- +array(2) { + ["foo"]=> + string(3) "bar" + ["bar"]=> + string(3) "foo" +} diff --git a/tests/002.phpt b/tests/002.phpt new file mode 100644 index 0000000..c4e008c --- /dev/null +++ b/tests/002.phpt @@ -0,0 +1,102 @@ +--TEST-- +apfd +--SKIPIF-- + +--PUT-- +Content-Type: multipart/form-data; boundary=----------------------------6e182425881c +------------------------------6e182425881c +Content-Disposition: form-data; name="LICENSE"; filename="LICENSE" +Content-Type: application/octet-stream + +Copyright (c) 2011-2012, Michael Wallner . +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +------------------------------6e182425881c +Content-Disposition: form-data; name="composer"; filename="composer.json" +Content-Type: application/octet-stream + +{ + "name": "m6w6/autocracy", + "type": "library", + "description": "http\\Controller preserves your autocracy", + "keywords": ["http", "controller", "pecl", "pecl_http"], + "homepage": "http://github.com/m6w6/autocracy", + "license": "BSD-2", + "authors": [ + { + "name": "Michael Wallner", + "email": "mike@php.net" + } + ], + "require": { + "php": ">=5.4.0", + "pecl/pecl_http": "2.*" + }, + "autoload": { + "psr-0": { + "http\\Controller": "lib" + } + } +} + +------------------------------6e182425881c-- +--FILE-- + +--EXPECTF-- +array(0) { +} +array(2) { + ["LICENSE"]=> + array(5) { + ["name"]=> + string(7) "LICENSE" + ["type"]=> + string(24) "application/octet-stream" + ["tmp_name"]=> + string(66) "%sphp%s" + ["error"]=> + int(0) + ["size"]=> + int(1353) + } + ["composer"]=> + array(5) { + ["name"]=> + string(13) "composer.json" + ["type"]=> + string(24) "application/octet-stream" + ["tmp_name"]=> + string(66) "%sphp%s" + ["error"]=> + int(0) + ["size"]=> + int(550) + } +} \ No newline at end of file