X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_message.c;h=b3adb46911e79ef46281e50f3a68f38d116f9335;hb=d926a12aeec96752456eddfbf9a04a002809a0d2;hp=d6a7f755c76b73e0b6a6719f5ac1d42b80d222b1;hpb=aacbe6aa75ca07853bf88d5b3647f67f107d1af7;p=m6w6%2Fext-http diff --git a/php_http_message.c b/php_http_message.c index d6a7f75..b3adb46 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -124,17 +124,25 @@ PHP_HTTP_API php_http_message_t *php_http_message_parse(php_http_message_t *msg, { php_http_message_parser_t p; php_http_buffer_t buf; + int free_msg; - if (!msg) { - msg = php_http_message_init(NULL, 0 TSRMLS_CC); - } php_http_buffer_from_string_ex(&buf, str, len); php_http_message_parser_init(&p TSRMLS_CC); - php_http_message_parser_parse(&p, &buf, PHP_HTTP_MESSAGE_PARSER_CLEANUP, &msg); + + if ((free_msg = !msg)) { + msg = php_http_message_init(NULL, 0 TSRMLS_CC); + } + + if (FAILURE == php_http_message_parser_parse(&p, &buf, PHP_HTTP_MESSAGE_PARSER_CLEANUP, &msg)) { + if (free_msg) { + php_http_message_free(&msg); + } + msg = NULL; + } + php_http_message_parser_dtor(&p); php_http_buffer_dtor(&buf); - /* FIXME */ return msg; } @@ -161,7 +169,8 @@ PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, char *key_st ZVAL_STRINGL(header_str, PHP_HTTP_BUFFER_VAL(&str), PHP_HTTP_BUFFER_LEN(&str), 0); ret = header_str; } else { - ret = php_http_ztyp(IS_STRING, *header); + Z_ADDREF_PP(header); + ret = *header; } } @@ -1139,7 +1148,7 @@ static zval **php_http_message_object_get_prop_ptr(zval *object, zval *member, c if (SUCCESS == php_http_message_object_get_prophandler(Z_STRVAL_P(copy), Z_STRLEN_P(copy), &handler)) { zval_ptr_dtor(©); - return &php_http_property_proxy_init(NULL, object, member TSRMLS_CC)->myself; + return &php_http_property_proxy_init(NULL, object, member, NULL TSRMLS_CC)->myself; } zval_ptr_dtor(©); @@ -1153,18 +1162,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)) { - 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"); - 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); } @@ -1280,16 +1287,17 @@ PHP_METHOD(HttpMessage, __construct) with_error_handling(EH_THROW, php_http_exception_class_entry) { if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &message, &length) && message && length) { - php_http_message_t *msg = obj->message; + if (message && length) { + php_http_message_t *msg = php_http_message_parse(NULL, message, length TSRMLS_CC); - php_http_message_dtor(msg); - with_error_handling(EH_THROW, php_http_exception_class_entry) { - if ((obj->message = php_http_message_parse(msg, message, length TSRMLS_CC))) { + if (!msg) { + php_http_error(HE_THROW, PHP_HTTP_E_MESSAGE, "could not parse message: %.*s", 25, message); + } else { + php_http_message_dtor(obj->message); + obj->message = msg;{ if (obj->message->parent) { obj->parent = php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, NULL TSRMLS_CC); } - } else { - obj->message = php_http_message_init(msg, 0 TSRMLS_CC); } } end_error_handling(); }