X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_message.c;h=3186b79edca07ed13a09e982c9ced7bf64d5a239;hp=0701af00c562d1241ca3106c3f17f844f323ebfc;hb=refs%2Fheads%2Fv2.6.x;hpb=42f0deb424dd6348d91d09120f015844d832afd6 diff --git a/src/php_http_message.c b/src/php_http_message.c index 0701af0..3186b79 100644 --- a/src/php_http_message.c +++ b/src/php_http_message.c @@ -358,25 +358,15 @@ void php_http_message_update_headers(php_http_message_t *msg) static void message_headers(php_http_message_t *msg, php_http_buffer_t *str) { char *tmp = NULL; + size_t len = 0; TSRMLS_FETCH_FROM_CTX(msg->ts); - switch (msg->type) { - case PHP_HTTP_REQUEST: - php_http_buffer_appendf(str, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF)); - PTR_FREE(tmp); - break; - - case PHP_HTTP_RESPONSE: - php_http_buffer_appendf(str, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, tmp, PHP_HTTP_CRLF)); - PTR_FREE(tmp); - break; - - default: - break; - } - + php_http_info_to_string((php_http_info_t *) msg, &tmp, &len, PHP_HTTP_CRLF TSRMLS_CC); php_http_message_update_headers(msg); + + php_http_buffer_append(str, tmp, len); php_http_header_to_string(str, &msg->hdrs TSRMLS_CC); + STR_FREE(tmp); } void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg) @@ -446,7 +436,7 @@ php_http_message_t *php_http_message_reverse(php_http_message_t *msg) if (c > 1) { php_http_message_t *tmp = msg, **arr; - arr = ecalloc(c, sizeof(**arr)); + arr = ecalloc(c, sizeof(*arr)); for (i = 0; i < c; ++i) { arr[i] = tmp; tmp = tmp->parent; @@ -712,7 +702,7 @@ void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_D php_http_message_object_t **objects; int last; - objects = ecalloc(i, sizeof(**objects)); + objects = ecalloc(i, sizeof(*objects)); /* we are the first message */ objects[0] = obj; @@ -1391,24 +1381,13 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(HttpMessage, getInfo) { if (SUCCESS == zend_parse_parameters_none()) { - char *tmp = NULL; + size_t len = 0; php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); - switch (obj->message->type) { - case PHP_HTTP_REQUEST: - Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, tmp, "")); - PTR_FREE(tmp); - break; - case PHP_HTTP_RESPONSE: - Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, PHP_HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, tmp, "")); - PTR_FREE(tmp); - break; - default: - RETURN_NULL(); - break; - } + php_http_info_to_string((php_http_info_t *) obj->message, &Z_STRVAL_P(return_value), &len, "" TSRMLS_CC); + Z_STRLEN_P(return_value) = len; Z_TYPE_P(return_value) = IS_STRING; return; }