X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_message.c;h=c96531748c166ad8c86407e7d4c278650055fcad;hp=f7696da5f520915f135ce051b368068c2b41b101;hb=c0a90e57b4fe369f68b02111770815d66ec5a380;hpb=a5c998ba6ef2aaa080ee724ddfac5bfd9ef995c9 diff --git a/php_http_message.c b/php_http_message.c index f7696da..c965317 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -937,14 +937,12 @@ static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC) { zval *headers; php_http_message_object_t *obj = zend_object_store_get_object(object TSRMLS_CC); - php_http_message_t *msg = obj->message; HashTable *props = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC); zval array, *parent, *body; char *version; int verlen; PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - INIT_PZVAL_ARRAY(&array, props); #define ASSOC_PROP(ptype, n, val) \ @@ -969,17 +967,17 @@ static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC) verlen = spprintf(&version, 0, "%u.%u", obj->message->http.version.major, obj->message->http.version.minor); ASSOC_STRINGL_EX("httpVersion", version, verlen, 0); - switch (msg->type) { + switch (obj->message->type) { case PHP_HTTP_REQUEST: ASSOC_PROP(long, "responseCode", 0); ASSOC_STRINGL("responseStatus", "", 0); - ASSOC_STRING("requestMethod", STR_PTR(msg->http.info.request.method)); - ASSOC_STRING("requestUrl", STR_PTR(msg->http.info.request.url)); + ASSOC_STRING("requestMethod", STR_PTR(obj->message->http.info.request.method)); + ASSOC_STRING("requestUrl", STR_PTR(obj->message->http.info.request.url)); break; case PHP_HTTP_RESPONSE: - ASSOC_PROP(long, "responseCode", msg->http.info.response.code); - ASSOC_STRING("responseStatus", STR_PTR(msg->http.info.response.status)); + ASSOC_PROP(long, "responseCode", obj->message->http.info.response.code); + ASSOC_STRING("responseStatus", STR_PTR(obj->message->http.info.response.status)); ASSOC_STRINGL("requestMethod", "", 0); ASSOC_STRINGL("requestUrl", "", 0); break; @@ -995,18 +993,19 @@ static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC) MAKE_STD_ZVAL(headers); array_init(headers); - zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + zend_hash_copy(Z_ARRVAL_P(headers), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); ASSOC_PROP(zval, "headers", headers); MAKE_STD_ZVAL(body); - if (!obj->body) { - php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), (void *) &obj->body TSRMLS_CC); + if (obj->body) { + ZVAL_OBJVAL(body, obj->body->zv, 1); + } else { + ZVAL_NULL(body); } - ZVAL_OBJVAL(body, obj->body->zv, 1); ASSOC_PROP(zval, "body", body); MAKE_STD_ZVAL(parent); - if (msg->parent) { + if (obj->message->parent) { ZVAL_OBJVAL(parent, obj->parent->zv, 1); } else { ZVAL_NULL(parent); @@ -1042,13 +1041,15 @@ static PHP_METHOD(HttpMessage, __construct) if (s && php_http_message_parser_init(&p TSRMLS_CC)) { unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0); + php_http_buffer_t buf; - if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse_stream(&p, s, flags, &msg)) { + php_http_buffer_init_ex(&buf, 0x1000, PHP_HTTP_BUFFER_INIT_PREALLOC); + if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse_stream(&p, &buf, s, flags, &msg)) { if (!EG(exception)) { php_http_throw(bad_message, "Could not parse message from stream", NULL); } } - + php_http_buffer_dtor(&buf); php_http_message_parser_dtor(&p); }