Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 38 additions & 37 deletions src/php_http_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ PHP_METHOD(HttpHeader, __construct)
}
}

ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_serialize, 0, 0, 0)
ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_tostring, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpHeader, serialize)
PHP_METHOD(HttpHeader, __toString)
{
if (SUCCESS == zend_parse_parameters_none()) {
php_http_buffer_t buf;
Expand All @@ -219,42 +219,44 @@ PHP_METHOD(HttpHeader, serialize)
RETURN_EMPTY_STRING();
}

ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_serialize, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpHeader, __serialize)
{
zval *val, tmp;

if (SUCCESS != zend_parse_parameters_none()) {
RETURN_THROWS();
}
array_init(return_value);

val = zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), 0, &tmp);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), val);
val = zend_read_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), 0, &tmp);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), val);
}

ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpHeader, unserialize)
PHP_METHOD(HttpHeader, __unserialize)
{
char *serialized_str;
size_t serialized_len;

if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized_str, &serialized_len)) {
HashTable ht;

zend_hash_init(&ht, 1, NULL, ZVAL_PTR_DTOR, 0);
if (SUCCESS == php_http_header_parse(serialized_str, serialized_len, &ht, NULL, NULL)) {
if (zend_hash_num_elements(&ht)) {
zend_string *zs, *key;
zend_ulong idx;

zend_hash_internal_pointer_reset(&ht);
switch (zend_hash_get_current_key(&ht, &key, &idx)) {
case HASH_KEY_IS_STRING:
zend_update_property_str(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), key);
break;
case HASH_KEY_IS_LONG:
zend_update_property_long(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), idx);
break;
default:
break;
}
zs = zval_get_string(zend_hash_get_current_data(&ht));
zend_update_property_str(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), zs);
zend_string_release(zs);
}
}
zend_hash_destroy(&ht);
zval *serialized;
HashTable *data;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "h", &data) == FAILURE) {
RETURN_THROWS();
}

ZVAL_NULL(return_value);
serialized = zend_hash_index_find(data, 0);
if (serialized) {
zend_update_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("name"), serialized);
}
serialized = zend_hash_index_find(data, 1);
if (serialized) {
zend_update_property(php_http_header_class_entry, Z_OBJ_P(ZEND_THIS), ZEND_STRL("value"), serialized);
}
}

ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_match, 0, 0, 1)
Expand Down Expand Up @@ -399,10 +401,10 @@ PHP_METHOD(HttpHeader, parse)

static zend_function_entry php_http_header_methods[] = {
PHP_ME(HttpHeader, __construct, ai_HttpHeader___construct, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
ZEND_MALIAS(HttpHeader, toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, __serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, __toString, ai_HttpHeader_tostring, ZEND_ACC_PUBLIC)
ZEND_MALIAS(HttpHeader, toString, __toString, ai_HttpHeader_tostring, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, __unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, match, ai_HttpHeader_match, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, negotiate, ai_HttpHeader_negotiate, ZEND_ACC_PUBLIC)
PHP_ME(HttpHeader, getParams, ai_HttpHeader_getParams, ZEND_ACC_PUBLIC)
Expand All @@ -416,7 +418,6 @@ PHP_MINIT_FUNCTION(http_header)

INIT_NS_CLASS_ENTRY(ce, "http", "Header", php_http_header_methods);
php_http_header_class_entry = zend_register_internal_class(&ce);
zend_class_implements(php_http_header_class_entry, 1, zend_ce_serializable);
zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_LOOSE"), PHP_HTTP_MATCH_LOOSE);
zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_CASE"), PHP_HTTP_MATCH_CASE);
zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_WORD"), PHP_HTTP_MATCH_WORD);
Expand Down
70 changes: 39 additions & 31 deletions src/php_http_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,44 +1764,53 @@ static PHP_METHOD(HttpMessage, toCallback)

ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_serialize, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, serialize)
static PHP_METHOD(HttpMessage, __serialize)
{
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *string;
size_t length;

PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
char *string;
size_t length;
zval zstr;

php_http_message_serialize(obj->message, &string, &length);
RETURN_STR(php_http_cs2zs(string, length));
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
RETURN_EMPTY_STRING();
array_init(return_value);

PHP_HTTP_MESSAGE_OBJECT_INIT(obj);

php_http_message_serialize(obj->message, &string, &length);
ZVAL_STR(&zstr, php_http_cs2zs(string, length));
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &zstr);
}

ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, unserialize)
static PHP_METHOD(HttpMessage, __unserialize)
{
size_t length;
char *serialized;
zval *serialized;
HashTable *data;

if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &length)) {
php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_message_t *msg;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "h", &data) == FAILURE) {
RETURN_THROWS();
}

if (obj->message) {
/* do not free recursively */
php_http_message_dtor(obj->message);
efree(obj->message);
}
if ((msg = php_http_message_parse(NULL, serialized, length, 1))) {
obj->message = msg;
} else {
obj->message = php_http_message_init(NULL, 0, NULL);
php_error_docref(NULL, E_ERROR, "Could not unserialize http\\Message");
}
php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_http_message_t *msg;

if (obj->message) {
/* do not free recursively */
php_http_message_dtor(obj->message);
efree(obj->message);
}

serialized = zend_hash_index_find(data, 0);
if (serialized && Z_TYPE_P(serialized) == IS_STRING &&
(msg = php_http_message_parse(NULL, Z_STRVAL_P(serialized), Z_STRLEN_P(serialized), 1))) {
obj->message = msg;
} else {
obj->message = php_http_message_init(NULL, 0, NULL);
php_error_docref(NULL, E_ERROR, "Could not unserialize http\\Message");
}
}

Expand Down Expand Up @@ -2038,9 +2047,8 @@ static zend_function_entry php_http_message_methods[] = {
/* implements Countable */
PHP_ME(HttpMessage, count, ai_HttpMessage_count, ZEND_ACC_PUBLIC)

/* implements Serializable */
PHP_ME(HttpMessage, serialize, ai_HttpMessage_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessage, unserialize, ai_HttpMessage_unserialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessage, __serialize, ai_HttpMessage_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessage, __unserialize, ai_HttpMessage_unserialize, ZEND_ACC_PUBLIC)

/* implements Iterator */
PHP_ME(HttpMessage, rewind, ai_HttpMessage_rewind, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -2079,7 +2087,7 @@ PHP_MINIT_FUNCTION(http_message)
php_http_message_object_handlers.get_gc = php_http_message_object_get_gc;
php_http_message_object_handlers.cast_object = php_http_message_object_cast;

zend_class_implements(php_http_message_class_entry, 3, zend_ce_countable, zend_ce_serializable, zend_ce_iterator);
zend_class_implements(php_http_message_class_entry, 2, zend_ce_countable, zend_ce_iterator);

zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, php_http_message_object_prophandler_hash_dtor, 1);
zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED);
Expand Down
43 changes: 36 additions & 7 deletions src/php_http_message_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,16 +688,46 @@ PHP_METHOD(HttpMessageBody, __toString)
RETURN_EMPTY_STRING();
}


ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_serialize, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessageBody, __serialize)
{
php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
zend_string *zs;
zval zstr;

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
array_init(return_value);

PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);

zs = php_http_message_body_to_string(obj->body, 0, 0);
if (zs) {
ZVAL_STR(&zstr, zs);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &zstr);
}
}


ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpMessageBody, unserialize)
PHP_METHOD(HttpMessageBody, __unserialize)
{
zend_string *us_str;
zval *serialized;
HashTable *data;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "h", &data) == FAILURE) {
RETURN_THROWS();
}

if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "S", &us_str)) {
serialized = zend_hash_index_find(data, 0);
if (serialized && Z_TYPE_P(serialized) == IS_STRING) {
php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, getThis());
php_stream *s = php_http_mem_stream_open(0, us_str);
php_stream *s = php_http_mem_stream_open(0, Z_STR_P(serialized));

obj->body = php_http_message_body_init(NULL, s);
php_stream_to_zval(s, obj->gc);
Expand Down Expand Up @@ -912,8 +942,8 @@ static zend_function_entry php_http_message_body_methods[] = {
PHP_ME(HttpMessageBody, __construct, ai_HttpMessageBody___construct, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
PHP_MALIAS(HttpMessageBody, toString, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
PHP_MALIAS(HttpMessageBody, serialize, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, unserialize, ai_HttpMessageBody_unserialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, __serialize, ai_HttpMessageBody_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, __unserialize, ai_HttpMessageBody_unserialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, toStream, ai_HttpMessageBody_toStream, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, toCallback, ai_HttpMessageBody_toCallback, ZEND_ACC_PUBLIC)
PHP_ME(HttpMessageBody, getResource, ai_HttpMessageBody_getResource, ZEND_ACC_PUBLIC)
Expand All @@ -938,7 +968,6 @@ PHP_MINIT_FUNCTION(http_message_body)
php_http_message_body_object_handlers.clone_obj = php_http_message_body_object_clone;
php_http_message_body_object_handlers.free_obj = php_http_message_body_object_free;
php_http_message_body_object_handlers.get_gc = php_http_message_body_object_get_gc;
zend_class_implements(php_http_message_body_class_entry, 1, zend_ce_serializable);

return SUCCESS;
}
Expand Down
33 changes: 21 additions & 12 deletions src/php_http_querystring.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,26 +568,35 @@ PHP_METHOD(HttpQueryString, xlate)

ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_serialize, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, serialize)
PHP_METHOD(HttpQueryString, __serialize)
{
zval zstr;

if (SUCCESS != zend_parse_parameters_none()) {
return;
RETURN_THROWS();
}
php_http_querystring_str(getThis(), return_value);
ZVAL_NULL(&zstr);
array_init(return_value);

php_http_querystring_str(getThis(), &zstr);
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &zstr);
}

ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_unserialize, 0, 0, 1)
ZEND_ARG_INFO(0, serialized)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, unserialize)
PHP_METHOD(HttpQueryString, __unserialize)
{
zval *serialized;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "z", &serialized)) {
return;
HashTable *data;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "h", &data) == FAILURE) {
RETURN_THROWS();
}

if (Z_TYPE_P(serialized) == IS_STRING) {
ZVAL_NULL(return_value);
serialized = zend_hash_index_find(data, 0);
if (serialized && Z_TYPE_P(serialized) == IS_STRING) {
php_http_querystring_set(getThis(), serialized, 0);
} else {
php_error_docref(NULL, E_WARNING, "Expected a string as parameter");
Expand Down Expand Up @@ -708,9 +717,9 @@ static zend_function_entry php_http_querystring_methods[] = {
PHP_ME(HttpQueryString, xlate, ai_HttpQueryString_xlate, ZEND_ACC_PUBLIC)
#endif

/* Implements Serializable */
PHP_ME(HttpQueryString, serialize, ai_HttpQueryString_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpQueryString, unserialize, ai_HttpQueryString_unserialize, ZEND_ACC_PUBLIC)

PHP_ME(HttpQueryString, __serialize, ai_HttpQueryString_serialize, ZEND_ACC_PUBLIC)
PHP_ME(HttpQueryString, __unserialize, ai_HttpQueryString_unserialize, ZEND_ACC_PUBLIC)

/* Implements ArrayAccess */
PHP_ME(HttpQueryString, offsetGet, ai_HttpQueryString_offsetGet, ZEND_ACC_PUBLIC)
Expand All @@ -728,7 +737,7 @@ PHP_MINIT_FUNCTION(http_querystring)
INIT_NS_CLASS_ENTRY(ce, "http", "QueryString", php_http_querystring_methods);
php_http_querystring_class_entry = zend_register_internal_class(&ce);
php_http_querystring_class_entry->create_object = php_http_querystring_object_new;
zend_class_implements(php_http_querystring_class_entry, 3, zend_ce_serializable, zend_ce_arrayaccess, zend_ce_aggregate);
zend_class_implements(php_http_querystring_class_entry, 2, zend_ce_arrayaccess, zend_ce_aggregate);

zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("instance"), (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE));
zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("queryArray"), ZEND_ACC_PRIVATE);
Expand Down
2 changes: 1 addition & 1 deletion tests/envresponse016.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "skipif.inc";
echo "Test\n";

class closer extends php_user_filter {
function filter ($in, $out, &$consumed, $closing) {
function filter ($in, $out, &$consumed, $closing): int {
while ($bucket = stream_bucket_make_writeable($in)) {
stream_bucket_append($out, $bucket);
}
Expand Down