Skip to content

Commit 3964b8f

Browse files
committed
split off pecl_http
1 parent 5c72938 commit 3964b8f

10 files changed

+467
-0
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.deps
2+
*.lo
3+
*.la
4+
.libs
5+
acinclude.m4
6+
aclocal.m4
7+
autom4te.cache
8+
build
9+
config.guess
10+
config.h
11+
config.h.in
12+
config.log
13+
config.nice
14+
config.status
15+
config.sub
16+
configure
17+
configure.in
18+
include
19+
install-sh
20+
libtool
21+
ltmain.sh
22+
Makefile
23+
Makefile.fragments
24+
Makefile.global
25+
Makefile.objects
26+
missing
27+
mkinstalldirs
28+
modules
29+
run-tests.php
30+
tests/*/*.diff
31+
tests/*/*.out
32+
tests/*/*.php
33+
tests/*/*.exp
34+
tests/*/*.log
35+
tests/*/*.sh
36+
php_json_post.o

CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
json_post
2+
Michael Wallner

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015, Michael Wallner <[email protected]>.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
17+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

config.m4

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PHP_ARG_ENABLE(json-post, whether to enable json-post support,
2+
[ --enable-json-post Enable json-post support])
3+
4+
if test "$PHP_JSON_POST" != "no"; then
5+
PHP_NEW_EXTENSION(json_post, php_json_post.c, $ext_shared)
6+
PHP_ADD_EXTENSION_DEP(json_post, json, true)
7+
fi

config.w32

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ARG_ENABLE("json-post", "enable json_post support", "no");
2+
3+
if (PHP_JSON_POST != "no") {
4+
EXTENSION("json_post", "php_json_post.c");
5+
}

package.xml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
3+
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="
6+
http://pear.php.net/dtd/tasks-1.0
7+
http://pear.php.net/dtd/tasks-1.0.xsd
8+
http://pear.php.net/dtd/package-2.0
9+
http://pear.php.net/dtd/package-2.0.xsd">
10+
<name>json_post</name>
11+
<channel>pecl.php.net</channel>
12+
<summary>JSON POST handler</summary>
13+
<description><![CDATA[
14+
This extension provides a PHP content type handler for "text/json" to PHP's
15+
form data parser. If the `Content-Type` of an incoming request is `text/json`,
16+
the JSON contents of the request body will by parsed into `$_POST`.
17+
18+
This extension does not provide any constants, functions or classes.
19+
]]></description>
20+
<lead>
21+
<name>Michael Wallner</name>
22+
<user>mike</user>
23+
<email>[email protected]</email>
24+
<active>yes</active>
25+
</lead>
26+
<date>2015-03-01</date>
27+
<version>
28+
<release>1.0.0</release>
29+
<api>1.0.0</api>
30+
</version>
31+
<stability>
32+
<release>stable</release>
33+
<api>stable</api>
34+
</stability>
35+
<license>BSD, revised</license>
36+
<notes><![CDATA[
37+
* Split off pecl_http
38+
]]></notes>
39+
<contents>
40+
<dir name="/">
41+
<file role="doc" name="LICENSE"/>
42+
<file role="doc" name="CREDITS"/>
43+
<file role="src" name="config.m4"/>
44+
<file role="src" name="config.w32"/>
45+
46+
<file role="src" name="php_json_post.h"/>
47+
<file role="src" name="php_json_post.c"/>
48+
49+
<dir name="tests">
50+
<file role="test" name="001.phpt"/>
51+
<file role="test" name="002.phpt"/>
52+
</dir>
53+
</dir>
54+
</contents>
55+
<dependencies>
56+
<required>
57+
<php>
58+
<min>5.3.0</min>
59+
</php>
60+
<pearinstaller>
61+
<min>1.4.1</min>
62+
</pearinstaller>
63+
<extension>
64+
<name>json</name>
65+
</extension>
66+
</required>
67+
</dependencies>
68+
<providesextension>json_post</providesextension>
69+
<extsrcrelease/>
70+
<changelog />
71+
</package>

php_json_post.c

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
+--------------------------------------------------------------------+
3+
| PECL :: json_post |
4+
+--------------------------------------------------------------------+
5+
| Redistribution and use in source and binary forms, with or without |
6+
| modification, are permitted provided that the conditions mentioned |
7+
| in the accompanying LICENSE file are met. |
8+
+--------------------------------------------------------------------+
9+
| Copyright (c) 2015, Michael Wallner <[email protected]> |
10+
+--------------------------------------------------------------------+
11+
*/
12+
13+
14+
#ifdef HAVE_CONFIG_H
15+
# include "config.h"
16+
#endif
17+
18+
#include "php.h"
19+
#include "php_ini.h"
20+
#include "ext/standard/info.h"
21+
#include "ext/json/php_json.h"
22+
#include "php_json_post.h"
23+
#include "SAPI.h"
24+
25+
ZEND_DECLARE_MODULE_GLOBALS(json_post);
26+
27+
PHP_INI_BEGIN()
28+
STD_PHP_INI_ENTRY("json_post.flags", "1", PHP_INI_PERDIR, OnUpdateLong, flags, zend_json_post_globals, json_post_globals)
29+
PHP_INI_END()
30+
31+
static void php_json_post_init_globals(zend_json_post_globals *json_post_globals)
32+
{
33+
json_post_globals->flags = PHP_JSON_OBJECT_AS_ARRAY;
34+
}
35+
36+
PHP_MINFO_FUNCTION(json_post)
37+
{
38+
php_info_print_table_start();
39+
php_info_print_table_header(2, "json_post support", "enabled");
40+
php_info_print_table_end();
41+
42+
DISPLAY_INI_ENTRIES();
43+
}
44+
45+
static SAPI_POST_HANDLER_FUNC(php_json_post_handler)
46+
{
47+
zval *zarg = arg;
48+
char *json_str = NULL;
49+
size_t json_len = 0;
50+
51+
#if PHP_VERSION_ID >= 50600
52+
if (SG(request_info).request_body) {
53+
/* FG(stream_wrappers) not initialized yet, so we cannot use php://input */
54+
php_stream_rewind(SG(request_info).request_body);
55+
json_len = php_stream_copy_to_mem(SG(request_info).request_body, &json_str, PHP_STREAM_COPY_ALL, 0);
56+
}
57+
#else
58+
json_str = SG(request_info).raw_post_data;
59+
json_len = SG(request_info).raw_post_data_length;
60+
#endif
61+
62+
if (json_len) {
63+
zval zjson;
64+
65+
INIT_ZVAL(zjson);
66+
php_json_decode_ex(&zjson, json_str, json_len, JSON_POST_G(flags), PG(max_input_nesting_level) TSRMLS_CC);
67+
if (Z_TYPE(zjson) != IS_NULL) {
68+
zval_dtor(zarg);
69+
ZVAL_COPY_VALUE(zarg, (&zjson));
70+
}
71+
}
72+
#if PHP_VERSION_ID >= 50600
73+
if (json_str) {
74+
efree(json_str);
75+
}
76+
#endif
77+
}
78+
79+
PHP_MINIT_FUNCTION(json_post)
80+
{
81+
sapi_post_entry entry = {NULL, 0, NULL, NULL};
82+
83+
entry.post_reader = sapi_read_standard_form_data;
84+
entry.post_handler = php_json_post_handler;
85+
86+
entry.content_type = "text/json";
87+
entry.content_type_len = sizeof("text/json")-1;
88+
sapi_register_post_entry(&entry TSRMLS_CC);
89+
90+
ZEND_INIT_MODULE_GLOBALS(json_post, php_json_post_init_globals, NULL);
91+
REGISTER_INI_ENTRIES();
92+
return SUCCESS;
93+
}
94+
95+
PHP_MSHUTDOWN_FUNCTION(json_post)
96+
{
97+
UNREGISTER_INI_ENTRIES();
98+
99+
return SUCCESS;
100+
}
101+
102+
zend_function_entry json_post_functions[] = {
103+
{0}
104+
};
105+
106+
static zend_module_dep json_post_module_deps[] = {
107+
ZEND_MOD_REQUIRED("json")
108+
{NULL, NULL, NULL, 0}
109+
};
110+
111+
zend_module_entry json_post_module_entry = {
112+
STANDARD_MODULE_HEADER_EX,
113+
NULL,
114+
json_post_module_deps,
115+
"json_post",
116+
json_post_functions,
117+
PHP_MINIT(json_post),
118+
PHP_MSHUTDOWN(json_post),
119+
NULL,
120+
NULL,
121+
PHP_MINFO(json_post),
122+
PHP_JSON_POST_VERSION,
123+
STANDARD_MODULE_PROPERTIES
124+
};
125+
/* }}} */
126+
127+
#ifdef COMPILE_DL_JSON_POST
128+
ZEND_GET_MODULE(json_post)
129+
#endif
130+
131+
/*
132+
* Local variables:
133+
* tab-width: 4
134+
* c-basic-offset: 4
135+
* End:
136+
* vim600: noet sw=4 ts=4 fdm=marker
137+
* vim<600: noet sw=4 ts=4
138+
*/

php_json_post.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
+--------------------------------------------------------------------+
3+
| PECL :: json_post |
4+
+--------------------------------------------------------------------+
5+
| Redistribution and use in source and binary forms, with or without |
6+
| modification, are permitted provided that the conditions mentioned |
7+
| in the accompanying LICENSE file are met. |
8+
+--------------------------------------------------------------------+
9+
| Copyright (c) 2015, Michael Wallner <[email protected]> |
10+
+--------------------------------------------------------------------+
11+
*/
12+
13+
#ifndef PHP_JSON_POST_H
14+
#define PHP_JSON_POST_H
15+
16+
extern zend_module_entry json_post_module_entry;
17+
#define phpext_json_post_ptr &json_post_module_entry
18+
19+
#define PHP_JSON_POST_VERSION "1.0.0"
20+
21+
#ifdef PHP_WIN32
22+
# define PHP_JSON_POST_API __declspec(dllexport)
23+
#elif defined(__GNUC__) && __GNUC__ >= 4
24+
# define PHP_JSON_POST_API extern __attribute__ ((visibility("default")))
25+
#else
26+
# define PHP_JSON_POST_API extern
27+
#endif
28+
29+
#ifdef ZTS
30+
# include "TSRM.h"
31+
#endif
32+
33+
ZEND_BEGIN_MODULE_GLOBALS(json_post)
34+
long flags;
35+
ZEND_END_MODULE_GLOBALS(json_post)
36+
37+
ZEND_EXTERN_MODULE_GLOBALS(json_post);
38+
39+
#ifdef ZTS
40+
# define JSON_POST_G(v) TSRMG(json_post_globals_id, zend_json_post_globals *, v)
41+
#else
42+
# define JSON_POST_G(v) (json_post_globals.v)
43+
#endif
44+
45+
#endif /* PHP_JSON_POST_H */
46+
47+
/*
48+
* Local variables:
49+
* tab-width: 4
50+
* c-basic-offset: 4
51+
* End:
52+
* vim600: noet sw=4 ts=4 fdm=marker
53+
* vim<600: noet sw=4 ts=4
54+
*/

0 commit comments

Comments
 (0)