projects
/
m6w6
/
ext-http
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
fix leak
[m6w6/ext-http]
/
php_http_message.c
diff --git
a/php_http_message.c
b/php_http_message.c
index 318470e34ffe2f297b562fd1a71d7653e6ec255a..066deca86566b3e640d6e92e0d9ab2f112e39c49 100644
(file)
--- a/
php_http_message.c
+++ b/
php_http_message.c
@@
-6,17
+6,11
@@
| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
- | Copyright (c) 2004-201
0
, Michael Wallner <mike@php.net> |
+ | Copyright (c) 2004-201
1
, Michael Wallner <mike@php.net> |
+--------------------------------------------------------------------+
*/
+--------------------------------------------------------------------+
*/
-/* $Id: http_message_api.c 298689 2010-04-28 06:50:06Z mike $ */
-
-#include "php_http.h"
-
-#include <main/SAPI.h>
-#include <ext/spl/spl_iterators.h>
-#include <Zend/zend_interfaces.h>
+#include "php_http_api.h"
PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC)
{
PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC)
{
@@
-149,7
+143,7
@@
PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, char *key_st
zval *ret = NULL, **header;
char *key = php_http_pretty_key(estrndup(key_str, key_len), key_len, 1, 1);
zval *ret = NULL, **header;
char *key = php_http_pretty_key(estrndup(key_str, key_len), key_len, 1, 1);
- if (SUCCESS == zend_
hash
_find(&msg->hdrs, key, key_len + 1, (void *) &header)) {
+ if (SUCCESS == zend_
symtable
_find(&msg->hdrs, key, key_len + 1, (void *) &header)) {
if (join && Z_TYPE_PP(header) == IS_ARRAY) {
zval *header_str, **val;
HashPosition pos;
if (join && Z_TYPE_PP(header) == IS_ARRAY) {
zval *header_str, **val;
HashPosition pos;
@@
-382,8
+376,9
@@
PHP_HTTP_API php_http_message_t *php_http_message_reverse(php_http_message_t *ms
php_http_message_count(c, msg);
if (c > 1) {
php_http_message_count(c, msg);
if (c > 1) {
- php_http_message_t *tmp = msg, **arr = ecalloc(c, sizeof(**arr));
-
+ php_http_message_t *tmp = msg, **arr;
+
+ arr = ecalloc(c, sizeof(**arr));
for (i = 0; i < c; ++i) {
arr[i] = tmp;
tmp = tmp->parent;
for (i = 0; i < c; ++i) {
arr[i] = tmp;
tmp = tmp->parent;
@@
-566,7
+561,7
@@
PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC)
}
*/
}
*/
-PHP_HTTP_API php_http_message_t *php_http_message_copy
(php_http_message_t *from, php_http_message_t *to
)
+PHP_HTTP_API php_http_message_t *php_http_message_copy
_ex(php_http_message_t *from, php_http_message_t *to, zend_bool parents
)
{
php_http_message_t *temp, *copy = NULL;
php_http_info_t info;
{
php_http_message_t *temp, *copy = NULL;
php_http_info_t info;
@@
-581,7
+576,7
@@
PHP_HTTP_API php_http_message_t *php_http_message_copy(php_http_message_t *from,
zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
php_http_message_body_copy(&from->body, &temp->body, 1);
zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
php_http_message_body_copy(&from->body, &temp->body, 1);
- while (from->parent) {
+
if (parents)
while (from->parent) {
info.type = from->parent->type;
info.http = from->parent->http;
info.type = from->parent->type;
info.http = from->parent->http;
@@
-598,6
+593,11
@@
PHP_HTTP_API php_http_message_t *php_http_message_copy(php_http_message_t *from,
return copy;
}
return copy;
}
+PHP_HTTP_API php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to)
+{
+ return php_http_message_copy_ex(from, to, 1);
+}
+
PHP_HTTP_API void php_http_message_dtor(php_http_message_t *message)
{
if (message) {
PHP_HTTP_API void php_http_message_dtor(php_http_message_t *message)
{
if (message) {
@@
-704,20
+704,12
@@
PHP_HTTP_BEGIN_ARGS(setHttpVersion, 1)
PHP_HTTP_ARG_VAL(http_version, 0)
PHP_HTTP_END_ARGS;
PHP_HTTP_ARG_VAL(http_version, 0)
PHP_HTTP_END_ARGS;
-PHP_HTTP_BEGIN_ARGS(guessContentType, 1)
- PHP_HTTP_ARG_VAL(magic_file, 0)
- PHP_HTTP_ARG_VAL(magic_mode, 0)
-PHP_HTTP_END_ARGS;
-
PHP_HTTP_EMPTY_ARGS(getParentMessage);
PHP_HTTP_EMPTY_ARGS(getParentMessage);
-PHP_HTTP_EMPTY_ARGS(send);
PHP_HTTP_EMPTY_ARGS(__toString);
PHP_HTTP_BEGIN_ARGS(toString, 0)
PHP_HTTP_ARG_VAL(include_parent, 0)
PHP_HTTP_END_ARGS;
PHP_HTTP_EMPTY_ARGS(__toString);
PHP_HTTP_BEGIN_ARGS(toString, 0)
PHP_HTTP_ARG_VAL(include_parent, 0)
PHP_HTTP_END_ARGS;
-PHP_HTTP_EMPTY_ARGS(toMessageTypeObject);
-
PHP_HTTP_EMPTY_ARGS(count);
PHP_HTTP_EMPTY_ARGS(serialize);
PHP_HTTP_EMPTY_ARGS(count);
PHP_HTTP_EMPTY_ARGS(serialize);
@@
-806,9
+798,11
@@
static STATUS php_http_message_object_add_prophandler(const char *prop_str, size
php_http_message_object_prophandler_t h = { read, write };
return zend_hash_add(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) &h, sizeof(h), NULL);
}
php_http_message_object_prophandler_t h = { read, write };
return zend_hash_add(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) &h, sizeof(h), NULL);
}
+/*
static int php_http_message_object_has_prophandler(const char *prop_str, size_t prop_len) {
return zend_hash_exists(&php_http_message_object_prophandlers, prop_str, prop_len + 1);
}
static int php_http_message_object_has_prophandler(const char *prop_str, size_t prop_len) {
return zend_hash_exists(&php_http_message_object_prophandlers, prop_str, prop_len + 1);
}
+*/
static STATUS php_http_message_object_get_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_t **handler) {
return zend_hash_find(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) handler);
}
static STATUS php_http_message_object_get_prophandler(const char *prop_str, size_t prop_len, php_http_message_object_prophandler_t **handler) {
return zend_hash_find(&php_http_message_object_prophandlers, prop_str, prop_len + 1, (void *) handler);
}
@@
-943,7
+937,7
@@
PHP_MINIT_FUNCTION(http_message)
php_http_message_object_handlers.get_properties = php_http_message_object_get_props;
php_http_message_object_handlers.get_property_ptr_ptr = php_http_message_object_get_prop_ptr;
php_http_message_object_handlers.get_properties = php_http_message_object_get_props;
php_http_message_object_handlers.get_property_ptr_ptr = php_http_message_object_get_prop_ptr;
- zend_class_implements(php_http_message_class_entry TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator
, php_http_fluently_callable_class_entry
);
+ zend_class_implements(php_http_message_class_entry TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, NULL, 1);
zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED TSRMLS_CC);
zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, NULL, 1);
zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED TSRMLS_CC);
@@
-1159,18
+1153,16
@@
static zval *php_http_message_object_read_prop(zval *object, zval *member, int t
zval *return_value, *copy = php_http_ztyp(IS_STRING, member);
if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
zval *return_value, *copy = php_http_ztyp(IS_STRING, member);
if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) {
- if (type == BP_VAR_W) {
- zval_ptr_dtor(©);
+ if (type == BP_VAR_R) {
+ ALLOC_ZVAL(return_value);
+ Z_SET_REFCOUNT_P(return_value, 0);
+ Z_UNSET_ISREF_P(return_value);
+
+ handler->read(obj, return_value TSRMLS_CC);
+ } else {
zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
- return NULL;
+ return
_value =
NULL;
}
}
-
- ALLOC_ZVAL(return_value);
- Z_SET_REFCOUNT_P(return_value, 0);
- Z_UNSET_ISREF_P(return_value);
-
- handler->read(obj, return_value TSRMLS_CC);
-
} else {
return_value = zend_get_std_object_handlers()->read_property(object, member, type, literal_key TSRMLS_CC);
}
} else {
return_value = zend_get_std_object_handlers()->read_property(object, member, type, literal_key TSRMLS_CC);
}
@@
-1392,10
+1384,10
@@
PHP_METHOD(HttpMessage, setHeader)
}
if (!zvalue) {
}
if (!zvalue) {
- zend_
hash
_del(&obj->message->hdrs, name, name_len + 1);
+ zend_
symtable
_del(&obj->message->hdrs, name, name_len + 1);
} else {
Z_ADDREF_P(zvalue);
} else {
Z_ADDREF_P(zvalue);
- zend_
hash
_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
+ zend_
symtable
_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
}
efree(name);
}
}
efree(name);
}
@@
-1441,7
+1433,7
@@
PHP_METHOD(HttpMessage, addHeader)
convert_to_array(header);
zend_hash_next_index_insert(Z_ARRVAL_P(header), &zvalue, sizeof(void *), NULL);
} else {
convert_to_array(header);
zend_hash_next_index_insert(Z_ARRVAL_P(header), &zvalue, sizeof(void *), NULL);
} else {
- zend_
hash
_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
+ zend_
symtable
_update(&obj->message->hdrs, name, name_len + 1, &zvalue, sizeof(void *), NULL);
}
efree(name);
}
}
efree(name);
}