split off pecl_http
authorMichael Wallner <mike@php.net>
Thu, 5 Mar 2015 06:44:21 +0000 (07:44 +0100)
committerMichael Wallner <mike@php.net>
Thu, 5 Mar 2015 06:47:00 +0000 (07:47 +0100)
.gitignore [new file with mode: 0644]
CREDITS [new file with mode: 0644]
LICENSE [new file with mode: 0644]
config.m4 [new file with mode: 0644]
config.w32 [new file with mode: 0644]
package.xml [new file with mode: 0644]
php_apfd.c [new file with mode: 0644]
php_apfd.h [new file with mode: 0644]
tests/001.phpt [new file with mode: 0644]
tests/002.phpt [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..42e064e
--- /dev/null
@@ -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 (file)
index 0000000..0968dc2
--- /dev/null
+++ b/CREDITS
@@ -0,0 +1,2 @@
+apfd
+Michael Wallner
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..b49d8ed
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2015, Michael Wallner <mike@iworks.at>.
+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 (file)
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 (file)
index 0000000..c4cab2e
--- /dev/null
@@ -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 (file)
index 0000000..16a0181
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
+ xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+  http://pear.php.net/dtd/tasks-1.0
+  http://pear.php.net/dtd/tasks-1.0.xsd
+  http://pear.php.net/dtd/package-2.0
+  http://pear.php.net/dtd/package-2.0.xsd">
+ <name>apfd</name>
+ <channel>pecl.php.net</channel>
+ <summary>Always Populate Form Data</summary>
+ <description><![CDATA[
+This tiny extension lets PHP's post handler parse `multipart/form-data` and
+`application/x-www-form-urlencoded` (or any other customly registered form data
+handler, like "json_post") without regard to the request's request method.
+
+This extension does not provide any INI entries, constants, functions or classes.
+
+]]></description>
+ <lead>
+  <name>Michael Wallner</name>
+  <user>mike</user>
+  <email>mike@php.net</email>
+  <active>yes</active>
+ </lead>
+ <date>2015-03-01</date>
+ <version>
+  <release>1.0.0</release>
+  <api>1.0.0</api>
+ </version>
+ <stability>
+  <release>stable</release>
+  <api>stable</api>
+ </stability>
+ <license>BSD, revised</license>
+ <notes><![CDATA[
+* Split off pecl_http
+]]></notes>
+ <contents>
+  <dir name="/">
+   <file role="doc" name="LICENSE"/>
+   <file role="doc" name="CREDITS"/>
+   <file role="src" name="config.m4"/>
+   <file role="src" name="config.w32"/>
+
+   <file role="src" name="php_apfd.h"/>
+   <file role="src" name="php_apfd.c"/>
+
+   <dir name="tests">
+     <file role="test" name="001.phpt"/>
+     <file role="test" name="002.phpt"/>
+   </dir>
+  </dir>
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.3.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.4.1</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <providesextension>apfd</providesextension>
+ <extsrcrelease/>
+ <changelog />
+</package>
diff --git a/php_apfd.c b/php_apfd.c
new file mode 100644 (file)
index 0000000..8270fcb
--- /dev/null
@@ -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 <mike@php.net>                 |
+    +--------------------------------------------------------------------+
+*/
+
+#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 (file)
index 0000000..e248688
--- /dev/null
@@ -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 <mike@php.net>                 |
+    +--------------------------------------------------------------------+
+*/
+
+#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 (file)
index 0000000..ed20f71
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+apfd
+--SKIPIF--
+<?php
+extension_loaded("apfd") or die("skip need apfd support\n");
+?>
+--PUT--
+Content-Type: application/x-www-form-urlencoded
+foo=bar&bar=foo
+--FILE--
+<?php
+
+var_dump($_POST);
+
+?>
+--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 (file)
index 0000000..c4e008c
--- /dev/null
@@ -0,0 +1,102 @@
+--TEST--
+apfd
+--SKIPIF--
+<?php
+extension_loaded("apfd") or die("skip need apfd support\n");
+?>
+--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 <mike@iworks.at>.
+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--
+<?php
+
+var_dump($_POST, $_FILES);
+
+?>
+--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