Skip to content

Commit

Permalink
Merge pull request #16 from zelgerj/master
Browse files Browse the repository at this point in the history
fixed memory leaks. added new function
  • Loading branch information
zelgerj committed Mar 31, 2014
2 parents 9be1394 + 88268c9 commit 4826b94
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Registeres an uploaded file top super global hash table rfc1867_uploaded_files a
#####appserver_set_headers_sent(boolean $sent)
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);

#####appserver_set_raw_post_data(string $postData)
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.

# Debug on Mac OS X

Expand Down
7 changes: 3 additions & 4 deletions build.default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

# ---- General Settings ---------------------------------------------------------
php.ext.name = appserver
php.sapi.name = appserver

release.version = 0.1.6
release.version = 0.1.7
release.stability = beta
api.version = 0.1.6
api.version = 0.1.7
api.stability = beta

php.version = 5.5.10
Expand Down Expand Up @@ -41,7 +40,7 @@ php.configure = --prefix=/opt/appserver \
--with-zlib \
zmq.version = dev-master
pthreads.version = 1.0.1
pthreads.version = 2.0.4
memcached.version = 2.1.0
redis.version = 2.2.3
apcu.version = 4.0.2
Expand Down
36 changes: 23 additions & 13 deletions src/appserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const zend_function_entry appserver_functions[] = {
PHP_FE(appserver_register_file_upload, NULL)
PHP_FE(appserver_set_headers_sent, NULL)
PHP_FE(appserver_redefine, NULL)
PHP_FE(appserver_set_raw_post_data, NULL)
PHP_FE_END
};

Expand Down Expand Up @@ -207,25 +208,16 @@ PHP_RINIT_FUNCTION(appserver)
{
char *ptr, *str, *sapiconst = APPSERVER_CONSTANT_PHP_SAPI;
zend_constant *defined;
zval *new_phpsapi;
char *new_phpsapi_name;

if (INI_STR("appserver.php_sapi") != "") {
new_phpsapi_name = INI_STR("appserver.php_sapi");
/* check if PHP_SAPI const can be found to overwrite cli sapi name to appserver */
if (zend_hash_find(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void **) &defined) == SUCCESS) {
/* create zval for new sapi string */
MAKE_STD_ZVAL(new_phpsapi);
ZVAL_STRING(new_phpsapi, new_phpsapi_name, 1);
/* create new constant with new php sapi name */
zend_constant c;
c.value = *new_phpsapi;
c.flags = PHP_USER_CONSTANT;
c.name = zend_strndup(&sapiconst, strlen(sapiconst));
c.name_len = strlen(sapiconst) + 1;
c.module_number = 0;
/* update PHP_SAPI constant in hash table */
zend_hash_update(EG(zend_constants), sapiconst, strlen(sapiconst)+1, (void*)&c, sizeof(zend_constant), (void **)&c);
/* delete old hash entry */
zend_hash_del(EG(zend_constants), sapiconst, strlen(sapiconst)+1);
/* register new constant with new php sapi name */
zend_register_string_constant(sapiconst, strlen(sapiconst)+1, new_phpsapi_name, CONST_CS | CONST_PERSISTENT, 0 TSRMLS_CC);
}
}

Expand Down Expand Up @@ -269,6 +261,24 @@ PHP_MINFO_FUNCTION(appserver)
DISPLAY_INI_ENTRIES();
}

/* {{{ proto boolean appserver_set_raw_post_data(string $postData)
sets the raw post data to be available in php://input stream */
PHP_FUNCTION(appserver_set_raw_post_data)
{
char *postData;
zend_uint postData_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &postData, &postData_len) == FAILURE) {
return;
}

/* set to $HTTP_RAW_POST_DATA var */
SET_VAR_STRINGL("HTTP_RAW_POST_DATA", estrndup(postData, postData_len), postData_len);
/* set to php://input */
SG(request_info).raw_post_data = estrndup(postData, postData_len);
SG(request_info).raw_post_data_length = postData_len;
}

/* {{{ proto boolean appserver_redefine(string $constant [, mixed $value])
redefine/undefine constant at runtime ... /* }}} */
PHP_FUNCTION(appserver_redefine)
Expand Down
1 change: 1 addition & 0 deletions src/php_appserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ PHP_FUNCTION(appserver_get_headers);
PHP_FUNCTION(appserver_register_file_upload);
PHP_FUNCTION(appserver_set_headers_sent);
PHP_FUNCTION(appserver_redefine);
PHP_FUNCTION(appserver_set_raw_post_data);

ZEND_BEGIN_MODULE_GLOBALS(appserver)
appserver_llist *headers;
Expand Down
6 changes: 2 additions & 4 deletions src/tests/appserver_009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ Johann Zelger <jz [at] techdivision [dot] com>
appserver.php_sapi=appserver
--FILE--
<?php

echo PHP_SAPI . "\r\n";

var_dump(PHP_SAPI);
?>
--EXPECT--
appserver
string(9) "appserver"
13 changes: 13 additions & 0 deletions src/tests/appserver_010.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
appserver: call appserver_set_raw_post_data and check if string is available in php://input and $HTTP_RAW_POST_DATA var.
--CREDITS--
Johann Zelger <jz [at] techdivision [dot] com>
--FILE--
<?php
appserver_set_raw_post_data('Set this string to php://input and HTTP_RAW_POST_DATA var');
var_dump(file_get_contents('php://input'));
var_dump($HTTP_RAW_POST_DATA);
?>
--EXPECT--
string(57) "Set this string to php://input and HTTP_RAW_POST_DATA var"
string(57) "Set this string to php://input and HTTP_RAW_POST_DATA var"

0 comments on commit 4826b94

Please sign in to comment.