Skip to content

Commit 4826b94

Browse files
committed
Merge pull request #16 from zelgerj/master
fixed memory leaks. added new function
2 parents 9be1394 + 88268c9 commit 4826b94

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Registeres an uploaded file top super global hash table rfc1867_uploaded_files a
4343
#####appserver_set_headers_sent(boolean $sent)
4444
If you want to reset the flag that headers already sent while runtime you can easly do it with this function by calling appserver_set_headers_sent(false);
4545

46+
#####appserver_set_raw_post_data(string $postData)
47+
To have the raw post data available in php://input you can simple use this function. I'll be available in $HTTP_RAW_POST_DATA too.
4648

4749
# Debug on Mac OS X
4850

build.default.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
# ---- General Settings ---------------------------------------------------------
1111
php.ext.name = appserver
12-
php.sapi.name = appserver
1312

14-
release.version = 0.1.6
13+
release.version = 0.1.7
1514
release.stability = beta
16-
api.version = 0.1.6
15+
api.version = 0.1.7
1716
api.stability = beta
1817

1918
php.version = 5.5.10
@@ -41,7 +40,7 @@ php.configure = --prefix=/opt/appserver \
4140
--with-zlib \
4241
4342
zmq.version = dev-master
44-
pthreads.version = 1.0.1
43+
pthreads.version = 2.0.4
4544
memcached.version = 2.1.0
4645
redis.version = 2.2.3
4746
apcu.version = 4.0.2

src/appserver.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const zend_function_entry appserver_functions[] = {
5454
PHP_FE(appserver_register_file_upload, NULL)
5555
PHP_FE(appserver_set_headers_sent, NULL)
5656
PHP_FE(appserver_redefine, NULL)
57+
PHP_FE(appserver_set_raw_post_data, NULL)
5758
PHP_FE_END
5859
};
5960

@@ -207,25 +208,16 @@ PHP_RINIT_FUNCTION(appserver)
207208
{
208209
char *ptr, *str, *sapiconst = APPSERVER_CONSTANT_PHP_SAPI;
209210
zend_constant *defined;
210-
zval *new_phpsapi;
211211
char *new_phpsapi_name;
212212

213213
if (INI_STR("appserver.php_sapi") != "") {
214214
new_phpsapi_name = INI_STR("appserver.php_sapi");
215215
/* check if PHP_SAPI const can be found to overwrite cli sapi name to appserver */
216216
if (zend_hash_find(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void **) &defined) == SUCCESS) {
217-
/* create zval for new sapi string */
218-
MAKE_STD_ZVAL(new_phpsapi);
219-
ZVAL_STRING(new_phpsapi, new_phpsapi_name, 1);
220-
/* create new constant with new php sapi name */
221-
zend_constant c;
222-
c.value = *new_phpsapi;
223-
c.flags = PHP_USER_CONSTANT;
224-
c.name = zend_strndup(&sapiconst, strlen(sapiconst));
225-
c.name_len = strlen(sapiconst) + 1;
226-
c.module_number = 0;
227-
/* update PHP_SAPI constant in hash table */
228-
zend_hash_update(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void*)&c, sizeof(zend_constant), (void **)&c);
217+
/* delete old hash entry */
218+
zend_hash_del(EG(zend_constants), sapiconst, strlen(sapiconst)+1);
219+
/* register new constant with new php sapi name */
220+
zend_register_string_constant(sapiconst, strlen(sapiconst)+1, new_phpsapi_name, CONST_CS | CONST_PERSISTENT, 0 TSRMLS_CC);
229221
}
230222
}
231223

@@ -269,6 +261,24 @@ PHP_MINFO_FUNCTION(appserver)
269261
DISPLAY_INI_ENTRIES();
270262
}
271263

264+
/* {{{ proto boolean appserver_set_raw_post_data(string $postData)
265+
sets the raw post data to be available in php://input stream */
266+
PHP_FUNCTION(appserver_set_raw_post_data)
267+
{
268+
char *postData;
269+
zend_uint postData_len;
270+
271+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &postData, &postData_len) == FAILURE) {
272+
return;
273+
}
274+
275+
/* set to $HTTP_RAW_POST_DATA var */
276+
SET_VAR_STRINGL("HTTP_RAW_POST_DATA", estrndup(postData, postData_len), postData_len);
277+
/* set to php://input */
278+
SG(request_info).raw_post_data = estrndup(postData, postData_len);
279+
SG(request_info).raw_post_data_length = postData_len;
280+
}
281+
272282
/* {{{ proto boolean appserver_redefine(string $constant [, mixed $value])
273283
redefine/undefine constant at runtime ... /* }}} */
274284
PHP_FUNCTION(appserver_redefine)

src/php_appserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ PHP_FUNCTION(appserver_get_headers);
7171
PHP_FUNCTION(appserver_register_file_upload);
7272
PHP_FUNCTION(appserver_set_headers_sent);
7373
PHP_FUNCTION(appserver_redefine);
74+
PHP_FUNCTION(appserver_set_raw_post_data);
7475

7576
ZEND_BEGIN_MODULE_GLOBALS(appserver)
7677
appserver_llist *headers;

src/tests/appserver_009.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ Johann Zelger <jz [at] techdivision [dot] com>
66
appserver.php_sapi=appserver
77
--FILE--
88
<?php
9-
10-
echo PHP_SAPI . "\r\n";
11-
9+
var_dump(PHP_SAPI);
1210
?>
1311
--EXPECT--
14-
appserver
12+
string(9) "appserver"

src/tests/appserver_010.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
appserver: call appserver_set_raw_post_data and check if string is available in php://input and $HTTP_RAW_POST_DATA var.
3+
--CREDITS--
4+
Johann Zelger <jz [at] techdivision [dot] com>
5+
--FILE--
6+
<?php
7+
appserver_set_raw_post_data('Set this string to php://input and HTTP_RAW_POST_DATA var');
8+
var_dump(file_get_contents('php://input'));
9+
var_dump($HTTP_RAW_POST_DATA);
10+
?>
11+
--EXPECT--
12+
string(57) "Set this string to php://input and HTTP_RAW_POST_DATA var"
13+
string(57) "Set this string to php://input and HTTP_RAW_POST_DATA var"

0 commit comments

Comments
 (0)