/* advance message */
if (!old || old->type || zend_hash_num_elements(&old->hdrs)) {
- (*message) = php_http_message_init(NULL, 0 TSRMLS_CC);
+ (*message) = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
(*message)->parent = old;
if (headers) {
(*headers) = &((*message)->hdrs);
return old != *message;
}
-PHP_HTTP_API php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type TSRMLS_DC)
+PHP_HTTP_API php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body TSRMLS_DC)
{
if (!message) {
message = emalloc(sizeof(*message));
message->http.version.major = 1;
message->http.version.minor = 1;
zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0);
- php_http_message_body_init(&message->body, NULL TSRMLS_CC);
+ message->body = body ? body : php_http_message_body_init(NULL, NULL TSRMLS_CC);
return message;
}
zval *sval, tval;
php_http_message_body_t *mbody;
- message = php_http_message_init(message, type TSRMLS_CC);
-
switch (type) {
case PHP_HTTP_REQUEST:
+ mbody = php_http_env_get_request_body(TSRMLS_C);
+ php_http_message_body_addref(mbody);
+ message = php_http_message_init(message, type, mbody TSRMLS_CC);
if ((sval = php_http_env_get_server_var(ZEND_STRL("SERVER_PROTOCOL"), 1 TSRMLS_CC)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
php_http_version_parse(&message->http.version, Z_STRVAL_P(sval) TSRMLS_CC);
}
}
php_http_env_get_request_headers(&message->hdrs TSRMLS_CC);
-
- if ((mbody = php_http_env_get_request_body(TSRMLS_C))) {
- php_http_message_body_dtor(&message->body);
- php_http_message_body_copy(mbody, &message->body, 0);
- }
break;
case PHP_HTTP_RESPONSE:
+ message = php_http_message_init(NULL, type, NULL TSRMLS_CC);
if (!SG(sapi_headers).http_status_line || !php_http_info_parse((php_http_info_t *) &message->http, SG(sapi_headers).http_status_line TSRMLS_CC)) {
if (!(message->http.info.response.code = SG(sapi_headers).http_response_code)) {
message->http.info.response.code = 200;
php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not fetch response body");
goto error;
} else {
- php_http_message_body_append(&message->body, Z_STRVAL(tval), Z_STRLEN(tval));
+ php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval));
zval_dtor(&tval);
}
}
default:
error:
if (free_msg) {
- php_http_message_free(&message);
+ if (message) {
+ php_http_message_free(&message);
+ }
} else {
message = NULL;
}
php_http_message_parser_init(&p TSRMLS_CC);
if ((free_msg = !msg)) {
- msg = php_http_message_init(NULL, 0 TSRMLS_CC);
+ msg = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (greedy) {
zval *h;
size_t size;
- if (php_http_message_body_stream(&msg->body)->readfilters.head) {
+ if (php_http_message_body_stream(msg->body)->readfilters.head) {
/* if a read stream filter is attached to the body the caller must also care for the headers */
- } else if ((size = php_http_message_body_size(&msg->body))) {
+ } else if ((size = php_http_message_body_size(msg->body))) {
MAKE_STD_ZVAL(h);
ZVAL_LONG(h, size);
zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), &h, sizeof(zval *), NULL);
- if (msg->body.boundary) {
+ if (msg->body->boundary) {
char *str;
size_t len;
if (!(h = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1))) {
- len = spprintf(&str, 0, "multipart/form-data; boundary=\"%s\"", msg->body.boundary);
+ len = spprintf(&str, 0, "multipart/form-data; boundary=\"%s\"", msg->body->boundary);
MAKE_STD_ZVAL(h);
ZVAL_STRINGL(h, str, len, 0);
zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL);
} else if (!php_http_match(Z_STRVAL_P(h), "boundary=", PHP_HTTP_MATCH_WORD)) {
zval_dtor(h);
- Z_STRLEN_P(h) = spprintf(&Z_STRVAL_P(h), 0, "%s; boundary=\"%s\"", Z_STRVAL_P(h), msg->body.boundary);
+ Z_STRLEN_P(h) = spprintf(&Z_STRVAL_P(h), 0, "%s; boundary=\"%s\"", Z_STRVAL_P(h), msg->body->boundary);
zend_hash_update(&msg->hdrs, "Content-Type", sizeof("Content-Type"), &h, sizeof(zval *), NULL);
} else {
zval_ptr_dtor(&h);
cb(cb_arg, str.data, str.used);
php_http_buffer_dtor(&str);
- if (php_http_message_body_size(&msg->body)) {
+ if (php_http_message_body_size(msg->body)) {
cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF));
- php_http_message_body_to_callback(&msg->body, cb, cb_arg, 0, 0);
+ php_http_message_body_to_callback(msg->body, cb, cb_arg, 0, 0);
}
}
php_http_buffer_init_ex(&str, 0x1000, 0);
message_headers(msg, &str);
- if (php_http_message_body_size(&msg->body)) {
+ if (php_http_message_body_size(msg->body)) {
php_http_buffer_appends(&str, PHP_HTTP_CRLF);
- php_http_message_body_to_callback(&msg->body, (php_http_pass_callback_t) php_http_buffer_append, &str, 0, 0);
+ php_http_message_body_to_callback(msg->body, (php_http_pass_callback_t) php_http_buffer_append, &str, 0, 0);
}
data = php_http_buffer_data(&str, string, length);
info.type = from->type;
info.http = from->http;
- copy = temp = php_http_message_init(to, 0 TSRMLS_CC);
+ copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL) TSRMLS_CC);
php_http_message_set_info(temp, &info);
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);
if (parents) while (from->parent) {
info.type = from->parent->type;
info.http = from->parent->http;
- temp->parent = php_http_message_init(NULL, 0 TSRMLS_CC);
+ temp->parent = php_http_message_init(NULL, 0, php_http_message_body_copy(from->parent->body, NULL) TSRMLS_CC);
php_http_message_set_info(temp->parent, &info);
zend_hash_copy(&temp->parent->hdrs, &from->parent->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
- php_http_message_body_copy(&from->parent->body, &temp->parent->body, 1);
temp = temp->parent;
from = from->parent;
{
if (message) {
zend_hash_destroy(&message->hdrs);
- php_http_message_body_dtor(&message->body);
+ php_http_message_body_free(&message->body);
switch (message->type) {
case PHP_HTTP_REQUEST:
if (msg_obj->body.handle) {
zend_objects_store_del_ref_by_handle(msg_obj->body.handle TSRMLS_CC);
- php_http_message_body_dtor(&msg_obj->message->body);
}
+ php_http_message_body_free(&msg_obj->message->body);
- php_http_message_body_copy(body_obj->body, &msg_obj->message->body, 0);
+ msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC);
msg_obj->body = Z_OBJVAL_P(zbody);
- if (tmp) {
- zval_ptr_dtor(&tmp);
- }
-
return SUCCESS;
}
}
if (msg) {
- php_http_message_body_object_t *body_obj;
-
o->message = msg;
if (msg->parent) {
o->parent = php_http_message_object_new_ex(ce, msg->parent, NULL TSRMLS_CC);
}
- o->body = php_http_message_body_object_new_ex(php_http_message_body_get_class_entry(), &msg->body, &body_obj TSRMLS_CC);
- body_obj->shared = 1;
+ o->body = php_http_message_body_object_new_ex(php_http_message_body_get_class_entry(), php_http_message_body_init(&msg->body, NULL TSRMLS_CC), NULL TSRMLS_CC);
}
ov.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_object_free, NULL TSRMLS_CC);
MAKE_STD_ZVAL(body);
if (!obj->body.handle) {
- php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_copy(&obj->message->body, NULL, 0), NULL TSRMLS_CC);
+ php_http_new(&obj->body, php_http_message_body_get_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), NULL TSRMLS_CC);
}
ZVAL_OBJVAL(body, obj->body, 1);
ASSOC_PROP(array, zval, "body", body);
}
}
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
} end_error_handling();
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (!obj->body.handle) {
- php_http_message_body_object_t *body_obj;
- obj->body = php_http_message_body_object_new_ex(php_http_message_body_get_class_entry(), &obj->message->body, &body_obj TSRMLS_CC);
- body_obj->shared = 1;
+ php_http_message_body_addref(obj->message->body);
+ php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, NULL TSRMLS_CC);
}
if (obj->body.handle) {
RETVAL_OBJVAL(obj->body, 1);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_object_prophandler_set_body(obj, zbody TSRMLS_CC);
}
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
php_http_message_body_object_t *new_obj = zend_object_store_get_object(new_body TSRMLS_CC);
- php_http_message_body_to_callback(new_obj->body, (php_http_pass_callback_t) php_http_message_body_append, &obj->message->body, 0, 0);
+ php_http_message_body_to_callback(new_obj->body, (php_http_pass_callback_t) php_http_message_body_append, obj->message->body, 0, 0);
}
RETVAL_ZVAL(getThis(), 1, 0);
}
zval *header;
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
array_init(return_value);
char *name = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (!zvalue) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
zend_hash_clean(&obj->message->hdrs);
zval *header;
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
Z_ADDREF_P(zvalue);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, append, ARRAY_JOIN_STRONLY|ARRAY_JOIN_PRETTIFY);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
RETURN_LONG(obj->message->type);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_set_type(obj->message, type);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
switch (obj->message->type) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_set_info(obj->message, &inf);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_version_to_string(&obj->message->http.version, &str, &len, NULL, NULL TSRMLS_CC);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (php_http_version_parse(&version, v_str TSRMLS_CC)) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (obj->message->parent) {
size_t length;
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (include_parent) {
php_stream_from_zval(s, &zstream);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s);
size_t length;
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_serialize(obj->message, &string, &length);
if ((msg = php_http_message_parse(NULL, serialized, (size_t) length, 1 TSRMLS_CC))) {
obj->message = msg;
} else {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
php_http_error(HE_ERROR, PHP_HTTP_E_RUNTIME, "Could not unserialize HttpMessage");
}
}
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0);
php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
if (!prepend_obj->message) {
- prepend_obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ prepend_obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
/* safety check */
if (php_http_message_is_multipart(obj->message, &boundary)) {
php_http_message_t *msg;
- if ((msg = php_http_message_body_split(&obj->message->body, boundary))) {
+ if ((msg = php_http_message_body_split(obj->message->body, boundary))) {
RETVAL_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
}
}
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (!obj->message) {
- obj->message = php_http_message_init(NULL, 0 TSRMLS_CC);
+ obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
}
php_http_message_count(i, obj->message);